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('Sei sicuro di voler eliminare questo elemento?')
}

function targetBlank (url) {
  blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
	return false;
}

function sth_detectIE(ClassID) 
{ 
	sth_iecoresult = false; 
	document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n sth_iecoresult = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); 
	return sth_iecoresult;
}
function sth_detectNS(ClassID) 
{
	var result = false;
	if (navigator.mimeTypes[ClassID]+"" != "undefined" && 
		navigator.mimeTypes[ClassID].type.toLowerCase() == ClassID &&
		navigator.mimeTypes[ClassID].enabledPlugin != null)
		result = true;
	return result; 
}

function sth_Browser (){
 
  // convert all characters to lowercase to simplify testing
  var agt=navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);

  this.mac      = ((agt.indexOf('mac')!=-1) && (agt.indexOf('windows')==-1));
  this.windows      = ((agt.indexOf('win')!=-1) && (agt.indexOf('mac')==-1));

  this.ns      = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) &&
  					  (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) &&
                 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)); 
  this.ns2     = (this.ns && (this.major == 2));
  this.ns3     = (this.ns && (this.major == 3));
  this.ns4     = (this.ns && (this.major == 4));
  this.ns4up   = (this.ns && (this.major >= 4));
  this.nsonly  = (this.ns && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)));
  this.ns6     = (this.ns && (this.major == 5));
  this.ns6up   = (this.ns && (this.major >= 5));
  this.gecko   = (agt.indexOf('gecko') != -1);
 
  this.ie      = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
  this.ie3     = (this.ie && (this.major < 4));
  this.ie4     = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
  this.ie4up   = (this.ie  && (this.major >= 4));
  this.ie5     = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1));
  this.ie5_5   = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
  this.ie5up   = (this.ie  && !this.ie3 && !this.ie4);
  this.ie5_5up = (this.ie && !this.ie3 && !this.ie4 && !this.ie5);
  this.ie6     = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
  this.ie6up   = (this.ie  && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);
 
  // BUG: On AOL4, returns false if IE3 is embedded browser or if this is the first
  //      browser window opened.  Thus the variables is.aol, is.aol3, and is.aol4
  //      aren't 100% reliable.
  this.aol     = (agt.indexOf("aol") != -1);
  this.aol3    = (this.aol && this.ie3);
  this.aol4    = (this.aol && this.ie4);
  this.aol5    = (agt.indexOf("aol 5") != -1);
  this.aol6    = (agt.indexOf("aol 6") != -1);

  // NOTE: Opera and WebTV spoof Navigator.  We do strict client detection. If you
  //       want to allow spoofing, take out the tests for opera and webtv.
  this.opera   = (agt.indexOf("opera") != -1);
  this.opera2  = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
  this.opera3  = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
  this.opera4  = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
  this.opera5  = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
  this.opera5up= (this.opera && !this.opera2 && !this.opera3 && !this.opera4);
 
  this.webtv   = (agt.indexOf("webtv") != -1);

  this.aoltv   = ((agt.indexOf("navio") != -1) ||
                 (agt.indexOf("navio_aoltv") != -1));

  this.hotjava = (agt.indexOf("hotjava") != -1);
  this.hotjava3 = (this.hotjava && (this.major == 3));
  this.hotjava3up = (this.hotjava && (this.major >= 3));

	if (this.ie && this.windows) 
	{
		this.plugin_svg = sth_detectIE("Adobe.SVGCtl");
		this.plugin_swc = sth_detectIE("SWCtl.SWCtl.1");
		this.plugin_swf = sth_detectIE("ShockwaveFlash.ShockwaveFlash.1"); 
		this.plugin_rp = sth_detectIE("rmocx.RealPlayer G2 Control.1");
		this.plugin_qt = sth_detectIE("QuickTimeCheckObject.QuickTimeCheck.1");
		this.plugin_wmp = sth_detectIE("MediaPlayer.MediaPlayer.1");
		this.plugin_pdf = sth_detectIE("PDF.PdfCtrl.5");
	}
	if (this.ie || this.ns || !this.windows) 
	{
		this.plugin_svg = sth_detectNS("image/svg-xml");
		this.plugin_swc = sth_detectNS("application/x-director");
		this.plugin_swf = sth_detectNS("application/x-shockwave-flash"); 
		this.plugin_rp = sth_detectNS("audio/x-pn-realaudio-plugin");
		this.plugin_qt = sth_detectNS("video/quicktime");
		this.plugin_wmp = sth_detectNS("application/x-mplayer2");
		this.plugin_pdf = sth_detectNS("application/pdf");
	}
}

var sth_browser = new sth_Browser();

// 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.type && (oInput.type == 'radio' || oInput.type == 'checkbox')) {
      if (!oInput.checked) {
			if (strMessage!="")
				alert(strMessage);
			oInput.focus();
			return false;
      }
   }
	if (oInput.value==null || oInput.value=="") {
		if (strMessage!="")
			alert(strMessage);
		oInput.focus();
		return false;
	}
	else
		return true;
}

function sth_popUp(strUrl, strWidth, strHeight, dbg, strName)
{
	var strTop = (screen.height - strHeight) / 2;
	var strLeft = (screen.width - strWidth) / 2;
	MM_openBrWindow(strUrl,strName,'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_getProp(objName,theProp) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    return eval("obj."+theProp);
  }
}

function sth_displayNone()
{
 var a=sth_displayNone.arguments;
 for(var i=0;i<a.length;i++) {
 	sth_changeProp(a[i],'style.display','none');
 }
}
function sth_displayBlock()
{
 var a=sth_displayBlock.arguments;
 for(var i=0;i<a.length;i++) {
 	sth_changeProp(a[i],'style.display','block');
 }
}
function sth_isDisplayed(objName)
{
  var obj = MM_findObj(objName);
  if (obj) {
   if (obj.display) {
      if (obj.display == 'none')
      	return false;
      else
      	return true;
   }
   else if (obj.style) {
      if (obj.style.display == 'none')
      	return false;
      else
      	return true;
   }
 }
 return false;
}

function sth_switchDisplay(objVName, objCName, objCProp, objCPropVis, objCPropHid)
{
  if (sth_isDisplayed(objVName)) {
  	  sth_displayNone(objVName);
	  sth_changeProp(objCName,objCProp,objCPropHid);
  }
  else {
  	  sth_displayBlock(objVName);
	  sth_changeProp(objCName,objCProp,objCPropVis);
  }
}
function sth_setDisplay(visib, objVName, objCName, objCProp, objCPropVis, objCPropHid)
{
  if (visib) {
  	  sth_displayBlock(objVName);
	  sth_changeProp(objCName,objCProp,objCPropVis);
  }
  else {
  	  sth_displayNone(objVName);
	  sth_changeProp(objCName,objCProp,objCPropHid);
  }
}

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);
}
function sth_scroll(objName,iAmount)
{
	if (sth_browser.opera)
		sth_changeProp('content','style.overflow','scroll');
	var iPos = parseInt(sth_getProp(objName,'scrollTop'));
	if (iAmount != 0) {
		if (sth_browser.ie && sth_browser.mac) {
			sth_changeProp('content','style.position','absolute');
			sth_changeProp('content','style.overflow','visible');
		}
		sth_changeProp(objName,'scrollTop',iPos + iAmount);
		scrolltimer = setTimeout("sth_scroll('"+objName+"',"+iAmount+")", 10);
	} else {
		if (sth_browser.ie && sth_browser.mac) {
			sth_changeProp('content','style.position','absolute');
			sth_changeProp('content','style.overflow','hidden');
		}
		clearTimeout(scrolltimer);
	}
}

function sth_addEvent(obj, evType, fn){
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent('on'+evType, fn);
        return r;
    } else {
	    return false;
    }
}
