﻿// JScript File

var last_thePopFrame=null;
var last_theSender=null;


function showPopup(theSenderId,thePopFrameId) {

    thePopFrame=document.getElementById(thePopFrameId);
    theSender=document.getElementById(theSenderId);
    
    if ((thePopFrame) && (theSender)) {
        
        thePopFrame.style.display='';
        
        centerPopup(thePopFrame.id);

    }
    if ((thePopFrame!=last_thePopFrame) && (last_thePopFrame)) {
        last_thePopFrame.style.display='none';
       
    }
    last_thePopFrame=thePopFrame;
    last_theSender=theSender;
    
}

function centerPopup(thePopFrameId){
    thePopFrame = document.getElementById(thePopFrameId);
    
    //FireFox
    var x = (window.innerWidth / 2) - (thePopFrame.offsetWidth / 2);
    var y = ((window.innerHeight / 2) - (thePopFrame.offsetHeight / 2)) + window.pageYOffset; 
  
    //IE 6 and any others that don't work with the top DOM
    if (!x){
        x= (document.body.offsetWidth / 2) - (thePopFrame.offsetWidth / 2);
    }  
    if (!y) {

        var top = (document.documentElement && document.documentElement.scrollTop) ?
            document.documentElement.scrollTop : document.body.scrollTop;
    
       var viewPortHeight=document.body.offsetHeight;
       if (document.body.offsetHeight < document.documentElement.clientHeight){
       viewPortHeight=document.documentElement.clientHeight;}
       
       y = ((viewPortHeight / 2) - (thePopFrame.offsetHeight / 2)) + (top);
    }

    //Set the Location      
    if (x){
        thePopFrame.style.left = x + "px";
    }
    if (y){
        thePopFrame.style.top = y + "px";
    }

}

function sizePopup(thePopFrameId){

    thePopFrame = document.getElementById(thePopFrameId);

}

function display(imageLocation){
    var imageObject = document.getElementById("MediumScreenshot");
    //if (imageObject){
    imageObject.src = imageLocation;
    
    //resize the popupsince the image could have changed the vertical size needed.
    //sizePopup("SsPopFrame","SSPopDiv");
    
    
    //}
}

//This method changes the iframe location and then uses the showpopup function
//to display the popup.
function openPollPopup(pollPopupLinkID, pollIFrameID,newSrc){
    document.getElementById(pollIFrameID).src=newSrc;
    showPopup(pollPopupLinkID,pollIFrameID); 
}
function openScreenshotPopup(ResourceId, tree_root){
  document.getElementById("SsPopFrame").src="/asp/fnc/ScreenshotViewerPopup?id="+ ResourceId +"&tree_root="+ tree_root;
   var linkId =  "ScreenshotLink_"+ResourceId;
   showPopup(linkId ,"SsPopFrame"); 
}
function openPopup(PopupLinkID, FrameID,newSrc){
    document.getElementById(FrameID).src=newSrc;
    showPopup(PopupLinkID,FrameID); 
}
function openPopup(PopupLinkID, FrameID){
    showPopup(PopupLinkID,FrameID); 
}

function closeScreenshotPopup(){
  document.getElementById("SsPopFrame").src="";
  showPopup(null);
}



function getInnerHeight(iframe){
    var d=iframe.contentWindow ?
    iframe.contentWindow.document :
    iframe.contentDocument;
    var h=0;
    if(d){
    if(d.documentElement && d.compatMode &&
        d.compatMode=="CSS1Compat")
        h=d.documentElement.scrollHeight;
        else if(d.body)
        h=d.body.scrollHeight;
        if(h) h+=getInsets(d);
    }
    return (h||549)+"px"; //300 is a default value
}

function getInsets(d){
    if(d.body.currentStyle)
    with (d.body.currentStyle)
        return (parseInt(marginTop)||0) +
        (parseInt(marginBottom)||0) +
        (parseInt(paddingTop)||0) +
        (parseInt(paddingBottom)||0);
        if(d.defaultView && d.defaultView.getComputedStyle)
    with (d.defaultView)
        return parseInt(getComputedStyle(d.body,"").
        getPropertyValue("margin-top"))+
        parseInt(getComputedStyle(d.body,"").
        getPropertyValue("margin-bottom"))+
        parseInt(getComputedStyle(d.body,"").
        getPropertyValue("padding-top"))+
        parseInt(getComputedStyle(d.body,"").
        getPropertyValue("padding-bottom"));
    return 0;
}
