	var Invalid_Email_Message = "Invalid Email Id";
	var UnSub_Newsletter_SelectionReq_Message  = 'Please select atleast one Newsletter';
	var Sub_Newsletter_SelectionReq_Message  = 'Please select atleast one Newsletter for subscription';
	var Mandatory_Fields_Message = 'Please enter all mandatory fields';
	var Mismatch_Emails_Message = 'Email fields do not match';

function displayErrorMessage(Message)
{
  var MessageToDisplay;
  switch (Message)
{
  case 'EMAIL_INVALID_MESSAGE':
       MessageToDisplay = Invalid_Email_Message;
  break;
  case 'UNSUB_SELECTION_REQUIRED_MESSAGE':
       MessageToDisplay = UnSub_Newsletter_SelectionReq_Message;
  break;
  case 'SUB_SELECTION_REQUIRED_MESSAGE':
       MessageToDisplay = Sub_Newsletter_SelectionReq_Message;
  break;
  case 'MAND_FIELDS_MESSAGE':
       MessageToDisplay = Mandatory_Fields_Message;
  break;
  case 'MISMATCH_EMAILS_MESSAGE':
       MessageToDisplay = Mismatch_Emails_Message;
       break;
}


    document.getElementById('error').innerHTML = MessageToDisplay;
    document.getElementById('error').className = 'error2';
}


function displayErrorMessage2(Message)
{
  var MessageToDisplay2;
  switch (Message)
{
  case 'EMAIL_INVALID_MESSAGE':
       MessageToDisplay2 = Invalid_Email_Message;
  break;
  case 'UNSUB_SELECTION_REQUIRED_MESSAGE':
       MessageToDisplay2= UnSub_Newsletter_SelectionReq_Message;
  break;
  case 'SUB_SELECTION_REQUIRED_MESSAGE':
       MessageToDisplay2 = Sub_Newsletter_SelectionReq_Message;
  break;
  case 'MAND_FIELDS_MESSAGE':
       MessageToDisplay2 = Mandatory_Fields_Message;
  break;
  case 'MISMATCH_EMAILS_MESSAGE':
       MessageToDisplay2 = Mismatch_Emails_Message;
       break;
}

	document.getElementById('error2').innerHTML = MessageToDisplay2;
    document.getElementById('error2').className = 'error2';
}

function echeckUnSubscribe(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  displayErrorMessage2('EMAIL_INVALID_MESSAGE');
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  
		  displayErrorMessage2('EMAIL_INVALID_MESSAGE');
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		  displayErrorMessage2('EMAIL_INVALID_MESSAGE');
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   displayErrorMessage2('EMAIL_INVALID_MESSAGE');
		   return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   displayErrorMessage2('EMAIL_INVALID_MESSAGE');
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
            displayErrorMessage2('EMAIL_INVALID_MESSAGE');
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		  displayErrorMessage2('EMAIL_INVALID_MESSAGE');
		    return false;
		 }

 		 return true;					
	}
	
	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){
		
		  displayErrorMessage('EMAIL_INVALID_MESSAGE');
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  alert("Invalid Email");
		  displayErrorMessage('EMAIL_INVALID_MESSAGE');
			
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		  displayErrorMessage('EMAIL_INVALID_MESSAGE');
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   displayErrorMessage('EMAIL_INVALID_MESSAGE');
		   return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   displayErrorMessage('EMAIL_INVALID_MESSAGE');
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
            displayErrorMessage('EMAIL_INVALID_MESSAGE');
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		  displayErrorMessage('EMAIL_INVALID_MESSAGE');
		    return false;
		 }

 		 return true;					
	}
	
	
		function ValidateSubscribeForm()
		{

	      var emailID=document.getElementById('email')
		 var repeateemailID=document.getElementById('repeatemail')
			
		if ((document.getElementById('firstName').value == '') ||(document.getElementById('lastName').value == '') || (document.getElementById('email').value == '') ||(document.getElementById('companyName').value == '')||(document.getElementById('repeatemail').value == ''))
	          {	
			displayErrorMessage('MAND_FIELDS_MESSAGE');
		    emailID.focus()
		    return false;
	         }
                if (!ValidateCountrySelection())
		   {

			   return false;
		   }

	       if (echeck(emailID.value)==false)
	       {
		      emailID.value=""
		      emailID.focus()
		      return false;
	       }

	       if (echeck(repeateemailID.value)==false)
	       {
		     repeateemailID.value=""
		     repeateemailID.focus()
		     return false;
	      }

	      if (!CompareEmailIdsForEquality(emailID.value,repeateemailID.value))
	      {
                return false;
	      }
		  
	   
		
	       return true;

	}


function ValidateCountrySelection()
{
   if (document.getElementById('countryPress').selectedIndex == 0)
              {

			   displayErrorMessage('MAND_FIELDS_MESSAGE');
			   return false;

            }
			return true;
}
      
	function CompareEmailIdsForEquality(EmailId,RepeatEmailId)
       {
		 if ((EmailId.toLowerCase()) != (RepeatEmailId.toLowerCase()))
	     {
            displayErrorMessage('MISMATCH_EMAILS_MESSAGE');
	       return false;
	     }
		 else
		   {
                  return true;
		   }

       }

 function ValidateUnSubscribeForm()
       {
              if (document.getElementById('email2').value == '')
              {
			   displayErrorMessage2('MAND_FIELDS_MESSAGE');
			   return false;

            }
          var emailID=document.getElementById('email2');
		if (echeckUnSubscribe(emailID.value)==false)
	       {
			emailID.value=""
			emailID.focus()
			return false;
	       }
		return true;
  }
