function getCountryCode(c_name) {
	if (c_name=="HK") {
		document.getElementById("txtPhone_c").value="852";
		document.getElementById("txtMobile_c").value="852";
		document.getElementById("txtFax_c").value="852";

	} else {
		document.getElementById("txtPhone_c").value="";
		document.getElementById("txtMobile_c").value="";
		document.getElementById("txtFax_c").value="";

	}
}

function checkOthers(thisRadio,thisOther) {
	if (thisRadio.checked) {
		thisOther.focus();
	}else{
		thisOther.value = "";
	}
}


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 CountryCode Number !");
			return (false);
	      	}
	}

/*	for (var i=0;i<document.form1.txtPhone_a.value.length;i++){
		temp=document.form1.txtPhone_a.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("Invalid Phone AreaCode Number !");
			return (false);
	      	}
	}
*/	
	for (var i=0;i<document.form1.txtPhone.value.length;i++){
		temp=document.form1.txtPhone.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("Invalid Phone Number !");
			return (false);
	      	}
	}

	for (var i=0;i<document.form1.txtMobile_c.value.length;i++){
		temp=document.form1.txtMobile_c.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("Invalid Mobile CountryCode Number !");
			return (false);
	      	}
	}
	  
/*	for (var i=0;i<document.form1.txtMobile_a.value.length;i++){
		temp=document.form1.txtMobile_a.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("Invalid Mobile AreaCode Number !");
			return (false);
	      	}
	}	  
*/	   
	for (var i=0;i<document.form1.txtMobile.value.length;i++){
		temp=document.form1.txtMobile.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("Invalid Mobile 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.txtSalutation)) {
		missinginfo += "\n     -  Title";
	} 

	if (document.form1.txtFirstName.value == "") {
		missinginfo += "\n     -  First Name";
	}
	
	if (document.form1.txtLastName.value == "") {
		missinginfo += "\n     -  Surname";
	}
	
	if (document.form1.txtJobTitle.value == "") {
		missinginfo += "\n     -  Job Title";
	}

	if (document.form1.txtCompany.value == "") {
		missinginfo += "\n     -  Company Name";
	}

	if (document.form1.txtAddress1.value == "") {
		missinginfo += "\n     -  Address";
	}
	
	if (document.form1.txtCity.value == "") {
		missinginfo += "\n     -  City";
	}
	/*
	if (document.form1.txtZip.value == "") {
		missinginfo += "\n     -  Zip Code/Postal Code";
	}
	*/
 	if (document.form1.txtCountry.value == "0") {
 		missinginfo += "\n     -  Country Region";
 	}
	
	if (document.form1.txtPhone.value == "") {
		missinginfo += "\n     -  Telephone Number";
	}
//	if (document.form1.txtPhone_c.value == "") {
//		missinginfo += "\n     -  Telephone Number with Country Code";
//	}
	if (document.form1.txtEmail.value == "") {
		missinginfo += "\n     -  Email Address";
	}

	i = 0;


	
	if (!CheckRadio(document.form1.txtQ1)) {
		missinginfo += "\n     -  Question 1";
	}
	
	if (!CheckRadio(document.form1.txtQ2)) {
		missinginfo += "\n     -  Question 2";
	} 
	else {
		if (document.form1.txtQ2[1].checked && document.form1.txtQ2Other.value == "") {
			missinginfo += "\n     -  Please Specify in Question 2";
		}
	}	
	

	while (document.form1.elements[i].name != "check301") {
		//alert(document.form1.elements[i].name);
		i++;
	}
	question3 = i;	
	
	if (!CheckQuestion(question3, 19)) {
		missinginfo += "\n     -  Question 3";
	} 
	else {
		if (document.form1.check319.checked && document.form1.txtQ3Other.value == "") {
			missinginfo += "\n     -  Please Specify in Question 3";
		}
	}	
	
	if (!CheckRadio(document.form1.txtQ4)) {
		missinginfo += "\n     -  Question 4";
	} 
	else {
		if (document.form1.txtQ4[16].checked && document.form1.txtQ4Other.value == "") {
			missinginfo += "\n     -  Please Specify in Question 4";
		}
	}

	while (document.form1.elements[i].name != "check501") {
		//alert(document.form1.elements[i].name);
		i++;
	}
	question5 = i;	
	if (!CheckQuestion(question5, 15)) {
		missinginfo += "\n     -  Question 5";
	} 
	
	else {
		if (document.form1.check515.checked && document.form1.txtQ5Other.value == "") {
			missinginfo += "\n     -  Please Specify in Question 5";
		}
	}		
/*
	if (!CheckRadio(document.form1.txtQ2)) {
		missinginfo += "\n     -  Question 2";
	} 
	else {
		if (document.form1.txtQ2[7].checked && document.form1.txtManager.value == "") {
			missinginfo += "\n     -  Please Specify in Question 2 Box (8) Manager";
		}
		if (document.form1.txtQ2[15].checked && document.form1.txtQ2Other.value == "") {
			missinginfo += "\n     -  Please Specify in Question 2 Box (16)";
		}
	}
	
   */

	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_____________________________________________________" +
			"\nPlease re-enter and submit again!";
			}
			else {
			missinginfo ="_____________________________________________________\n" +
			"You failed to correctly fill in your:\n" +
			missinginfo + "\n_____________________________________________________" +
			"\nPlease 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;
	     }
	}

}