function checkEmail()
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.form1.txtEmail.value))
	{
		return (true);
	} 
	
}

function isValidEmail(str) {
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
 
}

function validate_num(){
	var digits="0123456789-";
	var temp;

	for (var i=0;i<document.form1.txtPhone_c.value.length;i++){
		temp=document.form1.txtPhone_c.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("无效电话国家编码 / Invalid Phone Country Number !");
			return (false);
	      	}
	}
	
	for (var i=0;i<document.form1.txtPhone_n.value.length;i++){
		temp=document.form1.txtPhone_n.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("无效电话号码/ Invalid Phone Number !");
			return (false);
	      	}
	}
	
	for (var i=0;i<document.form1.txtFax_c.value.length;i++){
		temp=document.form1.txtFax_c.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("无效FAX国家编码 / Invalid FAX Country Number !");
			return (false);
	      	}
	}
	   
	for (var i=0;i<document.form1.txtFax_n.value.length;i++){
		temp=document.form1.txtFax_n.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("无效FAX号码 / Invalid Fax Number !");
			return (false);
	      	}
	} 
   
	return (true);
}

function CheckRadio(ThisRadio) {
	selected = false;
	for (i=0; i<ThisRadio.length; i++) {
		if (ThisRadio[i].checked)
			selected = true;
	}
	return selected;
}

function CheckQuestion(i, NoOfQuestion) {
	//NoOfQuestion
	ThisChecked = false;
	k = i+NoOfQuestion;
	for (i=i; i<k; i++) {
		if (document.form1.elements[i].checked) {
			ThisChecked = true;
		}
	}
	return ThisChecked;
}


function compulsory(){
	missinginfo = "";
//	if (!CheckRadio(document.form1.salutation)) {
//		missinginfo += "\n     -  称谓 / Title";
//	} 
	if (document.form1.txtFname.value == "") {
		missinginfo += "\n     -  姓名 / Name";
	}
	
//	if (document.form1.txtLname.value == "") {
//		missinginfo += "\n     -  姓 / Last Name";
//	}
	
	if (document.form1.txtCompany.value == "") {
		missinginfo += "\n     -  公司 / Company Name";
	}
	
	if (document.form1.txtJobTitle.value == "") {
		missinginfo += "\n     -  职位 / Job Title";
	}

	if (document.form1.txtAddress1.value == "") {
		missinginfo += "\n     -  地址 / Address";
	}
	
//	if (document.form1.txtCity.value == "") {
//		missinginfo += "\n     -  城市 / City";
//	}
	
//	if (document.form1.txtPostal.value == "") {
//		missinginfo += "\n     -  邮编 / Postcode";
//	}
	
 	if (document.form1.txtCountry.value == "0") {
 		missinginfo += "\n     -  国家地区 / Country Region";
 	}
	
	if (document.form1.txtPhone_n.value == "" || document.form1.txtPhone_c.value == "") {
		missinginfo += "\n     -  电话号码及国家代码 / Telephone Number with Country Code";
	}
	if (document.form1.txtFax_n.value == "" || document.form1.txtFax_c.value == "") {
		missinginfo += "\n     -  传真号码及国家代码 / Fax Number with Country Code";
	}
		
	if (document.form1.txtEmail.value == "") {
		missinginfo += "\n     -  电邮地址 / Email Address";
	}

	i = 0;

	while (document.form1.elements[i].name != "check101") {
		//alert(document.form1.elements[i].name);
		i++;
	}
	question1 = i;
	
	while (document.form1.elements[i].name != "check201") {
		//alert(document.form1.elements[i].name);
		i++;
	}
	question2 = i;
	
	while (document.form1.elements[i].name != "check401") {
		//alert(document.form1.elements[i].name);
		i++;
	}
	question4 = i;

	
	if (!CheckQuestion(question1, 3)) {
		missinginfo += "\n     -  问题 A / Question A";
	} 
	else {
		if (document.form1.check103.checked && document.form1.txt103.value == "") {
			missinginfo += "\n     -  请填写问题A中的第 3 栏 / Please Specify in Question A Box (3)";
		}
	}

    if (!CheckQuestion(question2, 8)) {
		missinginfo += "\n     -  问题 B / Question B";
	} 
	else {
		if (document.form1.check208.checked && document.form1.txt208.value == "") {
			missinginfo += "\n     -  请填写问题B中的第 8 栏 / Please Specify in Question B Box (8)";
		}
	}
	
	if (!CheckRadio(document.form1.radio3)) {
		missinginfo += "\n     -  问题 C / Question C";
	} 
	else {
		if (document.form1.radio3[5].checked && document.form1.txt306.value == "") {
			missinginfo += "\n     -  请填写问题C中的第 6 栏 / Please Specify in Question C Box (6)";
		}
	}
	
	if (!CheckQuestion(question4, 15)) {
		missinginfo += "\n     -  问题 D / Question D";
	} 
	else {
		if (document.form1.check415.checked && document.form1.txt415.value == "") {
			missinginfo += "\n     -  请填写问题D中的第 15 栏 / Please Specify in Question D Box (15)";
		}
	}
   
	if (missinginfo != "") 
	{
		//alert(missinginfo.substring(0,35));
		//alert(missinginfo.substring(0,17));
		if (missinginfo.substring(0, 35) == "\n     -  请填写问题 / Please Specify in Question" || missinginfo.substring(0, 17) == "\n     -  问题 / Question" ) {			missinginfo ="_____________________________\n" +
			missinginfo + "\n_____________________________________________________" +
			"\n请重新填写并再次提交 / Please re-enter and submit again!";
			}
			else {
			missinginfo ="_____________________________________________________\n" +
			"你没有正确填写以下项目 / You failed to correctly fill in your:\n" +
			missinginfo + "\n_____________________________________________________" +
			"\n请重新填写并再次提交 / Please re-enter and submit again!";
			}
			alert(missinginfo);
			return false;
	}
	
	else{
		//alert("Invalid E-mail Address! Please re-enter.");
	// if(isValidEmail(document.form1.txtEmail.value))	     
	   if (checkEmail())
		{	
		return validate_num();			
		}
	  else{
	  	alert("Invalid E-mail Address! Please re-enter.");
	   	return false;
	     }
	}

}