
// global.js

function setcookie (name,value,expires,path,domain,secure) {
	// If we're passing an expires variable, cast it (if necessary) to a Date
	if (expires) {
		if (typeof(expires) == "number" || typeof(expires) == "string") {
			expires = new Date(expires);
		}
	}
//    alert("the cookie string is '" + name + "=" + (value) + ((expires) ? "; expires=" + expires.toUTCString() : "") + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "; domain=.go.com") +   ((secure) ? "; secure" : "") + "'");
    document.cookie = name + "=" + (value) + ((expires) ? "; expires=" + expires.toUTCString() : "") + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "; domain=.go.com") +   ((secure) ? "; secure" : "");
}

function getparams(wut,qp,dflt){ dflt=(dflt==null)?'':dflt; try{r=unescape(wut.match(new RegExp(qp+"=+([^&;]*)"))[1]);}catch(qp){r=dflt;} return r; }

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 = "";
    }
}



function GetFlashMovieCookie(name) {
	if (document.cookie) {
		var cookies=document.cookie.split(";");
		for (var i=0; i<cookies.length; i++) {
			var varName=(cookies[i].split("=")[0]);
			var varValue=(cookies[i].split("=")[1]);

			while (varName.charAt(0)==" ") {
				varName=varName.substr(1,varName.length);

				// the escape() function will url encode the value				
				if (varName==name) {
					return escape(varValue);
				}
			}
		}
	}
	return "";
}

function GetFlashMoviePageCookies() {
	DCOMMoviePageMovieSelectionValue = "";
	DCOMMoviePageZipCodeValue = "";
	returnString = "";
	if (document.cookie) {
		var cookies=document.cookie.split(";");
		for (var i=0; i<cookies.length; i++) {
			var varName=(cookies[i].split("=")[0]);
			var varValue=(cookies[i].split("=")[1]);

			while (varName.charAt(0)==" ") {
				varName=varName.substr(1,varName.length);
			}
			
			// the escape() function will url encode the value				
			if (varName=="DCOMMoviePageMovieSelection") {
				DCOMMoviePageMovieSelectionValue = escape(varValue);
			}
			if (varName=="DCOMMoviePageZipCode") {
				DCOMMoviePageZipCodeValue = escape(varValue);
			}
		}
	}
	return DCOMMoviePageMovieSelectionValue + "|" + DCOMMoviePageZipCodeValue;
}






function setFlashMovieCookie (name,value,expires,path,domain,secure) {
	
	theDate = new Date(parseInt(expires));

//    alert(name + "=" + escape (value) + ((expires) ? "; expires=" + theDate.toGMTString() : "") + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "; domain=.go.com") +   ((secure) ? "; secure" : ""));
	
    document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + theDate.toGMTString() : "") + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "; domain=.go.com") +   ((secure) ? "; secure" : "");
}


function setFlashMoviePageCookieValues(theZipCode, theZipExpiration, theMovie, theMovieExpiration) {

	var zipExpireDate = new Date(theZipExpiration);
	var movieChoiceExpireDate = new Date(theMovieExpiration);
	
	setcookie('DCOMMoviePageMovieSelection', escape(theMovie), movieChoiceExpireDate,'',location.hostname,'');
	setcookie('DCOMMoviePageZipCode', escape(theZipCode), zipExpireDate,'',location.hostname,'');
	return "OK";
}




// Code to control dynamic relocation of ads when pages are resized.




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';
			}
			if (document.getElementById("Skyscraper") != null) {
				w = winSize.width < this.minW? 825+"px" : (((winSize.width - this.minW) / 2) + 825) + "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';
			}
		}
	}
}


function parseQueryString (theObject) {
	var query = location.search.substring(1);
	var pairs = query.split("&");
	for (var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		value = decodeURIComponent(value);
		theObject[argname] = value;
	}
	return theObject;
}



