﻿
// Array for Validation.
var ajaxValidationServerSideValidation='1';

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
fiterArr[4]=/^(.*?)\.([Xx][Ll][Ss])$/i; // For Excel File
fiterArr[5]=/^(.*?)\.([Jj][Pp][Gg]|[Jj][Pp][Ee][Gg]|[Gg][Ii][Ff])$/i; // For Image
fiterArr[6]=/^(.*?)\.([Dd][Oo][Cc])$/i; // For Word file
fiterArr[7]=/^(.*?)\.([Pp][Dd][Ff])$/i; // For PDF file
// 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><tr><td valign=top width=20px ><img src=";
var divHtmlImg2=" class='png_file' width=16px height=16px align=absmiddle /></td><td><font color='#434343'>";
var divHtmlDiv="</td></tr></table><div class=hint-pointer>&nbsp;</div>";

// Globle variables
var flagShow=false;                          //Use for show validation without button click.
var flag=false;                             //Use for set focus.
var flagFocus=false;                        //Use for hide validation first time when control is focus by code.
var spliter='$';                            //Use for split validation attribute parameter.
var valSpliter=';';                         //Use for split validation attribute.
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="#C1C1C1";                 //Color of control default.
var editorObj;                              //Use for get Editor Id.
var defaultImageUrl=relativePath()+"images/Validation/default.png";      //Use for set default image with error message.
var imageUrl=relativePath()+"images/Validation/default.png";             //Use for set image which you want to display with error message.
var validationGroup="";

// Function ValidateContentText is use for check Editor.
function ValidateContentText()
{
   if(validationGroup=="valMessage")
   {
      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_","");
            getObjValidation(divEditorObj+"_div").style.display="block";
        }
    }
}
function editorBlur( editorInstance )
{ 
    var divEditorObj=editorObj.replace("ctl00_cphContent_","");
    getObjValidation(divEditorObj+"_div").style.display="none";
}

// Function getFormElement is use for get all form element.
function getFormElement(formName,valGroup,showProgressBar,btnId,gridName,dragdropId,ajaxValidationServerSide)
    { 
//getObjValidation(btnId).focus();
    flagShow=true;
    flag=false;
    flagCompare=false;
    setColor=true;
    validationGroup=valGroup;
    var elements=formName.elements; 
  flagFocus=true;
    if(valGroup!=null)
    {
        for (var i=0; i<elements.length; i++)
        { 
         
            if(elements[i].getAttribute("validation")!=null && elements[i].getAttribute("valGroup")==valGroup && 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
            } 
            else
            {
                if(elements[i].id==editorObj)
                    ValidateContentText();
            }
          }
    }
    else
    {
        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
            } 
            else
            {
                if(elements[i].id==editorObj)
                    ValidateContentText();
            }
        }
    }
    
    
    if(flag)
        return false;
/******************************* This else is use for show Progress Bar. **********************************/
    else
    { 
        if(btnId!=null)
            {     
               var chkFileVal=false;
               var controlId="";
               var CheckfileUpload="";
               var Uploadflag=false;
               var textboxId=btnId.id.substring(0,btnId.id.lastIndexOf("_")+1);
              
               if(gridName!=null)
                 {
                   if(gridName.indexOf("ctl00_cphContent_ctrlTeam_grdTeam")>-1)
                   {
                         if(dragdropId!=null && dragdropId != '')
                           CheckfileUpload=gridName+"_"+dragdropId+"_hideFileVal";
                         else                         
                             CheckfileUpload=gridName+"_hideFileVal";
                             
                          
                         if(document.getElementById(CheckfileUpload).value!=undefined && document.getElementById(CheckfileUpload).value!="")
                           {  
                             controlId="ctl00_cphContent_ctrlTeam_";
                             Uploadflag=true;
                           }
                   }
                  
                  else if(gridName.indexOf("dtList")>-1)
                    {
                       chkFileVal=chkFileValueDtlist(gridName);
                    }
                                     
                  else 
                   {
                        chkFileVal=chkFileValue(gridName);
                        if(chkFileVal)
                            controlId=gridName.substring(0,gridName.lastIndexOf("_")+1);
                   
                   }
            
                 }
                  
                 if(ajaxValidationServerSide != undefined)
                 {                
                    if(ajaxValidationServerSide == 'mibteameit')
                    {
                        SaveUpdatedDataMibTeam(btnId);
                    }
                    else if(ajaxValidationServerSide == 'mibteamadd')
                    {
                       SaveAdddDataMibTeam(btnId);
                    }
                    else if(ajaxValidationServerSide == 'pastissuesedit')
                    {
                       AjaxIssueSavePastIssuesEdit(btnId);
                    }
                    else if(ajaxValidationServerSide == 'pastissuesadd')
                    {
                       AjaxSaveIssuePastIssuesAdd();
                    }
                    else if(ajaxValidationServerSide == 'ColumnistArticleAE')
                    {
                       AjaxColumnistArticleAE();
                    }
                    else if(ajaxValidationServerSide == 'facilitatoradd')
                    {
                       AjaxFacUserSave();
                    }
                    else if(ajaxValidationServerSide == 'bloggeradd')
                    {
                       AjaxblogUserSave();
                    }
                     else if(ajaxValidationServerSide == 'meetingadd')
                    {                       
                    AjaxMeetupSaveAdd();
                    }
                     else if(ajaxValidationServerSide == 'UpdateMeeting')
                    {                       
                   AjaxMeetupSaveUpdate(btnId);
                    }
                    
                    else if(ajaxValidationServerSide == 'facilitatoredit')
                    {
                       ajaxValidationServerSideValidation=='1';
                    }
                    
                     else if(ajaxValidationServerSide == 'bloggeredit')
                    {
                       ajaxValidationServerSideValidation=='1';
                    }
                    
                    
                     else if(ajaxValidationServerSide == 'memberdescadd')
                      {
                       ajaxValidationServerSideValidation=='1';
                    }
                 }
        
               if(ajaxValidationServerSideValidation=='1')
               {  
                  if(
                     (Uploadflag || chkFileVal ||((document.getElementById(textboxId+'txtImg')!=null 
                     && document.getElementById(textboxId+'txtImg').value.indexOf("\\")>-1) ||
                     (document.getElementById(textboxId+'txtImg2')!=null && 
                      document.getElementById(textboxId+'txtImg2').value.indexOf("\\")>-1))|| 
                     ((getObjValidation("upldImg1")!=null && 
                     getObjValidation("upldImg1").value.indexOf("\\")>-1)||(getObjValidation("upldImg2")!=null
                      && getObjValidation("upldImg2").value.indexOf("\\")>-1)))||((getObjValidation(textboxId+'hdnImgAE')!=null) && (getObjValidation(textboxId+'hdnImgAE').value!="") ))
                    {    
                    
                      if(getObjValidation('divBusyBox') || getObjValidation(textboxId+'divBusyBox') ||document.getElementById(controlId+"divBusyBox"))
                        {  
                            if(controlId=="")
                                controlId=textboxId;
                           showBusyBoxDiv(controlId,valGroup);
                        }
                   }
               }
            }
            if(ajaxValidationServerSideValidation=='1')
            {  
                return true;
            }
           else
           {
                return false;
           }
      }
    }
/**********************************************************************************************************/


function chkFileValue(gridName)
{
   oGrid=getObjValidation(gridName);
    var rows=oGrid.rows.length;
    for(i=2;i<=rows;i++)
	{		
		if(i<10)
			{
			  ctrli="0" + i;
			}
		else 
			{
			  ctrli= i;
			}
		if(document.getElementById(gridName+"_ctl"+ctrli+"_hideFileVal"))
		    {	
		      if (document.getElementById(gridName+"_ctl"+ctrli+"_hideFileVal").value!="")
		          return true;		   
		    }
		     if(document.getElementById(gridName+"_ctl"+ctrli+"_hideFileVal2"))
		    {	
		      if (document.getElementById(gridName+"_ctl"+ctrli+"_hideFileVal2").value!="")
		          return true;		   
		    }
	}
	return false;
}


function chkFileValueDtlist(Datalist)
{ 
	var dtList=getObjValidation(Datalist);
	var subImages = dtList.getElementsByTagName('IMG');		
	for(i=0;i<(subImages.length/2);i++)
    {	
	    if(i<10)
		    ctrli="0" + i;
	    else
		    ctrli= i;
		  
        if(getObjValidation("ctl00_cphContent_"+Datalist+"_ctl"+ctrli+"_hdnImgName").value!="")
	    {
	        return true;
	    }
    }	
	return false;	
}



function showBusyBoxDiv(controlId,valGroup)
{
        if(controlId!="")
        {
            showdeadcenterdiv('333','138',document.getElementById(controlId+"divBusyBox"),valGroup);
            document.getElementById(controlId+"divBusyBox").style.display='';  
           
       }
        else
        {
            showdeadcenterdiv('333','138',getObjValidation('divBusyBox'),valGroup);
            getObjValidation('divBusyBox').style.display='';   
          
        }
               
      setTimeout("showRotateImg()", 100);

        return false;
}
function showRotateImg()
{   var source= relativePath()+"images/transfer_new.gif";
    document.images["BusyBoxImg1"].src=source;
 }

function showdeadcenterdiv(Xwidth,Yheight,divid,valGroup) 
{ 
// 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.offsetHeight; 
//        centerY =  document.body.offsetWidth; 
       
       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; 
    var topoffset = parseInt(scrolledY,10) + parseInt(Yheight,10); 
    // 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(valGroup=='Add' && (window.location.href.indexOf("book-club-facilitator/home")>-1 || window.location.href.indexOf("admin/meetings")>-1))
  {
  r.top = (topoffset-250) + 'px'; 
   r.left =(leftoffset-150) + 'px'; 
  }
} 



function trim(value) 
{
	return value.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");
}

// Function chkInputText is use for check all inupt with type 'text' according to validation
function chkInputText(ObjInputId,eventValue)
{
    var inputObj=getObjValidation(ObjInputId);
    var valArrInput=new Array();
    var valExpArrInput=new Array();
    
    valArrInput = inputObj.getAttribute("validation").split(valSpliter);
    
    for(var j=0;j<valArrInput.length;j++)
    {
        valExpArrInput=valArrInput[j].split(spliter);
        
        if(valExpArrInput[2]!="''")
            imageUrl=relativePath()+valExpArrInput[2];
        else
            imageUrl=defaultImageUrl;
            
        var Html=divHtmlImg1+imageUrl+divHtmlImg2+valExpArrInput[1]+divHtmlDiv;
        
        switch (valExpArrInput[0].toLowerCase())
        {
            case "required":
                var spaceChk=trim(inputObj.value);
              //  alert(inputObj.id + '  '+inputObj.value);				
                if(inputObj.value=="" || spaceChk =="")
                { 
                    if(eventValue == 'onfocus')
                    {
                        getObjValidation(ObjInputId+"_div").innerHTML=Html;
                        getObjValidation(ObjInputId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                          getObjValidation(ObjInputId+"_div").style.display = "none";
                         // if(setColor)
                             // inputObj.style.borderColor=errorColor;
                    }
                    else
                        inputObj.style.borderColor=errorColor;
                   
                    if(!flag)
                    { 
                        try{
                            inputObj.focus();
                            flag=true;
                            }
                         catch(ex)
                        {
                            return false;
                        } 
                                
                    }
                    return false;
                }
                else
                {
                 
                    getObjValidation(ObjInputId+"_div").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')
                        {
                            getObjValidation(ObjInputId+"_div").innerHTML=Html;
                            getObjValidation(ObjInputId+"_div").style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObjValidation(ObjInputId+"_div").style.display = "none";
                           // if(setColor)
                               // inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObjValidation(ObjInputId+"_div").style.display = "none";                    
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObjValidation(ObjInputId+"_div").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')
                        {
                            getObjValidation(ObjInputId+"_div").innerHTML=Html;
                            getObjValidation(ObjInputId+"_div").style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObjValidation(ObjInputId+"_div").style.display = "none";
                           // if(setColor)
                               // inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObjValidation(ObjInputId+"_div").style.display = "none";                    
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObjValidation(ObjInputId+"_div").style.display = "none";                    
                    if(valArrInput.length==j+1)
                        inputObj.style.borderColor=defaultColor;
                }
            break;
            case "compare":
                var compObj=getObjValidation(valExpArrInput[3]);
                var compTypeIndex=valExpArrInput[4];
                var compOpIndex=valExpArrInput[5];
                var compValue=compObj.value;
                var validateValue=inputObj.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')
                        {
                            getObjValidation(ObjInputId+"_div").innerHTML=Html;
                            getObjValidation(ObjInputId+"_div").style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObjValidation(ObjInputId+"_div").style.display = "none";
                           // if(setColor)
                               // inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObjValidation(ObjInputId+"_div").style.display = "none";                    
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObjValidation(ObjInputId+"_div").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[5]==null)
			        {
		                if(valExpArrInput[4]==null) 
		                {
		                    searchCond = eval(getObjValidation(phoneId+"1").value.length <3 || getObjValidation(phoneId+"2").value.length < 3 || getObjValidation(phoneId+"3").value.length < 4 );
		                }
		                else
		                {
		                    searchCond = eval(getObjValidation(phoneId+"1").value.length <3  || getObjValidation(phoneId+"2").value.length < 3  || getObjValidation(phoneId+"3").value.length < 4  || getObjValidation(phoneId+"Ext").value.length != 0);
		                }   
		                    
                    }
                    else
                    {
	                    searchCond = eval(getObjValidation(phoneId+"1").value.length <3 || getObjValidation(phoneId+"2").value.length < 3  || getObjValidation(phoneId+"3").value.length < 4 );
	                    
                    }//alert(valExpArrInput[6]+'  '+valExpArrInput[4])
                    if(valExpArrInput[6])
                    k=valExpArrInput[6]
			        //for(k=1;k<=3;k++)
			        if(k<=3)
			        {
			            if(k==3)
			              chkNumber=4;
			         
        			    if(searchCond)
			            {   
                            if(getObjValidation(phoneId+k).value.length < chkNumber)
                            {    
                                if(eventValue == 'onfocus')
                                {
                                    getObjValidation(phoneId+"_div").innerHTML=Html;
                                    getObjValidation(phoneId+"_div").style.display = "inline";
                                    getObjValidation(phoneId+k).style.borderColor=errorColor;
                                }
                                else if(eventValue == 'onblur')
                                {
                                      getObjValidation(phoneId+"_div").style.display = "none";
                                     if(setColor)
                                          getObjValidation(phoneId+k).style.borderColor=errorColor;
                                }
                                else
                                {//alert(getObjValidation(phoneId+k).value.length+' '+k)
                                    getObjValidation(phoneId+k).style.borderColor=errorColor;
                                }
                               
                                if(!flag)
                                {
                                    getObjValidation(phoneId+k).focus();
                                    flag=true;
                                }
                                return false;
                            }
                            else
                            {
                                getObjValidation(phoneId+"_div").style.display = "none";                    
                                if(valArrInput.length==j+1)
                                    getObjValidation(phoneId+k).style.borderColor=defaultColor;
                            }
                        }
                        else
                        {
                            getObjValidation(phoneId+"_div").style.display = "none";                    
                            if(valArrInput.length==j+1)
                                getObjValidation(phoneId+k).style.borderColor=defaultColor;
                        }
                    }
            break;
            
            default: 
//                if(inputObj.value!="" || valExpArrInput[0]=='ValidateContentText()')
//                { 
                    if(!eval(valExpArrInput[0]))
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObjValidation(ObjInputId+"_div").innerHTML=Html;
                            getObjValidation(ObjInputId+"_div").style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObjValidation(ObjInputId+"_div").style.display = "none";
                           // if(setColor)
                               // inputObj.style.borderColor=errorColor;
                        }
                        else
                            inputObj.style.borderColor=errorColor;
                          
                        if(!flag)
                        {
                            inputObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObjValidation(ObjInputId+"_div").style.display = "none";                    
                        if(valArrInput.length==j+1)
                            inputObj.style.borderColor=defaultColor;
                    }
//                }
//                else
//                {
//                    getObjValidation(ObjInputId+"_div").style.display = "none";                    
//                    if(valArrInput.length==j+1)
//                        inputObj.style.borderColor=defaultColor;
//                }
        }
    }
}

// Function chkInputFile is use for check all inupt with type 'file' according to validation
function chkInputFile(ObjInputFileId,eventValue)
{
    var inputFileObj=getObjValidation(ObjInputFileId);
    var valArrInputFile=new Array();
    var valExpArrInputFile=new Array();
    
    valArrInputFile = inputFileObj.getAttribute("validation").split(valSpliter);
    
    for(var j=0;j<valArrInputFile.length;j++)
    {
        valExpArrInputFile=valArrInputFile[j].split(spliter);
        
        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')
                    {
                        getObjValidation(ObjInputFileId+"_div").innerHTML=Html;
                        getObjValidation(ObjInputFileId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObjValidation(ObjInputFileId+"_div").style.display = "none";
                       // if(setColor)
                           // inputFileObj.style.borderColor=errorColor;
                    }
                    else
                        inputFileObj.style.borderColor=errorColor;
                   
                    if(!flag)
                    {
                        inputFileObj.focus();
                        flag=true;
                    }
                    return false;
                }
                else
                {
                    getObjValidation(ObjInputFileId+"_div").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')
                        {
                            getObjValidation(ObjInputFileId+"_div").innerHTML=Html;
                            getObjValidation(ObjInputFileId+"_div").style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObjValidation(ObjInputFileId+"_div").style.display = "none";
                           // if(setColor)
                               // inputFileObj.style.borderColor=errorColor;
                        }
                        else
                            inputFileObj.style.borderColor=errorColor;
                              
                        if(!flag)
                        {
                            inputFileObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObjValidation(ObjInputFileId+"_div").style.display = "none";                    
                        if(valArrInputFile.length==j+1)
                            inputFileObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObjValidation(ObjInputFileId+"_div").style.display = "none";                    
                    if(valArrInputFile.length==j+1)
                         inputFileObj.style.borderColor=defaultColor;
                }
            break;
            default:
                if(!eval(valExpArrInputFile[0]))
                {
                    if(eventValue == 'onfocus')
                    {
                        getObjValidation(ObjInputFileId+"_div").innerHTML=Html;
                        getObjValidation(ObjInputFileId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObjValidation(ObjInputFileId+"_div").style.display = "none";
                       // if(setColor)
                           // inputFileObj.style.borderColor=errorColor;
                    }
                    else
                        inputFileObj.style.borderColor=errorColor;
                          
                    if(!flag)
                    {
                        inputFileObj.focus();
                        flag=true;
                    }
                    return false;
                }
                else
                {
                    getObjValidation(ObjInputFileId+"_div").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)
{
    var inputPasswordObj=getObjValidation(ObjInputPasswordId);
    var valArrInputPassword=new Array();
    var valExpArrInputPassword=new Array();
    
    valArrInputPassword = inputPasswordObj.getAttribute("validation").split(valSpliter);
    
    for(var j=0;j<valArrInputPassword.length;j++)
    {
        valExpArrInputPassword=valArrInputPassword[j].split(spliter);
        
        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')
                    {
                        getObjValidation(ObjInputPasswordId+"_div").innerHTML=Html;
                        getObjValidation(ObjInputPasswordId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                          getObjValidation(ObjInputPasswordId+"_div").style.display = "none";
                         // if(setColor)
                             // inputPasswordObj.style.borderColor=errorColor;
                    }
                    else
                        inputPasswordObj.style.borderColor=errorColor;
                   
                    if(!flag)
                    {
                        inputPasswordObj.focus();
                        flag=true;
                    }
                    return false;
                }
                else
                {
                      getObjValidation(ObjInputPasswordId+"_div").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')
                        {
                            getObjValidation(ObjInputPasswordId+"_div").innerHTML=Html;
                            getObjValidation(ObjInputPasswordId+"_div").style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                              getObjValidation(ObjInputPasswordId+"_div").style.display = "none";
                             // if(setColor)
                                 // inputPasswordObj.style.borderColor=errorColor;
                        }
                        else
                            inputPasswordObj.style.borderColor=errorColor;
                          
                        if(!flag)
                        {
                            inputPasswordObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObjValidation(ObjInputPasswordId+"_div").style.display = "none";                    
                        if(valArrInputPassword.length==j+1)
                            inputPasswordObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObjValidation(ObjInputPasswordId+"_div").style.display = "none";                    
                    if(valArrInputPassword.length==j+1)
                        inputPasswordObj.style.borderColor=defaultColor;
                }
            break;
            case "compare":
			    compObj=getObjValidation(valExpArrInputPassword[3]);
                if(compObj.value!="")
                {
                    if(inputPasswordObj.value=="")
                        Html=divHtmlImg1+imageUrl+divHtmlImg2+"Re-enter password"+divHtmlDiv;
                        
                    if(inputPasswordObj.value!=compObj.value)
                    {
                        if(eventValue == 'onfocus')
                        {
                            getObjValidation(ObjInputPasswordId+"_div").innerHTML=Html;
                            getObjValidation(ObjInputPasswordId+"_div").style.display = "inline";
                        }
                        else if(eventValue == 'onblur')
                        {
                            getObjValidation(ObjInputPasswordId+"_div").style.display = "none";
                           // if(setColor)
                               // inputPasswordObj.style.borderColor=errorColor;
                        }
                        else
                            inputPasswordObj.style.borderColor=errorColor;
                          
                        if(!flag)
                        {
                            inputPasswordObj.focus();
                            flag=true;
                        }
                        return false;
                    }
                    else
                    {
                        getObjValidation(ObjInputPasswordId+"_div").style.display = "none";                    
                        if(valArrInputPassword.length==j+1)
                            inputPasswordObj.style.borderColor=defaultColor;
                    }
                }
                else
                {
                    getObjValidation(ObjInputPasswordId+"_div").style.display = "none";                    
                    if(valArrInputPassword.length==j+1)
                        inputPasswordObj.style.borderColor=defaultColor;
                }
            break;  
            default:
                if(!eval(valExpArrInputPassword[0]))
                {
                    if(eventValue == 'onfocus')
                    {
                        getObjValidation(ObjInputPasswordId+"_div").innerHTML=Html;
                        getObjValidation(ObjInputPasswordId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObjValidation(ObjInputPasswordId+"_div").style.display = "none";
                       // if(setColor)
                           // inputPasswordObj.style.borderColor=errorColor;
                    }
                    else
                        inputPasswordObj.style.borderColor=errorColor;
                      
                    if(!flag)
                    {
                        inputPasswordObj.focus();
                        flag=true;
                    }
                    return false;
                }
                else
                {
                    getObjValidation(ObjInputPasswordId+"_div").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)
{
    var selectObj=getObjValidation(ObjSelectId);
    var valArrSelect=new Array();
    var valExpArrSelect=new Array();
    
    valArrSelect=selectObj.getAttribute("validation").split(valSpliter);
    
    for(var j=0;j<valArrSelect.length;j++)
    {
        valExpArrSelect=valArrSelect[j].split(spliter);
        
        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')
                    {
                        getObjValidation(ObjSelectId+"_div").innerHTML=Html;
                        getObjValidation(ObjSelectId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObjValidation(ObjSelectId+"_div").style.display = "none";
                       // if(setColor)
                           // selectObj.style.borderColor=errorColor;
                    }
                    else
					{
                        selectObj.style.borderColor=errorColor; 
                        
						if(!flag)
						{
							selectObj.focus();
							flag=true;
						} 
					}
					if(!flag)
					{
						//selectObj.focus();
						flag=true;
					} 
                    return false;
                }
                else
                {
                    getObjValidation(ObjSelectId+"_div").style.display = "none";
                    if(valArrSelect.length==j+1)
                        selectObj.style.borderColor=defaultColor;
                }
            break;            
            default:
                if(!eval(valExpArrSelect[0]))
                {
                    if(eventValue == 'onfocus')
                    {
                        getObjValidation(ObjSelectId+"_div").innerHTML=Html;
                        getObjValidation(ObjSelectId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObjValidation(ObjSelectId+"_div").style.display = "none";
                       // if(setColor)
                           // selectObj.style.borderColor=errorColor;
                    }
                    else
					{
                        selectObj.style.borderColor=errorColor; 
						if(!flag)
						{
							selectObj.focus();
							flag=true;
						} 
					}
                        
                    if(!flag)
                    {
                       // selectObj.focus();
                        flag=true;
                    } 
                    return false;
                }
                else
                {
                    getObjValidation(ObjSelectId+"_div").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)
{
    var textAreaObj=getObjValidation(ObjTextAreaId);
    var valArrTextArea=new Array();
    var valExpArrTextArea=new Array();
    
    valArrTextArea=textAreaObj.getAttribute("validation").split(valSpliter);
    
    for(var j=0;j<valArrTextArea.length;j++)
    {
        valExpArrTextArea=valArrTextArea[j].split(spliter);
        
        if(valExpArrTextArea[2]!="''")
            imageUrl=valExpArrTextArea[2];
        else
            imageUrl=defaultImageUrl;
        
        var Html=divHtmlImg1+imageUrl+divHtmlImg2+valExpArrTextArea[1]+divHtmlDiv;
        
        switch (valExpArrTextArea[0].toLowerCase())
        {
            case "required":
				var spaceChk=trim(textAreaObj.value);
                if(textAreaObj.value=="" || spaceChk=="")
                {
                    if(eventValue == 'onfocus')
                    {
                        getObjValidation(ObjTextAreaId+"_div").innerHTML=Html;
                        getObjValidation(ObjTextAreaId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObjValidation(ObjTextAreaId+"_div").style.display = "none";
                       // if(setColor)
                           // textAreaObj.style.borderColor=errorColor;
                    }
                    else
                        textAreaObj.style.borderColor=errorColor;
                           
                        
                    if(!flag)
                   { 
                        textAreaObj.focus();
                        flag=true;
                    }                    
                    return false;
                }
                else
                {
                    getObjValidation(ObjTextAreaId+"_div").style.display = "none";
                    if(valArrTextArea.length==j+1)
                        textAreaObj.style.borderColor=defaultColor;
                }
            break;            
            default:
                if(!eval(valExpArrTextArea[0]))
                {
                    if(eventValue == 'onfocus')
                    {
                        getObjValidation(ObjTextAreaId+"_div").innerHTML=Html;
                        getObjValidation(ObjTextAreaId+"_div").style.display = "inline";
                    }
                    else if(eventValue == 'onblur')
                    {
                        getObjValidation(ObjTextAreaId+"_div").style.display = "none";
                       // if(setColor)
                           // textAreaObj.style.borderColor=errorColor;
                    }
                    else
                        textAreaObj.style.borderColor=errorColor;
                        
                    if(!flag)
                    {
                        textAreaObj.focus();
                        flag=true;
                    } 
                    return false;
                }
                else
                {
                    getObjValidation(ObjTextAreaId+"_div").style.display = "none";
                    if(valArrTextArea.length==j+1)
                        textAreaObj.style.borderColor=defaultColor;
                }
        }
    }
}

// Function EnableTip is use for show tip
function EnableTip(ObjName,controlType,focusValue,FocusValidation)
{
    if(getObjValidation(FocusValidation) != null)
    {        
        if(getObjValidation(FocusValidation).value=='0')
        {       
            return;//no need of validation
        }
    }
    
    ObjName=ObjName.id;
//    if(focusValue==0 || (focusValue==1 && flagFocus))
//    {
    if(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 DisableTip(ObjName,controlType)
{
    ObjName=ObjName.id;
    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');
}

// Use for check Valid Date in MM/DD/YYYY format.
function checkDate(controlObj)
{  
    controlObj=controlObj.id;
    try
    {
        var controlValue=getObjValidation(controlObj).value;
        if(controlValue!="")
        {
            var date_Array=controlValue.split("/");

            var monthValue=date_Array[0];
            var dayValue=date_Array[1];
            var yearValue=date_Array[2];
            
            monthValue--;
           
            var chkDate=new Date(yearValue,monthValue,dayValue)
            
            var date=chkDate.getDate();
            var month=chkDate.getMonth();
            var year=chkDate.getFullYear();

            if((date==dayValue)&& (month==monthValue)&& (year==yearValue))
                return true;
            else
                return false;
        }
        else
            return true;
    }
    catch(ex)
    {
        return false;
    } 
}

function chkPostal1(val1, val2)
{
        var oZip1 = eval(getObjValidation(val1));   
        var oZip2 = eval(getObjValidation(val2)); 
        
	    inputStr1 = oZip1.value;
	    inputStr2 = oZip2.value;
	            
        if(inputStr1.length>0)
        {
            var objRegExp = /^[a-zA-Z]{1}\d{1}[a-zA-Z]{1}/;
         
            if(objRegExp.test(inputStr1)==false  )
             {
	            return false
             }	           
         }
         
         if(inputStr1.length==0 && inputStr2.length>0)
         {
            return false;
         } 
    	         
	    return true;
}
    
    function chkPostal2(val1, val2)
{

        var oZip1 = eval(getObjValidation(val1));   
        var oZip2 = eval(getObjValidation(val2)); 
        
	    inputStr1 = oZip1.value;
	    inputStr2 = oZip2.value;
     
        if(inputStr2.length>0 )
        {
            
            var objRegExp1=/^\d{1}[a-zA-Z]{1}\d{1}/;	
	
            if( objRegExp1.test(inputStr2)==false )
             {
	            return false
             }	             
         }   
         
         if(inputStr1.length>0 && inputStr2.length==0)
         {
            return false;
         } 
    	         
	    return true;
}       
// Function for get Object    
function getObjValidation(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 SaveUpdatedDataMibTeam(saveId)
{
    var rowsaveId=saveId.id.substring(0,saveId.id.lastIndexOf("_")+1);
    MibTeamId=saveId.id.substring(saveId.id.lastIndexOf("grdTeam")+8,saveId.id.lastIndexOf("_"));
    var returnValue=AjaxExistance(MibTeamId,getObjMIB(rowsaveId+"txtNameEdit").value,4,"Name already exists.",2,'',rowsaveId)
    
    if(returnValue==false)
        {         
            ajaxValidationServerSideValidation='0';
         
        }  
        else
        {
            ajaxValidationServerSideValidation='1';
        }
}
function SaveAdddDataMibTeam(saveId) 
{    
    var rowsaveId=saveId.id.substring(0,saveId.id.lastIndexOf("_")+1);	
    var returnValue=AjaxExistance(0,getObjMIB("ctrlTeam_txtName").value,4,"Name already exists.",1,null,rowsaveId)
   
    if(returnValue==false)
        {
              ajaxValidationServerSideValidation='0';
        }
        else
        {
            ajaxValidationServerSideValidation='1';
        }
}
function AjaxIssueSavePastIssuesEdit(editId) 
    {    
          var rowEditId=editId.id.substring(0,editId.id.lastIndexOf("_")+1);
          var Eventname= getObjMIB(rowEditId+"txtTitle").value;
          var returnValue=AjaxExistance(getObjMIB("ctrlTeam_hdnId").value,Eventname,3,"The Issue Name you have entered has already been assigned, please try again",null,null,rowEditId)
          
          if(returnValue==false)
            {         
                ajaxValidationServerSideValidation='0';
             
            }  
            else
            {
                ajaxValidationServerSideValidation='1';
            }
    }
    
function AjaxSaveIssuePastIssuesAdd()
{
    var returnValue=AjaxExistance(getObjMIB("ctrlTeam_hdnId").value,getObjMIB("ctrlTeam_txtTitle").value,3,"The Issue Name you have entered has already been assigned, please try again")
    if(returnValue==false)
    {
          ajaxValidationServerSideValidation='0';
    }
    else
        ajaxValidationServerSideValidation='1';

}
   function AjaxColumnistArticleAE() 
    {    

    var returnValue=AjaxExistance(getObjMIB("hdnId").value,getObjMIB("txtArticleName").value,9,"Article Name already exists.",0,getObjMIB("hdnColumnistId").value)

     if(returnValue==false)
    {
          ajaxValidationServerSideValidation='0';
    }
    else
        ajaxValidationServerSideValidation='1';
 }
 
 
function AjaxFacUserSave() 
{    //check terms checkbox
            //check username existance
          
    var returnValue=AjaxExistance(0,getObjMIB("ctrlTeam_txtUsername").value,5,"Sorry the user name you have entered has already been taken, please try a different one")

    if(returnValue==false)
    {
          ajaxValidationServerSideValidation='0';
    }
    else
        ajaxValidationServerSideValidation='1';
        
}

 function AjaxMeetupSaveAdd() 
    {   
        var returnValue=AjaxExistance(getObjMIB("ctrlTeam_ctrlMeeting_hdnMeetingId").value,getObjMIB("ctrlTeam_ctrlMeeting_txtBook").value,20,"Meeting already exists.")
        
            if(returnValue==false)
        {
              ajaxValidationServerSideValidation='0';
        }
        else
            ajaxValidationServerSideValidation='1';
    }
    
    function AjaxMeetupSaveUpdate(editId) 
    {    
          var rowEditId=editId.id.substring(0,editId.id.lastIndexOf("_")+1);
         
            var returnValue=AjaxExistance(getObjMIB(rowEditId+"hdnMeetingId").value,getObjMIB(rowEditId+"txtBook").value,20,"Meeting already exists.",null,null,rowEditId)
        
            if(returnValue==false)
        {
              ajaxValidationServerSideValidation='0';
        }
        else
            ajaxValidationServerSideValidation='1';
    }    
        
function AjaxblogUserSave() 
{    //check terms checkbox
            //check username existance
          
    var returnValue=AjaxExistance(0,getObjMIB("ctrlblog_txtUsername").value,5,"Sorry the user name you have entered has already been taken, please try a different one")

    if(returnValue==false)
    {
          ajaxValidationServerSideValidation='0';
    }
    else
        ajaxValidationServerSideValidation='1';
        
}
  
