﻿function openMediaPopup(url, widthParam, heightParam)
{
 if(url.length > 0)
 {
 var width = (widthParam > 984) ? 984 : widthParam;
 var height = (heightParam > 700) ? 700 : heightParam;

 // shows a pop up window
 var left = (screen.width) ? (screen.width-width)/2 : 0;
 var top = (screen.height) ? (screen.height-height)/3 : 0;
 var name = '_blank';
 // create the popup settings now
 var settings = 'height='+ (Number(height) + Number(50)) + ',width=' + width + ',top=' + top + ',left=' + left + ',status=no,menubar=no,directories=no,scrollbars=no,resizable=no';
 // open the new window
 win = window.open('/popup-media-viewer.aspx?media=' + url, name, settings);
 win.focus();
 }
}

function resizeWinTo( idOfDiv ) {
 var oH = getRef(idOfDiv); if( !oH ) {return false; }
 var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
 var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
 var x = window; x.resizeTo( oW, oH );
 var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
 if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
 else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
 else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
 if( window.opera && !document.childNodes ) { myW += 16; }
 x.resizeTo( oW + ( ( oW) - myW ) + 40, oH + ( (oH ) - myH ) );
}

function getRef(id) {
    return $(id).get(0);
}
