function IsEmailValidA(strMail)
{
    var checkThisEmail =  strMail;  
	var myEMailIsValid = true;
	var myAtSymbolAt = checkThisEmail.indexOf('@');
	var myLastDotAt = checkThisEmail.lastIndexOf('.');
	var mySpaceAt = checkThisEmail.indexOf(' ');
	var myLength = checkThisEmail.length;


	// at least one @ must be present and not before position 2
	// @yellow.com : NOT valid
	// x@yellow.com : VALID

	if (myAtSymbolAt < 1 ) 
	 {myEMailIsValid = false}


	// at least one . (dot) afer the @ is required
	// x@yellow : NOT valid
	// x.y@yellow : NOT valid
	// x@yellow.org : VALID

	if (myLastDotAt < myAtSymbolAt) 
	 {myEMailIsValid = false}

	// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
	// x.y@yellow. : NOT valid
	// x.y@yellow.a : NOT valid
	// x.y@yellow.ca : VALID

	if (myLength - myLastDotAt <= 2) 
	 {myEMailIsValid = false}

    //there should be atleast 1 character between the @ and the .
    //x@.com : NOT valid
	if (myLastDotAt - myAtSymbolAt <=1) 
	 {myEMailIsValid = false}
    

	// no empty space " " is permitted (one may trim the email)
	// x.y@yell ow.com : NOT valid

	if (mySpaceAt != -1) 
	 {myEMailIsValid = false}


	if (myEMailIsValid == true)
	{

	}
	else
	{
      //alert("Please input a valid email address!");
    }

	return myEMailIsValid
}

function isNum(argvalue)
{
	argvalue = argvalue.toString();

	if (argvalue.value == 0)
	return false;


	for (var n = 0; n < argvalue.length; n++)
		if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
		return false;

	return true;
}
      
function validate()
{

  var strName ;
  var strEmail;
  var strCity;
  var strPhoneNo;
  var strFax;
  var strPin;
  var strErr;

  strErr=""
  strName = document.mailorder.txtName.value;
  strFax = document.mailorder.txtFax.value;
  strPin = document.mailorder.txtPin.value;
  strPhoneNo = document.mailorder.txtPhone.value;
  strEmail=document.mailorder.txtEmail.value;

//validation for first name
  if(strName=="")
  {
     strErr=strErr + "Please enter name.\n";
  }  


//Validation for Email
	if (strEmail!="")
	{
		blnFlag=IsEmailValidA(strEmail);
		if(blnFlag==false)
		{
			strErr=strErr + "Please enter a valid email address.\n";
		}

	}   
	else
	{
	      strErr=strErr + "Please enter email address.\n";
	}

 //validate phone no
  if(strPhoneNo !="")
  {
	  if(isNum(strPhoneNo))
	  {
	       strErr=strErr + "";
	  }
	  else
	  {
	       strErr=strErr + "Entered Phone no is invalid\n";
	  }                            
   }


  //validate Fax
  if (strFax!="")
  {            
	  if(isNum(strFax))
	  {
		   strErr=strErr + "";
	  }
	  else
	  {
		   strErr=strErr + "Entered Fax no is invalid\n";
	  }   
  }	  

//validate Pin
 if (strPin!="")
 {
	  if(isNum(strPin))
	  {
		   strErr=strErr + "";
	  }
	  else
	  {
		   strErr=strErr + "Entered PIN no is invalid\n";
	  }   
  }		  

  if(strErr=="")
  {
  	fnCheckForEnter();
	document.mailorder.submit();
  }	
  else
  {
     alert(strErr);
  }  
}
        
        
function fnCheckForEnter()
{

	strTemp = document.mailorder.taDescription.value;

	while (strTemp.search('\n') != -1)
	{
	  strTemp = strTemp.replace('\n', '<br>');
	}

	while (strTemp.search('\r') != -1)
	{
	  strTemp = strTemp.replace('\r', ' ');
	}

	document.mailorder.hidtaDescription.value = strTemp;
}
    
    
    
    
function setCookie(name, value) 
{
	path="/"; 	 
	var expires= new Date();
	var twoYear= expires.getTime() + (365 * 24 * 60 * 60 * 1000)
	expires.setTime(twoYear)
	var curCookie = name + "=" + escape(value) +
	  ((expires) ? "; expires=" + expires.toGMTString() : "") +
	  ((path) ? "; path=" + path : "");
	
	document.cookie = curCookie;
}
    

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

function getCookie(name) 
{
      var dc = document.cookie;
      var prefix = name + "=";
      var begin = dc.indexOf("; " + prefix);
      if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
      } else
        begin += 2;
      var end = document.cookie.indexOf(";", begin);
      if (end == -1)
        end = dc.length;
      return unescape(dc.substring(begin + prefix.length, end));
}

function DeleteCookie(name) 
{  
	
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	document.cookie = name + 
	"=; expires=" + exp.toGMTString();
}




