﻿// JScript File
function apriContatti(richiesta){
    var myWin = window.open ('popContatti.aspx?richiesta=' + richiesta,'mywincont','width=305,height=420');

}

function selectedRadio(radiogroup){
    for(i=0;i<radiogroup.length;i++){
    if(radiogroup[i].checked) return i;
    }
}


function selezionaDdlByDdl(ddl1,ddl2id){
    var ddl2 = document.getElementById(ddl2id);
    if(ddl2 && ddl1){
        ddl2.selectedIndex = ddl1.selectedIndex;
    }
}

function isPwd(str){
  var r1 = new RegExp("(\\w{6,12}$)");
  if(str.length>12){
  return false
  }else{
  return (r1.test(str));
  }
}

//verifica se una data è corretta o meno
function isDate(dateStr) {
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
    if (matchArray == null) {
        return false;
    }
    month = matchArray[3];
    day = matchArray[1];
    year = matchArray[5];
    if (month < 1 || month > 12) {
        return false;
    }
    if (day < 1 || day > 31) {
        return false;
    }
    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        return false;
    }
    if (month == 2) {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            return false;
        }
    }
    return true;
}


function isEmail(str) {
  var supported = 0;
  if(window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) supported = 1;
  }
  if(!supported)
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
			
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function validaRichiestaCard(theContainer,theLng)
{
    theContainer = theContainer + "_";
    var errore = false;
    var msg = "";
    if(theLng=='en'){
        msg = "Sorry we can\'t process your request. Errors were found in your data: ";
    }else{
        msg = "Sono presenti degli errori nel modulo: ";
    }
    var currFld='';
    
    
    /*nome*/
    currFld = document.getElementById(theContainer + "txtNome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your FIRST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo NOME";
            }
        }
    }

    /*cognome*/
    currFld = document.getElementById(theContainer + "txtCognome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your LAST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo COGNOME";
            }
        }
    }


    /*indirizzo*/
    currFld = document.getElementById(theContainer + "txtIndirizzo");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your ADDRESS";
            }else{
                msg = msg + "\n - inserisci il tuo INDIRIZZO";
            }
        }
    }

    /*citta*/
    currFld = document.getElementById(theContainer + "txtCitta");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your CITY";
            }else{
                msg = msg + "\n - inserisci la tua CITTA";
            }
        }
    }


    /*provincia*/
    currFld = document.getElementById(theContainer + "txtProvincia");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your PROVINCE or STATE";
            }else{
                msg = msg + "\n - inserisci la tua PROVINCIA";
            }
        }
    }
    
    /*email*/
    currFld = document.getElementById(theContainer + "txtEmail");
    if(currFld){
        if(!isEmail(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid EMAIL ADDRESS";
            }else{
                msg = msg + "\n - inserisci un INDIRIZZO EMAIL valido";
            }
        }
    }

    /*privacy*/
    //currFld = document.getElementById(theContainer + "chkCondizioni");
    currFld = document.getElementById(theContainer + "chkPrivacy");

    if(currFld){
        if(!currFld.checked){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please accept PRIVACY STATEMENT";
            }else{
                msg = msg + "\n - devi accettare la nostra politica sula PRIVACY";
            }
        }
    }





    /*condizioni*/
    currFld = document.getElementById(theContainer + "chkCondizioni");

    if(!currFld){
        if(currFld.checked){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please accept USAGE CONDITIONS";
            }else{
                msg = msg + "\n - devi accettare le condizioni di utilizzo";
            }
        }
    }


    if(errore){
        alert(msg);
        return false;
    }else{
        return true;
    }         


}




function validaFranchising(theContainer,theLng)
{
    theContainer = theContainer + "_";
    var errore = false;
    var msg = "";
    if(theLng=='en'){
        msg = "Sorry we can\'t process your request. Errors were found in your data: ";
    }else{
        msg = "Sono presenti degli errori nel modulo: ";
    }
    var currFld='';
    
    
    /*nome*/
    currFld = document.getElementById(theContainer + "txtNome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your FIRST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo NOME";
            }
        }
    }

    /*cognome*/
    currFld = document.getElementById(theContainer + "txtCognome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your LAST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo COGNOME";
            }
        }
    }


    /*indirizzo*/
    currFld = document.getElementById(theContainer + "txtIndirizzo");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your ADDRESS";
            }else{
                msg = msg + "\n - inserisci il tuo INDIRIZZO";
            }
        }
    }

    /*citta*/
    currFld = document.getElementById(theContainer + "txtCitta");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your CITY";
            }else{
                msg = msg + "\n - inserisci la tua CITTA";
            }
        }
    }


    /*provincia*/
    currFld = document.getElementById(theContainer + "txtProvincia");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your PROVINCE or STATE";
            }else{
                msg = msg + "\n - inserisci la tua PROVINCIA";
            }
        }
    }
    
    /*email*/
    currFld = document.getElementById(theContainer + "txtEmail");
    if(currFld){
        if(!isEmail(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid EMAIL ADDRESS";
            }else{
                msg = msg + "\n - inserisci un INDIRIZZO EMAIL valido";
            }
        }
    }

    /*privacy*/
    //currFld = document.getElementById(theContainer + "chkCondizioni");
    currFld = document.getElementById(theContainer + "chkPrivacy");

    if(currFld){
        if(!currFld.checked){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please accept PRIVACY STATEMENT";
            }else{
                msg = msg + "\n - devi accettare la nostra politica sula PRIVACY";
            }
        }
    }


    if(errore){
        alert(msg);
        return false;
    }else{
        return true;
    }         


}



function validaLavora(theContainer,theLng)
{
    theContainer = theContainer + "_";
    var errore = false;
    var msg = "";
    if(theLng=='en'){
        msg = "Sorry we can\'t process your request. Errors were found in your data: ";
    }else{
        msg = "Sono presenti degli errori nel modulo: ";
    }
    var currFld='';
    
    /*profilo prof*/
    currFld = document.getElementById(theContainer + "ddlProfiloProfessionale");
    if(currFld){
        if(currFld.selectedIndex<=0){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please select your job profile";
            }else{
                msg = msg + "\n - seleziona il tuo PROFILO PROFESSIONALE";
            }
        }
    }
    
    
    /*nome*/
    currFld = document.getElementById(theContainer + "txtNome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your FIRST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo NOME";
            }
        }
    }

    /*cognome*/
    currFld = document.getElementById(theContainer + "txtCognome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your LAST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo COGNOME";
            }
        }
    }


    /*indirizzo*/
    currFld = document.getElementById(theContainer + "txtIndirizzo");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your ADDRESS";
            }else{
                msg = msg + "\n - inserisci il tuo INDIRIZZO";
            }
        }
    }

    /*citta*/
    currFld = document.getElementById(theContainer + "txtCitta");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your CITY";
            }else{
                msg = msg + "\n - inserisci la tua CITTA";
            }
        }
    }


    /*provincia*/
    currFld = document.getElementById(theContainer + "txtProvincia");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your PROVINCE or STATE";
            }else{
                msg = msg + "\n - inserisci la tua PROVINCIA";
            }
        }
    }
    
    /*email*/
    currFld = document.getElementById(theContainer + "txtEmail");
    if(currFld){
        if(!isEmail(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid EMAIL ADDRESS";
            }else{
                msg = msg + "\n - inserisci un INDIRIZZO EMAIL valido";
            }
        }
    }

    /*privacy*/
    //currFld = document.getElementById(theContainer + "chkCondizioni");
    currFld = document.getElementById(theContainer + "chkPrivacy");

    if(currFld){
        if(!currFld.checked){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please accept PRIVACY STATEMENT";
            }else{
                msg = msg + "\n - devi accettare la nostra politica sula PRIVACY";
            }
        }
    }


    if(errore){
        alert(msg);
        return false;
    }else{
        return true;
    }         


}


/*validazione dati cliente*/
function validaDatiCliente(theContainer,theLng)
{
    theContainer = theContainer + "_";
    var errore = false;
    var msg = "";
    if(theLng=='en'){
        msg = "Sorry we can\'t process your request. Errors were found in your data: ";
    }else{
        msg = "Sono presenti degli errori nel modulo: ";
    }
    var currFld='';
    
    /*nome*/
    currFld = document.getElementById(theContainer + "tb_clienteNome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your FIRST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo NOME";
            }
        }
    }

    /*cognome*/
    currFld = document.getElementById(theContainer + "tb_clienteCognome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your LAST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo COGNOME";
            }
        }
    }

    
    /*email*/
    currFld = document.getElementById(theContainer + "tb_clienteEmail");
    if(currFld){
        if(!isEmail(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid EMAIL ADDRESS";
            }else{
                msg = msg + "\n - inserisci un INDIRIZZO EMAIL valido";
            }
        }
    }

    /*privacy*/
    //currFld = document.getElementById(theContainer + "chkCondizioni");
    currFld = document.getElementById(theContainer + "chkPrivacy");

    if(currFld){
        if(!currFld.checked){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please accept PRIVACY STATEMENT";
            }else{
                msg = msg + "\n - devi accettare la nostra politica sula PRIVACY";
            }
        }
    }


//pagamento
    if (selectedRadio(document.forms[0]["ctl00$ContentPlaceHolder1$radio_clientePagamento"])==undefined)
    {
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please choose one payment type";
            }else{
                msg = msg + "\n - devi selezionare una forma di PAGAMENTO";
            }
    
    }
    


    //currFld = document.getElementById(theContainer + "chkCondizioni");
    currFld = document.getElementById(theContainer + "chkAvvertenze");

    if(currFld){
        if(!currFld.checked){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please accept RENTAL AGREEMENT";
            }else{
                msg = msg + "\n - devi accettare le condizioni qui riportate";
            }
        }
    }


    if(errore){
        alert(msg);
        return false;
    }else{
        return true;
    }         

}


function validaRegistrazione(theContainer,theLng)
{
    theContainer = theContainer + "_";
    var errore = false;
    var msg = "";
    if(theLng=='en'){
        msg = "Sorry we can\'t process your request. Errors were found in your data: ";
    }else{
        msg = "Sono presenti degli errori nel modulo: ";
    }
    var currFld='';
    
    
    /*email*/
    currFld = document.getElementById(theContainer + "txtEmail");
    if(currFld){
        if(!isEmail(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid EMAIL ADDRESS";
            }else{
                msg = msg + "\n - inserisci un INDIRIZZO EMAIL valido";
            }
        }
    }
    
    /*password*/
    currFld = document.getElementById(theContainer + "txtPassword");
    if(currFld){
        if(!isPwd(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid PASSWORD (6-12 characters)";
            }else{
                msg = msg + "\n - inserisci una PASSWORD valida (da 6 a 12 caratteri)";
            }
        }else{
            currFld2 = document.getElementById(theContainer + "txtPassword2");
            if(currFld2){
                if(currFld.value!=currFld2.value){
                    errore = true;
                    if(theLng=='en'){
                         msg = msg + "\n - CONFIRM PASSWORD does not match PASSWORD";
                    }else{
                        msg = msg + "\n - le 2 PASSWORD inserite sono differenti";
                    }
                }
                
            }
        
        }
    }



    /*nome*/
    currFld = document.getElementById(theContainer + "txtNome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your FIRST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo NOME";
            }
        }
    }

    /*cognome*/
    currFld = document.getElementById(theContainer + "txtCognome");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your LAST NAME";
            }else{
                msg = msg + "\n - inserisci il tuo COGNOME";
            }
        }
    }


    /*indirizzo*/
    currFld = document.getElementById(theContainer + "txtIndirizzo");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your ADDRESS";
            }else{
                msg = msg + "\n - inserisci il tuo INDIRIZZO";
            }
        }
    }


    /*indirizzo*/
    currFld = document.getElementById(theContainer + "txtCap");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your ZIP CODE";
            }else{
                msg = msg + "\n - inserisci il tuo CAP";
            }
        }
    }


    /*citta*/
    currFld = document.getElementById(theContainer + "txtCitta");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your CITY";
            }else{
                msg = msg + "\n - inserisci la tua CITTA";
            }
        }
    }


    /*provincia*/
    currFld = document.getElementById(theContainer + "txtProvincia");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your PROVINCE or STATE";
            }else{
                msg = msg + "\n - inserisci la tua PROVINCIA";
            }
        }
    }
    
    /*data nascita*/
    currFld = document.getElementById(theContainer + "txtDataNascita");
    if(currFld){
        if(currFld.value=='' || !isDate(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid DATE OF BIRTH";
            }else{
                msg = msg + "\n - inserisci una DATA DI NASCITA valida";
            }
        }
    }


    /*luogo di nascita*/
    currFld = document.getElementById(theContainer + "txtLuogoNascita");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your CITY OF BIRTH";
            }else{
                msg = msg + "\n - inserisci la tua CITTA' DI NASCITA";
            }
        }
    }


    /*telefono*/
    currFld = document.getElementById(theContainer + "txtTelefono");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your TELEPHONE NUMBER";
            }else{
                msg = msg + "\n - inserisci il NUMERO DI TELEFONO";
            }
        }
    }

   /*n patente*/
    currFld = document.getElementById(theContainer + "txtNumeroPatente");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your DIVER LICENSE NUMBER";
            }else{
                msg = msg + "\n - inserisci il NUMERO DI PATENTE";
            }
        }
    }
    
       /*n patente*/
    currFld = document.getElementById(theContainer + "txtLuogoPatente");
    if(currFld){
        if(currFld.value==''){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter your DIVER LICENSE ISSUING LOCATION";
            }else{
                msg = msg + "\n - inserisci il LUOGO DI RILASCIO DELLA PATENTE";
            }
        }
    }
    
    
    /*data rilascio patente*/
    currFld = document.getElementById(theContainer + "txtDataRilascioPatente");
    if(currFld){
        if(currFld.value=='' || !isDate(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid DIVER LICENSE ISSUING DATE";
            }else{
                msg = msg + "\n - inserisci una DATA DI EMISSIONE DELLA PATENTE valida";
            }
        }
    }

    /*data rilascio patente*/
    currFld = document.getElementById(theContainer + "txtDataScadenzaPatente");
    if(currFld){
        if(currFld.value=='' || !isDate(currFld.value)){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please enter a valid DIVER LICENSE EXPIRY DATE";
            }else{
                msg = msg + "\n - inserisci una DATA DI SCADENZA DELLA PATENTE valida";
            }
        }
    }

    /*privacy*/
    //currFld = document.getElementById(theContainer + "chkCondizioni");
    currFld = document.getElementById(theContainer + "chkPrivacyReg");

    if(currFld){
        if(!currFld.checked){
            errore = true;
            if(theLng=='en'){
                 msg = msg + "\n - please accept PRIVACY STATEMENT";
            }else{
                msg = msg + "\n - devi accettare la nostra politica sula PRIVACY";
            }
        }
    }


    if(errore){
        alert(msg);
        return false;
    }else{
        return true;
    }         


}

