var strMsg="";

var agent=navigator.userAgent;

var opera=agent.indexOf("Opera")>-1;

var curSelectedSubject="";



function selectSubject(objForm)

{

    curSelectedSubject = objForm.options[objForm.selectedIndex].value;

}





function showErrorMessage(strTxt)

{

    alert(strTxt);

}



/*

function hideLayers(divName){

    if(document.all && !opera)

    {

        document.all[divName].innerHTML = "";

        document.all[divName].style.visibility="hidden";

    }

    if(document.getElementById && !document.all && !opera)

    {

        document.getElementById(divName).style.visibility="hidden";

    }

    if(document.layers)

    {

        document.ns4errorLyr.document.ns4errorLyr2.document.write("");

        document.ns4errorLyr.document.ns4errorLyr2.document.close();

    }

}

*/





function takeCount(objForm) {

    prev = 140-objForm.message.value.length;

    if(objForm.message.value.length<=140)

    {

        objForm.counter.value= prev;

        msg140=objForm.message.value.substring(0,140);

    }

    else

    {

        objForm.message.value=msg140;

    }

}









function trim(inputString) {

    // Removes leading and trailing spaces from the passed string. Also removes

    // consecutive spaces and replaces it with one space. If something besides

    // a string is passed in (null, custom object, etc.) then return the input.

    if (typeof inputString != "string") { return inputString; }

    var retValue = inputString;

    var ch = retValue.substring(0, 1);

    while (ch == " ") { // Check for spaces at the beginning of the string

        retValue = retValue.substring(1, retValue.length);

        ch = retValue.substring(0, 1);

    }

    ch = retValue.substring(retValue.length-1, retValue.length);

    while (ch == " ") { // Check for spaces at the end of the string

        retValue = retValue.substring(0, retValue.length-1);

        ch = retValue.substring(retValue.length-1, retValue.length);

    }

    while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string

        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings

    }

    //alert("-"+retValue+"-");

    return retValue; // Return the trimmed string back to the user

} // Ends the "trim" function













function isValidAlternativePhoneNumber(field)

{

    // checks if the phone number is valid

    var phoneStr = trim(field);

    var phonePat = /^((\+)?[0-9]*)([0-9])$/;

    var matchArray = phoneStr.match(phonePat);

    if (matchArray == null) {

        return false;

    }

    return true;

}



function isValidNumber(field)

{

    //var NoSpaceNumber= trim(field.value);

    var valid = "0123456789";

    var temp;

    for (var index=0; index<field.value.length; index++){

        temp ="" + field.value.substring(index,index+1);

        //alert("+"+temp+"+");

        if (valid.indexOf(temp)=="-1")   return false;

    }

    return true;

}



function beforeSubmit_TopUp()
{
      document.formDati.targetMsisdn.value        = trim(document.formDati.targetMsisdn.value);
      document.formDati.targetMsisdnConfirm.value = trim(document.formDati.targetMsisdnConfirm.value);
      document.formDati.voucherCode.value         = trim(document.formDati.voucherCode.value);

      targetMsisdn        = document.formDati.targetMsisdn.value;
      targetMsisdnConfirm = document.formDati.targetMsisdnConfirm.value;
      voucherCode         = document.formDati.voucherCode.value;

      if ( (targetMsisdn == "") && (targetMsisdnConfirm == "") )
      {
          strMsg = errorMessage["ERROR_voucherRecharg_msisdn_1"];
          showErrorMessage(strMsg);
      }
      else if ( targetMsisdn == "" )
      {
          strMsg = errorMessage["ERROR_voucherRecharg_msisdn_2"];
          showErrorMessage(strMsg);
      }
      else if ( !isValidNumber(document.formDati.targetMsisdn) )
      {
          strMsg = errorMessage["ERROR_voucherRecharg_msisdn_4"];
          showErrorMessage(strMsg);
      }
      else if ( targetMsisdnConfirm == "" )
      {
          strMsg = errorMessage["ERROR_voucherRecharg_msisdn_3"];
          showErrorMessage(strMsg);
      }
      else if ( !isValidNumber(document.formDati.targetMsisdnConfirm) )
      {
      	strMsg = errorMessage["ERROR_voucherRecharg_msisdn_5"];
      	showErrorMessage(strMsg);
      }
      else if ( targetMsisdn != targetMsisdnConfirm )
      {
          strMsg = errorMessage["ERROR_voucherRecharg_msisdn_0"];
          showErrorMessage(strMsg);
      }
      else if ( voucherCode == "" )
      {
          strMsg = errorMessage["ERROR_voucherRecharg_secretCode_0"];
          showErrorMessage(strMsg);
      }
      else if ( voucherCode.length != 16 )
      {
          strMsg = errorMessage["ERROR_voucherRecharg_secretCode_1"];
          showErrorMessage(strMsg);
      }
      else if ( !isValidNumber(document.formDati.voucherCode) )
      {
          strMsg = errorMessage["ERROR_voucherRecharg_secretCode_2"];
          showErrorMessage(strMsg);
      }
      else
      {
         // hideLayers("errorLyr");
          document.formDati.submit();
      }
  }



function beforeSubmit_ContactInfo(){

    document.formDati.alternativePhoneNumber.value = trim(document.formDati.alternativePhoneNumber.value);

    document.formDati.alternativeEmailAddress.value = trim(document.formDati.alternativeEmailAddress.value);

    if(document.formDati.alternativePhoneNumber.value=="" || document.formDati.alternativePhoneNumber.value==null)

    {

        strMsg = errorMessage["ERROR_savePersonalData_alternativePhoneNumber_0"];

        showErrorMessage(strMsg);

    }

    else if(!isValidAlternativePhoneNumber(document.formDati.alternativePhoneNumber.value))

    {

        strMsg = errorMessage["ERROR_savePersonalData_alternativePhoneNumber_1"];

        showErrorMessage(strMsg);

    }

    else if(document.formDati.alternativeEmailAddress.value=="" || document.formDati.alternativeEmailAddress.value==null)

    {

        strMsg = errorMessage["ERROR_savePersonalData_alternativeEmailAddress_0"];

        showErrorMessage(strMsg);

    }

    else if (!emailCheck(document.formDati.alternativeEmailAddress.value)){

        strMsg = errorMessage["ERROR_savePersonalData_alternativeEmailAddress_1"];

        showErrorMessage(strMsg);

    }

    else

    {

//        hideLayers("errorLyr");

        document.formDati.submit();

    }

}





function beforeSubmit_ContactUs(){



    if(document.layers)

    {

        selectedSubject = curSelectedSubject;

    }

    else

    {

        selectedSubject = document.formDati.subject.value;

    }



    if(selectedSubject=="")

    {

        strSbj = errorMessage["ERROR_mailContact_subject_0"];

        showErrorMessage(strSbj);

    }



    else if(document.formDati.mailBody.value=="")

    {

        strMsg = errorMessage["ERROR_mailContact_mailBody_0"];

        showErrorMessage(strMsg);

    }



    else if(document.formDati.mailBody.value.length>=500)

    {

        strMsg = errorMessage["ERROR_mailContact_mailBody_1"];

        showErrorMessage(strMsg);

    }



    else if (selectedSubject!="" && document.formDati.mailBody.value!="")

    {

//        hideLayers("errorLyr");

        document.formDati.submit();

    }

}







function controlerStyle()

{

    alert(document.all.errorLyr.style.visibility);

}









function beforeSubmit_H3GNumbers()
{
    document.formDati.msisdnPrefix.value = trim(document.formDati.msisdnPrefix.value);
    document.formDati.msisdnNumber.value = trim(document.formDati.msisdnNumber.value);

    if(document.formDati.msisdnPrefix.value=="" && document.formDati.msisdnNumber.value=="")
    {
        strMsg = errorMessage["ERROR_h3GNumbers_msisdn_0"];
        showErrorMessage(strMsg);
    }
    else if(document.formDati.msisdnPrefix.value=="" || document.formDati.msisdnPrefix.value==null)
    {
        strMsg = errorMessage["ERROR_h3GNumbers_msisdnPrefix_0"];
        showErrorMessage(strMsg);
    }
    else if(!isValidNumber(document.formDati.msisdnPrefix))
    {
        strMsg = errorMessage["ERROR_h3GNumbers_msisdnPrefix_1"];
        showErrorMessage(strMsg);
    }
    else if(document.formDati.msisdnPrefix.value.length != 3)
    {
             strMsg = errorMessage["ERROR_h3GNumbers_msisdnPrefix_2"];
             showErrorMessage(strMsg)
    }
    else if(document.formDati.msisdnNumber.value=="" || document.formDati.msisdnNumber.value==null)
    {
        strMsg = errorMessage["ERROR_h3GNumbers_msisdnNumber_0"];
        showErrorMessage(strMsg);
    }
    else if(!isValidNumber(document.formDati.msisdnNumber))
    {
        strMsg = errorMessage["ERROR_h3GNumbers_msisdnNumber_1"];
        showErrorMessage(strMsg);
    }
    else if(document.formDati.msisdnNumber.value.length < 5 || document.formDati.msisdnNumber.value.length > 7)
    {
             strMsg = errorMessage["ERROR_h3GNumbers_msisdnNumber_2"];
             showErrorMessage(strMsg)
    }
    else
    {
        //hideLayers("errorLyr");
        document.formDati.submit();
    }
}





var curstartDay="";

var curstartMonth="";

var curstartYear="";

var curendDay="";

var curendMonth="";

var curendYear="";





function leapYear(year)

{

    if (year % 4 == 0)

        return true;   // anno bisestile

    return false; // anno non bisestile

}



function getRigthDate(month,year)

{

    //alert(month+","+year)

    var ar = new Array(12);

    ar[0] = 31; // Gennaio

    ar[1] = (leapYear(year)) ? 29 : 28; // Febbraio

    ar[2] = 31; // Marzo

    ar[3] = 30; // Aprile

    ar[4] = 31; // Maggio

    ar[5] = 30; // Giugno

    ar[6] = 31; // Luglio

    ar[7] = 31; // Agosto

    ar[8] = 30; // Settembre

    ar[9] = 31; // Ottobre

    ar[10] = 30; // Novembre

    ar[11] = 31; // Dicembre

    return ar[month-1];

}





function selectTrafficSubject(objForm)

{

    i= objForm.selectedIndex;

    if(objForm.name=="startDay" && document.formDati.startDay.value!="")

    {

        curstartDay = objForm.options[i].value;

    }

    if(objForm.name=="startMonth" && document.formDati.startMonth.value!="")

    {

        curstartMonth = objForm.options[i].value;

    }






    if(objForm.name=="startYear" && document.formDati.startYear.value!=""){

        curstartYear = objForm.options[i].value;

    }

    if(objForm.name=="endDay" && document.formDati.endDay.value!="")

    {

        curendDay = objForm.options[i].value;

    }

    if(objForm.name=="endMonth" && document.formDati.endMonth.value!="")

    {

        curendMonth = objForm.options[i].value;

    }

    if(objForm.name=="endYear" && document.formDati.endYear.value!="")

    {

        curendYear = objForm.options[i].value;

    }

}



function suycDateDiff( start, end) {

    var iOut = 0;

    var bufferA = Date.parse( start ) ;

    var bufferB = Date.parse( end ) ;

    var number = bufferB-bufferA ;

    iOut = parseInt(number / 86400000) ;

    return iOut ;

}



function checkFormDate()

{

    var objForm = document.formDati;

    var curstartDay=objForm.startDay.options[objForm.startDay.selectedIndex].value;

    var curstartMonth=objForm.startMonth.options[objForm.startMonth.selectedIndex].value;

    var curstartYear=objForm.startYear.options[objForm.startYear.selectedIndex].value;

    var curendDay=objForm.endDay.options[objForm.endDay.selectedIndex].value;

    var curendMonth=objForm.endMonth.options[objForm.endMonth.selectedIndex].value;

    var curendYear=objForm.endYear.options[objForm.endYear.selectedIndex].value;

    var checkFolderDate = (curstartDay=="" || curstartMonth=="" || curstartYear=="" || curendDay=="" || curendMonth=="" || curendYear=="");



    // controllo che le date immesse siano formalmente esatte

    if( checkFolderDate==true )

    {

        strMsg = errorMessage["ERROR_checkTrafficItem_date_0"];

        showErrorMessage(strMsg);

    }

    else if( curstartDay > getRigthDate(curstartMonth,curstartYear ) )

    {

        strMsg = errorMessage["ERROR_checkTrafficItem_date_5"];

        showErrorMessage(strMsg);

    }

    else if ( curendDay > getRigthDate(curendMonth,curendYear) )

    {

        strMsg = errorMessage["ERROR_checkTrafficItem_date_6"];

        showErrorMessage(strMsg);

    }

    else

    {

        //controllo che i giorni di differenza fra il mese di inizio ricerca e quello di fine ricerca siano inferiori o uguali a 15 gg

        startDate=curstartMonth+"/"+curstartDay+"/"+curstartYear;

        endDate=curendMonth+"/"+curendDay+"/"+curendYear;

        dayDifference = suycDateDiff(startDate,endDate);

        if(dayDifference>15){

            //checkFolderDate=false;

            strMsg=errorMessage["ERROR_checkTrafficItem_date_1"];

            showErrorMessage(strMsg);

        }

        // controllo che le date immesse abbiano ordine cronologico esatto

        else if(dayDifference<0){

            //checkFolderDate=false;

            strMsg=errorMessage["ERROR_checkTrafficItem_date_2"];

            showErrorMessage(strMsg);

        }

        else

        {

            //hideLayers("errorLyr");

            document.formDati.submit();

        }

    }



}



function beforeSubmit_TrafficItems()

{

    checkFormDate();

}









function submitForm()

{



  document.forms.formDati.submit();



}









function popupMessageDetail()

{

	winpops = popupCenteredWindow('../jsp/contactus/scflPopupDeleteMessage.jsp', 300, 180, '');

}









function popupMessageList()

{

    if ( isChecked() )

    {

        popupList();

    }

    else

    {

    	strMsg = errorMessage["ERROR_messageRepository_0"];

        showErrorMessage(strMsg);

    }

}



function isChecked()

{

    if (document.formDati.elements["Msg_Sel"])

    {

        for (var i=0; i<document.formDati.Msg_Sel.length; i++)

        {

            if (document.formDati.Msg_Sel[i].checked == true) {

                return true;

            }

        }

        if ((document.formDati.elements.length == 1 ) && (document.formDati.Msg_Sel.checked == true))

        {

            return true;

        }

    }

    else

    {

            return false;

    }

}





function popupCenteredWindow(url, width, height, features)

{

	var left = Math.floor( (screen.width - width) / 2);

	var top = Math.floor( (screen.height - height) / 2);



	var winpops=window.open(url,"popupWindow","width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "," + features);



	if (parseInt(navigator.appVersion) >= 4) { winpops.window.focus(); }



	return winpops;

}









function popupLegalInformation()

{

	winpops = popupCenteredWindow('../jsp/subscriptions/scflPopupLegalInformation.jsp', 390, 500, 'scrollbars');

}







function submitFormList()

{

    document.forms.formDati.submit();

}



function popupList()

{

	winpops = popupCenteredWindow('../jsp/contactus/scflPopupDeleteMessageList.jsp', 300, 180, '');

}









function emailCheck(email)

{

	if ((navigator.appName.indexOf("Netscape")>-1) && (parseInt(navigator.appVersion) <= 4) )

	{

		var emailStr = trim(email);



    	var emailPat = /^([\!\#\$\%\&\'\*\+\-\/0-9\=\?A-Z\^\_\`a-z\{\|\}\~\.])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;



    	var matchArray = emailStr.match(emailPat);

    	if (matchArray == null) {

        	return false;

    	}



    	return true;

	}

	return IsMailAddress(email);

}







function goToDownloadPageFromPopup()

{

	window.opener.document.forms.formToDownloadPage.submit();

	window.close();

}



function IsMailAddress(email)
{
    var emailStr = trim(email);

    // checks if the e-mail address is valid
    var emailPat = /^([\!\#\$\%\&\'\*\+\-\/0-9\=\?A-Z\^\_\`a-z\{\|\}\~])+(([\.][\!\#\$\%\&\'\*\+\-\/0-9\=\?A-Z\^\_\`a-z\{\|\}\~]+)?)*@([\!\#\$\%\&\'\*\+\-\/0-9\=\?A-Z\^\_\`a-z\{\|\}\~])+(([\.][\!\#\$\%\&\'\*\+\-\/0-9\=\?A-Z\^\_\`a-z\{\|\}\~]+)*)$/;
    // var emailPat = /^([^\(\)\<\>\@\\[\],\;\:\\\.])+(([\.][^\(\)\<\>\@\\[\],\;\:\\\.]+)?)*@([^\(\)\<\>\@\\[\],\;\:\\\.])+(([\.][^\(\)\<\>\@\\[\],\;\:\\\.]+)?)$/;
    var matchArray = emailStr.match(emailPat);

    if (matchArray == null) {
        return false;
    }

    return true;
}


function Submit_Threshold()

{
    var objForm = document.formThreshold;
    var curDay=objForm.dayThreshold.options[objForm.dayThreshold.selectedIndex].value;
    var curMonth=objForm.monthThreshold.options[objForm.monthThreshold.selectedIndex].value;
    var curYear=objForm.yearThreshold.options[objForm.yearThreshold.selectedIndex].value;
    var checkFolderDate = (curDay=="" || curMonth=="" || curYear=="");

    // controllo che le date immesse siano formalmente esatte
    if( checkFolderDate==true )
    {
        strMsg = errorMessage["ERROR_checkTrafficItem_threshold_0"];
        showErrorMessage(strMsg);
    }
    else if( curDay > getRigthDate(curMonth,curYear ) )
    {
        strMsg = errorMessage["ERROR_checkTrafficItem_threshold_1"];
        showErrorMessage(strMsg);
    }
    else
    {
        document.formThreshold.submit();
    }
}


// Funzioni aggiunte da BHuman

    // Restituisce un oggetto del modello DOM della pagina dato il suo Id
    //
    // Input: objectId		l'id dell' oggetto da risolvere
    //
    function getById ( objectId )
    {
        return document.getElementById ( objectId );
    }


    // Concatena in una stringa gli id delle checkboxes attivate (on) in un form, dato l'id del form
    // la stringa strSeparator ?sata come separatore   
    //
    // Input: formId   		l'id del form in questione
    //        strResultId   l'id del campo di testo per il risultato
    //        strSeparator  la stringa da usare come separatore
    // 
    function checkedBoxesToString ( formId, strResultId, strSeparator, msgSingle, msgMultiple )
    {
        var objForm      = getById ( formId );
        var objStrResult = getById ( strResultId );
        var tmpStr       = new String ();
        var numDeleted   = 0;
        var response     = false;
        
        for ( i = 0 ; i < objForm.elements.length ; i++ )
        {
            if ( ( objForm.elements [i].type == "checkbox" ) && ( objForm.elements [i].checked == true ) )
            {
                tmpStr = tmpStr + objForm.elements [i].name + strSeparator;
                numDeleted++;
            }
        }
        
        // toglie l'ultimo separator dalla stringa risultante
        tmpStr = tmpStr.substr ( 0, tmpStr.length -1 ); 

        if ( numDeleted == 1 )
           response = confirm ( msgSingle );
        else
        if ( numDeleted > 1 )
           response = confirm ( msgMultiple );
        
        if ( response == true )
        {
            objStrResult.value = tmpStr;
            objForm.submit ();
        }           
    }	

/*
    // Concatena in una stringa i valori delle checkboxes attivate (on) in un form, dato l'id del form
    // la stringa strSeparator viene usata come separatore   
    //
    // Input: formId   		  l'id del form in questione
    //        prefix        il prefisso dell'id delle checkboxes da considerare
    //        strSeparator  la stringa da usare come separatore
    // 
    function checkBoxValuesToString ( formId, prefix, strSeparator )
    {
        var objForm      = getById ( formId );
        var resultStr    = new String ();
        var prefixRegExp = new RegExp ( "^" + prefix + "\d*", "i" );

        for ( i = 0 ; i < objForm.elements.length ; i++ )
        {
            var currentElementId = new String ( objForm.elements [i].id );
          
            if ( ( objForm.elements [i].type == "checkbox" ) && ( objForm.elements [i].checked == true ) && currentElementId.match ( prefixRegExp ) )
            {
                resultStr = resultStr + objForm.elements [i].value;

                if ( getById ( currentElementId + "Desc" ) != null )
                    resultStr = resultStr + " (" + getById ( currentElementId + "Desc" ).value + ")";
                
                resultStr = resultStr + strSeparator;
        }   }
        
        // toglie l'ultimo separator dalla stringa risultante
        resultStr = resultStr.substr ( 0, resultStr.length -1 ); 
        
        return resultStr
    }
*/    



    // Concatena in una stringa i valori delle checkboxes attivate (on) in un form, dato l'id del form
    // la stringa strSeparator viene usata come separatore   
    //
    // Input: formId   		       l'id del form in questione
    //        prefix             il prefisso dell'id delle checkboxes da considerare
    //        strSeparator       la stringa da usare come separatore principale
    //        keyValueSeparator  la stringa da usare come separatore key, value
    //        mode               se mode = onlySelected, nella stringa risultante vengono inseriti solo i valori selezionati
    // 
//    function checkBoxValuesToString ( formId, prefix, strSeparator, keyValueSeparator, mode )
    function checkBoxValuesToString ( formId, prefix, strSeparator )
    {
        var objForm      = getById ( formId );
        var resultStr    = new String ();
        var prefixRegExp = new RegExp ( "^" + prefix + "\d*", "i" );

        if ( typeof ( mode ) == "undefined" )
            mode = "all";

        for ( i = 0 ; i < objForm.elements.length ; i++ )
        {
            var currentElementId = new String ( objForm.elements [i].id );
          
            if ( ( objForm.elements [i].type == "checkbox" ) && objForm.elements [i].checked == true && currentElementId.match ( prefixRegExp ) )
            {
//                if ( ( mode == "onlySelected" ) && ( objForm.elements [i].checked == false ) )
//                    continue;

                resultStr = resultStr + objForm.elements [i].value;
/*                
                if ( objForm.elements [i].checked == true )
                    resultStr = resultStr + "Si";
                else
                    resultStr = resultStr + "No";
*/                
                if ( getById ( currentElementId + "Desc" ) != null )
                    resultStr = resultStr + " (" + getById ( currentElementId + "Desc" ).value + ")";
                
                resultStr = resultStr + strSeparator;
            }
        }
        
        // toglie l'ultimo separator dalla stringa risultante
        resultStr = resultStr.substr ( 0, resultStr.length -1 ); 
 
        return resultStr
    }







    
    // Valida il form di reclamo (una limitata e parziale validazione ?ato javascript, il grosso della validazione ?ato server)
    //
    // INPUT formId     l'id del form da validare
    //       action     la action da settare per il form
    //       mode       mode determina la action mode (validate | submit)
    //       probList   l'id del campo contenente una lista di valori provenienti da un gruppo di checkbox di problemi
    //       reqList    l'id del campo contenente una lista di valori provenienti da un gruppo di checkbox di richieste
    function claimFormValidation ( formId, action, mode, probList, reqList )
    {
        var objForm    = getById ( formId );
        
        if ( mode == "Submit" )
        {
            var actionStr  = new String ( action );
            var regExp     = new RegExp ( "_", "gi" );
            var splits     = actionStr.split ( regExp );
            objForm.action = splits [0] + "_" + splits [1] + mode + "_" + splits [2] + "_" + splits [3] + "_" + splits [4];
        }
        else
            objForm.action = action;

        getById ( probList ).value =  checkBoxValuesToString ( formId, 'prob', '|' );
        getById ( reqList ).value  =  checkBoxValuesToString ( formId, 'req',  '|' );
 
        // Controlli lato javascript (controlli condizionali)
        if ( getById ( 'prob7' ).checked == false || ( getById ( 'prob7' ).checked == true && getById ( 'prob7Desc' ).value != "" ) )
            getById ( 'claim.prob7Validated' ).value = "true";

        if ( getById ( 'prob12' ).checked == false || ( getById ( 'prob12' ).checked == true && getById ( 'prob12Desc' ).value != "" ) )
            getById ( 'claim.prob12Validated' ).value = "true";

        if ( getById ( 'prob33' ).checked == false || ( getById ( 'prob33' ).checked == true && getById ( 'prob33Desc' ).value != "" ) )
            getById ( 'claim.prob33Validated' ).value = "true";

        if ( getById ( 'prob34' ).checked == false || ( getById ( 'prob34' ).checked == true && getById ( 'prob34Desc' ).value != "" ) )
            getById ( 'claim.prob34Validated' ).value = "true";

        if ( getById ( 'req4' ).checked == false || ( getById ( 'req4' ).checked == true && getById ( 'req4Desc' ).value != "" ) )
            getById ( 'claim.req4Validated' ).value = "true";

        if ( getById ( 'req7' ).checked == false || ( getById ( 'req7' ).checked == true && getById ( 'req7Desc' ).value != "" ) )
            getById ( 'claim.req7Validated' ).value = "true";

        if ( getById ( 'req10' ).checked == false || ( getById ( 'req10' ).checked == true && getById ( 'req10Desc' ).value != "" ) )
            getById ( 'claim.req10Validated' ).value = "true";

        if ( getById ( 'req13' ).checked == false || ( getById ( 'req13' ).checked == true && getById ( 'req13Desc' ).value != "" ) )
            getById ( 'claim.req13Validated' ).value = "true";

        if ( getById ( 'req17' ).checked == false || ( getById ( 'req17' ).checked == true && getById ( 'req17Desc' ).value != "" ) )
            getById ( 'claim.req17Validated' ).value = "true";

        if ( getById ( 'req18' ).checked == false || ( getById ( 'req18' ).checked == true && getById ( 'req18Desc' ).value != "" ) )
            getById ( 'claim.req18Validated' ).value = "true";
                   
        if ( getById ( 'claim.userType' ).value != "association" )
        {  
            // Resetta i campi relativi al footer con userType = association
            getById ( 'claim.consumersAssociationCode' ).value = "";
            
            getById ( 'claim.caCodeValidated' ).value = "true";
        
            if ( getById ( 'claim.userType' ).value == "user" )
            {
                if ( getById ( 'claim.documentType' ).value != "" )
                    getById ( 'claim.documentTypeValidated' ).value = "true";

                if ( getById ( 'claim.documentNumber' ).value != "" )
                    getById ( 'claim.documentNumberValidated' ).value = "true";

                if ( getById ( 'claim.releasedBy' ).value != "" )
                    getById ( 'claim.releasedByValidated' ).value = "true";

                // Valida la data di scadenza del documento
                var dateRegExp            = new RegExp ( "^[0-9]{2}/[0-9]{2}/[0-9]{4}$", "gi" );
                dateRegExp = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/i;
                var documentExpirationStr = new String ( getById ( 'claim.documentExpiration' ).value );

                if ( documentExpirationStr.match ( dateRegExp ) )
                    getById ( 'claim.documentExpirationValidated' ).value = "true";
            }
        }
        
        if ( getById ( 'claim.userType' ).value != "user" )
        {
            // Resetta i campi relativi al footer con userType = user
            var objDocumentType       = getById ( 'claim.documentType' );
            var objDocumentNumber     = getById ( 'claim.documentNumber' );
            var objReleasedBy         = getById ( 'claim.releasedBy' );
            var objDocumentExpiration = getById ( 'claim.documentExpiration' );
            
            if ( objDocumentType )
                objDocumentType.value = "";

            if ( objDocumentNumber )
                objDocumentNumber.value = "";

            if ( objReleasedBy )
                objReleasedBy.value = "";

            if ( objDocumentExpiration )
                objDocumentExpiration.value = "";
            
            getById ( 'claim.documentTypeValidated' ).value       = "true";
            getById ( 'claim.documentNumberValidated' ).value     = "true";
            getById ( 'claim.releasedByValidated' ).value         = "true";
            getById ( 'claim.documentExpirationValidated' ).value = "true";

            if ( getById ( 'claim.userType' ).value == "association" )
            {
                var associationCodeStr = new String ( getById ( 'claim.consumersAssociationCode' ).value );
                var regExp             = new RegExp ( "^[a-zA-Z0-9 '\(\)_+-\./:\=\?]{1,8}$", "gi" );

                if ( associationCodeStr.length > 0 && associationCodeStr.length <= 8 && associationCodeStr.match ( regExp ) )
                    getById ( 'claim.caCodeValidated' ).value = "true";
            }
        }

        objForm.submit ();
    }
    
    

    // Valida il form di conciliazione (una limitata e parziale validazione ?ato javascript, il grosso della validazione ?ato server)
    //
    // INPUT formId     l'id del form da validare
    //       action     la action da settare per il form
    //       mode       mode determina la action mode (validate | submit)
    //       motList    l'id del campo contenente una lista di valori provenienti da un gruppo di checkbox di richieste
    function conciliationFormValidation ( formId, action, mode, motList )
    {
        var objForm = getById ( formId );

        if ( mode == "Submit" )
        {
            var actionStr  = new String ( action );
            var regExp     = new RegExp ( "_", "gi" );
            var splits     = actionStr.split ( regExp );
            objForm.action = splits [0] + "_" + splits [1] + mode + "_" + splits [2] + "_" + splits [3] + "_" + splits [4];
        }
        else
            objForm.action = action;
        
        getById ( motList ).value = checkBoxValuesToString ( formId, 'mot',  '|', '=' );

        if ( getById ( 'mot14' ).checked == false || ( getById ( 'mot14' ).checked == true && getById ( 'mot14Desc' ).value != "" ) )
            getById ( 'conc.mot14Validated' ).value = "true";

        if ( getById ( 'conc.commission' ).value == "userDefined" && getById ( 'conc.associationSelected' ).value != "" )
            getById ( 'conc.associationSelectedValidated' ).value = "true";
        else
        if ( getById ( 'conc.commission' ).value != "userDefined" )
            getById ( 'conc.associationSelectedValidated' ).value = "true";

        if ( getById ( 'conc.userType' ).value != "association" )
        {  
            // Resetta i campi relativi al footer con userType = association
            getById ( 'conc.consumersAssociationCode' ).value = "";
            
            getById ( 'conc.caCodeValidated' ).value = "true";
        
            if ( getById ( 'conc.userType' ).value == "user" )
            {
                if ( getById ( 'conc.documentType' ).value != "" )
                    getById ( 'conc.documentTypeValidated' ).value = "true";

                if ( getById ( 'conc.documentNumber' ).value != "" )
                    getById ( 'conc.documentNumberValidated' ).value = "true";

                if ( getById ( 'conc.releasedBy' ).value != "" )
                    getById ( 'conc.releasedByValidated' ).value = "true";

                // Valida la data di scadenza del documento
                var dateRegExp            = new RegExp ( "^[0-9]{2}/[0-9]{2}/[0-9]{4}$", "gi" );
                dateRegExp = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/i;
                var documentExpirationStr = new String ( getById ( 'conc.documentExpiration' ).value );

                if ( documentExpirationStr.match ( dateRegExp ) )
                    getById ( 'conc.documentExpirationValidated' ).value = "true";
            }
        }
        
        if ( getById ( 'conc.userType' ).value != "user" )
        {
            // Resetta i campi relativi al footer con userType = user
            // Resetta i campi relativi al footer con userType = user
            var objDocumentType       = getById ( 'conc.documentType' );
            var objDocumentNumber     = getById ( 'conc.documentNumber' );
            var objReleasedBy         = getById ( 'conc.releasedBy' );
            var objDocumentExpiration = getById ( 'conc.documentExpiration' );
            
            if ( objDocumentType )
                objDocumentType.value = "";

            if ( objDocumentNumber )
                objDocumentNumber.value = "";

            if ( objReleasedBy )
                objReleasedBy.value = "";

            if ( objDocumentExpiration )
                objDocumentExpiration.value = "";
            
            getById ( 'conc.documentTypeValidated' ).value       = "true";
            getById ( 'conc.documentNumberValidated' ).value     = "true";
            getById ( 'conc.releasedByValidated' ).value         = "true";
            getById ( 'conc.documentExpirationValidated' ).value = "true";

            if ( getById ( 'conc.userType' ).value == "association" )
            {
                var associationCodeStr = new String ( getById ( 'conc.consumersAssociationCode' ).value );
                var regExp             = new RegExp ( "^[0-9]{1,8}$", "gi" );
                
                if ( associationCodeStr.length > 0 && associationCodeStr.length <= 8 && associationCodeStr.match ( regExp ) )
                    getById ( 'conc.caCodeValidated' ).value = "true";
            }

        }

        objForm.submit ();
    }



    // Restituisce il valore selezionato di un radio button dato il suo id
    // Restituisce undefined se nessun valore viene selezionato
    function getRadiosValue ( formId, radioButtonName )
    {
        var value;
        var objForm = getById ( formId );
        
        for ( i = 0 ; i < objForm.elements.length ; i++ )
        {
            var currentElementName = new String ( objForm.elements [i].name );

            if ( ( objForm.elements [i].type == "radio" ) && ( objForm.elements [i].checked == true ) && currentElementName.match ( radioButtonName ) )
                value = objForm.elements [i].value;
            else
                value = "";
        }
        
        return value;
    }

    
    // Chiede conferma per l'eliminazione del messaggio e
    // sottomette il form per l'eliminazione in caso di risposta affermativa
    //
    // Input: formId   l'id del form in questione
    // 
    function confirmDeleteMessage ( formId )
    {
        var objForm = getById ( formId );
        
        var result  = confirm ( "Vuoi cancellare il messaggio?" );
        
        if ( result == true )
            objForm.submit ();
    }




    // Controlla la validit?delle date inserite in InfoCosti e concatena i valori dei menu a tendina in una data di inizio e una data di fine
	  function buildDateString ()
	  {
	      var objDateFlag = getById ( 'dateFlag' );
	      
        var checkFailed = false;
	      var startDate   = "";
	      var endDate     = "";
	      var objForm     = getById ( "formDati" );	    
	      var resultStr1  = getById ( "startDate" );
	      var resultStr2  = getById ( "endDate" );
	    
        var objStartDay   = getById ( "startDay" );
	      var objStartMonth = getById ( "startMonth" );
	      var objStartYear  = getById ( "startYear" );
        var objEndDay     = getById ( "endDay" );
	      var objEndMonth   = getById ( "endMonth" );
	      var objEndYear    = getById ( "endYear" );

	      var startDay   = objStartDay.options [ objStartDay.selectedIndex ].value;
	      var startMonth = objStartMonth.options [ objStartMonth.selectedIndex ].value;
	      var startYear  = objStartYear.options [ objStartYear.selectedIndex ].value;
	      var endDay     = objEndDay.options [ objEndDay.selectedIndex ].value;
	      var endMonth   = objEndMonth.options [ objEndMonth.selectedIndex ].value;
	      var endYear    = objEndYear.options [ objEndYear.selectedIndex ].value;

        var objDateSelector = getById ( 'periodSelector' );

        if ( objDateFlag.value == "periodSelector" )
        {
            if ( objDateSelector.options [ objDateSelector.selectedIndex ].value == "" )
            {
                checkFailed = true;
                alert ( "Inserire correttamente le date di inizio e fine periodo" );
            }
        }
        else
        {
            // Controlla se le date inserite sono formalmente corrette
            if ( ( startDay == "" || startMonth == "" || startYear == "" ) && checkFailed == false )
            {
                checkFailed = true;
                alert ( "Inserire correttamente la data di inizio periodo" );
            }	    
           
            if ( ( endDay == "" || endMonth == "" || endYear == "" ) && checkFailed == false )
            {
                checkFailed = true;
                alert ( "Inserire correttamente la data di fine periodo" );
            }	    
        }
        // Se le date sono formalmente corrette, va avanti con l'elaborazione e sottomette il form
        if ( checkFailed != true )
        {
            if ( objDateFlag.value == "periodSelector" )
            {
                var datesStr   = new String ( getById ( "periodSelector" ).value );
                var splitDates = datesStr.split ( " - " );

                resultStr1.value = splitDates [0];        
                resultStr2.value = splitDates [1];        
            }
            else
            {
                if ( startDay.length < 2 )
	                  startDay = "0" + startDay;
         
	              if ( startMonth.length < 2 )
                    startMonth = "0" + startMonth;

	              if ( startYear.length < 2 )
                    startYear = "0" + startYear;
	    
                if ( endDay.length < 2 )
	                  endDay = "0" + endDay;
         
	              if ( endMonth.length < 2 )
	                  endMonth = "0" + endMonth;

	              if ( endYear.length < 2 )
	                  endYear = "0" + endYear;

                startDate = startDate + startDay + "/" + startMonth + "/" + startYear;
	              endDate   = endDate + endDay + "/" + endMonth + "/" + endYear;
                resultStr1.value = startDate;
                resultStr2.value = endDate;
            }  
            
            objForm.submit ();
        }
    }

    function buildDateString999 ()
	  {
	        var objDateFlag = getById ( 'dateFlag' );
	      
		var checkFailed = false;
		      var startDate   = "";
		      var endDate     = "";
		      var objForm     = getById ( "formDati" );	    
		      var resultStr1  = getById ( "startDate" );
		      var resultStr2  = getById ( "endDate" );
		    
		      var objStartDay   = getById ( "startDay" );
		      var objStartMonth = getById ( "startMonth" );
		      var objStartYear  = getById ( "startYear" );
		      var objEndDay     = getById ( "endDay" );
		      var objEndMonth   = getById ( "endMonth" );
		      var objEndYear    = getById ( "endYear" );

		      var startDay   = objStartDay.value;
		      var startMonth = parseInt(objStartMonth.options [ objStartMonth.selectedIndex ].value);
		      var startYear  = parseInt(objStartYear.options [ objStartYear.selectedIndex ].value);
		      var endDay     = objEndDay.value;
		      var endMonth   = parseInt(objEndMonth.options [ objEndMonth.selectedIndex ].value);
		      var endYear    = parseInt(objEndYear.options [ objEndYear.selectedIndex ].value);
                       
		       // Controlla se le date inserite sono formalmente corrette

		    if (  startMonth == "" && startYear == "" && endMonth == "" && endYear == "" )
                    {
		     objForm.submit (); 
                     return;                          
                    }
                    
		    if ( ( startMonth > endMonth && startYear == endYear ) && checkFailed == false )
		    {
		        checkFailed = true;
                        alert(getById( "msgErroreInserimentoMeseInizio" ).innerHTML);
		    }	    
		    if ( ( startDay == "" || startMonth == "" || startYear == "" ) && checkFailed == false )
		    {
		        checkFailed = true;
                       alert(getById( "msgErroreInserimentoDataInizio" ).innerHTML);
		    }	    
		   
		    if ( ( endDay == "" || endMonth == "" || endYear == "" ) && checkFailed == false )
		    {
		        checkFailed = true;
                        if(getById( "msgErroreInserimentoDataFine" ))
                          alert(getById( "msgErroreInserimentoDataFine" ).innerHTML);
                        else
		          alert ( "Inserire correttamente la data di fine periodo" );
		    }	
                     
                    
                    if (checkFailed == false )
		    {
                      if(startYear>endYear){
		        checkFailed = true;
                        alert ( getById ( "msgErroreInserimentoAnnoFineMaggioreAnnoInizio" ).innerHTML );

		       // alert ( "L'anno di fine non può essere minore dell'anno di inizio" );
                      	}
                     
		    }
                    
                    
                    
                             
		
		// Se le date sono formalmente corrette, va avanti con l'elaborazione e sottomette il form
		if ( checkFailed != true )
		{
		          if ( startDay.length < 2 )
			          startDay = "0" + startDay;
		 
			      if ( startMonth.length < 2 )
		            startMonth = "0" + startMonth;

			      if ( startYear.length < 2 )
		            startYear = "0" + startYear;
		    
		        if ( endDay.length < 2 )
			          endDay = "0" + endDay;
		 
			      if ( endMonth.length < 2 )
			          endMonth = "0" + endMonth;

			      if ( endYear.length < 2 )
			          endYear = "0" + endYear;

		        startDate = startDate + startDay + "/" + startMonth + "/" + startYear;
			      endDate   = endDate + endDay + "/" + endMonth + "/" + endYear;
		        resultStr1.value = startDate;
		        resultStr2.value = endDate;

                        objForm.submit ();
		    
		}  
		    
		    
               
    }

function buildDateString2 ()
	  {
		      var startDate   = "";
		      var endDate     = "";
		      var objForm     = getById ( "formDati" );	    
		      var resultStr1  = getById ( "startDate" );
		      var resultStr2  = getById ( "endDate" );		  
                      var check = false;  
		     
                      var objStartDay   = getById ( "startDay" );
		      var objStartMonth = getById ( "startMonth" );
		      var objStartYear  = getById ( "startYear" );
                      var objEndDay     = getById ( "endDay" );
                      var objEndMonth   = getById ( "endMonth" );
                      var objEndYear    = getById ( "endYear" );
               
                      
                      var startDay   = objStartDay.value;
                      var startMonth = objStartMonth.options [ objStartMonth.selectedIndex ].value;
		      var startYear  = objStartYear.options [ objStartYear.selectedIndex ].value;
                      var endDay     = objEndDay.value;
                      var endMonth   = objEndMonth.options [ objEndMonth.selectedIndex ].value;
		      var endYear    = objEndYear.options [ objEndYear.selectedIndex ].value;
                      var inOut;
                     
                     for (i = 0; i <objForm.inOut.length; i++) 
                       if (objForm.inOut[i].checked) 
                        inOut = objForm.inOut[i].value

                      
                      //alert("startDate :"+startMonth+" "+startYear+", endDate :"+endMonth+" "+endYear +", inOut: "+ inOut);
                        
		      if (  startMonth == "" && startYear == "" && endMonth == "" && endYear == "" && inOut == "")
                      {
                      check=true;
		      objForm.submit (); 
                      return;                          
                      }
                      
  
                      if(startMonth == "" && check == false){
                          alert(getById( "msgErroreInserimentoDataInizio" ).innerHTML);
                          return;
                      }
                      if (startYear == ""){                      
                           alert(getById( "msgErroreInserimentoDataInizio" ).innerHTML);
                          return;
                      }
                      if (endMonth == ""){                      
                            alert(getById( "msgErroreInserimentoDataFine" ).innerHTML);
                          return;
                      }
                      if (endYear == ""){                      
                            alert(getById( "msgErroreInserimentoDataFine" ).innerHTML);
                          return;
                      }

                       
                     /*if(startMonth != "" && startYear != "" && endMonth != "" && endYear != "")
                      {
                         startMonth = parseInt(startMonth);
                         startYear  = parseInt(startYear);
                         endMonth   = parseInt(endMonth);
	     	         endYear    = parseInt(endYear);
                         alert("startDate2 :"+startMonth+" "+startYear+", endDate2 :"+endMonth+" "+endYear);
                       }*/
		      
             
		     if( (startYear < endYear) || (startMonth <= endMonth && startYear == endYear) ) {
                     startDate = startDate + startDay + "/" + startMonth + "/" + startYear;
	             endDate   = endDate + endDay + "/" + endMonth + "/" + endYear;
		     resultStr1.value = startDate;
		     resultStr2.value = endDate;
		     objForm.submit ();
                     }
                     else alert(getById( "msgErroreGenerico" ).innerHTML);
                                                     

                      
	    
               
    }



    function invalidateSelectors ( startDay, startMonth, startYear, endDay, endMonth, endYear )
    {
        getById ( 'dateFlag' ).value = "periodSelector"; 

        var objStartDay   = getById ( startDay );
        var objStartMonth = getById ( startMonth );
        var objStartYear  = getById ( startYear );
        var objEndDay     = getById ( endDay );
        var objEndMonth   = getById ( endMonth );
        var objEndYear    = getById ( endYear );

        objStartDay.selectedIndex   = 0;
        objStartMonth.selectedIndex = 0;
        objStartYear.selectedIndex  = 0;
        objEndDay.selectedIndex     = 0;
        objEndMonth.selectedIndex   = 0;
        objEndYear.selectedIndex    = 0;
    }



    function invalidate ( selector )
    {
        getById ( 'dateFlag' ).value = ""; 
        getById ( selector ).selectedIndex = 0;        
    }
    
    
    // Aggiorna un contatore associato ad un campo di input
    //
    // Input: counterId     l'id del counter
    //        textId        l'id del campo di testo soggetto al conteggio dei caratteri
    //        maxChars      Il massimo numero di caratteri allocati nel campo di input
    // 
    function updateCounter ( counterId, textId, maxChars ) 
    {
        var objCounter = getById ( counterId );
        var objText    = getById ( textId );
    
        var prev = maxChars - objText.value.length;

        if ( objText.value.length <= maxChars )
        {
            objCounter.value = prev;
            msg = objText.value.substring ( 0, maxChars );
        }
        else
        {
            objText.value = msg;
        }
    }


    // Usata per forzare la scelta di un radio button nel form activateForm nella pagina activateInternationalNoLimit.xsl
 	function activateFormValidation ( formAction )
 	{
  	  	var objForm      = getById ( "activateForm" );
  	  	var objPriceBand = getById ( "pricebandSelected" );

        if ( objPriceBand.value == "" )
            alert ( "E' necessario selezionare un importo" );
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   		        objForm.action = formAction;
   			    
             objForm.submit ();
  		}
 	}


    
    // Usata attualmente solo per validare username per il "recupera password"
 	function loginFormValidation ( formAction, checkUsername, checkPassword )
 	{
  	  	var errorMsg  = "";
  		var errorMsg2 = "";

        if ( typeof ( checkUsername ) == "undefined" )
            checkUsername = true;

        if ( typeof ( checkPassword ) == "undefined" )
            checkPassword = true;

  		if ( checkUsername && document.formDati.username.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";

  		if ( checkPassword && document.formDati.password.value == "" )
   		    errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
  		else
		if ( checkPassword && document.formDati.password.value.length < 6 )
   		    errorMsg2 = "Attenzione: i dati inseriti sono errati.\nControlla il modulo!!!";
  
  		if ( errorMsg != "" )
    	    alert ( errorMsg );
  		else 
  		if ( errorMsg2 != "" )
    	    alert ( errorMsg2 );
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   		        document.formDati.action = formAction;
   			    
             document.formDati.submit ();
  		}
 	}





    // Usata per validare username e password per il form associaUsimForm nella pagina associaUsim.xsl
 	function associaUsimFormValidation ( formAction, checkAssociatedMsisdn, checkPassword, checkConfirmPassword )
 	{
  	    var errorMsg  = "";
  		var errorMsg2 = "";

        if ( typeof ( checkAssociatedMsisdn ) == "undefined" )
            checkAssociatedMsisdn = true;

        if ( typeof ( checkPassword ) == "undefined" )
            checkPassword = true;

        if ( typeof ( checkConfirmPassword ) == "undefined" )
            checkConfirmPassword = true;

  		if ( checkAssociatedMsisdn && document.associaUsimForm.associatedMsisdn.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";

  		if ( checkPassword && document.associaUsimForm.password.value == "" )
   		    errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
  		else
		if ( checkPassword && document.associaUsimForm.password.value.length < 6 )
   		    errorMsg2 = "Attenzione: i dati inseriti sono errati.\nControlla il modulo!!!";
  
  		if ( checkConfirmPassword && document.associaUsimForm.confirmPassword.value == "" )
   		    errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
  		else
		if ( checkConfirmPassword && ( document.associaUsimForm.confirmPassword.value != document.associaUsimForm.password.value ) )
   		    errorMsg2 = "Attenzione: la password di conferma differisce dalla password inserita";

  		if ( errorMsg != "" )
    	    alert ( errorMsg );
  		else 
  		if ( errorMsg2 != "" )
    	    alert ( errorMsg2 );
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   		        document.associaUsimForm.action = formAction;
   			    
            document.associaUsimForm.submit ();
  		}
 	}


    // Usata per validare il form retrievePasswordForm
 	function retrievePasswordFormValidation ( formAction, checkSecretAnswer, checkPassword, checkPasswordConfirm )
 	{
        var errorMsg  = "";
  	  	var errorMsg2 = "";
  		var errorMsg3 = "";
        
        if ( typeof ( checkSecretAnswer ) == "undefined" )
            checkSecretAnswer = true;

        if ( typeof ( checkUsername ) == "undefined" )
            checkUsername = true;

        if ( typeof ( checkPassword ) == "undefined" )
            checkPassword = true;

  		if ( checkSecretAnswer && document.retrievePasswordForm.secretAnswer.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";

  		if ( checkPassword && document.retrievePasswordForm.password.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
        else
		if ( checkPassword && document.retrievePasswordForm.password.value.length < 6 )
            errorMsg2 = "Attenzione: i dati inseriti sono errati.\nControlla il modulo!!!";

  		if ( checkPasswordConfirm && document.retrievePasswordForm.passwordConfirm.value == "" )
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
        else
		if ( checkPasswordConfirm && document.retrievePasswordForm.passwordConfirm.value.length < 6 )
            errorMsg2 = "Attenzione: i dati inseriti sono errati.\nControlla il modulo!!!";
  		
		if ( checkPassword && checkPasswordConfirm && ( document.retrievePasswordForm.password.value != document.retrievePasswordForm.passwordConfirm.value ) )
            errorMsg3 = "Attenzione: la password di conferma differisce dalla password inserita.\n";

  		if ( errorMsg != "" )
            alert ( errorMsg );
  		else 
  		if ( errorMsg2 != "" )
    	    alert ( errorMsg2 );
  		else 
  		if ( errorMsg3 != "" )
    	    alert ( errorMsg3 );
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   		   	     document.retrievePasswordForm.action = formAction;
   			   
            document.retrievePasswordForm.submit ();
  		}
 	} 		
 	
 	
    // Usata per validare il form registrationForm
 	function registrationFormValidation ( formAction, checkFirstParam, checkSecondParam )
 	{
        var errorMsg  = "";
  	  	var errorMsg2 = "";

        if ( typeof ( checkFirstParam ) == "undefined" )
            checkFirstParam = true;

        if ( typeof ( checkSecondParam ) == "undefined" )
            checkSecondParam = true;

        if ( document.registrationForm.step.value == "1" )
        {
          	if ( checkFirstParam && document.registrationForm.prefix.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
    
          	if ( checkSecondParam && document.registrationForm.number.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
        }
        else
        {
          	if ( checkFirstParam && document.registrationForm.pin.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
    
          	if ( checkSecondParam && document.registrationForm.email.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
        }

  		if ( errorMsg != "" )
		{
            alert ( errorMsg );
			return false;
  		}
		else
  		if ( errorMsg2 != "" )
		{
    	    alert ( errorMsg2 ); 
			return false; 
		}
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   		   	     document.registrationForm.action = formAction;
   			   
            return true;
  		}
 	} 
 	
	function registrationFormValidationDtc ( formAction, checkFirstParam, checkSecondParam, checkThirdParam)
 	{
        var errorMsg  = "";
  	  	var errorMsg2 = "";

		
        if ( typeof ( checkFirstParam ) == "undefined" )
            checkFirstParam = true;

        if ( typeof ( checkSecondParam ) == "undefined" )
            checkSecondParam = true;
            
		if ( typeof ( checkThirdParam ) == "undefined" )
            checkSecondParam = true;
        if ( document.registrationForm.step.value == "1" )
        {
          	if ( checkFirstParam && document.registrationForm.prefix.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
    
          	if ( checkSecondParam && document.registrationForm.number.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
        }
        else
        {
          	if ( checkFirstParam && document.registrationForm.pin.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
    
          	if ( checkSecondParam && document.registrationForm.email.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
            
            if ( checkThirdParam && document.registrationForm.emaildtc.value == "" ) 
                errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
            if ( document.registrationForm.emaildtc.value != "" && document.registrationForm.email.value != "" ){
            	if (document.registrationForm.email.value != document.registrationForm.emaildtc.value )
            		errorMsg = "Attenzione: le password inserite non coincidono.\n";
            }
        }

  		if ( errorMsg != "" )
            alert ( errorMsg );
  		else 
  		if ( errorMsg2 != "" )
    	    alert ( errorMsg2 );
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   		   	     document.registrationForm.action = formAction;
   			   
            document.registrationForm.submit ();
  		}
 	} 

 	
 
    // Usata per validare il form changePasswordForm (solo il confronto tra newPassword e confirmPassword, il resto viene validato server side)
 	function changePasswordFormValidation ( formId )
 	{
        if ( getById ( 'password' ).value == getById ( 'confirmPassword' ).value )
            getById ( 'password_validity' ).value = "true";
            
        getById ( formId ).submit ();
 	}	
 	




    // Usata per validare il form modificaDatiForm
 	function modificaDatiFormValidation ( formAction, checkTelephone, checkEmail )
 	{
       	var errorMsg  = "";
  	  	var errorMsg2 = "";

        if ( typeof ( checkTelephone ) == "undefined" )
            checkTelephone = true;

        if ( typeof ( checkEmail ) == "undefined" )
            checkEmail = true;

  		if ( checkTelephone && document.formDati.telephone.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";

  		if ( checkEmail && document.formDati.email.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";

        // Controlla se l'indirizzo email inserito ?alido
        var emailStr    = new String ( document.formDati.email.value );
        var emailRegExp = new RegExp ( "[^@%]+@(([a-zA-Z0-9\-\_])+\.)+([a-zA-Z0-9]{2,4})+", "gi" );
        
        if ( emailStr.search ( emailRegExp ) == -1 )
            errorMsg2 = "Attenzione: l'indirizzo email inserito non ?alido.\n";
 
  		if ( errorMsg != "" )
            alert ( errorMsg );
  		else 
  		if ( errorMsg2 != "" )
    	    alert ( errorMsg2 );
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   		  	     document.formDati.action = formAction;
   			   
            document.formDati.submit ();
  		}
 	}	


	function trimString(stringa){
		while (stringa.substring(0,1) == ' '){
			stringa = stringa.substring(1, stringa.length);
		}
		while (stringa.substring(stringa.length-1, stringa.length) == ' '){
			stringa = stringa.substring(0,stringa.length-1);
		}
		return stringa;
	}

    // Usata per validare il form di invio email
 	function sendMailFormValidation ( a, b, msg1, msg2, msg3, msg4)
 	{
        var errorMsg  = "";

		if ( document.formDati.useAlternativeMsisdn.checked == true && (trimString(document.formDati.alternativeMsisdn.value) == "" || document.formDati.alternativeMsisdn.value =='+39' ))
		{	
			//errorMsg = "Attenzione: si è scelto di essere contattati su un numero alternativo, ma il numero non è stato inserito\n";
			errorMsg = msg1;
			document.formDati.alternativeMsisdn.focus();
		}
		else if ( document.formDati.useAlternativeEmail.checked == true && trimString(document.formDati.alternativeEmail.value) == "")
		{	
			//errorMsg = "Attenzione: si è scelto di essere contattati su una mail alternativa, ma l'indirizzo non è stato inserito\n";
			errorMsg = msg2;
			document.formDati.alternativeEmail.focus();
		}
		else if ( (document.formDati.useAlternativeEmail.checked == true ) && (document.formDati.consenso1[0].checked == false) )
		{
			//errorMsg = "Attenzione: se si sceglie un recapito mail è necessario esprimere il consenso al trattamento dei dati personali\n";
			errorMsg = msg3;
		}
  		else if ( trimString(document.formDati.body.value) == "" ) 
		{
			//errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
			errorMsg = msg4;
			document.formDati.body.focus();
		}

			
  		if ( errorMsg != "" )
		{
            alert ( errorMsg );
  		}
		else
  		{
            document.formDati.submit ();
  		}
 	} 



    // Usata per validare il form di attivazione dell'opzione VideoNoi
 	function videoNoiFormValidation ( formAction, checkPartnerMsisdn, checkConfirmMsisdn )
 	{
        var errorMsg  = "";
  	    var errorMsg2 = "";
  		
        if ( typeof ( checkPartnerMsisdn ) == "undefined" )
            checkPartnerMsisdn = true;

        if ( typeof ( checkConfirmMsisdn ) == "undefined" )
            checkConfirmMsisdn = true;

  		if ( checkPartnerMsisdn && document.videoNoiForm.partnerMsisdn.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";

  		if ( checkConfirmMsisdn && document.videoNoiForm.confirmMsisdn.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
        else
		if ( checkConfirmMsisdn && ( document.videoNoiForm.confirmMsisdn.value != document.videoNoiForm.partnerMsisdn.value ) )
            errorMsg2 = "Attenzione: il numero di conferma differisce dal numero VideoNoi inserito.\n";
  
		if ( errorMsg != "" )
          alert ( errorMsg );
  		else 
  		if ( errorMsg2 != "" )
    	    alert ( errorMsg2 );
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   			    document.videoNoiForm.action = formAction;
   			   
            document.videoNoiForm.submit ();
  		}
 	}	



    // Usata per validare il form di modifica del numero partner dell'opzione VideoNoi
 	function changePartnerMsisdnFormValidation ( formAction, checkPartnerMsisdn, checkPartnerMsisdnConfirm )
 	{
        var errorMsg  = "";
  	    var errorMsg2 = "";
  		
        if ( typeof ( checkPartnerMsisdn ) == "undefined" )
            checkPartnerMsisdn = true;

        if ( typeof ( checkPartnerMsisdnConfirm ) == "undefined" )
            checkPartnerMsisdnConfirm = true;

  		if ( checkPartnerMsisdn && document.changePartnerMsisdnForm.partnerMsisdn.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";

  		if ( checkPartnerMsisdnConfirm && document.changePartnerMsisdnForm.partnerMsisdnConfirm.value == "" ) 
            errorMsg = "Attenzione: non sono stati compilati tutti i campi.\n";
        else
		if ( checkPartnerMsisdnConfirm && ( document.changePartnerMsisdnForm.partnerMsisdnConfirm.value != document.changePartnerMsisdnForm.partnerMsisdn.value ) )
            errorMsg2 = "Attenzione: il numero di conferma differisce dal nuovo numero VideoNoi inserito.\n";
  
		if ( errorMsg != "" )
            alert ( errorMsg );
  		else 
  		if ( errorMsg2 != "" )
    	    alert ( errorMsg2 );
  		else
  		{
  		    if ( typeof ( formAction ) != "undefined" && formAction != "" )
   			    document.changePartnerMsisdnForm.action = formAction;
   			   
            document.changePartnerMsisdnForm.submit ();
  		}
 	}	
 	  
  
// OVERRIDING delle stesse funzioni definite in /js/common.js  
function validateFormShopAssistance ( formActionOnValidationSuccess, formActionOnValidationErrors )
{
    var errorMsg = "";
    var alertMsg = "";

    errorMsg = isEmptyRegion ( document.regionProvinceForm.regionId ) 
             + isEmptyProvince ( document.regionProvinceForm.provinceId ) 
             + isEmptyCity ( document.regionProvinceForm.cityId );
  
    if ( !( document.regionProvinceForm.shopFlag.checked || document.regionProvinceForm.serviceFlag.checked ) )
	   errorMsg += " - TIPO DI PUNTO VENDITA \n";

    if ( errorMsg != "" )
    {
       document.regionProvinceForm.action = formActionOnValidationErrors;
       alert ( "Prego voler inserire i seguenti campi obbligatori:\n" + errorMsg );
    }
    else
    {
       document.regionProvinceForm.action = formActionOnValidationSuccess;
       document.regionProvinceForm.submit ();
    }
}

// Checks if city selected is empty
function isEmptyCity(obj)
{
  if(obj.selectedIndex==0)
    return " - COMUNE \n";
  else
    return "";
}

// Checks if province selected is empty
function isEmptyProvince(obj)
{
  if(obj.selectedIndex==0)
    return " - PROVINCIA \n";
  else
    return "";
}

// FINE OVERRIDING 

// Checks if region selected is empty
function isEmptyRegion(obj)
{
  if(obj.selectedIndex==0)
    return " - REGIONE \n";
  else
    return "";
}


function clearFormDati() {
    if ( confirm ( 'Attenzione, stai per cancellare tutti i campi' ) ) 
    { 
        if (document.getElementById('divFile2').style.display != 'none')
            document.getElementById('divFile2').style.display='none';
        if (document.getElementById('divFile3').style.display!='none')
            document.getElementById('divFile3').style.display='none';
        if (document.getElementById('divFile4').style.display!='none')
            document.getElementById('divFile4').style.display='none';
        if (document.getElementById('divFile5').style.display!='none')
            document.getElementById('divFile5').style.display='none';
        document.formDati.reset();    
    }    
}

function showConsensi(show)
{
    if (show)
    {
        document.getElementById('consensiClosed').style.display = 'none';
        document.getElementById('consensiOpen').style.display = 'block';
    }
    else
    {
        document.getElementById('consensiClosed').style.display = 'block';
        document.getElementById('consensiOpen').style.display = 'none';
    }
}

function checkConsensi(element)
{
    if (element.checked==true)
    {
        showConsensi(true);
    }
}

function checkConsensiAndEnableField(element1, element2)
{
    if (element1.checked==true)
    {
        showConsensi(true);
		element2.disabled = false;
    } 
	else
	{
		element2.disabled = true;
	}
}

function submitMsisdnSwitch()
{
    document.formDati.switchMsisdn.value = true;
    document.formDati.submit();
}

function trySubmit()
{

    if ((document.getElementById('consensiOpen').style.display == 'none') && !(document.modifyContactsForm.personalEmail.value == ''))
    {
        document.getElementById('consensiOpen').style.display = 'block';
    }
	else if (document.modifyContactsForm.consenso1[0].checked == false && !(document.modifyContactsForm.personalEmail.value == ''))
	{
		alert("Attenzione: è necessario esprimere il consenso al trattamento dei dati personali\n");
		document.modifyContactsForm.consenso1[0].focus();
	}
    else
    {
        document.modifyContactsForm.submit();
    }

}
















