function getUserAgent() {
    return navigator.userAgent;
}
function reloadGame(arg) {
    SWFAddress.setValue("");
    document.location.reload(true);
}
var oldTitle = null;
var pingInterval = null;
function ping(msg) {
    if (pingInterval) {
      clearInterval(pingInterval);
      document.title = oldTitle;
    }

    oldTitle = document.title;
    if (!msg) msg = oldTitle;
    pingInterval = setInterval(function() {
        document.title = (document.title == msg) ? oldTitle : msg;
    }, 1000);
    window.onmousemove = function() {
        clearInterval(pingInterval);
        document.title = oldTitle;
        window.onmousemove = null;
    };
}
function getUser() {
    return getCookie('u');
}
function rememberUser(u) {
    setCookie("u", u, 365);
}
function doNotRememberUser() {
    setCookie("u", "", -1);
}

function getCookie(c_name) {
    if (document.cookie.length>0) {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1) {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}
function setCookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+ ";path=/"+
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

//Grab URL parameter
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

var setScroll = function(){
  var win = $(window);
  if (win.width() > 1024 && win.height() > 609) {
    var body = $('body');
    body.scrollTop();
    body.css('overflow', 'hidden');
  }
};


// navigation-related
var standardParams = {
    "allowScriptAccess": "always",
    "quality": "high",
    "bgcolor": "#1598be"
}

var mode;

function getMode() {
    return mode;
}

function switchMode(moduleName) {
    SWFAddress.setValue("/" + moduleName);
    if (mode == "external") {
        loadMain();
    } else {
        loadExternal();
    }
}


function loadExternal() {
    unloadCurrent();
    mode = "external";
    setTimeout("doLoadExternal()", 10);
}

function doLoadExternal() {
    swfobject.embedSWF("ExternalModule.swf", "application", 1024, 609, "9.0.0", false, standardParams, {"id": "xekoswf"});
}

function unloadCurrent() {
    if (mode) {
        swfobject.removeSWF("xekoswf");
        $('#wrapper').append('<div id="application">');
    }
}