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?')
}

// usage: js_swapImage('image_name','../graphics/new.src.gif'[,'image2_name','../graphics/new2.src.gif',...]);
// to restore: MM_swapImgRestore();
function js_swapImage() { //v3.0
  var i,j=0,x,a=js_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 js_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 js_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 js_hide()
{
 var a=js_hide.arguments;
 for(var i=0;i<a.length;i++) {
 	js_changeProp(a[i],'style.visibility','hidden');
 }
}
function js_show()
{
 var a=js_show.arguments;
 for(var i=0;i<a.length;i++) {
 	js_changeProp(a[i],'style.visibility','visible');
 }
}
function js_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 js_switchVisibility(objVName, objCName, objCProp, objCPropVis, objCPropHid)
{
  if (js_isVisible(objVName)) {
  	  js_hide(objVName);
	  js_changeProp(objCName,objCProp,objCPropHid);
  }
  else {
  	  js_show(objVName);
	  js_changeProp(objCName,objCProp,objCPropVis);
  }
}
function js_setVisibility(visib, objVName, objCName, objCProp, objCPropVis, objCPropHid)
{
  if (visib) {
  	  js_show(objVName);
	  js_changeProp(objCName,objCProp,objCPropVis);
  }
  else {
  	  js_hide(objVName);
	  js_changeProp(objCName,objCProp,objCPropHid);
  }
}
function js_initTabs()
{
 var a=js_initTabs.arguments;
 if (!document.js_tabs) document.js_tabs=new Array;
 document.js_tabs[a[0]] = new Array;
 for(var i=1;i<a.length;i++) {
   document.js_tabs[a[0]][document.js_tabs[a[0]].length] = a[i];
 }
}

function js_selectTab(groupName,tabName)
{
 if (document.js_tabs && document.js_tabs[groupName])
 {
 	var g = document.js_tabs[groupName];
 	for (var i=0;i<g.length;i++) {
 		 js_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)');
	}
 	js_setVisibility(true,tabName,groupName+'_'+tabName+'_sw','style.backgroundImage','url(graphics/engine/admin.bgr.tab.o.gif)','url(graphics/engine/admin.bgr.tab.gif)');
 }
}

function js_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 js_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 js_selectInParent(strId, strDesc) {
	if (js_inputid && js_inputid != "") {
		oIdField = MM_findObj(js_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) {
				   js_addToSelect(js_inputid,strId,strDesc,window.opener.document);
				}
			}
		 	oIdField.value = strId;
		}
		if (js_inputtext && js_inputtext != "") {
			oTextField = MM_findObj(js_inputtext,window.opener.document);
			if (oTextField)	{
				oTextField.value = strDesc;
			}
		}
	}
	else {
		return;
 }
}
function js_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 js_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 js_removeFieldFromForm (formName, fieldName) {
  var field = js_getFormField(formName, fieldName);
  if (field && !field.length)
    field.parentNode.removeChild(field);
}
function numedit(){
	var str = '';
	var aCheck = document.edit.numbers;
	for (i=0; i<aCheck.length;i++){
		if (aCheck[i].checked) str += ' '+aCheck[i].value;
	}
	js_selectInParent(str,str);
}
function isEmpty(oField, strMessage) {
	with (oField) {
		if (value==null || value=="") {
			if (strMessage!="")
				alert(strMessage);
			oField.focus();
			return true;
		} else
			return false;
	}
}
function validaFormvoto() {
	with(document.votaristorante) {
		
		if (isEmpty(nomerist,"Inserire il nome del ristorante")) return false;
		if (isEmpty(indirizzo,"Inserire l'indirizzo del ristorante")) return false;
		if (isEmpty(citta,"Inserire la citta del ristorante")) return false;
		if (isEmpty(provincia,"Inserire la proivincia del ristorante")) return false;
		if (isEmpty(tipologia,"Inserire una tipologia di ristorante")) return false;
		if (isEmpty(cibo,"Inserire un voto per il cibo")) return false;
		if (isEmpty(ambiente,"Inserire un voto per l'ambiente")) return false;
		if (isEmpty(servizio,"Inserire un voto per il servizio")) return false;
		if (isEmpty(prezzo,"Inserire un prezzo")) return false;
		return true;
	}
}
function validaFormarretrati() {
	with(document.frmarretrati) {
		
		if (isEmpty(nome,"Inserire il nome")) return false;
		if (isEmpty(cognome,"Inserire il cognome")) return false;
		if (isEmpty(indirizzo,"Inserire l'indirizzo ")) return false;
		if (isEmpty(citta,"Inserire la citta")) return false;
		if (isEmpty(cap,"Inserire il CAP")) return false;
		if (isEmpty(arretrati,"Selezionare almeno un numero arretrato")) return false;
		return true;
	}
}

function validaFormprodotti() {
	with(document.frmprodotti) {
		
		if (isEmpty(nome,"Inserire il nome")) return false;
		if (isEmpty(cognome,"Inserire il cognome")) return false;
		if (isEmpty(indirizzo,"Inserire l'indirizzo ")) return false;
		if (isEmpty(citta,"Inserire la citta")) return false;
		if (isEmpty(cap,"Inserire il CAP")) return false;
		return true;
	}
}

function validaFormraccoglitore() {
	with(document.frmraccoglitore) {
		
		if (isEmpty(nome,"Inserire il nome")) return false;
		if (isEmpty(cognome,"Inserire il cognome")) return false;
		if (isEmpty(indirizzo,"Inserire l'indirizzo ")) return false;
		if (isEmpty(citta,"Inserire la citta")) return false;
		if (isEmpty(cap,"Inserire il CAP")) return false;
		return true;
	}
}

function validaFormcollezioni() {
	with(document.frmcollezioni) {
		
		if (isEmpty(nome,"Inserire il nome")) return false;
		if (isEmpty(cognome,"Inserire il cognome")) return false;
		if (isEmpty(indirizzo,"Inserire l'indirizzo ")) return false;
		if (isEmpty(citta,"Inserire la citta")) return false;
		if (isEmpty(cap,"Inserire il CAP")) return false;
		if ((c03.checked==false) && (c04.checked==false)) {
			alert('Selezionare almeno una collezione');
			return false;
		}
		return true;
	}
}

function validaFormnewsletter() {
	with(document.frmnewsletter) {
		
		if (isEmpty(nome,"Inserire il nome")) return false;
		if (isEmpty(cognome,"Inserire il cognome")) return false;
		if (isEmpty(indirizzo,"Inserire l'indirizzo ")) return false;
		if (isEmpty(citta,"Inserire la citta")) return false;
		if (isEmpty(cap,"Inserire il CAP")) return false;
		if (isEmpty(provincia,"Inserire la privincia")) return false;
		if (isEmpty(nazione,"Inserire la nazione")) return false;
		if (isEmpty(email,"Inserire l'indirizzo e-mail")) return false;
		
		return true;
	}
}

function validaFormiscrizioneedicole() {
	with(document.frmiscrizioneedicole) {

		if (isEmpty(nome,"Inserire la ragione sociale")) return false;
		if (isEmpty(cognome,"Inserire il codice edicola")) return false;
		if (isEmpty(indirizzo,"Scegliere il distributore ")) return false;
		if (isEmpty(nome,"Inserire il nome")) return false;
		if (isEmpty(cognome,"Inserire il cognome")) return false;
		if (isEmpty(indirizzo,"Inserire l'indirizzo ")) return false;
		if (isEmpty(citta,"Inserire la citta")) return false;
		if (isEmpty(cap,"Inserire il CAP")) return false;
		if (isEmpty(provincia,"Inserire la privincia")) return false;
		if (isEmpty(nazione,"Inserire la nazione")) return false;
		if (isEmpty(email,"Inserire l'indirizzo e-mail")) return false;
		
		return true;
	}
}

function validaFormiscrizioneforum() {
	with(document.frmiscrizioneforum) {
	
		if (isEmpty(nome,"Inserire il nome")) return false;
		if (isEmpty(cognome,"Inserire il cognome")) return false;
		if (isEmpty(indirizzo,"Inserire l'indirizzo ")) return false;
		if (isEmpty(citta,"Inserire la citta")) return false;
		if (isEmpty(cap,"Inserire il CAP")) return false;
		if (isEmpty(provincia,"Inserire la privincia")) return false;
		if (isEmpty(nazione,"Inserire la nazione")) return false;
		if (isEmpty(email,"Inserire l'indirizzo e-mail")) return false;
		
		return true;
	}
}