//checks if all the controls contain valid data
function testEnquiry(form)
{
	if(form.Name.value != null && (form.Name.value == '' || form.Name.value == ' '))
	{	alert('Please enter your name');
		form.Name.focus();
		return false;
	}
	
	if(form.Company.value != null && (form.Company.value == '' || form.Company.value == ' '))
	{	alert('Please enter your Company name');
		form.Company.focus();
		return false;
	}
	
	if(form.Telephone.value != null && (form.Telephone.value == '' || form.Telephone.value == ' '))
	{	alert('Please enter your Telephone number');
		form.Telephone.focus();
		return false;
	}
	if(isTelephone(form.Telephone.value) == false)
	{
		//alert('Please enter valid Telephone number');
		form.Telephone.focus();
		return false;
	}
	
	if(form.Email.value != null && (form.Email.value == '' || form.Email.value == ' '))
	{	alert('Please enter your Email Id');
		form.Email.focus();
		return false;
	}
	if(isEmail(form.Email.value) == false)
	{
		alert('Please enter valid Email Id');
		form.Email.focus();
		return false;
	}
	
	if(form.Subject[0].selected == true)
	{	alert('Please select other enquiry subject');
		form.Subject.focus();
		return false;
	}
	return true;	
}

// Return true if value is an e-mail address
//not same as the one present in javascript.js
function isEmail(value) {
	//only commma can seperate all email addresses
	invalidChars = " /:;,";
	if (value=="") return false;
	
	for (i=0; i<invalidChars.length;i++) {
	   badChar = invalidChars.charAt(i);
	   if (value.indexOf(badChar,0) != -1) return false;
	}
	
	atPos = value.indexOf("@", 1);
	if (atPos == -1) return false;
	if (value.indexOf("@", atPos + 1) != -1) return false;
	
	periodPos = value.indexOf(".", atPos);
	if (periodPos == -1) return false;
	
	if (periodPos+3 > value.length) return false;

	return true;
}

//checks if a valid telephone number has been entered
function isTelephone(tno)
{	
	//alert(tno);
	if (tno == null || tno == "")
	{   alert('Please input valid Number');
		return false;
	}
	//only allow below characters & numbers
	allowedchar = new String('+-0123456789');
	ispresent = new Boolean(false);
	for(j=0; j < tno.length; j++)
	{
		k = 0;
		//alert('to compare characters');
		while(k < allowedchar.length)
		{
			ispresent = false;
			//alert("char is " + tno.charAt(j) + " allow " + allowedchar.charAt(k));
			t = tno.charAt(j);
			ac =  allowedchar.charAt(k);
			if(t == ac)
			{   //alert('successatlast'); 
				ispresent = true; 
				break; 
			}
			k++;			
		}
		if(ispresent == false)
		{
			//alert("char <>  " + tno.charAt(j));
			break;
		}
	}
	if(ispresent == false)
	{
		alert('Please enter proper Telephone number');
		return false;
	}	
	return true;
 }