
/**
 * Initialize select box and add to specified DOM element
 */
// function mapselect_init() {
// //     pmMapSelectSettings.displayText + 
//     var select =  ' <select id="mapSelector" onchange="mapSelectChange()">';
//     $.each(pmMapSelectSettings.configList, function(key, val) {
//         var presel = key == PMap.config ? 'selected="selected"' : '';
//         select += '<option value="' + key + '" ' + presel + '>' + val + '</option>';
//     });
//     select += '</select>';
//        
//     $('#' + pmMapSelectSettings.divId).append('<div>' + select + '</div>');
// }

// function mapselect_init() {
// //     pmMapSelectSettings.displayText + 
//     var select =  ' <select id="mapSelector" onchange="mapSelectChange()" multiple=\"multiple\">';
//     $.each(pmMapSelectSettings.configList, function(key0, val0) {
//         select += '<optgroup label="' + profiles[key0] + '">';
//         $.each(val0, function(key, val) {
//           var presel = key == PMap.config ? 'selected="selected"' : '';
//           select += '<option value="' + key + '" ' + presel + '>' + val + '</option>';
//         });
//         select += '</optgroup>';
//     });
//     select += '</select>';
//     
//        
//     $('#' + pmMapSelectSettings.divId).append(select);
// }

function mapselect_init() {
  var table = '';
  var classTd = '';
  $.each(pmMapSelectSettings.configList, function(key0, val0) {
   table += '<i><b>' + profiles[key0] + '</b></i>';
   table += '<table class="mapSelector">';
    $.each(val0, function(key, val) {
      if (PMap.config == key){classTd = 'justConfig';}else{classTd = '';}
      table += '<tr class="' + key + '"><td class="' + classTd + '">' + val + '</td></tr>'
    });
    table += '</table>';
  });
    $('#' + pmMapSelectSettings.divId).append(table);
    $('table.mapSelector tr').click(function(){
       var baseLoc = location.href.split(/\?/)[0];
        var searchLoc = location.search;
        var sessId = pmMapSelectSettings.keepSession ? '&' + SID : '';
        var configUrl = baseLoc;
        if (searchLoc.length > 0) {
            if (searchLoc.match(/config=[a-zA-Z0-9\_]+/)) {
                configUrl += searchLoc.replace(/config=[a-zA-Z0-9\_]+/,'config=' + $(this).attr('class'));
            } else {
                configUrl += searchLoc + '&config=' + $(this).attr('class');
            }
            
            if (!searchLoc.match(/PHPSESS/))  configUrl += sessId;
        } else {
            configUrl += '?config=' + $(this).attr('class') + sessId;
        }
        //alert(configUrl);
        window.location = configUrl
    });
}

/**
 * OnChange function for select box; 
 * reloads application with selected config parameter
 */
// function mapSelectChange() {
//     $("#mapSelector option:selected").each(function () {
//         var baseLoc = location.href.split(/\?/)[0];
//         var searchLoc = location.search;
//         var sessId = pmMapSelectSettings.keepSession ? '&' + SID : '';
//         var configUrl = baseLoc;
//         
//         if (searchLoc.length > 0) {
//             if (searchLoc.match(/config=[a-zA-Z0-9\_]+/)) {
//                 configUrl += searchLoc.replace(/config=[a-zA-Z0-9\_]+/,'config=' + $(this).val());
//             } else {
//                 configUrl += searchLoc + '&config=' + $(this).val();
//             }
//             
//             if (!searchLoc.match(/PHPSESS/))  configUrl += sessId;
//         } else {
//             configUrl += '?config=' + $(this).val() + sessId;
//         }
//         //alert(configUrl);
//         window.location = configUrl;
//     });
// }


