function buton(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
        if (self.xmlHttpReq.responseText==1) 
            updatepage("buton", '<input src="includes/languages/english/images/buttons/button_continue.gif" alt="Continua" title=" Continua " name="trimite" type="image">'); 
            else if (self.xmlHttpReq.responseText==0)
            updatepage("buton", '<input disabled type="submit" value="Va rugam verificati campurile obligatorii">');
            xmlhttpPost("buton", "email", "validate.php?camp=buton");
        }
    }

    self.xmlHttpReq.send("");
}

function xmlhttpPost(loc, camp, strURL) {

    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
                       updatepage(loc, self.xmlHttpReq.responseText);
                
                  buton("validate.php?camp=buton");
       
        } else updatepage(loc, '<img style="float:left;" src="images/ajax-loader.gif" border="0" ></img>');
    }

    self.xmlHttpReq.send(getquerystring(camp));
}

function dropdownvalid(loc, camp, strURL) {

    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(loc, self.xmlHttpReq.responseText);
        }
    }

    self.xmlHttpReq.send(getquerystringdropdown(camp));
}

function ckvalid(loc, camp, strURL) {

    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(loc, self.xmlHttpReq.responseText);
            buton("validate.php?camp=buton");
        }
    }

    self.xmlHttpReq.send(getquerystringck(camp));
}

function radiovalid(loc, camp, strURL) {

    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(loc, self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystringradio(camp));
}

function getquerystringradio(camp) {

    var form     = document.forms['create_account'];
    for (i=0;i<form.schimba_formular.length;i++) {
	if (form.schimba_formular[i].checked) qstr = 'w=' + i;

}
  
    return qstr;
}

function getquerystringck(camp) {

    var form     = document.forms['create_account'];
    var checkbox = form[camp];
    if (checkbox.checked) {
    var word = camp;
    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
        } else qstr="w=error";
    return qstr;
}

function getquerystringdropdown(camp) {

    var form     = document.forms['create_account'];
    var dropdown = form[camp];
    var word = form[camp].options[dropdown.selectedIndex].value;

    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
        
    return qstr;
}

function getquerystring(camp) {

    var form     = document.forms['create_account'];
    var word = form[camp].value;

    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
        
    return qstr;
}

function updatepage(loc, str){
    document.getElementById(loc).innerHTML = str;
}
