﻿ // Size Object
function Size()
{

}

Size.prototype._windowX;
Size.prototype._windowY;
Size.prototype._scrOfY;
Size.prototype._scrOfY;
//Get Sizes
function GetSizes()
{
//alert( getDocHeight());
    var result = new Size();
    
    result._windowX = GetWidth() ;
    result._windowY = GetHeight();    
    var scrolls = getScrollXY();
    result._scrOfX = scrolls._x;
    result._scrOfY = scrolls._y;
    result._y =getDocHeight();
    result._x = getDocWidth();
    //alert('x: ' + result._scrOfX +'y: ' + result._scrOfY+'Wx: ' + result._windowX+'Wy: ' + result._windowY);
    return result;
}
// window size
 function GetHeight()
        {
            var y = 0;
            if (window.innerHeight) {
                y=window.innerHeight;
            }
            else if (document.documentElement && document.documentElement.clientHeight) {
                y=document.documentElement.clientHeight;
            }
            else if (document.body) {
                y=document.body.clientHeight;
            }
            return y;
        }
        
        function GetWidth()
        {
                var x = 0;
                if (self.innerHeight)
                {
                        x = self.innerWidth;
                }
                else if (document.documentElement && document.documentElement.clientHeight)
                {
                        x = document.documentElement.clientWidth;
                }
                else if (document.body)
                {
                        x = document.body.clientWidth;
                }
                return x;
        }
// Brower size
function getScrollXY() {
    var result = new Size();
      var scrOfX = 0, scrOfY = 0;
      if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
      }
      result._x= scrOfX;
        result._y = scrOfY;
      return result;
}
function getDocHeight() {
   var db = document.body;
   var dde = document.documentElement;
   return Math.max(db.scrollHeight, dde.scrollHeight, db.offsetHeight, dde.offsetHeight, db.clientHeight, dde.clientHeight)
}
function getDocWidth() {
   var db = document.body;
   var dde = document.documentElement;
   return Math.max(db.scrollWidth, dde.scrollWidth, db.offsetWidth, dde.offsetWidth, db.clientWidth, dde.clientWidth)
}

 function PanelSaveState(divName, title){
 
      divName.style.display = 'none';    
   
 }

var popupCloseTimer ;
 function modalAutoHide(time){  
    if(popupCloseTimer == -1){
        popupCloseTimer = time
    }
        if(popupCloseTimer>=0){
         document.getElementById('popupCloseBtn').innerHTML = time;
         document.getElementById('popupCloseBtn').className = 'popupClose2';
         if(time >0 ){
            time -=1;
            setTimeout('modalAutoHide(\''+time+'\')',1000);
         }
         else{
            closePopup();
         }
     }
 }
 var popupWidth;
 var oldHtml;
 var senderObject;
 function setPopupContent(param)
 {
     if(param != null){
         document.getElementById('mapIframe').src = param;
        // document.getElementById('mapContent').style.display = 'block'
         
     }
 } 
 
 var popup_centering = false
 function centerPopup(){

    popup_centering = true;
    setTimeout('centerPopupInterval()',5);
 }
 function centerPopupInterval(){
    //alert(popup_centering);
    
    var topPopup = document.getElementById('topPopup');
    var topPopupOpacity = document.getElementById('topPopupOpacity');
    var pageWidth = topPopupOpacity.offsetWidth;
    var widnowWidth = topPopup.offsetWidth;

    
    var pageSize = GetSizes();
    var widnowHeight = topPopup.offsetHeight;
    var targetMargin = pageSize._scrOfY + (pageSize._windowY)/2 - (widnowHeight/2) ;
    
        if(popup_centering == true){
        setTimeout('centerPopupInterval()',5);
    }
    if(targetMargin< 15){
    targetMargin = 15;
    }
  
    var targetLeft = pageWidth/2 - widnowWidth/2 + 'px';
    document.getElementById('popupTitle').innerHTML  = targetLeft;
  
    if(targetLeft< 15){
         targetLeft = 15;
    }
  
    var startMarginLeft = topPopup.style.left;
    var currentMarginLeft = startMarginLeft.replace('px','') ;
  
    
    var startMargin = topPopup.style.top;
    var currentMargin = startMargin.replace('px','') ;   
    
  
    var step = 2 * Math.abs(parseInt(targetMargin) - parseInt(currentMargin))/25 ;
    if(step < 6)
        step = 6;
  
    if( Math.abs(parseInt(targetMargin) - parseInt(currentMargin)) > 5){
  
        if( parseInt(targetMargin) > parseInt(currentMargin))
        {
            var moved = (parseInt(currentMargin) + parseInt(step));
            topPopup.style.top = moved  + 'px';
           // document.getElementById('popupTitle').innerHTML = 't: ' + targetMargin + ' current' + topPopup.style.top + ' after move ' + moved + 'px'   ;
        }
        else
        {
            var moved = (parseInt(currentMargin) - parseInt(step));
            topPopup.style.top = moved  + 'px';
         //   document.getElementById('popupTitle').innerHTML = 't: ' + targetMargin + ' current' + topPopup.style.top + ' after move ' + moved + 'px' ; 
        }    
    }
    else{
     if( Math.abs(parseInt(targetLeft) - parseInt(currentMarginLeft)) > 5){
        
        if( parseInt(targetLeft) > parseInt(currentMarginLeft))
        {
            var moved = (parseInt(currentMarginLeft) + parseInt(step/2));
            topPopup.style.left = moved  + 'px';
           // document.getElementById('popupTitle').innerHTML = 't: ' + targetMargin + ' current' + topPopup.style.top + ' after move ' + moved + 'px'   ;
        }
        else
        {
            var moved = (parseInt(currentMarginLeft) - parseInt(step/2));
            topPopup.style.left = moved  + 'px';
         //   document.getElementById('popupTitle').innerHTML = 't: ' + targetMargin + ' current' + topPopup.style.top + ' after move ' + moved + 'px' ; 
        }    
     
     }
        }
    
    
 }
 
 
 function showPanelModal(divName, title,map )
 {     
      if(divName == null){
        alert('error no popup content');
        return;
      }
      senderObject = divName;
      
      document.getElementById('popupTitle').innerHTML = title;
      popupCloseTimer = -1;

      var topPopup = document.getElementById('topPopup');
      var topPopupContent = document.getElementById('topPopupContent');
      var topPopupOpacity = document.getElementById('topPopupOpacity');
      var pageSize = GetSizes();
     
      $("#topPopup").fadeIn("slow");
            
      var html = divName.innerHTML;
      divName.innerHTML = '';
      topPopupContent.innerHTML = html;
      oldHtml = html;
      topPopupContent.className =  divName.className ;   
      $("#topPopupOpacity").fadeIn(100);               
      popupCenterCount(topPopup,topPopupOpacity)
     
      
 }
 function popupCenterCount (topPopup,topPopupOpacity){
      var pageSize = GetSizes();  
      var pageWidth = topPopupOpacity.offsetWidth;
      var widnowWidth = topPopup.offsetWidth;
      var widnowHeight = topPopup.offsetHeight;
 
      topPopup.style.left = pageWidth/2 - widnowWidth/2 + 'px';
      var topMargin = pageSize._scrOfY + (pageSize._windowY)/2 - (widnowHeight/2) ;

      if(topMargin > 0){
        topPopup.style.top = topMargin + 'px';
      }
      else
      {
        topPopup.style.top = '15px';

      }
      topPopupOpacity.style.height = pageSize._y + 'px';      
      popupWidth = widnowWidth;      
      return  topMargin;   
          
 } 
    
 function closePopup(){    
    
          popup_centering = false; // diable scrooling
 
        if(upAfterClose != null){
        __doPostBack(upAfterClose, '')
        }
                
        popupCloseTimer = -2;            
        var topPopup = document.getElementById('topPopup');
        var topPopupContent = document.getElementById('topPopupContent');
        var topPopupOpacity = document.getElementById('topPopupOpacity');
        topPopup.style.display = 'none';
        topPopupContent.innerHTML = '';
        topPopupOpacity.style.display = 'none';
          
        senderObject.innerHTML = oldHtml;
               
        if(closeWithReload == true)
        {
            window.location.reload();
        }
    }    
    function reloadPage()
    {
        closeWithReload = true;
    }
    function setUpAfterClose(id)
    {
  
        upAfterClose=id;
   
    }    
    var upAfterClose ;
    var closeWithReload;
    
    
    
    
    
    
        function expandCatalogItem(hitindex0){
      
                
            $(document).ready(function() {
    
                 $($('.item_qmenu')[hitindex0]).css('color','white');         
                 $($('.item_sub_qmenu')[hitindex0]).fadeIn("slow"); 
                  $($('.item_qmenu')[hitindex0]).addClass("item_qmenu2");
                     
            });          
       }  