/*
###  ini.js                                    
#  ver1.5 (2007.01.10) SEO登録区分対応        
#  ver1.4 (2006.09.06) Web顧客集客(Safari対応)
#  ver1.3 (2002.12.01)                       
#  ver1.2 (2002.11.01)                       
#  ver1.1 (2002.08.01)                       
#  ver1.0 (2002.01.01)                       
#  "ini.js" is Initial-setting file.         
###
*/

// # Delete Error Message
// # 2002.12.01
function HideError(){
	return true;
}
window.onerror = HideError;


// # OS,Browser Info
// # 2002.01.01
var ie  = (navigator.appName.indexOf('Micr') != -1);
var mac = (navigator.userAgent.indexOf('Mac') != -1 || navigator.userAgent.indexOf('mac') != -1);
var win = (navigator.userAgent.indexOf('Win') != -1 || navigator.userAgent.indexOf('win') != -1);


// # IMGのPreLoad
// # 2002.01.01
function PreLoad() {
	var d = document;
	if(d.images){
		if(!d.My_IMG) d.My_IMG = new Array();
		var i , j = d.My_IMG.length , a = PreLoad.arguments;
		for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){
			d.My_IMG[j] = new Image;
			d.My_IMG[j++].src = a[i];
		}
	}
}


// # Object検索・取得
// # 2002.01.01
function GetObj(n, d) {
	var p,i,x;
	if(!d) d = document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d = parent.frames[n.substring(p+1)].document;
		n = n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x = d.all[n];
	for(i=0; !x&&i<d.forms.length; i++) x = d.forms[i][n];
	for(i=0; !x&&d.layers&&i<d.layers.length; i++) x = GetObj(n,d.layers[i].document);
	if(!x && document.getElementById) x = document.getElementById(n);
	return x;
}


// # IMG切り替え
// # 2002.01.01
function ChgIMG() {
	var i , j = 0 , x , a = ChgIMG.arguments;
	document.My_sr = new Array;
	for(i=0; i<(a.length-2); i+=3) if ((x=GetObj(a[i]))!=null){
		document.My_sr[j++] = x;
		if(!x.oSrc) x.oSrc = x.src;
		x.src = a[i+2];
	}
}

// # 切り替えIMGのReset
// # 2002.01.01
function ResetIMG() {
	var i , x , a = document.My_sr;
	for(i=0; a&&i<a.length&&(x=a[i])&&x.oSrc; i++) x.src = x.oSrc;
}

// # PullDown Menu Link
// # 2002.01.01
function JumpMenu(targ,selObj,restore){
	if(selObj.options[selObj.selectedIndex].value != "-"){
		eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
	}
	if (restore) selObj.selectedIndex = 0;
}

// # Sub Window Open2
var agt=navigator.userAgent.toLowerCase();
var newwin = "";
var winie4 = ( navigator.userAgent.indexOf('MSIE 4')!=-1 && win );
//2004.3.31	mac&netscape4.7判定
var is_nsc  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nsc4 = (is_nsc && navigator.appVersion.indexOf("4.7") != -1);

function popup(u,n,w,h) {

	if( sbwin_closed(newwin) ){
		//2004.3.31 netscape4.7の場合はステータスバーを表示
		if (is_nsc4 && mac) {
		//2003.9.4  IBM修正－ツールバーを表示
			newwin = window.open(u,n,'width=' + w + ',height=' + h + ',toolbar=yes,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes');
		} else {
			newwin = window.open(u,n,'width=' + w + ',height=' + h + ',toolbar=yes,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no');
		}

	} else if ( newwin.name != n ) {
		//2003.9.4  既存ウィンドウ名が別名ならば、新しく開く
		if (is_nsc4 && mac) {
			newwin = window.open(u,n,'width=' + w + ',height=' + h + ',toolbar=yes,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes');
		} else {
			newwin = window.open(u,n,'width=' + w + ',height=' + h + ',toolbar=yes,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no');
		}
	} else {
		newwin.location.href = u;
	}
	newwin.focus();
	reset();
}

// # 商品詳細用サブウィンドウ
function popupWithNoMenu(u,n,w,h) {
	
	if( sbwin_closed(newwin) ){
		if (is_nsc4 && mac) {
			newwin = window.open(u,n,'width=' + w + ',height=' + h + ',toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes');
		} else {
			newwin = window.open(u,n,'width=' + w + ',height=' + h + ',toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no');
		}
	//2003.9.4  既存ウィンドウ名が別名ならば、新しく開く
	} else if ( newwin.name != n ) {
		if (is_nsc4 && mac) {
			newwin = window.open(u,n,'width=' + w + ',height=' + h + ',toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes');
		} else {
			newwin = window.open(u,n,'width=' + w + ',height=' + h + ',toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no');
		}
	}else{
		newwin.location.href = u;
	}
	newwin.focus();
	reset();
}

// # サーバ上位パス						2003.9.12追加

var pathStr = location.pathname.match('/webapp/.*/servlet/');
//

// URLのみ指定してサブウィンドウを開く(幅=580、高さ=480　固定)
function popupInfo(URL) {
	//URLと固定ウィンドウサイズでpopup関数を呼ぶ
	popup(URL, 'info', '580', '480');
}

// 権限振り分けコマンドでサブウィンドウを開く
function popupURLBySiteId(displaySiteId, screenId) {
	// パラメータからURLを生成して、サブウィンドウを開く
	URL = pathStr + 'YChangeURL?screenID=' + screenId + '&displaySiteId=' + displaySiteId;
	//URLと固定ウィンドウサイズでpopUpWin関数を呼ぶ
	popupInfo(URL);
}

// サブウィンドウに商品詳細画面を開く
function popupProductDisplay(catEntryId, screenID) {
	// パラメータから商品詳細用のURLを生成して、サブウィンドウを開く
	URL = pathStr + 'YReferentialProductDisplayView?storeId=1001&screenID=' + screenID + '&catEntryId=' + catEntryId;
	popupWithNoMenu(URL, 'product', '580', '480');
}

// サブウィンドウに商品詳細画面を開く（CATENTRY_IDでなくPARTNUMBERを渡す）
function popupProductDisplayByPartNumber(partNumber, screenID) {
	// パラメータから商品詳細用のURLを生成して、サブウィンドウを開く
	URL = pathStr + 'YReferentialProductDisplayView?storeId=1001&screenID=' + screenID + '&partNumber=' + partNumber;
	popupWithNoMenu(URL, 'product', '580', '480');
}

// サブウィンドウに商品詳細画面を開く（URLのみ指定してサブウィンドウを開く）
function popupProductDisplayByUrl(URL) {
	popupWithNoMenu(URL + '&storeId=1001', 'product', '580', '480');
}

function sbwin_closed(winVar) {
	if( !winVar ) {
		if( winie4 ) return winVar.closed;
		else return typeof winVar.document != 'object';
	}else{
		return true;
	}
}

//# Win IE4／Mac IE4でclosed判定バグ回避
function sbwin_closed(winVar) {
	var ua = navigator.userAgent
	if( !!winVar )
		if( ( ua.indexOf('Gecko')!=-1 || ua.indexOf('MSIE 4')!=-1 ) && ua.indexOf('Win')!=-1 )
			return winVar.closed
		else return typeof winVar.document  != 'object'
	else return true
}


// # StatusBar Message
// # 2002.01.01
function StatusMsg(MS) {
	window.status = MS;
	document.FLAG = true;
}


// # Layer 切り替え
// # 2002.10.01
function SHLayer() {
	var i,p,v,obj,args = SHLayer.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=GetObj(args[i]))!=null) {
		v = args[i+2];
		if (obj.style) {
			obj = obj.style;
			v = (v=='show')?'visible':(v=='hide')?'hidden':v;
		}
		obj.visibility=v;
	}
}

//戻るボタン関連---ここから
//var confirm_cookie = "SHOW_CONFIRM=1";
//
//function setCookie() {
//	ck = document.cookie;
//	if (!ck.match(confirm_cookie)) {
//		document.cookie = confirm_cookie;
//	}
//}
//
//function getNextView(nextView, errView) {
//	ck = document.cookie;
//	if (!ck.match(confirm_cookie)) {
//		return errView;
//	} else {
//		return nextView;
//	}
//}
//
//function checkCookie(fname, nextView, errView) {
//	ck = document.cookie;
//	if (!ck.match(confirm_cookie)) {
//		fname.action = errView;	
//	} else {
//		fname.action = nextView
//	}
//	fname.submit();
//}
//
//function delCookie() {
//	expDate = new Date("January 1, 2000");
//	document.cookie = confirm_cookie + ";expires=" + expDate.toGMTString();
//}
//
//function setNextCookie() {
//	ck = document.cookie;
//	if (!ck.match(confirm_cookie)) {
//		setNextCookieVal();
//		delCookie();
//
//	} else {
//		delCookie();
//		setNextCookieVal();
//		setCookie();
//	}
//}
//
//function setNextCookieVal() {
//	confirm_cookie = "SHOW_CONFIRM=2";
//}

function getLayField(fname) {
	if(document.BackControl == null){
		return document.layers['lay'].document.forms['BackControl'].elements[fname];
	}
	return document.BackControl.elements[fname];
}
	
function reloadMe(){
	if(getLayField('reloadFlg').value != 0){
		location.reload(true);
	}
	getLayField('reloadFlg').value = 1;
}
//戻るボタン関連---ここまで



//新戻る対応---ここから
function setCookie(cookieName) {
	ck = document.cookie;
	if (!ck.match(cookieName)) {
		document.cookie = cookieName + ";secure";
	}
}

function getNextView(nextView, errView, cookieName) {
	ck = document.cookie;
	if (!ck.match(cookieName)) {
		return errView;
	} else {
		return nextView;
	}
}

function delCookie(cookieName) {
	expDate = new Date("January 1, 2000");
	document.cookie = cookieName + ";expires=" + expDate.toGMTString();
}
//新戻る対応---ここまで


//２重クリック関連---ここから
function clickCheck(fname, aname, targ){
	flg = document.DoubleClick.submitFlg.value;
	if(flg == 0){	
		if (targ != "") {
			fname.target = targ;
		}
		if (aname != "") {
			fname.action = aname;
		}
		document.DoubleClick.submitFlg.value = 1;
		fname.submit();	
	}		
}
//２重クリック関連-スイスイカタログ用
function clickCheckOnlineCat(fname, aname, targ){
	var flg = 0;
	var checkFlg = (mac && navigator.userAgent.indexOf('MSIE')!=-1);

	if(!checkFlg){
		flg = parent.parent.frames['left'].document.DoubleClick.submitFlg.value;
	}else{
		flg = document.DoubleClick.submitFlg.value;
	}

	if(flg == 0){	
		if (targ != "") {
			fname.target = targ;
		}
		if (aname != "") {
			fname.action = aname;
		}
		if(!checkFlg){
			parent.parent.frames['left'].document.DoubleClick.submitFlg.value = 1;
		}else{
			document.DoubleClick.submitFlg.value = 1;
		}
		fname.submit();	
	}
}
//--------------------------------------------------------
//
// 親の配下のフレームの２重押下フラグを全てクリアする
// 但しSafariブラウザの場合は自分のフラグだけをクリアする
//
//--------------------------------------------------------
function reset(targ) {
// 2006/09/06 Sano Natsumi Web顧客集客(Safari対応) mod start
	// Safariの場合は自分のフラグだけをクリア
	var uName = navigator.userAgent.toUpperCase();
	if(uName.indexOf("SAFARI") >= 0) {
		resetSelf();
	} else {
		resetAll();
	}
// 2006/09/06 Sano Natsumi Web顧客集客(Safari対応) mod end
}
//--------------------------------------------------------
//
// TOPの配下フレームの２重押下フラグを全てクリアする
//
//--------------------------------------------------------
function resetParent(targ) {
	if (top.frames.length == 0) {
		if ((document.DoubleClick == null) ||
						(document.DoubleClick.submitFlg.value == null)) {
			
		} else {
			document.DoubleClick.submitFlg.value = 0;
		}
	} else {
		for (i = 0; i < top.frames.length; i++) {
			if ((top.frames[i].document.DoubleClick == null) ||
						(top.frames[i].document.DoubleClick.submitFlg.value == null)) {

			} else {
				top.frames[i].document.DoubleClick.submitFlg.value = 0;
			}
		}		
	}
}
// 2006/09/06 Sano Natsumi Web顧客集客(Safari対応) add start
//--------------------------------------------------------
//
// 親の配下のフレームの２重押下フラグを全てクリアする
//
//--------------------------------------------------------
function resetAll() {
	if (parent.frames.length == 0) {
		if ((document.DoubleClick == null) ||
						(document.DoubleClick.submitFlg.value == null)) {
			
		} else {
			document.DoubleClick.submitFlg.value = 0;
		}
	} else {
		for (i = 0; i < parent.frames.length; i++) {
			if ((parent.frames[i].document.DoubleClick == null) ||
						(parent.frames[i].document.DoubleClick.submitFlg.value == null)) {
				
			} else {
				parent.frames[i].document.DoubleClick.submitFlg.value = 0;
			}
		}		
	}
}
//--------------------------------------------------------
//
// 自フレームの２重押下フラグだけをクリアする
//
//--------------------------------------------------------
function resetSelf() {
	if ((document.DoubleClick == null) ||
					(document.DoubleClick.submitFlg.value == null)) {
		
	} else {
		document.DoubleClick.submitFlg.value = 0;
	}
}
// 2006/09/06 Sano Natsumi Web顧客集客(Safari対応) add end

//２重クリック関連---ここまで
// E N D

// サブウィンドウに賞品詳細画面を開く
function popupPrizeDisplay(przCode, screenID) {
	// パラメータから商品詳細用のURLを生成して、サブウィンドウを開く
	URL = pathStr + 'YPointItemDisplayPopupView?storeId=1001&screenID=' + screenID + '&przCode=' + przCode;
	popupWithNoMenu(URL, 'product', '580', '480');
}

// 2007/01/10 Mitsuru Sakamoto SEO登録区分対応 add start
//SEO対応済み画面に遷移元判定クッキーを埋め込む
seoCookieValue='SO';
lastVisitCookieName='lastVisit';
function setSeoCookie(screenValue) {
	domainName= 'askul.co.jp';
	myRef = isMyReferer();
	noExistSeoCookie = getSeoCookie(seoCookieValue); 
	//遷移元が自サイトではなく、かつ、遷移元クッキーがSEO用の場合に２つのクッキーを発行する。
	if(myRef == false && noExistSeoCookie == false){
		var exp=new Date();
		exp.setTime(exp.getTime()+1000*60*60*24*90);
		document.cookie = lastVisitCookieName + '=' + escape(seoCookieValue) + '; path=/ ; domain='+ domainName +'; expires=' + exp.toGMTString();
		document.cookie = 'visitTool=' + escape(screenValue) + '; path=/ ; domain='+ domainName +'; expires=' + exp.toGMTString();
	}
}

//referrerが自サイトであるかどうかを判定する
function isMyReferer() {
	isMyRefFlg = false;
	ref = document.referrer ;
	if(ref != null && ref != '' && isMyDomain(ref) == false){
		isMyRefFlg = false;
	}
	else{
		isMyRefFlg = true;
	}
	return (isMyRefFlg);
}

//referrerが自サイトであるかどうかをドメイン比較で判定する
function isMyDomain(strReferrer) {
	chkhostname ='';
	hostName = location.hostname;
	//ドメインの開始文字数を取得
	pnt1 = strReferrer.indexOf("://", 0);
	if (pnt1 > -1) {
		//ドメイン後の/まで取得
		pnt2 = strReferrer.indexOf("/", pnt1 + 3);
		//ドメイン部分のみを抽出
		chkhostname = strReferrer.substring(pnt1 + 3, pnt2);
	}

	if(chkhostname == hostName){
		isMyDomainFlg = true;
	}
	else{
		isMyDomainFlg = false;
	}
	return (isMyDomainFlg)
}
//遷移元判定クッキー(SEO以外のものがあるかを判定する
function getSeoCookie(seoName) {
	ckary = new Array();
	ckary = document.cookie.split('; ');
	ckFlg = false;
	i = 0;
	while (ckary[i]){
		if (ckary[i].substr(0,9) == lastVisitCookieName  
		&& unescape(ckary[i].substr(10,11)) != seoName){
			ckFlg = true;
			break;
		}
		i++;
	}
	return (ckFlg);
}
// 2007/01/10 Mitsuru Sakamoto SEO登録区分対応 add end
// ウィンドウを閉じる
function close_win(){
	var nvua = navigator.userAgent;
	if(nvua.indexOf('MSIE') >= 0){
		if(nvua.indexOf('MSIE 5.0') == -1) {
		top.opener = '';
		}
	} else if(nvua.indexOf('Gecko') >= 0){
		top.name = 'CLOSE_WINDOW';
		wid = window.open('','CLOSE_WINDOW');
	}
	top.close();
}

//-----------------------------------------------------------------------------
//    【メソッド名】
//        商品画像生成
//    【引数】
//        targetImg     : イメージタグ
//        imgPath       : 商品画像パス + 画像ファイル名
//    【処理概要】
//        ・商品画像パスにプロトコルが含まれている場合は
//          プロトコルを除去して、location.protocolをセットする
//-----------------------------------------------------------------------------
function getImgSrc(imgPath, h, w, a) {
	path=imgPath;
	idx = imgPath.indexOf("//", 0);
	if (idx != -1){
		path = imgPath.substring(idx);
		path = location.protocol + path;
	}
	document.write("<img src='" + path + "' heigth='" + h + "' width='" + w + "' alt='" + a + "' border='0'>");
}
