var xmlHttpoferta = creazaXmlHttpoferta();

 
/*
Returneaza obiectul XMLHttpRequest creat
*/
function selectedValue(selBox) {
  return document.getElementById(selBox).options[document.getElementById(selBox).selectedIndex].value;
}
function creazaXmlHttpoferta()
{
    var xmlHttp;
    // pentru IE
    if(window.ActiveXObject)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp = false;
        }
    }
//Pt Mozilla sau alte browsere
    else
    {
        try
        {
            xmlHttp = new XMLHttpRequest();
        }
        catch (e)
        {
            xmlHttp = false;
       }
    }

    if (!xmlHttp)
        alert("Nu s a putut crea obiectul XMLHttpRequest .");
    else
        return xmlHttp;
}
/*
Acesta functie preia numerele introduse in input -uri si le trimite php-ului pentru update
*/
// function that makes update on.. venire
function trimiteoferta()
{

 
 
 
    // verificam daca xmlHttp este liber
    if (xmlHttpoferta.readyState == 4 || xmlHttpoferta.readyState == 0)
    {
        //obtinem cele doua valori ale inputurilor
        
        try{
        
         
           
        var nume = document.getElementById('nume').value;
        var email = document.getElementById('email').value;
        var telefon = document.getElementById('telefon').value;
        var mesaj = document.getElementById('mesaj').value;
        var q = document.getElementById('q').value;
        
        
     
         
        }catch(e){
       alert(e.message);
        return;
        }
        //alert("get");
       // executam script-ul php de update trimitand cele doua numere ca paramentri prin GET
        xmlHttpoferta.open("GET", "trimiteoferta2.php?nume=" + nume + "&email=" + email + "&mesaj=" + mesaj + "&telefon="+telefon +"&q="+q, true);
         
           
       //definim functia care se va ocupa de manipularea rezultatului primit de la script-ul php
        xmlHttpoferta.onreadystatechange = gestioneazaRezultatoferta;
        
        

        // trimitem cererea catre server
        xmlHttpoferta.send(null);
    }
    
   //~ function  that takes the response in corrrect format

 
    
 
    
}

 

 

/*
Acesta este functia de "callback" care primeste rezultatul de la php
*/
function gestioneazaRezultatoferta()
{

 
    // daca rezultatul este obtinut
    if (xmlHttpoferta.readyState == 4 || xmlHttpoferta.readyState == 0)
    {
        // status = 200 arata faptul ca cererea a fost rezolvata cu succes
        if (xmlHttpoferta.status == 200)
        {
            // extragem rezultatul
           var ofertauns = xmlHttpoferta.responseText;
            //ofertaunsplecare = xmlHttp.responseText;
         try{
         
         
            //modificam div-ul rezultat cu rezultatul
            //document.getElementById("oravenire").value =   ofertaunsvenire;
          //  document.getElementById("oraplecare").value =   ofertaunsplecare;
          
          
            document.getElementById("raspunstrimitere").innerHTML =   ofertauns;
            
       }catch(e){
       alert(e.message);
       return;
       
       }
      // alert("balhh");
       }
        // daca statusul este diferit avem o problema
        else
        {
            alert("Problema la accesare: " + xmlHttpoferta.statusText);
        }
    }
    
   //~ cand se incarca & shit
    if(xmlHttpoferta.readyState<4 && xmlHttpoferta.readyState!=0 ){
     document.getElementById("raspunstrimitere").innerHTML =   '<strong style="color:#336699;text-decoration:blink;">...asteptati..se incarca...</strong>';
 
      }
     
    
     
} 



