// JavaScript Document

//ヘルプウインドウオープン
function helpWin(url) {
	newwin =window.open(url,'help','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=520,height=520,left=0,top=0');
	newwin.focus();
}

//クッキー
function cookieWin() {
	newwin =window.open('http://www.webcrew.co.jp/browser/','help','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=550,height=400,left=0,top=0');
	newwin.focus();
}

function cookieWin2(){
	newwin =window.open('http://www.bang.co.jp/cgi-bin/cookie/cookie_check.pl','help','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=550,height=400,left=0,top=0');
	newwin.focus();
}

//相互リンク募集フォーム
function mutualWin() {
	newwin =window.open('https://www.webcrew.co.jp/step/contact/mutual_link.html','mutual','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=500,height=440,left=0,top=0');
	newwin.focus();
}

//利用規約
function termWin() {
	newwin =window.open('/partner/terms.html','com','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=520,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();
}

//life Card
function lifeWin() {
	newwin = window.open('/','life','toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,width=760,height=600,left=0,top=0');
	newwin.focus();
}

//お問い合わせ
function btnBack(url) {
	document.location = url;
}

//ソーシャルブックマーク
function postLink(strType) {
	var refUrl = "";
	var strId = "%3FID%3Darkaw00001";
	var strTitle = encodeURIComponent(document.title);
	//【心配なので残す】
	//ボタン無版（04_2.html）のURLを投稿時にボタン有版（04.html）に変更
	//var strUrlBase = location.href.split("?")[0];
	//var strUrl = encodeURIComponent(strUrlBase.replace(/04_2.html/,'04.html'));
	var strUrl = encodeURIComponent("http://www.webcrew.co.jp/promo/campaign/zubat_hikkoshi04.html");
	//var strUrl = encodeURIComponent(location.href.split("?")[0]);

	if( strType == "twitter" ) {
		refUrl = "http://twitter.com/intent/tweet?text=%e3%80%8a%e6%9c%9f%e9%96%93%e9%99%90%e5%ae%9a%e3%80%8b%e6%af%8e%e6%9c%88%e5%bd%93%e3%81%9f%e3%82%8b%ef%bc%81%e5%bc%95%e8%b6%8a%e3%81%97%e4%bb%a3%e9%87%91%e4%b8%8a%e9%99%9010%e4%b8%87%e5%86%86%5b%e7%84%a1%e6%96%99%5d%e3%82%ad%e3%83%a3%e3%83%b3%e3%83%9a%e3%83%bc%e3%83%b3%e5%ae%9f%e6%96%bd%e4%b8%ad%ef%bc%81%e3%80%90%e5%bc%95%e8%b6%8a%e3%81%97%e6%af%94%e8%bc%83%e3%80%91" + "%EF%BD%9C" + strUrl + strId +"%20%23%e5%bc%95%e8%b6%8a%e3%81%97%e6%af%94%e8%bc%83%20%23%e5%bc%95%e8%b6%8a%e3%81%97" + "&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;
}

///// for キャンペーンフォーム /////

//フォーム背景色
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();
}

function pageRedirect(strSiteUrl,strDefId){
	var strlocationUrl = document.location.search;
	var flagId = 0;
	if(strlocationUrl == "" || strlocationUrl == null) {
		if(strDefId != ""){
			strSiteUrl += "?ID=" + strDefId;
		}
	} else {
		var strParam = strlocationUrl.split('?')[1];
		var params = strParam.split('&');

		for(var i=0; i < params.length; i++) {
			var strKV = params[i].split('=');
			
			if(strKV[0] == "ID" || strKV[0] == "id") {
				strSiteUrl += "?ID=" + strKV[1];
				flagId = 1;
			}
			//マイページからの流入対策
			if(strKV[0] == "XID" || strKV[0] == "xid") {
				switch(flagId) {
					case 0:
						strSiteUrl += "?XID=" + strKV[1];
						break;
					case 1:
						strSiteUrl += "&XID=" + strKV[1];
						break;
				}
			}
		}
	}
	window.open(strSiteUrl);
}

// --- recruit専用 ---
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

