//FIND AN OBJECT
function findObj(theObj, theDoc){ // a
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

// TRIM A STRING
function trim(a){
	return a.replace(/^\s+|\s+$/,'');	
}

// MENU, SHOW/HIDE SUBMENUS
function showsub(subname){ // b
	var namepieces = subname.split('_');
	if(namepieces[2] == 0) findObj(subname).className = 'subsubmenu firstsub';
	else	findObj(subname).className = 'subsubmenu';
}

function hidesub(subname){ // b
	findObj(subname).className = 'invisible';
}

// OPEN URL IN NEW WINDOW
function openWindow(url){
	var setting="toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,width=650, height=600, left=100, top=25";
	if (disclaimer()) window.open("http://"+url,"newwindow",setting);
}

// IS PROBABLY DEPRICATED
function FORM_SendTheForm(theform, errordiv, resultdiv){ 
	AjaxSend(theform, 'AjaxOutput2', errordiv, resultdiv);
}

// TOGGLE OBJECTS, MAKE ARG0 visible (classname ARG2 or ''), make all ARG1 invisible (classname ARG3 or 'invisible')
function toggle_objects(divon, divsoff){
	var classon = '';
	var classoff = 'invisible';
	if(toggle_objects.arguments.length > 2) classon = toggle_objects.arguments[2];
	if(toggle_objects.arguments.length > 3) classoff = toggle_objects.arguments[3];
	for(i=0; i<divsoff.length; i++){
		if(findObj(divsoff[i])) findObj(divsoff[i]).className = classoff;
	}
	if(divon != '' && findObj(divon)) findObj(divon).className = classon;	
}

// DYNAMICALLY ADD JS TO BODY.ONLOAD
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function debug(){
	var MSG = arguments[0];
	if(findObj('admin_debug')) findObj('admin_debug').innerHTML = MSG + '<hr />' + findObj('admin_debug').innerHTML;
}
