<!-- general javascript functions

function valid_alnumdash(val)
{
    if(val.length == 0) {
        alert("Entry must contain some characters");
        return false;
    }
    if(val.search(/[^\w\-]/) != -1) {
        alert(  "Entry can only contain alphanumeric "
              + "and underscore characters");
        return false;
    }
    return true;
}
function upload_checks(form)
{
    form.board.value = get_selected_text('board');
    form.tag.value   = get_selected_value('upload_tag');
    if(form.pathname.value == null || form.pathname.value == "") {
        alert("Please select a path using the browse button");
        return false;
    }
    return true;
}

function get_selected_text(sel)
{
    if(typeof(sel) == 'string') {
        sel = document.getElementById(sel);
    }
    if(sel == null) { return null; }
    return sel.options[sel.selectedIndex].text;
}

function get_selected_value(sel)
{
    if(typeof(sel) == 'string') {
        sel = document.getElementById(sel);
    }
    if(sel == null) { return null; }
    return sel.options[sel.selectedIndex].value;
}

function get_radio_value(sel)
{
    var radio = document.getElementsByName(sel);
    for(var i = 0; i < radio.length; i++) {
        if(radio[i].checked) {
            return radio[i].value;
        }
    }
    return null;
}

function update_div(divid, html, mode)
{
    var div =  document.getElementById(divid);
    if(div == null) {
        alert("no div named: "+divid)
    } else {
        if(mode == null) { mode = 'replace' }
        switch(mode) {
            case 'replace':
                div.innerHTML = html;
                break;
            case 'append':
                div.innerHTML += html;
                break;
            default:
                alert("update_div, invalid mode passed: "+mode);
        }
    }
}

function exp_col(id) {
    var div = document.getElementById(id);
    var lnk = document.getElementById('x'+id);
    if(lnk) lnk.blur();
    if (div.style.display=="none") {
        div.style.display="block";
		if(lnk) lnk.innerHTML="[-]";
    } else {
        div.style.display="none";
        if(lnk) lnk.innerHTML="[+]";
    }
}

function ua_init()
{
    var ua = null;
    try{
        // Opera 8.0+, Firefox, Safari
        ua = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ua =  new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ua = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                alert("Unsupported browswer, or javascript disabled");
                return false;
            }
        }
    }
    return ua;
}

function ua_get_sync(url)
{
    var ua = ua_init();
    if(ua == null) {
        alert('cannot create request object');
        return '';
    }
    ua.open("GET", url, false);
    ua.send(null);
    if(ua.status == 200) {
        if(ua.responseText.substr(0,7) == "status:") {
            alert(ua.responseText);
        } else {
            return ua.responseText;
        }
    } else {
        alert("GET " + url + "status=" + ua.status);
    }
    return '';
}

function ua_get_async_res(ua)
{
    switch(ua.readyState) {
      case 0:   // req not initialised
      case 1:   // req has not been setup
      case 2:   // req has been sent
      case 3:   // req is in process
        break;
      case 4:   // req is complete
        if(ua.status == 200) {
            if(ua.responseText.substr(0,7) == "status:") {
                alert(ua.responseText);
            } else {
                return ua.responseText;
            }
        } else {
            alert("GET " + url + "status=" + ua.status);
            return '';
        }
    }
    return null;
}

function ua_get_async(url, callback)
{
    var ua = ua_init();
    if(ua == null) {
        alert('cannot create request object');
        return null;
    }
    if(callback != null) {
        ua.onreadystatechange = callback;
    }
    ua.open("GET", url, true);
    ua.send(null);
    return ua;
}

-->

