﻿// 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';
    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();
//     
//      $("#topPopup").fadeIn("slow");
//            
//      var html = divName.innerHTML;
//      
//      //divName.innerHTML = '';
//      oldHtml =  container;
//      $(topPopupContent).append(divName);
//      
//  
//      $("#topPopupOpacity").fadeIn(100);               
//      popupCenterCount(topPopup,topPopupOpacity)
//   
//      senderObject = divName;
//      
// }
// 
// 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';

//        $( oldHtml ).append( senderObject );
//               
//        if(closeWithReload == true)
//        {
//            window.location.reload();
//        }
//  }

function showPanelModal(divName, title, map, saveState) {

    document.getElementById('popupTitle').innerHTML = title;

    popupCloseTimer = -1;

    if (map == null) {
        document.getElementById('popupPrint').style.display = "none";
        document.getElementById('popupIco').style.display = "none";
    } else {
        document.getElementById('popupPrint').style.display = "block";
    }

    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);

    var pageWidth = topPopupOpacity.offsetWidth;
    var widnowWidth = topPopup.offsetWidth;
    var widnowHeight = topPopup.offsetHeight;
    popupWidth = widnowWidth;


    topPopup.style.left = pageWidth / 2 - widnowWidth / 2 + 'px';
    var topMargin = pageSize._scrOfY + (pageSize._windowY) / 2 - (widnowHeight / 2) - 100;

    if (topMargin > 0) {
        topPopup.style.top = topMargin + 'px';

    }
    else {
        topPopup.style.top = '15px';

    }
    topPopupOpacity.style.height = pageSize._y + 'px';


    if (saveState == null)
        PanelSaveState(divName, title);

}

//  var oldHtml;
//  var senderObject;

function closePopup() {



    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 PrintElement(id) {

    var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
    disp_setting += "scrollbars=yes,width=450, height=400, left=100, top=25";


    // hide label
    //showLabel("spanGenerateShipmentLabel" , false);    


    var content_vlue = document.getElementById(id).innerHTML;

    var docprint = window.open("", "", disp_setting);
    docprint.document.open();
    docprint.document.write('<html><head><title>Print Contact Info</title>');
    docprint.document.write('<link href="');
    docprint.document.write('/Themes/FeinmanLawRedesign/CSS/Common/popup.css');
    docprint.document.write('" rel="stylesheet" type="text/css">');
    docprint.document.write('</head><body onLoad="self.print()"><div class="form-normal"  >');
    docprint.document.write(content_vlue);
    docprint.document.write('</div></body></html>');
    docprint.document.close();
    docprint.focus();

    // show label   
    // showLabel("spanGenerateShipmentLabel",true);
}
