var active_box = '';
var active_list = '';
var active_list_name = '';
function sms_display(what_to_display, id, name) {
    var chosenHandset = encodeURIComponent($('#smsChosenHandset').val());
    if (what_to_display=='latestlist' || what_to_display=='toplist') {
        $('#smsItem').css('display', 'none');
        $('#smsItems').load('/getAjax/sms/getItems.php?list='+what_to_display+'&handset='+chosenHandset);
        $('#smsItems').html('');
        $('#smsItems').css('display', 'block');
        active_box = 'smsItems';
        active_list = what_to_display;
    } else
    if (what_to_display=='category' && id < 50000 && id > 1000) {  // the value of id is just to check if it is a number without using regexp
        $('#smsItem').css('display', 'none');
        $('#smsItems').load('/getAjax/sms/getItems.php?category='+id+'&name='+name+'&handset='+chosenHandset);
        $('#smsItems').html('');
        $('#smsItems').css('display', 'block');
        active_box = 'smsItems';
        active_list = id;
        active_list_name = name;
    } else
    if (what_to_display=='item' && id < 5000000 && id > 30000) {  // the value of id is just to check if it is a number without using regexp
        $('#smsItems').css('display', 'none');
        $('#smsItem').load('/getAjax/sms/getItems.php?item='+id);
        $('#smsItem').html('');
        $('#smsItem').css('display', 'block');
        active_box = 'smsItem';
    } else
    if (what_to_display=='back') {
        $('#smsItems').css('display', 'block');
        $('#smsItem').css('display', 'none');
        active_box = 'smsItems';
    } else
    if (what_to_display=='menu') {
        $('#smsMenu').load('/getAjax/sms/getItems.php?menu=1&handset='+chosenHandset);
    } else
    if (what_to_display=='chooseHandset') {
        $('#smsChooseHandset').load('/getAjax/sms/getItems.php?chooseHandset=1');
    } else
    if (what_to_display=='choosed_handset') {
        sms_display('menu');
        if (active_box == 'smsItems') {
            if (active_list < 5000000 && active_list > 1000) {   // e.g. if a number
                sms_display('category', active_list, active_list_name)
            } else {
                sms_display(active_list);
            }
        }
        //$("#smsItem > .handsets > ul > li:contains('"+$('#smsChosenHandset').val()+"')").css("text-decoration", "underline");  // hmm, needs a true/false result if an li contains the chosen handset
    } else
    if (what_to_display=='search') {
        var query = encodeURIComponent($('#smsSearchInput').val());
        $('#smsItem').css('display', 'none');
        $('#smsItems').load('/getAjax/sms/getItems.php?search='+query+'&handset='+chosenHandset);
        $('#smsItems').html('');
        $('#smsItems').css('display', 'block');
        active_box = 'smsItems';
        active_list = 'search';
    }
}

var current_brand = '';
function choose_handset() {
    if (current_brand != '') {
        $(current_brand).css('display', 'none');
        $(current_brand+' > select').removeAttr('id');
    }
    var chosenBrand = encodeURIComponent($('#smsChosenBrand').val());
    var id = '#smsBrand'+chosenBrand;
    current_brand = id;
    $(id+' > select').attr('id', 'smsChosenHandset');
    $(id).css('display', 'block');
}
