function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ConfirmDelete()
{
	return confirm('Do you really want to delete this item?')
}

// usage: sth_swapImage('image_name','../graphics/new.src.gif'[,'image2_name','../graphics/new2.src.gif',...]);
// to restore: MM_swapImgRestore();
function sth_swapImage() { //v3.0
  var i,j=0,x,a=sth_swapImage.arguments;
  document.MM_sr=new Array;
  for(i=0;i<a.length;i+=2)
   if ((x=MM_findObj(a[i]))!=null){
      document.MM_sr[j++]=x;
      if(!x.oSrc)
         x.oSrc=x.src;
      x.src=a[i+1];
   }
}

// usage: inputIsValid(inputObjectToValidate, 'Message to show if field is empty');
function inputIsValid(oInput, strMessage) {
   if (!oInput)
      return true;
   if (oInput.length > -1) {
      if (oInput[0] && oInput[0].type 
         && (oInput[0].type == 'radio' || oInput[0].type == 'checkbox')) {
            var valid = false;
            for (var i = 0; i < oInput.length; i++) {
                if (oInput[i].checked)
                   valid = true;
            }
            if (!valid) {
               if (strMessage!="")
      			   alert(strMessage);
      		}
            return valid;
      }
      else if (oInput[0]  && oInput[0].type 
         && (oInput[0].type == 'text' || oInput[0].type == 'textarea')) {
            var valid = false;
            for (var i = 0; i < oInput.length; i++) {
                if (oInput[i].value != null && oInput[i].value != "")
                   valid = true;
            }
            if (!valid) {
               if (strMessage!="")
      			   alert(strMessage);
      		}
            return valid;
      }
   }
	if (oInput.value==null || oInput.value=="") {
		if (strMessage!="")
			alert(strMessage);
		oInput.focus();
		return false;
	}
	else
		return true;
}

function sth_popUp(strUrl, strWidth, strHeight, dbg)
{
	var strTop = (screen.height - strHeight) / 2;
	var strLeft = (screen.width - strWidth) / 2;
	MM_openBrWindow(strUrl,'','scrollbars,width='+strWidth+',height='+strHeight+',left='+strLeft+',top='+strTop+((dbg==1)?',status=yes':''));
}

function sth_changeProp(objName,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function sth_hide()
{
 var a=sth_hide.arguments;
 for(var i=0;i<a.length;i++) {
 	sth_changeProp(a[i],'style.visibility','hidden');
 }
}
function sth_show()
{
 var a=sth_show.arguments;
 for(var i=0;i<a.length;i++) {
 	sth_changeProp(a[i],'style.visibility','visible');
 }
}
function sth_isVisible(objName)
{
  var obj = MM_findObj(objName);
  if (obj) {
   if (obj.visibility) {
      if (obj.visibility == 'hidden')
      	return false;
      else
      	return true;
   }
   else if (obj.style) {
      if (obj.style.visibility == 'hidden')
      	return false;
      else
      	return true;
   }
 }
 return false;
}

function sth_switchVisibility(objVName, objCName, objCProp, objCPropVis, objCPropHid)
{
  if (sth_isVisible(objVName)) {
  	  sth_hide(objVName);
	  sth_changeProp(objCName,objCProp,objCPropHid);
  }
  else {
  	  sth_show(objVName);
	  sth_changeProp(objCName,objCProp,objCPropVis);
  }
}
function sth_setVisibility(visib, objVName, objCName, objCProp, objCPropVis, objCPropHid)
{
  if (visib) {
  	  sth_show(objVName);
	  sth_changeProp(objCName,objCProp,objCPropVis);
  }
  else {
  	  sth_hide(objVName);
	  sth_changeProp(objCName,objCProp,objCPropHid);
  }
}
function sth_initTabs()
{
 var a=sth_initTabs.arguments;
 if (!document.sth_tabs) document.sth_tabs=new Array;
 document.sth_tabs[a[0]] = new Array;
 for(var i=1;i<a.length;i++) {
   document.sth_tabs[a[0]][document.sth_tabs[a[0]].length] = a[i];
 }
}

function sth_selectTab(groupName,tabName)
{
 if (document.sth_tabs && document.sth_tabs[groupName])
 {
 	var g = document.sth_tabs[groupName];
 	for (var i=0;i<g.length;i++) {
 		 sth_setVisibility(false,g[i],groupName+'_'+g[i]+'_sw','style.backgroundImage','url(graphics/engine/admin.bgr.tab.o.gif)','url(graphics/engine/admin.bgr.tab.gif)');
	}
 	sth_setVisibility(true,tabName,groupName+'_'+tabName+'_sw','style.backgroundImage','url(graphics/engine/admin.bgr.tab.o.gif)','url(graphics/engine/admin.bgr.tab.gif)');
 }
}

function sth_addToSelect(selectName,value,text,doc)
{
  if (!doc) doc = window.document;
  var sel = MM_findObj(selectName,doc);
  if (sel && sel.options)
  {
	  oOpt = doc.createElement("OPTION");
	  oOpt.value = value;
	  oOpt.text = text;
	  if (navigator.appName == "Netscape" || navigator.appName == "Mozilla") sel.appendChild(oOpt);
	  else sel.options.add(oOpt);
  }
}

function sth_revoveFromSelect(selectName,value,doc)
{
  if (!doc) doc = window.document;
  var sel = MM_findObj(selectName,doc);
  if (sel && sel.options)
  {
  	  var item = -1;
  	  for (var i=0;i<sel.options.length;i++) {
  	  		if (sel.options[i].value == value)
  	  			item = i;
     }
     if (item > -1) {
		  if (navigator.appName == "Netscape" || navigator.appName == "Mozilla") sel.removeChild(sel.options[item]);
		  else sel.options.remove(item);
     }
  }
}

function sth_selectInParent(strId, strDesc) {
	if (sth_inputid && sth_inputid != "") {
		oIdField = MM_findObj(sth_inputid,window.opener.document);
		if (oIdField && oIdField.type)	{
			if (oIdField.options) {
				var found = false;
				for (var i=0;i<oIdField.options.length;i++) {
					if (oIdField.options[i].value == strId) {
						oIdField.options[i].selected = true;
						found = true; 
						break;
					}
				}
				if (!found) {
				   sth_addToSelect(sth_inputid,strId,strDesc,window.opener.document);
				}
			}
		 	oIdField.value = strId;
		}
		if (sth_inputtext && sth_inputtext != "") {
			oTextField = MM_findObj(sth_inputtext,window.opener.document);
			if (oTextField)	{
				oTextField.value = strDesc;
			}
		}
	}
	else {
		return;
 }
}
function sth_addFieldToForm (formName, fieldType, fieldName, fieldValue) {
 var form = MM_findObj(formName);
  if (form && document.getElementById) {
    var input = document.createElement('INPUT');
      if (document.all) { 
        input.type = fieldType;
        input.name = fieldName;
        input.value = fieldValue;
      }
      else if (document.getElementById) {
        input.setAttribute('type', fieldType);
        input.setAttribute('name', fieldName);
        input.setAttribute('value', fieldValue);
      }
    form.appendChild(input);
  }
}
function sth_getFormField (formName, fieldName) {
 var form = MM_findObj(formName);
 if (form) {
  if (!document.all)
    return form[fieldName];
  else
    for (var e = 0; e < form.elements.length; e++)
      if (form.elements[e].name == fieldName)
        return form.elements[e];
  return null;
  }
  return null;
}        
function sth_removeFieldFromForm (formName, fieldName) {
  var field = sth_getFormField(formName, fieldName);
  if (field && !field.length)
    field.parentNode.removeChild(field);
}
