function getHTTPObject(url,c) {
	  var http_request;
	  if (window.XMLHttpRequest) { // Mozilla, Safari,... alte browsere normale
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                
            }
        } else if (window.ActiveXObject) { // IE
            try {
		    //ie 6 sp
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
			// ie 5,6
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e2) {
			// daca e un browser de consola n-ar trebui sa fie deranjat de alert
		alert('Your browser doesnt understand Ajax. Use Firefox');
		}
            }
        }

        if (!http_request) {
		// daca e un browser de consola n-ar trebui sa fie deranjat de alert
            alert('Your browser doesnt understand Ajax. Use Firefox');
            return false;
        }
	
	http_request.onreadystatechange = function() { handleHttpResponse(http_request,c); };
        http_request.open('GET', url, true);
	// nefolosit
        http_request.send(null);
  }
  

  
function handleHttpResponse(http_request,c) {

	if (http_request.readyState == 4) {
		// ca sa ii afisam un div cu Loading... sa stie omul ca dureaza - acum nefolosit
		//document.getElementById('loading').style.display = 'none';
            if (http_request.status == 200) {
		switch (c)
		{
			case 'serie':
				document.getElementById('seria_facturii').innerHTML = http_request.responseText;
				break;
			case 'nr_factura':
				document.getElementById('numarul_facturii').innerHTML = http_request.responseText;
				break;
			case 'produse':
				document.getElementById('produse').innerHTML = http_request.responseText;
				break;
		
		}
            } else {
                alert('There was a problem with the request.');
            }
        }
	else
	{
		// ca sa ii afisam un div cu Loading... sa stie omul ca dureaza -nefolosit acum
		//document.getElementById('loading').style.display = 'inline';
	}
		
}



// Sectiune de TOUR Operatori


 
function serie_fact(){
	var index=document.getElementById('tip').selectedIndex;
	var value=document.getElementById('tip').options[index].value

	 getHTTPObject('ajax/factura.php?tip=serie&d='+value,'serie');
	 document.getElementById('asocieri').innerHTML = '';
	

	}



function numar_factura(){
	var index=document.getElementById('id_serie').selectedIndex;
	var value=document.getElementById('id_serie').options[index].value

	 getHTTPObject('ajax/factura.php?tip=nr_factura&d='+value,'nr_factura');
	 document.getElementById('asocieri').innerHTML = '';
	}
	
	

function numar_chitanta(){
	var index=document.getElementById('id_serie').selectedIndex;
	var value=document.getElementById('id_serie').options[index].value

	 getHTTPObject('ajax/chitanta.php?tip=numar_chitanta&d='+value,'nr_factura');
	 document.getElementById('numarul_facturii').innerHTML = '';
	}
function add_product(){
	var value='';
	value+="&produs="+document.getElementById('produse_text').value;
	value+="&cantitate="+document.getElementById('cantitatea').value;
	value+="&pret="+document.getElementById('pret').value;
	
	 getHTTPObject('ajax/factura.php?tip=produs'+value,'produse');
	 document.getElementById('produse_text').value='';
	 document.getElementById('pret').value=''
	 
	}	
	
function schimba(produs){
	getHTTPObject('ajax/factura.php?tip=produs&id_produs='+produs,'produse');
	}

function edit_product(produs){
	var value='';
	value+="&produs="+document.getElementById('produse_text2').value;
	value+="&cantitate="+document.getElementById('cantitatea2').value;
	value+="&pret="+document.getElementById('pret2').value;
	
	 getHTTPObject('ajax/factura.php?tip=produs&edit=1&id_produs='+produs+value,'produse');
	 document.getElementById('produse_text').value='';
	 document.getElementById('pret').value=''
	 
	}	
function sterge(produs){
	if(confirm("Sunteti sigur?"))
		getHTTPObject('ajax/factura.php?tip=produs&sterge=1&id_produs='+produs,'produse');
		
	}
