function set_price(){
	var selector 		 = document.getElementById('setprice');
	var price1	 		 = Number(selector.options[selector.selectedIndex].value);

	document.getElementById('price').innerHTML = price1;
	//document.getElementById('newprice').value = price;
}

var request = false;
    try {
      request = new XMLHttpRequest();
    } catch (trymicrosoft) {
      try {
        request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (othermicrosoft) {
        try {
          request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (failed) {
          request = false;
        }
      }
    }

    if (!request)
      alert("Error initializing XMLHttpRequest!");

function loadResponse(){
	if (request.readyState == 4) {
	     if(request.status == 200){
		 	var result = request.responseText;
			document.getElementById("update_ajax").innerHTML = result;
		 }
	}
}


function refresh_price(id,price){
	var quantity  = document.getElementById('quantity_'+id).value;
	var old_price = document.getElementById('quantity_max_'+id).value;
	var price_all = document.getElementById('price_all').innerHTML;

	var price_new = quantity*parseFloat(price);

	var old_price_new = parseFloat(price_all) - parseFloat(old_price);

	var new_price = parseFloat(price_new) + parseFloat(old_price_new);

	document.getElementById('quantity_max_'+id).value = price_new;
	document.getElementById('price_all').innerHTML = new_price;

	var times = Number(new Date());

	var url = "update_quantity.php?quantity="+quantity+"&id="+id+"&times="+times;

	request.open("GET", url, true);
	request.onreadystatechange = loadResponse;
	request.send(null);
}

function delete_product(id,link){
		var answer = confirm("Сигурни ли сте че искате да изтриете продукта?");
	if (answer == true){
		alert("Продукта беше изтрит успешно!");
		window.location = "delete.php?id="+id;
	}
	  else{
	 	window.location = link;
	  }
}

function submit() {
	 document.forma.submit();
}

function dobavi(id, product_id, price){

	//var selector		    = document.getElementById('setprice');
	//var idselector		= Number(selector.options[selector.selectedIndex].value);

	window.location = "cart.php?id="+id+"&product_id="+product_id+"&price="+price;
}

