
// 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=.telefe.com") +   ((secure) ? "; secure" : "") + "'");
    document.cookie = name + "=" + (value) + ((expires) ? "; expires=" + expires.toUTCString() : "") + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "; domain=.telefe.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=.telefe.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? 867+"px" : (((winSize.width - this.minW) / 2) + 867) + "px";
			if (document.getElementById("rascacielo") != null) {
				document.getElementById("rascacielo").style.left = w;
				document.getElementById("rascacielo").style.visibility = 'visible';
			}
			if (document.getElementById("top_left") != null) {
				w = winSize.width < this.minW? 52+"px" : (((winSize.width - this.minW) / 2) + 52) + "px";
				document.getElementById("top_left").style.left = w;
				document.getElementById("top_left").style.visibility = 'visible';
			}
			if (document.getElementById("top_right") != null) {
				w = winSize.width < this.minW? 700+"px" : (((winSize.width - this.minW) / 2) + 700) + "px";
				document.getElementById("top_right").style.left = w;
				document.getElementById("top_right").style.visibility = 'visible';
			}
			
			if (document.getElementById("live") != null) {
				w = winSize.width < this.minW? 10+"px" : (((winSize.width - this.minW) / 2) + 10) + "px";
				document.getElementById("live").style.left = w;
				document.getElementById("live").style.visibility = 'visible';
			}
						
			if (document.getElementById("main_top") != null) {
				w = winSize.width < this.minW? 133+"px" : (((winSize.width - this.minW) / 2) + 133) + "px";
				document.getElementById("main_top").style.left = w;
				document.getElementById("main_top").style.visibility = 'visible';
				
				}
						
			if (document.getElementById("music_left") != null) {
				w = winSize.width < this.minW? 17+"px" : (((winSize.width - this.minW) / 2) + 17) + "px";
				document.getElementById("music_left").style.left = w;
				document.getElementById("music_left").style.visibility = 'visible';
				
				}
						
			if (document.getElementById("main_music_right") != null) {
				w = winSize.width < this.minW? 797+"px" : (((winSize.width - this.minW) / 2) + 797) + "px";
				document.getElementById("main_music_right").style.left = w;
				document.getElementById("main_music_right").style.visibility = 'visible';
				
				}
						
			if (document.getElementById("telefenoticias") != null) {
				w = winSize.width < this.minW? 5+"px" : (((winSize.width - this.minW) / 2) + 5) + "px";
				document.getElementById("telefenoticias").style.left = w;
				document.getElementById("telefenoticias").style.visibility = 'visible';
			
			}
			
			if (document.getElementById("top_left_noticias") != null) {
				w = winSize.width < this.minW? 16+"px" : (((winSize.width - this.minW) / 2) + 16) + "px";
				document.getElementById("top_left_noticias").style.left = w;
				document.getElementById("top_left_noticias").style.visibility = 'visible';
			
			}
			
				if (document.getElementById("top_right_noticias") != null) {
				w = winSize.width < this.minW? 514+"px" : (((winSize.width - this.minW) / 2) + 514) + "px";
				document.getElementById("top_right_noticias").style.left = w;
				document.getElementById("top_right_noticias").style.visibility = 'visible';
			
			}
			
			if (document.getElementById("top_left_talento") != null) {
				w = winSize.width < this.minW? 11+"px" : (((winSize.width - this.minW) / 2) + 11) + "px";
				document.getElementById("top_left_talento").style.left = w;
				document.getElementById("top_left_talento").style.visibility = 'visible';
			
			}
			
				if (document.getElementById("top_right_talento") != null) {
				w = winSize.width < this.minW? 796+"px" : (((winSize.width - this.minW) / 2) + 796) + "px";
				document.getElementById("top_right_talento").style.left = w;
				document.getElementById("top_right_talento").style.visibility = 'visible';
			
			}
						
			if (document.getElementById("tlfhomeleft") != null) {
				w = winSize.width < this.minW? 15+"px" : (((winSize.width - this.minW) / 2) + 15) + "px";
				document.getElementById("tlfhomeleft").style.left = w;
				document.getElementById("tlfhomeleft").style.visibility = 'visible';
				
				}
						
			if (document.getElementById("tlfhomeright") != null) {
				w = winSize.width < this.minW? 797+"px" : (((winSize.width - this.minW) / 2) + 797) + "px";
				document.getElementById("tlfhomeright").style.left = w;
				document.getElementById("tlfhomeright").style.visibility = 'visible';

				}
				
				if (document.getElementById("tlfhomerightteatro") != null) {
				w = winSize.width < this.minW? 695+"px" : (((winSize.width - this.minW) / 2) + 695) + "px";
				document.getElementById("tlfhomerightteatro").style.left = w;
				document.getElementById("tlfhomerightteatro").style.visibility = 'visible';

				}

						
			if (document.getElementById("ot_right") != null) {
				w = winSize.width < this.minW? 797+"px" : (((winSize.width - this.minW) / 2) + 797) + "px";
				document.getElementById("ot_right").style.left = w;
				document.getElementById("ot_right").style.visibility = 'visible';

				}
						
			if (document.getElementById("ot_bottom_right") != null) {
				w = winSize.width < this.minW? 797+"px" : (((winSize.width - this.minW) / 2) + 797) + "px";
				document.getElementById("ot_bottom_right").style.left = w;
				document.getElementById("ot_bottom_right").style.visibility = 'visible';
				}
						
			if (document.getElementById("ot_bottom_left") != null) {
				w = winSize.width < this.minW? 10+"px" : (((winSize.width - this.minW) / 2) + 10) + "px";
				document.getElementById("ot_bottom_left").style.left = w;
				document.getElementById("ot_bottom_left").style.visibility = 'visible';
				
}
						
			if (document.getElementById("ot_top_right") != null) {
				w = winSize.width < this.minW? 780+"px" : (((winSize.width - this.minW) / 2) + 780) + "px";
				document.getElementById("ot_top_right").style.left = w;
				document.getElementById("ot_top_right").style.visibility = 'visible';
}
				
			if (document.getElementById("ver_para_leer") != null) {
				w = winSize.width < this.minW? 780+"px" : (((winSize.width - this.minW) / 2) + 780) + "px";
				document.getElementById("ver_para_leer").style.left = w;
				document.getElementById("ver_para_leer").style.visibility = 'visible';
}
		
				
			if (document.getElementById("ot_top_left") != null) {
				w = winSize.width < this.minW? 10+"px" : (((winSize.width - this.minW) / 2) + 10) + "px";
				document.getElementById("ot_top_left").style.left = w;
				document.getElementById("ot_top_left").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;
}



