function validate(){
	var field_name= new Array("c_email");
		var display_name= new Array("E-Mail ");
		var count_array=1;
		
		if(check_fields('form',field_name,display_name,count_array)){
			if(checkEmail(document.form.c_email.value))
			{
			 	document.form.submit();
			}
			else {
				 document.form.c_email.focus();
			}
		}
} 


function form_submit(){

	//alert(document.newsletter.email.value);
	 var field_name= new Array("email");
		var display_name= new Array("E-Mail ");
		var count_array=1;
		
		
		
		if(check_fields('newsletter',field_name,display_name,count_array)){
			if(checkEmail(document.newsletter.email.value))
			{
			
				window.location="http://www.topretirements.com/Newsletter.html?email="+document.newsletter.email.value;
			}
			else {
				document.newsletter.email.focus();
			}
		}
} 

function check_fields(form_name,f_name,d_name,c_array)
{

	var incre=0;
	for (incre=0; incre<c_array; incre++)
	{
		var frm="document."+form_name+"."+f_name[incre]+".value";
		var foc="document."+form_name+"."+f_name[incre];
		
		if(trimSpaces(eval(frm))=="")
		{	
		   alert(d_name[incre]+" is a Required Field !!");
			  var foc_field=eval(foc);
			  
			  foc_field.focus();
			  return false;
		}		
		
	}
	
	return true;
}


function trimSpaces(stringValue) 
{
	   // Checks the first occurance of spaces and removes them
	   for(i = 0; i < stringValue.length; i++) 
	   {
		    if(stringValue.charAt(i) != " ") 
		     {			break;		}
	   }
	
	   if(i > 0) 
	   {		stringValue = stringValue.substring(i);	}
	
	   // Checks the last occurance of spaces and removes them
	   strLength = stringValue.length - 1;
	   for(i = strLength; i >= 0; i--) 
	   {
		   if(stringValue.charAt(i) != " ") 
		   {		break;		}
	   }
	
	   if(i < strLength) 
	   {		stringValue = stringValue.substring(0, i + 1);	}
	
	   // Returns the string after removing leading and trailing spaces.
	return stringValue;
}


/* character checking */
function checkAllowedChars(strToCheck, allowedChars) 
{
     var acLen     = allowedChars.length;
     var stcLen     = strToCheck.length;
     strToCheck     = strToCheck.toLowerCase();
     var i;
     var j;
     var rightCount = 0;
     for(i = 0; i < acLen; i++)
     {
          switch(allowedChars.charAt(i))
          {
          case 'A':
               for(j = 0; j< stcLen; j++)
               {
                    rightCount += strToCheck.charAt(j) >= 'a' && strToCheck.charAt(j) <= 'z';
               }
               break;
          case 'N':
               for(j = 0; j< stcLen; j++)
               {
                    rightCount += strToCheck.charAt(j) >= '0' && strToCheck.charAt(j) <= '9';
               }
               break;
          default:
               for(j = -1; -1 != (j = strToCheck.indexOf(allowedChars.charAt(i), j + 1)); rightCount++);
               break;
          }
     }
     if(rightCount == stcLen)
     {
          return true;
     }
     return false;
}


function checkEmail(emailString)
{
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) 
	{
		alert("Please Enter A Valid Email Address !!");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) 
	{
		alert("Please Enter A Valid Email Address !!");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) 
	{
		alert("Please Enter A Valid Email Address !!");
		return false;
	}
	
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) 
	{
		alert("Please Enter A Valid Email Address !!");
		return false;
	}
	return true;
}