var oldValue = "";

function kosarba(sor_id, meret_id, betet_id){
	var darab = document.getElementById("darab_" + sor_id + "_" + meret_id).value;
	if (darab >= 0) {
		window.frames["kosar"].document.getElementById("sor_id").value = sor_id;
		window.frames["kosar"].document.getElementById("meret_id").value = meret_id;
		if (!betet_id) { betet_id = "0"; }
		window.frames["kosar"].document.getElementById("betet_id").value = betet_id;
		window.frames["kosar"].document.getElementById("darab").value = darab;
		window.frames["kosar"].document.getElementById("action").value = "set";
		window.frames["kosar"].document.getElementById("kuld").click();
	} else {
		alert("Hibás formátum!");
	}
}

function torol(id){ 
	document.getElementById("kosar_id").value = id;
	document.getElementById("action").value = "del";
	document.getElementById("kuld").click();
}

function checkData(){
	
	var obj = document.getElementById("nev");
	if (obj.value == "") {
		alert("A név mezőt kötelező kitölteni!");
		obj.focus();
		return 0;
	}
	
	obj = document.getElementById("varos");
	if (obj.value != "Budapest") {
		alert("Jelenleg csak Budapesten van kiszállítís!");
		obj.focus();
		return 0;
	}
	
	obj = document.getElementsByTagName("option")[document.getElementById("ker").selectedIndex];
	if (obj.value == "") {
		alert("Kérjük válasszon kerületet!");
		return 0;
	}
	
	obj = document.getElementById("cim");
	if (obj.value == "") {
		obj.focus();
		alert("A Cím mezőt kötelező kitölteni!");
		return 0;
	}
	
	obj = document.getElementById("tel");
	if (obj.value == "") {
		alert("Kérjük adjon meg egy telefonszámot!");
		obj.focus();
		return 0;
	} else {
		if (obj.value.length < 7) {
			alert("Érvénytelen telefonszám formátum!");
			obj.focus();
			return 0;
		}
	}
		
	if (!ValidateForm(document.getElementById("mail"))) {
		return 0;	
	}
	document.getElementById('adatok').action = "php/rend_kuld.php";
	document.getElementById('kuld').click();
}

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Érvénytelen E-amil cím formátum!");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Érvénytelen E-amil cím formátum!");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Érvénytelen E-amil cím formátum!");
			return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			alert("Érvénytelen E-amil cím formátum!");
			return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Érvénytelen E-amil cím formátum!");
			return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Érvénytelen E-amil cím formátum!");
			return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
			alert("Érvénytelen E-amil cím formátum!");
			return false;
		 }

		 return true;					
	}

function ValidateForm(mail){
	var emailID=mail;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Kérjük adjon meg egy E-mail címet!");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
 }
 
function getHeight() {
	window.parent.setHeight(document.body.clientHeight + 20);
}

function setHeight(h) {
	window.parent.document.getElementById("kosar").height = h;
}
