﻿

    
/*******************************************************************************
          Login Validation
********************************************************************************/
// Removes leading whitespaces
    function LTrim( value ) {
    	
    	var re = /\s*((\S+\s*)*)/;
    	return value.replace(re, "$1");
    	
    }
    
    // Removes ending whitespaces
    function RTrim( value ) {
    	
    	var re = /((\s*\S+)*)\s*/;
    	return value.replace(re, "$1");
    	
    }
    
    // Removes leading and ending whitespaces
    function trim( value ) {
    	
    	return LTrim(RTrim(value));
    	
    }
function verifylogin(myform){
    valid = true;
    str = trim(myform.username.value);
        if (trim(myform.username.value) == "" || myform.username.value.length < 0){
            alert("Please Enter the Valid Email.....");
            myform.username.focus();
            valid = false;
            }
        else if (trim(myform.username.value) == "" || myform.username.value.length > 25){
            alert("E-Mail is too large.....");
            myform.username.focus();
            valid = false;
        }
        else if (str.indexOf("'") > 0){
            alert("Please don't use sepecial characters.....");
            myform.username.focus();
            valid = false;
        }
        else if (str.indexOf("@") < 0 || str.indexOf(".") < 0){
            alert("Please Enter E-Mail correct.....");
            myform.username.focus();
            valid = false;
        }
        else if (str.substring(str.indexOf("@")).length < 3 || str.substring(str.indexOf(".")).length < 3){
            alert("Please Enter E-Mail correct.....");
            myform.username.focus();
            valid = false;
        }
        else if (trim(myform.password.value) == "" || myform.password.value.length < 0){
            alert("Please Enter the Password.....");
            myform.password.focus();
            valid = false;
        }
        else if (myform.password.value.length > 20){
            alert("Password is too large.....");
            myform.password.focus();
            valid = false;
        }
        
        if(valid) {
            //myform.signin.value = "Please Wait"
            //myform.signin.disabled = true;
            myform.submit();
        }
    
}

/*******************************************************************************
          Search Validation
********************************************************************************/

function serachValidation(myform){
        valid = true;
        str = trim(myform.txtsearch.value);
        if (trim(myform.txtsearch.value) == "" || myform.txtsearch.value.length < 0){
            alert("Please Enter the Valid Search.....");
            myform.txtsearch.focus();
            valid = false;
            }
        else if (trim(myform.txtsearch.value) == "" || myform.txtsearch.value.length > 15){
            alert("Please Enter the Valid Search.....");
            myform.txtsearch.focus();
            valid = false;
            }
       else if (str.indexOf("'") > 0){
            alert("Please don't use sepecial characters.....");
            myform.txtsearch.focus();
            valid = false;
        }
         if(valid) {
            //myform.signin.value = "Please Wait"
            //myform.signin.disabled = true;
            myform.submit();
        }
}