function creeazaObjReq(){
    var cerere;
    if(window.XMLHttpRequest){
        cerere=new XMLHttpRequest();
    }else if(window.ActiveXObject){
        cerere=new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        alert("Browserul nu suporta AJAX");
    }
    return cerere;
}
var http=creeazaObjReq();
function SendForm(form){
    hd="";
    phpscript="_include/_elements/sendform.php";
    div="Message";
    for(i=0;i<form.elements.length;i++){
        if(i!=0)
            hd= hd + "&"
        hd =hd + form.elements[i].name + "=" +form.elements[i].value;
    }
    //alert(hd);
    http.open('post',phpscript);
    http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    http.onreadystatechange = function (){ 
            if(http.readyState==1){
                document.getElementById(div).innerHTML='<div id="opaque"><div class="msgbox"><img src="_pic/loading.gif" alt="Alaval"></div></div>';
            }else if(http.readyState==4 && http.status == 200){
                var raspuns=http.responseText;
                if(raspuns){
                    document.getElementById(div).innerHTML=raspuns;
                }
            } 
        }
    http.send(hd);
    return false;
}

function SimpleQuery(query){
    hd="query=" + query + "&do=executeQuery";
    phpscript="_include/_pages/process.php"; 
    //alert(hd);
    div='LoaderGraph';
    http.open('post',phpscript);
    http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    http.onreadystatechange = function (){ 
            if(http.readyState==1){
                document.getElementById(div).innerHTML='<img class="loader" alt="Va rugam asteptati" src="_img/loader.gif" />';
            }else if(http.readyState==4 && http.status == 200){
            var raspuns=http.responseText;
                if(raspuns){
                    document.getElementById(div).innerHTML=raspuns;
                }
                else{
                    document.getElementById(div).innerHTML='<img class="loader" alt="Gata" src="_img/check.gif" />';
                }
            } 
        }
    http.send(hd);
    return false;
}

function Execute(Array,action,table){
    ExecuteExp(Array,action,table,""); 
}
function ExecuteExp(Array,action,table,headers){
    phpscript="_include/_pages/process.php";
    div='VariableList';
    hd="table=" +table;
    hd = hd + "&do=" +action;
    for(i=0;i<Array.length;i++){
        hd= hd + "&"
        hd =hd + Array[i].name + "=" +Array[i].value;    
    }
    if(headers!=""){
        hd= hd + "&" + headers;
    }
    http.open('post',phpscript);
    http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    http.onreadystatechange = function (){ 
            if(http.readyState==1){
                document.getElementById(div).innerHTML='<img class="loader" alt="Va rugam asteptati" src="_img/loader.gif" />';
            }else if(http.readyState==4 && http.status == 200){
                var raspuns=http.responseText;
                if(raspuns){
                    document.getElementById(div).innerHTML=raspuns;
                }
            } 
        }
    http.send(hd);
    
}
