﻿
function OpenWindow(url) {
	var strWinFeatures = 'height=700,width=850,location=NO, resizable=yes,directories=no,menubar=no,scrollbars=YES,status=no,titlebar=no,application=yes';
	WindowHndl = window.open(url, String(parseInt(Math.random()*10000)), strWinFeatures);
	if (WindowHndl) WindowHndl.focus();
} 


var demoPopupDiv = null;
function ViewDemo(url) {
    winHeight = "670px"
    winWidth = "830px"

    if (demoPopupDiv == null) {
        demoPopupDiv = document.createElement("div");
        demoPopupDiv.id = "demoPopupDiv";
        demoPopupDiv.className = "dialog";
        demoPopupDiv.style.background = "#000000";
        demoPopupDiv.style.height = winHeight;
        demoPopupDiv.style.width = winWidth;
        demoPopupDiv.style.display = "none";
        demoPopupDiv.style.padding = "0";
    }
//window.open ('/viewImageLarge.aspx?ProductID=' + ProductID + '&BrandID=' + BrandID);

	demoPopupDiv.innerHTML = '<iframe src="' + url + '" style="width:' + winWidth + ';height:' + winHeight + ';" frameborder="0" scrolling="no" scrollbars="no"></iframe>';
    document.body.appendChild(demoPopupDiv);
	show_modal_dialog("demoPopupDiv");	
}


var content_shield = null;
var modal_dialog = null;
function show_modal_dialog(divID) {
//IE is sometimes not ready for the appendChild method, so wait...
if (document.body.readyState && document.body.readyState != "complete") { 
window.setTimeout('show_modal_dialog("' + divID + '")', 10);
return;
}
if (content_shield == null) {
content_shield = document.createElement("div");
content_shield.style.height = getPageSize()[1] + "px";

document.body.appendChild(content_shield);
content_shield.className = (arguments.length>1) ? arguments[1]:"content_faded";
}
modal_dialog = document.getElementById(divID);
if (modal_dialog == null) return;
modal_dialog.style.display = "block";

var left = ((getWindowXY()[0]+getScrollXY()[0]) / 2)-(modal_dialog.scrollWidth / 2);
var top =  ((getWindowXY()[1]) / 2)+getScrollXY()[1]-(modal_dialog.scrollHeight / 2);

modal_dialog.style.left = left + 'px';
modal_dialog.style.top = top + 'px';

//store the values in hidden fields (declared as JS variables)
//used in GiftWrapping.aspx
if (typeof(modalDialogLeft)!="undefined") modalDialogLeft.value = left + 'px';
if (typeof(modalDialogTop)!="undefined") modalDialogTop.value = top + 'px';
} 

function hide_modal_dialog() {
if (modal_dialog != null) 
modal_dialog.style.display = "none";
if (content_shield != null) {
document.body.removeChild(content_shield);
content_shield = null;
}
if (demoPopupDiv != null) document.body.removeChild(demoPopupDiv);
}


function getPageSize(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
//alert(pageWidth + " || " + pageHeight + " || " + windowWidth + " || " + windowHeight);
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}
 
function getScrollXY() {
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;
}
return [ scrOfX, scrOfY ];
}

function getWindowXY() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}


function stopProp(e) {
	if (e && e.stopPropogation) e.stopPropogation();
	else if (window.event && window.event.cancelBubble)
	window.event.cancelBubble = true;
}

