function order_change_image(curdiv,radioid,bg_path,changecbx) {

	if (bg_path != "") {
		document.getElementById(curdiv).style.backgroundImage="url("+bg_path+")";
	}
	if (radioid != "") {
		var y=document.getElementById('qty__'+radioid);
		var x=document.getElementById(radioid);
		if(x.checked) {
			x.checked=false;
			y.value=0;
		} else {
			x.checked=true;
			y.value=1;
		}
	}
}


function order_change_image_cbx(curdiv,radioid,bg_path,changecbx) {

	if (bg_path != "") {
		document.getElementById(curdiv).style.backgroundImage="url("+bg_path+")";
	}

		var y=document.getElementById('qty__'+radioid);
		var x=document.getElementById(radioid);
		var tagname = x.tagName;
		if(x.checked) {
			y.value=1;
		} else {
			y.value=0;
		}
}

function order_change_cbx(radioid) {

		var y=document.getElementById('qty__'+radioid);
		var x=document.getElementById(radioid);
		if(y.value > 0) {
			x.checked = true;
		} else {
			x.checked = false;
		}
}

function set_value(phpfile,gets,divid)
{
if (gets=="")
  {
  document.getElementById(divid).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(divid).innerHTML=xmlhttp.responseText;
    }
  }
url=phpfile+"?"+gets
url=url+"&sid="+Math.random();
xmlhttp.open("GET",url,true);
xmlhttp.send();
}

String.prototype.reverse = function(){
	splitext = this.split("");
	revertext = splitext.reverse();
	reversed = revertext.join("");
	return reversed;
}

function allprice(inputid,add) {

	var inputs = document.getElementsByTagName('input');
	var price = 0;
	var qty = 0;
	var all_amount=0;
	var message
	var out
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].getAttribute('type') == "input") {
		inputid2 = inputs[i].getAttribute('id');
		qty = Math.round(document.getElementById(inputid2).value);
		price = document.getElementById('hidden_'+inputid2).value;
		if (qty > 1 && inputid==inputid2) amount = price*(qty-(-1)*add);
 		else if (qty == 1 && inputid==inputid2 && add==1) amount = price*(qty-(-1)*add);
		else amount = price*qty;
		all_amount = all_amount-(-1)*amount;
		}
	}
	all_amount_s = all_amount.toString();
	var str_all='';
	var maradek=0;
	var o=0;
	var all_amount_sr = all_amount_s.reverse();
	for (var i = 0; i <= all_amount_sr.length; i++) {
		if (((o-1)%3)==0) {
			str_all += ' ';
		}
		o++;
		str_all += all_amount_sr.substring((i-1),i);
	}
	var str_all_rev = str_all.reverse();
	if (all_amount >= document.getElementById('transit').value) out=str_all_rev + ' Ft';
	else out=str_all_rev + ' Ft ' + document.getElementById('transit_text').value;
	document.getElementById('allprice').innerHTML = out;
}

function cart_change_price_qty(phpfile,gets,divid,dividprice,inputid,productprice){
	set_value(phpfile,gets,divid);
	var qty=Math.round(document.getElementById(inputid).value);
	var price;
	if (qty == 1)  price = productprice*qty;
	else price = productprice*(qty-1);
	document.getElementById(dividprice).innerHTML = price + " Ft";
	allprice(inputid,-1);

}

function cart_change_price_qty2(phpfile,gets,divid,dividprice,inputid,productprice){
	set_value(phpfile,gets,divid);
	var qty=Math.round(document.getElementById(inputid).value-(-1));
	var price = productprice*qty;
	document.getElementById(dividprice).innerHTML = price + " Ft";
		allprice(inputid,1);

}


function rendeles_galeria(curdiv,radioid,bg_path,phpfile,gets,divid) {
	order_change_image(curdiv,radioid,bg_path);
	set_value(phpfile,gets,divid);
}

function show_assoc(elid,size) {

	document.getElementById(elid).width = size;

}

function order_read_input_value(phpfile,gets,divid,inputid,dividprice,productprice) {
	var x=document.getElementById(inputid);
	var qty=Math.round(x.value);
	if (qty <=0 ) {
		qty=1;
		x.value = 1;
	}
	var y=document.getElementById(divid);
	setTimeout(function (){y.focus()}, 5);
	var gets2 = gets + '/' + x.value;
	set_value(phpfile,gets2,divid);

	var price = productprice*qty;
	document.getElementById(dividprice).innerHTML = price + " Ft";
	allprice(inputid,0);
}

function rollover_image(imgid,imgpath) {
	var x=document.getElementById(imgid);
	x.src=imgpath;


}

function part(adat,minta){
for (var i=0; i<adat.length; i++)
	if (minta.indexOf(adat.charAt(i)) == -1)
	return false;
	return true;
}

function numerikusCheck(value){
	if (part(value,"1234567890"))
		return true;
	else{
		return false;
	}

}

function tartalmaz(adat,minta){
	for (var i=0; i<adat.length; i++)
		if (minta.indexOf(adat.charAt(i)) != -1)
		return true;
	return false;
}

function telefonCheck(mezo){
	if (part(string,"1234567890+()/- ") &&
		tartalmaz(string,"1234567890"))
		return true;
	else{
		return false;
	}
}

function checkForm(checkid,type,text) {
	var x=document.getElementById(checkid);
	string = x.value;


	if (string != '') {
		if (type=='') return true;

		if (type=='email') {
			if (string != null && string.length > 2  && string.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)) {
				return true;
			} else {
				jAlert(text,'Figyelem');
				return false;
			}
		}
		if (type=='numeric') {
			if(numerikusCheck(string)) {
				return true;
			} else {
				jAlert(text,'Figyelem');
				return false;
			}
		}
		if (type=='tel') {
			if(telefonCheck(string)) {
				return true;
			} else {
				jAlert(text,'Figyelem');
				return false;
			}
		}
	} else {
		x.style.borderstyle = 'solid';
		x.style.bordercolor = 'red';
		x.style.borderwidth = 1;
		jAlert(text,'Figyelem');

		return false;
	}

	if (type=='cbx') {
		if(x.checked) return true;
		else {
			jAlert(text,'Figyelem');
			return false;
		}
	}

}

function ismaxlength(obj){
		var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
		if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength)
}
