function validateEmailForm(){
//alert("validate");
	var newEmail=document.changeEmailForm.newEmail.value;
	var password = document.changeEmailForm.currentPassword;
  if(newEmail == "")  {
	   alert("Please enter the New Email Address");
	   document.changeEmailForm.newEmail.focus();
	   return false;
	   
   }
   else if( !emailcheck(newEmail) ){
	   alert("New Email Address should be valid ");
	   document.changeEmailForm.newEmail.focus();
	   document.changeEmailForm.newEmail.value = "";
	   return false;
   }
   else if(document.changeEmailForm.reEnterEmail.value=="")   {
	   alert("Please enter the Re-enter New Email Address");
	   document.changeEmailForm.reEnterEmail.focus();
	   return false;
	   
   }  
    
   else if(newEmail != document.changeEmailForm.reEnterEmail.value)
   {
	   alert("Re-enter New Email Address should match the New Email Address");
	   document.changeEmailForm.reEnterEmail.focus();
	   document.changeEmailForm.reEnterEmail.value = "";
	   return false;
   }
   else if(!validatePassword(password))
   {
	   return false;  
   }
   return true;
   }
function emailcheck(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false; 
		}
 
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

 		 return true;					
	}
	
	
function validatePassword(password){
	var password = password;
	var valid="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*";
	var num_valid = "0123456789";
	var alpha_valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var numberExists = false;
	var alphaExists = false;
	
	//Check if password is entered
	if(isEmpty(password.value)){
		alert("Please enter the Current Password");
		password.focus();
		return false;
	}
	//Check if password has 8 charecters
	if(password.value.length < 8) {
        alert("Current Password should be of 8 to 10 charecters");
		password.focus();
		password.value = "";
        return false;
    }
    //Check if password has more than 10 charecters
    if(password.value.length > 10) {
        alert("Current Password should be of 8 to 10 charecters");
		password.focus();
		password.value = "";
        return false;
    }
    //Check for invalid charecters.
    for (var i=0; i<password.value.length; i++) {
        if(valid.indexOf(password.value.charAt(i)) < 0) {
            alert("Current Password contains invalid characters");
			password.focus();
			password.value = "";
            return false;
        }
    }
    //Check for numbers
    for(var i=0; i<password.value.length; i++) {
        if(num_valid.indexOf(password.value.charAt(i)) >= 0) {
            numberExists = true;
        }
    }
    if(!numberExists){
    	alert("Current Password should have atleast one number");
		password.focus();
		password.value = "";
    	return false;
    }
    //Check for alphabets
    for(var i=0; i<password.value.length; i++) {
    	if(alpha_valid.indexOf(password.value.charAt(i)) >= 0) {
    		alphaExists = true;
        }
    }
    if(!alphaExists){
    	alert("Current Password should have atleast one alphabet");
		password.focus();
		password.value = "";
    	return false;
    }
    return true;
	
}	

function clearEmailFields() {
document.changeEmailForm.newEmail.value="";
document.changeEmailForm.reEnterEmail.value="";
document.changeEmailForm.currentPassword.value="";
document.changeEmailForm.newEmail.focus();
}