if (document.getElementById)
	w3c = true;
else 
	w3c = false;
if (document.all) 
	ie4 = true;
else
	ie4 = false;
	
function semaphore(campo) {
	campo.value = "si";
}

function seleziona(nome) {
	var elemento;
	if (w3c) {elemento = document.getElementById(nome);}
	else {if (ie4) {elemento = document.all(nome); }
	else {alert('Questo browser non supporta l\'operazione richiesta'); elemento=false;}}
	return elemento;
}
function vuota(elemento) {
         var indice; var ultimo; var lunghezza;
         while (lunghezza = elemento.childNodes.length) {
		indice = lunghezza - 1;
		ultimo = elemento.childNodes[indice];
		elemento.removeChild(ultimo);
	 }
}
function switchStrum(show, hide) {
         var mostra = seleziona(show);
         var nascondi = seleziona(hide);
         if (! mostra || ! nascondi) {alert('Si è verificato un errore'); return;}
         nascondi.style.display='none';
         mostra.style.display='block';
}
function chiudiMsg() {
         var div = seleziona('msgDiv');
         div.style.visibility='hidden';
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var element = seleziona(id);
    var object = element.style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function showElement(name) {
   var el = seleziona(name);
   el.style.display = 'block';
}
function hideElement(name) {
   var el = seleziona(name);
   el.style.display = 'none';
}
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}
function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}
