/*
    This needs to be in the jsp file.
    <%for ( int x=0; x < TimeZones.getCount() ; x++ ){%>
            tzObj = new Object();
            tzObj.id = <%=TimeZones.getID(x)%>;
            tzObj.country = <%=TimeZones.getCountry(x)%>;
            tzObj.label = "<%=TimeZones.getGMT(x)%> <%=TimeZones.getTimeZoneLocation(x)%>";
            all_tz[<%=x%>]=tzObj;
    <%}%>
*/


var showAllTZ = false;
var currentTZID = 0;
var all_tz = new Array();

function changeTZview(selectID){
    if ( showAllTZ == true ){
        showAllTZ = false;
    }else{
        showAllTZ = true;
    }
    buildTZ( currentTZID,selectID );
}

function isTZExpaned(currTZid){
    for (i=0; i <all_tz.length ; i++){
        if ( currTZid == all_tz[i].id ){
            if ( all_tz[i].country == 223 ){
                return false;
            }else{
                return true;
            }
        }
    }
    return false;
}
function InitialTZ(currTZid,selectID){
    if ( all_tz.length == 0 ){
        alert("Array all_tz need to be populated");
        return;
    }

    currentTZID =  currTZid;
    var selbox = document.getElementById("timezone");
    if ( isTZExpaned(currTZid) ){
        document.getElementById("tzshowall").checked = true;
        showAllTZ = true;
    }
    buildTZ(currentTZID,selectID);
}
function buildTZ(currTZid,selectID){
    var selbox = document.getElementById(selectID);
    selbox.options.length=0;

    for (i=0; i <all_tz.length ; i++){
        if ( showAllTZ == true  ) {
            if ( currTZid == all_tz[i].id ){
                selbox.options[selbox.options.length]=new Option(all_tz[i].label, all_tz[i].id, true, true)
            }else{
                selbox.options[selbox.options.length]=new Option(all_tz[i].label, all_tz[i].id, false, false)
            }
        }else if ( all_tz[i].country == 223 ){
            if ( currTZid == all_tz[i].id ){
                selbox.options[selbox.options.length]=new Option(all_tz[i].label, all_tz[i].id, true, true)
            }else{
                selbox.options[selbox.options.length]=new Option(all_tz[i].label, all_tz[i].id, false, false)
            }
        }
    }
}
