var popUnderWindowReference = null;



/* Returns information about browser window as 2 element array:

    [0] = width in pixels

    [1] = height in pixels */

function getWindowDimensions() {

    var windowDimensions=new Array(630,460);

    if (parseInt(navigator.appVersion)>3) {

        if (navigator.appName=="Netscape") {

            windowDimensions[0] = window.innerWidth;

            windowDimensions[1] = window.innerHeight;

        }

        if (navigator.appName.indexOf("Microsoft")!=-1) {

            windowDimensions[0] = document.body.offsetWidth;

            windowDimensions[1] = document.body.offsetHeight;

        }

    }

    return windowDimensions;

}



/* Returns information about browser window as 2 element array:

    [0] = number of pixels from left of screen

    [1] = number of pixels from top of screen */

function getWindowLocation() {

    var windowOffsets=new Array(0,0);

    if (parseInt(navigator.appVersion)>3) {

        if (navigator.appName=="Netscape") {

            windowOffsets[0] = window.screenX;

            windowOffsets[1] = window.screenY;

        }

        if (navigator.appName.indexOf("Microsoft")!=-1) {

            windowOffsets[0] = window.screenLeft;

            windowOffsets[1] = window.screenTop;

        }

    }

    return windowOffsets;

}



function freeShippingPopups() {

    revealElement("FreeShippingDescription", 300, 390);

    //popUnder();

    window.focus();

}



/* Spawns new up window and sets it's Z order equal to the existing browser window - 1. */

function popUnder() {

    var dimensions = getWindowDimensions();

    var windowLocation = getWindowLocation();

    /* This window is intended to open underneath the current browser window, so

       prevent the user from accidentally spawning several new browser windows */

	var merchant = 999;
	switch(BCNTRY.site.catalog){
		case 'bonktown': merchant = 801; break;
		case 'brociety': merchant = 798; break;
		case 'chainlove': merchant = 796; break;
		case 'steepcheap': merchant = 799; break;
		case 'tramdock': merchant = 800; break;
		case 'wm': merchant = 797; break;
	}

    if (popUnderWindowReference == null || popUnderWindowReference.closed) {

        popUnderWindowReference = window.open('https://www.freeshipping.com/join.asp?PID2='+merchant,'','status=1,toolbar=1,location=1,menubar=1,resizable=1,scrollbars=1,width='+dimensions[0]+',height='+dimensions[1]+',left='+windowLocation[0]+',top='+windowLocation[1]);

    }

}



/* Generic method to reveal an element that had previously

   been hidden by the CSS style "display:hidden".

   elementID == string of an id in the DOM

   popWidth sets the width of the revealed element

   popHeight sets the height of the revealed element

   Assert: elementID exists in the DOM */

function revealElement(elementID, popWidth, popHeight) {

    var windowDimensions = getWindowDimensions();    

    try {

        var element = document.getElementById(elementID);

        element.style.display = "block";

        element.style.left = windowDimensions[0]/2 - popWidth/2;

        element.style.top = windowDimensions[1]/2 - popHeight/2;

        element.style.width = popWidth;

        element.style.height = popHeight;

    } catch (ex) {

        //elementID was not found in the DOM;

    }

}



/* Hides a named element in the DOM

    Assert: element has id attribute and value. */

function hideElement(element) {

    try {

        document.getElementById(element.id).style.display="none";

    } catch (ex) {    

        //element does not have an id.

    }

}



/* The next four functions are to work around a known

    bug in IE 6 where select elements always appear at

    the highest z-order, regardless of CSS styling */



/* hides the select elements on a page */

function hideSelects(){



    if ( (navigator.appName.indexOf("Microsoft")!=-1) && (parseInt(navigator.appVersion)>3) && (parseInt(navigator.appVersion)<7) )

    {    

	    var oSelects=document.getElementsByTagName("select");

	    for(var i=0;i<oSelects.length;i++)

	    {

		    oSelects[i].style.display="none";

	    }

	}

}



/* restores the select elements on a page */

function showSelects(){

	if ( (navigator.appName.indexOf("Microsoft")!=-1) && (parseInt(navigator.appVersion)>3) && (parseInt(navigator.appVersion)<7) )

    {    

	    var oSelects=document.getElementsByTagName("select");

	    for(var i=0;i<oSelects.length;i++)

	    {

		    oSelects[i].style.display ="inline";

    	}

    }

}
