﻿

/*
   How to use current JS
   ---------------------
1. validationArr Array is use for set all validation.
2. fiterArr Array is use for set Regular Expression. If you want to use Regular Expresson validation then you have to give expression in that array and pass that Index number in  Regular Expresson validation.
3. If you want to use this JavaScript then you have to follow some basic rules these are following.

   A). First you have to give validation attribute in that control which you want to validate.
   B). In validation attribute you give your every validation with ';' separated and parameter with ',' separated.
   C). Basically each validation has three parameter. But in some cases you have to give 4 parameter.
       1). First parameter is Validation name which you want to apply validation. (Ex. required)
       2). Second parameter is Error Message which you want to display when validation is fire. (Ex. Please enter your email)
       3). Third parameter is complete image url which you want to display with error message. (Ex. images/email.png)

       For Required validation:
           1) required
           2) and 3) same as defined above.
       For Custom validation:
           1) custom validation name with parenthesis and parameter. (For ex. getFormElement(formName) )
           2) and 3) same as defined above.
       For Regular Expression validation:
           1) regexp
           2) and 3) same as defined above.
           4) Index number of fiterArr for expression which you add expression for validation.
       For Range validation:
           1) range
           2) and 3) same as defined above.
           4) Minimum value (Suppose you want to show error message when user enter passord less then 5. So you give 5 as 4th parameter.)
       For Compare validation (For Text field):
           1) compare
           2) and 3) same as defined above.
           4) Id of that control which you want to compare with this control.
           5) Index number of compTypeArr for Compare Type.
           6) Index number of compOpArr for Compare Operator.
       For Compare validation (For Password field):
           1) compare
           2) and 3) same as defined above.
           4) Id of that control which you want to compare with this control.
       
   D). Call EnableTip function on onfocus event and DisableTip function on onblur event of that control on which you want to apply validation.
       1) Pass three argument in EnableTip function.
           a). First argument is Id of control as string such as 'txtemail'.
           b). Second argument is type of control as  string.
           
               Input Tag: 
                   1) 'text' for input type="text"
                   2) 'password' for input type="password"
                   3) 'file' for input type="file"
               TextArea Tag:
                   1) 'textarea' for TextArea
               Select Tag:
                   1) 'select' for Select
                   
           c). Third argument is bydefault 0. But if you focus your control using code then you have to pass 1 instead of 0.
       
       2) Pass two argument in DisableTip function same as EnableTip function.
           a). First argument is Id of control as string such as 'txtname'.
           b). Second argument is type of control as string (describe above).
        
   E). After your control add this division tag.
            <div id="div_txtname" class="hint"></div>
       Id of this divsion must be 'div_'+controlId. You have to give id of this division is 'div_' plus your control Id on which you want to apply validation.
   F). Call getFormElement function on button click and pass your form name as string.
   G). Add this style in your page:
   
       .hint
        {
            position: absolute;
            display:none;
            margin-top: -4px;
            border: 1px solid #c93;
            padding: 5px 5px;
            margin-left:10px;
            z-index:100;
            background:#F9E197 url(images/pointer.gif) no-repeat -16px 0px;
            font-family:arial;
	        font-size:12px;
	        vertical-align:middle;
	        height:19px;
        }
        //The pointer image is added by using another div
        .hint .hint-pointer
        {
            position: absolute;
            left: -16px;
            top: 0px;
            width: 16px;
            height: 14px;
            background: url(images/pointer.gif) left top no-repeat; // pointer.gif is the image which point the control.
        }

For Example if you want to apply Required,Email regular exprassion and custom valditaion with customEmail function on a textbox then use following thing.

<input type="text" validation="Required,Please enter email,images/name.png;regexp,Please enter Valid Email,images/email.png,0;customEmail(),Please enter your email with custom,images/name.png"
 id="txtname" runat="server" onfocus="EnableTip('txtname','text',0);" onblur="DisableTip('txtname','text');" />
   <div id="div_txtname" class="hint"></div>

*/



// Array for Validation.
var validationArr =new Array();
validationArr[0]='required';
validationArr[1]='regexp';
validationArr[2]='range';
validationArr[3]='compare';
validationArr[4]='phone';

// Array for Regular Expression.
var fiterArr=new Array();
fiterArr[0]=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; // For Email
fiterArr[1]=/^(.*?)\.([Jj][Pp][Gg]|[Jj][Pp][Ee][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Bb][Mm][Pp])$/i; // For Image
//fiterArr[1]=/^((\w[\w].*))+(.[Gg][Ii][Ff]|.[Jj][Pp][Gg]|.[Jj][Pp][Ee][Gg]|.[Pp][Nn][Gg]|.[Bb][Mm][Pp])$/i; // For Image
//fiterArr[2] = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/; // For Url
//fiterArr[2]=  (/^[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3})$/); //for URL
fiterArr[2]=  (/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_%&\?\/.=]+$/);
fiterArr[3]=  /^[w]{3}\.([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/; //for Trackback


// Array for Compare Type.
var compTypeArr=new Array();
compTypeArr[0]="Integer";
compTypeArr[1]="Date";

// Array for Compare Operator.
var compOpArr=new Array();
compOpArr[0]="Equal";
compOpArr[1]="GreaterThan";
compOpArr[2]="GreaterThanEqual";
compOpArr[3]="LessThan";
compOpArr[4]="LessThanEqual";
compOpArr[5]="NotEqual";
compOpArr[6]="FromDateNotBlank";

// Html for create pointer.
var divHtmlImg1="<table cellpadding=0 cellspacing=0 class=msgtable><tr><td valign=top><img src="+RelativePath()+"images/Validation/";
var divHtmlImg2=" class='png_file' width=16px height=16px border=0 align=absmiddle  />&nbsp;</td><td>";
var divHtmlDiv="</td></tr></table><div class=hint-pointer>&nbsp;</div>";

// Globle variables
//var flagShow=false;
var flag=false;                             //Use for set focus.
var flagFocus=false;                        //Use for hide validation first time when control is focus by code.
var setColor=false;                         //Use for set color after error.
var flagCompare=false;                      //Use for Show Compare error message.
var errorColor="#EA080B";        //Color of control after error.
var defaultColor="";      //Color of control default.
//#7F9DB9
var editorObj;                              //Use for get Editor Id.
var defaultImageUrl=RelativePath()+"/name.png";      //Use for set default image with error message.
var imageUrl=RelativePath()+"/name.png";             //Use for set image which you want to display with error message.

// Function ValidateContentText is use for check Editor.
function ValidateContentText()
{ 
      var fckBody= FCKeditorAPI.GetInstance(editorObj);  
     
      if(fckBody.GetXHTML()=="" ||fckBody.GetXHTML()=="<br />" ||fckBody.GetXHTML()=="&nbsp;" ||fckBody.GetXHTML()=="<br type=\"_moz\" />" )
      {  
        if(!flag)
        {
            fckBody.Focus();
            flag=true;
        }
        return false;
      }
      else
      {  
         return true;
      }
}

function editorFocus( editorInstance )
{ 
//    if(flagShow)
//    {
        if(!eval(ValidateContentText()))
        {
            var divEditorObj=editorObj.replace("ctl00_cphContent_","");
            getObj("div_"+divEditorObj).style.display="block";
        }
//    }
}
function editorBlur( editorInstance )
{ 
    var divEditorObj=editorObj.replace("ctl00_cphContent_","");
    getObj("div_"+divEditorObj).style.display="none";
}

// Function getFormElement is use for get all form element.
function getFormElement(formName,btnId)
{

    
//    flagShow=true;

//formName.click();//alert(formName.click)

    flag=false;
    flagCompare=false;
    setColor=true;
    
    var elements=formName.elements; 
    
    for (var i=0; i<elements.length; i++)
    { 
        if(elements[i].getAttribute("validation")!=null)
        {
            if(elements[i].type == "text")
                chkInputText(elements[i].id,'ButtonClick');//for textbox
            if(elements[i].type=="password")
                chkInputPassword(elements[i].id,'ButtonClick');//for password mode
            if(elements[i].type=="file")
                chkInputFile(elements[i].id,'ButtonClick');//for browse button
            if(elements[i].type=="select-one")
                chkSelect(elements[i].id,'ButtonClick');//for dropdown
            if(elements[i].type=="textarea")
                chkTextArea(elements[i].id,'ButtonClick');//for multiline textbox
//            if(elements[i].type == "hidden")
//            {
//                editorObj=elements[i].getAttribute("validation");
//                ValidateContentText();
//            }
        } 
        else
        {
            
            if(elements[i].id==editorObj)
                ValidateContentText();
        }
    }
    
    if(flag)
        return false;
    else
    {
   
        if(btnId!=null)
        {
       


 if((getObj("hdnBusyBoxImg")!=null && getObj("hdnBusyBoxImg").value!="") )
            { 
            
           
                parent.busyBox.Show();
                try
                {
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(btnId, '', true, '', '', false, false));
                }
                catch(e)
                {
                
                }
            }
        }
        return true;
    }
}

// Function chkInputText is use for check all inupt with type 'text' according to validation
function chkInputText(ObjInputId,eventValue)
{
    ObjInputId=ObjInputId.replace("ctl00_cphContent_","");
    var inputObj=getObj(ObjInputId);
    var valArrInput=new Array();
    var valExpArrInput=new Array();
    
    valArrInput = inputObj.getAttribute("validation").split(';');
    
    for(var j=0;j<valArrInput.length;j++)
    {
        valExpArrInput=valArrInput[j].split(',');
        
        if(valExpArrInput[2]!="''")
            imageUrl=valExpArrInput[2];
        else
            imageUrl=defaultImageUrl;
            
        var Html=divHtmlImg1+imageUrl+divHtmlImg2+valExpArrInput[1]+divHtmlDiv;
        
        switch (valExpArrInput[0].toLowerCase())
        {
            case "required":
                
                var spaceChk=inputObj.value.substring(0,1);  
               if(inputObj.value=="" || spaceChk ==" "  || inputObj.value=="Blog Title *"||inputObj.value=="First Name *"|| inputObj.value=="Name *" || inputObj.value=="Last Name *" ||  inputObj.value=="Title *" || inputObj.value=="Your Comments *")
                { 
                  
                    if(eventValue == 'onfocus')
                    {
                   
                        getObj("div_"+ObjInputId).innerHTML=Html;
                        getObj("div_"+ObjInputId).style.display = "inline";
                 
                    }
                    else if(eventValue == 'onblur')
                    {
                          getObj("div_"+ObjInputId).style.display = "none";
                          if(setColor)
                              inputObj.style.borderColor=errorColor;
                    }
                    else
                        inputObj.style.borderColor=errorColor;
                   
                    if(!flag)
                    {
                        inputObj.focus();
                        flag=true;
                    }
                    return false;
                }
                else
                {
                    getObj("div_"+ObjInputId).style.display = "none";                    
                    if(valArrInput.length==j+1)
                        inputObj.style.borderColor=defaultColor;
                }


            break;
            case "regexp":
                var expIndex=valExpArrInput[3];
                
                var expValue=inputObj.value.replace("http://","");
                //expValue=expValue.replace("https://","");
              
                 if(inputObj.value =="Website URL")
                 {
                    getObj("div_"+ObjInputId).style.display = "none";                    
                    if(valArrInput.length==j+1)
                        inputObj.style.borderColor=defaultColor;
                        break;
                 }
                  if(inputObj.value =="Email * (will not be published)" || inputObj.value=="Website" || inputObj.value=="Website URL" )
                  {
                  
                  }
                  
              else  if(inputObj.value!="" || inputObj.value =="Email * (will not be published)")
                {
                 
                    if(!fiterArr[expIndex].test(expValue)  )
                    {
                        if(expIndex=="1")
                            Html=divHtmlImg1+imageUrl+divHtmlImg2+"Image should be in jpeg, jpg, bmp, png or gif format"+divHtmlDiv;

                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputId).innerHTML=Html;
                            getObj("div_"+ObjInputId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObj("div_"+ObjInputId).style.display = "none";
                            if(setColor)
                                inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObj("div_"+ObjInputId).style.display = "none";                    
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputId).style.display = "none";                    
                    if(valArrInput.length==j+1)
                        inputObj.style.borderColor=defaultColor;
                }
            break;
            case "range":
                if(inputObj.value!="")
                {
                    if(inputObj.value.length<valExpArrInput[3])
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputId).innerHTML=Html;
                            getObj("div_"+ObjInputId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObj("div_"+ObjInputId).style.display = "none";
                            if(setColor)
                                inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObj("div_"+ObjInputId).style.display = "none";                    
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputId).style.display = "none";                    
                    if(valArrInput.length==j+1)
                        inputObj.style.borderColor=defaultColor;
                }
            break;
            case "compare":
                var compObj=getObj(valExpArrInput[3]);
                var compTypeIndex=valExpArrInput[4];
                var compOpIndex=valExpArrInput[5];
                var compValue=compObj.value;
                var validateValue=inputObj.value;
                
                if(compObj.value!="")
                {
                    if(compTypeArr[compTypeIndex]=="Date")
                    {
                        compValue=Date.parse(compValue);
                        validateValue=Date.parse(validateValue);
                    }
                    
                    if(compOpArr[compOpIndex]=="Equal")
                    {
                        if(validateValue==compValue)
                            flagCompare=false;
                        else
                            flagCompare=true;
                    }
                    else if(compOpArr[compOpIndex]=="GreaterThan")
                    {
                        if(validateValue>compValue)
                            flagCompare=false;
                        else
                            flagCompare=true;
                    }
                    if(compOpArr[compOpIndex]=="GreaterThanEqual")
                    {
                        if(validateValue>=compValue)
                            flagCompare=false;
                        else
                            flagCompare=true;
                    }
                    if(compOpArr[compOpIndex]=="LessThan")
                    {
                        if(validateValue<compValue)
                            flagCompare=false;
                        else
                            flagCompare=true;
                    }
                    if(compOpArr[compOpIndex]=="LessThanEqual")
                    {
                        if(validateValue<=compValue)
                            flagCompare=false;
                        else
                            flagCompare=true;
                    }
                    if(compOpArr[compOpIndex]=="NotEqual")
                    {
                        if(validateValue!=compValue)
                            flagCompare=false;
                        else
                            flagCompare=true;
                    }
                    if(compOpArr[compOpIndex]=="FromDateNotBlank")
                    {     
                              
                        if(validateValue>0 && compValue>0)
                            flagCompare=false;
                        else
                            flagCompare=true;
                    }
                    if(flagCompare)
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputId).innerHTML=Html;
                            getObj("div_"+ObjInputId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObj("div_"+ObjInputId).style.display = "none";
                            if(setColor)
                                inputObj.style.borderColor=errorColor;
                        }
                        else
                        
                            inputObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObj("div_"+ObjInputId).style.display = "none";                    
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputId).style.display = "none";                    
                    if(valArrInput.length==j+1)
                        inputObj.style.borderColor=defaultColor;
                }
            break;
            case "phone":
                var phoneId=valExpArrInput[3];
                
			        var chkNumber=3;
			        var searchCond ="";
		            if(valExpArrInput[4]==null) 
		                searchCond = eval(getObj(phoneId+"1").value.length != 0 || getObj(phoneId+"2").value.length != 0 || getObj(phoneId+"3").value.length != 0);
		            else
		                searchCond = eval(getObj(phoneId+"1").value.length != 0 || getObj(phoneId+"2").value.length != 0 || getObj(phoneId+"3").value.length != 0 || getObj(phoneId+"ext").value.length != 0);

			        for(k=1;k<=3;k++)
			        {
			            if(k==3)
			                chkNumber=4;
			              
        			    if(searchCond)
			            {   
                            if(getObj(phoneId+k).value.length != chkNumber)
                            { 
                                if(eventValue == 'onfocus')
                                {
                                    getObj("div_"+phoneId).innerHTML=Html;
                                    getObj("div_"+phoneId).style.display = "inline";
                                }
                                else if(eventValue == 'onblur')
                                {
                                      getObj("div_"+phoneId).style.display = "none";
                                      if(setColor)
                                          getObj(phoneId+k).style.borderColor=errorColor;
                                }
                                else
                                    getObj(phoneId+k).style.borderColor=errorColor;
                               
                                if(!flag)
                                {
                                    getObj(phoneId+k).focus();
                                    flag=true;
                                }
                                return false;
                            }
                            else
                            {
                                getObj("div_"+phoneId).style.display = "none";                    
                                if(valArrInput.length==j+1)
                                    getObj(phoneId+k).style.borderColor=defaultColor;
                            }
                        }
                        else
                        {
                            getObj("div_"+phoneId).style.display = "none";                    
                            if(valArrInput.length==j+1)
                                getObj(phoneId+k).style.borderColor=defaultColor;
                        }
                    }
            break;
            case "rate":
                
               var spaceChk=inputObj.value.substring(0,1);
               if(inputObj.value=="" || spaceChk ==" ")
                { 
                       if(txtFrom2 != "")
                       {
                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputId).innerHTML=Html;
                            getObj("div_"+ObjInputId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                              getObj("div_"+ObjInputId).style.display = "none";
                              if(setColor)
                                  inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                       
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputId).style.display = "none";                    
                    if(valArrInput.length==j+1)
                        inputObj.style.borderColor=defaultColor;
                }
            break;
            default: 
            
                if(inputObj.value!="" || valExpArrInput[0]=='ValidateContentText()')
                { 
                    if(!eval(valExpArrInput[0]))
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputId).innerHTML=Html;
                            getObj("div_"+ObjInputId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObj("div_"+ObjInputId).style.display = "none";
                            if(setColor)
                                inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                          
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObj("div_"+ObjInputId).style.display = "none";                    
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputId).style.display = "none";                    
                    if(valArrInput.length==j+1)
                        inputObj.style.borderColor=defaultColor;
                }
        }
    }
}

// Function chkInputText is use for check all inupt with type 'text' according to validation
function chkInputFile(ObjInputFileId,eventValue)
{
    ObjInputFileId=ObjInputFileId.replace("ctl00_cphContent_","");
    var inputFileObj=getObj(ObjInputFileId);
    var valArrInputFile=new Array();
    var valExpArrInputFile=new Array();
    
    valArrInputFile = inputFileObj.getAttribute("validation").split(';');
    
    for(var j=0;j<valArrInputFile.length;j++)
    {
        valExpArrInputFile=valArrInputFile[j].split(',');
        
        if(valExpArrInputFile[2]!="''")
            imageUrl=valExpArrInputFile[2];
        else
            imageUrl=defaultImageUrl;
        
        var Html=divHtmlImg1+imageUrl+divHtmlImg2+valExpArrInputFile[1]+divHtmlDiv;
        
        switch (valExpArrInputFile[0].toLowerCase())
        {
            case "required":
                if(inputFileObj.value=="")
                { 
                    if(eventValue == 'onfocus')
                    {
                        getObj("div_"+ObjInputFileId).innerHTML=Html;
                        getObj("div_"+ObjInputFileId).style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObj("div_"+ObjInputFileId).style.display = "none";
                        if(setColor)
                            inputFileObj.style.borderColor=errorColor;
                    }
                    else
                        inputFileObj.style.borderColor=errorColor;
                   
                    if(!flag)
                    {
                        inputFileObj.focus();
                        flag=true;
                    }
                    return false;
                }
                else
                {
                 
                    getObj("div_"+ObjInputFileId).style.display = "none";                    
                    if(valArrInputFile.length==j+1)
                        inputFileObj.style.borderColor=defaultColor;
                }
            break;
            case "regexp":
                var expIndex=valExpArrInputFile[3];
                if(inputFileObj.value!="")
                {
                    if(!fiterArr[expIndex].test(inputFileObj.value))
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputFileId).innerHTML=Html;
                            getObj("div_"+ObjInputFileId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObj("div_"+ObjInputFileId).style.display = "none";
                            if(setColor)
                                inputFileObj.style.borderColor=errorColor;
                        }
                        else
                            inputFileObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputFileObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObj("div_"+ObjInputFileId).style.display = "none";                    
                        if(valArrInputFile.length==j+1)
                            inputFileObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputFileId).style.display = "none";                    
                    if(valArrInputFile.length==j+1)
                         inputFileObj.style.borderColor=defaultColor;
                }
            break;
            default:
                if(inputFileObj.value!="")
                {
                    if(!eval(valExpArrInputFile[0]))
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputFileId).innerHTML=Html;
                            getObj("div_"+ObjInputFileId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObj("div_"+ObjInputFileId).style.display = "none";
                            if(setColor)
                                inputFileObj.style.borderColor=errorColor;
                        }
                        else
                            inputFileObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputFileObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObj("div_"+ObjInputFileId).style.display = "none";                    
                        if(valArrInputFile.length==j+1)
                            inputFileObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputFileId).style.display = "none";                    
                    if(valArrInputFile.length==j+1)
                        inputFileObj.style.borderColor=defaultColor;
                }
        }
    }
}

// Function chkInputPassword is use for check all inupt with type 'password' according to validation
function chkInputPassword(ObjInputPasswordId,eventValue)
{
    ObjInputPasswordId=ObjInputPasswordId.replace("ctl00_cphContent_","");
    var inputPasswordObj=getObj(ObjInputPasswordId);
    var valArrInputPassword=new Array();
    var valExpArrInputPassword=new Array();
    
    valArrInputPassword = inputPasswordObj.getAttribute("validation").split(';');
    
    for(var j=0;j<valArrInputPassword.length;j++)
    {
        valExpArrInputPassword=valArrInputPassword[j].split(',');
        
        if(valExpArrInputPassword[2]!="''")
            imageUrl=valExpArrInputPassword[2];
        else
            imageUrl=defaultImageUrl;
        
        var Html=divHtmlImg1+imageUrl+divHtmlImg2+valExpArrInputPassword[1]+divHtmlDiv;
        
        switch (valExpArrInputPassword[0].toLowerCase())
        {
            case "required":
                if(inputPasswordObj.value=="")
                { 
                    if(eventValue == 'onfocus')
                    {
                        getObj("div_"+ObjInputPasswordId).innerHTML=Html;
                        getObj("div_"+ObjInputPasswordId).style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                          getObj("div_"+ObjInputPasswordId).style.display = "none";
                          if(setColor)
                              inputPasswordObj.style.borderColor=errorColor;
                    }
                    else
                        inputPasswordObj.style.borderColor=errorColor;
                   
                    if(!flag)
                    {
                        inputPasswordObj.focus();
                        flag=true;
                    }
                    return false;
                }
                else
                {
                      getObj("div_"+ObjInputPasswordId).style.display = "none";                    
                      if(valArrInputPassword.length==j+1)
                          inputPasswordObj.style.borderColor=defaultColor;
                }
            break;
            case "range":
                if(inputPasswordObj.value!="")
                {
                    if(inputPasswordObj.value.length<valExpArrInputPassword[3])
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputPasswordId).innerHTML=Html;
                            getObj("div_"+ObjInputPasswordId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                              getObj("div_"+ObjInputPasswordId).style.display = "none";
                              if(setColor)
                                  inputPasswordObj.style.borderColor=errorColor;
                        }
                        else
                            inputPasswordObj.style.borderColor=errorColor;
                          
                        if(!flag)
                        {
                            inputPasswordObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObj("div_"+ObjInputPasswordId).style.display = "none";                    
                        if(valArrInputPassword.length==j+1)
                            inputPasswordObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputPasswordId).style.display = "none";                    
                    if(valArrInputPassword.length==j+1)
                        inputPasswordObj.style.borderColor=defaultColor;
                }
            break;
            case "compare":
                compObj=getObj(valExpArrInputPassword[3]);
                if(compObj.value!="")
                {
                    if(inputPasswordObj.value=="")
                        Html=divHtmlImg1+imageUrl+divHtmlImg2+"Re-enter password"+divHtmlDiv;
                        
                    if(inputPasswordObj.value!=compObj.value)
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObj("div_"+ObjInputPasswordId).innerHTML=Html;
                            getObj("div_"+ObjInputPasswordId).style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObj("div_"+ObjInputPasswordId).style.display = "none";
                            if(setColor)
                                inputPasswordObj.style.borderColor=errorColor;
                        }
                        else
                            inputPasswordObj.style.borderColor=errorColor;
                          
                        if(!flag)
                        {
                            inputPasswordObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObj("div_"+ObjInputPasswordId).style.display = "none";                    
                        if(valArrInputPassword.length==j+1)
                            inputPasswordObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObj("div_"+ObjInputPasswordId).style.display = "none";                    
                    if(valArrInputPassword.length==j+1)
                        inputPasswordObj.style.borderColor=defaultColor;
                }
            break;
              
            default:
                if(!eval(valExpArrInputPassword[0]))
                {
                    if(eventValue == 'onfocus')
                    {
                        getObj("div_"+ObjInputPasswordId).innerHTML=Html;
                        getObj("div_"+ObjInputPasswordId).style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObj("div_"+ObjInputPasswordId).style.display = "none";
                        if(setColor)
                            inputPasswordObj.style.borderColor=errorColor;
                    }
                    else
                        inputPasswordObj.style.borderColor=errorColor;
                      
                    if(!flag)
                    {
                        inputPasswordObj.focus();
                        flag=true;
                    }
                    return false;
                }
                else
                {
                    getObj("div_"+ObjInputPasswordId).style.display = "none";                    
                    if(valArrInputPassword.length==j+1)
                        inputPasswordObj.style.borderColor=defaultColor;
                }
        }
    }
}

// Function chkSelect is use for check all select according to validation
function chkSelect(ObjSelectId,eventValue)
{
   
    ObjSelectId=ObjSelectId.replace("ctl00_cphContent_","");
    var selectObj=getObj(ObjSelectId);
    var valArrSelect=new Array();
    var valExpArrSelect=new Array();
    
    valArrSelect=selectObj.getAttribute("validation").split(';');
    
    for(var j=0;j<valArrSelect.length;j++)
    {
        valExpArrSelect=valArrSelect[j].split(',');
        
        if(valExpArrSelect[2]!="''")
            imageUrl=valExpArrSelect[2];
        else
            imageUrl=defaultImageUrl;
        
        var Html=divHtmlImg1+imageUrl+divHtmlImg2+valExpArrSelect[1]+divHtmlDiv;
        
        switch (valExpArrSelect[0].toLowerCase())
        {
            case "required":
                if(selectObj.selectedIndex==0)
                {
                    if(eventValue == 'onfocus')
                    {
                        getObj("div_"+ObjSelectId).innerHTML=Html;
                        getObj("div_"+ObjSelectId).style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObj("div_"+ObjSelectId).style.display = "none";
                        if(setColor)
                            selectObj.style.borderColor=errorColor;
                    }
                    else
                        selectObj.style.borderColor=errorColor; 
                        
                    if(!flag)
                    {
                        selectObj.focus();
                        flag=true;
                    } 
                    return false;
                }
                else
                {
                    getObj("div_"+ObjSelectId).style.display = "none";
                    if(valArrSelect.length==j+1)
                        selectObj.style.borderColor=defaultColor;
                }
            break;            
            default:
                if(!eval(valExpArrSelect[0]))
                {
                    if(eventValue == 'onfocus')
                    {
                        getObj("div_"+ObjSelectId).innerHTML=Html;
                        getObj("div_"+ObjSelectId).style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObj("div_"+ObjSelectId).style.display = "none";
                        if(setColor)
                            selectObj.style.borderColor=errorColor;
                    }
                    else
                        selectObj.style.borderColor=errorColor; 
                        
                    if(!flag)
                    {
                        selectObj.focus();
                        flag=true;
                    } 
                    return false;
                }
                else
                {
                    getObj("div_"+ObjSelectId).style.display = "none";
                    if(valArrSelect.length==j+1)
                        selectObj.style.borderColor=defaultColor;
                }
        }
    }
}

// Function chkTextArea is use for check all TextArea according to validation
function chkTextArea(ObjTextAreaId,eventValue)
{
    ObjTextAreaId=ObjTextAreaId.replace("ctl00_cphContent_","");
    var textAreaObj=getObj(ObjTextAreaId);
    var valArrTextArea=new Array();
    var valExpArrTextArea=new Array();
    
    valArrTextArea=textAreaObj.getAttribute("validation").split(';');
    
    for(var j=0;j<valArrTextArea.length;j++)
    {
        valExpArrTextArea=valArrTextArea[j].split(',');
        
        if(valExpArrTextArea[2]!="''")
            imageUrl=valExpArrTextArea[2];
        else
            imageUrl=defaultImageUrl;
        
        var Html=divHtmlImg1+imageUrl+divHtmlImg2+valExpArrTextArea[1]+divHtmlDiv;
        
        switch (valExpArrTextArea[0].toLowerCase())
        {
            case "required":
                if(textAreaObj.value=="")
                {
                    if(eventValue == 'onfocus')
                    {
                        getObj("div_"+ObjTextAreaId).innerHTML=Html;
                        getObj("div_"+ObjTextAreaId).style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObj("div_"+ObjTextAreaId).style.display = "none";
                        if(setColor)
                            textAreaObj.style.borderColor=errorColor;
                    }
                    else
                        textAreaObj.style.borderColor=errorColor;
                           
                        
                    if(!flag)
                    {
                        textAreaObj.focus();
                        flag=true;
                    }                    
                    return false;
                }
                else
                {
                    getObj("div_"+ObjTextAreaId).style.display = "none";
                    if(valArrTextArea.length==j+1)
                        textAreaObj.style.borderColor=defaultColor;
                }
            break;            
            default:
                if(!eval(valExpArrTextArea[0]))
                {
                    if(eventValue == 'onfocus')
                    {
                        getObj("div_"+ObjTextAreaId).innerHTML=Html;
                        getObj("div_"+ObjTextAreaId).style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObj("div_"+ObjTextAreaId).style.display = "none";
                        if(setColor)
                            textAreaObj.style.borderColor=errorColor;
                    }
                    else
                        textAreaObj.style.borderColor=errorColor;
                        
                    if(!flag)
                    {
                        textAreaObj.focus();
                        flag=true;
                    } 
                    return false;
                }
                else
                {
                    getObj("div_"+ObjTextAreaId).style.display = "none";
                    if(valArrTextArea.length==j+1)
                        textAreaObj.style.borderColor=defaultColor;
                }
        }
    }
}

// Function EnableTip is use for show tip
function EnableTip(ObjName,controlType,focusValue)
{
    
    if(focusValue==0 || (focusValue==1 && flagFocus))
    {
    if(controlType == 'text')
            {
                chkInputText(ObjName,'onfocus');
                   function handleError(){return true;}window.onerror = handleError;
                   if(document.getElementById('tdCaptcha_div')!=null)
                 document.getElementById('tdCaptcha_div').style.display="none"; 
                  
            }
            else if(controlType == 'textarea')
            {
                chkTextArea(ObjName,'onfocus');
                   function handleError(){return true;}window.onerror = handleError;
                document.getElementById('tdCaptcha_div').style.display="none";  
                }
            else if(controlType == 'select')
            {
                chkSelect(ObjName,'onfocus');
                   function handleError(){return true;}window.onerror = handleError;
                document.getElementById('tdCaptcha_div').style.display="none";  
                }
            else if(controlType == 'password')
            {
                chkInputPassword(ObjName,'onfocus');
                   function handleError(){return true;}window.onerror = handleError;
                document.getElementById('tdCaptcha_div').style.display="none";  
                }
            else if(controlType == 'file')
            {
                chkInputFile(ObjName,'onfocus');
                   function handleError(){return true;}window.onerror = handleError;
                document.getElementById('tdCaptcha_div').style.display="none";  
            }
//        if(flagShow)
////        {
//            if(controlType == 'text')
//                chkInputText(ObjName,'onfocus');
//            else if(controlType == 'textarea')
//                chkTextArea(ObjName,'onfocus');
//            else if(controlType == 'select')
//                chkSelect(ObjName,'onfocus');
//            else if(controlType == 'password')
//                chkInputPassword(ObjName,'onfocus');
//            else if(controlType == 'file')
//                chkInputFile(ObjName,'onfocus');
//        }
    }
    else
    {
        flagFocus=true;
        flag=true;
    }
    
}

// Function DisableTip is use for hide tip
function keyDisableTip(e,ObjName,controlType)
{

var HandleEvent='' ;
if(window.event) {

                HandleEvent = e.keyCode; 
             }
             else if(e.which) {
            
                HandleEvent = e.which; 
             }  
    if(HandleEvent == 9 || HandleEvent == 13){    

    }
    else{
        if(controlType == 'text')
        chkInputText(ObjName,'onblur');
        else if(controlType == 'textarea')
        chkTextArea(ObjName,'onblur');
        else if(controlType == 'select')
        chkSelect(ObjName,'onblur');
        else if(controlType == 'password')
        chkInputPassword(ObjName,'onblur');
        else if(controlType == 'file')
        chkInputFile(ObjName,'onblur');
    }

}

function DisableTip(ObjName,controlType)
{

        if(controlType == 'text')
        chkInputText(ObjName,'onblur');
        else if(controlType == 'textarea')
        chkTextArea(ObjName,'onblur');
        else if(controlType == 'select')
        chkSelect(ObjName,'onblur');
        else if(controlType == 'password')
        chkInputPassword(ObjName,'onblur');
        else if(controlType == 'file')
        chkInputFile(ObjName,'onblur');
    
}



// Custom validation Function 
function customVal(Obj)
{
    if(document.getElementById(Obj).value=="")
        return false;
    else
        return true;
}
           
// Function for get Object    
function getObj(objID) 
{
    if (document.getElementById)
    {
        if (document.getElementById(objID)==null)
        objID="ctl00_cphContent_"+objID;
        
        return document.getElementById(objID)
    }
    else if (document.all)
    {
        if (document.all(objID)==null)
        objID="ctl00_cphContent_"+objID;
        
        return document.all[objID];
    }
    else if (document.layers)
    {
        if (document.layers(objID)==null)
        objID="ctl00_cphContent_"+objID;
        	    
        return document.layers[objID];
    }
}    

function blockSpace(ctrl,e) 
        {  
	        var isIE = document.all?true:false;
            var isNS = document.layers?true:false;	 
           var key = (isIE) ? window.event.keyCode : e.which;  
           if(key == 32 &&  ctrl.value.length == 0)
           {
              return false;
           }
	       else
           {
              return true;  
           }
      } 
      
       function blockHtml(ctrl,e) 
        {  
     
	        var isIE = document.all?true:false;
            var isNS = document.layers?true:false;	 
           var key = (isIE) ? window.event.keyCode : e.which;  
  
          if(key == 188 || key == 190)
           {
         
              return false;
           }
	       else
           {
          
              return true;  
           }
      }    
function keyDisableTip(e,ObjName,controlType)
{

var HandleEvent='' ;
if(window.event) {

                HandleEvent = e.keyCode; 
             }
             else if(e.which) {
            
                HandleEvent = e.which; 
             }  
    if(HandleEvent == 9 || HandleEvent == 13){    

    }
    else{
        if(controlType == 'text')
        chkInputText(ObjName,'onblur');
        else if(controlType == 'textarea')
        chkTextArea(ObjName,'onblur');
        else if(controlType == 'select')
        chkSelect(ObjName,'onblur');
        else if(controlType == 'password')
        chkInputPassword(ObjName,'onblur');
        else if(controlType == 'file')
        chkInputFile(ObjName,'onblur');
    }

}

//validation="chkRateDate1('txtFrom2|txtTo2'),Please enter a promotion start date,calendar.png"
function chkRateDate1(test)
{
formatChar = "|";

var controls = new Array();
 controls =  test.split(formatChar);
 var txtRate1 = getObj(controls[0]).value;
 var txtRate2 = getObj(controls[1]).value; 

    if(txtRate1=="" && txtRate2 != "")
    {
        return false;
    }
    
    if(txtRate1!="" && txtRate2 == "")
    {   
       chkRateDate2(test)
    }
    
    return;
}

function chkRateDate2(cntrl)
{

 formatChar = "|";

 var controls = new Array();
 controls =  test.split(formatChar);
 var txtRate1 = getObj(controls[0]).value;
 var txtRate2 = getObj(controls[1]).value;
 
    if(txtRate1!="" && txtRate2 == "")
    {
        return false;
    }
    else
    {
        return true;
    }
}

function chkRateDate(chkVal)
{

 formatChar = "|";

 var controls = new Array();
 controls =  chkVal.split(formatChar);
 var txtRate1 = getObj(controls[0]).value;
 var txtRate2 = getObj(controls[1]).value;
 
    if(txtRate1!="" && txtRate2 == "")
    {
        return false;
    }
    else
    {
        return true;
    }
}
