//Browser Support Code
function ajaxFunction(id){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState==4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	
	nrbuc = document.getElementById('buc'+id).value;
	
	var queryString = "?id=" + id + "&nrbuc=" + nrbuc;
	ajaxRequest.open("GET", "updatecos.php" + queryString, true);
	ajaxRequest.send(null); 
	
	document.getElementById("buc"+id).style.color="#eb7b1c";
	document.getElementById("buc"+id).style.fontWeight ="bold";
}

function scadeBuc(obi){
	if(document.getElementById(obi).value > 1)
		document.getElementById(obi).value --;
}

function cresteBuc(obi){
	if(document.getElementById(obi).value < 100)
		document.getElementById(obi).value ++;
}

i = 1;
categ = 0;
z=1;
function setProdNr(obi,cat,id){

	nrprod = document.getElementById(obi+'txt').value;
	
	if(categ != cat)
	{
		if(nrprod != '0'){
			z=1;
			i = parseInt(nrprod) + 1;
		}
		else{
			i=1;
		}
		categ = cat;
	}
	else
	{
		if(nrprod != '0'){
			z++;
		}
		i++;
	}
	
	document.getElementById("subm" + id).setAttribute("onclick","ajaxFunction("+id+")")
	
	if(i != 1){
		document.getElementById(obi).innerHTML = i + " produse in cos";
	}
	else{
		document.getElementById(obi).innerHTML = i + " produs in cos";
	}
}
