// JavaScript Document

var error = false;
var newsletterError = false;

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 ID")
		   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 ID")
		    return false
		}

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

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

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

 		 return true					
	}

function ValidateForm(){
	var emailID=document.contactForm.mail;
	error = false;
	if(document.contactForm.name.value == ""){
		highlight("name");
		error = true;
		
	//return false	
	}
	if(document.contactForm.message.value == ""){
		highlight("message");
		error = true;
	}
	if ((emailID.value==null)||(emailID.value=="")){
		//alert("Please Enter your Email ID")
		highlight("mail");
		//emailID.focus()
		error = true;
		//return false
	}
	if (echeck(emailID.value)==false){
		//emailID.value="";
		highlight("mail");
		//emailID.focus()
		error = true;
		//return false
	}
	
	if(error == true)
	{
		return false
	}
	else
	{
		return true
	}
	
	//return true
 }
function ValidateMail()
{
	newsletterError = false;
	var checkboxID = document.newsletterForm.privacy.checked;
	var email = document.newsletterForm.email;
	if ((email.value==null)||(email.value=="")){
		highlight("newsletterMail");
		newsletterError = true;
	}
	if (echeck(email.value)==false){
		highlight("newsletterMail");
		newsletterError = true;
	}
	if(checkboxID == undefined)
	{
		newsletterError = true;
	}
	if(checkboxID == false)
	{
		newsletterError = true;
	}
	
	
	if(newsletterError == true)
	{
		return false
	}
	else
	{
		return true
	}
		
}
 
 function checkInput(str)
 {
	 if(str == '')
	 {
		 return false;
	 }
	 else
	 {
		 return true;
	 }
 }
 
 function highlight(str)
 {
	 if(str == "name")
	 {
		  document.contactForm.name.style.background = '#e49fc0';
	 }
	 else if(str == "message")
	 {
		 document.contactForm.message.style.background = '#e49fc0';
	 }
	 else if(str == "mail")
	 {
		 document.contactForm.mail.style.background = '#e49fc0';
	 }
	 else if(str == "newsletterMail")
	 {
		 document.newsletterForm.email.style.background = '#e49fc0';
	 }
 }
 
 function changeBG(field)
 {
	if(field == "name")
	{
		document.contactForm.name.style.background = 'white';
	}
	if(field == "mail")
	{
		document.contactForm.mail.style.background = 'white';
		
	}
	if(field == "message")
	{
		 document.contactForm.message.style.background = 'white';
	}
	if(field == "newsletterMail")
	{
		document.newsletterForm.email.style.background = 'white';
	}
 }
