﻿

/*******************************************************************
Created By: Dharminder Singh
Created Date: 07 Sep 2007

* All the validations are checked on IE and Mozrilla Firefox 

* A <Validation.CSS> Style Sheet is used for displaying the style of 
validation Message 
To change  'style of validation message' or 'Images of successful and error'
we can change into style sheeet  

* Every function of javascript file we used two input parameters >...
First Parameter is 'object' of any element
Second parameter is 'Id' of any element 
Basically Second Parameter is used for displaying error message into any label
control or span
  
* for check validtaion on onkeyup ,onblur  events of any control we use validation method 
such as e.g. onblur="OnlyInteger(this,'integerstatus')"
here  'this' is element object and 'integerstatus' is span Id
   
* To check validations on any control button ,firstly you set onkeyup property of every object 
so the all validation error message display on the page 
e.g.   var obj1=document.getElementById('<%=txtNumeric.ClientID%>');
var obj2=document.getElementById('<%=txtfirstname.ClientID%>');
obj1.onkeyup();
obj2.onkeyup();
if (OnlyInteger(obj1,'integerstatus')&&OnlyNumeric(obj7,'NumericStatus'))
{return true}else{return false}}
          
* To display error style of textbox,Please add CssClass <inboxSuccess> to every input Types 
e.g. 	<asp:TextBox CssClass =" inboxSuccess" runat ="server"  id="txtpassword" ></asp:TextBox>

  
*******************************************************************/
// JScript File

/*******************************************************************
Function to Check for Empty value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function SetErrorSuccessCheckBoxList(Flag, span, msz) {
    var obj = document.getElementById(span);
    if (Flag == false) {
        setError(obj, msz);
        return false;
    }
    else {
        setSuccess(obj);
        return true;
    }
}
/*******************************************************************
Validation added by Jalaj on 11 jan 2011
Function to Check for Range of control 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message 
R1 >> Range one
R2 >> Range two 
msg >> Message to display 
********************************************************************/
function SetRange(em, id, R1, R2, msz) {
    var obj = document.getElementById(id);
    if (em.value.trim() < R1 || em.value.trim() > R2) {
        setErrorColor(em);
        setError(obj, msz);
        enableTooltips(id, msz, "error");
        $('#' + id).unbind('mouseover');
        return false;
    }
    else {
        setSuccessColor(em);
        setSuccess(obj);

        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e)
        });
        return true;
    }
}







/*******************************************************************
Function to Check for Middle Name Empty value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function IsMiddleNameEmpty(em, id, msz) {
    var obj2 = document.getElementById(id);
    if (em.value.trim().length > 0) {

        //        var blnResult =false;
        //        var StrInValidChars='{}[]`,.<>~!@#$%^&*()-+=:;"?/\|'
        //        var Space=" ";
        //        for (i = 0; i < em.value.length && blnResult == false; i++)
        //        {   
        //            strChar = em.value.charAt(i);
        //            if (StrInValidChars.indexOf(strChar) >=0)
        //            {
        //                 blnResult = true;
        //            }
        //           
        //        }
        //        if(blnResult == true)
        //        {
        //            setErrorColor(em);
        //            msz='Field cannot contain special characters';
        //            setError(obj2,msz);
        //            obj2.style.visibility="visible";
        //            return false;        
        //        }
        //        else
        //        {
        setSuccessColor(em);
        setSuccess(obj2);
        obj2.style.visibility = "visible";
        return true;
        //  }
    }
    else {
        obj2.style.visibility = "hidden";
        return true;
    }
}
/*****************************************************************/
function IsDateEmpty(em, id, msz) {

    var obj2 = document.getElementById(id);
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj2, msz);
        return false;
    }
    else {
        return true;
    }
}

/*******************************************************************
Function to Check for Empty value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
/********************************************************************/

function IsEmpty(em, id, msz) {
    var obj2 = document.getElementById(id);

    if (em.value.trim().length == 0) {

        setErrorColor(em);
        setError(obj2, msz);
        enableTooltips(id, msz, "error");
        $('#' + id).unbind('mouseover');
        return false;
    }
    else {

        setSuccessColor(em);
        setSuccess(obj2);

        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e)
        });

        //        var blnResult =false;
        //        var StrInValidChars='{}[]`,<>~!@#$%^&*()-+=:;"?/\|'
        //        var Space=" ";
        //        for (i = 0; i < em.value.length && blnResult == false; i++)
        //        {   
        //            strChar = em.value.charAt(i);
        //            if (StrInValidChars.indexOf(strChar) >=0)
        //            {
        //                 blnResult = true;
        //            }
        //           
        //        }
        //        if(blnResult == true)
        //        {
        //            setErrorColor(em);
        //            msz='Field cannot contain special characters';
        //            setError(obj2,msz);
        //            return false;        
        //        }
        //        else
        //        {
        return true;
        // }
    }
}
function IsEmptytemp(em, id, msz) {
    var obj2 = document.getElementById(id);

    if (em.value.trim().length == 0) {
       
        setErrorColor(em);
        setError(obj2, msz);
        $('#' + id).unbind('mouseover');
        return false;
    }
    else {

        setSuccessColor(em);
        setSuccess(obj2);
        $('#' + id + '[class*=success_]').mouseover(function(e) {
        });

        //        var blnResult =false;
        //        var StrInValidChars='{}[]`,<>~!@#$%^&*()-+=:;"?/\|'
        //        var Space=" ";
        //        for (i = 0; i < em.value.length && blnResult == false; i++)
        //        {   
        //            strChar = em.value.charAt(i);
        //            if (StrInValidChars.indexOf(strChar) >=0)
        //            {
        //                 blnResult = true;
        //            }
        //           
        //        }
        //        if(blnResult == true)
        //        {
        //            setErrorColor(em);
        //            msz='Field cannot contain special characters';
        //            setError(obj2,msz);
        //            return false;        
        //        }
        //        else
        //        {
        return true;
        // }
    }
}


/*******************************************************************
Function to Check for Empty value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
/********************************************************************/

function IsMoreKeyWords(em, id, msz) {
    var obj2 = document.getElementById(id);
    var arrKey= em.value.trim().split(',');
    if (arrKey.length > 9) {
        setErrorColor(em);
        setError(obj2, msz);
        enableTooltips(id, msz, "error");
        $('#' + id).unbind('mouseover');
        return false;
    }
    else {
        setSuccessColor(em);
        setSuccess(obj2);
        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e)
        });
        return true;

    }
}








/***********************************************************
Function to Check for Tags(<>) in a Text 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
***********************************************************/
function IsTag(em, id, msz) {


    var obj2 = document.getElementById(id);

    if ((em.value.indexOf("<") > "-1") || (em.value.indexOf(">") > "-1")) {

        setErrorColor(em);
        setError(obj2, msz);
        $('#' + id).unbind('mouseover');
        enableTooltips(id, msz, "error");
        return false;

    }
    else {

        setSuccessColor(em);
        setSuccess(obj2);

        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e);
        });

        return true;

    }
}

/*****************************************************************
Function  Check for valid Username 
Output: function give error message return false if input is not valid
else it return successful message
Here emailID >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
******************************************************************/
function ValidateUserName(em, id, msz) {

    var obj2 = document.getElementById(id);
    var varFlag = false;

    if (em.value != '' && checkMail(em.value)) {
        varFlag = true;
    }

    if (em.value != '' && OnlyAlphaNumericNew(em, id)) {
        varFlag = true;
    }

    if (!varFlag) {
        setErrorColor(em);
        setError(obj2, msz);
        $('#' + id).unbind('mouseover');
        enableTooltips(id, msz, "error");

        return false;
    }
    else {
        setSuccessColor(em);
        setSuccess(obj2);
        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e);
        });

        return true;
    }
}


/*****************************************************************
Function  Check for minimum length of the control 
Output: function give error message return false if input is not valid
else it return successful message. By: Manpreet Singh
******************************************************************/

function CheckMinimumLength(em, id, msz,minLength) {
    var obj2 = document.getElementById(id);
    if (minLength < $.trim(obj2.value).length) {
       setErrorColor(em);
       setError(obj2, msz);
        $('#' + id).unbind('mouseover');
        enableTooltips(id, msz, "error");
        return false;
    }
    else {
        
        setSuccessColor(em);
        setSuccess(obj2);
        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e);
        });
        return true;
    }




}
//------------------------------------------------------------------------------

function IsSpecialCharacterECDynamicName(em, id, msz) {
    var iChars = "!@#$%^&*()+=[]\;,'/{}|\":<>?_ ";
    var obj2 = document.getElementById(id);
    var flag = 1;

    for (var i = 0; i < em.value.length; i++) {
        if (iChars.indexOf(em.value.charAt(i)) != -1) {
            flag = 2;
        }
    }
    if (flag == 2) {
        setErrorColor(em);
        setError(obj2, msz);
        enableTooltips(id, msz, "error");
        $('#' + id).unbind('mouseover');
        return false;
    }
    else {

        setSuccessColor(em);
        setSuccess(obj2);
        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e);
        });

        return true;
    }




}





//---Function For Special Character--(rahul)------------------------------------

function IsSpecialCharacter(em, id, msz) {
    var iChars = "!@#$%^&*()+=-[]\;,'/{}|\":<>?_";
    var obj2 = document.getElementById(id);
    var flag=1;

    for (var i = 0; i < em.value.length; i++) {

        if (iChars.indexOf(em.value.charAt(i)) != -1) {
            flag = 2;
        }
    }
    if (flag == 2) {
        setErrorColor(em);
        setError(obj2, msz);
        enableTooltips(id, msz, "error");
        $('#' + id).unbind('mouseover');
        return false;
    }
    else {

        setSuccessColor(em);
        setSuccess(obj2);
        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e);
        });

        return true;
    }

    


}

//--------------------------------------
/*******************************************************************
Function to Check Login in Database
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function LoginStatus(id, msz, flag) {
    var obj2 = document.getElementById(id);
    if (flag == 0) {

        setError(obj2, msz);
        return false;
    }
}

/*********************************************************************/
function DateStatus(em, id, msz) {
    var obj2 = document.getElementById(id);
    setErrorColor(em);
    setError(obj2, msz);
}
//  /***********
/*******************************************************************
Function to Check Availablity of User Name in Database
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function AvailabilityUserName(em, id, msz, flag) {

    var obj2 = document.getElementById(id);

    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj2, "Required");
        return false;
    }
    else {
        if (flag == 0) {
            setErrorColor(em);
            setError(obj2, msz);
            return false;
        }
        else {
            if (ValidateEmailAddress(em, id) == true) {
                setSuccessColor(em);
                setSuccess(obj2);
                return true;
            }
            else {
                return false;
            }
        }

    }

}
/*******************************************************************
Function to Check Availablity of Reseller User Name in Database
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function Availability(em, id, msz, flag) {
    var obj2 = document.getElementById(id);

    //    if(path==0)
    //    {
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj2, "Required");
        return false;
    }
    else {

        if (flag > 0) {

            setErrorColor(em);
            setError(obj2, msz);
            return false;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj2);
            return true;
        }

    }

    //    }
    //    else
    //    {
    //        if( em.value.trim().length==0 )
    //        {
    //            return true;
    //        }
    //        else
    //        {
    //            if(flag > 0)
    //            {
    //               
    //                setErrorColor(em);
    //                setError(obj2,msz);
    //                return false;
    //            }
    //            else
    //            {
    //                setSuccessColor(em);
    //                setSuccess(obj2);
    //                return true;    
    //            }
    //        
    //        }
    //    
    //    }


}
/*******************************************************************
Function to Check Availablity of Referral Code in Database
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function AvailabilityReferralCode(em, id, msz, flag) {

    var obj2 = document.getElementById(id);
    if (em.value.trim().length == 0) {
        setSuccessColor(em);
        obj2.innerHTML = "";
        obj2.className = "RefferalSuccess";
        return true;
    }
    else {
        if (flag == 0) {
            setErrorColor(em);
            setError(obj2, msz);
            return false;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj2);
            return true;
        }

    }

}
/****************************************************************
Function  Check for  Phone number value of USA like <123 456 456456>
This function accepts s as any control element object and verifies the
phone number.
Output: function give error message return false if input is not valid
else it return successful message 
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
******************************************************************/
function checkphoneformatwithMsg(s, id, msg) {
    var flag = 0;
    var obj1 = document.getElementById(id);
    if (OnlyInteger(s, id, msg) == false) {
        
        return false;
    }
    if (s.value.trim().length > 12 || s.value.trim().length < 11) {
        setErrorColor(s);
        setError(obj1, msg );
        $('#' + id).unbind('mouseover');
        enableTooltips(id, msg, "error");
        return false;
    }

    setSuccessColor(s);
    setSuccess(obj1);
    $('#' + id + '[class*=success_]').mouseover(function(e) {
        hideTooltip(e)
    });

    return true;
}



/*****************************************************************
Function  Check for valid Email or not 
Output: function give error message return false if input is not valid
else it return successful message
Here emailID >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
******************************************************************/

function ValidateEmailAddressWithMessage(emailID, id, msg) {

    var obj2 = document.getElementById(id);
    if (emailID.value != '' && checkMail(emailID.value)) {
        setSuccessColor(emailID);
        setSuccess(obj2);
        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e)
        });
        return true;
    }
    else {
        if (emailID.value.trim().length == 0) {
            setErrorColor(emailID);
            setError(obj2, "Required");
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;
        }
        else {
            setErrorColor(emailID);
            setError(obj2, ("Invalid Email Address"));
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;
        }
        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e);
        });
        return true;

    }
}
function ValidateEmailAddress(emailID, id) {

    var obj2 = document.getElementById(id);
    if (emailID.value != '' && checkMail(emailID.value)) {
        setSuccessColor(emailID);
        setSuccess(obj2);
        hideTooltip(e);
        return true;
    }
    else {
        if (emailID.value.trim().length == 0) {
            setErrorColor(emailID);
            setError(obj2, "Required");
            enableTooltips(id, msg, "error");
            return false;
        }
        else {
            setErrorColor(emailID);
            setError(obj2, ("Invalid Email Address"));
            enableTooltips(id, msg, "error");
            return false;
        }
        return true;

    }
}

/*****************************************************************
Function  Check for selecting item in DropDown list 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any DropDown object
id >>Any span Id or label Id for Display Validation Message
*******************************************************************/
function ValidateDropDown(em, id, msz) {
    var obj2 = document.getElementById(id);
    if (em.selectedIndex == 0 || em.value == '00' || em.value == '' || em.value == '--Select--' || em.value == 'All') {
        setErrorColor(em);
        setError(obj2, msz);

        $('#' + id).unbind('mouseover');

        return false;
    }
    else {

        setSuccessColor(em);
        setSuccess(obj2);
        window.focus();
        $('#' + id + '[class*=success_]').mouseover(function(e) {

        });
        return true;
    }
}

/******************************************************************
Function  Check for  password value in DropDown list
Output: function give error message return false if input is not valid
else it return successful message 
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
here password length is minimum 5 character
********************************************************************/
function checkFirstPassword(em, id) {
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = false;
    var obj2 = document.getElementById(id);
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj2, "Required");
        return false;
    }
    else {
        //                var blnResult =false;
        //                var StrInValidChars='{}[]`,.<>~!@#$%^&*()-+=:;"?/\|'
        //                var Space=" ";
        //                for (i = 0; i < em.value.length && blnResult == false; i++)
        //                {   
        //                    strChar = em.value.charAt(i);
        //                    if (StrInValidChars.indexOf(strChar) >=0)
        //                    {
        //                         blnResult = true;
        //                    }
        //                   
        //                    if(Space.indexOf(strChar) >=0)
        //                    {
        //                        setErrorColor(em);
        //                        msz='Password cannot contain SPACE.';
        //                        setError(obj2,msz);
        //                        return false;     
        //                    }
        //                }
        //                if(blnResult == true)
        //                {
        //                    setErrorColor(em);
        //                    msz='Field cannot contain special characters.';
        //                    setError(obj2,msz);
        //                    return false;        
        //                }
        if (em.value.trim().length < 6) {
            setErrorColor(em);
            setError(obj2, "Minimum 6 characters.");
            return false;
        }
        else {
            for (i = 0; i < em.value.length; i++) {
                strChar = em.value.charAt(i);
                if (strValidChars.indexOf(strChar) >= 0) {
                    blnResult = true;
                }
            }
            if (blnResult == false) {
                setErrorColor(em);
                setError(obj2, "Must contain a number.");
                return false;
            }
            else {
                setSuccessColor(em);
                setSuccess(obj2);
                return true;
            }
        }
    }
}
/*********************************************************************************************
Function  Check for match password value of two elements 
Output: function give error message return false if input is not valid
else it return successful message
Here em1 >>first password textbox object
em2 >>second password textbox object
here password length is minimum 5 character
***********************************************************************************************/
function confirmPassword(emA, emB) {
    var flag = false;
    if (emA.value != "" && emB.value != "") {
        if (emA.value == emB.value) {
            flag = true;
            setSuccess(emA);
            setSuccess(emB);
        }
        else {
            flag = false;
            setError(emA);
            setError(emB);
        }
    }
    else {
        flag = false;
        setError(emA);
        setError(emB);
    }

    return flag;
}

function confirmPasswordWithMessage(emA, emB, msg) {
    var flag = false;
    if (emA.value != "" && emB.value != "") {
        if (emA.value == emB.value) {
            flag = true;
            setSuccess(emA);
            setSuccess(emB);
        }
        else {
            flag = false;
            setError(emA);
            setError(emB);
        }
    }
    else {
        flag = false;
        setError(emA);
        setError(emB);
    }
    if (flag == true) {
        $('#' + emB.id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e);
        });
    }
    else {
        $('#' + emB.id).unbind('mouseover');
        enableTooltips(emB.id, msg, "error");
    }
    return flag;
}

//=============================Function for User Request to Match New Password with Confirm Password======================================================================

function MatchNewPassword(emA, emB, msg) {
    var flag = false;
    if (emA.value != "" && emB.value != "") {
        if (emA.value == emB.value) {
            flag = true;
            setSuccess(emA);
            setSuccess(emB);
        }
        else {
            flag = false;
            setError(emA);
            setError(emB);
        }
    }
    else {
        flag = false;
        setError(emA);
        setError(emB);
    }
    if (flag == true) {
        $('#' + emA.id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e)
        });

    }
    else {
        $('#' + emB.id).unbind('mouseover');
        $('#' + emA.id).unbind('mouseover');
        enableTooltips(emB.id, msg, "error");
        enableTooltips(emA.id, msg, "error");
    }
    return flag;
}

//==========================================================================================================================================================

function checkPassword(emA, emB, id1, id2) {


    var obj1 = document.getElementById(id1);
    var obj3 = document.getElementById(id2);
    if (emA.value == emB.value) {
        setSuccessColor(emA);
        setSuccessColor(emB);
        setSuccess(obj1);
        setSuccess(obj3);
        return true;
    }
    else {

        setErrorColor(emB);
        setError(obj3, "Passwords do not match");
        return false;

    }
}
function checkEmail(emA, emB, id1, id2) {


    var obj1 = document.getElementById(id1);
    var obj3 = document.getElementById(id2);
    if (emA.value == emB.value) {
        setSuccessColor(emA);
        setSuccessColor(emB);
        setSuccess(obj1);
        setSuccess(obj3);
        return true;
    }
    else {

        setErrorColor(emB);
        setError(obj3, "Emails do not match");
        return false;

    }
}
/********************************************************************
Function  Validate Zip Code 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
*********************************************************************/
function ValidateZip(em, id) {

    var obj1 = document.getElementById(id);
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj1, "Please insert Zip Code");
        return false;
    }
    else {
        if (em.value.trim().length != 6) {
            setErrorColor(em);
            setError(obj1, "Invalid Zip Code");
            return false;
        }
        else {
            for (i = 0; i < em.value.length && blnResult == true; i++) {
                strChar = em.value.charAt(i);
                if (strValidChars.indexOf(strChar) == -1) {

                    blnResult = false;
                }
            }
            if (blnResult == false) {
                setErrorColor(em);
                setError(obj1, "Invalid Zip Code");
                return false;
            }
            else {
                setSuccessColor(em);
                setSuccess(obj1);
                return true;
            }
        }
    }

}

/********************************************************************
Function  Check for  integer value  
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
*********************************************************************/
function OnlyInteger(em, id, msz) {
    var obj1 = document.getElementById(id);
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj1, "Required");
        return false;
    }
    else {
        for (i = 0; i < em.value.length && blnResult == true; i++) {
            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {

                blnResult = false;
            }
        }
        if (blnResult == false) {
            setErrorColor(em);
            setError(obj1, msz);
            return true;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj1);
            return true;
        }
    }
}
/******************************************************************   
Function  Check for Numeric value
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
*******************************************************************/
function OnlyNumeric(em, id) {

    var obj1 = document.getElementById(id);
    var strValidChars = "0123456789.";
    var strChar;
    var blnResult = true;
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj1, "Insert numeric value");
        return false;
    }
    else {
        for (i = 0; i < em.value.length && blnResult == true; i++) {
            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                blnResult = false;
            }
        }
        if (blnResult == false) {
            setErrorColor(em);
            setError(obj1, "Value is not numeric");
            return false;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj1);
            return true;
        }
    }
}
function OnlyNumericWithMessage(em, id, msg) {

    var obj1 = document.getElementById(id);
    var strValidChars = "0123456789.";
    var strChar;
    var blnResult = true;
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj1, "");
        $('#' + id).unbind('mouseover');
        enableTooltips(id, msg, "error");
        return false;
    }
    else {
        for (i = 0; i < em.value.length && blnResult == true; i++) {
            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                blnResult = false;
            }
        }
        if (blnResult == false) {
            setErrorColor(em);
            setError(obj1, msg);
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj1);
            $('.success_input').mouseover(function(e) {
                hideTooltip(e);
            });
            return true;
        }
    }
}
/*******************************************************************    
Function  Check for  Alphabets value
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message 
********************************************************************/
function OnlyAlphabets(em, id) {
    var obj1 = document.getElementById(id);
    var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    var strChar;
    var blnResult = true;
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj1, "Insert alphabetic value");
        return false;
    }
    else {
        for (i = 0; i < em.value.length && blnResult == true; i++) {
            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                blnResult = false;
            }
        }
        if (blnResult == false) {
            setErrorColor(em);
            setError(obj1, "Value is not alphabetic");
            return false;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj1);
            return true;
        }
    }
}
/*******************************************************************         
Function  Check for  AlphaNumeric value
This function accepts s as any control element object and verifies the
Alphanumeric value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message
********************************************************************/
function UserLoginName(em, id) {
    var obj1 = document.getElementById(id);
    var strValidChars = "abcdefghijklmnopqrstuvwxyz0123456789._";
    var strChar;
    var blnResult = true;
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj1, "Insert alphanumeric value");
        return false;
    }
    else {
        for (i = 0; i < em.value.length && blnResult == true; i++) {
            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                blnResult = false;
            }
        }
        if (blnResult == false) {
            setErrorColor(em);
            setError(obj1, "Value is not alphanumeric");

            return false;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj1);
            return true;
        }
    }
}


/*******************************************************************         
Function  Check for  AlphaNumeric value
This function accepts s as any control element object and verifies the
Alphanumeric value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message
********************************************************************/
function OnlyAlphaNumeric(em, id) {
    var obj1 = document.getElementById(id);
    var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .";
    var strChar;
    var blnResult = true;
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj1, "Insert alphanumeric value");
        return false;
    }
    else {
        for (i = 0; i < em.value.length && blnResult == true; i++) {
            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                blnResult = false;
            }
        }
        if (blnResult == false) {
            setErrorColor(em);
            setError(obj1, "Value is not alphanumeric");

            return false;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj1);
            return true;
        }
    }
}
/****************************************************************
Function  Check for  Phone number value of USA like <123 456 456456>
This function accepts s as any control element object and verifies the
phone number.
Output: function give error message return false if input is not valid
else it return successful message 
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
******************************************************************/
function checkphoneformat(s, id) {

    var obj1 = document.getElementById(id);

    if (s.value.trim().length == 0) {
        setErrorColor(s);
        setError(obj1, "Required");
        return false;
    }
    if (OnlyInteger(s, id, 'Only 11 or 12 digits required') == false) {
        return false;
    }
    if (s.value.trim().length > 12 || s.value.trim().length < 11) {
        setErrorColor(s);
        setError(obj1, "Only 11 or 12 digits required");
        return false;
    }
    //	if ((s.value.charAt(4)!=" ")||(s.value.charAt(8)!=" "))
    //	{
    //	  setError(objTd,objSpan,"Use Format 01234 567 890");
    //	  return false;
    //	}

    //	for(var i=0;i < s.value.length;i++)
    //	{
    //	    if(s.value.charAt(i)== "-")
    //	    {
    //	        setError(objTd,objSpan,"Use Format 01234 567 890");
    //	        return false;
    //	    }
    //	}
    //	if ( isNaN(s.value.charAt(0))==true || isNaN(s.value.charAt(1))==true || isNaN(s.value.charAt(2))==true || isNaN(s.value.charAt(3))==true || isNaN(s.value.charAt(5))==true || isNaN(s.value.charAt(6))==true || isNaN(s.value.charAt(7))==true || isNaN(s.value.charAt(9))==true || isNaN(s.value.charAt(10))==true || isNaN(s.value.charAt(11))==true )
    //	{
    //		 setError(objTd,objSpan,"Use Format 01234 567 890");
    //	     return false;
    //	}

    setSuccessColor(s);
    setSuccess(obj1);
    return true;
}

/****************************************************************
Function  Check the File Extensions
This function accepts s as any control element object and verifies the
extension of file.
Output: function give error message return false if input is not valid
else it return successful message
Here s >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
******************************************************************/

function ValidExtension(s, id) {
    var obj1 = document.getElementById(id);
    var item = s.value
    if (item.trim().length == 0) {
        setErrorColor(s);
        setError(obj1, "Insert value");
        return false;
    }
    else if (item.indexOf('.jpg', 0) > 0 || item.indexOf('.JPG', 0) > 0) {
        setSuccessColor(s);
        setSuccess(obj1);
        return true;
    }
    else if (item.indexOf('.jpeg', 0) > 0 || item.indexOf('.JPEG', 0) > 0) {
        setSuccessColor(s);
        setSuccess(obj1);
        return true;
    }
    else if (item.indexOf('.png', 0) > 0 || item.indexOf('.PNG', 0) > 0) {
        setSuccessColor(s);
        setSuccess(obj1);
        return true;
    }
    else if (item.indexOf('.gif', 0) > 0 || item.indexOf('.GIF', 0) > 0) {
        setSuccessColor(s);
        setSuccess(obj1);
        return true;
    }

    else {
        setErrorColor(s);
        setError(obj1, "Invalid file extension");
        return false;
    }
}
/****************************************************************
Function  Check the  date format <dd/mm/yyyy> 
This function accepts a string variable and verifies if it is a
proper date or not. It validates format matching either
mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
has the proper number of days, based on which month it is.
Output: function give error message return false if input is not valid
else it return successful message     
Here s >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
******************************************************************/
function isDate(s, id) {

    dateStr = s.value.trim()
    var obj1 = document.getElementById(id);
    if (s.value.trim().length > 0) {

        var datePat = /^(\d{1,2})(\/|)(\d{1,2})(\/|)(\d{4})$/;
        var matchArray = dateStr.match(datePat); // is the format ok?
        months = new Array(12);
        months[0] = "Jan";
        months[1] = "Feb";
        months[2] = "Mar";
        months[3] = "Apr";
        months[4] = "May";
        months[5] = "Jun";
        months[6] = "Jul";
        months[7] = "Aug";
        months[8] = "Sep";
        months[9] = "Oct";
        months[10] = "Nov";
        months[11] = "Dec";
        if (dateStr.length == 0) {
            setErrorColor(s);
            setError(obj1, "Insert date");
            return false;
        }
        if (matchArray == null) {
            setErrorColor(s);
            setError(obj1, "Please enter date as either mm/dd/yyyy");
            return false;
        }
        day = matchArray[3];
        month = matchArray[1];
        year = matchArray[5];
        if (day < 1 || day > 31) {
            setErrorColor(s);
            setError(obj1, "Day must be between 1 and 31.");
            return false;
        }
        if (month < 1 || month > 12) // check month range
        {
            setErrorColor(s);
            setError(obj1, "Month must be between 1 and 12.");
            return false;

        }
        if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
            setErrorColor(s);
            setError(obj1, "Month " + months[month - 1] + " doesn't have 31 days!");
            return false;
        }
        if (year < 1900) {
            setErrorColor(s);
            setError(obj1, "Year must be after 1900");
            return false;

        }
        if (month == 2)  // check for february 29th
        {
            var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
            if (day > 29 || (day == 29 && !isleap)) {
                setErrorColor(s);
                setError(obj1, "February " + year + " doesn't have " + day + " days!");
                return false;

            }
        }
        setSuccessColor(s);
        setSuccess(obj1);
        return true; // date is valid
    }
    else {

        setErrorColor(s);

        setError(obj1, 'Required');
        return false;
    }
}


function isDateWithMessage(s, id, msg) {

    dateStr = s.value.trim()
    var obj1 = document.getElementById(id);
    if (s.value.trim().length > 0) {

        var datePat = /^(\d{1,2})(\/|)(\d{1,2})(\/|)(\d{4})$/;
        var matchArray = dateStr.match(datePat); // is the format ok?
        months = new Array(12);
        months[0] = "Jan";
        months[1] = "Feb";
        months[2] = "Mar";
        months[3] = "Apr";
        months[4] = "May";
        months[5] = "Jun";
        months[6] = "Jul";
        months[7] = "Aug";
        months[8] = "Sep";
        months[9] = "Oct";
        months[10] = "Nov";
        months[11] = "Dec";
        if (dateStr.length == 0) {
            setErrorColor(s);
            setError(obj1, "Insert date");
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;
        }
        if (matchArray == null) {
            setErrorColor(s);
            setError(obj1, "Please enter date as either mm/dd/yyyy");
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;
        }
        day = matchArray[3];
        month = matchArray[1];
        year = matchArray[5];
        if (day < 1 || day > 31) {
            setErrorColor(s);
            setError(obj1, "Day must be between 1 and 31.");
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;
        }
        if (month < 1 || month > 12) // check month range
        {
            setErrorColor(s);
            setError(obj1, "Month must be between 1 and 12.");
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;

        }
        if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
            setErrorColor(s);
            setError(obj1, "Month " + months[month - 1] + " doesn't have 31 days!");
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;
        }
        if (year < 1900) {
            setErrorColor(s);
            setError(obj1, "Year must be after 1900");
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msg, "error");
            return false;

        }
        if (month == 2)  // check for february 29th
        {
            var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
            if (day > 29 || (day == 29 && !isleap)) {
                setErrorColor(s);
                setError(obj1, "February " + year + " doesn't have " + day + " days!");
                $('#' + id).unbind('mouseover');
                enableTooltips(id, msg, "error");
                return false;

            }
        }
        setSuccessColor(s);
        setSuccess(obj1);
        $('#' + id + '[class*=success_]').mouseover(function(e) {
            hideTooltip(e)
        });
        return true; // date is valid
    }
    else {

        setErrorColor(s);

        setError(obj1, 'Required');
        $('#' + id).unbind('mouseover');
        enableTooltips(id, msg, "error");
        return false;
    }
}
/****************************************************************
Function  verify the IPAddress
This function accepts s as any control element object and verifies the
IPAddress.
Output: function give error message return false if input is not valid
else it return successful message
Here s >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
******************************************************************/


function verifyIP(s, id) {
    var errorString = "";
    var theName = "IPaddress";
    var IPvalue = s.value
    var obj1 = document.getElementById(id);
    var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
    var ipArray = IPvalue.match(ipPattern);
    if (IPvalue.trim().length == 0) {
        setErrorColor(s);
        setError(obj1, "Insert IP address");
        return false;
    }
    if (IPvalue == "0.0.0.0")
        errorString = errorString + theName + ': ' + IPvalue + ' is a special IP address and cannot be used here.';
    else if (IPvalue == "255.255.255.255")
        errorString = errorString + theName + ': ' + IPvalue + ' is a special IP address and cannot be used here.';
    if (ipArray == null)
        errorString = errorString + theName + ': ' + IPvalue + ' is not a valid IP address.';
    else {
        for (i = 0; i < 4; i++) {
            thisSegment = ipArray[i];
            if (thisSegment > 255) {
                errorString = errorString + theName + ': ' + IPvalue + ' is not a valid IP address.';
                i = 4;
            }
            if ((i == 0) && (thisSegment > 255)) {
                errorString = errorString + theName + ': ' + IPvalue + ' is a special IP address and cannot be used here.';
                i = 4;
            }
        }
    }
    extensionLength = 3;
    if (errorString == "") {
        setSuccessColor(s);
        setSuccess(obj1);
        return true;
    }
    else {
        setErrorColor(s);
        setError(obj1, errorString);
        return false;
    }
}




/****************************************************************
Function  for returning object of any element
Here n >>Any textbox Id
         
******************************************************************/
function de(n) {
    return document.getElementById(n);
}

/****************************************************************
Function  for confirmation about deletion of any item
OUTPUT: return true if confirmed else false
   
         
******************************************************************/
function ConfirmDelete() {
    if (confirm("Are You Sure To Delete the Record?"))
        return true;
    else
        return false;
}







//************************************************************************************
//*************************Inner function********************************************
// function for trim
String.prototype.trim = new Function("return this.replace(/^\\s+|\\s+$/g,'')");
//function for replacing string
String.prototype.replaceStr = function(find, replace)
{ return this.split(find).join(replace); };
//function for check name
function checkName(name) { return true; }
//function for validation successful message
function setSuccess(o, m) {

    if (o.className.indexOf('success_') < 0) {
        if (o.className.indexOf('error_') >= 0) {
            o.className = o.className.replace('error_', 'success_');
        }
        else {
            o.className = 'success_' + o.className;
        }
    }
}

function addEventListener(element, event_name, observer, capturing) {
    if (element.addEventListener) // the DOM2, W3C way  
        element.addEventListener(event_name, observer, capturing);
    else if (element.attachEvent) // the IE way  
        element.attachEvent("on" + event_name, observer);
}

function ShowErrorMessageInBallon(evt) {
    //alert(evt); 
}
function listener2(evt) {
    alert("Hello from listener2");
}

//function for validation Error Message
function setError(o, m) {

    if (o.className.indexOf('error_') < 0) {
        if (o.className.indexOf('success_') >= 0) {
            o.className = o.className.replace('success_', 'error_');
        }
        else {

            o.className = 'error_' + o.className;

        }
    }

    //For DropDown
    if (o.id.indexOf('DropDown') >= 0) {

        if (o.className.indexOf('error_') < 0) {
            if (o.className.indexOf('success_') >= 0) {
                o.className = o.className.replace('success_', 'error_');

            }
            else {

                o.className = 'error_' + o.className;


            }
        }

    }
    if (o.id.indexOf('ddl') >= 0) {

        if (o.className.indexOf('error_') < 0) {
            if (o.className.indexOf('success_') >= 0) {
                o.className = o.className.replace('success_', 'error_');
            }
            else {
                o.className = 'error_select';


            }
        }
        o.className = 'error_select';
    }

    //addEventListener( o, "mouseover", ShowErrorMessageInBallon, false ); 
}
// function foe set background color for Error Message
function setSuccessColor(inpElem) {
    //inpElem.className="inboxSuccess";
}
// function foe set background color for success Message
function setErrorColor(inpElem) {

    //inpElem.className="inboxError";
}
//Inner function for Email check
function checkMail(email) {
    email = email.trim();
    //    alert('checkmail  = ' + email);
    var filter = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(email)) {

        return true;
    }
    else {
        //        alert('else-false');
        return false;
    }
}
//************************************************************************************
/********************************************************************
Function  Validate Fax Code 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
*********************************************************************/
function checkFaxformat(s, id) {

    var obj1 = document.getElementById(id);

    if (s.value.trim().length != 12) {
        setErrorColor(s);
        setError(obj1, "Use Format 123-456-7890");
        return false;
    }
    if ((s.value.charAt(3) != "-") || (s.value.charAt(7) != "-")) {
        setErrorColor(s);
        setError(obj1, "Use Format 123-456-7890");
        return false;
    }

    for (var i = 0; i < s.value.length; i++) {
        if (s.value.charAt(i) == " ") {
            setErrorColor(s);
            setError(obj1, "Use Format 123-456-7890");
            return false;
        }
    }
    if (isNaN(s.value.charAt(0)) == true || isNaN(s.value.charAt(1)) == true || isNaN(s.value.charAt(2)) == true || isNaN(s.value.charAt(4)) == true || isNaN(s.value.charAt(5)) == true || isNaN(s.value.charAt(6)) == true || isNaN(s.value.charAt(8)) == true || isNaN(s.value.charAt(9)) == true || isNaN(s.value.charAt(10)) == true || isNaN(s.value.charAt(11)) == true) {
        setErrorColor(s);
        setError(obj1, "Use Format 123-456-7890");
        return false;
    }
    setSuccessColor(s);
    setSuccess(obj1);
    return true;
}

function AvailabilityName(em, id, msz, flag) {

    var obj2 = document.getElementById(id);

    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj2, "Required");
        return false;
    }
    else {
        if (flag == 0) {
            setErrorColor(em);
            setError(obj2, msz);
            return false;

        }
        else {
            setSuccessColor(em);
            setSuccess(obj2);
            return true;
        }

    }

}
/*******************************************************************
Function to Check Availablity of Company Name in Database
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function AvailabilityCompanyName(em, id, msz, flag, path) {

    var obj2 = document.getElementById(id);
    if (path == 0) {
        if (em.value.trim().length == 0) {
            setErrorColor(em);
            setError(obj2, "Please fill Company Name");
            return false;
        }
        else {
            if (flag > 0) {
                setErrorColor(em);
                setError(obj2, msz);
                return false;
            }
            else {
                setSuccessColor(em);
                setSuccess(obj2);
                return true;
            }

        }
    }
    else {

        if (em.value.trim().length == 0) {
            return true;

        }
        else {
            if (flag > 0) {
                setErrorColor(em);
                setError(obj2, msz);
                return false;
            }
            else {
                setSuccessColor(em);
                setSuccess(obj2);
                return true;
            }
        }
    }
}

/*******************************************************************
Function to Check for User Name Empty value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function IsUserNameEmpty(em, id, msz) {

    var obj2 = document.getElementById(id);
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj2, msz);
        return false;
    }
    else {
        var blnResult = false;
        var strValidChars = '{}[]`,.<>~!@#$%^&*()-+=:;"?/\|'
        var Space = " ";
        for (i = 0; i < em.value.length && blnResult == false; i++) {
            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) >= 0) {
                blnResult = true;
            }

            if (Space.indexOf(strChar) >= 0) {
                setErrorColor(em);
                msz = 'User Name cannot contain SPACE';
                setError(obj2, msz);
                return false;
            }
        }

        if (blnResult == true) {
            setErrorColor(em);
            msz = 'Field cannot contain special characters';
            setError(obj2, msz);
            return false;
        }
        else {
            setSuccessColor(em);
            setSuccess(obj2);
            return true;
        }
    }
}

/*******************************************************************
Function to Check for Address Empty value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function IsAddressEmpty(em, id, msz) {

    var obj2 = document.getElementById(id);
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj2, msz);
        return false;
    }
    else {
        //        var blnResult =false;
        //        var StrInValidChars='{}[]`<>~!@$%^&*()+=:;"?|'
        //        var Space=" ";
        //        for (i = 0; i < em.value.length && blnResult == false; i++)
        //        {   
        //            strChar = em.value.charAt(i);
        //            if (StrInValidChars.indexOf(strChar) >=0)
        //            {
        //                 blnResult = true;
        //            }
        //           
        //        }
        //        if(blnResult == true)
        //        {
        //            setErrorColor(em);
        //            msz='Field cannot contain special characters';
        //            setError(obj2,msz);
        //            return false;        
        //        }
        //        else
        //        {
        setSuccessColor(em);
        setSuccess(obj2);
        return true;
        //}
    }
}

/*******************************************************************
Function to Check for Address Empty value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
********************************************************************/
function IsAddress2Empty(em, id, msz) {

    var obj2 = document.getElementById(id);

    if (em.value.trim().length > 0) {
        //        var blnResult =false;
        //        var StrInValidChars='{}[]`<>~!@$%^&*()+=:;"?|'
        //        var Space=" ";
        //        for (i = 0; i < em.value.length && blnResult == false; i++)
        //        {   
        //            strChar = em.value.charAt(i);
        //            if (StrInValidChars.indexOf(strChar) >=0)
        //            {
        //                 blnResult = true;
        //            }
        //           
        //        }
        //        if(blnResult == true)
        //        {
        //            
        //            setErrorColor(em);
        //            msz='Field cannot contain special characters';
        //            setError(obj2,msz);
        //            obj2.style.visibility="visible";
        //            return false;        
        //        }
        //        else
        //        {
        setSuccessColor(em);
        setSuccess(obj2);
        obj2.style.visibility = "visible";
        return true;
        // }
    }
    else {
        obj2.style.visibility = "hidden";
        return true;
    }
}

//************************************************************************************
//Uk Post Code Format
function checkUKPostCode(toCheck, span) {

    var obj = document.getElementById(span);

    if (toCheck.value.trim().length == 0) {
        setErrorColor(toCheck);
        setError(obj, 'Required');
        return false;
    }
    else {
        // Permitted letters depend upon their position in the postcode.
        var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
        var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
        var alpha3 = "[abcdefghjkstuw]";                                // Character 3
        var alpha4 = "[abehmnprvwxy]";                                  // Character 4
        var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5

        // Array holds the regular expressions for the valid postcodes
        var pcexp = new Array();

        // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
        pcexp.push(new RegExp("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$", "i"));

        // Expression for postcodes: ANA NAA
        pcexp.push(new RegExp("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$", "i"));

        // Expression for postcodes: AANA  NAA
        pcexp.push(new RegExp("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$", "i"));

        // Exception for the special postcode GIR 0AA
        pcexp.push(/^(GIR)(\s*)(0AA)$/i);

        // Standard BFPO numbers
        pcexp.push(/^(bfpo)(\s*)([0-9]{1,4})$/i);

        // c/o BFPO numbers
        pcexp.push(/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

        // Overseas Territories
        pcexp.push(/^([A-Z]{4})(\s*)(1ZZ)$/i);

        // Load up the string to check
        var postCode = toCheck.value;

        // Assume we're not going to find a valid postcode
        var valid = false;

        // Check the string against the types of post codes
        for (var i = 0; i < pcexp.length; i++) {
            if (pcexp[i].test(postCode)) {

                // The post code is valid - split the post code into component parts
                pcexp[i].exec(postCode);

                // Copy it back into the original string, converting it to uppercase and
                // inserting a space between the inward and outward codes
                postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();

                // If it is a BFPO c/o type postcode, tidy up the "c/o" part
                postCode = postCode.replace(/C\/O\s*/, "c/o ");

                // Load new postcode back into the form element
                valid = true;

                // Remember that we have found that the code is valid and break from loop
                break;
            }
        }

        // Return with either the reformatted valid postcode or the original invalid 
        // postcode
        if (valid) {
            return true;
        }
        else {
            alert('Invalid PostCode');
            return false;
        }
    }
    // Return with either the reformatted valid postcode or the original invalid 
    // postcode

}



/****************************************************************
Function  Check the File Extensions
This function accepts s as any control element object and verifies the
extension of file.
Output: function give error message return false if input is not valid
else it return successful message
Here s >>Any textbox object
id >>Any span Id or label Id for Display Validation Message  
******************************************************************/



//-------------------------------Arwinder Singh-------------------------------------------
//--------------------------------24-12-2009----------------------------------------------
//--------------------------------purpose for saving the file-----------------------------
//summary of the function

// this function is called by FileUpload_Validation()(function name) which is located
// on the upload_validation.js (name of javascript page). we can use this function for saving
//the doc file and pdf file only. if file is doc file or pdf file than function return true 
//else(case like  text file, rar file etc) function return false. 

//-------------------------------------------
function FileUpload_ValidExtension(s, id) {

    var obj1 = document.getElementById(id);
    var item = s.value
    if (item.trim().length == 0) {
        setErrorColor(s);
        setError(obj1, "Insert  value");
        return false;
    }
    else if (item.indexOf('.doc', 0) > 0 || item.indexOf('.DOC', 0) > 0) {

        setSuccessColor(s);
        setSuccess(obj1);
        return true;
    }
    else if (item.indexOf('.pdf', 0) > 0 || item.indexOf('.PDF', 0) > 0) {

        setSuccessColor(s);
        setSuccess(obj1);
        return true;

    }
    else {
        alert("Not valid Extension please choose Doc File Or Pdf File");
        setErrorColor(s);
        setError(obj1, "Invalid file extension");
        return false;
    }
}

//-------------------------------------------------------------------------------------

function OnlyIntegerValue(em, id, msz) {
    var obj1 = document.getElementById(id);
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;
    if (em.value.trim().length == 0) {
        setSuccessColor(em);
        setSuccess(obj1);
        $('.success_input').mouseover(function(e) {
            hideTooltip(e);
        });
        return true;
    }
    else {
        for (i = 0; i < em.value.length && blnResult == true; i++) {

            strChar = em.value.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {

                blnResult = false;
            }
        }
        if (blnResult == false) {

            setErrorColor(em);
            setError(obj1, msz);
            $('#' + id).unbind('mouseover');
            enableTooltips(id, msz, "error");
            return false;
        }
        else {

            $('.success_input').mouseover(function(e) {
                hideTooltip(e);
            });
            setSuccessColor(em);
            setSuccess(obj1);

            return true;
        }
    }
}

//----------------------------------------------------------------------------------------


function IsValidUrl(em, id, msz) {

    var obj2 = document.getElementById(id);
    if (em.value.trim().length == 0) {
        setErrorColor(em);
        setError(obj2, msz);
        $('#' + id).unbind('mouseover');
        return false;
    }
    else {
        //        setSuccessColor(em);
        //        setSuccess(obj2);
        var theurl = em.value.trim();
        var tomatch = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
        if (tomatch.test(theurl)) {
            $('#' + id + '[class*=success_]').mouseover(function(e) {
            });
            return true;
        }
        else {
            setErrorColor(em);
            setError(obj2, msz);
            return false;
        }

        return true;
        // }
    }
}
//----------------------------------------------------------------------------------------



//************************************************************************
//   By Aman Juneja for Ecarpets requirement     Creation Date: 7/9/2010
/*************************************************************************/

function checkEmpty(id) {
    var obj = $("#" + id);
    if ($.trim(obj.val()) == "") {
        var css = obj.attr("class");

        obj.attr("class", "error_input");
        obj.keypress(function() {
            $(this).attr("class", css);
        });
        return false;
    }
    else
        return true;
}

//************************************************************************
//   By Manpreet Singh for Ecarpets requirement     Creation Date: 24/11/2010
/*************************************************************************/

function IsTagNew(id, em) {
    var obj = $("#" + id);
    if ((em.value.indexOf("<") > "-1") || (em.value.indexOf(">") > "-1")) {

        var css = obj.attr("class");

        obj.attr("class", "error_input");
        obj.keypress(function() {
            $(this).attr("class", css);
        });
        return false;
    }
    else
        return true;
}

//---------------By Abhishek for Special Character -----------------------------------------//

function IsSpecialCharacter_BYJquery(id) {
    var iChars = "'!@#$%^&*()+=-[]\;,/{}|\":<>?_'";
    //var obj2 = document.getElementById(id);
    var obj = $("#" + id);
    for (var i = 0; i < obj.val().length; i++) {

        if (iChars.indexOf(obj.val().charAt(i)) != -1) {
            var css = obj.attr("class");
            obj.attr("class", "error_input");
            obj.keypress(function() {
                $(this).attr("class", css);
            });
            return false;
        }

        else {
            return true;
        }

    }


}


/*******************************************************************         
Function  Check for  AlphaNumeric value
This function accepts s as any control element object and verifies the
Alphanumeric value 
Output: function give error message return false if input is not valid
else it return successful message
Here em >>Any textbox object
id >>Any span Id or label Id for Display Validation Message
********************************************************************/
function OnlyAlphaNumericNew(em, id) {
    var obj = $("#" + id);
    var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .";
    var strChar;
    var blnResult = true;

    for (i = 0; i < em.value.length && blnResult == true; i++) {
        strChar = em.value.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    if (blnResult == false) {
        var css = obj.attr("class");

        obj.attr("class", "error_input");
        obj.keypress(function() {
            $(this).attr("class", css);
        });
        return false;
    }
    return true;
}

function checkEmptyForClass(id) {

    var obj = $("." + id);
    if ($.trim(obj.val()) == "") {

        var css = obj.attr("class");

        obj.attr("class", "error_input");
        obj.keypress(function() {
            $(this).attr("class", css);
        });
        return false;
    }
    else
        return true;
}


function ChkNumeric(id) {
    var obj = $("#" + id);

    var strValidChars = "0123456789.";
    var strChar;
    var blnResult = true;
    // alert(obj.val().length);
    for (i = 0; i < obj.val().length && blnResult == true; i++) {
        strChar = obj.val().charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
            break;
        }
    }
    if (blnResult == false) {
        var css = obj.attr("class");
        obj.attr("class", "error_input");
        obj.keypress(function() {
            $(this).attr("class", css);
        });
        return false;
    }
    else
        return true;

}
function isValidDate(date, id) {

}

/*******************************************************************         
Function To Validate UserName Availablity For Buyer Sign Up Section
********************************************************************/

function ValidateBuyerExpertUserName(em, id, msz, flag) {
    var obj2 = document.getElementById(id);
    $('#' + id).removeClass();
    $('#' + id).addClass($('#' + id).attr("classname"));
    if (flag == 1) {
        setSuccessColor(em);
        setBuyerExpertSuccess(obj2);
        $('#' + id + '[class*=buyerexpert_success_]').mouseover(function(e) {
            hideTooltip(e)
        });
        return true;
    }
    else {
        setErrorColor(em);
        setBuyerExpertError(obj2, msz);
        enableTooltips(id, msz, "error");
        $('#' + id).unbind('mouseover');
        return false;
    }
}

function setBuyerExpertError(o, m) {
    if (o.className.indexOf('buyerexpert_error_') < 0) {
        if (o.className.indexOf('buyerexpert_success_') >= 0) { o.className = o.className.replace('buyerexpert_success_', 'buyerexpert_error_'); }
        else { o.className = 'buyerexpert_error_' + o.className; }
    }
}
function setBuyerExpertSuccess(o, m) {
    if (o.className.indexOf('buyerexpert_success_') < 0) {
        if (o.className.indexOf('buyerexpert_error_') >= 0) { o.className = o.className.replace('buyerexpert_error_', 'buyerexpert_success_'); }
        else { o.className = 'buyerexpert_success_' + o.className; }
    }
}

function ValidateBuyerExpertPassword(em, id, em2, id2) {
    var obj1 = document.getElementById(id);
    var obj2 = document.getElementById(id2);
    $('#' + id2).removeClass();
    $('#' + id2).addClass($('#' + id2).attr("classname"));

    if (em.value.trim() == em2.value.trim()) {
        setErrorColor(em2);
        setBuyerExpertError(obj2, "Username cannot be Password");
        enableTooltips(id2, "Username cannot be Password", "error");
        $('#' + id2).unbind('mouseover');
        return false;
    }
    else if (em2.value.trim() == "") {
        setErrorColor(em2);
        setBuyerExpertError(obj2, "Password cannot be Blank");
        enableTooltips(id2, "Password cannot be Blank", "error");
        $('#' + id2).unbind('mouseover');
        return false;
    }
    else if ($('#' + id2).val().length < 4) {

        setErrorColor(em2);
        setBuyerExpertError(obj2, "Minimum 4 characters");
        enableTooltips(id2, "Minimum 4 characters", "error");
        $('#' + id2).unbind('mouseover');
        return false;
    }
    else {

        setSuccessColor(em2);
        setBuyerExpertSuccess(obj2);
        $('#' + id2 + '[class*=buyerexpert_success_]').mouseover(function(e) {
        hideTooltip(e)
        });

        return true;

    }
}

function ValidateBuyerExpertConfirmPassword(em, id, em2, id2) {
    var obj1 = document.getElementById(id);
    var obj2 = document.getElementById(id2);
    $('#' + id2).removeClass();
    $('#' + id2).addClass($('#' + id2).attr("classname"));

    if (em2.value.trim() == "") {
        setErrorColor(em2);
        setBuyerExpertError(obj2, "Confirm Password cannot be Blank");
        enableTooltips(id2, "Confirm Password cannot be Blank", "error");
        $('#' + id2).unbind('mouseover');
        return false;
    }

    else if (em.value.trim() == em2.value.trim()) {
        setSuccessColor(em2);
        setBuyerExpertSuccess(obj2);
        $('#' + id2 + '[class*=buyerexpert_success_]').mouseover(function(e) {
            hideTooltip(e)
        });

        return true;
    }
    else {

        setErrorColor(em2);
        setBuyerExpertError(obj2, "Password Not Matched");
        enableTooltips(id2, "Password Not Matched", "error");
        $('#' + id2).unbind('mouseover');
        return false;

    }
}
