//--------------------------------------------------------------------
//関数名：AgreeSubmit
//内容：入会申込書で、同意チェックがクリックされたら送信ボタンをクリック可
//作成日：2009/08/05
//作成者：C.T
//--------------------------------------------------------------------
function AgreeSubmit(){
	if (document.getElementById("agreeChk").checked == true){
		//チェックあり
		document.getElementById("submitBtn").disabled = true;
	}else{
		//チェックなし
		document.getElementById("submitBtn").disabled = false;
	}
}

//--------------------------------------------------------------------
//関数名：ChkInput
//内容：入力チェック
//作成日：2009/08/07
//作成者：C.T
//--------------------------------------------------------------------
function ChkInput(){

	var phone;    //連絡先
	var mail;	  //メール
	var mail2;	  //メール(確認用)
	var birth;    //生年月日
	var birth_y;  //生年月日(年)
	var birth_m;  //生年月日(月)
	var birth_d;  //生年月日(日)
	
	//----名前----
	//未入力チェック
	//姓・名で分かれているかどうかで分岐
	if (document.getElementById("last_name") == null){
		if(document.getElementById("name").value ==""){
			alert("名前を入力してください");
			return false;
		}
	} else {
		if(document.getElementById("last_name").value =="" ||
		   document.getElementById("first_name").value ==""){
			alert("名前を入力してください");
			return false;
		}
	}

	//----連絡先----
	//形式チェック
	phone = document.getElementById("phone").value;
	if (phone !="" && !(phone.match(/^[0-9]+\-[0-9]+\-[0-9]+$/))) {
		alert("連絡先は正しく入力してください。");
        return false;
      }

	//----メール----
	mail  = document.getElementById("email").value;
	mail2 = document.getElementById("email2").value;
	//形式チェック
	if (mail !="" && !(mail.match("^[0-9A-Za-z._]+@[0-9A-Za-z.]+.[0-9A-Za-z]$"))){
		alert("メールアドレスは正しく入力してください。");
		return false;
	}
	
	//確認用差異チェック
	if (mail != mail2){
		alert("ご確認用とメールアドレスが違います。");
		return false;
	}

	//----生年月日----
	if (document.getElementById("00N80000003tCt6") != null){
		birth = document.getElementById("00N80000003tCt6").value;

		// 正規表現による書式チェック 
	    if(!birth.match(/^\d{4}\/\d{2}\/\d{2}$/)){
	    	alert("生年月日は正しく入力してください。");
	        return false; 
	    } 
	    birth_y = birth.substr(0, 4) - 0; 
	    birth_m = birth.substr(5, 2) - 1; // Javascriptは、0-11で表現 
	    birth_d = birth.substr(8, 2) - 0; 
	    // 月,日の妥当性チェック
	    if(birth_m >= 0 && birth_m <= 11 && birth_d >= 1 && birth_d <= 31){
	        var vDt = new Date(birth_y, birth_m, birth_d); 
	    	if((isNaN(vDt)) || !(vDt.getFullYear() == birth_y && vDt.getMonth() == birth_m && vDt.getDate() == birth_d)){
				alert("生年月日は正しく入力してください。");
				return false; 
	        } 
	    }else{ 
	    	alert("生年月日は正しく入力してください。");
	        return false; 
	    }
	}

	//----郵便番号----
	if (document.getElementById("zip") != null){
		zip = document.getElementById("zip").value;
		if (zip !="" && !(zip.match(/^[0-9]+\-[0-9]+$/))) {
			alert("郵便番号は正しく入力してください。");
	        return false;
		}
	}

}

//--------------------------------------------------------------------
//関数名：4桁自動採番
//内容：自動採番
//作成日：2009/08/31
//作成者：T.Y
//--------------------------------------------------------------------
function SetFourFigures(n){
   var CODE_TABLE = "0123456789";
   var r = "";
   for (var i = 0, k = CODE_TABLE.length; i < n; i++)
       r += CODE_TABLE.charAt(Math.floor(k * Math.random()));
   document.getElementById("00N10000000j1AF").value = r;
}



