/* 
      - Author(s):     Ivan V.
      - Date:          Last updated 03/02/09
      - Description:   This is a JS driving opening, closing and scrolling of olo popups 
*/
function getPageDimensions()
{
	var body = document.getElementsByTagName("body")[0];
	var bodyOffsetWidth=0;
	var bodyOffsetHeight=0;
	var bodyScrollWidth=0;
	var bodyScrollHeight=0;
	var pageDimensions = [0,0];
	
	if(typeof document.documentElement !="undefined" && typeof document.documentElement.scrollWidth != "undefined")
	{
		pageDimensions[0] = document.documentElement.scrollWidth;
		pageDimensions[1] = document.documentElement.scrollHeight;
	}
	
	bodyOffsetWidth=body.offsetWidth;
	bodyOffsetHeight=body.offsetHeight;
	bodyScrollWidth=body.scrollWidth;
	bodyScrollHeight=body.scrollHeight;
	
	if(bodyOffsetWidth > pageDimensions[0])
	{
		pageDimensions[0] = bodyOffsetWidth;
	}
	
	if(bodyOffsetHeight > pageDimensions[1])
	{
		pageDimensions[1] = bodyOffsetHeight;
	}
	
	if(bodyScrollWidth > pageDimensions[0])
	{
		pageDimensions[0] = bodyScrollWidth;
	}
	
	if(bodyScrollHeight > pageDimensions[1])
	{
		pageDimensions[1] = bodyScrollHeight;
	}
	return pageDimensions;
}

function getViewportSize(){
	var size=[0,0];
	if(typeof window.innerWidth != 'undefined')
	{
		size=[
			window.innerWidth,
			window.innerHeight
		];
	}
	else if (typeof document.documentElement!='undefined' && typeof document.documentElement.clientWidth!='undefined' && typeof document.documentElement.clientWidth!=0){
		
		size=[
			document.documentElement.clientWidth,
			document.documentElement.clientHeight
		];
	}
	else
	{
		size=[
			document.getElementsByTagName('body')[0].clientWidth,
			document.getElementsByTagName('body')[0].clientHeight
		];
	}
	return size;	
} 

function makeDim(){
	var body = document.getElementsByTagName("body")[0];
	var pageDimensions=getPageDimensions();
	var viewportSize=getViewportSize();
	
	if(viewportSize[1]>pageDimensions[1])
	{
		pageDimensions[1]=viewportSize[1];
	}
	var dropSheet=document.createElement("div");
	dropSheet.setAttribute("id", "dropSheet");
	dropSheet.style.position = "absolute";
	dropSheet.style.left = "0";
	dropSheet.style.top = "0";
	if (document.all) {
		dropSheet.style.width = parseInt(pageDimensions[0]) +"px";
	} else {
		dropSheet.style.width = pageDimensions[0] +"px";
	}
	dropSheet.style.height = pageDimensions[1]+"px";
	dropSheet.style.zIndex = 1000;
	body.appendChild(dropSheet);		
}

function getScrollY() {
    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 scrOfY;
  }

function showPopup(frameId, divId, listSize, dontDim, leftOfCenter) {
	
    if (!listSize || listSize == null) {
    	listSize = 0;
    }
    var frameHeight = 140 + listSize * 25;
	if (!dontDim) {
		makeDim();
	}
	if (!leftOfCenter || leftOfCenter == '' || leftOfCenter == null) {
		leftOfCenter = 200;
	}

	var viewportSize = getViewportSize();
	var browserWidth = viewportSize[0];
	var browserHeight = viewportSize[1];

	leftPos = parseInt((browserWidth/2) - leftOfCenter);
	topPos = parseInt((browserHeight/2) - leftOfCenter) + parseInt(getScrollY());
	
	document.getElementById(divId).style.display = "";
	document.getElementById(divId).style.visibility = "visible";
	if (listSize > -2) {
		document.getElementById(divId).style.left = leftPos + "px";
		document.getElementById(divId).style.top = topPos + "px";
	}
	if (listSize > -1) {
		document.getElementById(divId).style.height = "auto";
	}
	document.getElementById(divId).style.zIndex = 1010;

	if (divId == "crosssell-popup") {
	    if($OLO("freeDeliveryFlag")) {
	    	if($OLO("freeDeliveryFlag").value == "Y") {
			    myEventTracker('Delivery Offer','View','View Delivery Offer');
	    	}
	    }        
	} 
	
	if (frameId) {
	    if (document.getElementById(frameId) && navigator.userAgent.toLowerCase().indexOf("msie 6") != -1) {
			document.getElementById(frameId).style.visibility = "visible";
			if (listSize > -2) {
				document.getElementById(frameId).style.left = leftPos + 1 + "px";
				document.getElementById(frameId).style.top = topPos + 5 + "px";
			}
			if (listSize > -1) {
				document.getElementById(frameId).style.height = frameHeight;
			}
			document.getElementById(frameId).style.zIndex = 1000;
		}
	}
	    
	activePopupDiv = divId;
	activePopupFrame = frameId;
	activePopupListSize = listSize;
	activePopupLeftOfCenter = leftOfCenter;
    
}



function showBuilderPopup(frameId, divId, strType) {

    var objTitle = document.getElementById('builderPopupTitle');
    var objContent = document.getElementById('builderPopupContent');
    var strTitle = "WHOA THERE";
    var strContent = "";

    if (strType == "toppings") {
        strContent = "That's quite a pizza you're building.  But please, be responsible " +
            "with your toppings.  Too many can leave your pizza on the soggy side.  So keep it to 10 toppings or less.";
    } else if (strType == "crust") {
        strContent = "Crustless pizza, huh?  Could be huge.  We'll start crunching the numbers and trying " +
            "to perfect it.  Until then, please select a crust.";
    } else if (strType == "size") {
        strContent = "Please select a size.  The suspense is killing us.";
    } else if (strType == "nocheese") {
        strTitle = "TRUST US";
        strContent = "We know you don't want cheese on your pizza but showing your pizza " +
            "in just its sauce is a little risqué.  Rest assured though, we won't put cheese on your pizza.";
    } else if (strType == "lightcheese") {
        strTitle = "TRUST US";
        strContent = "Showing light cheese on your pizza could reveal something a little too saucy for our website. " +
            "Don't worry though, we'll put light cheese.";
    } else if (strType == "extracheese") {
        strTitle = "TRUST US";
        strContent = "We know you ordered extra cheese but flaunting that much cheesy goodness in front of you seems " +
            "a bit cruel. Rest assured though, we'll put extra cheese on your pizza.";
    }

    if (objTitle) {
        objTitle.innerHTML = strTitle;
    }
    if (objContent) {
        objContent.innerHTML = strContent;
    }

    alert(strContent);

	/*makeDim();
	var viewportSize = getViewportSize();
	var browserWidth = viewportSize[0];
	var browserHeight = viewportSize[1];
	document.getElementById(divId).style.visibility = "visible";

	leftPos = parseInt((browserWidth/2) - 200);
	document.getElementById(divId).style.left = leftPos + "px";
	topPos = parseInt((browserHeight/2) - 200) + parseInt(getScrollY());
	document.getElementById(divId).style.top = topPos + "px";
	document.getElementById(divId).style.zIndex = 1010;
	
    if (document.getElementById(frameId) && navigator.userAgent.toLowerCase().indexOf("msie 6") != -1) {
		document.getElementById(frameId).style.visibility = "visible";
		document.getElementById(frameId).style.top = topPos + 5 + "px";
		document.getElementById(frameId).style.left = leftPos + 1 + "px";
		document.getElementById(frameId).style.zIndex = 1000;
		document.getElementById(frameId).style.height = 140;
	}*/  
}


function closePopupNew(frameId, divId) {
	var body = document.getElementsByTagName("body")[0];
	var dropSheet = document.getElementById("dropSheet");
	if (dropSheet) {
		body.removeChild(dropSheet);
	}
	document.getElementById(divId).style.display = "none";
	document.getElementById(divId).style.visibility = "hidden";
	
	if (frameId) {
		if (document.getElementById(frameId)) {
			document.getElementById(frameId).style.visibility = "hidden";
		}
	}
		
	activePopupDiv = "";
	activePopupFrame = "";
	activePopupListSize = "";
	activePopupLeftOfCenter = "";
}


function closeBuilderPopup(frameId, divId) {
	var body = document.getElementsByTagName("body")[0];
	var dropSheet = document.getElementById("dropSheet");
    var strAddPizza = "false";
    var strProductNum = "";
	body.removeChild(dropSheet);
	document.getElementById(divId).style.visibility = "hidden";
	
	if (document.getElementById(frameId)) {
		document.getElementById(frameId).style.visibility = "hidden";
	}
    if (document.getElementById('builderPopup')) {
        strAddPizza = document.getElementById('builderPopup').getAttribute("addPizza");
    }
    if (document.getElementById('builderPopup')) {
        strProductNum = document.getElementById('builderPopup').getAttribute("prodNumber");
    }

    addPizza();
	
} //closeBuilderPopup()

