$(document).ready(function() {
	$("#entered_login").focus();
	
	$.validator.addMethod("password", function(value, element) {
		return this.optional(element) || /^[A-Za-z0-9~!?@#$%^&*+-=:.;_\(\)\[\]]{4,24}$/i.test(value);
	}, "Passwords 4-16 letter");

	// validate login form
	$("#login_form").validate({
		rules: {
			entered_login: "required email",
			entered_password: "required password"
		},
		messages: {
			entered_login: { 
				required: "Require Email",
				email: "Invalid email address."
			},
			entered_password: {
				required: "Require Password",
				password: "Invalid Password format."
			}
		},
		errorPlacement: function(error, element) { 
            if(element.is("#entered_login") && document.getElementById("tologout") != null)
	           	error.insertBefore(element.parent().parent().next().find("#error"));
            else
            	error.insertBefore(element.parent().parent().next().next().next().find("#error"));

			if(element.is("#entered_password"))
				error.insertBefore(element.parent().parent().next().find("#error"));
        }
	});
});

//--- For Email Login textbox ---
function textEmailOnfocus(id) {
  var txtUsername = document.getElementById(id);
   if(txtUsername.value == "" || txtUsername.value == "Username(Email Address)") {
      txtUsername.value = "";
      txtUsername.style.cssText = "width:200px; color: #000000; font-style: normal;";
      txtUsername.loginbox = "background-color: red;";
   }
}

function textEmailOnblur(id) {
  var txtUsername = document.getElementById(id);
    if(txtUsername.value == "") {
      txtUsername.value = "Username(Email Address)";
      txtUsername.style.cssText = "width:200px; color: #c0c0c0; font-style: italic";
    }
}  

//--- For Password textbox ---
function textPassOnfocus(id){
  var txtPass = document.getElementById(id);
    if(txtPass.value == "" || txtPass.value == "........") {
    	txtPass.value = "";
    	txtPass.style.cssText = "width:200px; color: #000000; font-style: normal";
    }
}
function textPassOnblur(id){
  var txtPass = document.getElementById(id);
    if(txtPass.value == "") {
    	txtPass.value = "........";
    	txtPass.style.cssText="width:200px; color: #c0c0c0; font-style: italic";
    }
}
