//汎用ウィンドウオープン
function openWin(url,name,property) {
	newwin =window.open(url,name,property);
	newwin.focus();
}

//ブックマーク
function bookmark(url,title) {
	if(navigator.userAgent.indexOf("MSIE") > -1){
		window.external.AddFavorite('http://www.mizutaku.jp/','ウォーターサーバー・水の宅配会社を徹底比較！【ミズタク】');
	} else if(navigator.userAgent.indexOf("Firefox") > -1){
		window.sidebar.addPanel('ウォーターサーバー・水の宅配会社を徹底比較！【ミズタク】','http://www.mizutaku.jp/','');
	}
}

//ご意見＆ご質問オープン
function cntWinTano() {
	newwin =window.open('https://www.mizutaku.jp/step/mizutaku/contact.htm','cnt','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=500');
	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');
    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=520,height=500');
	newwin.focus();
}

//会員規約
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();
}

//ブラウザオープン
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();
}

//STEP各社オープン
function comWin(url) {
	newwin =window.open(url,'com','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=725,height=550,left=0,top=0');
	newwin.focus();
}



//フォームアラート
function checkForm(fm) {
	var strZip = toSm(fm.zip.value);
	
	strZip = strZip.replace("-","");

	if ( strZip.length !=7 ) {
		window.alert("郵便番号を正しく入力してください\n(郵便番号は7桁でお願いします)");
	} else if ( isNaN(strZip) ) {
		window.alert("郵便番号を正しく入力してください\n(数字以外が入力されています)");
	} else {
		fm.zip.value = strZip;
		return true;
	}
	return false;
}

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);
}



function enableForm(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.elements.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit") {
				tempobj.disabled = false;
			}
		}
	}
}




//フォームカラー変更
function onForm(which){
	if (document.all || document.getElementById){
		which.style.backgroundColor="#E6FFEC"
		}
}

function blurForm(which){
	if (document.all || document.getElementById){
		which.style.backgroundColor="#FFFFFF"
		}
}

//フォーム背景色
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;
		}
	}
}



// onload時にフォーム背景色設定を実行
window.onload = function() {
   var formColor = new colorChange;
   formColor.set();
}


