
// global.js


function setcookie (name,value,expires,path,domain,secure) {
// amend pl - pilot - august 2007 - removed hardcoded domain name
 var cookiestr =   name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "") +   ((secure) ? "; secure" : "");
 document.cookie = cookiestr;
}

//PL - 2007-09-11 function definition moved from HTML 
function params(wut,qp,dflt){ dflt=(dflt==null)?'':dflt; try{r=unescape(wut.match(new RegExp(qp+"=+([^&;]*)"))[1]);}catch(qp){r=dflt;} return r; }
	
var getparams = params; // PL - 2007-09-11 alias the function so the definition is not duplicated


// PL - 2007-09-12 function to calculate the correct wmode for the main flash movie when showing ads
function getWmodeForAds() {
	return (navigator.userAgent.toLowerCase().indexOf("mac")>-1)?"transparent":"opaque";
}


function getCartCount() {
    count = getparams(document.cookie, "DSIshopcartcount", null);
    if (count == null || isNaN(count)) {
        return 0;
    }
    count = parseInt(count);
    return (count == NaN)  ? 0 : count;
}

function isLoggedIn() {
    var blue = getparams(document.cookie, "BLUE", null);
    if (blue == null || blue == "") {
        return false;
    } else {
        return true;
    }
}

// used to clear default text in search boxes
function setIfBlank(obj, defaulttext)
{
    if (obj.value == "") {
        obj.value = defaulttext;
    }
}

// used to populate default text in search boxes
function clearIfDefault(obj, defaulttext)
{
    if (obj.value == defaulttext) {
        obj.value = "";
    }
}

////////////////////////////////////////////////////////////////////////////////////
// Code to control dynamic relocation of ads when pages are resized.
// - Retrieved from the US site - 20071204 - PL

var theAdDiv;
var adItem;
function adMover(theAdDiv, minWidth, minHeight) {



	this.div = theAdDiv;
	this.minW = minWidth;
	this.minH = minHeight;
	
	var o = this;
	this.addWindowEvent( 'onresize', this, this.onResizeDiv );
}

adMover.prototype = {
	addWindowEvent: function( eventName, scope, func )
	{
		var oldEvent = window[ eventName ];
		if (typeof window[ eventName ] != 'function') window[ eventName ] = function(){ func.call( scope ); };
		else
		{
			window[ eventName ] = function()
			{ 
				if( oldEvent ) oldEvent();
				func.call( scope );
			}
		}
		
	},

	getWinSize: function()
	{
		var winW;
		if (parseInt(navigator.appVersion)>3) {
			if ( document.body.offsetWidth ){ // Gecko / WebKit
				winW = document.body.offsetWidth;
			} else if ( document.body.offsetWidth ){ // MS
				winW = document.body.offsetWidth;
			}
		}
		return { width: winW };
	},
	
	
	onResizeDiv: function()
	{
		var winSize = this.getWinSize();
		if (!(winSize.width === undefined)) {
			var w = winSize.width < this.minW? 691+"px" : (((winSize.width - this.minW) / 2) + 691) + "px";
			if (document.getElementById("MediumRectangle") != null) {
				document.getElementById("MediumRectangle").style.left = w;
				document.getElementById("MediumRectangle").style.visibility = 'visible';
			}
			if (document.getElementById("Super") != null) {
				w = winSize.width < this.minW? 131+"px" : (((winSize.width - this.minW) / 2) + 131) + "px";
				document.getElementById("Super").style.left = w;
				document.getElementById("Super").style.visibility = 'visible';
			}
			// updated skyscraper for EMEA widths - PL - 20071204
			if (document.getElementById("Skyscraper") != null) {
				w = winSize.width < this.minW? 862+"px" : (((winSize.width - this.minW) / 2) + 862) + "px";
				document.getElementById("Skyscraper").style.left = w;
				document.getElementById("Skyscraper").style.visibility = 'visible';
			}
			if (document.getElementById("MidLeftPromote") != null) {
				w = winSize.width < this.minW? 6+"px" : (((winSize.width - this.minW) / 2) + 6) + "px";
				document.getElementById("MidLeftPromote").style.left = w;
				document.getElementById("MidLeftPromote").style.visibility = 'visible';
			}
			if (document.getElementById("HSMSkyscraper") != null) {
				w = winSize.width < this.minW? 826+"px" : (((winSize.width - this.minW) / 2) + 826) + "px";
				document.getElementById("HSMSkyscraper").style.left = w;
				document.getElementById("HSMSkyscraper").style.visibility = 'visible';
			}
		}
	}
}
