var IE = (document.all) ? 1 : 0;
var NS = (document.layers) ? 1 : 0;

// WINDOW STATUS FUNCTIONS
window.defaultStatus = "";
function winStatus( msg )
{
	window.status = msg;
}

// ALERT FUNCTIONS
function adminAlert( msg ) {
	if( msg != null && trim(msg) != "" ) {
		alert( msg );
	}
}

function addToWelcomePage( jvm, webApp, sectionName, URL, formItem ) {
	//alert(sectionName);
	top.adminHeader.location = "/properties/addToWelcomePage.jsp?" +
		"jrun_j=" + escape(jvm) +
		"&jrun_wa=" + escape(webApp) +
		"&sectionName=" + escape(sectionName) +
		"&checkOn=" + formItem.checked +		
		"&jmcLinkURL=" + escape(URL);
}

function goThere( node,loc ) {
	//Only perform folder opening, don't close anything
	if( parent.nav.indexOfEntries[node].isOpen == false )
		parent.nav.clickOnNode(node);
	window.location = loc;
}

function popUp( loc, winvar, w, h, menubar, resize, scroll ){
	if( w == null ) { w = 500; }
	if( h == null ) { h = 350; }
	if( menubar == null || menubar == false ) {
		menubar = "";
	} else {
		menubar = "menubar,";
	}
	if( resize == null || resize == false ) {
		resize = "resizable=no";
	} else {
		resize = "resizable,";
	}
	if( scroll == null || scroll == false ) {
		scroll = "scrollbars=no";
	} else {
		scroll = "scrollbars,";
	}	
	
	if( NS ) { w += 50; }
	// Need the var or else IE4 blows up not recognizing editorWin
	var editorWin = window.open(loc, winvar, menubar + 'resizable,scrollbars,width=' + w + ',height=' + h);
	//if( !newWin.opener )
		//newWin.opener = window;
	editorWin.focus(); //causing intermittent errors
}

function popUpLarge( loc, menubar ) {
	if( menubar == null ) { menubar = false; }
	popUp( loc, 700, 500, menubar );
}

function connectorWizardPrompt( jvm ) {
	// Go to the connector wizard if the user wants to run it for the first time
	if( confirm('You have not configured the connection between this server and an external Web server.\n\n Click OK to run the Connector Wizard.') ) {
		self.location = "/jvm/webserver/connectors/index.jsp?jrun_j=" + escape(jvm);
	}
}

function closeMe() {
	//self.close();
	parent.close();
}

function formSubmit() {
	parent.frames[0].document.forms[0].submit();
}

function openerReload() {
	if( parent.opener.name != null )
		parent.opener.location.reload();
		//alert( parent.opener.name );
		//parent.opener.r();
}

function r() {
	self.setTimeout("rl()", 2000);
}
function rl(){
	self.location.reload();
}

function browseWindow( ele, fileExtension ) {
	if( fileExtension == null ) { fileExtension = ""; }
	page = "/includes/dirReader.jsp?jrun_target_element=" + ele + "&jrun_file_ext=" + fileExtension;
	bWin = window.open(page,'browseWin','resizable,scrollbars,width=500,height=60,screenX=300,screenY=200');
	bWin.focus();
}

// STRING FUNCTIONS
function trim( 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;
}

// Execute Search Function
function doSearch(l){
	appname= navigator.appName;
	if (appname == "Netscape"){
		st = document.Search.SearchText.value;
	}else{
		st = document.all("ST").value;
	}
	loc=l+"&search="+st+"&st="+st;
	//alert(loc);
	if (appname == "Netscape"){
//		parent.ListFrame.location.href=loc;
		parent.location.href=loc;
	}else{
		parent.location=loc;
	}	
}

// Function SelectYear
function SelectYear(selObj,restore,lnk,typ){
	appname= navigator.appName;
	par = selObj.options[selObj.selectedIndex].value;
	loc=lnk+"&"+typ+"="+par;
	if (appname == "Netscape"){
//		parent.ListFrame.location.href=loc + "&search=" + document.Search.SearchText.value;
		parent.location.href=loc + "&st=" + document.Search.ST.value;		
		st = document.Search.ST.value;		
	}else{
//		parent.ListFrame.location=loc + "&search=" + document.all("ST").value;
//		parent.location=loc + "&st=" + document.all("ST").value;		
		parent.location=loc;				
	}	
}

// Function ResetSelect: Resets a SELECT TAG if dependance exist
function ResetSelect(selObj,restore,l,t,p,k,o,c,typ,kk){
	appname= navigator.appName;
	par = selObj.options[selObj.selectedIndex].value;
	if (typ=="GT"){t = par;}		
	if (typ=="GP"){p = par;}	
	if (typ=="GK"){k = par;}
	if (typ=="GO"){o = par;}
	if (typ=="GC"){c = par;}
	if (typ=="KK"){kk = par;}
	loc=l+"&th="+t+"&gp="+p+"&gk="+k+"&go="+o+"&gc="+c+"&kk="+kk;
	if (appname == "Netscape"){
		parent.location.href=loc;
	}else{
		parent.location=loc;
	}	
}

//Function ChangeLanguage
function ChangeLang(selObj,restore){
	 self.location='/system/app/chg_lng.cfm?L='+selObj.options[selObj.selectedIndex].value;
	  if (restore) selObj.selectedIndex=0;
}

//Execute Link from News
function ExecLink(lnk,typ,w,h,r,s){
	if( w == '' ) { w = 100; }
	if( h == '' ) { h = 100; }
	if( r == '' ) { r = 1; }
	if(typ=="doc"){GetDocument(lnk);}
	if(typ=="pop"){var popwin = window.open(lnk,'pop','toolbars=1, scrollbars='+s+', location=0, statusbars=0, menubars=1, resizable='+r+', width='+w+', height='+h+', left = 500, top = 100');}
	if(typ=="web"){window.open(lnk,'Link');}
	if(typ=="app"){
		loc=lnk;
		top.Right_frame.Info_Frame.location=loc;
	}
}

//Get Documnet
function GetDocument(docID){
	var docWin = window.open('/system/app/dm_download.cfm?D='+docID,'DocWin');
}

function ShowPath(men){
	loc="/system/app/showpath.cfm?M="+men;
	top.Right_frame.path_frame.location=loc;
}

// Select Line
//	obj:	item to handle
//	doc:	actual document
function SelectLine(obj,doc,stclass,rpclass) {
	appname= navigator.appName;
	if (appname == "Netscape"){
		to = document.layers(obj).id;
		alert(to);
		for(x=0; x<document.layers(obj).length; x++) {
			ao = document.layers(x).id;
			
			if (ao.substr(ao.length-1,1) == "s"){
				if(ao == to){
					if (document.layers(to).style.color == "white"){
						document.layers(to).style.color = "Black";
						document.layers(to).style.background = "white";
						top.actDocument = "";											
					}else{
						document.layers(to).style.color = "white";
						document.layers(to).style.background = "Navy";		
						top.actDocument = doc;			
					}
				}else{		
					document.layers(ao).style.background ="white";	
					document.layers(ao).style.color = "Black";			
				}				
			}	
		}	
	}else{
		to = document.all(obj).id;
		for(x=0; x<document.all.length; x++) {
			ao = document.all(x).id;
			if (ao.substr(ao.length-1,1) == "s"){
				if(ao == to){
					if (document.all(to).style.color == "white"){
						document.all(to).style.color = "Black";
						document.all(to).style.background = "white";
						top.actDocument = "";											
					}else{
						document.all(to).style.color = "white";
						document.all(to).style.background = "Navy";		
						top.actDocument = doc;			
					}
				}else{		
					document.all(ao).style.background ="white";	
					document.all(ao).style.color = "Black";			
				}				
			}	
		}
	}
}


// Select Line
//	obj:	item to handle
//	doc:	actual document
function SelectLine_old(obj,doc) {
	appname= navigator.appName;
	if (appname == "Netscape"){

		to = document.layers(obj).id;
		alert(to);
		for(x=0; x<document.layers(obj).length; x++) {
			ao = document.layers(x).id;
			
			if (ao.substr(ao.length-1,1) == "s"){
				if(ao == to){
					if (document.layers(to).style.color == "white"){
						document.layers(to).style.color = "Black";
						document.layers(to).style.background = "white";
						top.actDocument = "";											
					}else{
						document.layers(to).style.color = "white";
						document.layers(to).style.background = "Navy";		
						top.actDocument = doc;			
					}
				}else{		
					document.layers(ao).style.background ="white";	
					document.layers(ao).style.color = "Black";			
				}				
			}	
		}	
	}else{
		to = document.all(obj).id;
		for(x=0; x<document.all.length; x++) {
			ao = document.all(x).id;
			if (ao.substr(ao.length-1,1) == "s"){
				if(ao == to){
					if (document.all(to).style.color == "white"){
						document.all(to).style.color = "Black";
						document.all(to).style.background = "white";
						top.actDocument = "";											
					}else{
						document.all(to).style.color = "white";
						document.all(to).style.background = "Navy";		
						top.actDocument = doc;			
					}
				}else{		
					document.all(ao).style.background ="white";	
					document.all(ao).style.color = "Black";			
				}				
			}	
		}
	}
}

//	Show Document
//	doc:	document to show
function ShowDoc(doc){
	var docWin = window.open('/system/app/dm_download.cfm?doc='+doc,'DocWin');
}


