//************************************************************************************
//page functions														 *
//************************************************************************************

 $(document).ready(function(){
		$("#datepicker").datepicker({ 
			changeMonth: true,
			changeYear: true,
			yearRange: '1900:2050'
		});
		
		
		//$('#signupbtn').click(function() {
		//	validateFormById('formEmploy');
		//}); 
		
  });

//************************************************************************************
//Login Validation															 *
//************************************************************************************

function validateEmail(textfield) {
        //var regex_email = /^.+@[^\.].*\.[a-z]{2,}$/;     
	
    var value = textfield.value;                       
    // If the value does not match the pattern set the class to "invalid".
    if (value.search(regex_email) == -1) textfield.className = "invalid";
    else textfield.className = "valid";
}

function validatePassword(textfield) {                         
    var regex_password = /\w{8}/;
    var value = textfield.value;                      
    // If the value does not match the pattern set the class to "invalid".
    if (value.search(regex_password) == -1) textfield.className = "invalid";
    else textfield.className = "valid";
}

function validateCustomerLogin() {
	var flag = true;
	var GenError = "";
	
	
	//var regex_email = /^.+@[^\.].*\.[a-z]{2,}$/;
	var regex_email = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/;
	var regex_password = /\w{5}/;
	var email = document.loginForm.email.value;
	var password = document.loginForm.password.value;
	
	if (password.type=="select-one" && password.value=="none") {
		document.loginForm.password.className = "invalid";
		flag=false;	
		GenError = "Incomplete Data.  Please fill in any missing fields!"
	}
	else if (password.search(regex_password) == -1) {
		flag=false;
		document.loginForm.password.className = "invalid";
		GenError = "Password length must have at least 5 characters"
		}
	else
		document.loginForm.password.className = "logininput";
	
	
	if (email.type=="select-one" && email.value=="none") {
		document.loginForm.email.className = "invalid";
		flag=false;	
		GenError = "Incomplete Data.  Please fill in any missing fields!"
	}
	else if (email.search(regex_email) == -1) {	
		flag=false;
		document.loginForm.email.className = "invalid";
		GenError = "Invalid Email Address"
		}
	else
		document.loginForm.email.className = "logininput";
	
	
	if (!flag) 
		document.getElementById('errorCell2').innerHTML = GenError;
	else
		document.loginForm.submit();
}
	
//********************************************************************************
//New Customer Login															 *
//********************************************************************************

function validateNewCustomerLogin(formId) {

    var f = document.getElementById(formId); 
	var regex_text = /\w{1}/;
	var regex_password = /\w{5}/;
	var regex_email = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/;
	var flag=true;
	var flagP=true;
	var password1 = document.SignUpForm.password1.value;
	var password2 = document.SignUpForm.password2.value;
	var GenError = ""
	var passwordLength = ""
	var passwordSame = ""	
	
	
	  for(j = 0; j < f.elements.length; j++) {
		  var e = f.elements[j];
		  if (e.className != "RadioButton"){
			
		  e.className = "logininput";
		  }
	  }
		
	
    for(j = 0; j < f.elements.length; j++) {
        var e = f.elements[j];
		var required = e.getAttribute("required")!=null;
		if (required) {
			
			if (e.type=="select-one" && e.value=="none") {
				e.className="invalid";
				flag=false;	
				GenError = "Incomplete Data.  Please fill in any missing fields!"
			}
			else if (e.value.search(regex_text) == -1) {
				e.className = "invalid";
				flag=false;	
				GenError = "Incomplete Data.  Please fill in any missing fields!"
			}
			else if (e.id == "email1"){
				if (e.value.search(regex_email) == -1) {
					e.className = "invalid";
					flag=false;	
					passwordSame = "Invalid Email Address"
				}
			}
			else if (e.id == "password1" || e.id == "password2"){
				
					if (e.value.search(regex_password) == -1) {
						e.className = "invalid";
						flag=false;	
						passwordSame = "Password length must have at least 5 characters"
					}
					
					if (password1 != password2){
						e.className = "invalid";
						flag=false;
						passwordLength = "Passwords do not match"
					}
			}
			else
				e.className = "logininput";
		}
		
		
	}
	if (flag)
		f.submit();
	else 
		
	document.getElementById('errorCell').innerHTML =  GenError  + "<br />" + passwordSame + "<br />" + passwordLength;
}