/* popup utils */
var resWidth, resHeight;
var avWidth = screen.availWidth;

if (typeof(Ext.isGecko2) == 'undefined') {
    Ext.isGecko2 = false;
    if (Ext.isGecko && (navigator.userAgent.search('Firefox/2.0') != -1)) {
        Ext.isGecko2 = true;
    }
}
if (typeof(Ext.isGecko3) == 'undefined') {
    Ext.isGecko3 = false;
    if (Ext.isGecko && (navigator.userAgent.search('Firefox/3.0') != -1)) {
        Ext.isGecko3 = true;
    }
}
if (typeof(Ext.isCamino) == 'undefined') {
    Ext.isCamino = false;
    if (Ext.isGecko && (navigator.userAgent.search('Camino/') != -1)) {
        Ext.isCamino = true;
    }
}
function browserSafeResize(innerwidth, innerheight) {
	var width, height;
	width  = innerwidth;
	height = innerheight;
	if (Ext.isMac) {
	    if (Ext.isCamino) {
	        height += 40;
	    } else if (Ext.isGecko2) {
            height += 18;
        } else if (Ext.isGecko3) {
            height += 67;
        } else if (Ext.isOpera) {
            height += 41;
        } else if (Ext.isSafari) {
            height += 39;
        } else {
            height += 50;
        }
	} else {
		if (Ext.isGecko2) {
			width  += 8;
			height += 56;
		} else if (Ext.isGecko3) {
			width  += 16;
			height += 86;
		} else if (Ext.isOpera) {
			width  += 18;
			height += 52;
		} else if (Ext.isSafari) {
			width  += 16;
			height += 50;
		} else if (Ext.isIE6) {
			width  += 8;
			height += 54;
	    } else {
		    // suppose it's IE7
			width  += 11;
			height += 81;
	    }
	}		
	window.resizeTo(width, height);
}
function popupsBlocked()  {
	var testWindow = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
	if (testWindow) {
	    var popUpsBlocked = false;
	    testWindow.close();
	} else {
        var popUpsBlocked = true;
	}
	return popUpsBlocked;
}
function openWindow(url, name, width, height, resizable, scrollbars) {   
    var w = window.screen.width;
    var h = window.screen.height;

    if(width > w) {
        width = w / 2;
    }
    if(height > h) {
        height = h / 2;
    }

    var wind = window.open(url, name,
        "resizable=" + resizable +
        ",scrollbars=" + scrollbars +
        ",width=" + width +
        ",height=" + height +
        ",status=yes");
    if (wind) {
        wind.focus();
        wind.opener = window;
    }
    
    return wind;
}

/* flash utils */
function gameLauncherFlash(game_id) {
	gameLauncher(game_id);
}
function getFlash(name) {
    return swfobject.getObjectById(name);
}

/* stylesheet utils */
function appendStyleSheet(href) {
    var head = document.getElementsByTagName('head')[0];
    var link = document.createElement('link');
    link.setAttribute('type', 'text/css');
    link.setAttribute('media', 'screen');
    link.setAttribute('rel', 'stylesheet');
    link.setAttribute('href', href);
    head.appendChild(link);            	
}

/* cookie utils */
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function eraseCookie(name) {
    createCookie(name,"",-1);
}

