//z_jp_test.js --> z_jp_script.jsの変更テストに使用。m_info_test.htmlでcall


//クッキー保存(パラメータ→キーワード、値)
function SetCookie (key_wd,value)
{
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path    = (argc > 3) ? argv[3] : null;
   var domain  = (argc > 4) ? argv[4] : null;
   var secure  = (argc > 5) ? argv[5] : false;

   document.cookie = key_wd + "="  + escape (value) +
    ((expires == null) ? ""		: ("; expires=" + expires.toGMTString())) +
    ((path == null)    ? ""		: ("; path=" + path)) +
    ((domain == null)  ? "" 	: ("; domain=" + domain)) +
    ((secure == true)  ? "; secure" : "");
}

// クッキー有効期限（１週間とする）
function set_data(key_wd,put_data)
{
   var expdate = new Date ();
   expdate.setDate(expdate.getDate() + 7);//１週間
       //expdate.setDate(expdate.getDate( ) + 50); // 「50日後」に設定する場合
       //expdate.setMonth(expdate.getMonth( ) + 6); // 「6か月後」に設定する場合
       //expdate.setFullYear(expdate.getFullYear( ) + 10); // 「10年後」に設定する場合
   SetCookie (key_wd,put_data,expdate);
}

//クッキー呼出（パラメータ→キーワード）
function GetCookie (key_wd)
{//指定されたキーワードで保存されてるクッキー値を返す
	var arg  = key_wd + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	//alert("getCookie_key_wd --->"+key_wd);
	//alert("getCookie_alen --->"+alen);
        while (i < clen)
		{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg){
                   //Debug alert("getCookieVal--->"+getCookieVal (j));
		   return getCookieVal (j);}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
		}
	//return null; //IEで「null」という文字が入るので変更
	return '';
}

function getCookieVal (offset)
{
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset,endstr));
}

//資料請求メールフォーム用
function saveValues() {
  // 入力値をクッキーに保存する。このページ終了時に実行
  set_data("t_name", document.forms[0].名前.value);
  set_data("t_name_kana", document.forms[0].ふりがな.value);
  set_data("t_age",  document.forms[0].年令.value);
  set_data("t_yuubin", document.forms[0].郵便番号.value);
  set_data("t_pref", document.forms[0].都道府県.value);
  set_data("t_add", document.forms[0].住所.value);
  set_data("t_comp", document.forms[0].会社名.value);
  set_data("t_sec", document.forms[0].部課名.value);
  set_data("t_tel", document.forms[0].ＴＥＬ.value);
  set_data("t_fax", document.forms[0].ＦＡＸ.value);
  set_data("t_type_gyou", document.forms[0].業種.value);
  set_data("t_type_syoku", document.forms[0].職種.value);
  set_data("t_email", document.forms[0].email.value);
  set_data("t_url", document.forms[0].ＵＲＬ.value);
  //性別はラジオボタンなので別記
  if (document.forms[0].性別[0].checked == true){
     set_data("rb_sei", "0");
  } else if (document.forms[0].性別[1].checked == true){
     set_data("rb_sei", "1");
  }
  //debug表示 alert(unescape(document.cookie));
}

//資料請求メールフォーム用
function displayValues() {
   //クッキー無効になってる場合は警告表示。以降、スクリプト続行
   if (!navigator.cookieEnabled) alert("クッキーが書込不可となっております。入力値の再現は出来ません。");

  //クッキーに保存されてる値とフォームに表示。ページロード時に実行
  if(document.cookie != ""){
    var form = document.forms[0];
    form.名前.value = (GetCookie("t_name"));
    form.ふりがな.value = (GetCookie("t_name_kana"));
    form.年令.value  = (GetCookie("t_age"));
    form.郵便番号.value  = (GetCookie("t_yuubin"));
    form.住所.value = (GetCookie("t_add"));
    form.会社名.value = (GetCookie("t_comp"));
    form.部課名.value = (GetCookie("t_sec"));
    form.ＴＥＬ.value = (GetCookie("t_tel"));
    form.ＦＡＸ.value = (GetCookie("t_fax"));
    form.業種.value = (GetCookie("t_type_gyou"));
    form.職種.value = (GetCookie("t_type_syoku"));
    form.email.value = (GetCookie("t_email"));
    form.ＵＲＬ.value = (GetCookie("t_url"));

    //都道府県はselect項目のため下記で指定
	form.elements["都道府県"].value = (GetCookie("t_pref"));

    //性別はクッキーの値により、ラジオボタンを選択する
    var flg_sei = (GetCookie("rb_sei"));
    if (flg_sei == "0") {
       form.性別[0].checked = true;
    } else if (flg_sei == "1") {
       form.性別[1].checked = true;
    }
  }
//debug表示 alert("DisplayValues実行");  
}

