// JavaScript Utilities
// Copyright (c) 2003 Gulliver S.r.L.
// All Rights Reserved.
//----------------------------------------------------------------------------------------------------
// Verifica se i cookie sono abilitati
//----------------------------------------------------------------------------------------------------
    function testCookie() {
      if (!navigator.cookieEnabled) {
        alert("Abilitare i cookie del browser per una corretta navigazione del sito.");
        return false;
      } else {
        return true;
      }
    }
//----------------------------------------------------------------------------------------------------
// Variabili
    var oBigPhotoUrl;
    var basketCookieName = "basket";
    var basketCookiePersistenceInHours = 960;
    var basketCookie;
    var oProductCode, oProductName, oProductDesc, oProductImg, oProductPricev, oProductAttrib1, oProductAttrib2;
    var basketArray, basketArrayLength, qtaArray, tmpArray;
    var maxBasketArrayLength = 50;
    var attri = new Array();
    var mFrame = top.frames['storeBasket'];
    var quantitaPezzi = 1;
    var numOfSelectedRows;
    var prefixes = new Array();
    var badCodes = new Array();
    var badPrefixes = new Array();
    var attributes = new Array();
    var priceArray = new Array();
    var tettoSpesaMsg = "L'importo della spesa deve essere maggiore di 40 euro.";
	var statiArray = new Array();
	var ordineArray = new Array();
	var abilitazioniArray = new Array();
	var mailArray = new Array();
    var daDataCalendarForm;
    var daDataCalendarObj;
    var aDataCalendarForm;
    var aDataCalendarObj;
//----------------------------------------------------------------------------------------------------

    function init() {
        if (testCookie()) {
    	    basketCookie = new Cookie(document, basketCookieName, basketCookiePersistenceInHours);
    	    if (!(basketCookie.load() && basketCookie.data)) {
    	        basketArray = new Array();
    	 		    qtaArray = new Array();
    	        tmpArray = new Array();
    	        basketArrayLength = basketArray.length;
    	    } else {
    	        tmpArray = basketCookie.data.split(":");
    	  	    basketArray=tmpArray[0];
    	  	    basketArray=basketArray.split("|");
    	  	    qtaArray=tmpArray[1];
    	  	    qtaArray=qtaArray.split("|");
    	  	    if (basketArray.length > maxBasketArrayLength) {
    	            basketArray = basketArray.slice(0, maxBasketArrayLength - 1);
    	        }
    	        basketArrayLength = basketArray.length;
    	    }
    	    inLineBasket();
        }
	}

  	function promozione_anticaduta() {
		var sectionCode 	= "88767";
		var subsection1Code = "87894";
        loadCataloguePagePromozioni("1",sectionCode,subsection1Code,"","","");
	}

	function promozione_cofanetti() {
        var sectionCode 	= "88767";
		var subsection1Code = "34457";
        loadCataloguePagePromozioni("1",sectionCode,subsection1Code,"","","");
	}


  	function promozione_spazzole() {
		var sectionCode 	= "75646";
		var subsection1Code = "6996";
        loadCataloguePagePromozioni("1",sectionCode,subsection1Code,"","","");
	}

	function promozione_starpouf() {
        var sectionCode 	= "75646";
		var subsection1Code = "79965";
        loadCataloguePagePromozioni("1",sectionCode,subsection1Code,"","","");
	}

    function doRemoveFromOrder() {
      while (basketArrayLength > 0) {
    		prefix = basketArray.pop();
    		basketArrayLength--;
    	}
    	basketCookie.data = basketArray.join("|");
    	basketCookie.store();
        init();
    }

    function doRemoveFromBasket() {
      var prefix, L = prefixes.length;
      if (numOfSelectedRows == 0) {
        alert("Nessun prodotto selezionato. ");
      } else {
            if (confirm("Sei sicuro di voler togliere i prodotti selezionati? ")) {
                for (i = 0; i < L; i++) {
                        prefix = prefixes[i];
                           if (MM_findObj(prefix + '_flagCheckBoxCtrl').checked == true) {
                               basketArray[i] = basketArray[basketArrayLength - 1];
                               qtaArray[i] = qtaArray[basketArrayLength - 1];
                               prefixes[i] = prefixes[L - 1];
                               L--;
                               basketArray.pop();
                               qtaArray.pop();
                          basketArrayLength--;
                          i--;
                           }
                      }
                  }
                   tmpArray[0]=basketArray.join("|");
                   tmpArray[1]=qtaArray.join("|");
                   if(basketArray.length != 0){
                   basketCookie.data = tmpArray.join(":");
                   }else{basketCookie.data = basketArray.join("|");}
                   basketCookie.store();
                   doBasketOpenFromBasket();
            }
    }

    function doBasketOpenFromBasket() {
	    if (basketArrayLength == 0) {
		    alert("Ora il tuo carrello è vuoto! ");
      	    document.location.href="index.htm"
		} else {
		    document.productsListPageByPrefixesForm.GB_TYPER.value = "CREATTIVA_BASKET";
			document.productsListPageByPrefixesForm.prefixes.value = basketArray.join(",");
			document.productsListPageByPrefixesForm.submit();
		}
	}

    function doBasketOpen() {
	    if (basketArrayLength == 0) {
		    alert("Non hai nessun prodotto nel carrello! ");
			} else {
		        document.productsListPageByPrefixesForm.GB_TYPER.value = "CREATTIVA_BASKET";
				document.productsListPageByPrefixesForm.prefixes.value = basketArray.join(",");
				document.productsListPageByPrefixesForm.submit();
			}
		}

     function addqtaManual(prefix,value){
        qtaval=(isNaN(value))?0:value
        if(qtaval==0){
            qtaobj=eval("document.budgetForm.q_"+prefix);
            qtaobj.value=parseInt(0);
            addQtaToBasketCookie(prefix-1,0);
        }
        else{addQtaToBasketCookie(prefix-1,parseInt(qtaval));}
        calcolaTotale();
     }

    function addqta(prefix,p) {
        qtaobj=eval("document.budgetForm.q_" + prefix);
        qtaval=parseInt(qtaobj.value);
        qtaval=(isNaN(qtaval))?0:qtaval;
        if (p) {
            qtaobj.value=parseInt(qtaval)+1;
            addQtaToBasketCookie(prefix-1,parseInt(qtaval)+1);
        } else if (qtaval > 1){
            qtaobj.value=parseInt(qtaval)-1;
            addQtaToBasketCookie(prefix-1,parseInt(qtaval)-1);
          }
        calcolaTotale();
    }

    function addQtaToBasketCookie(pos,qta){
        qtaArray[pos]=qta;
        tmpArray[0]=basketArray.join("|");
        tmpArray[1]=qtaArray.join("|");
        basketCookie.data = tmpArray.join(":");
        basketCookie.store();
    }

    function selectAllProducts() {
        var prefix, L = prefixes.length;
        if (MM_findObj('TUTTI_flagCheckBoxCtrl').checked == false) {
            for (i = 0; i < L; i++) {
                prefix = prefixes[i];
                MM_findObj(prefix + '_flagCheckBoxCtrl').checked = false;
                numOfSelectedRows--;
            }
        } else {
            for (i = 0; i < L; i++) {
                prefix = prefixes[i];
                MM_findObj(prefix + '_flagCheckBoxCtrl').checked = true;
                numOfSelectedRows++;
            }
        }
    }

    function doToggleProduct(prefix) {
        if (attributes[prefix + '_flag']) {
            attributes[prefix + '_flag'] = false;
            numOfSelectedRows--;
        } else {
            attributes[prefix + '_flag'] = true;
            numOfSelectedRows++;
        }
    }

    function submitOrdine(user){
        if (user == 'guest') {
            alert("Attenzione!\r\nPer acquistare devi inserire la tua email e password.\r\nSe non sei ancora registrato devi cliccare sul tasto registrazione posto nel menù qui a sinistra.");
        } else {
            if(controlQta()){
                basketArray[basketArray.length]=getSpese(priceArray,qtaArray);
               qtaArray[qtaArray.length]=1;
               document.aggiornaCarrelloForm.GB_TYPER.value     = "CREATTIVA_ECOMMERCE";
               document.aggiornaCarrelloForm.prefixies.value    = basketArray.join(",");
               document.aggiornaCarrelloForm.quantities.value   = qtaArray.join("|");
               document.aggiornaCarrelloForm.submit();
            }
            else{alert("Controlla di avere inserito valori validi nelle quantità.");}
        }
    }

    function controlQta(){
        for(var i=0,h=qtaArray.length; i < h; i ++){
            if(qtaArray[i]==0){
            return false;}
        }
        return true;
    }

    function showDetailInfoBox(cod){
        dettaglioProdotto("","","","","",cod);
    }

    function dettaglioProdotto(liv1,liv2,liv3,liv4,liv5,cod) {
        document.detailForm.GB_TYPER.value          = "CREATTIVA_DETTAGLIO";
        document.detailForm.sectionCode.value       = liv1;
        document.detailForm.subsection1Code.value   = liv2;
        document.detailForm.subsection2Code.value   = liv3;
        document.detailForm.subsection3Code.value   = liv4;
        document.detailForm.subsection4Code.value   = liv5;
        document.detailForm.ProductCode.value       = cod;
        document.detailForm.submit();
    }

    function dettaglioProdottoPromozioni(liv1,liv2,liv3,liv4,liv5,cod) {
        document.detailForm.GB_TYPER.value          = "CREATTIVA_DETTAGLIO_PROMOZIONI";
        document.detailForm.sectionCode.value       = liv1;
        document.detailForm.subsection1Code.value   = liv2;
        document.detailForm.subsection2Code.value   = liv3;
        document.detailForm.subsection3Code.value   = liv4;
        document.detailForm.subsection4Code.value   = liv5;
        document.detailForm.ProductCode.value       = cod;
        document.detailForm.submit();
    }

    function showDeatilOrder(cod){
        document.ordiniDetail.numOrdine.value = cod;
        document.ordiniDetail.submit();
    }

	function getOrderHistory(page){
        document.getOrderHistory.PAGINA.value = page;
        document.getOrderHistory.submit();
    }

    function getOrderData(page,gDaData,mDaData,aDaData,gAData,mAData,aAData){
	    document.getOrderByDateForm.PAGINA.value = page;
		document.getOrderByDateForm.gDaData.value = gDaData;
		document.getOrderByDateForm.mDaData.value = mDaData;
		document.getOrderByDateForm.aDaData.value = aDaData;
		document.getOrderByDateForm.gAData.value = gAData;
		document.getOrderByDateForm.mAData.value = mAData;
		document.getOrderByDateForm.aAData.value = aAData;
	    document.getOrderByDateForm.submit();
    }

    function getOrderCerca(){
  	    document.getOrderForStatiForm.STATO.value = document.statoForm.stato.value;
  	    document.getOrderForStatiForm.submit();
    }

    function getOrderStato(page,stato){
  	    document.getOrderForStatiForm.STATO.value = stato;
		document.getOrderForStatiForm.PAGINA.value = page;
  	    document.getOrderForStatiForm.submit();
    }

    function showDettagliOrdine(numOrdine){
        document.getOrderDetailForm.numOrdine.value = numOrdine;
        document.getOrderDetailForm.submit();
    }

    function aggiornaSingoloStato(nOrdine){
    	document.agiornaStatoOrdineForm.idOrdine.value = nOrdine + "|";
    	document.agiornaStatoOrdineForm.stato.value = document.statoForm.stato.value + "|";
    	document.agiornaStatoOrdineForm.submit();
    }

	function showSchedaTecnica(scheda) {
		var url = scheda;
		var parametri="resizable=yes, width = 640, height = 480, location=no, top = 0, left = 0";
		window.open(url, "SchedaTecnica", parametri);
	}

    function inLineBasket() {
        if (basketArrayLength == 0) {
            if(window.frames["iFrameCarrello"]) {
                window.frames["iFrameCarrello"].document.location.href="carrelloVuoto.htm";
            } else {
               top.location.href="index.htm";
            }
    	} else {
    	   if(mFrame && window.frames["iFrameCarrello"]){
    	        document.inLineproductsListPageByPrefixesForm.GB_TYPER.value = "CREATTIVA_INLINEBASKET";
    	        document.inLineproductsListPageByPrefixesForm.prefixes.value = basketArray.join(",");
    	        document.inLineproductsListPageByPrefixesForm.submit();
    	    } else {
    	        top.location.href="index.htm";
    	    }
    	}
    }

    function inLineBasket2() {
        document.inLineproductsListPageByPrefixesForm.GB_TYPER.value = "CREATTIVA_INLINEBASKET";
        document.inLineproductsListPageByPrefixesForm.prefixes.value = "";
        document.inLineproductsListPageByPrefixesForm.submit();
    }

    function deleteCookie() {
      var cookie = basketCookieName + '=';
      if (this.$path) {
        cookie += '; path=' + this.$path;
      }
      if (this.$domain) {
        cookie += '; domain=' + this.$domain;
      }
      cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
      this.document.cookie = cookie;
    }

    function addToBasket(prefix,descrizione,prezzo) {
        var descrizioneCarrello = descrizione.substring(0, 41);
        descrizioneCarrello += "...";
        if(basketArray.length==0){
            mFrame.basketArrayDesc = new Array();
            mFrame.basketArrayPrezzo = new Array();
        }
        if (basketArrayLength >= maxBasketArrayLength) {
            alert("Il carrello è pieno, impossibile aggiungere altri prodotti. ");
        } else {
            var tempBasketArray=new Array();
            if (!(basketCookie.load() && basketCookie.data)) {
                basketArray.push(prefix);
                qtaArray.push(quantitaPezzi);
                basketArrayLength++;
                tmpArray[0]=basketArray.join("|");
                tmpArray[1]=qtaArray.join("|");
                basketCookie.data = tmpArray.join(":");
                mFrame.basketArrayDesc.push(descrizioneCarrello);
                mFrame.basketArrayPrezzo.push(prezzo);
                basketCookie.store();

            } else {
                tempBasketArray=basketArray;
                for(var i=0,h=tempBasketArray.length; i<h; i++){
                    if(tempBasketArray[i]==prefix){
                        //alert("Questo prodotto è già nel carrello!");
                        doBasketOpen();
                        return;
                    }
                }
                basketArray.push(prefix);
                qtaArray.push(quantitaPezzi);
                basketArrayLength++;
                tmpArray[0]=basketArray.join("|");
                tmpArray[1]=qtaArray.join("|");
                basketCookie.data = tmpArray.join(":");
                mFrame.basketArrayDesc.push(descrizioneCarrello);
                mFrame.basketArrayPrezzo.push(prezzo);
                basketCookie.store();
            }
        }
        inLineBasket();
    }

    function validateUser(){
        var ur                                  = document.logonForm.userTextCtrl.value;
        var pd                                  = document.logonForm.passwordCtrl.value;
        if(ur == "") {
            alert("Email obbligatoria.");
            document.logonForm.userTextCtrl.focus();
            return;
        }
        if(pd == "") {
            alert("Password obbligatoria.");
            document.logonForm.passwordCtrl.focus();
            return;
        }
        document.validateForm.user.value        = ur;
        document.validateForm.password.value    = pd;
        document.validateForm.submit();
    }

    function loadCataloguePage(pageIndex, sectionCode, subsection1Code, subsection2Code, subsection3Code, subsection4Code) {
        document.cataloguePageForm.GB_TYPER.value         = "CREATTIVA_CATPAGE";
        document.cataloguePageForm.pageIndex.value        = pageIndex;
        document.cataloguePageForm.sectionCode.value      = sectionCode;
        document.cataloguePageForm.subsection1Code.value  = subsection1Code;
        document.cataloguePageForm.subsection2Code.value  = subsection2Code;
        document.cataloguePageForm.subsection3Code.value  = subsection3Code;
        document.cataloguePageForm.subsection4Code.value  = subsection4Code;
        document.cataloguePageForm.submit();
    }

    function loadCataloguePagePromozioni(pageIndex, sectionCode, subsection1Code, subsection2Code, subsection3Code, subsection4Code) {
        document.cataloguePageForm.GB_TYPER.value         = "CREATTIVA_PROMOZIONI";
        document.cataloguePageForm.pageIndex.value        = pageIndex;
        document.cataloguePageForm.sectionCode.value      = sectionCode;
        document.cataloguePageForm.subsection1Code.value  = subsection1Code;
        document.cataloguePageForm.subsection2Code.value  = subsection2Code;
        document.cataloguePageForm.subsection3Code.value  = subsection3Code;
        document.cataloguePageForm.subsection4Code.value  = subsection4Code;
        document.cataloguePageForm.submit();
    }

    function loadOtherPage(typeOfpage) {
        document.cataloguePageForm.GB_TYPER.value = "CREATTIVA_" + typeOfpage;
        document.cataloguePageForm.submit();
    }

	function loadSearchResultsPage() {
    	var searchTextCtrl = document.searchForm.searchTextCtrl;
    	var searchTextCtrlValue = searchTextCtrl.value;

     	if (searchTextCtrlValue == '') {
      	    alert("Devi specificare qualcosa da cercare prima di avviare una ricerca.");
            document.searchForm.searchTextCtrl.focus();
    	} else {
      	    document.searchResultsPageForm.searchText.value = searchTextCtrlValue;
            document.searchResultsPageForm.submit();
    	}
	}

	function loadSearchResultsPageByText(pageIndex, newSearchFlag, searchText) {
      if (newSearchFlag) {
      	document.searchResultsPageForm.pageIndex.value = pageIndex;
        document.searchResultsPageForm.searchText.value = searchText;
        document.searchResultsPageForm.submit();
      } else {
      	document.searchResultsPageForm.pageIndex.value = pageIndex;
        document.searchResultsPageForm.submit();
      }
    }

    function showOrdini(codice, mail){
        document.getHistoryClienteForm.code.value   = codice;
        document.getHistoryClienteForm.email.value  = mail;
        document.getHistoryClienteForm.submit();
    }

    function aggiornaStati(){
        var ordini = "";
        var stati = "";
        for(var i=0, l= ordineArray.length; i < l; i++){
            var idOrdine=ordineArray[i];
            var s = document.forms["statiForm_"+idOrdine].stato.value;
            statiArray[i]=s;
        }
        for(var i=0, l = ordineArray.length; i < l; i++){
        	ordini += ordineArray[i] + "|";
    	    stati += statiArray[i] + "|";
        }
        document.agiornaStatoOrdineForm.idOrdine.value = ordini;
        document.agiornaStatoOrdineForm.stato.value = stati;
        document.agiornaStatoOrdineForm.submit();
    }

	function showAllAddresses(codice) {
        document.getSediDetailsClientForm.codice.value = codice;
        document.getSediDetailsClientForm.submit();
    }

    function aggiornaDatiUtente(codice){
        if(validateForm()){
            document.updateClientDetailsForm.codice.value           = codice;
            document.updateClientDetailsForm.email.value            = document.validateForm.Email.value;
            document.updateClientDetailsForm.password.value         = document.validateForm.Password.value;
            document.updateClientDetailsForm.confirmPassword.value  = document.validateForm.ConfirmPassword.value;
            document.updateClientDetailsForm.nome.value             = document.validateForm.Nome.value;
            document.updateClientDetailsForm.cognome.value          = document.validateForm.Cognome.value;
            document.updateClientDetailsForm.dataNascita.value      = document.validateForm.DataNascita.value;
            document.updateClientDetailsForm.telefono.value         = document.validateForm.Telefono.value;
            document.updateClientDetailsForm.indirizzo.value        = document.validateForm.Indirizzo.value;
            document.updateClientDetailsForm.provincia.value        = document.validateForm.Provincia.value;
            document.updateClientDetailsForm.cap.value              = document.validateForm.Cap.value;
            document.updateClientDetailsForm.localita.value         = document.validateForm.Localita.value;
            document.updateClientDetailsForm.nazione.value          = document.validateForm.Nazione.value;
            //document.updateClientDetailsForm.numBadge.value       = document.validateForm.Badge.value;
            document.updateClientDetailsForm.note.value             = "";
            document.updateClientDetailsForm.ragSociale.value       = document.validateForm.RagSociale.value;
            document.updateClientDetailsForm.sconto.value           = document.validateForm.Sconto.value / 100;
            if (validatePIVaCodFiscale()) {
                var codFpIva = document.validateForm.pIva.value;
                if(codFpIva.length == 11) {
                    document.updateClientDetailsForm.pIva.value   = codFpIva;
                } else {
                    document.updateClientDetailsForm.codFiscale.value         = codFpIva;
                }
                var abilitato = "";
                if (document.validateForm.abilitato.checked) {
        	        abilitato += 1 + "|";
                    document.updateClientDetailsForm.abilitato.value    = abilitato;
                    document.updateClientDetailsForm.submit();
                } else {
        	        abilitato += 0 + "|";
                    document.updateClientDetailsForm.abilitato.value    = abilitato;
                    document.updateClientDetailsForm.submit();
                }
            }
        }
    }

    function aggiornaAbilitazioni(){
    	var mail = "";
    	var abilitato = "";
    	for(var i=0, l=mailArray.length; i<l; i++){
    		mail += mailArray[i] + "|";
    		if(document.forms[mailArray[i]].abilitato.checked)
    			abilitato += 1 + "|";
    		else
    			abilitato += 0 + "|";
    	}
    	document.aggiornaAbilitazioniForm.strEmail.value = mail;
    	document.aggiornaAbilitazioniForm.strAbilit.value = abilitato;
    	document.aggiornaAbilitazioniForm.submit();
    }

    function getOrder(page){
        document.getAllECommerceUserForm.PAGINA.value = page;
      	document.getAllECommerceUserForm.submit();
    }

    function ok() {
    	var nomeValue 	    = document.couponForm.nome.value;
    	var cognomeValue    = document.couponForm.cognome.value;
        var cityValue       = document.couponForm.city.value;
    	var telefonoValue   = document.couponForm.telefono.value;
    	var emailValue 		= document.couponForm.email.value;
    	var testoValue 		= document.couponForm.testo.value;
    	var privacyValue 	= getCheckedValue(document.couponForm.privacy);
        var emailck 	    = getCheckedValue(document.couponForm.emailck);
        var smsck           = getCheckedValue(document.couponForm.smsck);

        var body;
        var to;
        var from;
        var showAlert = false;
    	  if (nomeValue == '') {
    	  	showAlert = true;
    		document.couponForm.nome.focus();
    	  } else if (cognomeValue == '') {
    	  	showAlert = true;
    		document.couponForm.cognome.focus();
    	  } else if (cityValue == '') {
    	    showAlert = true;
    	    document.couponForm.city.focus();
          } else if (telefonoValue == '') {
    	  	showAlert = true;
    		document.couponForm.telefono.focus();
    	  } else if (emailValue == '') {
    	  	showAlert = true;
    		document.couponForm.email.focus();
    	  } else if (testoValue == '') {
    	  	showAlert = true;
    		document.couponForm.testo.focus();
    	  }

    	  if (showAlert) {
    		alert("Hai omesso uno o più campi obbligatori. ");
    	  } else if (privacyValue != 'si') {
    		alert("Devi autorizzare il trattamento dei dati personali. ");
    	  } else if (isValidEmailAddrs(emailValue)) {
          to = "JLD"
          //to = "Prova";
        	from = nomeValue + " " + cognomeValue;
        		body =
					    "\r\n\r\n================== INFO UTENTE ==================" +
					    "\r\n Nome:       " + nomeValue +
    					"\r\n Cognome:    " + cognomeValue +
                        "\r\n Città:      " + cityValue +
    					"\r\n Telfono:    " + telefonoValue +
    					"\r\n E-mail:     " + emailValue +
                        "\r\n Mailing:    " + emailck +
                        "\r\n Sms:        " + smsck +
    					"\r\n=====================================================\r\n" +
    					"\r\n\r\n\r\n Testo:\r\n" + testoValue;
                        showSendMailDlgBox(to, from, "Corani & partners - Contatto da web", body, emailValue, nomeValue, cognomeValue, telefonoValue, emailck, smsck);
    	  } else {
    		alert("Hai scritto l'indirizzo di posta elettronica in modo errato.");
    		document.couponForm.email.select();
    		document.couponForm.email.focus();
    	  }
    }

  	function showSendMailDlgBox(to, from, subject, body, email, nomeValue, cognomeValue, telefonoValue, emailck, smsck) {
  	  oCopy     = 1;
  	  oTo       = to;
  	  oFrom     = from;
  	  oSubject  = subject;
  	  oBody     = body;
  	  oEmail    = email;
      oNome     = nomeValue;
      oCognome  = cognomeValue;
      oTelefono = telefonoValue;
      oEmailck  = emailck;
      oSmsck    = smsck;

  	  openBrWindow("dlgbox-sendmail.htm", "sendMailDlgBoxWin", "width=280,height=165");
  	}

    function registrazione() {
        document.getECLocalitaForm.GB_TYPER.value = "CREATTIVA_REGISTRAZIONE";
        document.getECLocalitaForm.submit();
    }

    function cambiaRegione() {
        var regione = document.validateForm.Regione.value;
        if (regione != "") {
            modificaProvincia(regione,"");
        }
    }

    function cambiaProvincia() {
        var regione     = document.validateForm.Regione.value;
        var idprovincia   = document.validateForm.Provincia.value;
        if (idprovincia != "") {
            modificaProvincia(regione,idprovincia);
        }
    }

    function modificaProvincia(regione,provincia) {
        document.getECLocalitaForm.GB_TYPER.value   = "CREATTIVA_REGISTRAZIONE";
        document.getECLocalitaForm.regione.value    = regione;
        document.getECLocalitaForm.provincia.value  = provincia;
        document.getECLocalitaForm.field1.value     = document.validateForm.Nome.value;
        document.getECLocalitaForm.field2.value     = document.validateForm.Cognome.value;
        document.getECLocalitaForm.field3.value     = document.validateForm.Email.value;
        document.getECLocalitaForm.field4.value     = document.validateForm.ConfirmEmail.value;
        document.getECLocalitaForm.field5.value     = document.validateForm.Password.value;
        document.getECLocalitaForm.field6.value     = document.validateForm.DataNascita.value;
        document.getECLocalitaForm.field7.value     = document.validateForm.Indirizzo.value;
        document.getECLocalitaForm.field8.value     = document.validateForm.Cap.value;
        document.getECLocalitaForm.field9.value     = document.validateForm.Telefono.value;
        document.getECLocalitaForm.field10.value    = document.validateForm.pIva.value;
        document.getECLocalitaForm.submit();
    }

    function cambiaProfiloRegione() {
        var regione = document.validateForm.Regione.value;
        if (regione != "") {
            modificaProfiloProvincia(regione,"");
        }
    }

    function cambiaProfiloProvincia() {
        var regione     = document.validateForm.Regione.value;
        var idprovincia   = document.validateForm.Provincia.value;
        if (idprovincia != "") {
            modificaProfiloProvincia(regione,idprovincia);
        }
    }

    function modificaProfiloProvincia(regione,provincia) {
        document.getECLocalitaForm.GB_TYPER.value   = "CREATTIVA_MODIFICA";
        document.getECLocalitaForm.regione.value    = regione;
        document.getECLocalitaForm.provincia.value  = provincia;
        document.getECLocalitaForm.field1.value     = document.validateForm.Nome.value;
        document.getECLocalitaForm.field2.value     = document.validateForm.Cognome.value;
        document.getECLocalitaForm.field3.value     = document.validateForm.Email.value;
        document.getECLocalitaForm.field4.value     = document.validateForm.ConfirmEmail.value;
        document.getECLocalitaForm.field5.value     = document.validateForm.Password.value;
        document.getECLocalitaForm.field6.value     = document.validateForm.DataNascita.value;
        document.getECLocalitaForm.field7.value     = document.validateForm.Indirizzo.value;
        document.getECLocalitaForm.field8.value     = document.validateForm.Cap.value;
        document.getECLocalitaForm.field9.value     = document.validateForm.Telefono.value;
        document.getECLocalitaForm.field10.value    = document.validateForm.pIva.value;
        document.getECLocalitaForm.submit();
    }

    function cambiaIndirizzoRegione() {
        var regione = document.validateForm.Regione.value;
        if (regione != "") {
            modificaIndirizzoProvincia(regione,"");
        }
    }

    function cambiaIndirizzoProvincia() {
        var regione     = document.validateForm.Regione.value;
        var idprovincia   = document.validateForm.Provincia.value;
        if (idprovincia != "") {
            modificaIndirizzoProvincia(regione,idprovincia);
        }
    }

    function modificaIndirizzoProvincia(regione,provincia) {
        document.getECLocalitaForm.GB_TYPER.value   = "CREATTIVA_NUOVOINDIRIZZO";
        document.getECLocalitaForm.regione.value    = regione;
        document.getECLocalitaForm.provincia.value  = provincia;
        document.getECLocalitaForm.field1.value     = document.validateForm.NomeSede.value;
        document.getECLocalitaForm.field7.value     = document.validateForm.Indirizzo.value;
        document.getECLocalitaForm.field8.value     = document.validateForm.Cap.value;
        document.getECLocalitaForm.submit();
    }

//----------------------------------------------------------------------------------------------------
// Funzione registrazione
//----------------------------------------------------------------------------------------------------

function doOk(){

    var privacyValue 	= getCheckedValue(document.validateForm.privacy);
    var emailck 	    = getCheckedValue(document.validateForm.emailck);
    var smsck           = getCheckedValue(document.validateForm.smsck);

		if(validateForm()){
			document.insertECommerceUserForm.email.value            = document.validateForm.Email.value;
			document.insertECommerceUserForm.password.value         = document.validateForm.Password.value;
			document.insertECommerceUserForm.confirmPassword.value  = document.validateForm.ConfirmPassword.value;
			document.insertECommerceUserForm.nome.value             = document.validateForm.Nome.value;
			document.insertECommerceUserForm.cognome.value          = document.validateForm.Cognome.value;
			document.insertECommerceUserForm.dataNascita.value      = document.validateForm.DataNascita.value;
			document.insertECommerceUserForm.telefono.value         = document.validateForm.Telefono.value;
			document.insertECommerceUserForm.indirizzo.value        = document.validateForm.Indirizzo.value;
			document.insertECommerceUserForm.provincia.value        = document.validateForm.Provincia.value;
			document.insertECommerceUserForm.cap.value              = document.validateForm.Cap.value;
			document.insertECommerceUserForm.localita.value         = document.validateForm.Localita.value;
			document.insertECommerceUserForm.nazione.value          = document.validateForm.Nazione.value;
			//document.insertECommerceUserForm.note.value             = document.validateForm.Note.value;
    	    //document.insertECommerceUserForm.numBadge.value         = document.validateForm.Badge.value;
        if (validatePIVaCodFiscale()) {
            var codFpIva = document.validateForm.pIva.value;
            if(codFpIva.length == 11) {
                document.insertECommerceUserForm.pIva.value   = codFpIva;
            } else {
                document.insertECommerceUserForm.codFiscale.value         = codFpIva;
            }
        } else {
            return;
        }
            if (privacyValue != 'si') {
    		    alert("Devi autorizzare il trattamento dei dati personali.");
    		} else {
                if (document.layers)
    	  	  	    document.captureEvents(Event.MOUSEDOWN | Event.CLICK);
      	  	     	document.onmousedown = document.onclick = function (evt) {
          	        return false;
        	  	 }

                if(parent.frames['storeBasket']) {
                    var aclUser = document.validateForm.Email.value;
                    parent.frames['storeBasket'].location.href = "_creattivaSmsEmail.jsp?aclUser=" + aclUser + "&flagEmail=" + emailck + "&flagSms=" + smsck;
                }

                 var indirizzoCV = document.validateForm.Indirizzo.value + " " + document.validateForm.NCivico.value;
                 document.insertECommerceUserForm.indirizzo.value = indirizzoCV;
              	 document.insertECommerceUserForm.submit();

        }
    }
}

function doOk2(){
	if(validateForm()){
	    document.updateECommerceUserForm.password.value         = document.validateForm.Password.value;
		document.updateECommerceUserForm.confirmPassword.value  = document.validateForm.ConfirmPassword.value;
		document.updateECommerceUserForm.nome.value             = document.validateForm.Nome.value;
		document.updateECommerceUserForm.cognome.value          = document.validateForm.Cognome.value;
		document.updateECommerceUserForm.dataNascita.value    = document.validateForm.DataNascita.value;
		document.updateECommerceUserForm.telefono.value         = document.validateForm.Telefono.value;
		document.updateECommerceUserForm.indirizzo.value        = document.validateForm.Indirizzo.value;
		document.updateECommerceUserForm.provincia.value        = document.validateForm.Provincia.value;
		document.updateECommerceUserForm.cap.value              = document.validateForm.Cap.value;
		document.updateECommerceUserForm.localita.value         = document.validateForm.Localita.value;
		document.updateECommerceUserForm.nazione.value          = document.validateForm.Nazione.value;
		//document.updateECommerceUserForm.note.value           = document.validateForm.Note.value;
        //document.updateECommerceUserForm.numBadge.value       = document.validateForm.Badge.value;
        if (validatePIVaCodFiscale()) {
            var codFpIva = document.validateForm.pIva.value;
            if(codFpIva.length == 11) {
                document.updateECommerceUserForm.pIva.value   = codFpIva;
            } else {
                document.updateECommerceUserForm.codFiscale.value         = codFpIva;
            }
            document.updateECommerceUserForm.submit();
        }
    }
}

function doOkFornitore(){
	if(validateForm()){
        document.updateECommerceAdminForm.emailGenerale.value   = document.validateForm.Email.value;
        document.updateECommerceAdminForm.password.value        = document.validateForm.Password.value;
				document.updateECommerceAdminForm.emailOrdini.value     = document.validateForm.EmailOrdini.value;
				document.updateECommerceAdminForm.emailClienti.value    = document.validateForm.EmailClienti.value;
				document.updateECommerceAdminForm.submit();
	}
}

function updatePassword(){
    if(validateForm()){
	    document.modificaAdminPasswordForm.password.value           = document.validateForm.Password.value;
	    document.modificaAdminPasswordForm.confirmPassword.value    = document.validateForm.ConfirmPassword.value;
	    document.modificaAdminPasswordForm.submit();
    }
}

function validateUser(){
    document.validateForm.user.value        = document.logonForm.userTextCtrl.value;
    document.validateForm.password.value    = document.logonForm.passwordCtrl.value;
    document.validateForm.submit();
}

function logout(){
    top.location.href="logout.jsp"
}

function completaPagamento() {
    var metodiPagamRadio = document.forms['configPagForm'].elements['METODOPAGAM'];

    var metodoPagam = null;
    if (!metodiPagamRadio) {
        alert("Nessun metodo di pagamento disponibile!\r\nImpossibile completare l'ordine.");
        return;
    } else if (metodiPagamRadio.length) {
        metodoPagam = getCheckedRadioCtrlValue(metodiPagamRadio);
    } else {
        metodoPagam = metodiPagamRadio.value;
    }

    if (metodoPagam == null) {
        alert("Nessun metodo di pagamento selezionato!\r\nEffettuare una selezione per completare l'ordine.");
        return;
    }

    var goForm = null;
    var goMeto = "";
    if (metodoPagam == 'CONTRAS') {
      // Pagamento in contrassegno
        goForm = document.forms['fCOrdine'];
        goForm.modoDiPagamento.value = "CONTRAS";
        goMeto = "makeOrdineECommerce"
    } else if (metodoPagam == 'BPW') {
     	// Pagamento BankPass Web
     	  goForm = document.forms['fCOrdine'];
          goForm.modoDiPagamento.value = "BPW";
          goMeto = "makeOrdineECommerceBPW"
    } else {
     	// Metodo di pagamento non riconosciuto
     	  alert("Metodo di pagamento sconosciuto o non supportato!");
     	  return;
    }

    if (goForm != null) {
        goForm.GB_METHOD.value = goMeto;
        goForm.submit();
       	if (document.layers) {
       	    document.captureEvents(Event.MOUSEDOWN | Event.CLICK);
      	}
      	document.onmousedown = document.onclick = function (evt) { return false; }
  	}
}

function updateFlagSmsEmail() {
    if(parent.frames['storeBasket']) {
        parent.frames['storeBasket'].location.href = "_updateFlagSmsEmail.jsp";
    }
}

function goBankWeb() {
    if (document.layers) {
   	    document.captureEvents(Event.MOUSEDOWN | Event.CLICK);
  	}
    document.onmousedown = document.onclick = function (evt) { return false; }
    document.forms['bpwform'].submit();
}
