function Wopen(url,w,h,n) {
	var winName = n;
	var Width   = 'width='   + w;
	var Height  = ',height=' + h;
	var Left    = ',left='   + ((screen.width - w) / 2);
	var Top     = ',top='    + ((screen.height- h) / 2);
	var Option = ',status=1,menubar=0,scrollbars=0,resizable=0';
	var features = Width + Height + Left + Top + Option;
	winName = window.open(url,winName,features);
	if (window.focus) {
		winName.focus();
	}
}

function WopenScroll(url,w,h,n) {
	var winName = n;
	var Width   = 'width='   + w;
	var Height  = ',height=' + h;
	var Left    = ',left='   + ((screen.width - w) / 2);
	var Top     = ',top='    + ((screen.height- h) / 2);
	var Option = ',status=1,menubar=0,scrollbars=1,resizable=0';
	var features = Width + Height + Left + Top + Option;
	winName = window.open(url,winName,features);
	if (window.focus) {
		winName.focus();
	}
}

function WopenScrollVariable(url,w,h,n) {
	var winName = n;
	var Width   = 'width='   + w;
	var Height  = ',height=' + h;
	var Left    = ',left='   + ((screen.width - w) / 2);
	var Top     = ',top='    + ((screen.height- h) / 2);
	var Option = ',status=1,menubar=0,scrollbars=1,resizable=1';
	var features = Width + Height + Left + Top + Option;
	winName = window.open(url,winName,features);
	if (window.focus) {
		winName.focus();
	}
}

function imgcng(iName,str){
	document.images[iName].src = str;
}

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src") != null && images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}

function WopenL(url,w,h,n) {
	var winName = n;
	var Width   = 'width='   + w;
	var Height  = ',height=' + h;
	var Left    = ',left='   + 2;
	var Top     = ',top='    + 2;
	var Option = ',status=1,menubar=0,scrollbars=1,resizable=1';
	var features = Width + Height + Left + Top + Option;
	winName = window.open(url,winName,features);
	if (window.focus) {
		winName.focus();
	}
}

/**
 * バナー出力のjqueryプラグイン
 *   pageNo
 *   bannerNo
 *   shopType
 *   nodisp : 非表示にする対象（jqueryで指定可能な形に書くこと）
 *   separator startに開始タグ、endに終了タグ
 */
(function($){
	$.fn.banner=function(config) {
		var url = basepath + '/banner/banner';
		config = jQuery.extend({
			pageNo : '0',
			bannerNo : '0',
			shopType : '',
			separator : { start : "", end : "" }
		},config);

		var current = this;
		$.getJSON(
			url,
			{
				pageNo : config.pageNo,
				bannerNo : config.bannerNo,
				shopType : config.shopType
			},
			function(json) {
				var banners = eval(json);
				//分割表示の対応。バナー表示用divを配列で受け取りバナーデータを等分して表示
				var sIdx = 0;
				var eIdx = 0;
				for (var n = 0; n < current.size(); n++) {
    				var html='';
    				if(banners != null) {
        				for (var i = sIdx; i < (banners.length/current.size())+sIdx; i++) {
    						if (banners[i].bannerBody != null) {
    							html += config.separator.start + banners[i].bannerBody + config.separator.end
    						}
    						eIdx = i;
    					}
        				sIdx = eIdx+1;
    					html = jQuery.trim(html);
    				}
    				if(html != '') {
    					$(current.get(n)).html(html);
    				} else {
    					if(config.nodisp != null) {
    						$(config.nodisp).hide();
    					} else {
    						$(current.get(n)).hide();
    					}
    				}
				}

			}
		);
	};
})(jQuery);

/**
 * エンドユーザーがログインしていれば追加ボタンを表示する
 */
function anyAddDispCtrl(){
	var url = basepath + '/mypage/logincheck';
	var current = this;
	var retVar = false;
	$.getJSON(
		url,
		{
		},
		function(json) {
			var retHUserLogin = eval(json);
			if(retHUserLogin != null) {
				retVar = retHUserLogin[0].isLogin;
				if (retVar == true) {
					// なんでもBOX
					if ($('#anyBookmarkCtrl') != null) {
						$('#anyBookmarkCtrl').show();
					}
					// 俺の店
					if ($('#myShopCtrl') != null) {
						$('#myShopCtrl').show();
					}
					// 俺の女
					if ($('#myGirlCtrl') != null) {
						$('#myGirlCtrl').show();
					}
				}
			}
		});
}

/**
 * なんでもBOXのページ名入力ダイアログ表示
 */
function showPrompt_addAnyBookmark() {
	jPrompt('なんでもBOXの追加<br>このページを追加します<br>登録した項目はMyPageから閲覧できます<br>ページ名を入力してください', '', '名前', function(r) {
		// 未入力なら''、キャンセルならnullが取得できるはず
		if (r == '') {
			inValidAuth(r);
		} else if (r != null) {
			addAnyBox(r)
		}

	});
}
/**
 * ページ名が未入力の場合
 */
function inValidAuth() {
	alert('ページ名が未入力です');
}
/**
 * 追加処理呼び出し
 * @param pageName
 * @returns {Boolean}
 */
function addAnyBox(pageName) {
	var url = $("#basepath_anybox").get()[0].value;
	url = url + "/shop/unsyncupdate?anybox=true&addurl="+document.URL+"&pagename="+pageName;
	$.post(url, {}, postresult_anybox);
	return false;
}
/**
 * 件数オーバー時のメッセージ表示
 * @param data
 */
function postresult_anybox(data){
	if (data == 'over_max_count') {
		alert('最大登録件数を超えています。\nMyPageから削除してください。');
	}
}

