//価格切り替え
function kakaku_kirikae(str){
	str=str-0;
	if(str==1){
		document.getElementById("non_u1").style.display = "";
		document.getElementById("non_u2").style.display = "";
		document.getElementById("non_u3").style.display = "";
		document.getElementById("non_u4").style.display = "";
		document.getElementById("non_u5").style.display = "";
		document.getElementById("non_u6").style.display = "";
		
		document.getElementById("ari_u1").style.display = "none";
		document.getElementById("ari_u2").style.display = "none";
		document.getElementById("ari_u3").style.display = "none";
		document.getElementById("ari_u4").style.display = "none";
		document.getElementById("ari_u5").style.display = "none";
		document.getElementById("ari_u6").style.display = "none";
		
		document.getElementById("non_s1").style.display = "";
		document.getElementById("non_s2").style.display = "";
		document.getElementById("non_s3").style.display = "";
		document.getElementById("non_s4").style.display = "";
		document.getElementById("non_s5").style.display = "";
		document.getElementById("non_s6").style.display = "";
		
		document.getElementById("ari_s1").style.display = "none";
		document.getElementById("ari_s2").style.display = "none";
		document.getElementById("ari_s3").style.display = "none";
		document.getElementById("ari_s4").style.display = "none";
		document.getElementById("ari_s5").style.display = "none";
		document.getElementById("ari_s6").style.display = "none";
	}else{
		document.getElementById("non_u1").style.display = "none";
		document.getElementById("non_u2").style.display = "none";
		document.getElementById("non_u3").style.display = "none";
		document.getElementById("non_u4").style.display = "none";
		document.getElementById("non_u5").style.display = "none";
		document.getElementById("non_u6").style.display = "none";
		
		document.getElementById("ari_u1").style.display = "";
		document.getElementById("ari_u2").style.display = "";
		document.getElementById("ari_u3").style.display = "";
		document.getElementById("ari_u4").style.display = "";
		document.getElementById("ari_u5").style.display = "";
		document.getElementById("ari_u6").style.display = "";
		
		document.getElementById("non_s1").style.display = "none";
		document.getElementById("non_s2").style.display = "none";
		document.getElementById("non_s3").style.display = "none";
		document.getElementById("non_s4").style.display = "none";
		document.getElementById("non_s5").style.display = "none";
		document.getElementById("non_s6").style.display = "none";
		
		document.getElementById("ari_s1").style.display = "";
		document.getElementById("ari_s2").style.display = "";
		document.getElementById("ari_s3").style.display = "";
		document.getElementById("ari_s4").style.display = "";
		document.getElementById("ari_s5").style.display = "";
		document.getElementById("ari_s6").style.display = "";
	}
}

//シアリス変更
function siarisu_henkou(){
	boxsuu		=(document.fm_smt.siarisu_box.options[document.fm_smt.siarisu_box.selectedIndex].value)-0;
	barasuu		=(document.fm_smt.siarisu_bara.options[document.fm_smt.siarisu_bara.selectedIndex].value)-0;
	boxkingaku	=(document.fm_smt.kari_siarisuboxkakaku.value)-0;
	barakingaku	=(document.fm_smt.kari_siarisubarakakaku.value)-0;
	
	
	karikingaku=boxsuu*boxkingaku + barasuu*barakingaku - 0;
	kingaku=myFormatNumber(karikingaku);
	
	document.getElementById("non_u6").innerHTML='(箱数：'+boxsuu+'箱、バラ数：'+barasuu+'錠)'+kingaku+'円&nbsp;';
	document.getElementById("ari_u6").innerHTML='(箱数：'+boxsuu+'箱、バラ数：'+barasuu+'錠)'+kingaku+'円&nbsp;';
	document.getElementById("non_s6").innerHTML='(箱数：'+boxsuu+'箱、バラ数：'+barasuu+'錠)'+kingaku+'円&nbsp;';
	document.getElementById("ari_s6").innerHTML='(箱数：'+boxsuu+'箱、バラ数：'+barasuu+'錠)'+kingaku+'円&nbsp;';
	
	
	nasi_kei=myFormatNumber((document.fm_smt.karikei_nasi.value - 0) + (karikingaku - 0));
	ari_kei=myFormatNumber((document.fm_smt.karikei_ari.value - 0) + (karikingaku - 0));
	
	document.getElementById("non_u5").innerHTML=(nasi_kei)+'円&nbsp;';
	document.getElementById("ari_u5").innerHTML=(ari_kei)+'円&nbsp;';
	document.getElementById("non_s5").innerHTML=(nasi_kei)+'円&nbsp;';
	document.getElementById("ari_s5").innerHTML=(ari_kei)+'円&nbsp;';
}


//配送日切り替え
function haisoubikirikae(str){
	str=str - 0;
	if(!str){
		document.fm_smt.order_siteibi.disabled='none';
		//document.fm_smt.nen.disabled='none';
		//document.fm_smt.tuki.disabled='none';
		//document.fm_smt.hi.disabled='none';
	}else{
		document.fm_smt.order_siteibi.disabled='';
		//document.fm_smt.nen.disabled='';
		//document.fm_smt.tuki.disabled='';
		//document.fm_smt.hi.disabled='';

	}
}



//サブミットcheck
function submit_ck(){
	ck_msg="【入力エラーです】\n\n";
	
	//メールアドレス
	document.fm_smt.mail.value=z2h_ascii(document.fm_smt.mail.value);
	str=z2h_ascii(document.fm_smt.mail.value);
	if(str=='' || !str){
		ck_msg+="「メールアドレス」を入力してください";
		alert(ck_msg);
		document.fm_smt.mail.focus();
		return false;
	}else{
		if (!str.match(/^[0-9A-Za-z.\-_]+@[0-9A-Za-z\-_]+\.[0-9A-Za-z.\-_]+[A-Za-z]$/)) {
			ck_msg+="「メールアドレス」を確認してください";
			alert(ck_msg);
			document.fm_smt.mail.focus();
			return false;
		}
	}
	
	//メールアドレス確認
	document.fm_smt.mail_sub.value=z2h_ascii(document.fm_smt.mail_sub.value);
	str=z2h_ascii(document.fm_smt.mail_sub.value);
	if(str=='' || !str){
		ck_msg+="「メールアドレス(確認)」を入力してください";
		alert(ck_msg);
		document.fm_smt.mail_sub.focus();
		return false;
	}else{
		if (!str.match(/^[0-9A-Za-z.\-_]+@[0-9A-Za-z\-_]+\.[0-9A-Za-z.\-_]+[A-Za-z]$/)) {
			ck_msg+="「メールアドレス(確認)」を確認してください";
			alert(ck_msg);
			document.fm_smt.mail_sub.focus();
			return false;
		}
	}
	
	//メールアドレスとメールアドレス確認
	if(document.fm_smt.mail.value != document.fm_smt.mail_sub.value){
		ck_msg+="「メールアドレス(確認)」を確認してください";
		alert(ck_msg);
		document.fm_smt.mail_sub.focus();
		return false;
	}
	
	//氏名
	if(!document.fm_smt.name.value){
		ck_msg+="「氏名」を入力してください";
		alert(ck_msg);
		document.fm_smt.name.focus();
		return false;
	}
	
	//ふりがな
	if(!document.fm_smt.kana.value){
		ck_msg+="「ふりがな」を入力してください";
		alert(ck_msg);
		document.fm_smt.kana.focus();
		return false;
	}
	
	//郵便番号
	document.fm_smt.zip.value=z2h_ascii(document.fm_smt.zip.value);
	str=z2h_ascii(document.fm_smt.zip.value);
	if ((str.match(/^[0-9]{7}$/)) || (str.match(/^[0-9]{3}-[0-9]{4}$/))) {
		//ok
	}else{
		ck_msg+="「郵便番号」を確認してください";
		alert(ck_msg);
		document.fm_smt.zip.focus();
		return false;
	}
	
	//都道府県
	if(!document.fm_smt.todoufuken.options[document.fm_smt.todoufuken.selectedIndex].value){
		ck_msg+="「都道府県」を確認してください";
		alert(ck_msg);
		document.fm_smt.todoufuken.focus();
		return false;
	}
	
	//住所
	if(!document.fm_smt.jyuusyo1.value){
		ck_msg+="「住所」を入力してください";
		alert(ck_msg);
		document.fm_smt.jyuusyo1.focus();
		return false;
	}else{
/*
		str=document.fm_smt.jyuusyo1.value + document.fm_smt.jyuusyo2.value;
		if (str.match(/^.{1,}郵便局止.{0,}$/)) {
			ck_msg+="郵便局止めの発送につきましては、申し訳ありませんがお受けすることは出来ません。ご了承下さい。";
			alert(ck_msg);
			document.fm_smt.jyuusyo1.focus();
			return false;
		}
		if (str.match(/^.{1,}郵便局留.{0,}$/)) {
			ck_msg+="郵便局留めの発送につきましては、申し訳ありませんがお受けすることは出来ません。ご了承下さい。";
			alert(ck_msg);
			document.fm_smt.jyuusyo1.focus();
			return false;
		}
*/
	}
	
	//電話番号
	document.fm_smt.tel.value=z2h_ascii(document.fm_smt.tel.value);
	str=document.fm_smt.tel.value;
	str=str.replace("-", "");
	str=str.replace("-", "");
	str=str.replace("-", "");
	if ((str.match(/^0([0-9]{9})$/)) || (str.match(/^0[5987]0([0-9]{8})$/))) {
		//ok
	}else{
		ck_msg+="「電話番号」を確認してください";
		alert(ck_msg);
		document.fm_smt.tel.focus();
		return false;
	}
	
	

	//配送希望日
	if(document.fm_smt.haisoukiboubi[1].checked){
		if(!document.fm_smt.order_siteibi.options[document.fm_smt.order_siteibi.selectedIndex].value){
			ck_msg+="「配送希望日」を確認してください";
			alert(ck_msg);
			document.fm_smt.order_siteibi.focus();
			return false;
		}
	}


}


function z2h_ascii(src) {
    var str = new String;
    var len = src.length;
    for (var i = 0; i < len; i++) {
        var c = src.charCodeAt(i);
        if (c >= 65281 && c <= 65374 && c != 65340) {
            str += String.fromCharCode(c - 65248);
        } else if (c == 8217) {
            str += String.fromCharCode(39);
        } else if (c == 8221) {
            str += String.fromCharCode(34);
        } else if (c == 12288) {
            str += String.fromCharCode(32);
        } else if (c == 65507) {
            str += String.fromCharCode(126);
        } else if (c == 65509) {
            str += String.fromCharCode(92);
        } else {
            str += src.charAt(i);
        } 
    }
    return str;
}

function myFormatNumber(x) { // 引数の例としては 95839285734.3245
    var s = "" + x; // 確実に文字列型に変換する。例では "95839285734.3245"
    var p = s.indexOf("."); // 小数点の位置を0オリジンで求める。例では 11
    if (p < 0) { // 小数点が見つからなかった時
        p = s.length; // 仮想的な小数点の位置とする
    }
    var r = s.substring(p, s.length); // 小数点の桁と小数点より右側の文字列。例では ".3245"
    for (var i = 0; i < p; i++) { // (10 ^ i) の位について
        var c = s.substring(p - 1 - i, p - 1 - i + 1); // (10 ^ i) の位のひとつの桁の数字。例では "4", "3", "7", "5", "8", "2", "9", "3", "8", "5", "9" の順になる。
        if (c < "0" || c > "9") { // 数字以外のもの(符合など)が見つかった
            r = s.substring(0, p - i) + r; // 残りを全部付加する
            break;
        }
        if (i > 0 && i % 3 == 0) { // 3 桁ごと、ただし初回は除く
            r = "," + r; // カンマを付加する
        }
        r = c + r; // 数字を一桁追加する。
    }
    return r; // 例では "95,839,285,734.3245"
}