/**
 * post
 * 
 * @param 	elmName	エレメント名
 * @return	void
 */
function doPost(elmName) {
	
	fm.sid.value = get_sid();


	if(inputCheck()){
		fm.m.value = "shiryoSeikyu";
		fm.action = "https://www.shopfucoidan.com/shopcart/";
		fm.method = "post";
		fm.submit();
	}
}

/**
 * 入力チェック
 * 
 * @param 	none
 * @return	boolean
 */
function inputCheck() 
{
	chkName = "お名前（姓）";
	chkElem = fm.name_sei;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkZenlength(chkElem, 1, 100, chkName)) return false;

	chkName = "お名前（名）";
	chkElem = fm.name_mei;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkZenlength(chkElem, 1, 100, chkName)) return false;

	chkName = "ふりがな（姓）";
	chkElem = fm.name_sei_kana;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkZenlength(chkElem, 1, 100, chkName)) return false;

	chkName = "ふりがな（名）";
	chkElem = fm.name_mei_kana;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkZenlength(chkElem, 1, 100, chkName)) return false;
	
	chkName = "メールアドレス";
	chkElem = fm.EMAIL;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkMail(chkElem, chkName)) return false;
	if (!chkHanlength(chkElem, 5, 100, chkName)) return false;

	chkName = "郵便番号(上3桁)";
	chkElem = fm.yuubin_a;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkNum(chkElem, chkName)) return false;
	if (!chkHanlength(chkElem, 3, 3, chkName)) return false;
	
	chkName = "郵便番号(下4桁)";
	chkElem = fm.yuubin_2;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkNum(chkElem, chkName)) return false;
	if (!chkHanlength(chkElem, 4, 4, chkName)) return false;

	chkName = "都道府県";
	chkElem = fm.kenmei;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkSelect(chkElem, chkName)) return false;

	chkName = "住所";
	chkElem = fm.address;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkZenlength(chkElem, 0, 200, chkName)) return false;

	chkName = "建物名";
	chkElem = fm.tatemonomei;
	if (!chkZenlength(chkElem, 0, 100, chkName)) return false;

	chkName = "電話番号";
	chkElem = fm.tel;
	if (!chkEmpty(chkElem, chkName)) return false;
	if (!chkTel(chkElem, chkName)) return false;
	if (!chkHanlength(chkElem, 10, 20, chkName)) return false;	
	
	chkName = "診断のご病気名";
	chkElem = fm.disease;
	if (!chkZenlength(chkElem, 0, 140, chkName)) return false;
	
	chkName = "ご応募のきっかけ";
	chkElem = fm.opportunity;
	if (!chkZenlength(chkElem, 0, 1000, chkName)) return false;

	return true;
}


/**
 * 送信ＩＤ取得
 * 
 * @param	
 * @return	integer
 */
function get_sid() 
{
	$id = Math.floor(Math.random() * 10000000000);

	var d = new Date();
	var ydmhis  = d.getYear().toString() 
				+ (d.getMonth() + 1).toString()
				+ d.getDate().toString()
				+ d.getHours().toString()
				+ d.getMinutes().toString()
				+ d.getSeconds().toString()

	return ydmhis + "_" + $id;
}
/**
 * 必須チェック
 * 
 * @param	object	elem	対象エレメント
 * @param	string	objname	アラート用名称
 * @return	boolean
 */
function chkEmpty(elem, objname)
{	
	var chktxt = elem.value;
	
	if(!chktxt || chktxt.length <= 0){
		alert(objname + "を入力してください。");
		elem.focus();
		return false;
	}
	return true;
}
/**
 * 全角文字数チェック
 * 
 * @param	object	elem	対象エレメント
 * @param	integer	min		最小文字数
 * @param	integer	max		最大文字数
 * @param	string	objname	アラート用名称
 * @return	boolean
 */
function chkZenlength(elem, min, max, objname)
{	
	var chktxt = elem.value;
	var txtcnt = 0;
	var maxcnt = 1;
	if(max > 1){
		maxcnt = Math.round(max / 2);
	}
	
	if(chktxt.length > 0){
	
		for(i=0;i<chktxt.length;i++){
			//全角
			if(escape(chktxt.charAt(i)).length >= 4){
				txtcnt += 2;
			//半角
			} else {
				txtcnt += 1;
			}
		}
		if(txtcnt < min){
			alert(objname + "を全角" + min + "文字以上で入力してください。");
			elem.select();
			return false;
		}
		if(txtcnt > max){
			alert(objname + "を全角" + maxcnt + "文字以内で入力してください。");
			elem.select();
			return false;
		}
	}
	return true;
}

/**
 * 半角文字数チェック
 * 
 * @param	object	elem	対象エレメント
 * @param	integer	min		最小文字数
 * @param	integer	max		最大文字数
 * @param	string	objname	アラート用名称
 * @return	boolean
 */
function chkHanlength(elem, min, max, objname)
{	
	var chktxt = elem.value;
	var txtcnt = 0;
	
	if(chktxt.length > 0){
	
		for(i=0;i<chktxt.length;i++){
			//全角
			if(escape(chktxt.charAt(i)).length >= 4){
				txtcnt += 2;
			//半角
			} else {
				txtcnt += 1;
			}
		}
		if(txtcnt < min){
			alert(objname + "を半角" + min + "文字以上で入力してください。");
			elem.select();
			return false;
		}
		if(txtcnt > max){
			alert(objname + "を半角" + max + "文字以内で入力してください。");
			elem.select();
			return false;
		}
	}
	return true;
}
/**
 * 数値チェック
 * 
 * @param	object	elem	対象エレメント
 * @param	string	objname	アラート用名称
 * @return	boolean
 */
function chkNum(elem, objname)
{	
	var num = '0123456789'; 
	var tmp = new Array();
	var str = elem.value;
	for(var i=0; i<str.length; i++){
		tmp[i]=str.substring(i,i+1);
		var flag=num.indexOf(tmp[i]);
		if(flag==-1){
			alert(objname + "は数値のみ入力してください。");
			elem.select();
			return false;
		}
	}
	return true;
}

/**
 * オプション選択チェック
 * 
 * @param	object	elem	対象エレメント
 * @param	string	objname	アラート用名称
 * @return	boolean
 */
function chkSelect(elem, objname)
{
	var chkidx = elem.selectedIndex;
	var chkval = elem.value;

	if(chkidx == 0 && chkval == ""){
		alert(objname + "を選択してください。");
		elem.focus();
		return false;
	}
	return true;
}


/**
 * 電話番号チェック
 * 
 * @param	object	elem	対象エレメント
 * @param	string	objname	アラート用名称
 * @return	boolean
 */
function chkTel(elem, objname)
{
	var num = '-0123456789'; 
	var tmp = new Array();
	var str = elem.value;
	for(var i=0; i<str.length; i++){
		tmp[i]=str.substring(i,i+1);
		var flag=num.indexOf(tmp[i]);
		if(flag==-1){
			alert(objname + "は数値とハイフンのみ入力してください。");
			elem.select();
			return false;
		}
	}
	return true;
}



/**
 * メールチェック
 * 
 * @param	object	elem	対象エレメント
 * @param	string	objname	アラート用名称
 * @return	boolean
 */
function chkMail(elem, objname)
{
	var str=elem.value; 
	if (!str.match(/^([0-9A-Za-z]+[._-])*[0-9A-Za-z]+@([0-9a-zA-Z]+[-._]*[0-9a-zA-Z-._]*[.])+[a-zA-Z]{2,6}$/)) {
		alert(objname + "の形式が正しくありません。");
		elem.select();
		return false;
	}
	return true;
}