// JavaScript Document



validNo=/^[0-9]$/;

function stripCharacter(words,character) {
	//documentation for this script at http://www.shawnolson.net/a/499/
	  var spaces = words.length;
	  for(var x = 1; x<spaces; ++x){
	   words = words.replace(character, "");   
	 }
	 return words;
}




function runForm() {


	if (document.claimform.name.value == "")
	{
		alert('Name is a required field.');
		document.claimform.name.select();
		return false;
	}
	
	var sFullName = document.claimform.name.value;
	sFullName = stripCharacter(sFullName,' ');
	
	//alert('sFullName = ' + sFullName);
	
	if (sFullName.length <= 2)
	{
		alert('Your Full Name must be longer than 2 characters.');
		document.claimform.name.select();
		return false;
	}		
	
	if (document.claimform.email.value == "")
	{
		alert('E-Mail is a required field.');
		document.claimform.email.select();
		return false;
	}	
	
	var str = document.claimform.email.value;
	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!");
		document.claimform.email.select();
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		alert("Invalid E-mail Address!");
		document.claimform.email.select();
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		alert("Invalid E-mail Address!");
		document.claimform.email.select();
		return false;
	}

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

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

	if (str.indexOf(dot,(lat+2))==-1)
	{
		alert("Invalid E-mail Address!");
		document.claimform.email.select();
		return false;
	}
		
	if (str.indexOf(" ")!=-1)
	{
		alert("Invalid E-mail Address!");
		document.claimform.email.select();
		return false;
	}			
	
	if (document.claimform.phone.value == "")
	{
		alert('Telephone is a required field.');
		document.claimform.phone.select();
		return false;
	}		
	
	var iTelephoneNo = document.claimform.phone.value;
	iTelephoneNo = stripCharacter(iTelephoneNo,' ');
	
	if (isNaN(iTelephoneNo)) 
	{
		alert(document.claimform.phone.value + ' is not a telephone number');
		document.claimform.phone.select();
		return false;
	}
		
	if (iTelephoneNo.length <= 5)
	{
		alert('Your Telephone number must be greater then 5 digits.');
		document.claimform.phone.select();
		return false;
	}		
	

		

}


