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", "Email Address");
}


function wrapCheck(){
	doCheckMember();
	return false;
}

function checkAll(){

	var eMsg="";
	var isOK=true;

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


	if(document.frm.name.value==""){
		eMsg += "Name as in IC is required<br>";
	}
	
	if(document.frm.eClubName.value==""){
		eMsg += "Name as displayed on e-club card is required<br>";
	}
	
	if(document.frm.national.value==""){
		eMsg += "Nationality is required<br>";
	}else{
		if(document.frm.national.value=="M"){
			if(document.frm.icno.value==""){
				eMsg += "IC No. is required<br>";
			}
		}else if(document.frm.national.value=="N"){
			if(document.frm.passport.value==""){
				eMsg += "Passport No. is required<br>";
			}
		}
	}
	
	if(document.frm.age.value==""){
		eMsg += "Age is required<br>";
	}

	
	if(document.frm.email.value==""){
		eMsg += "Email Address is required<br>";
	} else {
		/*
		var testresults;
		var str=document.frm.email.value;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (filter.test(str)){
		}else{
			eMsg += "Please input a valid email address!<br>";
		}
		*/
		if(document.getElementById("reqEmail").innerHTML!=""){
			eMsg += document.getElementById("reqEmail").innerHTML + "<br>";
		}
	}
	
	if(document.frm.password.value==""){
		eMsg += "Password is required<br>";
	}
	
	if(document.frm.confirmPassword.value==""){
		eMsg += "Confirm Password is required<br>";
	} else {
		if(document.frm.password.value != document.frm.confirmPassword.value){
			eMsg += "Confirm Password DO NOT MATCH, please input correctly<br>";
		}
	}
	
	if(document.frm.contact.value==""){
		eMsg += "Contact Number is required<br>";
	}

	if(document.frm.address.value==""){
		eMsg += "Address is required<br>";
	}
	
	if(document.frm.postcode.value==""){
		eMsg += "Postcode is required<br>";
	}
	
	if(document.frm.country.value==""){
		eMsg += "Country is required<br>";
	}
	if(document.frm.country.value=="MY" && document.frm.state.value==""){
		eMsg += "State is required<br>";
	}
	if(document.frm.profession.value==""){
		eMsg += "Profession is required<br>";
	}
	if(document.frm.income.value==""){
		eMsg += "Annual Income field is required<br>";
	}
	
	if(document.frm.pregnant.value==""){
		eMsg += "Questionaire: Are you pregnant?<br>";
	} else if(document.frm.pregnant.value=="1"){
		if(document.frm.delivery.value==""){
			eMsg += "Expected Delivery field is required<br>";
		}
	}
	
	
	
	if(document.frm.children.value==""){
		eMsg += "Questionaire: How many children you have below 6 years old?<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 += "1st Child D.O.B is required<br>";
			} else if(i=="1" && document.getElementById('child' + i).value==""){
				eMsg += "2nd Child D.O.B is required<br>";
			} else if(i=="2" && document.getElementById('child' + i).value==""){
				eMsg += "3rd Child D.O.B is required<br>";
			} else {
				if(document.getElementById('child' + i).value==""){
					eMsg += (i+1) + "th Child D.O.B is required<br>";
				}
			}
		}
	}
	
	if(document.frm.pregnant.value=="1" && document.frm.hospital.value==""){
		eMsg += "Questionaire: Which hospital have you planned for your delivery?<br>";
	}

	if(!document.frm.chkAgree.checked){
		eMsg += "You must read and agree to the terms below.<br />";	
	}	

	if(eMsg !=""){
		eMsg = "<b>The following field information is required:</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 + " is required";
	}else{
		f.className="normal";
		document.getElementById(msg).innerHTML = n + " is filled";
	}

}
