﻿//.v 1.1
jQuery.noConflict();
// example onclick="showPanelModal( $('#tellFriendContainer')[0], $('#tellFriendControl')[0], 'Tell a friend about this educator', null); centerPopup()"
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';    
      senderObject = divName;
 }

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);
    }
    
    var targetLeft = pageWidth/2 - widnowWidth/2 + 'px';
  //  document.getElementById('popupTitle').innerHTML  = targetLeft;
    
    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));
            if(moved < 20)
            moved = 20;
            topPopup.style.top = moved  + 'px';
         //   document.getElementById('popupTitle').innerHTML = 't: ' + targetMargin + ' current' + topPopup.style.top + ' after move ' + moved + 'px' ; 
        }
    
    }
    
 }
 
 

 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 reloadPage()
    {
        closeWithReload = true;
    }
    function setUpAfterClose(id)
    {
  
        upAfterClose=id;
   
    }    
    var upAfterClose ;
    var closeWithReload;

  
  
/// container - any div on page 
/// divName - pop up copntent
/// title of pop up
/// map - use only for google maps in other case null    
 function showPanelModal(container,divName , title,map )
 {     
        

      if(divName == null){
        alert('error no popup content');
        return;
      }
 
      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();
     
      jQuery("#topPopup").fadeIn("slow");
            
      var html = divName.innerHTML;
      
      //divName.innerHTML = '';
      oldHtml =  container;
      jQuery(topPopupContent).append(divName);
      
  
     jQuery("#topPopupOpacity").fadeIn(100);               
      popupCenterCount(topPopup,topPopupOpacity)
   
      senderObject = divName;
      
      
      
 }
 
 var panelToReload;    
 // uses global value
 function refresPopup(){
 
   if(panelToReload != null)
         __doPostBack(panelToReload,"");
 }
 
 
 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';

        jQuery( oldHtml ).append( senderObject );
             
        if(closeWithReload == true)
        {
            window.location.reload();
        }
       // if(panelToReload != null)
       //  __doPostBack(panelToReload,"");
        
  }  
