﻿// JavaScript Document

var mailAddress;
var page;
var to;

/* オンロード時に実行 */
window.onload=getdata;

function getdata(){
    if(window.location.search){
        /* URLの「?」以降のパラメータを変数nに代入 */
        var n=window.location.search.substring(1,window.location.search.length);
        var val=window.location.search.substring(1,window.location.search.length);
        var prm = getParameter(val);
        setParameter(prm);
        
        getReferrer();
            
        // デフォルト問合先設定
　　    for (i=0;i< document.sendMailForm.inquiry.length ;i++) {

            if ( document.sendMailForm.inquiry[i].value == to ){
                document.sendMailForm.inquiry[i].checked = true;
                break;
            }    　　        
        }

    }
}

// Referrerを取得
function getReferrer(){
    var path = document.referrer;
    
    page = path.substring(path.lastIndexOf ('/',path.length) +1,path.length);

}

// Query String から 配列を返す
function getParameter(str){
  var dec = decodeURIComponent;
  var par = new Array, itm;
  if(typeof(str) == 'undefined') return par;
  if(str.indexOf('?', 0) > -1) str = str.split('?')[1];
  str = str.split('&');
  for(var i = 0; str.length > i; i++){
    itm = str[i].split("=");
    if(itm[0] != ''){
      par[itm[0]] = typeof(itm[1]) == 'undefined' ? true : dec(itm[1]);
    }
  }
  return par;
}
// 配列 から Query Stringを返す
function setParameter(par){
  var enc = encodeURIComponent;
  var str = '', amp = '';
  if(!par) return '';
  
  //// 問合元ページ
  //page = par["pg"];
  
  // デフォルト問合先
  to = par["to"];
    
  return;
}

//問い合わせメールを送信
function SendMail()
{
	var errormessage = "";
	
	// 会社名（学校名）
	if(document.getElementById('ComName').value.length==0)
	{
		errormessage += "会社名（学校名）を入力して下さい。\n";
		document.getElementById('ComName').focus();
	}
		
	// お名前
	if(document.getElementById('Name').value.length==0)
	{
		errormessage += "お名前を入力して下さい。\n";
		document.getElementById('Name').focus();
	}
		
	// メールアドレス
	if(document.getElementById('Mail_1').value.length==0)
	{
		errormessage += "メールアドレスを入力して下さい。\n";
		document.getElementById('Mail_1').focus();
	}
		
	// メールアドレス（確認）
	if(document.getElementById('Mail_2').value.length==0)
	{
		errormessage += "メールアドレス（確認）を入力して下さい。\n";
		document.getElementById('Mail_2').focus();
	}
		
	// メールアドレスとメールアドレス（確認）のチェック
	if( document.getElementById('Mail_1').value != document.getElementById('Mail_2').value )
	{
		errormessage += "メールアドレスとメールアドレス（確認）の内容が異なります。\n";
		document.getElementById('Mail_1').focus();
	}		
		
	// 電話番号
	if(document.getElementById('Tel_1').value.length==0 || document.getElementById('Tel_2').value.length==0 || document.getElementById('Tel_3').value.length==0)
	{
		errormessage += "電話番号を入力して下さい。\n";
		document.getElementById('Tel_1').focus();
	}
		
	// 問合せ先
	
	
	// 問合せ内容
	if(document.getElementById('Comment').value.length==0)
	{
		errormessage += "お問合せ内容を入力して下さい。\n";
		document.getElementById('Comment').focus();
	}	
	

	//入力チェックに一つでも引っかかったらアラート出して終了
	if(errormessage.length > 0){
		alert(errormessage);
		return false;
	}
	
	// 問い合わせ先ｱﾄﾞﾚｽを取得
　　for (i=0;i< document.sendMailForm.inquiry.length ;i++) {
　　    frag = document.sendMailForm.inquiry[i].checked;
　　    if (frag) {
　　        value = document.sendMailForm.inquiry[i].value;        
　　        break;
　　    }
    }
    
	document.getElementById('RedirectURL_').value=document.location.href;
	document.getElementById('RedirectFile_').value="mail_finish.html";
	document.getElementById('sendMailForm').method="post";
	document.getElementById('sendMailForm').action="http://www.e-benrida.net/SendMail/Yuken_Contact.ashx?culture=ja-JP&pg=" + page + "&id=" + value;
	document.getElementById('sendMailForm').submit();

	return true;
		
}

