var fMozilla	= (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
var fSafari		= navigator.userAgent.toLowerCase().indexOf("safari") != -1;
var fIE			= !this.fMozilla && !this.fSafari;	// default to IE

if (fMozilla)
	document.write("<script src='/js/mozilla.js'></script>");


/******************************************************************
 * Sting extensions
 */
 
/**
 * Replaces {0}..{n} substrings with argument values
 * @return {string} The newly formatted string
 */
String.prototype.format = function()
{
	var s = this;
	for (var i=0; i < arguments.length; i++)
		s = s.replace("{" + (i) + "}", arguments[i]);
	return(s);
};

/**
 * Trims non-text characters from the beginning of the string
 * @return {string} The newly trimmed string
 */
String.prototype.lTrim = function () {return this.replace(/^\s*/, "");};

/**
 * Trims non-text characters from the end of the string
 * @return {string} The newly trimmed string
 */
String.prototype.rTrim = function () {return this.replace(/\s*$/, "");};

/**
 * Trims non-text characters from the beginning and the end of the string
 * @return {string} The newly trimmed string
 */
String.prototype.trim = function () {return this.rTrim().lTrim();};

/**
 * Pads out a string if it is shorter than a specified length
 * @param {integer} pad The requested length of the string
 * @param {string} ch The character to prepend to the string if it is shorter than the given length
 * @return {string} The newly padded string
 */
String.prototype.lpad = function (pad,ch)
{
	var out = "";
	pad = (pad-this.length);
	while(pad-- > 0)
		out += ch;
	out += this;
	return out;
};

/**
 * Checks for specified text at the end of the string
 * @param {string} sEnd Ending text to check for
 * @return {boolean} True if the text is at the end
 */
String.prototype.endsWith = function(sEnd) {return (this.substr(this.length-sEnd.length)==sEnd);};

/**
 * Removes a part of a space delimited string. 
 * 
 * @param {string} r The string to remove
 * @return {string} The modified string
 */
String.prototype.removeSpaceDelimitedString = function(r) 
{
	var s = " " + this.trim() + " ";
	return s.replace(" " + r,"").rTrim();
};


/******************************************************************
 * Namespaces
 *
 * Temporary hack, use constructors to delineate a namespace as
 * JSDoc does not support namespaces
 */

/**
 * @constructor
 */
function ninemsn()
{
}

/**
 * @constructor
 */
ninemsn.AP = function()
{
};


/**
 * @constructor
 */
ninemsn.AP.Util = function()
{
};

/**
 * @constructor
 */
ninemsn.AP.Config = function()
{
};

/**
 * @constructor
 */
ninemsn.AP.Modules = function()
{
};

/**
 * @constructor
 */
ninemsn.AP.Modules.Weather = function()
{
};


/******************************************************************
 * Cookie helpers
 */
 
 /**
  * Reads a cookie value
  *
  * @param  {string} strName The name of the cookie
  * @return {string} The cookie value
  */
function readCookie(strName)
{
	var strCookie = document.cookie;
	
	var ca = strCookie.split(";");
	for(var i=0; i < ca.length; i++)
	{
		var va = ca[i].split("=");
		if (va[0].trim() == strName)
			return va[1];
	}
	
	return null;
}

 /**
  * Writes a cookie value
  *
  * @param {string} strName The name of the cookie
  * @param {string} strVal The value of the cookie
  * @param {string} strDomain The domain of the cookie (optional)
  */
function writeCookie(strName, strVal, strDomain)
{
	var newExpiry;
    
	newExpiry = new Date();
	newExpiry.setYear(newExpiry.getFullYear() + 5);
	
	if (typeof document!='undefined')
	{
		var strCook = (strName+"="+strVal+";expires=" + newExpiry.toGMTString() + ";path=/");
		
		if (strDomain)
		    strCook += ";domain=" + strDomain;

		document.cookie = strCook;
    }
}

 /**
  * Deletes a cookie value
  * 
  * @param {string} strCookieName The name of the cookie
  * @param {string} strDomain The domain of the cookie (optional)
  */
function deleteCookie(strCookieName, strDomain)
{
    var ca = document.cookie.split(';');

    if (ca != null)
    {
        for(var i=0;i<ca.length;i++)
        {
            var c = ca[i];
            
            var n = c.split("=");
            if (n.length > 0)
            {
				var strName = n[0].lTrim();
				
				if (strName == strCookieName)
				{
				    var strCook = strName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
				    if (strDomain)
				        strCook += "domain=" + strDomain + ";";
				        
					document.cookie = strCook;
				}
            }
        }
    }
}


function constructThis(ns, th, arg) { return arg[1]; }
function initializeThis(ns, th, arg) {}
function disposeThis(ns, th, arg) {}
/******************************************************************
 * Array extensions
 */
Array.prototype.indexOf = function(p_var)
{
	for (var i=0; i<this.length; i++)
	{
		if (this[i] == p_var)
		{
			return(i);
		}
	}
	return(-1);
};

Array.prototype.exists = function(p_var)
{
	return this.indexOf(p_var) != -1;
};

Array.prototype.contains = function(item) {
    var index = this.indexOf(item);
    return (index >= 0);
};

Array.prototype.removeAt = function(p_iIndex) {return this.splice(p_iIndex, 1);};










