// JavaScript Document
function echeck(str) 
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true 					
}

function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < document.forms[0].regarding.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (document.forms[0].regarding[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
// If there were no selections made display an alert box 

return (false);
}
return (true);
}

function check_telephone(userText)
{
var reIntegers = /^[0-9.]*$/;
if(userText.match(reIntegers)==null)
{
	alert('Not a valid telephone number');
	return false ;
}

}


function checkForm()
{
var telephoneID = document.forms[0].telephone ;
if(document.forms[0].email.value == "" && document.forms[0].telephone.value == "")
{
	alert('Please supply either a valid email or telephone number') ;
	document.forms[0].email.focus() ;
	return false ;
	
}
else if (check_telephone(telephoneID.value) == false)
{
	telephoneID.value="" ;
	telephoneID.focus();
	return false ;
}
else if (document.forms[0].email.value != "")
{
var emailID=document.forms[0].email ;
if (echeck(emailID.value)==false)
{
		emailID.value=""
		emailID.focus()
		return false ;
}
else if (check_telephone(telephoneID.value) == false)
{
	telephoneID.value="" ;
	telephoneID.focus();
	return false ;
}
else if(radio_button_checker()==false)
{
	alert('Please select one regarding button') ;
	return false ;
}
else if(document.forms[0].comments.value == "")
{
	alert('Comments field is empty') ;
	document.forms[0].comments.focus() ;
	return false ;
}
}

else if(radio_button_checker()==false)
{
	alert('Please select one regarding button') ;
	return false ;
}
else if(document.forms[0].comments.value == "")
{
	alert('Comments field is empty') ;
	document.forms[0].comments.focus() ;
	return false ;
}
else
{
	return true ;
}
}