//=============================================================
// POPUP UTILS
//-------------------------------------------------------------
//opens a schreenshot popup from Game-page
function popScreenshot(gCode,imgName, imgWidth, imgHeight)
{
	window.open("screenshot.aspx?code=" + gCode + "&src="+imgName, "screenshot", "toolbar=no, status=no, resize, width=" + imgWidth + ", height=" + imgHeight + " ")
	return
}
//-------------------------------------------------------------
// opens an online-game popup
function popOnlineExt(gameUrl, gameCode, origin, width, height) {    
    window.open(gameUrl + "?code=" + gameCode + "&origin=" + origin, "online", "width=" + width + ", height=" + height);
    return;
}
//-------------------------------------------------------------
// opens an online-game popup
function popPlayOnline(gCode, gWidth, gHeight){
	if (window != top)
		top.popPlayOnline(gCode, gWidth, gHeight);

	var oWidth, oHeight, oWindow
	oWidth = parseInt(gWidth) +80
	oHeight = parseInt(gHeight) - 250
	oWindow=window.open("/PlayOnline.aspx?code="+gCode,'null',"width=" + oWidth + ",Height=" + oHeight + ",status=no,toolbar=no,menubar=no,location=no,resizeable=yes")
	oWindow.focus()
}
//-------------------------------------------------------------
// opens an online-game popup
function popPlayOnline2(gameUrl, gCode, gWidth, gHeight){
	if (window != top)
		top.popPlayOnline2(gameUrl, gCode, gWidth, gHeight)
		
	var oWidth, oHeight, oWindow, oURL
	oWidth = parseInt(gWidth) +80
	oHeight = parseInt(gHeight) - 250
	oURL = gameUrl + "?code=" + gCode
	
	if(oURL.charAt(0) != "/" && -1 == oURL.indexOf("http://") && -1 == oURL.indexOf("https://")) 
		oURL = "/" + oURL;
			
	oWindow=window.open(oURL ,'null',"width=" + oWidth + ",Height=" + oHeight + ",status=no,toolbar=no,menubar=no,location=no,resizeable=yes")
	oWindow.focus()
}
//=============================================================
// OMNITURE URILS
//-------------------------------------------------------------
//Logs an omniture event - wrapper
function omnitureLogDownload(gameCode, omnitureChannel,gameName,catName,dlDateTime) {
	try{
	omnitureLogDownload_Real(gameCode, omnitureChannel,gameName,catName,dlDateTime);
	}
	catch(e){}
}
//-------------------------------------------------------------
//stores the download time per sku fixme and refid?
//the page that is calling this function is required to include the omniture js files   
function omnitureLogDownload_Real(gameCode, omnitureChannel,gameName,catName,dlDateTime) {
	var expirationPeriod = 180; //the number of days before expiration
	var today = new Date();
	try{		
	setCookie(gameCode,today,expirationPeriod);

	s_linkType="d";
	s_linkName=gameName;
	s_events="event1";
	s_products=catName + ";" + gameName;
	s_lnk=s_co(this);		
	s_eVar11=dlDateTime;
	s_gs(omnitureChannel);
	}
	catch(e){}
	return true;
}
//=============================================================
// IFRAME UTILS
//-------------------------------------------------------------
function sendOpenerToUrl(url){
	if(null == window.opener || window.opener.closed){
		var iWidth = screen.availWidth - 10;
		var iHeight = screen.availHeight - 150;
		window.open(url,'_blank',"width=" + iWidth + ",Height=" + iHeight + ",top=0,left=0,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes,maximize=yes")
	}else{
		opener.top.location=url;
		opener.focus();
	}
}
//-------------------------------------------------------------
/*function resizeContentIFrame(srcEvent, newHeight) 
{
	try
	{
		if (newHeight == null)
			newHeight = document.frames("ContentIFrame").document.body.scrollHeight + 20;
			document.getElementById("ContentIFrameTable").height = newHeight;
	}
	catch(e) { }
}*/
//-------------------------------------------------------------


function resizeContentIFrame(srcEvent, newHeight)
{
	try
		{
			if (newHeight == null)
			{
				var IframeObj = document.getElementById("ContentIFrame");
				var TableObj = document.getElementById("ContentIFrameTable");
				IframeObj.height = window.frames["ContentIFrame"].document.body.scrollHeight;
				TableObj.height = (IframeObj.height)*1 ;

			}
		}
	catch(e) 
	{
	}
}








function addExternalDashboardIFrame(strHTML){
	try{
		var e = document.createElement('<Div></div>');
		e.innerHTML = strHTML;
		var p = document.getElementById("tdBottom")
		while (p.hasChildNodes())
			p.childNodes(0).removeNode(true); 
			
		p.appendChild( e );
	}catch(e){
		alert(e.message)
	}
}
//-------------------------------------------------------------
function AlignHomePageCats(){
	var total=0
	row1 = new Array('CatTable_0','CatTable_1','CatTable_2')
	row2 = new Array('CatTable_3','CatTable_4','CatTable_5')
	row3 = new Array('CatTable_6','CatTable_7','CatTable_8')
	row  = new Array(row1,row2,row3)
	tempArr=null

	j=0
	do{
		i=0
		tempArr = new Array()
		do{
			divID=eval(row[j][i]+"LST.offsetHeight")
			tempArr[tempArr.length]=divID
			i++
		}while (i<3)
		
		rowMax=Math.max(tempArr[0],tempArr[1],tempArr[2])
		total = total + rowMax
		i=0
		do{
			gap=rowMax-tempArr[i]
			var oid = eval(row[j][i]+"Gap")
			oid.style.height=17+gap
			i++	
		}while (i<3)
		j++
	}while(j<3)
		
	//optional to align also the HOT GAMES column
	hotLST.style.height=total+190
}
//=============================================================
// COOKIES UTILS
//-------------------------------------------------------------
//name - the name of cookie
function getCookie(name) { 
	var index = document.cookie.indexOf(name + "=");
	if (index == -1) return null;
	index = document.cookie.indexOf("=", index) + 1;
	var endstr = document.cookie.indexOf(";", index);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(index, endstr));
}
//-------------------------------------------------------------
//name - the name of cookie
//value - the value of the cookie
//expiration - the expiration period of the cookie (in days)
//name - the name of cookie
//value - the value of the cookie
//expiration - the expiration period of the cookie (in days)
function setCookie(name, value, expiration) { // use: setCookie("name", value);
	try {
		var strDate = new String();
		strDate = value.toString();
		//replace all chars with URL encoding
		while (strDate.indexOf(" ") != -1) {
			strDate = strDate.replace(" ","%20");
		}
		while (strDate.indexOf(":") != -1) {
			strDate = strDate.replace(":","%3A");
		}
		strDate = strDate.replace("+","%2B");
		strDate = strDate.replace("-","%2D");
		var today = new Date();
		var expiry = new Date(today.getTime() + expiration * 24 * 60 * 60 * 1000); 
		if (strDate != null && strDate != "") {
			document.cookie=name + "=" + strDate + "; expires=" + expiry.toGMTString();
		}
	}
	catch(e){}
}
