﻿/*  Validation  */  
var isRequiredValid;   // flag to test if require field validator is parsed
var isChangeCalled;
var isvalidated = false;
var isSameValidator;
var isSame ;
var isValidDD; // for dropdown
var sessioncheck;  //to hold is the session is exist ot not

Window.onDomReady( function(){   
   var arr = $$('span');      // 1. Get all span tag elements as array
   var setbg=false;
   arr.each(function(item){
	   if(item.getProperty('class') == 'errormsg' || item.getProperty('class') == 'check_valid' ){	// 2. Check if span element has validator class
			var ctrl = $(item.controltovalidate);              // Get controls in the page
			if(ctrl.innerHTML.toLowerCase().match("checkbox")=="checkbox"){	// Add events to check box
			    ctrl.addEvent('click',function(e){		   
			        if(CheckBoxListValidatorEvaluateIsValid(item) == true){                		                        
			             removeyellowbg(item.getNext());	
			             item.style.display = "none";	   	                       
			        }else{
			             setyellowbg(item.getNext());		
			             item.style.display = "inline";	
			        }
			     });	
			 }else if(ctrl.innerHTML.toLowerCase().match("radio")=="radio" || ctrl.getProperty('type')=="checkbox"){ // Add events to radio buttons
			     ctrl.addEvent('click',function(e){
			        if(ctrl.getProperty('type')=="checkbox"){
			             if(CheckBoxValidatorEvaluateIsValid(item) == true){    
			                 if($(item.controltovalidate).checked){		                            		                        
			                     removeyellowbg(item.getNext());	
			                     item.style.display = "none";	
			                  }	                       
			              }else{
			                  if(!($(item.controltovalidate).checked)){
			                     setyellowbg(item.getNext());		
			                     item.style.display = "inline";	
			                  }
			              }			                
			         }else{
			              if(RequiredFieldValidatorEvaluateIsValid(item) == true){  		                           
			                  if(item.style.display == 'none')
			                      removeyellowbg(item.getNext());
			              }else{
			                  if(item.style.display == 'inline')
			                      setyellowbg(item.getNext());		
			              }
			          }
			      });	    
			 }else if(ctrl.innerHTML.toLowerCase().match("option")=="option"){  // Add events to dropdown list
			      ctrl.addEvent('change',function(e){
			          if(typeof(item.controltocompare)=="string" ){		               
			               var comparectrl = item.controltocompare;
			               if($(comparectrl).innerHTML.toLowerCase().match("option")=="option"){
			                    $(comparectrl).addEvent('change',function(e){
			                        if(!CompareValidatorEvaluateIsValid(item) == true){
			                             if(item.style.display =="inline")
			                                 setyellowbg(item.getNext());	
			                         }else{
			                             if(item.style.display =="none"){
			                                 if(($(item.controltovalidate).value != 0)&&($(item.controltocompare).value != 0))
			                                      removeyellowbg(item.getNext());
			                             }
			                         }
			                     });
			                }
			               if(!CompareValidatorEvaluateIsValid(item) == true){
			                    if(item.style.display =="inline"){
			                        setyellowbg(item.getNext());
			                        isValidDD = false;
			                    }
			               }else{
			                    if(item.style.display =="none"){
			                        if(($(item.controltovalidate).value != 0)&&($(item.controltocompare).value != 0))
			                            removeyellowbg(item.getNext()); 			                            
			                    }
			               }
			          }else if(typeof(item.clientvalidationfunction)=="string"){
			               if(!CustomValidatorEvaluateIsValid(item) == true){		
			                    if(item.style.display =="inline")	                        
			                        setyellowbg(item.getNext());
			               }else{
			                    if(item.style.display =="none")
			                        removeyellowbg(item.getNext());
			               }
			          }else{
			               if(isValidDD != false){
			                    if(RequiredFieldValidatorEvaluateIsValid(item) == true){		
			                        if(item.style.display =="none")
			                            removeyellowbg(item.getNext());
			                    }else{
			                        if(item.style.display =="inline")
			                            setyellowbg(item.getNext());
			                    }
			               }
			          }    		
			      });
			}else{                    // Add events to text box
			      ctrl.addEvent('blur',function(e){
			          if(isSameValidator == item.getProperty('id'))
			        	   isvalidated = false;
			          if (!(item.controltovalidate == isSame)){
			               isvalidated = false;
			               isSame = item.controltovalidate;
			               isSameValidator = item.getProperty('id');
			          }
			          if(typeof(item.validationexpression) == "string"){
			               if (isvalidated == false){
			                   if(!RegularExpressionValidatorEvaluateIsValid(item) == true){	
			                        isvalidated = true;     
			                        setyellowbg(item.getNext());
			                        item.style.display ="inline";                        		                       			                       
			                   }else{		                                        
			                        item.style.display ="none";                       			                 
			                        removeyellowbg(item.getNext());
			                   }
			               }
			          }else if(typeof(item.controltocompare)=="string" ){
			               if (isvalidated == false){
			                   if(!CompareValidatorEvaluateIsValid(item) == true){
			                        isvalidated = true;     
			                        setyellowbg(item.getNext());
			                        item.style.display ="inline";
			                   }else{
			                                removeyellowbg(item.getNext());
			                                item.style.display ="none";
			                   }
			               } 
			          }else if(typeof(item.maximumvalue) == "string"){ 
			               if(!RangeValidatorEvaluateIsValid(item) == true){	
			                   isvalidated = true;			                              
			                   setyellowbg(item.getNext());
			                   item.style.display ="inline";		                       			                       
			               }else{		                                      
			                   item.style.display ="none";                      			                 
			                   removeyellowbg(item.getNext());
			               }
			           }else if(typeof(item.clientvalidationfunction)=="string"){
			               if (isvalidated == false){
			                   if(!CustomValidatorEvaluateIsValid(item) == true){		
			                        isvalidated = true;                             
			                        setyellowbg(item.getNext());
			                        item.style.display ="inline";
			                   }else{
			                        removeyellowbg(item.getNext());
			                        item.style.display ="none";
			                   }
			                }
			           }else if(typeof(item.minimumNumberOfSelectedCheckBoxes)=="string" || typeof(item.mustBeChecked)=="string"){
			                if (isvalidated == false){
			                    if(!CheckBoxListValidatorEvaluateIsValid(item) == true){
			                         isvalidated = true; 
			                         setyellowbg(item.getNext());
			                         item.style.display ="inline";
			                    }else{
			                         removeyellowbg(item.getNext());
			                         item.style.display ="none";
			                    }
			                 }
			           }else{
			                if (isvalidated == false){
			                    if(RequiredFieldValidatorEvaluateIsValid(item) == true ){		
			                          removeyellowbg(item.getNext());	
			                          item.style.display ="none";
			                          isvalidated = false; 
			                    }else{		
			                          if(item.style.display == "inline"){                    
			                               isvalidated = true;             			                           
			                               setyellowbg(item.getNext());
			                               item.style.display ="inline";
			                          }
			                          if(item.enabled == true)
			                               setTimeout("addYellowbg('"+item.getProperty('id')+"');",50)  
			                    }
			                }
			                 
			          }    
			        });			    
			    }
			} 
		}
	);
});
function addYellowbg(item){
    if($(item).style.display == "inline")
          setyellowbg($(item).getNext());
}
//------Function to add yellowbg class next to validator control
function setyellowbg(item)
{
     while(item.getProperty('class') == 'errormsg' || item.getProperty('class') == 'check_valid' || item.getTag() != "span"){
          item=item.getNext();     
     } 	
     if(item.hasClass('errorlbl'))
          item.removeClass('errorlbl');    
     item.addClass('yellowbg');      
}
//------Function to remove yellowbg class next to validator control
function removeyellowbg(item){
     while(item.getProperty('class') == 'errormsg' || item.getProperty('class') == 'check_valid' || item.getTag() != "span"){
          item=item.getNext();     
     }
     item.removeClass('yellowbg');
}  
//------ Function to add yellow back ground to labelon click of next button
function Validate(){
     //membertype is used in session out validation for create new account page
     var membertype = GetCookie('membertype');
     //To check for session out
     sessioncheck = SessionCheckRequest();
     if (sessioncheck == 'InValid' && !(membertype == undefined || membertype == false)){
	      window.location.href = virdirectory + "/Default.aspx";
	 }else{   
          var arr = $$('span');
          var setbg=false;
		  arr.each(function(item){
			   if(setbg && !((item.getProperty('class') == 'errormsg') || (item.getProperty('class') == 'check_valid'))){	
			        item.addClass('yellowbg');
			        setbg=false;	        
			   }else{
			        item.removeClass('yellowbg');
			   }
			   if(item.getProperty('class') == 'errormsg' || item.getProperty('class') == 'check_valid' ){	
			        if(typeof(item.validationexpression) == "string"){
			             if(!RegularExpressionValidatorEvaluateIsValid(item) == true){
			                 setbg=true;
			                 item.style.display = "inline";
			             }
			        }else if(typeof(item.controltocompare)=="string"){
			             if(!CompareValidatorEvaluateIsValid(item) == true)		                   
			                 setbg=true;
			        }else if(typeof(item.clientvalidationfunction)=="string"){
			             if(!CustomValidatorEvaluateIsValid(item) == true)
			                 setbg=true;
			        }else if(typeof(item.minimumNumberOfSelectedCheckBoxes)=="string"){
			             if(!CheckBoxListValidatorEvaluateIsValid(item) == true)
			                 setbg=true;
			        }else if(typeof(item.mustBeChecked)=="string"){
			             if(!CheckBoxValidatorEvaluateIsValid(item) == true)
			                 setbg=true;
			        }else if(typeof(item.maximumvalue) == "string"){ 
			             if(!RangeValidatorEvaluateIsValid(item) == true)
			                 setbg = true;   
                    }else{
			             if(!RequiredFieldValidatorEvaluateIsValid(item) == true){
			                 if(item.enabled != false)
			                     setbg=true;
			             }
			        }
			       if(((item.getProperty('class') == 'check_valid' )) && (item.enabled == false)){
			             item.removeClass('yellowbg');
			             setbg=false;
			       }	
			    } 
			});
		} 	
}
//------- Function to check invalid field to close prompt during resubmit
function IsPageValid(){
    var arr = $$('span.yellowbg');
    if(arr.length > 0)
        MoodalBox.close();
}   
/*******************   MOODAL BOX PROMPT  **************************/
//---- OOPS Prompt
function ShowOngoingAppPrompt(){
	Window.onDomReady( function(){
	    MoodalBox.modal({ContainerId:'OngoingAppPromptDiv', contentsWidth:318, contentsHeight:144});
        MoodalBox.click();
	});	
}	
//---- Delete confirmation Prompt
function showDeleteConfirmation(formtype,applicant){
	sessioncheck = SessionCheckRequest();
 	if (sessioncheck == 'InValid'){
	     window.location.href = virdirectory + "/Default.aspx";
	}else{
	    var ConfirmationText;
	    ConfirmationText = formtype + ' for ' + applicant
	    MoodalBox.modal({ContainerId:'ContainerDIV', contentsWidth:318, contentsHeight:144,pageName:ConfirmationText,autoHeight:true});
        MoodalBox.click();
	}
}
//---- Terms and condition Prompt
function showTermsPopUp(){
	MoodalBox.modal({ContainerId:'ContainerDIV', contentsWidth:570, contentsHeight:360});
    MoodalBox.click();
}
//---- Help Prompt
function showHelp(){
	MoodalBox.modal({ContainerId:'ContainerDIVHelp', contentsWidth:570, contentsHeight:360});
    MoodalBox.click();
}
//---- Image popup Prompt
function showImagePopUp(imgvar, caption, width, height){
 	MoodalBox.modal({ContainerId:'ContainerDIV', contentsWidth:width, contentsHeight:height, imgName:imgvar, imgCaption:caption});
 	MoodalBox.click();
}
//---- Upload Notify Prompt
function showNotifyUploadPopUp(){
	sessioncheck = SessionCheckRequest();
 	if (sessioncheck == 'InValid'){
	        window.location.href = virdirectory + "/Default.aspx";
	}else{
	     var file1 = new String($('ctl00_Content_fileCtlPath1').value);
	     var file2 = new String($('ctl00_Content_fileCtlPath2').value);
	     var file3 = new String($('ctl00_Content_fileCtlPath3').value);
	     var file4 = new String($('ctl00_Content_fileCtlPath4').value);
	     var fileLen = file1.length + file2.length + file3.length + file4.length;
	     var contentid = "NotifyUploadDIV";
	     if(fileLen > 0){
	        MoodalBox.modal({ContainerId:contentid, contentsWidth:318, contentsHeight:144});		
 	        MoodalBox.click();
 	     }
 	}
}

function Close(){
document.cookie = "NavigationUrl=" + virdirectory + "/dashboard/default.aspx";
window.location.href = virdirectory + "/dashboard/default.aspx";
}

function centerPopup( url, default_left, default_top, width, height, scrollbars, winName) {
	var posX, posY;

	posX = default_left;
	posY = default_top;

	if( parseFloat(navigator.appVersion) >= 4.0 ) {
		posX = parseInt(screen.availWidth / 2.0) - (width / 2.0);
		posY = parseInt(screen.availHeight / 2.0) - (height / 2.0);
	}

	if (scrollbars) {
		var win = window.open( url, (winName==null ? "popupWin" : winName), "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,location=no,status=yes,left=" + posX + ",top=" + posY );
	} else {
		var win = window.open( url, (winName==null ? "popupWin" : winName), "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=no,left=" + posX + ",top=" + posY );
	}

	if( parseFloat(navigator.appVersion) >= 4.0 ) {
		//win.moveTo( posX, posY );
		//if( navigator.appName.indexOf("Netscape") != -1 )
		win.focus( );
	}
}

//---- Quit and Save Prompt
function showLinkPopUp(url,name){
	var formstate , contentid , promptText;
	formstate = GetCookie("formstatus");
	document.cookie ="NavigationUrl=" + url + "";
	sessioncheck = SessionCheckRequest();
 	if (sessioncheck == 'InValid'){
	     window.location.href = virdirectory + "/Default.aspx";
	}else{
	    switch(formstate){
	        case "IP":
	            contentid ="SaveContainerDIV";
	            if(url == virdirectory + "/dashboard/LogOut.aspx")
	                 promptText='Log out';
	            else
	                 promptText ='return to ' + name;
	            MoodalBox.modal({ContainerId:contentid, contentsWidth:318, contentsHeight:144, pageName:promptText});		               
                MoodalBox.click();
	        break;
	        case "UPD":
	            contentid ="ResubmitContainerDIV";
	            if(url == virdirectory + "/dashboard/LogOut.aspx")
	                 promptText='Log out';
	            else
	                 promptText ='return to ' + name;   
	            MoodalBox.modal({ContainerId:contentid, contentsWidth:318, contentsHeight:144, ResubmitpageName:promptText});		               
                MoodalBox.click();
	        break;
	        case "SUB":
	            contentid = "SubmitContainerDIV";
	        break;
	     }    
	}                                     	    
}
//---- Close Moodal box
function ClosePrompt(){
	document.cookie ="NavigationUrl=" + virdirectory + "/dashboard/default.aspx";
	MoodalBox.close();
}	
function GetCookie(cookieName){	
	var name , i , start , end;
	var cookies;
	var exists=true;	     
	cookies = document.cookie.split(';');
	for (i=0;i<cookies.length;i++){
	    end = cookies[i].indexOf('=');
	    name = trimAll(cookies[i].substring(0,end));   
	   if( (name.toString() < cookieName.toString()) || (name.toString() > cookieName.toString()) ){		         
	        exists=false;
	   }else{	  
	        return cookies[i].substring(end+1,cookies[i].length);
	   } 
	}
	return exists;
}	
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
					((expires) ? "; expires=" + expires.toGMTString() : "") +
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					((secure) ? "; secure" : "");
					alert(curCookie);
					curCookie="cookies=cookies;expires=Sun, 14 Oct 2015 00:00:00 GMT"
					alert(curCookie);
	document.cookie = curCookie;
}
//---- Function to create the popup window n center of the page
function popUp(URL, width, height, scrollbars, menubar, location) {
     var popday = new Date();
     var popupid = popday.getTime();
     var leftpos = (Window.getWidth()-width)/2;
     var toppos =(screen.height-(height+55))/2;
     eval("page" + popupid + " = window.open(URL, '" + popupid + "', 'toolbar=0,scrollbars="+ (scrollbars ? 1 : 0) +",location="+ (location ? 1 : 0) +",statusbar=1,menubar="+ (menubar ? 1 : 0) +",resizable=1,width="+width+",height="+height+",left = "+leftpos+",top = "+toppos+"');");
}
//----- IE 6 fix to add hover to the links
function AddLinkHover(anchor){
     var browser=navigator.appName;
		if( browser == "Microsoft Internet Explorer")
            anchor.className+=(anchor.className.length>0? " ": "") + "linkhover";
}
function RemoveLinkHover(anchor){
    var browser=navigator.appName;
		if( browser == "Microsoft Internet Explorer")
			anchor.className=anchor.className.replace(new RegExp('( ?|^)linkhover\\b'), '');
}
//---- Function to format the phone number on blur of the text box 
function FormatPhoneNumber(phctl,pattern ,validator,errormsg){
    var number = phctl.value;
    var formattedphone = pattern;
    var patlen , numReg ,  i;
    var reg = new RegExp(pattern);
    numReg = /[0-9]/;
    try{
        if(phctl.value != "" ){
            number = ReplaceAll('(','',number);
            number = ReplaceAll(')','',number);
            number = ReplaceAll('-','',number);
            number = ReplaceAll(' ','',number);
            formattedphone = ReplaceAll('(','',formattedphone);
            formattedphone = ReplaceAll(')','',formattedphone);
            formattedphone = ReplaceAll('-','',formattedphone);
            if(number.match(numReg) != null && ((number.length == 11  && number.charAt(0) != '1')||(number.length < 10 || number.length > 11))){
                if($(errormsg).style.display != 'block'){
                    $(errormsg).innerHTML='Please enter 10 digit phone number';              
                    $(errormsg).style.display='block';
                }
                //if($('IsThirdRefctl_ques')!=null)
                   // $(errormsg).getParent().getParent().getParent().setStyle('height', $(errormsg).getParent().getParent().offsetHeight);
            }else{
                $(errormsg).style.display='none';
            }
           if(RegularExpressionValidatorEvaluateIsValid($(validator))){            
                patlen= formattedphone.length;
                if (number.length <patlen)
                   number = formattedphone.charAt(0) + number;           
                var startindex=0;
                for(i=0;i<patlen;i++){
                    if(pattern.charAt(i)=='-'){
                        number=number.substring(0,startindex) + number.substring(startindex,i) + '-' + number.substring(i,number.length);    
                        startindex=i;
                    }
                }
                phctl.value = number;
            }
        }else{
            $(errormsg).style.display='none';
        }              
    } 
    catch (e) {}
}
//----  Function to clear all occurances of the space within the text 
function trimAll(sString){
    while (sString.substring(0,1) == ' '){
         sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' '){
         sString = sString.substring(0,sString.length-1);
    }
    return sString;
}
//----- Replace all occurance of the old char with new char in given text
function ReplaceAll(oldchar,newchar,str)
{
   var i;
   if(str.indexOf(newchar) != -1){
       for(i=0;i<str.length;i++){
            if(str.charAt(i) == oldchar)
                 str=str.replace(oldchar,newchar);
       }
   }
   return str;
}
/**      Common Messages displayed through out the site   ***** also available in utilities.vb       **/
/******************************************************************************************************/
var ValidationMessages = {
    PageValidation : ReturnMessage("We're sorry<span>Please check the fields below to make sure they are filled in correctly, thank you.</span>"),    
    AddMemberButtonClicked : ReturnMessage("We're sorry" + '<span>Please add your family member by clicking the "Add household member" button.</span>'),
    AddPetButtonClickToProceed : ReturnMessage("We're sorry" + '<span>Please click the "Add Pet" button before proceeding.</span>'),
    AddAnotherPetBtnToProceed : ReturnMessage("We're sorry" + '<span>Please click the "Add another Pet" button before proceeding.</span>' ),
    AwaitingUserEmail : ReturnMessage("<span>Whoops!</span> This email address is awaiting activation, should we <a href='activationemail.aspx{queryStr}'>resend the activation email</a> ?"),
    CurrentUserEmail : ReturnMessage("<span>Whoops!</span> This email address is already active; <a href='" + virdirectory + "/dashboard/login.aspx'>login</a> or get a <a href='" + virdirectory + "/dashboard/forgotpassword.aspx{queryStr}'>password reminder</a> ?"),
    ArchivedUserEmail : ReturnMessage("<span>Whoops!</span> This email address has been deactivated. To reactivate this account, please contact us at <a href='mailto:support@effoundation.org'>support@effoundation.org</a> or call us at 1-800-577-6784"),
    PasswordMatch : ReturnMessage("&nbsp;<img src='" + virdirectory + "/_images/errmsg.gif' />&nbsp;&nbsp;<b><b><font color='red'>Password do not match</font></b>"),
    SchoolPasswordMatch : ReturnMessage("<img src='" + virdirectory + "/_images/error-btn.PNG' />&nbsp;<b><font color='red'>Password do not match</font></b>"),
    EmailReq : ReturnMessage("<IMG SRC='" + virdirectory + "/_images/errmsg.gif' /><span>We're sorry</span><p>Please enter your email address...</p>"),
    InvalidEmail : ReturnMessage("<IMG SRC='" + virdirectory + "/_images/errmsg.gif' /><span>We're sorry</span><p>Please enter an valid email address...</p>"),
    AccountInfoSent : ReturnMessage("<IMG id='tickimg' SRC='" + virdirectory + "/_images/check.gif' />Your account information has been sent…"),
    EmailNotFound : ReturnMessage("<IMG SRC='" + virdirectory + "/_images/errmsg.gif' /><span>We're sorry</span><p>We couldn’t find your email address…</p>"),
    WaitText : ReturnMessage("<IMG SRC='" + virdirectory + "/_images/spinner.gif' />Please Wait..."),
    EnterEmail : ReturnMessage("<span>We're sorry</span><p>Please enter your email address...</p>"),
    IncorrectEmail : ReturnMessage("<span>We're sorry</span><p>The email address is incorrect. Please try again.</p>"),
    OtherHouseHoldMemberConfirmMessageYes : ReturnMessage("By checking this box, you confirm that the individuals listed above remain the only people residing in the house."),
    OtherHouseHoldMemberConfirmMessageNo : ReturnMessage("By checking this box, you confirm that there are no other individuals residing in your house at this time."),
    OtherHouseholdWithMembersMessage : ReturnMessage("Please confirm household members<span>Please review the household members listed below and confirm the list accurately displays all individuals in your house. Check the box and click Next to continue.</span>"),
    OtherHouseholdWithoutMembersMessage : ReturnMessage("Please confirm<span>Please confirm that there are no other individuals living in your house by checking the box below and click Next to continue.</span>")
}
var RegularExpression = {
    Email : ReturnMessage(/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,3})$/)
}
function ReturnMessage(message)
{
    return message
}
/*****   Function to return the focus to first control on blur of last control (used in 'Quit & save ' on key down event)   ****/
function IEChostfunc(e) {       
  if(!e) e=window.event;
  key = e.keycode ? e.keycode : e.which;
  if(key==9){ 
    document.forms[0][0].focus();
    e.returnValue=false;
  }
}
/******   Function to enable/disble validation within slide in fields   *******/
function EnableValidation(id,index){
    var ctl = "";
    var arr = $$("#" + id + " span.check_valid");
    arr.each(function(item) {
        if(ctl != item.controltovalidate && index != null ) {
            document.getElementById(item.controltovalidate).tabIndex = index;
        }
	    if(item.enabled == false || item.enabled=="False"){
	        item.enabled = true;
	    }
	    ctl =item.controltovalidate;
	});
}
function DisableValidation(id){
    var arr = $$("#" + id + " span.check_valid");
    arr.each(function(item) {
		if(item.enabled){   
			item.enabled = false;	
			document.getElementById(item.controltovalidate).tabIndex = null;
		}
	});
}
/***** Function to apply datepicker *****/
function CreateDatePicker(options){
    $$('img.' + options.dpImgClass).each( function(el){
		new DatePicker(el,{textid:options.txtCtlId,removeErrorMsg:true});
	});
}
/******   Function to replace all occurance of the character    ******/
function ReplaceAll(oldchar,newchar,str){
   var i;
   for(i=0;i<str.length;i++){
        if(str.charAt(i) == oldchar)             
              str=str.replace(oldchar,newchar)        
   }
   return str;
}
/******     Object that Creates XMLHttp object for ajax    *******/
var AjaxHandler = {
      createObject: function () {
        if (window.XMLHttpRequest)  {   // Mozilla, Safari, ...
                this.httpRequest = new XMLHttpRequest();
                if (this.httpRequest.overrideMimeType) 
                    this.httpRequest.overrideMimeType('text/xml');
       } 
            else if (window.ActiveXObject){ // IE
                try {
                    this.httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) 
                {
                     try{
                           this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                     } 
                     catch (e) {return false;}
                }
             }
           if (!this.httpRequest){
                alert('Giving up :( Cannot create an XMLHTTP instance');
                return false;
           }else {
                return this.httpRequest;
           }        
      },
      sendRequest : function (options){
             if(options.async == false)
                this.httpRequest.open(options.method, options.url , false);  
             else
                this.httpRequest.open(options.method, options.url , true);       
             this.httpRequest.send(null); 
      }
}
/***  Session Check  ***/
function SessionCheckRequest(){
    var stamp = new Date();
    var url = virdirectory + "/sessionCheck.aspx" + "?stamp="+stamp.getMinutes().toString() + stamp.getSeconds().toString();
    var httpRequest = AjaxHandler.createObject();        
    var xmlDoc;
       
    AjaxHandler.sendRequest({url:url,method:'GET',async:false});
    xmlDoc = SessionCheck(httpRequest);
    return xmlDoc;
}
function SessionCheck(httpRequest) {    
    if (httpRequest.readyState == 4){                                // {0 - UNINITIALIZED} {1 - LOADING} {2 - LOADED} {3 - INTERACTIVE} {4 - COMPLETED} 
        if (httpRequest.status == 200) // {404 - Not Found} {500 - Internal Server Error} {200 - Is Perfect}
        {   
             xmlDoc = httpRequest.responseText;
             return xmlDoc;
        }else{
                    alert('There was a problem with the request.');
        }
    }
}   