
function add_comand(id,nume,pret){

	add_ajax(nume,pret);
	
}

function add_topping(id,nume,pret,afis,id_link){
	var x=document.getElementById(id);
	
	for (i=1;i<10;i++){
		y=document.getElementById('topping'+i);
		y.innerHTML='';
	}
	
	if(afis=='y'){
		x.innerHTML ='<form action="" onsubmit="check_topping(\''+id+'\',\''+nume+'\',\''+pret+'\',\''+id_link+'\');return false;" onreset="add_topping(\''+id+'\',\'n\',\''+id_link+'\')"><table border=0 width=480 style="border:1px solid #000000"><tr><td><input type=checkbox id=che1 value="sunca"></td><td>sunca <input type="text" id=cha11 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che2 value="parmezan"></td><td>parmezan <input type="text" id=cha21 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che3 value="masline"></td><td>masline <input type="text" id=cha31 value="2.5" readonly style="width:30px;"></td></tr><tr><td><input type=checkbox id=che4 value="piept de pui"></td><td>piept de pui <input type="text" id=cha41 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che5 value="cascaval vegetal"></td><td>cascaval vegetal <input type="text" id=cha51 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che6 value="ardei gras"></td><td>ardei gras <input type="text" id=cha61 value="1" readonly style="width:30px;"></td></tr><tr><td><input type=checkbox id=che7 value="carnaciori"></td><td>carnaciori<input type="text" id=cha71 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che8 value="gorgonzola"></td><td>gorgonzola <input type="text" id=cha81 value="3.5" readonly style="width:30px;"></td><td><input type=checkbox id=che9 value="porumb"></td><td>porumb <input type="text" id=cha91 value="1" readonly style="width:30px;"></td></tr><tr><td><input type=checkbox id=che10 value="mozzarella"></td><td>mozzarella <input type="text" id=cha101 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che11 value="ardei iute"></td><td>ardei iute <input type="text" id=cha111 value="1" readonly style="width:30px;"></td></tr><tr><td><input type=checkbox id=che12 value="ton"></td><td>ton <input type="text" id=cha121 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che13 value="cascaval"></td><td>cascaval <input type="text" id=cha131 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che14 value="ceapa"></td><td>ceapa <input type="text" id=cha141 value="1" readonly style="width:30px;"></td></tr><tr><td><input type=checkbox id=che15 value="bacon"></td><td>bacon <input type="text" id=cha151 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che16 value="oregano"></td><td>oregano <input type="text" id=cha161 value="1" readonly style="width:30px;"></td><td><input type=checkbox id=che17 value="rosii"></td><td>rosii <input type="text" id=cha171 value="1" readonly style="width:30px;"></td></tr><tr><td><input type=checkbox id=che18 value="prosciuto crud"></td><td>prosciuto crud <input type="text" id=cha181 value="3.5" readonly style="width:30px;"></td><td><input type=checkbox id=che19 value="ciuperci"></td><td>ciuperci <input type="text" id=cha191 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che20 value="banana"></td><td>banana <input type="text" id=cha201 value="1" readonly style="width:30px;"></td></tr><tr><td><input type=checkbox id=che21 value="chorizo"></td><td>chorizo <input type="text" id=cha211 value="2.5" readonly style="width:30px;"></td><td><input type=checkbox id=che22 value="ananas"></td><td>ananas <input type="text" id=cha221 value="1" readonly style="width:30px;"></td></tr><tr><td colspan=3 align=center><input type=reset value=Renunta></td><td colspan=3 align=center><input type=submit value=Comanda></td></tr></table></form>';
		
		z=document.getElementById(id_link);
		z.href="javascript:add_topping(\'"+id+"\',\'"+nume+"\',\'"+pret+"\',\'n\',\'"+id_link+"\');";
	}
	
	if(afis=='n'){
		x.innerHTML='';	
		z=document.getElementById(id_link);
		z.href="javascript:add_topping(\'"+id+"\',\'"+nume+"\',\'"+pret+"\',\'y\',\'"+id_link+"\');";
	}
}

function check_topping(id,nume,pret,id_link){
	
	
	
	var x=document.getElementById(id);
	//add_comand(id,nume,pret);
	
	tops=nume+"/";
	preturi=pret+"/";
	
	for(i=1;i<=22;i++){
		x=document.getElementById("che"+i);
		x2=document.getElementById("cha"+i+"1");
		
		if(x.checked==true){
			
			tops+=","+x.value;
			preturi+=","+x2.value;
			
		}
		
	}
	
	add_comand('1',tops,preturi);
	add_topping(id,nume,pret,'n',id_link);
}


function question0(){
	
	alert("Comanda minima este de doua pizza!");
	
}

function question1(){
	
	
		question2();
	
}
function question2(){	
	
		question3();
}

function question3(){	
	window.open("finalizeaza-comanda.php","_self");
}


var xmlHttp = new Array();
var url

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {// Internet Explorer
 try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
 catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
 }
return xmlHttp;
}

function stateChanged(id){
	
	if (xmlHttp[id].readyState==4){ 
		document.getElementById("calculator").innerHTML=xmlHttp[id].responseText;
	}

}

function onload_ajax(){
	
	xmlHttp[1]=GetXmlHttpObject(); 
	
	url="ajax.php";
	
	xmlHttp[1].onreadystatechange=function () { stateChanged('1'); };
	xmlHttp[1].open("GET",url,true);
	xmlHttp[1].send(null);

}

function add_ajax(nume,pret){

	xmlHttp[2]=GetXmlHttpObject(); 
	
	url="ajax.php";
	url=url+"?action=add&nume="+nume+"&pret="+pret;
	
	xmlHttp[2].onreadystatechange=function () { stateChanged('2'); };
	xmlHttp[2].open("GET",url,true);
	xmlHttp[2].send(null);
	
}


function del_ajax(nr){
	
	xmlHttp[3]=GetXmlHttpObject(); 
	
	url="ajax.php";
	url=url+"?action=del&nr="+nr;
	
	xmlHttp[3].onreadystatechange=function () { stateChanged('3'); };
	xmlHttp[3].open("GET",url,true);
	xmlHttp[3].send(null);
	
}

function schimba_cartier(c){
	cart = document.getElementById("cartier");
	x1=cart.cells[0];
	x1.innerHTML = '*Cartier: ';
	
	x2=document.form_comanda.cartier;
	x2.innerHTML='';
	x2.style.display='block';
	
	var x;
	
	switch (c){
		case '1': 

			var sectoare = new Array("Centru","Aviatorilor-Kiseleff","Aviatiei-Pipera","1 Mai","Primaverii","Floreasca",
									 "Herastrau","Baneasa","Bucurestii noi","Grivita","Pajura","Chitila","Damaroaia");
			
		
		break;
		case '2':	
			var sectoare = new Array("Iancului","Pantelimon","Vatra Luminoasa","Baicului","Colentina","Mosilor","Obor",
									 "Stefan cel Mare","Tei","Andronache","Pipera","Floreasca");
			
		break;
		case '3':
			var sectoare = new Array("Centru","Dristor","Dudesti","Muncii","Titan","Vitan","Alba Iulia","Traian");
			
		break;
		case '4':	
			var sectoare = new Array("Centru","Progresul","Aparatorii Patriei","Oltenitei","Berceni","Oltenitei",
									 "Tineretului","Vacaresti");
			
		break;
		case '5':
			var sectoare = new Array("Centru","13 Septembrie","Cotroceni","Ferentari","Rahova",
									 "Salaj","Ghencea","Odai");
			
		break;
		case '6':
			var sectoare = new Array("Crangasi","Ghencea","Giulesti","Drumul Taberei","Militari","Grozavesti","Brancusi");
			
		break;
	}
	
	for (x in sectoare){
		y=document.createElement('option');
		y.value=sectoare[x];
		y.text=sectoare[x];
		
		try
		{
		x2.add(y,null); // standards compliant
		}
	  catch(ex)
		{
		x2.add(y); // IE only
		}
		
		
	}
	
}

function check_submit(){
	var x= document.form_comanda;
	
	if(x.nume.value.length < 3) {
		alert("Completati numele si prenumele!");
		x.nume.focus();
		return false;
	}
	
	if(x.telefon.value.length < 6) {
		alert("Completati telefonul!");
		x.telefon.focus();
		return false;
	}
	
	if(x.strada.value.length < 2) {
		alert("Completati strada!");
		x.strada.focus();
		return false;
	}
	
	if(x.nr_strada.value.length < 1) {
		alert("Completati nr_strada!");
		x.nr_strada.focus();
		return false;
	}
	
	if(x.sector.value.length < 1) {
		alert("Completati sectorul!");
		x.sector.focus();
		return false;
	}
	
	//ajax_insert_comand();
	return true;
}


