﻿function mask(str,textbox,loc,delim){
var locs = loc.split(',');

for (var i = 0; i <= locs.length; i++){
	for (var k = 0; k <= str.length; k++){
	 if (k == locs[i]){
	  if (str.substring(k, k+1) != delim){
	    str = str.substring(0,k) + delim + str.substring(k,str.length)
	  }
	 }
	}
 }
textbox.value = str
}


function validAll(){
	document.frm.reset();
	validField(document.frm.email, "reqEmail", "电子邮件");
}

function wrapCheck(){
	doCheckMember();
	//alert("chk");	
	return false;
	
}

function checkAll(){

	var eMsg="";
	var isOK=true;

		  document.frm.btnSubmit.value="提交";
		  document.frm.btnSubmit.disabled=false;
		document.getElementById("reqNote").innerHTML="";


	if(document.frm.name.value==""){
		eMsg += "姓名 (如显示于身份证)必填项目<br>";
	}
	
	if(document.frm.eClubName.value==""){
		eMsg += " e-club card 显示姓名必填项目<br>";
	}
	
	if(document.frm.national.value==""){
		eMsg += "国籍必填项目<br>";
	}else{
		if(document.frm.national.value=="M"){
			if(document.frm.icno.value==""){
				eMsg += "身份证必填项目<br>";
			}
		}else if(document.frm.national.value=="N"){
			if(document.frm.passport.value==""){
				eMsg += "护照编号必填项目<br>";
			}
		}
	}
	
	if(document.frm.age.value==""){
		eMsg += "年龄必填项目<br>";
	}

	
	if(document.frm.email.value==""){
		eMsg += "电邮地址(用户名)必填项目<br>";
	} else {
		//doCheckMember();
		//alert("chk");
		if(document.getElementById("reqEmail").innerHTML!=""){
			eMsg += document.getElementById("reqEmail").innerHTML + "<br>";
		}
	}
	
	if(document.frm.password.value==""){
		eMsg += "密码必填项目<br>";
	}
	
	if(document.frm.confirmPassword.value==""){
		eMsg += "证实密码必填项目<br>";
	} else {
		if(document.frm.password.value != document.frm.confirmPassword.value){
			eMsg += "证实密码不匹配，请恰当地输入<br>";
		}
	}
	
	if(document.frm.contact.value==""){
		eMsg += "联络电话必填项目<br>";
	}

	if(document.frm.address.value==""){
		eMsg += "地址必填项目<br>";
	}
	
	if(document.frm.postcode.value==""){
		eMsg += "邮区编号必填项目<br>";
	}
	
	if(document.frm.country.value==""){
		eMsg += "国家必填项目<br>";
	}
	if(document.frm.country.value=="MY" && document.frm.state.value==""){
		eMsg += "州属必填项目<br>";
	}
	if(document.frm.profession.value==""){
		eMsg += "职业必填项目<br>";
	}
	if(document.frm.income.value==""){
		eMsg += "年收入必填项目<br>";
	}
	
	if(document.frm.pregnant.value==""){
		eMsg += "家庭状况: 您是否正在怀孕？<br>";
	} else if(document.frm.pregnant.value=="1"){
		if(document.frm.delivery.value==""){
			eMsg += "预产期必填项目<br>";
		}
	}
	
	
	
	if(document.frm.children.value==""){
		eMsg += "家庭状况: 您有多少位6岁以内的宝宝?<br>";
	} else {
		var num = document.frm.children.value;
		for(var i=0;i<parseInt(num);i++){
			if(i=="0" && document.getElementById('child' + i).value==""){
				eMsg += "第一个孩子出生日期必填项目<br>";
			} else if(i=="1" && document.getElementById('child' + i).value==""){
				eMsg += "第二个孩子出生日期必填项目<br>";
			} else if(i=="2" && document.getElementById('child' + i).value==""){
				eMsg += "第三个孩子出生日期必填项目<br>";
			} else if(i=="3" && document.getElementById('child' + i).value==""){
				eMsg += "第四个孩子出生日期必填项目<br>";
			} else if(i=="4" && document.getElementById('child' + i).value==""){
				eMsg += "第五个孩子出生日期必填项目<br>";
			} else if(i=="5" && document.getElementById('child' + i).value==""){
				eMsg += "第六个孩子出生日期必填项目<br>";
			}
		}
	}
	
	if(document.frm.pregnant.value=="1" && document.frm.hospital.value==""){
		eMsg += "家庭状况: 您打算在哪一所医院分娩？<br>";
	}

	if(eMsg !=""){
		eMsg = "<b>以下项目必填:</b><br>" + eMsg;
		//goto top
		isOK = false;


if(document.getElementById('abox')!=null){
document.getElementById('ibox').removeChild(document.getElementById('abox'));	
}

var newdiv = document.createElement('div');
  var divIdName = 'abox';
  newdiv.setAttribute('id','abox');
  newdiv.setAttribute('name','abox');	
  newdiv.setAttribute('class','alert');	
  newdiv.setAttribute('className','alert');	
  newdiv.innerHTML = eMsg;
document.getElementById('ibox').appendChild(newdiv);
document.location.href="#top";
	} else {
	isOK=true;
	if(document.getElementById('abox')!=null){
		document.getElementById('ibox').removeChild(document.getElementById('abox'));
	}

	}
	
	if(isOK==true){
		document.frm.submit();	
	}
	
	return isOK;

}

function validFieldHighlight(f){
	if(f.value==""){
		f.className="man";
	}else{
		f.className="normal";
	}
}

function validFieldHighlightSmall(f){
	if(f.value==""){
		f.className="smallMan";
	}else{
		f.className="smallNormal";
	}
}

function validFieldDropHighlight(f){
	if(f.value==""){
		f.className="dropBoxMan";
	}else{
		f.className="dropBox";
	}
}

function validField(f, msg, n){

	if(f.value==""){
		f.className="man";
		document.getElementById(msg).innerHTML = n + "必填项目";
	}else{
		f.className="normal";
		document.getElementById(msg).innerHTML = n + "被填";
	}

}