﻿/**
 * @author opher.vishnia
 */


// xDocSize r1, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL


var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos = appVer.indexOf('msie');
if (iePos !=-1) {
is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
is_major = parseInt(is_minor);
}
var is_getElementById = (document.getElementById) ? "true" : "false";
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var is_documentElement = (document.documentElement) ? "true" : "false";
var is_ie = ((iePos!=-1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5 = (is_ie && is_major == 5);
var is_ie5up = (is_ie && is_minor >= 5);
var is_ie5_5 = (is_ie && (agt.indexOf("msie 5.5") !=-1));
var is_ie5_5up =(is_ie && is_minor >= 5.5);
var is_ie6 = (is_ie && is_major == 6);
var is_ie6up = (is_ie && is_minor >= 6);
var is_ie7 = (is_ie && is_major == 7);

function xDocSize()
{
  var b=document.body, e=document.documentElement;
  var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
  if (e) {
    esw = e.scrollWidth;
    eow = e.offsetWidth;
    esh = e.scrollHeight;
    eoh = e.offsetHeight;
  }
  if (b) {
    bsw = b.scrollWidth;
    bow = b.offsetWidth;
    bsh = b.scrollHeight;
    boh = b.offsetHeight;
  }
//  alert('compatMode: ' + document.compatMode + '\n\ndocumentElement.scrollHeight: ' + esh + '\ndocumentElement.offsetHeight: ' + eoh + '\nbody.scrollHeight: ' + bsh + '\nbody.offsetHeight: ' + boh + '\n\ndocumentElement.scrollWidth: ' + esw + '\ndocumentElement.offsetWidth: ' + eow + '\nbody.scrollWidth: ' + bsw + '\nbody.offsetWidth: ' + bow);
  return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}

function navToggle(which, event){
	if (event.type=="mouseover"){
		if (!which.originalClass)
			which.originalClass=which.className;
		if (which.className!="buttonOn")
			which.className="buttonHover";	
	} else
	if (event.type=="mouseout"){
		which.className=which.originalClass;
	}
}


var Client = {
  viewportWidth: function() {
    return self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
  },

  viewportHeight: function() {
    return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
  },
  
  viewportSize: function() {
    return { width: this.viewportWidth(), height: this.viewportHeight() };
  }
};


function pageLoad(isPopup){
    if (isPopup == "False") {
                        ShowLinkImg();
				        adjustMainContentHeight()				
				    }				    
			}
			
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function openWindow(url,w,h) {
 var sURL = url
 var  wleft = (screen.width-w ) / 2;
 var wtop = (screen.height-h ) / 2;
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
 var sName = "popName";
 var sFeatures = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=no";
 sFeatures = sFeatures + ",width=" + w + ",height=" + h+',left=' + wleft + ', top=' + wtop ;
 
 var wizWin = window.open(sURL, sName, sFeatures);
 
   // Just in case width and height are ignored
  //wizWin.resizeTo(w, h);
  // Just in case left and top are ignored
 // wizWin.moveTo(wleft, wtop);
  wizWin.focus();
  
  return wizWin;
}
			
//=============================================================================================


function selectMenuEntry(strPageName)
{
    //alert(document.getElementById("div"+strPageName))
    document.getElementById("div"+strPageName).className = "buttonOn";
}

function PrintWindow(filePath)
{
 
    var browserName=navigator.appName;
    
    if (browserName=="Microsoft Internet Explorer")
     {
        window.print();
     }
    else
     {
        PrintFireFox(filePath);
     } 
}

function PrintFireFox(filePath)
{
    PrintPageFireFox(filePath);

}

function PrintPageFireFox(filePath)
{
    window.open(filePath ,'','menubar=no,scrollbars=yes,resizable=no,top=0,left=0 ,width=675,height=600');
     
}

function ValidateTime(obj,evt)
{
  
    var charCode = event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
         {
            return false;
         }
         else
         {
            var timeValue = obj.value;
            if(timeValue.length==0)//first entry digit
            {
                
            }
         }   
         return true;

}

function IsValidTime(obj) {
    // Checks if time is in HH:MM:SS AM/PM format.
    // The seconds and AM/PM are optional.
    ///add by hassn 
  
    var timeStr = obj.value;
    //alert('blur')
    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
    //if(timeStr=="__:__")
    //added by hassn 
    if(timeStr=='__:__'||timeStr=='')
        return false;
    var matchArray = timeStr.match(timePat);
    
    if (matchArray == null) {
    alert("זמן לא חוקי");
    obj.value = "";
    obj.focus();
    obj.select();
   
    return false;
    }
    hour = matchArray[1];
    minute = matchArray[2];
    second = matchArray[4];
    ampm = matchArray[6];

    if (second=="") { second = null; }
    if (ampm=="") { ampm = null }
    
    if (hour < 0  || hour > 23) {
   
    alert("שעה צריכה להיות בין 0 ל 23");
    //obj.value = "";
    document.getElementById(obj.id).value="__:__";
    document.getElementById(obj.id).focus();
    document.getElementById(obj.id).select();
   
      
    return false;
    }
    //if (hour <= 12 && ampm == null) {
    //if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
    //alert("You must specify AM or PM.");
    //return false;
     //  }
    //}
    //if  (hour > 12 && ampm != null) {
    //alert("You can't specify AM or PM for military time.");
    //return false;
    //}
    if (minute<0 || minute > 59) {
    alert ("דקה צריכה להיות בין 0 ל 59.");
    obj.value = "__:__";
    document.getElementById(obj.id).focus();
    document.getElementById(obj.id).select();
   // add by hassn
     enterkeypressed=false;
    return false;
    }
    if (second != null && (second < 0 || second > 59)) {
    alert ("Second must be between 0 and 59.");
    obj.value = "__:__";
    document.getElementById(obj.id).focus();
    document.getElementById(obj.id).select();
    return false;
    }
    return true;
}

//-------------------------------------------------------------------------------------------------------------------------
//this function search through the elements that have the css class SearchElement and check for each type if its empty
//if all elements are empty then message box appear and postback is canceld
//-------------------------------------------------------------------------------------------------------------------------

function CheckSearchForm()
{
 
    

    var formElementArray;
    var searchDivObj = document.getElementById('divSearchView');
    var numberOfElement = searchDivObj.childNodes;
    var returnResult = false; 
    var dangerResult=false;   
   formElementArray = ElementsByClass(searchDivObj,'SearchElement',false,true);
  
    
   for(var i=0;i<formElementArray.length;i++)
   {
    
   
    if(formElementArray[i].tagName=='INPUT'  )
    {   
     
     if(!checkDengerousKey(formElementArray[i])) //if dangerous key found set dangerresult field as true
            {
                dangerResult=true;
            }
     if(formElementArray[i].value != ''&& checkDengerousKeyOnSubmit(formElementArray[i])) //if element contains value and its not danger then set the resu
        {
            
            returnResult = true;
         
            break;
        }
     
    }
    else if(formElementArray[i].tagName=='SELECT')
    {
        
        if(formElementArray[i].selectedIndex != 0 && formElementArray[i].selectedIndex != -1)
        {
            
            returnResult = true;
            break;
        }
    }
    else if(formElementArray[i].tagName=='SPAN') // for radio buttons list and checkbox list
    {
      
        var innerChild = formElementArray[i].childNodes;
        var objRadioOrCheckbox;
     
        if(innerChild.length>0)
        {
         
            if(innerChild.length==2||innerChild.length==1) //when radio or checkbox list is implemented then it rendered in th efollowing html tags: <SPAN><LABLE><INPUT></SPAN>
            {
                
                if(innerChild[0].tagName=='INPUT')
                     objRadioOrCheckbox = innerChild[0];
                   
                else if(innerChild[1].tagName=='INPUT')
                     objRadioOrCheckbox = innerChild[1];
                  
                if(objRadioOrCheckbox.tagName == 'INPUT')
                {
                    if (objRadioOrCheckbox.getAttribute('type')=='checkbox' || objRadioOrCheckbox.getAttribute('type')=='radio')
                    {
                        if(objRadioOrCheckbox.checked)
                        {
                           
                            returnResult = true;
                            break;
                        }
                    }
                }
                
                 
                    
            }
            
            
            
        }
        
         
    } //end else clause
    else
    {
    
    }
    
   }
    
 
     
     
         if(!returnResult && !dangerResult)//
         
        alert('חובה להזין שדה חיפוש אחד לפחות ');
   // alert(dangerResult)
    //alert(returnResult)   
    return returnResult;

}
function pause(millisecondi)
{
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;
         while(true)    
         {        
            now = new Date();
            if(now.getTime() > exitTime) return;
         }
}
                     
//-------------------------------------------------------------------------------------------------------------------------
//this function search through the elements that have the css class SearchElement and clear each type 
//-------------------------------------------------------------------------------------------------------------------------

function ClearSearchForm()
{
 
  //clear=true;  
    var formElementArray;
    var searchDivObj = document.getElementById('divSearchView');
    var numberOfElement = searchDivObj.childNodes;
    var returnResult = false;
    
   formElementArray = ElementsByClass(searchDivObj,'SearchElement',false,true);
    
   for(var i=0;i<formElementArray.length;i++)
   {
   
    if(formElementArray[i].tagName=='INPUT'  )
    {
        formElementArray[i].value = ''
        
    }
    else if(formElementArray[i].tagName=='SELECT')
    {
        formElementArray[i].selectedIndex = -1
        var obj = document.getElementById('ctl00_ContentBody_ctl00_LocationControl1_hdnDdlZoneCleared')
        obj.value = "-1";
    }
    else if(formElementArray[i].tagName=='SPAN') // for radio buttons list and checkbox list
    {
       
        var innerChild = formElementArray[i].childNodes;
        var objRadioOrCheckbox;
        
        if(innerChild.length>0)
        {
           
            if(innerChild.length==2 ||innerChild.length==1) //when radio or checkbox list is implemented then it rendered in th efollowing html tags: <SPAN><LABLE><INPUT></SPAN>
            {
               
                if(innerChild[0].tagName=='INPUT')
                     objRadioOrCheckbox = innerChild[0];
                else if(innerChild[1].tagName=='INPUT')
                     objRadioOrCheckbox = innerChild[1];
                if(objRadioOrCheckbox.tagName == 'INPUT')
                {
                    if (objRadioOrCheckbox.getAttribute('type')=='checkbox' || objRadioOrCheckbox.getAttribute('type')=='radio')
                    {
                        objRadioOrCheckbox.checked = false
                        
                    }
                    //hassn
                    if(objRadioOrCheckbox.getAttribute('id')=='ctl00_ContentBody_ctl00_OwnershipControl1_rdoOwnerShip_3')
                    {
                        objRadioOrCheckbox.checked = true;
                    }
                   if(objRadioOrCheckbox.getAttribute('id')=='ctl00_ContentBody_ctl00_MaccabiBranchTypeControl1_rdoMaccabiBranch_0')
                    {
                    objRadioOrCheckbox.checked = true;
                    }
                }    
                    
            }
            
            
            
        }
        
       
         
    } //end else clause
    else
    {
    
    }
    
   }
   
            WsAjaxGlobal.SetServiceTypeText('', onsuccess2,onfail2);
           
            loadListAjaxCities('ServiceType','ctl00_ContentBody_ctl00_ServiceAreaControl1_txtServiceArea_b','ServiceType' )
            loadListAjaxCities('TreatmentType','ctl00_ContentBody_ctl00_TreatmentName1_txtTreatmentName_b','TreatmentType' )
            
             WsAjaxGlobal.SetRegionText(-1, onsuccess2,onfail2);
            loadListAjaxCities('Cities','ctl00_ContentBody_ctl00_LocationControl1_txtSettlement_b','Cities')
}

//returns an array of elements that match full or partial (indexOf) classname
function ElementsByClass(rootElement,ElementClass,ElementType,partialMatch){        
            ElementType=ElementType?ElementType:'*';
                  
                  var elementsArray=new Array();                  
            var theElements=rootElement.getElementsByTagName(ElementType);                  

            for (var x=0;x<theElements.length;x++){
                              if(partialMatch){
                                     if (theElements[x].className.indexOf(ElementClass)>-1){ 
                                              elementsArray[elementsArray.length]=theElements[x];
                                        }
                                }else{
                              if (theElements[x].className==ElementClass){ 
                                              elementsArray[elementsArray.length]=theElements[x];
                                        }
                                }
                        }                          

                  return elementsArray;
      }

function checkDengerousKey(obj)
{

  
        
      if(obj.value=='')  return true;
      var str = obj.value;
      
      var rexp = new RegExp('^[^<>@#$%^&]{0,'+str.length+'}$'); 
      var objId = obj.id;   
       
     
      

       if(rexp.test(obj.value)) 
        return true; 
       else 
       { 
        alert('תווים לא חוקיים ');
        obj.value='';
        
        
        setTimeout("document.getElementById('"+objId+"').focus();",1);
        setTimeout("document.getElementById('"+objId+"').select();",1);
        return false; 
      } 
      
   
   
}

///added New
function checkDengerousKeyFree(obj)
{

        //true means text OK
        
      var trimmed = (obj.value).replace(/^\s+|\s+$/g, '') ;
      if(obj.value=='')  return true;
      var str = obj.value;
      
      var rexp = new RegExp('^[^<>@#$%^&,]{0,'+str.length+'}$'); 


     
      
      if (trimmed.length==1)
      {
         alert('על מנת לבצע חיפוש חופשי יש להזין יותר מתו אחד');
         return false;
      }
       if(rexp.test(obj.value)) 
        return true; 
       else 
       { alert('תווים לא חוקיים ');
        obj.value='';
        obj.focus();
        return false; 
      } 
      
   
   
}


///add By hassn 
function checkDengerousKeyOnSubmit(obj)
{

  
  
      if(obj.value=='')  return true;
      var str = obj.value;
      
      var rexp = new RegExp('^[^<>@#$%^&]{0,'+str.length+'}$'); 


      //if (x.Match(text))
      
      
       if(rexp.test(obj.value)) 
        return true; 
       else 
       { 
         obj.value='';
        setTimeout("document.getElementById('"+objId+"').focus();",1);
        setTimeout("document.getElementById('"+objId+"').select();",1);
        return false; 
      } 
   
}

function showModalBackdrop(){
	var modalBackdrop=$('modalBackdrop');	
	modalBackdrop.style.display="block";	
}


function hideModalBackdrop(){
	var modalBackdrop=$('modalBackdrop');	
	modalBackdrop.style.display="none";	
}

function showModalBox(boxID){
    var modalBox=$(boxID);	
    
   appendModaltoBody(boxID);
    
    //set width and height parameters on the object, so we could use them later while
	// the objet is in display 'none'
	if (!modalBox.boxWidth && !modalBox.boxHeight)
	{
		modalBox.boxWidth=modalBox.offsetWidth;
		modalBox.boxHeight=modalBox.offsetHeight;
		
	} 				
	modalBox.style.top=Math.round((xClientHeight()/2)-modalBox.boxHeight/2+xScrollTop(document.body))+"px";
	modalBox.style.left=Math.round((xClientWidth()/2-modalBox.boxWidth/2))+"px";			    
	
	if (is_ie6){
	    hideSelectBox()
	}
	
	//take care of iframe height as well
	xGetElementsByClassName('modalIframe',modalBox)[0].style.height=modalBox.boxHeight+"px"; 
}

function hideModalBox(boxID){
    var modalBox=$(boxID);	
    modalBox.style.left="-1000px";
    
	if (is_ie6){
	    showSelectBox()
	}
}

function showPleaseWait(){
    showModalBackdrop()    
    showModalBox('pleaseWait');

}

function hidePleaseWait(){
    hideModalBackdrop()    
    hideModalBox('pleaseWait');
}

function appendModaltoBody(boxID){
    var modalBox=$(boxID);	
    
    //if box is not a direct child of the document, put it there
    if (modalBox.parentNode!=document.body){
        document.body.appendChild(modalBox);
    }
}

function hideSelectBox(){
    //hide selects to fix annoying select bug in ie
	var allSelects=document.getElementsByTagName("select");
	for(var x=0;x<allSelects.length;x++){		
		//if not in a modal box
		if(allSelects[x].className.indexOf('modal')==-1){
		    allSelects[x].style.visibility="hidden";	
		    }
	}
}

function showSelectBox(){
    //hide selects to fix annoying select bug in ie
	var allSelects=document.getElementsByTagName("select");
	for(var x=0;x<allSelects.length;x++){		
		allSelects[x].style.visibility="visible";	
	}
}

function ShowLinkImg() {
    //debugger;
    if (document.getElementById("ctl00_ContentBody_hidFiledLink") == null) {
        HideLinkImg();
    }
    else if (document.getElementById("ctl00_ContentBody_hidFiledLink").value == "aaa") {
        HideLinkImg();
    }
    else {
        document.getElementById("imgDirectLink").style.display = "inline";
    }
}
function HideLinkImg() {
    document.getElementById("imgDirectLink").style.display = "none";
}

function ShowHideLink() {
    //ctl00_ContentBody_hidFiledLink
    if (document.getElementById("lblDirectLink").style.visibility == "visible") {
        document.getElementById("lblDirectLink").style.visibility = "hidden";
    }
    else {
        document.getElementById("lblDirectLink").style.visibility = "visible";
        if (document.getElementById("lblDirectLink").style.display == "none") {
            document.getElementById("lblDirectLink").style.display = "inline";
            document.getElementById("lblDirectLink").value = document.getElementById("ctl00_ContentBody_hidFiledLink").value;
        }
    }
    
     
}
