
var tbls =new Array(
    'sma_table', 'mla_table', 'bha_table', 'wsa_table', 'hwa_table', 'bra_table', 'sfv_table', 'psa_table', 'iea_table', 'sba_table', 'cda_table', 'oca_table', 'scv_table', 'sbc_table', 'vca_table', 'sda_table', 'sfv_table'
)

var uparrow = '';
var downarrow = '';

if(document.images){
	uparrow = new Image(16, 16);   
	downarrow = new Image(16, 16);
	uparrow.src = '/images/up.gif';
	downarrow.src = '/images/down.gif';
}

function myGetCheckboxes(formName)
{
    var i = 0;
    var myForm = myGetElement(formName);    
    var cities = new Array;
    
    for (var j=0; j < myForm.length ; j++) {
        var e = myForm.elements[j]
        if (e.type == 'checkbox'){
            cities[i] = e;
            i++;    
        }
        
    }
    
    return cities;
}

function checkAll(obj)
{
    var cities = myGetCheckboxes('main-search');
    var status = obj.checked;
    var block_id = obj.id.substring(0,3);

    for (i=0; i < cities.length; i++){
        if (cities[i].id.substring(0,3) == block_id){
            cities[i].checked = status;
        }
    }
    

}

function checkGroup(obj)
{
    var cities = myGetCheckboxes('main-search');
    var status = obj.checked;
    var block_id = obj.id.substring(0,3);
    var group_id = obj.id.substring(3,5);

    for (i=0; i < cities.length; i++){
        if (cities[i].id.substring(3,5) == group_id && cities[i].id.substring(0,3) == block_id){
            cities[i].checked = status;
        }
    }
}

function showHide(tblName)
{
    tbl = myGetElement(tblName + '_table');
    img = myGetElement(tblName + '_image');

    if (tbl.style.display == 'none'){
        tbl.style.display = 'block';
        img.src = downarrow.src;
    }else{
        tbl.style.display = 'none';
        img.src = uparrow.src;
    }
}

function showHideAll(status)
{
    var tbl;

    for(i=0; i < tbls.length; i++){
        tbl = myGetElement(tbls[i]);
        if(tbl)
            tbl.style.display = status ? 'block' : 'none';
    }
}

// MAP

function checkAllMap(obj)
{
    var cities = document.city_search.elements;
    //var cities = getCheckboxes();
    var status = obj.checked;
    var block_id = obj.id.substring(0,3);
    var tbl = myGetElement(block_id + '_table')
    var img = myGetElement(block_id + '_image');

    for (i=0; i < cities.length; i++){
        if (cities[i].id.substring(0,3) == block_id){
            cities[i].checked = status;
        }
    }
    document.city_search.elements[block_id + '0000'].checked = status;

    if(status){
        tbl.style.display = 'block';
    }

}


function hideMapAll(mapName)
{
    var tbl = myGetElement(mapName + '_cities');
    var map = myGetElement(mapName + '_map');
    var img = myGetElement(mapName + '_image');

    tbl.style.display = 'none';
	map.style.display = 'none';		
    img.src = uparrow.src;    
}

function showMap(tblName)
{
    hideMapAll('sf');
    hideMapAll('la');
    hideMapAll('sd');
 
    var tbl = myGetElement(tblName + '_cities');
    var map = myGetElement(tblName + '_map');
    var img = myGetElement(tblName + '_image');

    tbl.style.display = 'block';
	map.style.display = 'block';
    img.src = downarrow.src;

}

function showHideOnMap(tblName)
{
	showHideAll(false);
 
    tbl = myGetElement(tblName + '_table');

    if (tbl.style.display == 'none'){
        tbl.style.display = 'block';
    }else{
        tbl.style.display = 'none';
    }
}