
//////////////// BROWSER DETECTION //////////////
var IE = (document.all) ? 1 : 0;
var NS = (document.layers) ? 1 : 0;

//////////////// WINDOW STATUS //////////////
window.defaultStatus = "";
function setWinStatus( msg )
{
	window.status = msg;
}

/////////////// JS ERROR CATCH ///////////
var debugJS = false;
function stopJSError() {
	if(!debugJS){
  		return true;
	}
}
window.onerror = stopJSError;


//////////////// ALERT ////////////////
function fsAlert( msg ) {
	if( msg != null && trim(msg) != "" ) {
		alert( msg );
	}
}

//////////////// WINDOW POPUP ////////////////
function popUp( loc, w, h, menubar, locationbar ) {
	if( w == null ) { w = 500; }
	if( h == null ) { h = 350; }
	if( menubar == null || menubar == false ) {
		menubar = "";
	} else {
		menubar = "menubar,";
	}
	if( locationbar == null || locationbar == false ) { 
		locationbar = "location=0,"; 
	} else {
		locationbar = "location=1,";
	}

	if( NS ) { w += 50; }
	// Need the var or else IE4 blows up not recognizing editorWin
	var editorWin = window.open(loc,'editorWin', menubar + locationbar + 'resizable,scrollbars,width=' + w + ',height=' + h);
	editorWin.focus();
}

function popUpLarge( loc, menubar ) {
	if( menubar == null ) { 
		menubar = false;
	}
	popUp( loc, 700, 500, menubar );
}


function closeMe() {
	//self.close();
	parent.close();
}


//////////////// FORM AND RELOAD ////////////////
function formSubmit() {
	parent.frames[0].document.forms[0].submit();
}

function openerReload() {
	if( parent.opener.name != null ) {
		parent.opener.location.reload();
	}
}

function delayReload() {
	self.setTimeout("selfReload()", 2000);
}
function selfReload(){
	self.location.reload();
}


//////////////// STRINGS ////////////////
function fsTrim( str ) {
	// Immediately return if no trimming is needed
	if( (str.charAt(0) != ' ') && (str.charAt(str.length-1) != ' ') ) { return str; }
	// Trim leading spaces
	while( str.charAt(0)  == ' ' ) {
		str = '' + str.substring(1,str.length);
	}
	// Trim trailing spaces
	while( str.charAt(str.length-1)  == ' ' ) {
		str = '' + str.substring(0,str.length-1);
	}

	return str;
}

function strReplace( entry, bad, good ) {
	temp = "" + entry; // temporary holder
	while( temp.indexOf(bad) > -1 ) {
		pos= temp.indexOf( bad );
		temp = "" + ( temp.substring(0, pos) + good + 
			temp.substring( (pos + bad.length), temp.length) );
	}
	return temp;
}

  