/**
 * @author Laura
 */

Ext.BLANK_IMAGE_URL = 'js/ext/images/default/s.gif';

Ext.getUrlParam = function(param) {
   // if debugging in Aptana //////////////////////////////////////////////
   var linenum = 10;
   	try
	  {
		   if (window.location.host == "127.0.0.1:8000") {
		   		return "000";
		   }
	  }
	catch(err)
	  {
		  txt="There was an error on this page.\n\n";
		  txt+= "getUrlParam(" + linenum + "): <br>" + err.description;
		  txt+="<br><br>Click OK to continue.<br>";
		  Ext.Msg.alert("Error",txt);
		  
	  }  
   //////////////////////////////////////////////////////////////////////////////
   
   var searchstr;
   try
	  {
	  searchstr = location.search.substring(1);
	  }
	catch(err)
	  {
	  return "";
	  }
   if(searchstr == "")return "";
   var params = Ext.urlDecode(searchstr);
   return param ? params[param] : params;
};


Ext.debugconsole = function(param,displaymode){
	var sid = Ext.getUrlParam('sid');
	var sid = "n/a";	
	if(displaymode == "msg"){
		Ext.Msg.alert("Debugging "+sid,param);	
	} else if(displaymode == "console" && window.location.host != "127.0.0.1:8000" && Ext.isGecko){ // if its not Aptana and is Firefox
		try
		  {
		  	console.log(param); // try to write to the Firebug console, if it fails, create an alert instead
		  }
		catch(err)
		  {
		  	// do nothing because Firebug is not running
		  	if(window.location.host.substring(0,6) == "debug."){
		  		Ext.Msg.alert("Debugging "+this.appStatus.sid,param);	
		  	}
		  }
	}
}
Ext.initstatus = function(msg,initstatus){
	Ext.get('loading-msg').dom.innerHTML = msg;
	if(initstatus == "stopped"){
		// hide the busy/working animated gif
		var el = Ext.get('loading_applabel')
		el.applyStyles('background-image: url(/images/extstopped.gif)');
	}
}

Ext.replaceall = function(divName,oldStr,newStr){
	// DISCLAIMER:  there is a size limitation to passing strings 4096???
	// WARNING: IE AND SAFARI CAN CONVERT MARKUP TO CAPITALS WHICH WILL NOT MATCH!!!!!!!
	//alert("utils.js (71): "+Ext.get(divName).dom.innerHTML);
	//alert("utils.js (72): "+oldStr);
	var divHTML = Ext.get(divName).dom.innerHTML;
	//alert("utils.js (74): "+divHTML);
	while ( divHTML.indexOf(oldStr) != -1)
	{
		//alert("utils.js (72): "+oldStr);
		divHTML = divHTML.replace(oldStr,newStr);
	}
	return divHTML;
}