﻿
///***********************VALIDATION.JS*************************///


/*
   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>

*/

function RelativePath()
{  
    var url = self.location.href;
    url = url.toLowerCase();
    var path = '';
     
    // determine the server   
    var local = 'localhost/';
    var server = 'server/';
    var theperimeter  = 'perimeter-com.sitepreview.ca/';
    var perimeter  = 'www.perimeterbus.com/';
         
    if(url.lastIndexOf(local) > 1)
        path = "http://localhost/PerimeterReservation/";
    else if(url.lastIndexOf(theperimeter) > 1)
        path = "http://perimeter-com.sitepreview.ca/";  
    else if(url.lastIndexOf(perimeter) > 1)
        path = "http://www.perimeterbus.com/"; 
    
    return path;
}



// 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]=/^(.*?)\.([Mm][Pp][Ee][Gg]|[Ww][Mm][Vv]|[Mm][Oo][Vv]|[Ww][Aa][Vv])$/i; // For Image
fiterArr[4]=/^\d+(\.\d{1,2})?$/i; // For 2 place decimal
// 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=";
var divHtmlImg2=" width=16px height=16px 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="#FF0000";                   //Color of control after error.
var defaultColor="#B5D5D9";                 //Color of control default.
var editorObj;                              //Use for get Editor Id.
var defaultImageUrl= RelativePath() + "images/Validations/default.png";      //Use for set default image with error message.
var imageUrl=RelativePath() +"images/Validations/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 checkValUserName() 
//{
// if(document.getElementById("ctl00_cphContent_txtUserName").value!="")
// {
//	var str;
//	var str = new String(document.getElementById("ctl00_cphContent_txtUserName").value);	
//	var mikExp = /[\`\~\!\@\#\$\%\^\&\*\(\)\+\=\|\\\{\}\[\]\:\;\"\'\<\>\,\/\?\' ']/;
//	
//	if(str.search(mikExp) != -1)
//	 {
//	   return false ; // invalid string
//	 }
//	else
//	{ 
//		return true ; // valid string
//	}	
//  }
//	
//}



function editorBlur( editorInstance )
{ 
    var divEditorObj=editorObj.replace("ctl00_cphContent_","");
    getObj("div_"+divEditorObj).style.display="none";
}
var checkEmptyNotes=0;
// Function getFormElement is use for get all form element.

function getFormElement(formName,btnId,chkEmptyNotes,valGroup,gridName)
{

    if(chkEmptyNotes!=null)
        checkEmptyNotes=chkEmptyNotes;     
    flagShow=true;
    flag=false;
    flagCompare=false;
    setColor=true;    
    var elements=formName.elements;     
    if(valGroup!=null)
    {
        for (var i=0; i<elements.length; i++)
        { 
            if(elements[i].getAttribute("validation")!=null && elements[i].getAttribute("valGroup")==valGroup)
            {                
                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=="Choose")
                    chkSelect(elements[i].id,'ButtonClick');//for dropdown
                if(elements[i].type=="textarea")
                    chkTextArea(elements[i].id,'ButtonClick');//for multiline textbox
            } 
            else
            {
                if(elements[i].id==editorObj)
                    ValidateContentText();
            }
        }
    }
    else
    {
        for (var i=0; i<elements.length; i++)
        { 
        
            if(elements[i].getAttribute("validation")!=null)
            {                
                if(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=="Choose")
                    chkSelect(elements[i].id,'ButtonClick');//for dropdown
                if(elements[i].type=="textarea")
                    chkTextArea(elements[i].id,'ButtonClick');//for multiline textbox
                }
            } 
            else
            {
                
                if(elements[i].id==editorObj)
                    ValidateContentText();
            }
        }
    } 
    
    if(flag)
    {
        return false;
    }
    else
        {            
           if(btnId!=null)
            {               
              var chkFileVal=false;
              if(gridName!=null)
                chkFileVal=chkFileValue(gridName);
             
             if(chkFileVal || (document.getElementById('ctl00_cphContent_grdUploadFile_ctl02_txtAttachment')!=null && (document.getElementById('ctl00_cphContent_grdUploadFile_ctl02_TxtAttach').value.indexOf("\\")>-1)) || (document.getElementById('ctl00_cphContent_dgiAttachments_ctl02_TxtAttach')!=null && (document.getElementById('ctl00_cphContent_dgiAttachments_ctl02_TxtAttach').value.indexOf("\\")>-1)) || ((getObj("fluUploadFirst")!=null && getObj("fluUploadFirst").value.indexOf("\\")>-1)) || ((getObj("fluUploadSecond")!=null && getObj("fluUploadSecond").value.indexOf("\\")>-1)) || ((getObj("fluUploadThird")!=null && getObj("fluUploadThird").value.indexOf("\\")>-1)))
             {
                if (window.navigator.userAgent.indexOf("Firefox") <= -1)
                {
                    getObj("BusyBoxIFrame").style.display="inline";
                    busyBox.Show();
                    
                }
                else if(getObjSW('divBusyBox'))
                {
                    showBusyBoxDiv()
                }
//                getObj("BusyBoxIFrame").style.display="inline";
//                busyBox.Show();
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(btnId, '', true, '', '', false, false));
             
              }
        }
        return true;
    }
}
function showBusyBoxDiv()
{
//      if (window.navigator.userAgent.indexOf("Firefox") > -1)
//        {
//            getObjSW('divBusyBox').style.left= ((parseInt(window.innerWidth) /2) - parseInt(165)) + 'px'
//            getObjSW('divBusyBox').style.top= ((parseInt(window.innerHeight) /2)) + 'px'
//        }
//        else
//        {
//         getObjSW('divBusyBox').style.left= ((parseInt(document.body.clientWidth) /2) - parseInt(165)) + 'px'
//         getObjSW('divBusyBox').style.top= ((parseInt(document.body.clientHeight) /2) - parseInt(84)) + 'px'            
//        }

        showdeadcenterdiv('333','138',getObjSW('divBusyBox'));
        getObjSW('divBusyBox').style.display='block';   
        //setTimeout('document.images["BusyBoxImg1"].src="<%=ResolveUrl("images/transfer/transfer.gif")%>"', 10);    
        return false;
}

  function showdeadcenterdiv(Xwidth,Yheight,divid) { 
// First, determine how much the visitor has scrolled 

var scrolledX, scrolledY; 
if( self.pageYoffset ) { 
scrolledX = self.pageXoffset; 
scrolledY = self.pageYoffset; 
} else if( document.documentElement && document.documentElement.scrollTop ) { 
scrolledX = document.documentElement.scrollLeft; 
scrolledY = document.documentElement.scrollTop; 
} else if( document.body ) { 
scrolledX = document.body.scrollLeft; 
scrolledY = document.body.scrollTop; 
} 

// Next, determine the coordinates of the center of browser's window 

var centerX, centerY; 
if( self.innerHeight ) { 
centerX = self.innerWidth; 
centerY = self.innerHeight; 
} else if( document.documentElement && document.documentElement.clientheight ) { 
centerX = document.documentElement.clientWidth; 
centerY = document.documentElement.clientheight; 
} else if( document.body ) { 
centerX = document.body.clientWidth; 
centerY = document.body.clientHeight; 
} 

// Xwidth is the width of the div, Yheight is the height of the 
// div passed as arguments to the function: 
var leftoffset = scrolledX + (centerX - Xwidth) / 2; 
var topoffset = scrolledY + (centerY - Yheight) / 2; 
// the initial width and height of the div can be set in the 
// style sheet with display:none; divid is passed as an argument to // the function 
//var o=document.getElementById(divid); 
var o=divid; 
var r=o.style; 
r.position='absolute'; 
r.top = topoffset + 'px'; 
r.left = leftoffset + 'px'; 
if (window.navigator.userAgent.indexOf("Firefox") <= -1)
    r.top = (centerY - 300 )+ 'px'; 

    
//r.display = "block"; 
} 

function chkFileValue(gridName)
{

    oGrid=eval("getObj('"+gridName+"')");
    var rows=oGrid.rows.length;
    var _FileCount = 0;
    
    for(i=2;i<=rows;i++)
	{		
		if(i<10)
			{ctrli="0" + i;}
		else
			{ctrli= i;}
			if(getObj(gridName+"_ctl"+ctrli+"_hideFileVal").value!="")
		    {	
		       _FileCount++;			
		       //return true;		   
		    }
 		if(getObj("hdnFileBackCount"))
		{
		    if(getObj(gridName+"_ctl"+ctrli+"_hideFileVal").value!="")
		    {	
		       _FileCount++;			
		       //return true;		   
		    }
		 }
		else
		{
		  if(getObj(gridName+"_ctl"+ctrli+"_hideFileVal").value!="")
		    {	
		      return true;		   
		    }
		} 
		    
	}
	 
	if(getObj("hdnFileBackCount") && _FileCount > getObj("hdnFileBackCount").value)
	    return true;
	    
	return false;
}


function chkFileValue1(Datalist)
{ 

	var oGrid,sGrid,dtList;	
	dtList=eval("getObj('dtList')");
	var subImages = dtList.getElementsByTagName('IMG');		
	
    for(i=0;i<(subImages.length/3);i++)
    {	
	    if(i<10)
		    ctrli="0" + i;
	    else
		    ctrli= i;
        if(getObj("ctl00_cphContent_"+Datalist+"_ctl"+ctrli+"_hdnImgName").value!="")
	    {
	        return true;
	    }
    }	
	return false;	
}


// 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 ==" ")
                { 
                  
                    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://","").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')
                        {
                            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(validateValue!=="" && ObjInputId=="txtProposalDate")
                {
                    var today =	new	Date()
                    var dateNow	 = today.getDate()
                    var monthNow = today.getMonth()
                    var yearNow	 = today.getFullYear()
                    monthNow++;
                    if(dateNow<10)
                        dateNow="0"+dateNow;
                    if(monthNow<10)
                        monthNow="0"+monthNow;
                    compObj.value=monthNow+"/" + dateNow + "/" + yearNow ;                    
                }
                else if(validateValue=="" && ObjInputId=="txtProposalDate")
                {
                 compObj.value=""   
                }
                if(compObj.value!="")
                {
                    if(compTypeArr[compTypeIndex]=="Integer")
                    {                                              
                        compValue=parseFloat(compValue);
                        validateValue=parseFloat(validateValue);                        
                    }
                    else 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()' || (valExpArrInput[0].indexOf('CheckNoteSubject') )>-1 || valExpArrInput[0]=='CheckNote()' || valExpArrInput[0]=='CheckProfileNote()' || valExpArrInput[0]=='CheckNoteText()' || valExpArrInput[0].indexOf('checkTelephoneFormat') > -1 || valExpArrInput[0].indexOf('checkNote')>-1)
                { 
                    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.length==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;
                }
            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 == 'Choose')
                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 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 == 'Choose')
        chkSelect(ObjName,'onblur');
    else if(controlType == 'password')
        chkInputPassword(ObjName,'onblur');
    else if(controlType == 'file')
            chkInputFile(ObjName,'onblur');
}


     function CheckNoteSubject(strControlId)
     {    
        var controls=new Array()   
        
        controls=strControlId.split("?");
        
        var spaceChk=document.getElementById(controls[1]).value.substring(0,1);
     
        if(checkEmptyNotes==1)
        {  
            if(document.getElementById(controls[1]).value.trim()=='')
            {            
                return false;
            }
            else
            {            
                return true;
            }
        }
       
       if(checkEmptyNotes==2 || checkEmptyNotes==0)
       {          
            if(document.getElementById(controls[0]).value.trim()!='')
            {     
                if(document.getElementById(controls[1]).value.trim()=='' )
                {                 
                    return false;
                }
                else
                {             
                    return true;
                }
            }
            else
            {            
                return true;
            }
        }
     }


// Custom validation Function 
function customVal(Obj)
{
    if(document.getElementById(Obj).value=="")
        return false;
    else
        return true;
}
           
// Function for get Object    
function getObj(objID) 
{
    var orgObjId = objID.replace("ctl00_usrctrlBookingHeader_","");
 
    if (document.getElementById)
    {
        if (document.getElementById(objID)==null)
            objID="ctl00_cphContent_"+objID; 
        if(document.getElementById(objID)==null)
            objID="ctl00_usrctrlBookingHeader_"+orgObjId;             
        if(document.getElementById(objID)==null)
            objID = orgObjId;
        return document.getElementById(objID)
    }
    else if (document.all)
    {
        if (document.all(objID)==null)
            objID="ctl00_cphContent_"+objID;  
        if(document.getElementById(objID)==null)
            objID="ctl00_usrctrlBookingHeader_"+orgObjId;             
        if(document.getElementById(objID)==null)
            objID = orgObjId;
         
        return document.all[objID];
    }
    else if (document.layers)
    {
        if (document.layers(objID)==null)
            objID="ctl00_cphContent_"+objID;  
        if(document.getElementById(objID)==null)
            objID="ctl00_usrctrlBookingHeader_"+orgObjId;             
        if(document.getElementById(objID)==null)
            objID = orgObjId;
            	    
        return document.layers[objID];
    }
}    