function popup(name, title, URL, w, h){
	if (!w){
	  w = 500;
	}
  if (!h){
	  h = 600;
	}

	if (document.all){
  	var x = window.screenLeft;
    var y = window.screenTop;
    var wi = window.document.body.offsetWidth;
    var hi = window.document.body.offsetHeight;
  }else{
		var x = window.screenX;
		var y = window.screenY;
		var wi = window.outerWidth;
		var hi = window.outerHeight;
	}
  var cntx = x + Math.round((wi - w) / 2);
  var cnty = y + Math.round((hi - h) / 2);

	name = window.open(URL, title, "screenX="+ cntx + ", screenY=" + cnty + ",resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=0,width=" + w + ",height=" + h);
	name.location = URL;
}

function ValVer( e, chi){
	
	if(e.which){
		var iCode =  e.which;
	}else{ //IE
		var iCode = e.keyCode;
	}
	
	if((iCode >= 48 && iCode <= 57 )){ //numeri da 0 a 9
		if(chi.name == "ver1"){
			var ver = document.getElementById("ver2");
			ver.focus();
		}else if(chi.name == "ver2"){
			var ver = document.getElementById("ver3");
			ver.focus();			
		}
		return true;
	}
	
	if(iCode == 9){ //tab
		return true;
	}
	
	if(iCode == 8 || iCode == 46){ //8 = Backspace, 46 = Canc
		if(e.charCode == 46){//ho premuto il punto
			return false
		}
		return true;
	}
	
	if(iCode == 37 || iCode == 39){ //37 = <-, 39 = ->
		return true;
	}

	return false;
}

function IsDigit( e ){
	
	if(e.which){
		var iCode =  e.which;
	}else{ //IE
		var iCode = e.keyCode;
	}
	

	if((iCode >= 48 && iCode <= 57 ) || iCode == 8 || iCode == 44){
		return true;
	}else{
		return false;
	}
	
	/*
	( iCode >= 48 && iCode <= 57 )		// Numbers
	iCode == 8		// Backspace
	iCode == 44		// virgola
	iCode == 46		// punto
	*/
}

function persona(p){
  //Abilita/disabilita il nome, ecc. in base al tipo di persona scelto
  if (p == 0){ //persona giuridica
	  document.form1.nome.setAttribute('disabled', true);
	  document.form1.nome.style.background = "#F2F2F2";
	  document.form1.nome.value = "";
	  document.form1.cognome.setAttribute('disabled', true);
	  document.form1.cognome.style.background = "#F2F2F2";
	  document.form1.cognome.value = "";
	  document.form1.cod_fisc.setAttribute('disabled', true);
	  document.form1.cod_fisc.style.background = "#F2F2F2";
	  document.form1.cod_fisc.value = "";
	  
	  document.form1.rag_sociale.removeAttribute('disabled');
	  document.form1.rag_sociale.style.background = "#F7D2B3";
	  document.form1.part_iva.removeAttribute('disabled');
	  document.form1.part_iva.style.background = "#F7D2B3";
	  document.form1.cod_fiscA.removeAttribute('disabled');
	  document.form1.cod_fiscA.style.background = "#F7D2B3";
	}else if (p == 1){ //persona fisica
	  document.form1.nome.removeAttribute('disabled');
	  document.form1.nome.style.background = "#F7D2B3";
	  document.form1.cognome.removeAttribute('disabled');
	  document.form1.cognome.style.background = "#F7D2B3";
	  document.form1.cod_fisc.removeAttribute('disabled');
	  document.form1.cod_fisc.style.background = "#F7D2B3";
	  
	  document.form1.rag_sociale.setAttribute('disabled', true);
	  document.form1.rag_sociale.style.background = "#F2F2F2";
	  document.form1.rag_sociale.value = "";
	  document.form1.part_iva.setAttribute('disabled', true);
	  document.form1.part_iva.style.background = "#F2F2F2";
	  document.form1.part_iva.value = "";
	  document.form1.cod_fiscA.setAttribute('disabled', true);
	  document.form1.cod_fiscA.style.background = "#F2F2F2";
	  document.form1.cod_fiscA.value = "";
	}else{
	  exit;
	}
}

function aggiungiEmail(){
  sel = document.getElementById('emails');
	elemento = new Option( document.form1.email.value, document.form1.email.value, false, false );
	
	sel.options[sel.length] = elemento;
	document.form1.email.value = "";
}

function cancellaEmail(){
  sel = document.getElementById('emails');
	var cancella = 0;
	
	for( c = 0; c < sel.length; c++ ){
		if(sel.options[c].selected == true){
			cancella++;
		}
		
		if( cancella > 0 ){
			for(c = 0; c < sel.length; c++){
				if(sel.options[c].selected == true){
					sel.options[c] = null;
				}
			}
		cancellaEmail();
		}
	}
}

function seleziona(){
  sel = document.getElementById('emails');
  
	for( c = 0; c < sel.length; c++ ){
		sel.options[c].selected = true
	}			
}

function nomeUtente(form){
  Rag_sociale = form.rag_sociale.value;
  Nome        = form.nome.value;
  Cognome     = form.cognome.value;
  
  if ((Nome == "" || Cognome == "") && (Rag_sociale == "")){
		alert("ATTENZIONE! Inserire o il nome o la ragione sogiale.");
	  invia = false;
	}else{
	  invia = true;
	}
}

function insClasse(id_tipo){
	//svuota la select utente finale
	sel = document.getElementById("classe");
	for(c = (sel.length - 1); c >= 0; c -= 1){
		sel.options[c] = null;
	}
	
	//popolo la select utente finale con i valori appropriati
	for(c = 0; c < utente_classe[id_tipo].length; c += 1){
		elemento = new Option( utente_classe[id_tipo][c][1], utente_classe[id_tipo][c][0], false, false );
		sel.options[sel.length] = elemento;
	}
}

function annullaClick(clic){
	if(clic.button==2) {
		return false;
	}
	return true;
}

function inputBg(chi, cosa, classe){
	if(cosa == "f"){
		chi.className+=' ' + classe;
	}else{
		chi.className = chi.className.replace(' '+classe, '')
	}
}

function getEl(id){
    element = document.getElementById(id);

    return element;
}

function hideEl(id){
    var element = getEl(id);

    element.style.display = 'none';
}

function showEl(id){
    var element = getEl(id);

    element.style.display = '';
}

function ShowHide(nome){

	if(nome == 0){
		getEl("div"+nome).className = getEl("div"+nome).className.replace(" jwts_tabbertabhide", "");
		
		if(getEl("div1").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div1").className += " jwts_tabbertabhide";
		}

		if(getEl("div2").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div2").className += " jwts_tabbertabhide";
		}
		
		if(getEl("div3").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div3").className += " jwts_tabbertabhide";
		}
		
		getEl("li"+nome).className += " jwts_tabberactive";
		getEl("li1").className = getEl("li2").className.replace("jwts_tabberactive", "");
		getEl("li2").className = getEl("li2").className.replace("jwts_tabberactive", "");
		getEl("li3").className = getEl("li3").className.replace("jwts_tabberactive", "");
		
	}else	if(nome == 1){
		
		if(getEl("div0").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div0").className += " jwts_tabbertabhide";
		}

		getEl("div"+nome).className = getEl("div"+nome).className.replace(" jwts_tabbertabhide", "");
		
		if(getEl("div2").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div2").className += " jwts_tabbertabhide";
		}
		
		if(getEl("div3").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div3").className += " jwts_tabbertabhide";
		}
		
		getEl("li0").className = getEl("li2").className.replace("jwts_tabberactive", "");
		getEl("li"+nome).className += " jwts_tabberactive";
		getEl("li2").className = getEl("li2").className.replace("jwts_tabberactive", "");
		getEl("li3").className = getEl("li3").className.replace("jwts_tabberactive", "");
		
	}else if(nome == 2){
		
		if(getEl("div0").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div0").className += " jwts_tabbertabhide";
		}

		if(getEl("div1").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div1").className += " jwts_tabbertabhide";
		}
		
		getEl("div"+nome).className = getEl("div"+nome).className.replace(" jwts_tabbertabhide", "");
		
		if(getEl("div3").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div3").className += " jwts_tabbertabhide";
		}
		
		getEl("li0").className = getEl("li2").className.replace("jwts_tabberactive", "");
		getEl("li1").className = getEl("li1").className.replace("jwts_tabberactive", "");
		getEl("li"+nome).className += " jwts_tabberactive";
		getEl("li3").className = getEl("li3").className.replace("jwts_tabberactive", "");
		
	}else if(nome == 3){
		
		if(getEl("div0").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div0").className += " jwts_tabbertabhide";
		}

		if(getEl("div1").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div1").className += " jwts_tabbertabhide";
		}
		
		if(getEl("div2").className.search(/jwts_tabbertabhide/) == -1){
			getEl("div2").className += " jwts_tabbertabhide";
		}
		
		getEl("div"+nome).className = getEl("div"+nome).className.replace(" jwts_tabbertabhide", "");
		
		getEl("li0").className = getEl("li2").className.replace("jwts_tabberactive", "");
		getEl("li1").className = getEl("li1").className.replace("jwts_tabberactive", "");
		getEl("li2").className = getEl("li2").className.replace("jwts_tabberactive", "");
		getEl("li"+nome).className += " jwts_tabberactive";
		
	}
}

function chiudi(){
	document.getElementById('flottante').style.display = 'none';
}

