/* Ver 2.1 by Arrack */
var isclick=0;
function checkForm(formname){
	var errormsg='';
	try{
		var c1=document.getElementById("ischeck1").value;
		if(c1!=""){
		}else{
			errormsg+="尚有錯誤，請確認畫面上紅色字，或是必填項目未填寫\n";
		}		
	} catch (e){
		errormsg+="尚有錯誤，請確認畫面上紅色字，或是必填項目未填寫\n";
	}	
	//checkField(str1,msg,type,str2,notaddstr,minlength,maxlength)
	errormsg+=checkField('customers_email_address','請填寫您的帳號，必須是EMAIL','email','',1);
	errormsg+=checkField('customers_password','兩次輸入的密碼不相同','equal','customers_password2',1);
	errormsg+=checkField('customers_password','密碼長度限制在4-24','','',1,4,24);
	errormsg+=checkField('customers_firstname','姓名未填寫','','',1);
	errormsg+=checkField('customers_twid','身分證號未填寫','','',1);
	t=checkTWID(document.getElementById('customers_twid').value);
	if(t!=''){errormsg+=t;}	
	errormsg+=checkField('customers_gender','性別未選擇','','',1);
	errormsg+=checkField('customers_dob','生日未填寫','','',1);
	errormsg+=checkField('bm','生日月份未選擇','','',1);
	errormsg+=checkField('bd','生日日期未選擇','','',1);
	errormsg+=checkField('entry_postcode','郵遞區號未填寫','','',1);
	errormsg+=checkField('entry_street_address','地址未填寫','','',1);
	errormsg+=checkField('customers_telephone','電話未填寫','','',1);

	if(errormsg==''){
		if(isclick==0){isclick=1;document.getElementById(formname).submit();		
		}else{alert('please wait submit()');isclick=0;}
	}else{alert(errormsg);isclick=0;}
}

function getxmlhttp(){
	var xmlhttp
	if (window.XMLHttpRequest) {xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}}}
	return xmlhttp;
}
function getContents(xmlhttp,msgname) {
	var msg=document.getElementById(msgname);
	if (xmlhttp.readyState == 4) {
		if(xmlhttp.status == 200) {
			//alert(xmlhttp.responseText);
			msg.innerHTML=xmlhttp.responseText;
		} else {
			//alert('error');
		}
	}
}
function AccountCheck() {	
	if(checkField('customers_email_address','格式錯誤','email','',1)!=''){
		a$('msg_customers_email_address').innerHTML='<font style="color:#FF0000">格式錯誤</span>';
		return false;
	}
	var xmlhttp = getxmlhttp();
	var account = document.getElementById("customers_email_address").value;
	if (!xmlhttp) {alert('Error');return false;}
    xmlhttp.onreadystatechange = function() { 
		getContents(xmlhttp,"msg_customers_email_address");
	};
	url = "check.php?kind=1&account=" + encodeURI(account);
    xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}
