// JavaScript Document

function validateContactForm(theForm)
{
	if (theForm.name.value=="")
	{
		alert("Please enter your name.");
		theForm.name.focus();
		return (false);
	}
	if (theForm.email.value=="")
	{
		alert("Please enter your Email address.");
		theForm.email.focus();
		return (false);
	}
	if (theForm.phone.value=="")
	{
		alert("Please enter your contact number.");
		theForm.phone.focus();
		return (false);
	}
	if (theForm.subject.value=="")
	{
		alert("Please specify your Email subject.");
		theForm.subject.focus();
		return (false);
	}
	if (theForm.message.value=="")
	{
		alert("Email Message can not be left blank.");
		theForm.message.focus();
		return (false);
	}
	if (theForm.phone.value!="")
	{
		for(var i=0; i < theForm.phone.value.length; i++)
		{       
			var ch= theForm.phone.value.substring(i,i+1);
			if (ch < "0" || ch >"9")
			{
				if (ch == " " || ch == "-") 
				{
				}
				else
				{
					alert("You have entered an invalid Phone number. It must be numeric. No alphabets.");
					theForm.phone.focus();
					return (false);
				}
			}
		}
	}	
	if (theForm.email.value!="")
	{
		var useremail = theForm.email.value;
		var at="@"; var dot=".";
		var lat=useremail.indexOf(at);
		var lstr=useremail.length;
		var ldot=useremail.indexOf(dot);
		
		if (useremail.indexOf(at)==-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.indexOf(at)==-1 || useremail.indexOf(at)==0 || useremail.indexOf(at)==lstr)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.indexOf(dot)==-1 || useremail.indexOf(dot)==0 || useremail.indexOf(dot)==lstr)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.indexOf(at,(lat+1))!=-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.substring(lat-1,lat)==dot || useremail.substring(lat+1,lat+2)==dot)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.indexOf(dot,(lat+2))==-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}		
		if (str.indexOf(" ")!=-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}		
	}
	return (true);
}

function validateOrderForm(theForm)
{
	if (theForm.name.value=="")
	{
		alert("Please enter your name.");
		theForm.name.focus();
		return (false);
	}
	if (theForm.address1.value=="")
	{
		alert("Please enter your address in Address1.");
		theForm.address1.focus();
		return (false);
	}
	if (theForm.address2.value=="")
	{
		alert("Please enter your address in Address2.");
		theForm.address2.focus();
		return (false);
	}
	if (theForm.county.value=="")
	{
		alert("Please enter your County.");
		theForm.county.focus();
		return (false);
	}
	if (theForm.postcode.value=="")
	{
		alert("Please enter your Postcode.");
		theForm.postcode.focus();
		return (false);
	}
	if (theForm.country.value=="")
	{
		alert("Please enter your country.");
		theForm.country.focus();
		return (false);
	}
	if (theForm.phone.value=="")
	{
		alert("Please enter your Contact number.");
		theForm.phone.focus();
		return (false);
	}
	if (theForm.phone.value!="")
	{
		for(var i=0; i < theForm.phone.value.length; i++)
		{       
			var ch= theForm.phone.value.substring(i,i+1);
			if (ch < "0" || ch >"9")
			{
				if (ch == " " || ch == "-") 
				{
				}
				else
				{
					alert("You have entered an invalid Phone number. It must be numeric. No alphabets.");
					theForm.phone.focus();
					return (false);
				}
			}
		}
	}	
	if (theForm.mobile.value!="")
	{
		for(var i=0; i < theForm.mobile.value.length; i++)
		{       
			var ch= theForm.mobile.value.substring(i,i+1);
			if (ch < "0" || ch >"9")
			{
				if (ch == " " || ch == "-") 
				{
				}
				else
				{
					alert("You have entered an invalid Mobile number. It must be numeric. No alphabets");
					theForm.mobile.focus();
					return (false);
				}
			}
		}
	}	
	if (theForm.email.value!="")
	{
		var useremail = theForm.email.value;
		var at="@"; var dot=".";
		var lat=useremail.indexOf(at);
		var lstr=useremail.length;
		var ldot=useremail.indexOf(dot);
		
		if (useremail.indexOf(at)==-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.indexOf(at)==-1 || useremail.indexOf(at)==0 || useremail.indexOf(at)==lstr)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.indexOf(dot)==-1 || useremail.indexOf(dot)==0 || useremail.indexOf(dot)==lstr)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.indexOf(at,(lat+1))!=-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.substring(lat-1,lat)==dot || useremail.substring(lat+1,lat+2)==dot)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}
		if (useremail.indexOf(dot,(lat+2))==-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}		
		if (str.indexOf(" ")!=-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.email.focus();
		   return (false);
		}		
	}
	return (true);
}


function validateJobForm(theForm)
{
	if (theForm.useremail.value=="")
	{
		alert("Please enter your Email address.");
		theForm.useremail.focus();
		return (false);
	}
	if (theForm.mailsubject.value=="")
	{
		alert("Please specify the position you are applying for.");
		theForm.mailsubject.focus();
		return (false);
	}
	if (theForm.mailmessage.value=="")
	{
		alert("Please specify your covering letter.");
		theForm.mailmessage.focus();
		return (false);
	}
	if (theForm.useremail.value!="")
	{
		var useremail = theForm.useremail.value;
		var at="@"; var dot=".";
		var lat=useremail.indexOf(at);
		var lstr=useremail.length;
		var ldot=useremail.indexOf(dot);
		
		if (useremail.indexOf(at)==-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.useremail.focus();
		   return (false);
		}
		if (useremail.indexOf(at)==-1 || useremail.indexOf(at)==0 || useremail.indexOf(at)==lstr)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.useremail.focus();
		   return (false);
		}
		if (useremail.indexOf(dot)==-1 || useremail.indexOf(dot)==0 || useremail.indexOf(dot)==lstr)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.useremail.focus();
		   return (false);
		}
		if (useremail.indexOf(at,(lat+1))!=-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.useremail.focus();
		   return (false);
		}
		if (useremail.substring(lat-1,lat)==dot || useremail.substring(lat+1,lat+2)==dot)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.useremail.focus();
		   return (false);
		}
		if (useremail.indexOf(dot,(lat+2))==-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.useremail.focus();
		   return (false);
		}		
		if (str.indexOf(" ")!=-1)
		{
		   alert("You have entered an Invalid E-mail Id.");
		   theForm.useremail.focus();
		   return (false);
		}		
	}
	return (true);
}
