//汎用ウィンドウオープン
function openWin(url,name,property) {
	newwin =window.open(url,name,property);
	newwin.focus();
}

//ヘルプウインドウオープン
function helpWin(url) {
	newwin =window.open(url,'help','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=440,left=0,top=0');
}

//各校オープン（for StepEngine）
function comWin(url) {
	newwin =window.open(url,'com','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=751,height=600,left=0,top=0');
	newwin.focus();
}

//cookie
function cookie_01(url){
helpwin = window.open("http://www.bang.co.jp/cgi-bin/cookie/cookie_check.pl","cookie","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=500,height=400");
helpwin.focus();
}

function cookie_02(url){
helpwin = window.open("http://www.bang.co.jp/cookie/","cookie","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=500,height=400");
helpwin.focus();
}

//参加業者一覧(promo・point用)
function comlistWin(url) {
newwin = window.open(url,"com","menubar=no,status=no,location=no,toolbar=no,scrollbars=1,left=0,top=0,width=700,height=500");
newwin.focus();
}

//繁忙期キャンペーン
function campaignWin(url) {
newwin = window.open(url,"campaign","toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=750,height=600,left=0,top=0");
newwin.focus();
}

//ブックマーク
function bookmark(url,title) {
	if(navigator.userAgent.indexOf("MSIE") > -1){
		window.external.AddFavorite('http://www.zubat.net/hikkoshi/','ズバット引越し比較');
	} else if(navigator.userAgent.indexOf("Firefox") > -1){
		window.sidebar.addPanel('ズバット引越し比較','http://www.zubat.net/hikkoshi/','');
	}
}

//ソーシャルブックマーク
function postLink(strType) {
	var refUrl = "";
	var strId = "%3FID%3Dbfkaw00001";
	var strTitle = encodeURIComponent(document.title);
	var strUrl = encodeURIComponent(location.href.split("?")[0]);

	if( strType == "twitter" ) {
		refUrl = "http://twitter.com/intent/tweet?text=" + strTitle + "%EF%BD%9C" + strUrl + strId +"%20%23zbt%20%23zbml" + "&charset=utf-8";
		twitterwin = window.open(refUrl,"popup","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=550,height=480");
		return;
	} else if( strType == "facebook" ) {
		refUrl = "http://www.facebook.com/sharer.php?u=" + strUrl + strId + "&t=" + strTitle;
		facebookwin = window.open(refUrl,"popup","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=550,height=480");
		return;
	} else if( strType == "yahoo" ) {
		refUrl = "http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?t=" + strTitle + "&u=" + strUrl + strId + "&opener=bm&ei=UTF-8";
		yahoowin = window.open(refUrl,"popup","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=550,height=480");
		return;
	} else if( strType == "google" ) {
		refUrl = "http://www.google.com/bookmarks/mark?op=edit&bkmk=" + strUrl + strId + "&title=" + strTitle;
	} else if( strType == "hatena" ) {
		refUrl = "http://b.hatena.ne.jp/add?mode=confirm&ei=UTF-8&url=" + strUrl + strId + "&title=" + strTitle;
		hatenawin = window.open(refUrl,"popup","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=550,height=480");
		return;
	} else if( strType == "livedoor" ) {
		refUrl = "http://clip.livedoor.com/redirect?link=" + strUrl + strId + "&title=" + strTitle;
	}

	if(!window.open(refUrl,'surfing'))location.href=refUrl;
}

//アンケート完了画面用twitter
function sendTwitter() {
	var strText = encodeURI(document.answerForm.twitterText.value);
	strText += "%20http://www.zubat.net/tw/1%20%23zbt%20%23zhks_happy";	
	refUrl = "http://twitter.com/intent/tweet?text=" + strText + "&charset=utf-8";
	
	var twitterwin = window.open(refUrl,"popup","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=550,height=480");
	return;
}

//ご意見＆ご質問オープン
function cntWin() {
	//newwin =window.open('http://help.zubat.net/hikkoshi/','cnt','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=500,left=0,top=0');
	newwin =window.open('http://help.zubat.net/hikkoshi/','cnt','');
	newwin.focus();
}

//kakaku.com
function cntWin2() {
	newwin =window.open('/step/zhks/contact.htm','cnt','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=600,left=0,top=0');
	newwin.focus();
}

//カカクコム用　＆　STEP０用
function cntWin3(promoCode) {
    if (promoCode == 'areaw00104')
    {
		cntWin2();
        return;
	}
	//newwin =window.open('http://help.zubat.net/hikkoshi/','cnt','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=500,left=0,top=0');
	newwin =window.open('http://help.zubat.net/hikkoshi/','cnt','');
	newwin.focus();
}

function cntWinHoujin() {
	newwin =window.open('http://help.zubat.net/hikkoshi/','cnt','');
	newwin.focus();
}

function cntWinKaigai() {
	newwin =window.open('http://help.zubat.net/hikkoshi/','cnt','');
	newwin.focus();
}


//プライバシーポリシーオープン
function privacyWin(url) {
    newwin =window.open(url,'privacy','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=500,left=0,top=0');
    newwin.focus();
}

//利用規約
function termWin(url) {
	if(!url){
		url = 'http://www.webcrew.co.jp/info/terms_pop.html';
	}
	newwin =window.open(url,'terms','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=520,height=500,left=0,top=0');
	newwin.focus();
}

//会員規約
function memberWin(url) {
	newwin =window.open(url,'member','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=500,left=0,top=0');
	newwin.focus();
}

//ブラウザオープン
function brwsWin(url) {
	newwin =window.open(url,'exp','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=550,height=400,left=0,top=0');
	newwin.focus();
}

//郵便番号逆引き
function showZipRev(from) {
	window.open('/common/zip_reverse/index.html?from=' + from,'_blank','width=430,height=640,statusbar=no,menubar=no,resizable=yes');
}

//チェックボックス関連
//ディノス
function dinosWin() {
	newwin =window.open('/hikkoshi/checkbox/dinos/','dinos','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=480,height=600,left=0,top=0');
	newwin.focus();
}

//ブランディア
function brandearWin() {
	newwin =window.open('/hikkoshi/checkbox/brandear/','brandear','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=580,height=600,left=0,top=0');
	newwin.focus();
}

//大地を守る会
function daichiWin() {
	newwin =window.open('/hikkoshi/checkbox/food_delivery/daichi.html','foodDelivery','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=480,height=600,left=0,top=0');
	newwin.focus();
}

//東都生協
function tohtoCoopWin() {
	newwin =window.open('/hikkoshi/checkbox/food_delivery/tohto_coop.html','foodDelivery','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=480,height=600,left=0,top=0');
	newwin.focus();
}

//FRESCO
function frescoWin() {
	newwin =window.open('/hikkoshi/checkbox/fresco/','fresco','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=480,height=600,left=0,top=0');
	newwin.focus();
}

//ベルメゾン
function bellemaisonWin() {
	newwin =window.open('/hikkoshi/checkbox/bellemaison/','bellemaison','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=600,height=500,left=0,top=0');
	newwin.focus();
}

//読売新聞
function yomiuriWin() {
	newwin =window.open('/hikkoshi/checkbox/yomiuri/','yomiuri','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=480,height=600,left=0,top=0');
	newwin.focus();
}

//朝日新聞
function asahiWin() {
	newwin =window.open('/hikkoshi/checkbox/asahi/','asahi','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=480,height=600,left=0,top=0');
	newwin.focus();
}

// エリア検索 
function searchWin(objUrl) {
	var url = objUrl.href;
	newwin =window.open(url,'search','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=630,height=500,left=0,top=0');
	newwin.focus();
}

//フォーム背景色
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;
		}
	}
}

//thanks バイク保険への誘導フォーム
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()};
		}
	}
}

// onload時にフォーム背景色設定を実行
window.onload = function() {
   //var formColor = new colorChange;
   //formColor.set();
   getLabel();
}

//入力項目チェック（旧hikkoshi.js）
function checkForm(fm){
  var boo1 = checkZip(fm);
  var boo2 = checkPrefecture(fm);
  var boo3 = checkPersonsNum(fm);

  var errMsg = "";
  if ( boo1 == false ){
	errMsg+= "郵便番号を正しく入力してください\n";
  }
  if ( boo2 == false ){
	errMsg+= "引越先都道府県を選択してください\n";
  }
  if ( boo3 == false ){
	errMsg+= "引越しされる方の人数を選択してください\n";
  }
  if ( errMsg != "" ){
	window.alert(errMsg);
	return false;
  }else{
	return true;
  }
}

function checkZip(fm){
  var answer_Q_zip_A_1 = toSm(fm.answer_Q_zip_A_1.value);
  var answer_Q_zip_A_2 = toSm(fm.answer_Q_zip_A_2.value);
  var errFlg = 1;
  if ( answer_Q_zip_A_1.length !=3 || answer_Q_zip_A_2.length != 4 ){
	errFlg = 0;
  }
  if ( isNaN(answer_Q_zip_A_1) || isNaN(answer_Q_zip_A_2) ){
	errFlg = 0;
  }
  if ( errFlg == 0 ){
	return false;
  }else{
	fm.answer_Q_zip_A_1.value = answer_Q_zip_A_1;
	fm.answer_Q_zip_A_2.value = answer_Q_zip_A_2;
	return true;
  }
}

function checkPrefecture(fm){
  var pref = toSm(fm.answer_Q_next_pref_id.value);
  var errFlg = 1;
  if ( pref == ""){
	errFlg = 0;
  }
  if ( errFlg == 0 ){
	return false;
  }else{
	return true;
  }
}

function checkPersonsNum(fm){
  var adult = fm.answer_Q_num_adult.value;
  var child = fm.answer_Q_num_child.value;

  if ( adult == 0 && child == 0){
	return false;
  }else{
	return true;
  }
}

function toSm(chkstr) {
  var ZenByte = "あ".length;
  var zenkaku = "０１２３４５６７８９．ＡＢＣＤＥＦＧＨＩＪＫＬＭＮＯＰＱＲＳＴＵＶＷＸＹＺａｂｃｄｅｆｇｈｉｊｋｌｍｎｏｐｑｒｓｔｕｖｗｘｙｚー−";
  var hankaku = "0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz--";

  for(cnt=0;cnt<=hankaku.length-1;cnt++){
	chktarget = zenkaku.substring(cnt*ZenByte,cnt*ZenByte+ZenByte);
	while(chkstr.indexOf(chktarget) >= 0){
	  chkstr = chkstr.substring(0,chkstr.indexOf(chktarget)) + hankaku.charAt(cnt) + chkstr.substring(chkstr.indexOf(chktarget) + ZenByte,chkstr.length);
	}
  }
  return (chkstr);
}

//inputタグのロールオーバ
//onload重複対策
function addOnload(func){  
	try {
		window.addEventListener("load", func, false);
	} catch (e) {
		// IE用
		window.attachEvent("onload", func);
	}  
}

addOnload(function(){
	//【TOP】テキストフィールドをフォーカス
	if(document.body.className == "pageTop" ||
	   document.body.className == "pageOffice" ||
	   document.body.className == "pageArea01" ||
	   document.body.className == "pageArea02" ||
	   document.body.className == "pageArea03" ||
	   document.body.className == "pageLanding" ||
	   document.body.className == "pageLowcost" ||
	   document.body.className == "pageMultiuseLp" ||
	   document.body.className == "pageLco"){
		document.forms[0].answer_Q_zip_A_1.focus();
	}

	//ロールオーバするclassを指定
	if(this.getElementsByClassName("buttonStart").length){
		btnControll(this.getElementsByClassName("buttonStart"));
	}
	if(this.getElementsByClassName("buttonStartS").length){
		btnControll(this.getElementsByClassName("buttonStartS"));
	}
	if(this.getElementsByClassName("buttonSearch").length){
		btnControll(this.getElementsByClassName("buttonSearch"));
	}
	if(this.getElementsByClassName("buttonReturn").length){
		btnControll(this.getElementsByClassName("buttonReturn"));
	}
	if(this.getElementsByClassName("buttonMoveOn").length){
		btnControll(this.getElementsByClassName("buttonMoveOn"));
	}
	if(this.getElementsByClassName("buttonBack").length){
		btnControll(this.getElementsByClassName("buttonBack"));
	}
	if(this.getElementsByClassName("buttonSubmit").length){
		btnControll(this.getElementsByClassName("buttonSubmit"));
	}

	/* 新しいロールオーバ */
	btnOpacity();
});

function btnControll(action) {
	//高さの取得
	var height;
	if(action[0].currentStyle) {//IE
		height = action[0].currentStyle.height.replace(/px/,"");
	}else if(getComputedStyle) {//Mozilla or Opera
		height = window.getComputedStyle(action[0],'').getPropertyValue("height").replace(/px/,"");
	}
	//複数の同名class対応
	for(i = 0;i < action.length;i++){
		/* マウスイベント */
		action[i].onmouseover = function () {this.style.backgroundPosition = "0 "+height*-1+"px";}
		action[i].onmousedown = function () {this.style.backgroundPosition = "0 "+height*-2+"px";}
		action[i].onmouseout = function () {this.style.backgroundPosition = "0 0";}
	}
}
function getElementsByClassName (className) {
	//inputタグのみ
	var children = document.getElementsByTagName('input');
	var elements = new Array();
	for (var i = 0; i < children.length; i++) {
		var child = children[i];
		var classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}

function btnOpacity() {
	var objInput = document.getElementsByName("start_btn");
	if(objInput.length){

		for( var i=0; i < objInput.length; i++){
		
			// マウスイベントの設定
			if (typeof document.body.style.maxHeight != "undefined") {
				// IE 7, mozilla, safari, opera 9
			} else { 
				// IE6, older browsers
				objInput[i].onmouseover = function () {this.className="buttonHover";}	
				objInput[i].onmouseout = function () {this.className = "";}
			}
		
		}
	}
}


