function showWait(tf){document.getElementById('plsWait').style.visibility=(tf?'visible':'hidden');}
function setFocus(a) { document.getElementById(a).focus()}
function formSubmit(a) { document.getElementById(a).submit()}
function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); }
function ltrim(stringToTrim) { return stringToTrim.replace(/^\s+/,""); }
function rtrim(stringToTrim) { return stringToTrim.replace(/\s+$/,""); }
function new_area(i) {
    var s=prompt('Νέα περιοχή');
    if (s) {
        var d;
        if ( i==1) d=document.getElementById('perioxh');
        if ( i==2) d=document.getElementById('perioxh2');
        var opt = document.createElement("option");
        d.options.add(opt);
        opt.text=s;
        opt.value=s;
        opt.selected=true;
    }
}
function new_action(q) {
    var s;
    var d=document.getElementById('action');
    if (q) {
        var a=d.options[d.selectedIndex].text;
        var id=d.options[d.selectedIndex].value;
        s=prompt('Τροποποίηση Ενέργειας ' + a, a);
    }
    else {
        s=prompt('Νέα Ενέργεια');
    }
    if (s && q) {
        showWait(1);
        xajax_update_action(id, s);
        d.options[d.selectedIndex].text = s;
    }
    if (s && ! q) {
        var opt = document.createElement("option");
        d.options.add(opt);
        opt.text=s;
        opt.value=s;
        opt.selected=true;
    }
}
function trans(i) {
    var d=document.getElementById('edit_trans');
    var c=document.getElementById('cust_div');
    d.style.display=(i)?'block':'none';
    c.style.display=(i)?'none':'block';
    if ( ! i) return;
    if ( i == 1 ) {
        document.getElementById('date_issued').value='';
        document.getElementById('result').value='';
        document.getElementById('followup').value='';
        document.getElementById('notes').value='';
    }
}
function save_trans() {
    var d=document.getElementById('date_issued');
    if ( ! isDate(d.value) ) {
        alert('Λάθος ημερομηνία!');
        return;
    }
    showWait(1);
    xajax_save_trans(xajax.getFormValues('id_form_trans'));
}
function conn_stuf() {
    var d=document.getElementById('code');
    if ( d.value == '' ) {
        alert('Λάθος κωδικός σύνδεσης!');
        return;
    }
    location.href="http://www.stoxosnet.gr/s" + d.value;
}
function sel_action(opt_val) {
    var d=document.getElementById('action');
    for ( i=0; i<d.options.length; i++ ) {
        if ( d.options[i].value == opt_val ) {
            d.options[i].selected = true;
            return;
        }
    }
}
function nomoi() {
    var d=document.getElementById("cust_nomos");
    var c=document.getElementById("cust_view");
    if ( d.style.display == 'block' ) {
        d.style.display = 'none';
        c.style.display = 'block';
        return;
    }
    else {
        d.style.display = 'block';
        c.style.display = 'none';
    }
}

function chk_nomos(id) {
    var d=document.getElementById(id);
    d.checked = ! d.checked;
}


function perioxes() {
    var d=document.getElementById("cust_perioxh");
    var c=document.getElementById("cust_view");
    if ( d.style.display == 'block' ) {
        d.style.display = 'none';
        c.style.display = 'block';
        return;
    }
    else {
        d.style.display = 'block';
        c.style.display = 'none';
    }
}

function chk_perioxh(id) {
    var d=document.getElementById(id);
    d.checked = ! d.checked;
}

function onoma_details(id) {
    var f=document.getElementById('frm_cust_details');
    var ff=document.getElementById('from_filter');
    var from_filter = '';
    if ( ff ) from_filter = '<input name="from_filter" type="hidden" value="1" />';
    //var d=document.getElementById('frm_cust_details_div');
    f.innerHTML = '<input type="hidden" name="id" value="' + id + '"/>' + from_filter;
    //f.submit();
    showWait(1);
    xajax_cust_detailsx(xajax.getFormValues('frm_cust_details'));

}

function cust_details(i) {
    var c=document.getElementById("cust_view");
    var d=document.getElementById('cust_details');
    if ( i ) {
        d.style.display = 'block';
        c.style.display = 'none';
    }
    else {
        if ( d.style.display == 'block' ) {
            d.style.display = 'none';
            c.style.display = 'block';
        }
        else {
            d.style.display = 'block';
            c.style.display = 'none';
        }
    }

}

function search_all() {
    var d=document.getElementById('search_in');
    var t=document.getElementById('search_txt');
    t.value = '';
    d.options.selectedIndex=-1;
    formSubmit('frm_search');
}

function show_f(f, url) {
    var d;
    switch(f) {
        case 4:
            d=document.getElementById('c1');
            break;
        case 5:
            d=document.getElementById('c2');
            break;
        case 6:
            d=document.getElementById('c3');
            break;
        case 7:
            d=document.getElementById('c4');
            break;
    default:
        return;
    }
    url += '/' + d[d.selectedIndex].value;
    location.href = url;

}

function make_form_trans(id) {
    hidden_id=document.getElementById("hidden_id");
    form=document.getElementById("form_trans");
    hidden_id.value = id;
    form.submit();

}

function make_form_email(id) {
    hidden_id=document.getElementById("hidden_id_email");
    form=document.getElementById("form_email");
    hidden_id.value = id;
    form.submit();

}
