//汎用ウィンドウオープン
function openWin(url,name,property) {
	newwin =window.open(url,name,property);
	newwin.focus();
}

//ブックマーク
function bookmark() {
	if(navigator.userAgent.indexOf("MSIE") > -1){
		window.external.AddFavorite('http://bike.bang.co.jp/','バイク保険の比較＆一括見積もり！ 【保険スクエアbang! バイク保険】');
	} else if(navigator.userAgent.indexOf("Firefox") > -1){
		window.sidebar.addPanel('バイク保険の比較＆一括見積もり！ 【保険スクエアbang! バイク保険】','http://bike.bang.co.jp/','');
	}
}

//トピックスオープン
function tpcsWin(url) {
	newwin =window.open(url,'topics','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=440,height=480,left=0,top=0');
	newwin.focus();
}

//ご意見＆ご質問オープン
//function cntWin() {
//	newwin =window.open("https://bike.bang.co.jp/step/bikebang/contact.htm",'cnt','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=440,left=0,top=0');
//	newwin.focus();
//}
function cntWin() {
	var strUrl = "https://bike.bang.co.jp/step/bikebang/contact.htm";
	var strUrlz = "https://help.zubat.net/Contact?siteId=10000";
	var strWinSize = "500";

	try {

		  var strCookie = document.cookie.split("; ");
		  
		  for( var x=0; x < strCookie.length; x++ ) {
			  var strCV = strCookie[x].split('=');
			  if( strCV[0].toUpperCase() == "ZB" ) {
				  strUrl = strUrlz;
				  strWinSize = "920";
				  break;
			  }
		  }

	} catch (e) {
	}

	newwin =window.open(strUrl,'cnt','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width='+strWinSize+',height=440,left=0,top=0');
	newwin.focus();
}







//プライバシーポリシーオープン
function privacyWin() {
    newwin
=window.open('http://www.webcrew.co.jp/info/privacy_pop.html','privacy','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=500,left=0,top=0');
    newwin.focus();
}

//利用規約
function termWin() {
	newwin =window.open('http://www.webcrew.co.jp/info/terms_pop.html','terms','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=500,left=0,top=0');
	newwin.focus();
}

//ウェブクルーID規約
function memberWin() {
	newwin =window.open('http://www.webcrew.co.jp/info/member_pop.html','member','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=500,left=0,top=0');
	newwin.focus();
}


///// for PointPage /////
//cookie設定
function cookieWin() {
	newwin =window.open('http://www.bang.co.jp/cookie/','cookie','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=520,height=500,left=0,top=0');
	newwin.focus();
}

//cookieチェック
function cookieCheckWin() {
	newwin =window.open('http://www.bang.co.jp/cgi-bin/cookie/cookie_check.pl','cookie','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=520,height=500,left=0,top=0');
	newwin.focus();
}


///// for StepEngine /////
//ヘルプウインドウオープン
function helpWin(url) {
	newwin =window.open(url,'help','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=520,height=420,left=0,top=0');
	newwin.focus();
}

//print
function ticketPrint() {
	window.print();
}

//フォーム背景色
function colorChange() {
	this.skip  = ['submit', 'button', 'radio', 'checkbox', 'select-one', 'select-multiple'];
	this.color = { 'blur': '', 'focus': '#DFF5FF' };

	this.set = function() {
		for (var i = 0; i < document.forms.length; i++) {
			for (var f = 0; f < document.forms[i].length; f++) {
				var elm = document.forms[i][f];
				if(!this.checkSkip(elm)) continue;
				this.setColor(elm, 'focus');
				this.setColor(elm, 'blur');
			}      
		}
	}

	this.checkSkip = function(elm) {
		for(var i in this.skip) {
			if(elm.type == this.skip[i]) return false;
		}
		return true;
	}

	this.setColor = function(elm, type) { 
		var color = this.color[type];
		var event = function() { elm.style.backgroundColor = color; };

		if(elm.addEventListener) {
			elm.addEventListener(type, event, false); 
		} else if(elm.attachEvent) {
			elm.attachEvent('on'+type, event); 
		} else {
			elm['on'+type] = event;
		}
	}
}

//stepShow0.htm
function getLabel(){
	var lbs = document.getElementsByTagName('label');
	for(var i=0;i<lbs.length;i++){
		var cimgs = lbs[i].getElementsByTagName('img');
		for(var j=0;j<cimgs.length;j++){
			cimgs[j].formCtrlId = lbs[i].htmlFor;
			cimgs[j].onclick = function(){document.getElementById(this.formCtrlId).click()};
		}
	}
}

//menu切り替え
function switchTab() {

	var currentPath = location.pathname;
	var pageName = new Array();	
		pageName[1] = '/index.html,/';
		pageName[2] = '/howto/index.html,/howto/';
		pageName[3] = '/contents/choice.html';
		pageName[4] = '/contents/about.html';
		pageName[5] = '/option/index.html,/option/,/option/difference.html';
		pageName[6] = '/contents/fact.html';
		pageName[7] = '/contents/accident01.html,/contents/accident02.html';
		pageName[8] = '/contents/case.html';'/compare/index.html,/compare/,/compare/smallsize.html,/compare/midiumsize.html,/compare/largesize.html';
		pageName[9] = '/grade/index.html,/grade/';

	for (i = 1; i < pageName.length; i++) {
		var tabId=document.getElementById('tab'+i);
		var strPageName = pageName[i];
		var strPage = new Array();
		
		strPage = strPageName.split(",");
		
		for(var j = 0; j < strPage.length; j++) {
			if(currentPath == strPage[j]) {
				tabId.className = "on";
				return;
			}
		}
	}
}

//プロモ(gogo)menu切り替え
function switchTabPromoGogogs() {

	var currentPath = location.pathname;
	var pageName = new Array();	
		pageName[1] = '/promo/gogo/index.html,/promo/gogo/';
		pageName[2] = '/promo/gogo/about.html';
		pageName[3] = '/promo/gogo/fact.html';
		pageName[4] = '/promo/gogo/accident01.html,/promo/gogo/accident02.html';
		pageName[5] = '/promo/gogo/case.html';

	for (i = 1; i < pageName.length; i++) {
		var tabId=document.getElementById('tab'+i);
		var strPageName = pageName[i];
		var strPage = new Array();
		
		strPage = strPageName.split(",");
		
		for(var j = 0; j < strPage.length; j++) {
			if(currentPath == strPage[j]) {
				tabId.className = "on";
				return;
			}
		}
	}
}

// onload時に実行する
window.onload = function() {	
	currentPath = location.pathname.split( "/" );
	currentPath = currentPath.slice( 1,2 );
	var formColor = new colorChange;
	formColor.set();
	switchTab();
	switchTabPromoGogogs();
	getLabel();
}

