function playSound() {
	if (ie4) document.all['BGSOUND_ID'].src='sound/beep.mp3';
 	if ((ns4||ns3) && navigator.javaEnabled() && navigator.mimeTypes['audio/x-midi'] && self.document.Bach.IsReady()) {
  		self.document.Bach.play();
 	}
}

function stopSound() {
	if (ie4) document.all['BGSOUND_ID'].src='sound/silence.mp3';
 	if ((ns4||ns3) && navigator.javaEnabled() && navigator.mimeTypes['audio/x-midi']) {
  		self.document.Bach.stop();
 	}
}

function beep() {
   playSound();
}

function beginrefresh(){
	if (!document.images)
		return;
	if (parselimit==1)
		window.location.reload();
	else{ 
		parselimit-=1;
		curmin=Math.floor(parselimit/60);
		cursec=parselimit%60;
		if (curmin!=0)
			curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!";
		else
			curtime=cursec+" until page refresh!";
		window.status=curtime;
		var interval = document.getElementById("interval").value;
		setTimeout("beginrefresh()",interval);
	}
}

function openwin() {
	wwidth=200;
	wheight=150;
	left=(screen.width-wwidth)/2;	
	ftop=(screen.height-wheight)/2;
	features ="height="+wheight+",width="+wwidth+",left="+left+",top="+ftop+",scrollbars=0,status=0";
	window.open("modifica.php","Poza",features);
} 

function modifica(id) {
	wwidth=400;
	wheight=350;
	left=(screen.width-wwidth)/2;	
	ftop=(screen.height-wheight)/2;
	features ="height="+wheight+",width="+wwidth+",left="+left+",top="+ftop+",scrollbars=0,status=0";
	window.open("modifica_produs.php?id="+id,"Poza1",features);
} 

function modificasal(id) {
	wwidth=400;
	wheight=350;
	left=(screen.width-wwidth)/2;	
	ftop=(screen.height-wheight)/2;
	features ="height="+wheight+",width="+wwidth+",left="+left+",top="+ftop+",scrollbars=0,status=0";
	window.open("modifica_salata.php?id="+id,"Poza1",features);
} 

function adauga() {
	wwidth=400;
	wheight=350;
	left=(screen.width-wwidth)/2;	
	ftop=(screen.height-wheight)/2;
	features ="height="+wheight+",width="+wwidth+",left="+left+",top="+ftop+",scrollbars=0,status=0";
	window.open("adauga_produs.php","Poza2",features);
} 

function adaugasal() {
	wwidth=400;
	wheight=350;
	left=(screen.width-wwidth)/2;	
	ftop=(screen.height-wheight)/2;
	features ="height="+wheight+",width="+wwidth+",left="+left+",top="+ftop+",scrollbars=0,status=0";
	window.open("adauga_salata.php","Poza2",features);
} 

function submitform() {
	p = document.getElementById("pass");
	p.value = hex_md5(p.value);
    document.getElementById("loginform").submit();
}

function submituser() {
	p1 = document.getElementById("pass1");
	p2 = document.getElementById("pass2");
	if (p1.value != p2.value) {
		alert("Verifica parola!");
	} else {
		p1.value = hex_md5(p1.value);
		p2.value = hex_md5(p2.value);
    	document.getElementById("formadauga").submit();
	}
}

function submitorder(id) {
	f = "form"+id;
	document.getElementById(f).submit();
}

function Screen() {
	screen_height = screen.height;
	screen_width = screen.width;
	if (screen_height>768 && screen_width>1024) {
		document.getElementById("left").innerHTML = '<img src="images/salate_22.jpg" width="230">';
	}
}

function adaugacos() {
	obj = document.getElementById("altprodus");
	ind = obj.selectedIndex;
	pid = obj.options[ind].value;
	
	obj1 = document.getElementById("altprodus1");
	produs = obj1.options[ind].value;

	cant = document.getElementById("cantalt").value;
		
	txt = document.getElementById("textcomanda");
	if (txt.value)
		txt.value += "\n"+produs+", cantitate: "+cant+" ";
	else
		txt.value = produs+", cantitate: "+cant+" ";
	document.getElementById("idcomanda").value+=pid+"/"+cant+",";
	totprod();
}

function adaugacossal() {
	obj = document.getElementById("salata");
	ind = obj.selectedIndex;
	pid = obj.options[ind].value;
	
	obj1 = document.getElementById("salata1");
	produs = obj1.options[ind].value;

	cant = document.getElementById("cantsal").value;
		
	txt = document.getElementById("textcomanda");
	if (txt.value)
		txt.value += "\n"+produs+", cantitate: "+cant+" ";
	else
		txt.value = produs+", cantitate: "+cant+" ";
	totsalate();
}

function adaugatop() {
	txt = "\nTOPPING: ";
	var tp;
	gasit = 0;
	for (i=1;i<=8;i++) {
		tp = "top"+i;
		if (document.getElementById(tp).checked) {
			gasit = 1;
			ttop = "t"+tp;
			txt += document.getElementById(ttop).innerHTML+" ";
		}
	}
	if (gasit == 1) {
		txt1 = document.getElementById("textcomanda");
		txt1.value += txt;
		tottopping();
	} else
		alert("Va rugam selectati cel putin un topping");
}

function adaugabautura() {
	obj = "cola";
	txt = "\nBAUTURI: ";
	gasit = 0;
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantcola").value;
		txt += cant+" Coca-Cola ";
		if(document.getElementById("cola3").checked)
			txt += " 330 ml ";
		if(document.getElementById("cola5").checked)
			txt += " 500 ml ";
	}
	obj = "colal";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantcl").value;
		txt += cant+" Coca-Cola Light ";
		if(document.getElementById("cola3l").checked)
			txt += " 330 ml ";
		if(document.getElementById("cola5l").checked)
			txt += " 500 ml ";
	}
	obj = "sprite";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantsp").value;
		txt += cant+" Sprite ";
		if(document.getElementById("sprite3").checked)
			txt += " 330 ml ";
		if(document.getElementById("sprite5").checked)
			txt += " 500 ml ";
	}
	obj = "fanta";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantf").value;
		txt += cant+" Fanta ";
		if(document.getElementById("fanta3").checked)
			txt += " 330 ml ";
		if(document.getElementById("fanta5").checked)
			txt += " 500 ml ";
	}
	obj = "energ";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantenerg").value;
		txt += cant+" Energizant Pit bull 330 ml. ";		
	}
	obj = "bere";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantb").value;
		txt += cant+" Bere Carlsberg 330 ml. ";		
	}
	obj = "murf";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantmu").value;
		txt += cant+" Vin alb Murfatlar 250 ml. ";
	}
	obj = "murfr";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantmur").value;
		txt += cant+" Vin rosu Murfatlar 250 ml. ";
	}
	obj = "apa";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantapa").value;
		txt += cant+" Apa plata light Perla Harghitei 500 ml. ";
	}
	obj = "apag";
	if (document.getElementById(obj).checked) {
		gasit = 1;
		cant = document.getElementById("cantag").value;
		txt += cant+" Apa minerala gazoasa 500 ml. ";
	}
	if (gasit == 1) {
		txt1 = document.getElementById("textcomanda");
		txt1.value += txt;
		totbauturi();
	} else
		alert("va rugam selectati cel putin o bautura");
}

function adaugainit() {
	init = document.getElementById("initial").value;
	txt = init;
	cant = document.getElementById("cantitate").value;
	txt += ", cantitate: "+cant+" ";
	txt1 = document.getElementById("textcomanda");
	txt1.value += txt;
	pid = document.getElementById("hidprodid").value;
	document.getElementById("idcomanda").value+=pid+"/"+cant+",";
	
	pret = document.getElementById("pretinit").value;
	pret = getpret(pret);
	tot = pret*cant;
	
	old = document.getElementById("totalplata").value;
	tot += parseFloat(old);
	document.getElementById("totalplata").value = tot;
}

function adaugainit1() {
	init = document.getElementById("initial").value;
	txt = init;
	cant = document.getElementById("cantitate").value;
	txt += ", cantitate: "+cant+" ";
	txt1 = document.getElementById("textcomanda");
	txt1.value += txt;
	
	pret = document.getElementById("pretinit").value;
	pret = getpret(pret);
	tot = pret*cant;
	
	old = document.getElementById("totalplata").value;
	tot += parseFloat(old);
	document.getElementById("totalplata").value = tot;
}

function userinr() {
	tel = document.getElementById("tel_client").value;
	if (tel) {
		cmd = document.getElementById("initial").value;
		ord = document.getElementById("textcomanda").value;
		stat = document.getElementById("idcomanda").value;
		pret = document.getElementById("totalplata").value;
		pretinit = document.getElementById("pretinit").value;
		adr = "submit_order.php?action=check&init="+cmd+"&tel="+tel+"&ord="+ord+"&stat="+stat+"&pret="+pret+"&prinit="+pretinit;
		document.location = adr;
	} else {
		alert("Completati numarul de telefon !");
	}
}

function userinr1() {
	tel = document.getElementById("tel_client").value;
	if (tel) {
		ord = document.getElementById("textcomanda").value;
		stat = document.getElementById("idcomanda").value;
		pret = document.getElementById("totalplata").value;
		adr = "comanda.php?action=check&tel="+tel+"&ord="+ord+"&pret="+pret+"&stat="+stat;
		document.location = adr;
	} else {
		alert("Completati numarul de telefon !");
	}
}


function userinr2() {
	tel = document.getElementById("tel_client").value;
	if (tel) {
		cmd = document.getElementById("initial").value;
		ord = document.getElementById("textcomanda").value;
		pret = document.getElementById("totalplata").value;
		adr = "salate.php?action=check&init="+cmd+"&tel="+tel+"&ord="+ord+"&pret="+pret;
		document.location = adr;
	} else {
		alert("Completati numarul de telefon !");
	}
}

function submit1() {
	tel = document.getElementById("tel_client").value;
	adr = document.getElementById("adresa_client").value;
	num = document.getElementById("nume_client").value;
	
	if (!tel||!adr||!num)
		alert("Va rugam completati toate informatiile de contact");
	else {	
		ord = document.getElementById("textcomanda").value;
		if (ord) {
			document.getElementById("hidtextcomanda").value = ord;
			ord = document.getElementById("totalplata").value;
			document.getElementById("hidtotal").value = ord;
			document.forms[0].submit();
		} else
			alert("Nu ati facut nici o comanda");
	}
}

function anuleaza() {
	document.getElementById("textcomanda").value = "";
	document.getElementById("idcomanda").value = "";
	document.getElementById("totalplata").value = "0";
}

function getpret(pret) {
	if (pret.indexOf(",")>=0)
		arr = pret.split(",");
	else
		arr = pret.split(".");
	pr = arr[0];	
	return pr;
}

function totsalate() {
	obj = document.getElementById("salata");
	ind = obj.selectedIndex;
	obj1 = document.getElementById("hidprsal");
	pret = obj1.options[ind].value;
	cant = document.getElementById("cantsal").value;	
	pret = getpret(pret);	
	tot = pret*cant;
	//return tot;
	old = document.getElementById("totalplata").value;
	tot += parseFloat(old);
	document.getElementById("totalplata").value = tot;
}

function totprod() {
	obj = document.getElementById("altprodus");
	ind = obj.selectedIndex;
	obj1 = document.getElementById("hidpret");
	pret = obj1.options[ind].value;
	cant = document.getElementById("cantalt").value;	
	pret = getpret(pret);	
	tot = pret*cant;
	//return tot;	
	old = document.getElementById("totalplata").value;
	tot += parseFloat(old);
	document.getElementById("totalplata").value = tot;
}

function tottopping() {
	tot = 0;
	for (i=1;i<=8;i++) {
		tp = "top"+i;
		if (document.getElementById(tp).checked) {
			tot++;
		}
	}
	tot *= 2;
	//return tot;
	old = document.getElementById("totalplata").value;
	tot += parseFloat(old);
	document.getElementById("totalplata").value = tot;
}

function totbauturi() {
	obj = "cola";
	tot = 0;
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantcola").value;
		if(document.getElementById("cola3").checked) 
			tot += 3*cant;
		if(document.getElementById("cola5").checked)
			tot += 3*cant;
	}
	obj = "colal";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantcl").value;
		if(document.getElementById("cola3l").checked)
			tot += 3*cant;
		if(document.getElementById("cola5l").checked)
			tot += 3*cant;
	}
	obj = "sprite";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantsp").value;		
		if(document.getElementById("sprite3").checked)
			tot += 3*cant;
		if(document.getElementById("sprite5").checked)
			tot += 3*cant;
	}
	obj = "fanta";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantf").value;		
		if(document.getElementById("fanta3").checked)
			tot += 3*cant;
		if(document.getElementById("fanta5").checked)
			tot += 3*cant;
	}
	obj = "energ";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantenerg").value;
		tot += 3.8*cant;
	}
	obj = "bere";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantb").value;
		tot += 3.4*cant;
	}
	obj = "murf";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantmu").value;
		tot += 4.5*cant;
	}
	obj = "murfr";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantmur").value;
		tot += 4.5*cant;
	}
	obj = "apa";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantapa").value;
		tot += 1.6*cant;
	}
	obj = "apag";
	if (document.getElementById(obj).checked) {
		cant = document.getElementById("cantag").value;
		tot += 1.4*cant;
	}
	//return tot;
	old = document.getElementById("totalplata").value;
	tot += parseFloat(old);
	document.getElementById("totalplata").value = tot;
}
