

function histats_timezone_form_class() {
    try {

        this.current_gmt_time = 0 ;
        this.Arr_fusoOrario = new Array();
        this.Arr_fusoOrario_ORA = new Array();
        this.Arr_ORE = new Array();


        this.AR_TZ_BY_HOURS = new Array();
        this.AR_TZ_BY_HOURS_sorting_VALUES = new Array(); // array of AR_TZ_BY_HOURS  but sorted on number of unixtime

        this._SEL_timezone_ALLTZ_name = 'sel_fusiOrari_AllTZ';
        this._SEL_timezone_listedTZ_name = 'sel_fusiOrari_NOJAVA';
        this._txt_timezone_SELECTED_name = 'SEL_TZ_txtSELECTED_timezone'; // text that contain in value the timezone selected

      
        this.BOOL_BLOCK_AUTOSET_TIMEZONE = false;

        this.TXT_SELECTED_ZONEname = '';

        this.MAIN_DIV_NAME = '' ;
        // get string time from ardate
        this.get_STR_TIME =  function (ARDATE) {
            this.current_gmt_time = parseInt(now);
        }

        // get timezone id from timezone name
        this.get_id_BY_ZONENAME =  function (zoneNAME) {
            for (k in G_AR_timezone_form_dati){
                if(G_AR_timezone_form_dati[k]['z'] == zoneNAME) return k;
            }
            return 100;
        }
      

        this.f_setZone_fusoOrario =  function (zoneNAME){
            try{
                if(zoneNAME.length>0){
                    this.TXT_SELECTED_ZONEname = zoneNAME;
                    document.getElementById(this._txt_timezone_SELECTED_name).value=zoneNAME;
                    var id_timezone_selected = this.get_id_BY_ZONENAME(zoneNAME);
                    var current_time_selected = G_AR_timezone_form_dati[id_timezone_selected]['str_dayhour'] + ' ' +  G_AR_timezone_form_dati[id_timezone_selected]['str_hour'];
                    document.getElementById('div_timeSelected').innerHTML = current_time_selected;
                //alert('CURRENT ZONE:' + zoneNAME );
                }else{
            //  alert('Select zone');
            }
            }catch(e){
                alert( e.message);
                document.getElementById('hidd_ERRORS').value = document.getElementById('hidd_ERRORS').value+ 'E:f_setZone_fusoOrario setzone interno ' + e.message;
            }
        }

        this.f_set_selected_city =  function (idTimezone){
            try{
                //alert('apply selection CITY timezone id : ' + idTimezone )  ;
                var zone_name = G_AR_timezone_form_dati[idTimezone]['z'];
                document.getElementById(this._SEL_timezone_ALLTZ_name).value = idTimezone;
                this.f_setZone_fusoOrario(zone_name);
                document.getElementById('sel_TZ_city').value = idTimezone;
            }catch(e){
                alert( e.message);
                document.getElementById('hidd_ERRORS').value = document.getElementById('hidd_ERRORS').value+ 'E:f_set_selected_city setzone interno ' + e.message;
            }
        }


        // after a zone has been choosen, must build the list of city
        this.f_apply_selection_TZ_id =  function (timezoneID){
            //alert('apply selection timezone id : ' + timezoneID )  ;
            var zone_name = G_AR_timezone_form_dati[timezoneID]['z'];
            this.f_setZone_fusoOrario(zone_name);
            if(document.getElementById('sel_TZ_city'))  document.getElementById('sel_TZ_city').value=timezoneID;


            
        }
        this.f_SELECT_hour_from_zoneSTR =  function (zoneNAME){
            var str_HOUR_TOSELECT = '' ;
            for (k in G_AR_timezone_form_dati){

                if(G_AR_timezone_form_dati[k]['z'] == zoneNAME){
                    str_HOUR_TOSELECT = (G_AR_timezone_form_dati[k]['str_dayhour'] + ' ' + G_AR_timezone_form_dati[k]['str_hour']) ;
                }
            }

            this.f_SELECT_hour(str_HOUR_TOSELECT);
        }
        
        this.f_SELECT_hour_autoset =  function (STR_hour){
            if(this.BOOL_BLOCK_AUTOSET_TIMEZONE == true ) return ; 
            this.f_SELECT_hour (STR_hour);
        }

        
        this.f_SELECT_hour =  function (STR_hour){
            if(document.getElementById('sel_fusiOrari'))  document.getElementById('sel_fusiOrari').value=STR_hour;
            this.f_SELECT_timezone_load_city(STR_hour);
        }
        // after a zone has been choosen, must build the list of city
        this.f_SELECT_timezone_load_city =  function (STR_hour){
            try{

                var lista_sel_zone = '';
                var this_selected = '';
                var this_selected_timeID = 0;
                var first_timeID = 0;
                  
                if(STR_hour.length>0){
                    lista_sel_zone = '<select name="sel_TZ_city" id="sel_TZ_city" size="12" onchange="G_TZ_form.f_set_selected_city(this.value);" class="sel_grey">';
                    for (k in G_AR_timezone_form_dati){
                        if( (G_AR_timezone_form_dati[k]['str_dayhour'] + ' ' + G_AR_timezone_form_dati[k]['str_hour']) ==STR_hour){
                            if(first_timeID==0) first_timeID=  parseInt(k);
                            if(AR_TZcity_defultset[G_AR_timezone_form_dati[k]['z']]){
                                this_selected_timeID = parseInt(k); // each zone have 1 or more default that shoudl be selected
                            }
                            lista_sel_zone += '<option value="'+k+'" >'+G_AR_timezone_form_dati[k]['z']+'</option>';
                        }
                    }
                    if(this_selected_timeID == 0  ) this_selected_timeID  = first_timeID; // if no one selected, select the first
                    //alert(lista_sel_zone);
                
                    lista_sel_zone += '</select>';
                    if(document.getElementById('div_lista_paesi_fusoOrario'))      document.getElementById('div_lista_paesi_fusoOrario').innerHTML = lista_sel_zone;
                    
                    this.f_set_selected_city(this_selected_timeID);
                   
                }
            }catch(e){
                alert( e.message);
            //                document.getElementById('hidd_ERRORS').value = document.getElementById('hidd_ERRORS').value+ 'E:caricacitt?fusoorario interno ' + e.message;
            }
        }

        
        this.set_current_USERPC_TIMEZONE =  function () {
            var GMT_minuti = '.$stringa_MINUTI_gmt.';
            var d = new Date();
            var curr_hour = d.getHours();
            var curr_min = d.getMinutes();
            var str_AMPM ='am';
            if( curr_hour >12){
                curr_hour-=12;
                str_AMPM = 'pm';
            }
            var diffmin = GMT_minuti-curr_min;
            if((diffmin  < -45 || diffmin  > 45)){
                if(diffmin   > 0 ){
                    curr_hour--;
                }else{
                    curr_hour++;
                }
            }
            var  str_hour = curr_hour+ '';
            if( curr_hour < 10){
                str_hour = '0' +  curr_hour+'';
            }
            if(str_hour=='00' && str_AMPM == 'am') str_hour = '12'; // problemad di mezzanotte

            str_hour = str_hour  + ':';
            var tmp_contatore_index = 0;
            //alert('inizio' +str_hour + str_AMPM );
            for( chiave in this.AR_TZ_BY_HOURS_sorting_VALUES){
                if(chiave.indexOf(str_hour)> 0 && chiave.indexOf(str_AMPM) > 0 ){
                    //alert('setto PC TIME ' + chiave);
                
                    setTimeout('G_TZ_form.f_SELECT_hour_autoset(\''+chiave+'\');',500);
                    
                // document.getElementById("sel_fusiOrari").selectedIndex = tmp_contatore_index;
                //  f_caricaCitta_fusoOrario(document.getElementById("sel_fusiOrari").value,1);
                }
                tmp_contatore_index++;
            }
        }

        this.f_applica_timezone_a_lista_oraria =  function (var_timezone_zone,listasingola){
            //                        alert(var_timezone_zone);
            if(!Arr_fusoOrario_ORA[var_timezone_zone]) return;

            var ora = Arr_fusoOrario_ORA[var_timezone_zone] ;
            var oraminuti = Arr_fusoOrario[var_timezone_zone];
            var tmp_contatore_index = 0;
            for( chiave in Arr_ORE){
                if(oraminuti ==chiave){
                    document.getElementById("sel_fusiOrari").selectedIndex = tmp_contatore_index;
                    f_caricaCitta_fusoOrario(document.getElementById("sel_fusiOrari").value,0);

                }
                tmp_contatore_index++;
            }


            tmp_contatore_index = 0;

            for(chiave in Arr_fusoOrario){
                if(Arr_fusoOrario[chiave]==oraminuti){
                    if(chiave==var_timezone_zone){
                        document.getElementById("sel_zone").selectedIndex = tmp_contatore_index;
                    }
                    tmp_contatore_index++;
                }
            }
            G_TZ_form.f_setZone_fusoOrario(var_timezone_zone);
          
            if(listasingola==1){ // applico il timezone anceh alla lista di tutti i timezone

                obj = document.getElementById('sel_fusiOrari_AllTZ');
                for (var i=0; i<obj.options.length; i++) {
                    if((obj[i].value) == var_timezone_zone) obj[i].selected = 'true';
                }

            }
        }

                
        this.set_now =  function (now) {
            this.current_gmt_time = parseInt(now);
        }


        // selected a timezone from the list of all timezones
        // G_TZ_form.ACTION_selected_AllTZ(this.value);
        this.ACTION_selected_AllTZ =  function (timezone_id) {
            var tmp_zonename = G_AR_timezone_form_dati[timezone_id]['z'];
            //alert('selected tz : ' + timezone_id );
            this.f_SELECT_hour_from_zoneSTR(tmp_zonename);
            G_TZ_form.f_apply_selection_TZ_id(timezone_id);
            document.getElementById('sel_fusiOrari_AllTZ').value = timezone_id;
        // document.getElementById(\'SEL_TZ_1timezone\').value = this.value;document.getElementById(\'div_timeSelected\').innerHTML = Arr_fusoOrario[this.value];f_applica_timezone_a_lista_oraria( this.value,0);
        }

        // G_TZ_form.ACTION_selected_TZ_1timezone(this.value);
        this.ACTION_selected_TZ_1timezone =  function (str_hour) {
            //f_caricaCitta_fusoOrario(this.value,1);document.getElementById(\'div_timeSelected\').innerHTML = this.value;
            //alert('selected hour : ' + str_hour );
            this.f_SELECT_timezone_load_city(str_hour);

        }

        this.set_now =  function (now) {
            this.current_gmt_time = parseInt(now);
        }

        
    } catch(e){
        alert("err loading javascript (timezone form ) ,    try refreshing browser cache \n "  + e.message + "\n ");
    }



//G_TZ_form.f_setZone_fusoOrario(var_timezone_zone);

} // end

// build online average values based on vis
var G_TZ_form = new histats_timezone_form_class();

// return single sid row
histats_timezone_form_class.prototype.f_print_todiv  = function(MAIN_DIV_NAME){
    this.MAIN_DIV_NAME =  MAIN_DIV_NAME;
    var HTML_SEL1 = '<select id="sel_fusiOrari_AllTZ" name="sel_fusiOrari_AllTZ" size="1" onchange="G_TZ_form.ACTION_selected_AllTZ(this.value);" class="select_grey">';
    var HTML_SEL2 = '<select id="sel_fusiOrari_NOJAVA" name="sel_fusiOrari_NOJAVA" size="1" onchange="document.getElementById(\'SEL_TZ_1timezone\').value = this.value;" class="select_grey">';

    var HTML_SEL3 = '<select id="sel_fusiOrari" name="sel_fusiOrari" size="12" onchange="G_TZ_form.ACTION_selected_TZ_1timezone(this.value);" class="sel_grey">';


    for (k in G_AR_timezone_form_dati){
        HTML_SEL1+=  '<option value="' + k + '">' + G_AR_timezone_form_dati[k]['str_hour'] + ' -> ' + G_AR_timezone_form_dati[k]['z'] + '</option>';
        HTML_SEL2+=  '<option value="' + k + '">' + G_AR_timezone_form_dati[k]['str_hour'] + ' -> ' + G_AR_timezone_form_dati[k]['z'] + '</option>';
    }
    for (k in this.AR_TZ_BY_HOURS_sorting_VALUES){
        HTML_SEL3+=  '<option value="' + k + '">' + k + '</option>';
    }
    HTML_SEL1+= '</select>';
    HTML_SEL2+= '</select>';
    HTML_SEL3+= '</select>';

    //document.getElementById(this.DIV_TABLE_tz_name ).innerHTML = HTML_SEL1 +  HTML_SEL3 +' <br><div id="div_lista_paesi_fusoOrario" ></div>' +' <br><div id="hidd_ERRORS" ></div>' ;
    document.getElementById(this.MAIN_DIV_NAME ).innerHTML = '<table border="0" width="450" id="table2" cellspacing="0" cellpadding="0" >\
                                                                <tr>\
                                                                    <td>\
                                                                        <table border="0" width="450" cellspacing="0" cellpadding="0" height="20"><tr><td style="padding-left: 5px" align="left"><font class="text12"><b>'+GL.R('select_your_time_and_then_your_zone')+'</b></font></td></tr></table>\
                                                                        <table border="0" width="450" id="table1" cellspacing="0" cellpadding="0">\
                                                                            <tr>\
                                                                                <td width="50%" valign="top" align="center" >\
                                                                                    <font class="text11_grey"><font color="#ff0000">1.</font> '+GL.R('seleziona_ora_corrente')+'</font><br>\
                                                                                    ' + HTML_SEL3 + '\
                                                                                </td>\
                                                                                <td width="50%" valign="top" align="center">\
                                                                                    <font class="text11_grey"><font color="#ff0000">2.</font> '+GL.R('seleziona_zona')+'</font><br>\
                                                                                    <div id="div_lista_paesi_fusoOrario"></div>\
                                                                                </td>\
                                                                            </tr>\
                                                                        </table>\
                                                                    </td>\
                                                                </tr>\
                                                                <tr>\
                                                                    <td align="center">\
                                                                        <table border="0" width="450" cellspacing="0" cellpadding="0" height="15"><tr><td></td></tr></table>\
                                                                        <table border="0" width="450" height="25" id="table2" cellspacing="0" cellpadding="0"><tr><td align="left" style="padding-left:5px;"><font class="text12"><b>'+GL.R('or_choose_from_this_list')+'</b></font></td></tr></table>\
                                                                        '+ HTML_SEL1 + '\
                                                                    </td>\
                                                                </tr>\
                                                                <tr>\
                                                                    <td height="25">\
                                                                        <table border="0" width="450" cellspacing="0" cellpadding="0" height="10"><tr><td align="center"></td></tr></table>\
                                                                        <table border="0" width="450" id="table3" cellspacing="0" cellpadding="0" height="30" bgcolor="#F2F2F2"><tr>\
                                                                            <td align="left" width="70" style="padding-left: 5px"><font class="text12"><b>'+GL.R('selezionato')+':</b></font></td>\
                                                                            <td  width="110" align="left"><font class="text11_orange"><div id="div_timeSelected" align="center"></div></font></td>\
                                                                            <td width="270" align="left"><input type="text" name="SEL_TZ_txtSELECTED_timezone" id="SEL_TZ_txtSELECTED_timezone" value="Europe/London"  readonly size="27"  style="border: 1px solid #CDCDCD;font-family: Arial; font-size: 16px; color:#000000; text-decoration:none; font-weight:bold;"></td>\
                                                                        </tr></table>\
                                                                    </td>\
                                                                </tr>\
                                                            </table>';
}



/*
*  [468] => Array
        (
            [o] => 72000
            [z] => US/Michigan
            [c] => US
            [t] => Michigan
            [y] => 
*/
histats_timezone_form_class.prototype._run_initialization  = function(){
    //alert('init');
    if(!G_AR_timezone_form_dati) return ;
    var tmp_current_zone_unixtime = 0 ;

    this.AR_TZ_BY_HOURS = Array();
    this.AR_TZ_BY_HOURS_sorting_VALUES = Array();
    
    for (k in G_AR_timezone_form_dati){
        G_AR_timezone_form_dati[k]['time'] = (  this.current_gmt_time -86400 )  + parseInt(G_AR_timezone_form_dati[k]['o']);
        G_AR_timezone_form_dati[k]['dateAR'] = f_return_DATE_AR(G_AR_timezone_form_dati[k]['time']);
        var tmp_0_hour = '';
        if(G_AR_timezone_form_dati[k]['dateAR']['hour12'] < 10) tmp_0_hour = '0';
        var tmp_0_min = '';
        if(G_AR_timezone_form_dati[k]['dateAR']['min'] < 10) tmp_0_min = '0';
        G_AR_timezone_form_dati[k]['str_hour'] = tmp_0_hour + G_AR_timezone_form_dati[k]['dateAR']['hour12'] + ':' + tmp_0_min + G_AR_timezone_form_dati[k]['dateAR']['min'] + ' ' + G_AR_timezone_form_dati[k]['dateAR']['hourampm']
        G_AR_timezone_form_dati[k]['str_dayhour'] = G_AR_timezone_form_dati[k]['dateAR']['day'] + ' ' + GL.R(GLOBAL_AR_MONTH[G_AR_timezone_form_dati[k]['dateAR']['month']]);
    }
    //print_r( G_AR_timezone_form_dati);
    var str_hour = '' ;

    for (k in G_AR_timezone_form_dati){
        str_hour = G_AR_timezone_form_dati[k]['str_dayhour'] + ' ' + G_AR_timezone_form_dati[k]['str_hour'];
        if(!this.AR_TZ_BY_HOURS[str_hour]){ 
            this.AR_TZ_BY_HOURS[str_hour] = Array();
            this.AR_TZ_BY_HOURS_sorting_VALUES[str_hour] =  G_AR_timezone_form_dati[k]['time'];
        }

        this.AR_TZ_BY_HOURS[str_hour][this.AR_TZ_BY_HOURS[str_hour].length] = k;


    }


    //this.AR_TZ_BY_HOURS_sorting_VALUES = sortAssoc(this.AR_TZ_BY_HOURS_sorting_VALUES );
    this.AR_TZ_BY_HOURS_sorting_VALUES = VIGOsortAssoc(this.AR_TZ_BY_HOURS_sorting_VALUES,0,'' );
    
   //print_r(this.AR_TZ_BY_HOURS_sorting_VALUES);
    G_TZ_form.set_current_USERPC_TIMEZONE();
    
//print_r(this.AR_TZ_BY_HOURS_sorting_VALUES);
// print_r( this.AR_TZ_BY_HOURS);
}





var AR_TZcity_defultset = new Array();
AR_TZcity_defultset['US/Samoa'] = 1;
AR_TZcity_defultset['US/Hawaii'] = 1;
AR_TZcity_defultset['Pacific/Marquesas'] = 1;
AR_TZcity_defultset['America/Yakutat'] = 1;
AR_TZcity_defultset['America/Los_Angeles'] = 1;
AR_TZcity_defultset['America/Denver'] = 1;
AR_TZcity_defultset['America/Chicago'] = 1;
AR_TZcity_defultset['America/New_York'] = 1;
AR_TZcity_defultset['America/Puerto_Rico'] = 1;
AR_TZcity_defultset['America/St_Johns'] = 1;
AR_TZcity_defultset['America/Santiago'] = 1;
AR_TZcity_defultset['America/Sao_Paulo'] = 1;
AR_TZcity_defultset['Atlantic/Azores'] = 1;
AR_TZcity_defultset['Europe/London'] = 1;

AR_TZcity_defultset['Egypt'] = 1;
AR_TZcity_defultset['Europe/Rome'] = 1;
AR_TZcity_defultset['Europe/Moscow'] = 1;
AR_TZcity_defultset['Iran'] = 1;
AR_TZcity_defultset['Asia/Dubai'] = 1;
AR_TZcity_defultset['Asia/Kabul'] = 1;
AR_TZcity_defultset['Indian/Maldives'] = 1;
AR_TZcity_defultset['Asia/Calcutta'] = 1;
AR_TZcity_defultset['Asia/Katmandu'] = 1;
AR_TZcity_defultset['Asia/Dhaka'] = 1;
AR_TZcity_defultset['Asia/Rangoon'] = 1;
AR_TZcity_defultset['Asia/Jakarta'] = 1;
AR_TZcity_defultset['Asia/Tokyo'] = 1;
AR_TZcity_defultset['Australia/North'] = 1;
AR_TZcity_defultset['Australia/Queensland'] = 1;
AR_TZcity_defultset['Australia/South'] = 1;
AR_TZcity_defultset['Australia/Sydney'] = 1;
AR_TZcity_defultset['Pacific/Norfolk'] = 1;
AR_TZcity_defultset['Pacific/Fiji'] = 1;
AR_TZcity_defultset['Pacific/Chatham'] = 1;


if(!JSCACHE) JSCACHE = [] ;
JSCACHE.push(['timezone_form.class.js',1]);
