// JavaScript Document

/////////////////////////////////////
// 汎用確認メッセージ
/////////////////////////////////////
function ConfirmMsg(msg){
	return (confirm(msg))?true:false;
}

/////////////////////////////////////////////////////////////////////////////////
// 未入力及び不正入力のチェック（※Safariのバグ（エスケープ文字認識）を回避）
/////////////////////////////////////////////////////////////////////////////////
function inputChk(f,confirm_flg){

	var flg = false;
	var error_mes = "Error Message\r\nExcuse me, please confirm the following content.\r\n\r\n";

	if(!f.name.value){
		error_mes += "・Please fill in the Personal Name.\r\n";flg = true;
	}

	if(!f.email.value){
		error_mes += "・Please fill in the E-mail.\r\n";flg = true;
	}
	else if(CheckLength(f.email.value,1)){
		error_mes += "・The em-size character is included in the E-mail.\r\n";flg = true;
	}
	else if(!f.email.value.match(/^[^@]+@[^.]+\..+/)){
		error_mes += "・The mistake is found in the form of E-mail.\r\n";flg = true;
	}

	if(CheckLength(f.tel.value,1)){
		error_mes += "・The em-size character is included in the telephone number.\r\n";flg = true;
	}

	if(!f.comment.value){
		error_mes += "・Please fill in the your inquiry.\r\n";flg = true;
	}
	
	if(flg){
		window.alert(error_mes);return false;
	}
	else{

		// 確認メッセージ
		if(confirm_flg){
			return ConfirmMsg('It transmits by the input content.\nIs it good?');
		}
		return true;
	}


}

function CheckLength(str,flg) { 
    for (var i = 0; i < str.length; i++) { 
        var c = str.charCodeAt(i); 
        // Shift_JIS: 0x0 〜 0x80, 0xa0 , 0xa1 〜 0xdf , 0xfd 〜 0xff 
        // Unicode : 0x0 〜 0x80, 0xf8f0, 0xff61 〜 0xff9f, 0xf8f1 〜 0xf8f3 
        if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) { 
            if(!flg) return true; 
        } else { 
            if(flg) return true; 
        } 
    } 
    return false; 
} 

