// cookie handlers
function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
}
		
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

// orders
function multiorder(id) {
	var string = "";
	// lekerdezem a darabszamot es az egysegarat 26-osra
	var count26 = parseInt(document.getElementById("count26_"+id).value);
	if ( isNaN(count26) ) { count26 = 0; }
	// lekerdezem a darabszamot es az egysegarat 30-asra
	var count30 = parseInt(document.getElementById("count30_"+id).value);
	if ( isNaN(count30) ) { count30 = 0; }
	// lekerdezem a darabszamot es az egysegarat 45-ösre
	var count45 = parseInt(document.getElementById("count45_"+id).value);
	if ( isNaN(count45) ) { count45 = 0; }

	if ( count26 > 0 ) {
		var eddigi = getCookie("corleone_basket");
		var mostani = eddigi+' '+id+'.26'+'_'+count26;
		setCookie("corleone_basket",mostani,1);
		string = '26-os méretből '+count26+' darab ';
	}
	
	if ( count30 > 0 ) {
		if ( string != "" ) { string = string+'és '; }
		var eddigi = getCookie("corleone_basket");
		var mostani = eddigi+' '+id+'.30'+'_'+count30;
		setCookie("corleone_basket",mostani,1);
		string = string+'30-as méretből '+count30+' darab ';
	}
	
	if ( count45 > 0 ) {
		if ( string != "" ) { string = string+'és '; }
		var eddigi = getCookie("corleone_basket");
		var mostani = eddigi+' '+id+'.45'+'_'+count45;
		setCookie("corleone_basket",mostani,1);
		string = string+'45-ös méretből '+count45+' darab ';
	}
	
	if ( string != "" ) {
		string = string+'hozzáadva a kosárhoz! A termékek tényleges megrendeléséhez menjen a kosár menüpontba! Ha még mást is kíván rendelni, először azokat is helyezze a kosarába!';
		alert(string);
	} else {
		alert("nincs mit hozzáadni");
	}
}

function singleorder(id) {
	// lekerdezem a darabszamot es az egysegarat
	var count = parseInt(document.getElementById("count_"+id).value);
	if ( isNaN(count) ) { count = 0; }

	if ( count > 0 ) {
		var eddigi = getCookie("corleone_basket");
		var mostani = eddigi+' '+id+'_'+count;
		setCookie("corleone_basket",mostani,1);
		alert(string = 'a termékből '+count+' darab hozzáadva a kosárhoz! A termékek tényleges megrendeléséhez menjen a kosár menüpontba! Ha még mást is kíván rendelni, először azokat is helyezze a kosarába!');
	} else {
		alert("nincs mit hozzáadni");
	}

}

// calculations
function recalc26(id) {
	// lekerdezem a darabszamot es az egysegarat 26-osra
	var count26 = parseInt(document.getElementById("count26_"+id).value);
	var price26 = parseInt(document.getElementById("divid26_"+id).title);

	if ( !isNaN(count26) || count26 == 0 ) {
		document.getElementById("price26_"+id).value = price26*count26;
	} else {
		document.getElementById("price26_"+id).value = "";
	}

	if ( document.getElementById("price26_"+id).value <= 0 ) {
		document.getElementById("price26_"+id).value = "";
		document.getElementById("count26_"+id).value = "";
	}
}

function recalc30(id) {
	// lekerdezem a darabszamot es az egysegarat 30-asra
	var count30 = parseInt(document.getElementById("count30_"+id).value);
	var price30 = parseInt(document.getElementById("divid30_"+id).title);

	if ( !isNaN(count30) ) {
		document.getElementById("price30_"+id).value = price30*count30;
	} else {
		document.getElementById("price30_"+id).value = "";
	}

	if ( document.getElementById("price30_"+id).value <= 0 ) {
		document.getElementById("price30_"+id).value = "";
		document.getElementById("count30_"+id).value = "";
	}
}

function recalc45(id) {
	// lekerdezem a darabszamot es az egysegarat 45-ösre
	var count45 = parseInt(document.getElementById("count45_"+id).value);
	var price45 = parseInt(document.getElementById("divid45_"+id).title);

	if ( !isNaN(count45) ) {
		document.getElementById("price45_"+id).value = price45*count45;
	} else {
		document.getElementById("price45_"+id).value = "";
	}

	if ( document.getElementById("price45_"+id).value <= 0 ) {
		document.getElementById("price45_"+id).value = "";
		document.getElementById("count45_"+id).value = "";
	}
}

function recalc00(id) {
	// lekerdezem a darabszamot es az egysegarat
	var count = parseInt(document.getElementById("count_"+id).value);
	var price = parseInt(document.getElementById("divid_"+id).title);

	if ( !isNaN(count) ) {
		document.getElementById("price_"+id).value = price*count;
	} else {
		document.getElementById("price_"+id).value = "";
	}

	if ( document.getElementById("price_"+id).value <= 0 ) {
		document.getElementById("price_"+id).value = "";
		document.getElementById("count_"+id).value = "";
	}
}

