/////////////////////////////////////////////////////////////////////////////////////////////////////
// String class
/////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * Check whether string is a local link, ie it has the domain in it 
 * or is a relative link or anchor
 */
String.prototype.isLocalHref = function  () {
	var domain = location.protocol + '//' + location.host + '/';
	return (this.indexOf(domain) == 0 || this.indexOf(location.protocol) == -1)
}

/**
 * Check whether string is a JS link (ie href is assigned to a JS function)
 */
String.prototype.isJavascriptHref = function  () {
	return (this.indexOf('javascript:') == 0)
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
// window.document
/////////////////////////////////////////////////////////////////////////////////////////////////////

window.document.setCookie = function (name, value, exp_y, exp_m, exp_d, path, domain, secure) {
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

window.document.deleteCookie = function ( cookie_name ) {
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

window.document.getCookie = function ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
// window.location
/////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * Returns a hash table of the query string keys=>values
 */
window.location.getQSMap = function (name) {
	if (!location.search)	return new Array();
	
	// Strip the leading '?'
	var qs = location.search.substr(1);
	var qsMap = new Array();
	
	// Chop it up!
	var tmpArr = qs.split('&');
	var tmpArr2 = new Array();
	for (var i=0; i<tmpArr.length; i++) {
		tmpArr2 = tmpArr[i].split('=');
		qsMap[tmpArr2[0]] = unescape(tmpArr2[1]);
	}
	
	return qsMap;
}
