function checkEmail()
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.form1.email.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.tel_c.value.length;i++){
		temp=document.form1.tel_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.tel_n.value.length;i++){
		temp=document.form1.tel_n.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("Invalid Phone Number !");
			return (false);
	      	}
	}
	
	for (var i=0;i<document.form1.fax_c.value.length;i++){
		temp=document.form1.fax_c.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("Invalid FAX Country Number !");
			return (false);
	      	}
	}
	   
	for (var i=0;i<document.form1.fax_n.value.length;i++){
		temp=document.form1.fax_n.value.substring(i,i+1);
		if (digits.indexOf(temp)==-1){
			alert("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_index() {
	missinginfo = "";
	if (document.form1.firstname.value == "") {
		missinginfo += "\n     -  First Name";
	}
	if (document.form1.lastname.value == "") {
		missinginfo += "\n     -  Last Name";
	}
	if (document.form1.email.value == "") {
		missinginfo += "\n     -  Email";
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________________________________\n" +
			"You failed to correctly fill in your:\n" +
			missinginfo + "\n_____________________________________________________" +
			"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	} else {
		if (checkEmail()) {	
			return true;			
		} else {
		  	alert("Invalid E-mail Address! Please re-enter.");
		   	return false;
		}
	}
}

function compulsory(noQuestion){
	missinginfo = "";
	if (!CheckRadio(document.form1.salutation)) {
		missinginfo += "\n     -  Salutation";
	} 
	
	if (document.form1.company.value == "") {
		missinginfo += "\n     -  Company Name";
	}
	
	if (document.form1.job_title.value == "") {
		missinginfo += "\n     -  Job Title";
	}

	if (document.form1.address1.value == "") {
		missinginfo += "\n     -  Address";
	}
	
	if (document.form1.city.value == "") {
		missinginfo += "\n     -  City";
	}
	
	if (document.form1.zip.value == "") {
		missinginfo += "\n     -  Zip Code";
	}
	
 	if (document.form1.country.value == "0") {
 		missinginfo += "\n     -  Country";
 	}
	
	if (document.form1.tel_c.value == "" || document.form1.tel_n.value == "") {
		missinginfo += "\n     -  Telephone Number with Country Code";
	}
	if (document.form1.fax_c.value == "" || document.form1.fax_n.value == "") {
		missinginfo += "\n     -  Fax Number with Country Code";
	}
	if(!arguments[0]) // for no question
	{
			i = 0;
		/*
			while (document.form1.elements[i].name != "product_category_01") {
				i++;
			}
			product_category = i;
		
			while (document.form1.elements[i].name != "business_nature_01") {
				i++;
			}
			business_nature = i;
		
			while (document.form1.elements[i].name != "q2_01") {
				i++;
			}
			question2 = i;
		*/
			while (document.form1.elements[i].name != "q3_01") {
				i++;
			}
			question3 = i;
		
			while (document.form1.elements[i].name != "q4_01") {
				i++;
			}
			question4 = i;
		
			/*
			if (!CheckQuestion(product_category, 8)) {
				missinginfo += "\n     -  Product Category";
			} else {
				if (document.form1.product_category_08.checked && document.form1.product_category_08_other.value == "") {
					missinginfo += "\n     -  Please Specify in Product Category - Others";
				}
			}
		
			if (!CheckQuestion(business_nature, 8)) {
				missinginfo += "\n     -  Business Nature";
			} else {
				if (document.form1.business_nature_08.checked && document.form1.business_nature_08_other.value == "") {
					missinginfo += "\n     -  Please Specify in Business Nature - Others";
				}
			}
		*/
			if (!CheckRadio(document.form1.q1)) {
				missinginfo += "\n     -  Question 1";
			} else {
				if (document.form1.q1_44.checked && document.form1.q1_other.value == "") {
					missinginfo += "\n     -  Please Specify Question 1 Business Type - Others";
				}
			}
		
			if (!CheckRadio(document.form1.q2)) {
				missinginfo += "\n     -  Question 2";
			}
		
			if (!CheckRadio(document.form1.q3)) {
				missinginfo += "\n     -  Question 3";
			} 
			
			if (document.form1.q3[0].checked) {
				if (!CheckQuestion(question3, 12)) {
					missinginfo += "\n     - Question 3";
				}	 
			}
		
			if (!CheckQuestion(question4, 7)) {
				missinginfo += "\n     -  Question 4";
			} else {
				if (document.form1.q4_07.checked && document.form1.q4_07_other.value == "") {
					missinginfo += "\n     -  Please Specify in Question 4 - Others";
				}
			}
		
			if (!CheckRadio(document.form1.q5)) {
				missinginfo += "\n     -  Question 5";
			} else {
				if (document.form1.q5[1].checked && document.form1.q5_yes.value == "") {
					missinginfo += "\n     -  Please Specify in Question 5 - Times";
				}
			}
		  
		  if (!CheckRadio(document.form1.q6)) {
				missinginfo += "\n     -  Question 6";
			}
	}
	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" +
			"You failed to correctly fill in your:\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{
		return validate_num();			
	}

}