/*********************************************************************
 * 派遣トップ用JavaScript
 * -------------------------------------------------------------------
 * ◆ 更新履歴
 * 2004.**.**    ILL)Oomura    (Rev.01)新規作成
**********************************************************************/




//クッキー取り出し ---------------------------------------------------
function getCookie(key) {
   tmp = document.cookie + ";"
   tmp1 = tmp.indexOf(key, 0);
   if(tmp1 != -1) {
      tmp = tmp.substring(tmp1, tmp.length);
      start = tmp.indexOf("=", 0) + 1;
      end = tmp.indexOf(";", start);
      return(unescape(tmp.substring(start, end)));
   }
   return("");
}




//クッキーの保存 -----------------------------------------------------
function setCookie(key,val) {
   tmp = key + "=" + escape(val) + "; ";
   tmp += "expires=Fri, 31-Dec-2030 23:59:59; ";
   document.cookie = tmp;
}




//地域検索 -----------------------------------------------------------
//影響フォーム名称：AreaSearch
function pSubmit(type,value) {
    var strUrl = "http://www.val.ne.jp/servlets/top?SID=SID13010";
    var strStartChk = 0;

    //地域検索用応募区分(htmlのhidden参照)
    var strObk = document.AreaSearch.aobk.value;

    document.AreaSearch.area.value = "";

    //リンクをクリックした場合
    if(type == 'click') {
        document.AreaSearch.area.value += value;

    //チェックボックスを選択した場合
    } else if(type == 'check') {
        for(i = 0; i < document.AreaSearch.place.length; i++) {
            if(strStartChk == 0 && document.AreaSearch.place[i].checked == true) {
                document.AreaSearch.area.value += document.AreaSearch.place[i].value;
                strStartChk = 1;
            }else if(document.AreaSearch.place[i].checked == true) {
                document.AreaSearch.area.value += "," + document.AreaSearch.place[i].value;
            }
        }
    }

    //デバッグ用
    //alert("[" + strObk + "]");
    //alert("[" + document.AreaSearch.area.value + "]");
    
    location.href = strUrl + "&place=" + document.AreaSearch.area.value + "&obk=" + strObk;
}




//Enterキーでキーワード検索 ------------------------------------------
function entKeyKeywordSearch() {
	// keyCode が Enterキー(13)の場合、キーワード検索を実行。
	// それだけでは、通常エンターを押下したときの処理である submit
	// が動作する為、returnValue を false (無効化)にする
	if(event.keyCode == 13) {
		window.event.returnValue = false;
		kSubmit();
	}
}
//キーワード検索 -----------------------------------------------------
function kSubmit() {
    var strWord = "";
    var strUrl = "http://www.val.ne.jp/servlets/top?SID=SID13010";

    //キーワード検索用応募区分(htmlのhidden参照)
    var strObk = document.KeywordSearch.kobk.value;
    //キーワード検索・地域フラグ(htmlのhidden参照)
    //var strArea = document.KeywordSearch.karea.value;

    strWord = document.KeywordSearch.word.value;

    //ワード未入力の場合
    if(strWord == "") {
        alert("恐れ入りますが、検索するワードをご入力ください");

    //ワード入力時
    } else {
        //全角空白を半角空白に変換
        while(strWord.indexOf("　") > 0) {
            strWord = strWord.replace("　", " ");
        }

        //半角空白をURLエンコード
        while(strWord.indexOf(" ") > 0) {
            strWord = strWord.replace(" ", "%20");
        }

        //location.href = strUrl + "&place=" + strArea + "&freewdkbn=1&freewd=" + strWord + "&obk=" + strObk;
		location.href = strUrl + "&freewdkbn=1&freewd=" + strWord + "&obk=" + strObk;
    }
}








//クッキーの値オブジェクトに反映 -------------------------------------
function inputCookie() {
    var strID = getCookie("STAFF_ID");
    var strSecureFlag = getCookie("ST_S_CHK");
    var strAutoLoginFlag = getCookie("ST_A_CHK");

    //デバッグ
    //alert("[" + strID + "]");
    //alert("[" + strSecureFlag + "]");
    //alert("[" + strAutoLoginFlag + "]");

    document.InputPage.tx_login_id.value = strID;
    if(strSecureFlag == 1) {
        document.InputPage.secure.checked = true;
    }
    if(strAutoLoginFlag == 1) {
        //デバッグ用
        //alert("[自動ログインロジック実行]");
        autoLogin(strSecureFlag);
    }
}




//自動ログイン -------------------------------------------------------
function autoLogin(strSecureFlag) {
    var strID = getCookie("STAFF_ID");
    var strPassword = getCookie("STAFF_PS");
    //var strSecureFlag = flag;

    //ログインIDとパスワードをオブジェクトに反映
    document.InputPage.tx_login_id.value = strID;
    document.InputPage.tx_passwd.value = strPassword;

    //デバッグ用
    //alert("ID [" + document.InputPage.tx_login_id.value + "]");
    //alert("PASSWORD [" + document.InputPage.tx_passwd.value + "]");

    //セキュリティONの場合、strSecureFlag = 1
    goLogin(strSecureFlag);
}





//Enterキーでパスワードボックスへフォーカス移動 ----------------------
function entKeyToPassword() {
	// keyCodeがEnterキー(13)の場合、キーワード検索を実行。
	// それだけでは、通常エンターを押下したときの処理である submit
	// が動作する為、returnValue を false (無効化)にする
	if(event.keyCode == 13) {
		window.event.returnValue = false;
		document.InputPage.tx_passwd.focus();
	}
}
//Enterキーでログイン ------------------------------------------------
function entKeyLogin() {
	// keyCodeがEnterキー(13)の場合、キーワード検索を実行。
	// それだけでは、通常エンターを押下したときの処理である submit
	// が動作する為、returnValue を false (無効化)にする
	if(event.keyCode == 13) {
		window.event.returnValue = false;
		loginInputChk();
	}
}
//ログインID、パスワード入力チェック ---------------------------------
//ログインボタンを押したときに実行
function loginInputChk(){
    var strCheckFlag = 0;

    var strID = document.InputPage.tx_login_id.value;
    var strPassword = document.InputPage.tx_passwd.value;
    var strSecureFlag = document.InputPage.secure.checked;
    //修正 Rev.03
    //var strAutoLoginFlag = document.InputPage.secure.checked;
    var strAutoLoginFlag = document.InputPage.alogin.checked;

    //デバッグ用
    //alert("[" + strID + "]");
    //alert("[" + strPassword + "]");
    //alert("[" + strSecureFlag + "]");
    //alert("[" + strAutoLoginFlag + "]");

    //ログインIDの入力チェック
    if(strID == "") {
        //return false;
        strCheckFlag += 1;

    //ログインID入力時、ログインIDを保存
    } else {
        //setCookie(クッキー名, 値)
        setCookie("STAFF_ID", strID);
    }

    //パスワードの入力チェック
    if(strPassword == "") {
        strCheckFlag += 2;

    //パスワード入力時
    } else {
        //自動ログインにチェックしている場合、パスワードを保存
        if(strAutoLoginFlag) {
            //setCookie(クッキー名, 値)
            setCookie("STAFF_PS", strPassword);
        }
    }

    //ログインID、パスワードが入力されていればログイン処理を実行
    if(strCheckFlag == 0) {
        //セキュリティONの場合、strSecureFlag = true
        goLogin(strSecureFlag);
    }else if(strCheckFlag == 1) {
        alert("恐れ入りますが、ログインID(メールアドレス)をご入力ください");
        document.InputPage.tx_login_id.focus();
    } else if(strCheckFlag == 2) {
        alert("恐れ入りますが、パスワードをご入力ください");
        document.InputPage.tx_passwd.focus();
    } else if(strCheckFlag == 3) {
        alert("恐れ入りますが、ログインID(メールアドレス)、\nおよびパスワードをご入力ください");
        document.InputPage.tx_login_id.focus();
    }
}




//ログイン -----------------------------------------------------------
function goLogin(flag){
    document.InputPage.SID.value = "SID20000";
    document.InputPage.CHAINSID.value = "SID20001";

    if(flag){
        document.InputPage.action = 'https://www.val.ne.jp/servlets/stafflogin';
        document.InputPage.submit();
    }else{
        document.InputPage.action = 'http://www.val.ne.jp/servlets/stafflogin';
        document.InputPage.submit();
    }

}








//セキュリティONチェック保存 -----------------------------------------
function saveSecureON() {
    if(document.InputPage.secure.checked == true) {
        temp = 1;
        setCookie("ST_S_CHK", temp);
    }else if(document.InputPage.secure.checked == false) {
        temp = 0;
        setCookie("ST_S_CHK", temp);
    }
}




//自動ログインチェック保存 -------------------------------------------
function saveAutoLogin() {
    if(document.InputPage.alogin.checked == true) {
        temp = 1;
        setCookie("ST_A_CHK", temp);
    }else if(document.InputPage.alogin.checked == false) {
        temp = 0;
        setCookie("ST_A_CHK", temp);
    }
}




//--------------------------------------------------------------------
//ポップアップウィンドウ用スクリプト
//--------------------------------------------------------------------

function miniWin(url,w,h){
	winnm = "cpChangeWin_" + Math.round(Math.random() * 1000);
	window.open(url,winnm,'scrollbars=yes,width='+w+',height='+h);
}


//ニューウィンドウ表示用関数 -----------------------------------------
function win1(html) { 
  var w1;
  w1 = window.open(html,"www1","");
  w1.focus();
  w1.resizeTo(850,600); 
}

function win2(html) { 
  var w2;
  w2 = window.open(html,"www2","");
  w2.focus();
  w2.resizeTo(850,600); 
}

function win3(html) { 
  var w3;
  w3 = window.open(html,"www3","");
  w3.focus();
  w3.resizeTo(850,600); 
}

function win4(html) { 
  var w4;
  w4 = window.open(html,"www4","");
  w4.focus();
}

function win5(html) { 
  var w5;
  w5 = window.open(html,"www5","");
  w5.focus();
  w5.resizeTo(850,600); 
}



//--------------------------------------------------------------------

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}