/*
	Suckerfish drop downs. This is the handler for Windows IE, 
 	which doesn't support the :hover pseudo selector on anything but "a" tags
*/
sfHover = function() 
{
	var sfEls = document.getElementById("sitenavigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) 
	{
		sfEls[i].onmouseover=function() 
		{
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() 
		{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/* function generates a (620 x 400) popup window displaying a given url */
function fPopUp(fUrl)
{
	window.open(fUrl,'fPopUp','width=620,height=400,resizable=1,scrollbars=yes,menubar=no,status=yes');
	return true;
}

/* shows or hides the given id */
function showhide(id)
{
  if (document.getElementById)
  {
  	var findopen = document.getElementById('findopen');
	var findclose = document.getElementById('findclose');
	obj = document.getElementById(id);
	if (obj.style.display == "none")
    {
      obj.style.display = "";
			findopen.style.display = "none";
			findclose.style.display = "";
    }
    else
    {
      obj.style.display = "none";
			findclose.style.display = "none";
			findopen.style.display = "";
    }
  }
}

/* returns a url parameter based on key (eg. index.php?foo=bar) */
function getURLParam(strParamName) {
	var strReturn = "";
  	var strHref = window.location.href;
  	if ( strHref.indexOf("?") > -1 ){
  		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
  		var aQueryString = strQueryString.split("&");
    	for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
    		if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
    	  		var aParam = aQueryString[iParam].split("=");
        		strReturn = aParam[1];
                break;
      	    }
    	}
    }
    return unescape(strReturn);
} 

/* returns base url of current environment */
function getBaseUrl() {
	
	var url = window.location.href;
	var environ = '';
	var baseUrl = '';
	
	if(url.indexOf("mit") > 0) {
		environ = "dev";
	} else if(url.indexOf("bne007dev")  > 0) {
		environ = "stage";
	} 
	
	switch (environ)
	{
		case "dev":
	         baseUrl = "webcentral.jon.mit";
	         break;
	    case "stage":
	    	 baseUrl = "svc007.bne007dev.server-web.com";
	         break;
	    default:
	    	 baseUrl = "www.webcentral.com.au";
	         break;           
	}
	
	return baseUrl;	
}

/* Adds commas to numbers. 1234567 becomes 1,234,567 */
function addCommas(nStr)
{
   nStr += '';
   x = nStr.split('.');
   x1 = x[0];
   x2 = x.length > 1 ? '.' + x[1] : '';
   var rgx = /(\d+)(\d{3})/;
   while (rgx.test(x1)) {
     x1 = x1.replace(rgx, '$1' + ',' + '$2');
   }
   return x1 + x2;
}
