﻿

function echeck(str) 
{
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var error_flag = 0;
		if (str.indexOf(at)==-1)
		{		   error_flag = 1;  		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{		   error_flag = 1;  		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{     error_flag = 1;		}

		 if (str.indexOf(at,(lat+1))!=-1)
		 {		    error_flag = 1;		 	 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {		    error_flag = 1;		 	 }

		 if (str.indexOf(dot,(lat+2))==-1)
		 {		    error_flag = 1;			 }
		
		 if (str.indexOf(" ")!=-1)
		 {		    error_flag = 1;		 	 }
		
		if( error_flag == 1 )
		{
			alert("Invalid Email ...........");
			return false;
		}
		else
 		 return true;				
	}

function validateEmail()
{
	var emailID=document.contact_us_form.contact_us_email_from;	
	if ((emailID.value==null)||(emailID.value==""))
	{
		alert("Please Enter your Email ID. Don't leave it BLANK");
		emailID.focus();
		return false;
	}

	if (echeck(emailID.value)==false)
	{
		emailID.focus();
		return false;
	}
	return true;
}

function validateName(fieldname)
{
	if(fieldname.value.length == 0) 
	{
		alert("!!!! Please donot leave the SUBJECT, EMAIL and MESSAGE text box EMPTY !!!!!");
		fieldname.focus();
		return false;
	}
/*	
// These codes determines whether there exists the following characters in the text box FIELDNAME

	var iChars = "!@#$%^&*()+=[]\\\';,/{}|\":<>?";
	for (var i = 0; i < fieldname.value.length; i++) 
	{ 	if (iChars.indexOf(fieldname.value.charAt(i)) != -1) 
	  	{
	  		alert ("Your Name has special characters. Please remove them and try again.");
		  	return false;
	  	}
	 }
*/	 
	 return true;
}

function validateForm()
{
	var submit_flag = 0; 
//	var fname = document.requestinfo.first_name;

// ---------------------------------	
	if( validateName(document.contact_us_form.contact_us_subject))
		submit_flag = 1;
	else
		submit_flag = 0;

// ---------------------------------	
	if((submit_flag == 1) && (validateEmail()))
		submit_flag = 1;
	else
		submit_flag = 0;
// ---------------------------------

	if((submit_flag == 1) && (validateName(document.contact_us_form.contact_us_message)))
		submit_flag = 1;
	else
		submit_flag = 0;

// ---------------------------------
	if (submit_flag == 1)
	{
		if(confirm("Are you sure to submit these data ? Press OK to SEND MESSAGE, or press CANCEL."))
		{
			contact_us_form.submit();
			return true;
		}
		else
			return false;
	}
	else
		return false;
}
 

