function handleErrorMsg(msg)
{
    var birthday = document.getElementById("birthday");
    if (birthday)
        birthday.style.display = "none";
    var elem = document.getElementById("errWindow")
//    if (elem)
 //       elem.style.display = "block";
    elem = document.getElementById("errMsg")
    if (elem)
    {
//        elem.innerHTML = msg;
        replaceHtml(elem, msg);
    }

	var playsafe =    	document.getElementById("playSafeWindow")
    if (playsafe)
    	playsafe.style.display="none";
    elem = document.getElementById("backlink")
    elem.style.display = "none";
    elem.style.display = "block";

    $("#errWindow").fadeIn("fast");
}

function handleSuspendErrorMsg(suspendStr)
{
    var colIndex=suspendStr.indexOf(":");
    var timeLeftStr = suspendStr.substring(colIndex + 1);
    var timeLeft = new Number(timeLeftStr)            
    timeLeft = timeLeft/60000;
    var hours = timeLeft/60;
    var minutes = timeLeft % 60;
    var msg = "You have been suspended from SuperSecret. Your account will be reactivated in " 
    hours = Math.floor(hours);
    minutes= Math.floor(minutes);
    if (hours != 0)
        msg +=  hours + " hours";
    if (hours != 0 && minutes != 0)
        msg += " and "
    if (minutes != 0)
        msg += minutes + " minutes"
    if (minutes == 0 && hours == 0) // case where its < 60 seconds
        msg += "a few minutes";
    msg += ". "; 

    handleErrorMsg(msg);

}

function replaceHtml(el, html) {
	var oldEl = typeof el === "string" ? document.getElementById(el) : el;
	/*@cc_on // Pure innerHTML is slightly faster in IE
		oldEl.innerHTML = html;
		return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	/* Since we just removed the old element from the DOM, return a reference
	to the new element, which can be used to restore variable references. */
	return newEl;
};

function closeErrMsg()
{
    var birthday = document.getElementById("birthday");
    if (birthday)
        birthday.style.display = "block";
    var elem = document.getElementById("errWindow")
    //if (elem)
    //    elem.style.display = "none";
    $("#errWindow").fadeOut("fast");
}

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 null;
}

function deleteCookie( name, path, domain ) {
    if ( getCookie( name ) ) 
    {
        var cookie_date = new Date();
        cookie_date.setTime(cookie_date.getTime() - 10);
        document.cookie = name + "=;Domain=" + domain + ";Expires=" + cookie_date.toGMTString() +"; Path=" + path;
    }
}

function getBaseDomain()
{
    var parts = document.domain.split('.');
    if (parts.length < 2)
    {
        return document.domain;
    }
    else
    {
        var domain = '.' + parts[parts.length-2] + '.' + parts[parts.length-1];
        return domain;
    }
}

function openInfoWindow(url, noLimitSize )
{
   var dimensions = "";
    if (noLimitSize == undefined)
        dimensions = "width=1000,height=580,";
    var winNew = window.open(url, 'info', dimensions + 'scrollbars=yes,resizeable=yes' ); 
    var shell =  document.getElementById("worldShell");
// this is to allow popups (from flash) on both safari and firefox. need to be able to try opening from both sides...this part below is in particular for the blog page
    if (shell == undefined || shell != null)
    {
        if ((winNew == undefined) || !winNew)
        {
             shell.openBrowserWindow(url);
        }
        else
             winNew.focus();
    }
    return "true";
}

function getErrorMsg(code)
{
    if ("USER_BANNED" == code)
        return "You have been banned from SuperSecret because you violated one of the SuperSecret Ground Rules. ";
    else if ("USER_SUSPENDED" == code)
        return "You have been suspended from SuperSecret for 24 hours. Please <a href='/login-server/spring/contactus'>contact us</a> if you have any questions.";
    else
        return "SuperSecret is down for routine maintenance. Please try again later.";
}



