// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function SetCookie(sName, sValue)
{	//date = new Date();
	var dt=new Date();
	var today=new Date();
	//dt.setFullYear(dt.getFullYear()+1)
	dt.setTime(today.getTime() + 1000*60*60*24*365)
	document.cookie = sName + "=" + escape(sValue) + "; expires=" + dt.toGMTString() + "; path=/";
}

function submitNewsLetter()
{	
	var strError=""
	strError=validateEmail1(document.newsLetter.txtMail.value,"email.\n")
	if(strError.length > 0)
	{	alert(strError)
		return false;
	}
	else
	{
		document.newsLetter.htbAction.value="submit"
		//document.thisForm.submit();
		SetCookie("PEOMail",document.newsLetter.txtMail.value)
		return true;
	}
}

function validateNewLetterForm()
{	var msg=""
	msg=validateEmail1(document.newsLetter.txtMail.value,"Email")
	if (msg=="")
	{	
		//return true;
		SetCookie("PEOMail",document.newsLetter.txtMail.value)
		document.newsLetter.htbAction.value="submit"
		document.newsLetter.submit();
	}
	else
	{	alert(msg)
	}
	
}

function validateEmail1(str,ident)
{
  var i,errormsg;
        errormsg = "" ;
         if( str == "")
         errormsg = "Please Enter " + ident 
         else
         {
			if(str.indexOf("/") != -1)
			errormsg = " / not allowed -Invalid  " + ident 
			if(str.indexOf("@") == -1)
			errormsg = " @ not Present -Invalid  " + ident 
			if(str.indexOf(".") == -1)
			errormsg = " Dot Not Present - Invalid  " + ident 
			if(str.indexOf(" ") != -1)
			errormsg = " Spaces not Allowed - Invalid  " + ident 
			if(str.indexOf('@')!=-1 && str.indexOf('.',str.indexOf('@'))!=-1)  
			{	//
			}
			else
			{	
				
				errormsg = "Invalid " + ident 	
			}
			
        //if(str.indexOf(".") != str.length-4)
        //errormsg = " Invalid " + ident 
          
         atcount = 0;
         for (i = 0;i < str.length ; i++)
         {    
			ch = str.charAt(i);
			if (ch == "@" )
			atcount ++       
         }
         if (atcount > 1) 		    
			errormsg = " Invalid " + ident
	      
	 }
	  return errormsg ;      

}


