function getXMLRequest(url) {
    xmlhttp = null;
    if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest()
    }
    else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
    }
    if (xmlhttp != null) {
        xmlhttp.open("GET", url, false)
        xmlhttp.send(null);
        return xmlhttp.responseText;
    }
    return null;
}

function checkUsernameAvailability(username, obj) {
    status = getXMLRequest('/checkUsernameAvailability?u='+username);
    if (status)
        if (status.indexOf('1') != -1) {
            obj.style.backgroundColor = '#caffca';
            obj.title = 'Available';
        } else {
            obj.style.backgroundColor = '#ffae9b';
            obj.title = 'Not available';
        }
}
