// JavaScript Document
// fuction to check proper sintax of email.
// Decription: This script validate the contact us and the email a friend on the corver section. 

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 address")
		   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 ValidateEmailForm()
{

	var youremail = document.emailafriend.txtYours
	var friedsemail = document.emailafriend.txtFrieds
	
	if((youremail.value==null)|| (youremail.value==""))
	{
	
	  alert("You have not enter an email address, please enter your email.")
	  youremail.focus()
	  return false
	}
	
	if (echeck(youremail.value)==false)
	{
		youremail.value=""
		youremail.focus()
		return false
	}
	
	if((friedsemail.value==null)|| (friedsemail.value==""))
	{
	
	  alert("You have not enter an email address, please enter your friends email.")
	  friedsemail.focus()
	  return false
	}
	
	if (echeck(friedsemail.value)==false)
	{
		friedsemail.value=""
		friedsemail.focus()
		return false
	}
 }
 
 
function ValidateContactUsForm()
{

	var name = document.contactus.txtname
	var email = document.contactus.txtemail
	var message = document.contactus.txtmessage
	var subject = document.contactus.txtsubject
	
	if((name.value==null)|| (name.value==""))
	{
	
	  alert("Please enter your name, thanks!.")
	  name.focus()
	  return false
	}
	
	if((subject.value==null)|| (subject.value==""))
	{
	
	  alert("Please enter a subject, thanks!.")
	  subject.focus()
	  return false
	}
	
	
	if((email.value==null)|| (email.value==""))
	{
	
	  alert("You have not enter an email address, please enter your email.")
	  email.focus()
	  return false
	}
	
	if (echeck(email.value)==false)
	{
		email.value=""
		email.focus()
		return false
	}
	
	
	if((message.value==null)|| (message.value==""))
	{
	
	  alert("Please enter a message, thanks!")
	  message.focus()
	  return false
	}
	
 }
