﻿

// 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[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";

// 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 align=absmiddle />&nbsp;</td><td><font color='#ffffff' size='2pt'>";
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="#FF0000";                   //Color of control after error.
var defaultColor="#5D3919";                 //Color of control default.
var editorObj;                              //Use for get Editor Id.
var defaultImageUrl="../../images/Validation/default.png";      //Use for set default image with error message.
var imageUrl="../../images/Validation/default.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;
    flag=false;
    flagCompare=false;
    setColor=true;
    
    var elements=formName.elements; 
   
    for (var i=0; i<elements.length; i++)
    { 
        if(elements[i].getAttribute("validation")!=null && elements[i].style.display!='none')
        {
             
            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)
    {
     if((getObj("hdnBusyBoxImg")!=null && getObj("hdnBusyBoxImg").value!="" && getObj("txtName").value!="") )
      {
            return true; 
      }
       
          return false;
       
    }
    else
    {
        
        if(btnId!=null)
        {
           
            //            if((getObj("TextImg").value.indexOf("\\")>-1) || (getObj("TextFile1").value.indexOf("\\")>-1) || (getObj("TextFile2").value.indexOf("\\")>-1) || (getObj("TextFile3").value.indexOf("\\")>-1))
            //            {
            //                getObj("BusyBoxIFrame").style.display="inline";
            //                parent.busyBox.Show();
            //                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(btnId, '', true, '', '', false, false));
            //               
            //            }

 if((getObj("hdnBusyBoxImg")!=null && getObj("hdnBusyBoxImg").value!="") )
            {
              //alert(getObj("hdnBusyBoxImg").value+' nn');
               
                if(parent.busyBox!=null)
                {
                    parent.busyBox.Show();
                    try{
                          WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(btnId, '', true, '', '', false, false));
                        }
                    catch(er){}
                }
            }
        }
        return true;
    }
}

// Function chkInputText is use for check all inupt with type 'text' according to validation
//function RateDatecheck(txtFrom)
//{

//if(getObj("txtFrom").value=="")
//{

// return false;
//}
//}

//function chkRateDate(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 true;
//    }
//    if(txtRate1!="" && txtRate2 == "")
//    {
//       return false;
//    }
//     if(txtRate1=="" && txtRate2 != "")
//    {
//    
//        return false;
//    }
//     if(txtRate1!="" && txtRate2 != "")
//    {
//    
//        return true;
//    }
//}

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;
    }
    else
    {
        return true;
    }
}

function chkRateDate2(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;
    }
    else
    {
        return true;
    }
}


function chkInputText(ObjInputId,eventValue)
{
//    if(ObjInputId.indexOf('dlCategory')>-1)
//        ObjInputId=ObjInputId;
//    else

        ObjInputId=ObjInputId.replace("ctl00_cphContent_","");
        
    var inputObj=getObj(ObjInputId);
    var valArrInput=new Array();
    var valExpArrInput=new Array();
    
    valArrInput = inputObj.getAttribute("validation").split(';');
    
//    if(ObjInputId.indexOf('dlCategory')>-1)
//        divHtmlImg2=" class='png_file' width=16px height=16px align=absmiddle />&nbsp;</td><td><font color='black' size='2pt'>";
    
    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 ==" ")
                { 
                  //alert('aa '+ObjInputId.indexOf('dlCategory'));
                    if(eventValue == 'onfocus')
                    { //alert('1');
                        if(ObjInputId.indexOf('dlCategory')>-1)
                        {
                            getObj(ObjInputId+"_div").innerHTML=Html;
                            getObj(ObjInputId+"_div").style.display = "inline";
                        }
                        else
                        {
                            getObj("div_"+ObjInputId).innerHTML=Html;
                            getObj("div_"+ObjInputId).style.display = "inline";
                        }
                    }
                    else if(eventValue == 'onblur')
                    { //alert('2');
                          if(ObjInputId.indexOf('dlCategory')>-1)
                                getObj(ObjInputId+"_div").style.display = "none";
                          else
                                getObj("div_"+ObjInputId).style.display = "none";
                          if(setColor)
                              inputObj.style.borderColor=errorColor;
                    }
                    else
                    {//alert(inputObj.id+' 3');
                        inputObj.style.borderColor=errorColor;
                    }
                    
                    if(!flag)
                    {//alert(flag+' raar '+inputObj.id);
//                        if(ObjInputId.indexOf('dlCategory')>-1)
//                            getObj(ObjInputId).focus();
//                        else
                            try{
                            inputObj.focus();                            
                            flag=true;
                            }
                            catch(er)
                            {
                                flag=false;
                            }
                    }
                    
                    return false;
                }
                else
                {
                    if(ObjInputId.indexOf('dlCategory')>-1)
                                getObj(ObjInputId+"_div").style.display = "none";
                          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!="")
                {
                    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')
                        {
                            if(ObjInputId.indexOf('dlCategory')>-1)
                            {
                                getObj(ObjInputId+"_div").innerHTML=Html;
                                getObj(ObjInputId+"_div").style.display = "inline";
                            }
                            else
                            {
                                getObj("div_"+ObjInputId).innerHTML=Html;
                                getObj("div_"+ObjInputId).style.display = "inline";
                            }
                        }
                        else if(eventValue == 'onblur')
                        {
                            if(ObjInputId.indexOf('dlCategory')>-1)
                                getObj(ObjInputId+"_div").style.display = "none";
                            else
                                getObj("div_"+ObjInputId).style.display = "none";
                           
                            if(setColor)
                                inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            try{
                            inputObj.focus();
                            flag=true;
                            }
                            catch(er)
                            {
                                flag=false;
                            }
                        }
                        return false;
                    }
                    else
                    {
                        if(ObjInputId.indexOf('dlCategory')>-1)
                          getObj(ObjInputId+"_div").style.display = "none";
                        else
                          getObj("div_"+ObjInputId).style.display = "none";                   
                        
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    if(ObjInputId.indexOf('dlCategory')>-1)
                       getObj(ObjInputId+"_div").style.display = "none";
                    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;
                    }
                    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(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;
            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 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(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 RelativePath()
{

    // Remove any frames
//    if (top.location != self.location) {
//      top.location = self.location;
//    }

    var url = self.location.href;
    url = url.toLowerCase();
    var path = '';
    
    // determine the server   
    var local = 'localhost/';
    var live  = 'hotelroyalempire.com/';
    
    if(url.lastIndexOf(local) > 1)
        path = "http://localhost/RoyalEmpire/";
    else if(url.lastIndexOf(live) > 1)
        path = "http://hotelroyalempire.com//";
  
    
    return path;
}

