/**
 * Funzioni standard di Dreamweaver per la gestione dei livelli
 */
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
/** Fine **/

/**
 * Conteggio caratteri rimanenti per testo messaggio (SMS/MMS)
 */
function resChars(control, length){
	var text = control.value;
	var len = text.length;
	var cl;
	var num = 0;
	
	for(i=0; i<text.length; i++){
		if(text.charAt(i) == "€" || text.charAt(i) == "[" || text.charAt(i) == "]" ||
		   text.charAt(i) == "{" || text.charAt(i) == "}" || text.charAt(i) == "^" ||
		   text.charAt(i) == "|" || text.charAt(i) == "~" || text.charAt(i) == "\\")
			num++;
	}
	
	len += num;
	
	if (len >= length) {
		control.value = control.value.substring(0, length-num);
		cl = 0;
	}else {
		cl = length - len;
	}
	document.frmVola.chars.value = cl;
}

/**
 * Inserisce nuovo numero
 */
function insNumber(){
	var num = document.frmVola.num.value;
	
	if(num == ""){
		alert("Specificare il numero di cellulare da inserire");
		return false;
	}
	
	var country = document.frmVola.country.value;
	var dest = "+("+country+")"+num;
	
	var values = document.frmVola.hdestinatari.value;
	var ins = "";
	
	if(values == ""){
		ins = dest;
	}else{ 
		ins = values + "," + dest;
	}	
	
	document.frmVola.hdestinatari.value = ins;
	document.frmVola.num.value = "";
	document.frmVola.country.value = "39";
	aggiorna();
}

/**
 * Elimina il destinatario selezionato dalla select dei destinatari
 */
function delNumber(){
	//--- determina il numero da eliminare
	var pos = document.frmVola.hdestsel.value;
	//----
	if(pos == -1){
		alert(unescape("ATTENZIONE!!!\nSeleziona il Numero che Vuoi Eliminare"));
	}
	//----
	var values = document.frmVola.hdestinatari.value;
	var numbers = values.split(",");
	var ins = "";

	for (i=0; i<numbers.length; i++){
		if(pos==i){
			//alert("numero da eliminare "+numeris[i]);
		}else{
			if(ins == ""){
				ins = numbers[i];
			}else{
				ins = ins + "," + numbers[i];
			}
		}
	}

	document.frmVola.hdestinatari.value = ins;
	document.frmVola.hdestsel.value = -1;
	aggiorna();
} 

/**
 * Ricarica la select dei destinatari
 */
function aggiorna(){
	var values = document.frmVola.hdestinatari.value;
	var numbers = values.split(",");
	
	if(values == ""){
		document.frmVola.destinatari.options[0] = null;
		document.frmVola.destinatari.options[0] = new Option("                         ", "");
		return;
	}
	
	with(document.frmVola.destinatari){
		while (document.frmVola.destinatari.options.length > 0)
			document.frmVola.destinatari.options[0] = null;
		for (i=0; i<numbers.length; i++)
			document.frmVola.destinatari.options[i] = new Option(numbers[i],numbers[i])
		document.frmVola.destinatari.options.selectedIndex = -1;
	}
}

/**
 * Ricarica la select dei gruppi
 */
function aggiornagruppi(){
	var valoregru = document.frmVola.hdestigruppi.value;
	valoregru = valoregru.replace(/\\"/gi, "\""); 
	valoregru = valoregru.replace(/\\'/gi, "'"); 
	var gruppis = valoregru.split(",");

	if(valoregru == ""){
		document.frmVola.destigru.options[0] = null;
		document.frmVola.destigru.options[0] = new Option("                         ", "");
		return;
	}

	with (document.frmVola.destigru){
		while (document.frmVola.destigru.options.length > 0)
			document.frmVola.destigru.options[0]=null;
		for (i=0;i<gruppis.length;i++){
			var lab = gruppis[i].split("##");   
			document.frmVola.destigru.options[i] = new Option(lab[0],lab[1])
			document.frmVola.destigru.options.selectedIndex = -1;
		}
	}
}

/**
 * Inserisce un gruppo per l'invio da VolaWEB
 */
function insGruppo(){
	pos = document.frmGruppi.gruppi.selectedIndex;
	
	if (pos>-1) {
		var valsel = document.frmGruppi.gruppi.options[pos].value;
		var labsel = valsel.split(",");
		var labgru = labsel[0];
		var idgru = labsel[1];
		var nrute = labsel[2];
				
		Hattu = window.opener.document.frmVola.Hdestigruppi.value;
		if(nrute<=0){
			alert(unescape("ATTENZIONE!!!\nQuesto Gruppo Non Ha\nNessun Contatto, Quindi\nNon puoi Selezionarlo!"));
		}else{
			//---------
			var newgruppo=labgru+"##"+idgru;
			if(Hattu==""){
				Hattu=newgruppo;
				window.opener.document.form1.Hdestigruppi.value=Hattu;
				self.close();
			}else{
				var gruppis=Hattu.split(",");
				//--- controlla ora che la stringa del gruppo non sia già presente
				var esiste=0;
				for (i=0;i<gruppis.length;i++){
					if(newgruppo==gruppis[i]){
						esiste=1;
						alert(unescape("ATTENZIONE!!!\nNon puoi selezionare due volte\nlo stesso gruppo.\n"));
					}
				}
				if(esiste==0){
					Hattu=Hattu+","+newgruppo;
					window.opener.document.form1.Hdestigruppi.value=Hattu;
					self.close();
				}
			}
			//------ aggiorna il contenuto visivo nella pag principale
			//------
		}
	}else{
		alert(unescape("ATTENZIONE!!!\nDevi Selezionare un Gruppo\nFra quelli presenti."));
	}
}

function importaDestinatariFile(){
	var trovati = document.frmImport.Htrovati.value;
	var destimpostati = window.opener.document.frmVola.hdestinatari.value;

	if(trovati <= 0){
		alert(unescape("Attenzione!!!\nNON è stato trovato Nessun Numero Valido"));
	}else{ 
		if (destimpostati == ""){
			window.opener.document.frmVola.hdestinatari.value = document.frmImport.Hnumeri.value;
		}else{
			window.opener.document.frmVola.hdestinatari.value = destimpostati + "," + document.frmImport.Hnumeri.value;
		}
		window.close();
	}
}

function importaDestinatariGruppo() {
	pos = document.frmGruppi.gruppi.selectedIndex;
	
	if (pos > -1){
		var valsel = document.frmGruppi.gruppi.options[pos].value;
		var labsel = valsel.split(",");
		var labgru = labsel[0];
		var idgru = labsel[1];
		var nrute = labsel[2];
		Hattu = window.opener.document.frmVola.hdestigruppi.value;

		
		if(nrute <= 0){
			alert(unescape("ATTENZIONE!!!\nQuesto Gruppo Non Ha\nNessun Contatto, Quindi\nNon puoi Selezionarlo!"));
		}else{
			var newgruppo = labgru + "##" + idgru;
			if(Hattu == ""){
				Hattu = newgruppo;
				window.opener.document.frmVola.hdestigruppi.value = Hattu;
				self.close();
			}else{
				var gruppis = Hattu.split(",");
				var esiste=0;
				for(i=0; i<gruppis.length; i++){
					if(newgruppo == gruppis[i]){
						esiste = 1;
						alert(unescape("ATTENZIONE!!!\nNon puoi selezionare due volte\nlo stesso gruppo.\n"));
					}
				}
				if(esiste == 0){
					Hattu = Hattu + "," + newgruppo;
					window.opener.document.frmVola.hdestigruppi.value = Hattu;
					self.close();
				}
			}
		}
	}else{
		alert(unescape("ATTENZIONE!!!\nDevi Selezionare un Gruppo\nFra quelli presenti."));
	}
}

function aggiornatutti(){
	//-- aggiorna sia i destinatari singoli che i gruppi
   aggiornagruppi();
   aggiorna();
}

function delGruppo(){
	var pos = document.frmVola.hgrpsel.value;
	
	if(pos == -1){
		alert(unescape("ATTENZIONE!!!\nSeleziona il Gruppo che Vuoi Eliminare"));
	}

	var valoresin = document.frmVola.hdestigruppi.value;
	var gruppos = valoresin.split(",");
	var newvalore = "";
	
	for (i=0; i<gruppos.length; i++){
		if(pos == i){
			//alert("gruppo da eliminare "+gruppos[i]);
		}else{
			if(newvalore == ""){
				newvalore = gruppos[i];
			}else{
				newvalore = newvalore + "," + gruppos[i];
			}
		}
	}

	document.frmVola.hdestigruppi.value = newvalore;
	document.frmVola.hgrpsel.value = -1;
	aggiornagruppi();
}

/*function nuovoGruppo(){
	document.frmMngGruppo.btnGruppo.value = "Crea";
	document.frmMngGruppo.action.value = 'new';
	
	MM_showHideLayers('mngGruppo','','show')
}*/

function nuovoMittente(){
    var sender_sel = document.frmSenders.mittente.value;
    var espressione = new RegExp("^(899|892|12|166|144)");
	var espressione2 = new RegExp("^([a-zA-Z0-9-_\.\+\*: ])+$");
	

    if (sender_sel == "") {
	  alert(unescape("ATTENZIONE!!!\nInserire il Mittente che vuoi Aggiungere"));
	   return false;
	}

    if (espressione.test(sender_sel)) {
	  alert(unescape("ATTENZIONE!!!\nNon e' possibile inserire mittenti che iniziano con 899, 892, 12, 166, 144"));
	  return false;
	}
	
	if (!espressione2.test(sender_sel)) {
	  alert(unescape("ATTENZIONE!!!\nIl mittente inserito contiene dei caratteri non validi."));
	  return false;
	}
	
	
	document.frmSenders.action.value = "new";	
	document.frmSenders.submit();
}

function eliminaMittente(){
	var sender_sel = document.frmSenders.senders.value;
	
	if(sender_sel == ""){
		alert(unescape("ATTENZIONE!!!\nSeleziona il Mittente che Vuoi eliminare"));
		return false;
	}
	
	document.frmSenders.action.value = "del";
	document.frmSenders.submit();
}

function mittentePredefinito(){
	var sender_sel = document.frmSenders.senders.value;
	
	if(sender_sel == ""){
		alert(unescape("ATTENZIONE!!!\nSeleziona il Mittente che Vuoi far diventare Predefinito"));
		return false;
	}
	
	document.frmSenders.action.value = "set_pred";
	document.frmSenders.submit();
}

function annullaAutenticazione(){
	document.frmSenders.action.value = "";
	document.frmSenders.submit();
}

function confermaPincode(){
    var pincode = document.frmSenders.pincode.value;
	
	if(pincode == ""){
		alert(unescape("ATTENZIONE!!!\nPrima di confermare si prega di inserire il codice di autenticazione."));
		return false;
	}
	document.frmSenders.action.value = "confpincode";
	document.frmSenders.submit();
}

function annullaPincode(){
  if (confirm("Sei sicuro di procedere con l'operazione?")) {
	document.frmSenders.action.value = "delpincode";
	document.frmSenders.submit();
  }
  return false;
}



function richiediPincode(){
	document.frmSenders.action.value = "pincode";
	document.frmSenders.submit();
}


function nuovoGruppo(){
	var elem = document.getElementById("tbedit");
	
	document.frmGruppi.idgruppo.value = "";
	document.frmGruppi.nomegruppo.value = "";
	document.frmGruppi.btnGruppo.value = "Crea";
	document.frmGruppi.action.value = "new";	
	
	if(elem.style.display == "inline")
		elem.style.display = "none";
	
	elem.style.display = "inline";
	return true;
}

function chiudiEditGruppo(){
	var elem = document.getElementById("tbedit");
	elem.style.display = "none";
	return true;
}

function submitGruppo(rules){
	if(performCheck('frmGruppi', rules, 'classic'))
		document.frmGruppi.submit();
	return false;
}

function modificaGruppo(){
	var grpsel = document.frmGruppi.gruppi.value;
	
	if(grpsel == ""){
		alert(unescape("ATTENZIONE!!!\nSeleziona il Gruppo che Vuoi modificare"));
		return false;
	}

	var infogrp = grpsel.split(",");	

	document.frmGruppi.idgruppo.value = infogrp[1];
	document.frmGruppi.nomegruppo.value = infogrp[2];
	document.frmGruppi.btnGruppo.value = "Modifica";
	document.frmGruppi.action.value = "mod";
	
	//MM_showHideLayers('mngGruppo','','show')
	var elem = document.getElementById("tbedit");
	
	if(elem.style.display == "inline")
		elem.style.display = "none";	
	
	elem.style.display = "inline";
	return true;	
}

function eliminaGruppo(){
	var grpsel = document.frmGruppi.gruppi.value;
	
	if(grpsel == ""){
		alert(unescape("ATTENZIONE!!!\nSeleziona il Gruppo che Vuoi eliminare"));
		return false;
	}

	var infogrp = grpsel.split(",");	

	document.frmGruppi.idgruppo.value = infogrp[1];
	document.frmGruppi.action.value = "del";
	
	document.frmGruppi.submit();
}

function spostaGruppo(){
	var grpsel = document.frmGruppi.nuovogruppo.value;
	
	alert(grpsel);
	
	/*if(grpsel == ""){
		alert(unescape("ATTENZIONE!!!\nSeleziona il Gruppo a cui vuoi associare i contatti"));
		return false;
	}
	
	var infogrp = grpsel.split(",");
	
	document.frmGruppi.idgrupponew.value = infogrp[1];
	document.frmGruppi.operation = "spgrp";
	
	document.frmGruppi.submit();*/
}

function mngSelector(){
	var num;
	var chk;
	if (document.frmCarrello.selector.value == 0)
		chk=1
	else
		chk=0
		
	num = document.frmCarrello.elements.length
	
	for (var i=0; i<num; i++) {
		var el = document.frmCarrello.elements[i];
		el.checked = chk;
	}
	
	document.frmCarrello.selector.value = chk;
}

function chkElimina() {
	var total = 0;
	var elems = document.frmCarrello.elements;
	var nelems = elems.length;

	for(i=0; i<nelems; i++){
			if((elems[i].type == "checkbox") && (elems[i].name == "item[]")){
					if(elems[i].checked == true){
							total++;
					}
			}
	}

	if (total == 0) {
			alert("Nessun prodotto selezionato.");
			return;
	}
	document.frmCarrello.cmd.value = "del";
	document.frmCarrello.action = "/ecommerce/mngcarrello.php";
	document.frmCarrello.submit();
}

function stampaCarrello(){
	window.open("/ecommerce/stampacarrello.php","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=635, height=700");	
}

function mngCarrello(value){
	document.frmCarrello.cmd.value = value;
	document.frmCarrello.action = "/ecommerce/mngcarrello.php";
	document.frmCarrello.submit();
}

function checkInvioPagamento(){
	// Da rivedere... prendendo direttamente i valori delle select non funzionava....
	var ok = true;
	var msg = "Attenzione si sono verificati i seguenti errori:\n";	
	var elems = document.frmRiepilogo.elements;
	var nelems = elems.length;
	
	for(i=0; i<nelems; i++){
		if((elems[i].name == "spesespedizione") && (elems[i].value == 0)){
			ok = false;
			
			msg += "Selezionare il tipo di spedizione desiderato\n";
		}
		if((elems[i].name == "tipopagamento") && (elems[i].value == 0)){
			ok = false;
			
			msg += "Selezionare il tipo di pagamento desiderato\n";
		}		
	}
	
	if(!document.frmRiepilogo.contratto.checked){
		ok = false;
		msg += "E' necessario accettare le condizioni di contratto\n";
	}
	
	if(!document.frmRiepilogo.clausole.checked){
		ok = false;
		msg += "E' necessario accettare le clausole indicate sul contratto\n";
	}	
	
	if(!document.frmRiepilogo.privacy.checked){
		ok = false;
		msg += "E' necessario accettare le norme sulla tutela della privacy\n";
	}

	if(! ok){ // Errore
		alert(msg);
		return;
	}
	
//	document.frmRiepilogo.action.value = "/ecommerce/pagamento.php";
	document.frmRiepilogo.submit();
	return;
}

function annullaOrdine(){
	if(confirm("Confermi la cancellazione dell'ordine?"))
		window.location = "/ecommerce/annullaordine.php";
	else
		return false;
}

function checkChiaveRicezione(x){
	document.frmCarrello.action = "/ecommerce/mngcarrello.php";
	document.frmCarrello.keynumber.value = x;
	document.frmCarrello.cmd.value='keycheck';
	document.frmCarrello.submit()
}

function confermaOrdine(){
	document.frmCarrello.action = "/ecommerce/confermaordine.php";
	document.frmCarrello.submit();
}

function setAutoresponder(value){
	window.open("/areaclienti/autoresponder.php?idchiave="+value,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=350");
}

function updateQuantita(idprodotto, element, giacenza, minquantita, maxquantita, quantita){
	if(element.value == "" || element.value == 0){
		alert("Specificare la quantità");
		element.value = quantita;
		return;
	}
		
	if(element.value > giacenza && giacenza != -1){
		alert("Quantità richiesta non disponibile");
		element.value = quantita;
		return;
	}
	
	if(element.value < minquantita){
		alert("Quantità richiesta insufficiente");
		element.value = minquantita;
		return;
	}

	if(element.value > maxquantita && maxquantita != 0){
		alert("Quantità richiesta maggiore di quella consentita");
		element.value = quantita;
		return;
	}

	document.frmCarrello.idupdate.value=idprodotto;
	mngCarrello('update');
}

function vrFatturePeriodo(rules){
	document.frmFatture.action.value = 'periodo';

	if(performCheck('frmFatture', rules, 'classic'))
		document.frmFatture.submit();
	return false;
}

function vrFattureMese(){
	document.frmFatture.action.value = 'mese';
	document.frmFatture.submit();
}

function vrFatture3Mesi(){
	document.frmFatture.action.value = '3mesi';
	document.frmFatture.submit();
}

function dettaglioFattura(id){
	window.open("/dettagliofattura.php?id="+id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=635, height=700");	
}

function mngCategoriaSupporto(obj){
	window.location = "/supporto/knowledge.php?id="+obj.value;
}

function viewTopic(codtopic, idtopic, categoria){
	document.frmTopic.cod_topic.value = codtopic;
	document.frmTopic.ID_topic.value = idtopic;
	document.frmTopic.id.value = categoria;
		
	document.frmTopic.submit();
}

function printTopic(id, cod){
	window.open("/supporto/printtopic.php?id="+id+"&cod="+cod,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=650, height=800");	
}

function viewSMS(id){
	window.open("/areaclienti/dettagliomess.php?idsms="+id,"_blan","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=650, height=550");
}

function viewMMS(id, clorid){
	window.open("/areaclienti/dettagliomess.php?idmms="+id+"&clorid="+clorid,"_blan","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=650, height=550");
}

function manageFattureCliente(tipoestrazione, rules){
	switch(tipoestrazione){
		case 1:
			cliFattureMese();
			break;
			
		case 2:
			cliFatture3Mesi();
			break;
			
		case 3:
			cliFatturePeriodo(rules);
			break;
	}
}

function cliFatturePeriodo(rules){
	document.frmFatture.cmd.value = 'periodo';

	if(performCheck('frmFatture', rules, 'classic'))
		document.frmFatture.submit();
	return false;
}

function cliFattureMese(){
	document.frmFatture.cmd.value = 'mese';
	document.frmFatture.submit();
}

function cliFatture3Mesi(){
	document.frmFatture.cmd.value = '3mesi';
	document.frmFatture.submit();
}

function inviasms(){
	window.location = '/areaclienti/inviasms.php';
}

function cercaInRubrica(){
	document.frmRubrica.cmd.value = 'search';
	document.frmRubrica.submit();
}

function modificaContattoRubrica(){
	var id = document.frmRubrica.contatti.value;
	
	if(id > 0){
		window.open("/areaclienti/contatto.php?id="+id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=500");
		return true;
	}
	
	alert("Attenzione: seleziona il contatto che vuoi modificare");
	return false;
}

function inserisciContattoRubrica(){
	window.open("/areaclienti/contatto.php","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=500");
	return true;
}

function eliminaContattoRubrica(){
	var id = document.frmRubrica.contatti.value;
	
	if(id > 0){
		if(confirm("Confermi la cancellazione del contatto selezionato?")){
			document.frmRubrica.cmd.value = 'del';
			document.frmRubrica.submit();			
		}
		return;
	}
	
	alert("Attenzione: seleziona il contatto che vuoi eliminare");
	return;
}

function importaGruppoDaRubrica(){
	var grpsel = document.frmGruppi.gruppi.value;
	
	if(grpsel != ''){
		var infogrp = grpsel.split(",");	
		
		var id = infogrp[1];	
	
		window.open("/areaclienti/grupporubrica.php?id="+id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=490, height=290");
		return true;		
	}
	
	alert("Attenzione: seleziona il gruppo in cui importare i contatti");
	return;
}

function importaGruppoDaFile(){
	var grpsel = document.frmGruppi.gruppi.value;
	
	if(grpsel == ""){
		alert(unescape("ATTENZIONE!!!\nSeleziona il Gruppo in cui importare i destinatari"));
		return false;
	}
	
	var infogrp = grpsel.split(",");
	
	var id = infogrp[1];	
	
	window.open("/areaclienti/gruppofile.php?id="+id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=490, height=595");
	return true;	
}

function stampaCondizioni(){
	window.open("/stampacondizioni.php","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=640, height=500");	
}

function gestioneSubaccountUtente(formname, action){
	var form = eval("document."+formname);

	var creditosmsutente = parseFloat(form.creditosmsutente.value);
	var creditommsutente = parseFloat(form.creditommsutente.value);
	var creditosmssubaccount = parseFloat(form.creditosmssubaccount.value);
	var creditommssubaccount = parseFloat(form.creditommssubaccount.value);
	var creditosms = parseFloat(form.creditosms.value);
	var creditomms = parseFloat(form.creditomms.value);
	
	switch(action){
		case "credsms+":			
			if(isNaN(creditosms) || creditosms==''){
				alert("Specificare un valore numerico per il credito SMS da aggiungere al subaccount");
				return false;
			}
			
			if(creditosms > creditosmsutente){
				alert("Non hai abbastanza credito SMS per effettuare questa operazione");
				return false;
			}
			
			var nuovocredito = eval(creditosms + creditosmssubaccount);
			
			if(confirm("Procedendo con l'operazione verranno accreditati "+creditosms+" crediti SMS Vola al subaccount")){
				form.doaction.value = action;
				form.submit();
			}
			return false;
			break;
			
		case "credsms-":
			if(isNaN(creditosms)){
				alert("Specificare un valore numerico per il credito SMS da togliere al subaccount");
				return false;
			}
			
			if(creditosms > creditosmssubaccount){
				alert("Si sta tentando di togliere un numero di crediti SMS maggiore di quello disponibile per il subaccount");
				return false;
			}
			
			if(confirm("Procedendo con l'operazione verranno tolti "+creditosms+" crediti SMS Vola al subaccount")){
				form.doaction.value = action;
				form.submit();
			}
			return false;		
			break;
			
		case "credmms+":
			if(isNaN(creditomms) || creditomms==''){
				alert("Specificare un valore numerico per il credito MMS da aggiungere al subaccount");
				return false;
			}
			
			if(creditomms > creditommsutente){
				alert("Non hai abbastanza credito MMS per effettuare questa operazione");
				return false;
			}
			
			var nuovocredito = eval(creditomms + creditommssubaccount);
			if(confirm("Procedendo con l'operazione verranno accreditati "+creditomms+" crediti MMS Vola al subaccount")){
				form.doaction.value = action;
				form.submit();
			}
			return false;
			break;
			
		case "credmms-":
			if(isNaN(creditomms) || creditomms==''){
				alert("Specificare un valore numerico per il credito MMS da togliere al subaccount");
				return false;
			}
			
			if(creditomms > creditommssubaccount){
				alert("Si sta tentando di togliere un numero di crediti MMS maggiore di quello disponibile per il subaccount");
				return false;
			}
			
			if(confirm("Procedendo con l'operazione verranno tolti "+creditomms+" crediti MMS Vola al subaccount")){
				form.doaction.value = action;
				form.submit();
			}
			return false;		
			break;			
			
		case "del":			
			if(confirm("Procedendo con l'operazione verrà eliminato il subaccount selezionato")){
				form.doaction.value = action;
				form.submit();
			}
			return false;
			break;
	}
	return false;
}

function gestioneSubaccount(formname, action){
	var form = eval("document."+formname);
	
	var creditovr = eval(form.creditovr.value);
	var creditosubaccount = eval(form.creditosubaccount.value);
	var credito = eval(form.credito.value);
	
	switch(action){
		case "cred+":
			var nuovocredito = eval(credito + creditosubaccount);
		
			if(isNaN(credito) || credito==''){
				alert("Specificare un valore numerico per il credito da aggiungere al subaccount");
				return false;
			}
			
			//if(credito > creditovr || nuovocredito > creditovr){
			if(credito > creditovr){
				alert("Non hai abbastanza credito per effettuare questa operazione");
				return false;
			}
			
			if(confirm("Procedendo con l'operazione verranno accreditati "+credito+" crediti Vola al subaccount")){
				form.doaction.value = action;
				form.submit();
			}
			return false;
			break;
			
		case "cred-":
			if(isNaN(credito)){
				alert("Specificare un valore numerico per il credito da togliere al subaccount");
				return false;
			}
			
			if(credito > creditosubaccount){
				alert("Si sta tentando di togliere un numero di crediti maggiore di quello disponibile per il subaccount");
				return false;
			}
			
			if(confirm("Procedendo con l'operazione verranno tolti "+credito+" crediti Vola al subaccount")){
				form.doaction.value = action;
				form.submit();
			}
			return false;		
			break;
			
		case "del":
			if(confirm("Procedendo con l'operazione verrà eliminato il subaccount selezionato")){
				form.doaction.value = action;
				form.submit();
			}
			return false;
			break;
	}
	return false;
}

function couponCarrello(azione){
	if(azione == 'utilizza'){
		var coupon = document.frmCarrello.coupon.value;
		if(coupon == ""){
			alert("Inserire il coupon che si vuole utilizzare");
			return;
		}
	}
	
	document.frmCarrello.doaction.value = azione;
	document.frmCarrello.action = "/ecommerce/applicacoupon.php";
	document.frmCarrello.submit();
}

function popupCondizioni(){
	window.open("/popupcondizioni.php", "_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=830, height=600");
}

function popupRiservatezza(){
	window.open("/popupriservatezza.php", "_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=830, height=600");
}

function popupCondizionivap(){
	window.open("/popupcondizionivap.php", "_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=830, height=600");
}

function regutenteback(step, rules){
	if(step == 1 || step == 2 || step == 3){
		document.frmRegistrazione.step.value=step;
		document.frmRegistrazione.submit();
		return;
	}
	
	if(performCheck('frmRegistrazione', rules, 'classic'))
		document.frmRegistrazione.submit();
	else
		return false
}

function tipoInvioSms(tipo){
	if(tipo == 0){
		var dispvalue = "none";
	}else{
		var dispvalue = "inline";
	}
	
	ele=document.getElementById("dt_gg");
	ele.style.display=dispvalue;
	ele=document.getElementById("dt_mm");
	ele.style.display=dispvalue;
	ele=document.getElementById("dt_yy");
	ele.style.display=dispvalue;
	ele=document.getElementById("tm_hh");
	ele.style.display=dispvalue;
	ele=document.getElementById("tm_mm");
	ele.style.display=dispvalue;
}

function confermaAnnullaSms(){
	if(confirm("Attenzione: annullando l'operazione i dati inseriti per l'SMS saranno cancellati")){
		window.location='/areaclienti/volasmsweb.php?cmd=new';
		return true;
	}
	return false;	
}

function confermaAnnullaMms(){
	if(confirm("Attenzione: annullando l'operazione i dati inseriti per l'MMS saranno cancellati")){
		window.location='/areaclienti/volammsweb.php?action=3';
		return true;
	}
	return false;	
}

function cambiaChiaveRicezione(x){
	document.frmCarrello.action = "/ecommerce/mngcarrello.php";
	document.frmCarrello.keynumber.value = x;
	document.frmCarrello.cmd.value='keynull';
	document.frmCarrello.submit()	
}

function dettagliOrdine(){	
	document.frmRiepilogo.action = '/ecommerce/confermaordine.php'; 
	document.frmRiepilogo.submit()
}

function vediOrdine(id){
	window.open("/areaclienti/dettaglioOrdine.php?id="+id,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=635, height=700");
}

function verificaSelezioneCheckbox(controllo, frm) {
	var total = 0;
	var form = eval("window.document."+frm);
	var elems = form.elements;
	var nelems = elems.length;

	for(i=0; i<nelems; i++){
		if((elems[i].type == "checkbox") && (elems[i].name == controllo)){
			if(elems[i].checked == true){
					total++;
			}
		}
	}

	if (total == 0) {
		return false;
	}
	return true;
}

function rinnovaChiave(controllo, frm){
	if(verificaSelezioneCheckbox(controllo, frm))
		return true;
		
	alert("Seleziona almeno una delle chiavi per il rinnovo");
	return false;
}

function eliminaMessaggi(controllo, frm){
	if(verificaSelezioneCheckbox(controllo, frm)){
		document.frmMess.action.value=1; 
		document.frmMess.submit();
		return true;
	}
	
	alert("Seleziona almeno un messaggio da eliminare");
	return false;
}

function checkAlertCredito(rules){
	var sms = document.getElementById('sms_si');
	var mms = document.getElementById('mms_si');
	
	var error = false;
	var alertmsg = "Attenzione:\n";

	if(sms.checked){
		if(! document.frmNotifica.notsms_sms.checked && ! document.frmNotifica.notsms_mail.checked){
			error = true;
			alertmsg += "* E' stata richiesta la notifica sul credito SMS ma non è stata specificata la modalità\n";
		}		
	}
	
	if(mms.checked){
		if(! document.frmNotifica.notmms_sms.checked && ! document.frmNotifica.notmms_mail.checked){
			error = true;
			alertmsg += "* E' stata richiesta la notifica sul credito MMS ma non è stata specificata la modalità\n";
		}		
	}
	
	if(! error)
		return performCheck('frmNotifica', rules, 'classic');
	
	alert(alertmsg);
	return false;
}

function printInfoBonifico(importo){
	window.open("/ecommerce/stampabonifico.php?importo="+escape(importo),"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=600, height=600");
}

function printInfoVaglia(importo){
	window.open("/ecommerce/stampavaglia.php?importo="+escape(importo),"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=600, height=600");
}

function printInfoFax(importo){
	window.open("/ecommerce/stampafax.php?importo="+escape(importo),"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=600, height=600");
}

function mostraInfoNotificaSms(){
	var elem_1 = document.getElementById("sogliasms");
	var elem_2 = document.getElementById("notificasms");
	
	elem_1.style.display = "inline";
	elem_2.style.display = "inline";
	
	return true;
}

function nascondiInfoNotificaSms(){
	var elem_1 = document.getElementById("sogliasms");
	var elem_2 = document.getElementById("notificasms");
	
	elem_1.style.display = "none";
	elem_2.style.display = "none";
	
	return true;
}

function mostraInfoNotificaMms(){
	var elem_1 = document.getElementById("sogliamms");
	var elem_2 = document.getElementById("notificamms");
	
	elem_1.style.display = "inline";
	elem_2.style.display = "inline";
	
	return true;
}

function nascondiInfoNotificaMms(){
	var elem_1 = document.getElementById("sogliamms");
	var elem_2 = document.getElementById("notificamms");
	
	elem_1.style.display = "none";
	elem_2.style.display = "none";
	
	return true;
}

function checkInvioPagamentoWlc(){
	// Da rivedere... prendendo direttamente i valori delle select non funzionava....
	var ok = true;
	var msg = "Attenzione si sono verificati i seguenti errori:\n";	
	var elems = document.frmRiepilogo.elements;
	var nelems = elems.length;
	
	for(i=0; i<nelems; i++){
		if((elems[i].name == "spesespedizione") && (elems[i].value == 0)){
			ok = false;
			
			msg += "Selezionare il tipo di spedizione desiderato\n";
		}	
	}
	
	if(!document.frmRiepilogo.contratto.checked){
		ok = false;
		msg += "E' necessario accettare le condizioni di contratto\n";
	}
	
	if(!document.frmRiepilogo.clausole.checked){
		ok = false;
		msg += "E' necessario accettare le clausole indicate sul contratto\n";
	}	
	
	if(!document.frmRiepilogo.privacy.checked){
		ok = false;
		msg += "E' necessario accettare le norme sulla tutela della privacy\n";
	}

	if(! ok){ // Errore
		alert(msg);
		return;
	}
	
//	document.frmRiepilogo.action.value = "/ecommerce/pagamento.php";
	document.frmRiepilogo.submit();
	return;
}

function verificaMittente(str){
	var myregexp2 = /^[a-zA-Z0-9]+$/;
	var myregexp1 = /^[0-9]+$/;
	
	if (myregexp2.test(str) == false) {
		if(str.length > 14){
			alert("Attenzione: se il mittente è numerico non può superare i 14 caratteri");
			return false;
		}
		return true;
	}
		
	if (myregexp1.test(str) == false) {
		if(str.length > 11){
			alert("Attenzione: se il mittente è alfanumerico non può superare gli 11 caratteri");
			return false;
		}
		return true;
	}
	
	return true;
}

function submitVolaWeb(rules){
	if(performCheck('frmVola', rules, 'classic') && verificaMittente(document.frmVola.mittente.value))
		return true;
	return false;
}

function disable(nameValues) {
	var controlli = document.filtroFrm.elements;
	for (var i = 0; i < controlli.length; i++) {
		for (var j = 0; j < nameValues.length; j++) {
			if (controlli[i].value == nameValues[j]) {
				controlli[i].checked = false;
				break;
			}
		}
	}	
}

function mostraStatsGenerali(){
	var elem = document.getElementById("statsgenerali");
	elem.style.display = "inline";
	
	var elem = document.getElementById("statsaccount");
	elem.style.display = "none";	
	return true;	
}

function mostraStatsSubaccount(){
	var elem = document.getElementById("statsgenerali");
	elem.style.display = "none";
	
	var elem = document.getElementById("statsaccount");
	elem.style.display = "inline";	
	return true;
}

function graficoSubaccount(idsubaccount, username){
	window.open("/partners/vr/graficosubaccount.php?idsubaccount="+idsubaccount+"&username="+username,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=560");
}

function checkFormLicenze(form, type){
	var myform = eval("window.document."+form);
	var quantita = myform.quantita.value;
	var lic_disp = myform.lic_disp.value;
	var lic_ass = myform.lic_ass.value;
	var lic_us = myform.lic_us.value;
	var tot_lic_subaccount = lic_ass + lic_us;
	
	if(isNaN(quantita)){
		alert("Specificare un valore numerico per il numero di licenze");
		return false;
	}
	
	myform.doaction.value = type;
	myform.submit();
}

function checkRagioneSociale(){
	var val = document.frmProfilo.rag_soc.value;
	
	rules = new Array();
	
	rules[0] = 'numero_mitt:Mittente messaggi|required';
	rules[1] = 'nome:Nome utente|required';
	rules[2] = 'ind:indirizzo|required';
	rules[3] = 'nome_pers:Nome|required';
	rules[4] = 'cognome_pers:Cognome|required';
	//rules[8] = 'email:E-mail|required';
	rules[5] = 'email:E-mail|email';
	rules[6] = 'tel_azienda|keypress|0123456789';
	rules[7] = 'cap|keypress|0123456789';
	rules[8] = '$nuova_password|equal|conferma_password|La nuova password e la conferma non coincidono';
	rules[9] = 'msisdn|keypress|0123456789';
	rules[10] = 'email_az:E-mail aziendale|email';
	rules[11] = 'password|keypress|0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_-';
	rules[12] = 'nuova_password|keypress|0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_-';
	rules[13] = 'conferma_password|keypress|0123456789qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_-';	
	
	if(val == ""){ // SETTING PAGINA PER PROFILO UTENTE PRIVATO
		eletr = document.getElementById("trpiva");
		eletr.style.display = "none";	
	
		rules[15] = 'cf:Codice Fiscale|codfisc'
	}else{ // SETTING PAGINA PER PROFILO UTENTE AZIENDALE
		eletr = document.getElementById("trpiva");
		if(navigator.appName == "Microsoft Internet Explorer")	
			eletr.style.display = "inline";
		else
			eletr.style.display = "table-row";
		
	
		rules[14] = 'piva:partita iva|piva';
		rules[15] = 'cf|keypress|0123456789';
		rules[16] = 'piva|keypress|0123456789';
		rules[17] = 'cf:codice fiscale|codfiscaz';
	}
}

function confirmGoldToSilver() {
	var message = "ATTENZIONE!: Il profilo Silver è un profilo di BASSA QUALITA' che utilizza per la consegna dei messaggi SMS diversi operatori "
				+ "esteri. La consegna dei messaggi è di tipo \"Best Effort\" e non è quindi garantita, sono possibili ritardi e problemi di "
				+ "consegna (in alcuni casi si possono riscontrare anche mancate consegne) in vari momenti della giornata.\r\n\r\n"
				+ "Confermando il cambio di profilo da Gold a Silver, accetto quanto sopra riportato e prendo atto che VOLA S.p.A. non potrà essere "
				+ "ritenuta responsabile di eventuali disservizi che potranno accadere con l’utilizzo del servizio Silver. VOLA consiglia l’utilizzo "
				+ "del profilo Gold.\r\n\r\nConfermi l'operazione di cambio profilo tariffario?";	
	
	if(confirm(message)) document.frmListino.submit()
}

function confirmSilverToGold() {
	var message = "Confermi l'operazione corrente?";

	if(confirm(message)) document.frmListino.submit()
}

/**
 * CODICE PER AVVISO FERIE
 */
function ShowLayerConfirm(request) {
    var d= $('ModalBGConfirm');
    var p= $('DialogWindowConfirm');
	
    if (d) { 	
	    offset = Position.realOffset(p);
	    pos = p.getDimensions();   

        if (pos.height > document.body.clientHeight){
    	    altez = offset[1] + 20;
        }else{
            altez = offset[1] + (document.body.clientHeight - pos.height) / 2;
        }

        if (pos.width > document.body.clientWidth){
            larg = offset[0] + 20;
        }else{
            larg = offset[0] + (document.body.clientWidth - pos.width) / 2;
        }
		
        p.style.left = larg + "px";
	    p.style.top = altez + "px";								  
								  
	    d.style.display='inline';
        p.style.display='inline';
	 
        if (/MSIE/.test(navigator.userAgent) || /Safari/.test(navigator.userAgent)) {
	        Position.absolutize('DialogWindowConfirm');
	    } 
	 
	    new Draggable('DialogWindowConfirm',{ scroll:window,
				                    handle: 'dw_header',
				                    starteffect:function(){},
									endeffect:function(){} 
                                  });	     							  
    } else {
        ShowError();
    }
}

function CloseDialogBoxConfirm() {
  var d= $('ModalBGConfirm');
  var p= $('DialogWindowConfirm');
  if (d) {
   d.style.display='none';
   p.style.display='none';
  }
  else 
  	ShowError();
}

// *******************

function notaSilver() {
	var msg = "ATTENZIONE al profilo SILVER: ritardi e problemi di consegna "
			+ "sono possibili \r\nin vari momenti della giornata. Vi ricordiamo "
			+ "che la consegna dei messaggi \r\nSMS sul profilo SILVER (bassa "
			+ "qualità) è di tipo \"Best Effort\" e non è quindi \r\ngarantita.\r\n"
			+ "Consigliamo l'utilizzo del profilo GOLD.";
	
	alert(msg);
}