var url = document.URL;
$(document).ready(function() {
	if (url.indexOf('login') != -1) {
	   $('#username').focus();	
	}
	else if (url.indexOf('forgot-password') != -1) {
       $('#username').focus();  
    }
    else if (url.indexOf('reset-password') != -1) {
       $('#password').focus();  
    }
});
//Validation for Login
function validateLogin() {
	var valid_form = 'ture';
	var err_found = 0;
	var first_err_occured_in='';

	valid_form = check_input_required($('#username'), 'User name is required.');
	if(!valid_form && err_found==0 && first_err_occured_in == '') {
	   first_err_occured_in = $('#username');
	   err_found=1;
	}
	if(valid_form) {
		valid_form = check_valid_email($('#username'),"Enter valid User name.");
		if(!valid_form && err_found==0 && first_err_occured_in == '') {
		   first_err_occured_in = $('#username');
		   err_found=1;
		}
	}
	valid_form = check_input_required($("#password"), 'Password is required.');
	if(!valid_form && err_found==0 && first_err_occured_in == '') {
	   first_err_occured_in = $("#password");
	   err_found=1;
	}
	
	if($("#password").val() != '')
	{
		if($("#password").val().length < 6 || $("#password").val().length > 12)
	    {
	       first_err_occured_in = $("#password");
	       display_error_msg($("#password"), 'Password must be between 6 and 12 characters.');
	       err_found=1;
	    }
	}
	
	if(err_found==1) {
	   $('#errorMessage').html('');
	   //goto_error_found(first_err_occured_in);
	   return false;
	}
    return true;
}

//Validation for forgot password
function validateForgotPassword() {
	var valid_form = 'ture';
	var err_found = 0;
	var first_err_occured_in='';

	valid_form = check_input_required($('#username'), 'User name is required.');
	if(!valid_form && err_found==0 && first_err_occured_in == '') {
	   first_err_occured_in = $('#username');
	   err_found=1;
	}
	if(valid_form) {
		valid_form = check_valid_email($('#username'),"Enter valid User name.");
		if(!valid_form && err_found==0 && first_err_occured_in == '') {
		   first_err_occured_in = $('#username');
		   err_found=1;
		}
	}
	if(err_found==1) {
	   //goto_error_found(first_err_occured_in);
	   return false;
	}
    return true;
}

//Validation for reset password
function validateResetPassword() {
	
	var Pass      = 'ture';
	var ConPass   = 'ture';
    var err_found = 0;
    var first_err_occured_in='';
    
	Pass = check_input_required($("#password"), 'Password is required.');
    if(!Pass && err_found==0 && first_err_occured_in == '') {
       first_err_occured_in = $("#password");
       err_found=1;
    }
    
	if ($("#password").val() != '')
	{
	    if($("#password").val().length < 6 || $("#password").val().length > 12)
	    {
	       first_err_occured_in = $("#password");
	       display_error_msg($("#password"), 'Password must be between 6 and 12 characters.');
	       err_found=1;
	    }
	}
	
    ConPass = check_input_required($("#confirmpassword"), 'Confirm Password is required.');
    if(!ConPass && err_found==0 && first_err_occured_in == '') {
       first_err_occured_in = $("#confirmpassword");
       err_found=1;
    }
  
    if (Pass && ConPass)
    {
    	if ($("#password").val() != $("#confirmpassword").val()) {
    		first_err_occured_in = $("#confirmpassword");
    		$("#confirmpassword_err").html('Password and Confirm Password should be same.')
            err_found=1;
    	}
    }
    if(err_found==1) {
        $('#errorMessage').html('');
        //goto_error_found(first_err_occured_in);
        return false;
    }
    return true;
}
