window.onloadListeners=new Array();

window.addOnLoadListener = function (listener, params) {
	window.onloadListeners[window.onloadListeners.length] = listener;
}

window.onload=function(){

	for (var i=0;i<window.onloadListeners.length;i++) {
		func = window.onloadListeners[i];
		func.call();
	}
}

function open_popup(pURL,name,w,h,scrollbars,resizable)
{
	if (resizable==null) resizable=1;
	if (scrollbars==null) scrollbars=1;
	var top  = ((screen.availHeight-h)/2);
	var left = ((screen.availWidth-w)/2);
	var nyit = window.open(pURL,name,'toolbar=0,location=0,directories=0,status=0,\
		menubar=0,scrollbars='+scrollbars+',resizable='+resizable+',width='+w+',height='+h+',top='+top+',left='+left);
	nyit.focus();
	return nyit;
}

function open_popup2(pURL,name,w,h,scrollbars,resizable)
{
	if (resizable==null) resizable=1;
	if (scrollbars==null) scrollbars=0;
	var top  = ((screen.availHeight-h)/2);
	var left = ((screen.availWidth-w)/2);
	var nyit = window.open(pURL,name,'toolbar=0,location=0,directories=0,status=0,\
		menubar=1,scrollbars='+scrollbars+',resizable='+resizable+',width='+w+',height='+h+',top='+top+',left='+left);
	nyit.focus();
	return false;
}



function addquotes(str)
{
	var re = /(['"])/g;
	return str.replace(re,function ($0, $1) {
	switch($1)
	{
		case '"':
		return "&quot;";
		case '&':
		return "&amp;";
		default:
		return $1;
	}});
}

function pop_kep(kep,label,w,h)
{
	var ablak=open_popup('about:blank','nagykep',w,h,0,0);
	var d=ablak.document;
	var title=(label.length>0) ? label+' - ' : '';
	d.write('<html><head><title>',addquotes(title),
		'</title></head><body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">',
		'<a name="nagykep" href="#" onclick="self.close();" onblur="self.close()">',
		'<img border="0" alt="',addquotes(label),'" src="',addquotes(kep),'" width="',w,'" height="',h,'"></a></body></html>');
	d.anchors[0].focus();

}

function pop_inner(inner,label,w,h)
{
	var ablak=open_popup('about:blank','inner_popup',w,h,1,0);
	var d=ablak.document;
	var title=(label.length>0) ? label+' - ' : '';
	d.write('<html><head><title>',title,
		'</title>\n',
		'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">\n',
		'<link rel=stylesheet type="text/css" href="/client.css">\n</head>\n',
		'<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">\n',
		inner,
		'\n</body>\n</html>\n');
	d.close();
}


function add_to_basket (id) {
	form1 = document.forms['pr'];
	form2 = document.forms['products'];
	form1.elements["doc_id"].value = id;
	form1.elements["piece"].value = form2.elements['pr_'+id].value;
	if (form2.elements['pr_'+id].value>=0)
	{
		form1.submit();
	}

}


//<input type="hidden" name="doc_id" value="">
//<input type="hidden" name="piece" value="">

function setPage(form, page) {
	form = document.forms[form];
	element = form.elements["page"];
	element.value = page;
	form.elements["t_number"].value =document.forms['tnumber'].elements["t_number"].value;
	form.submit();
}

function JumpToURL(targ,selObj,restore){
	if (selObj.options[selObj.selectedIndex].value) {
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
	}
}
//felsõmenü mouseoverjéhez:
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function openBox(objID) {
//alert (root_ids.length);
	for (i=0;i< root_ids.length; i++ ) {
		//alert (objID);
		//alert (root_ids[i]);
		if ((objID!=root_ids[i])) {// && (actual_root_id!=objID)
			CloseBox(root_ids[i]);
		}
	}
	for (i=0;i< submenu_ids.length; i++ ) {
		CloseBox(submenu_ids[i]);
	}
	if (document.getElementById(objID)) {
		document.getElementById(objID).style.display = "block";
		actual_root_id = objID;
	}
}

function openBox2(objID) {
	if (document.getElementById(objID)) {
		document.getElementById(objID).style.display = "block";
	}
}

function CloseBox(objID) {
	if (document.getElementById(objID)) {
		document.getElementById(objID).style.display = "none";
	}
}

/*

function openBox(objID) {
//alert (root_ids.length);
	for (i=0;i< root_ids.length; i++ ) {
		//alert (objID);
		//alert (root_ids[i]);
		if ((objID!=root_ids[i]) && (objID!='box_717') && (objID!='box_784')) {
			CloseBox(root_ids[i]);
		}
	}
	if (document.getElementById(objID)) {
		document.getElementById(objID).style.display = "block";
	}

}

function openBox2(objID) {
	if (document.getElementById(objID)) {
		document.getElementById(objID).style.display = "block";
	}

}

function CloseBox(objID) {
	if (document.getElementById(objID)) {
		document.getElementById(objID).style.display = "none";
	}
}
*/

function AddIfValid(field) {
   if ((field.value.length == 0) || (field.value == null) || (isNaN(field.value.toString().replace(/\./g,'')))) {
       return 0;
   } else {
       return eval(field.value.toString().replace(/\./g,''));
   }

}

function MakeSum() {
   var t = 0;

   t += AddIfValid(document.myform.pva_1);
//   t += AddIfValid(document.myform.pva_2)*arfolyam_js;
   t += AddIfValid(document.myform.pva_3);
   t += AddIfValid(document.myform.pva_4);
   t += AddIfValid(document.myform.pva_5);
   t += AddIfValid(document.myform.pva_6);
   t += AddIfValid(document.myform.pva_7);
//   t += AddIfValid(document.myform.pva_8);
//   t += AddIfValid(document.myform.pva_9);
   t += AddIfValid(document.myform.pva_10);
//   t += AddIfValid(document.myform.pva_11);
//   t += AddIfValid(document.myform.pva_12);
//   t += AddIfValid(document.myform.pva_13);
//   t += AddIfValid(document.myform.pva_14);
//   t += AddIfValid(document.myform.pva_15);
//   t += AddIfValid(document.myform.pva_16);
//   t += AddIfValid(document.myform.pva_17);
//   t += AddIfValid(document.myform.pva_18);
//   t += AddIfValid(document.myform.pva_19);
   t += AddIfValid(document.myform.pva_20);
   if (t !== 0)
   {
   document.getElementById("full_money").innerHTML = '<b>'+formatCurrency(Math.round(t))+' FT</b>';
   }


   if (!isNaN(document.myform.pva_1.value.toString().replace(/\./g,'')) && (document.myform.pva_1.value != '') && (document.myform.pva_1.value != null)  && (document.myform.pva_1.value != '0')) {
		document.getElementById("pva_1_div").innerHTML = (Math.round((document.myform.pva_1.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_1_div").innerHTML = '&nbsp;';
   }
   /*if (!isNaN(document.myform.pva_2.value.toString().replace(/\./g,'')) && (document.myform.pva_2.value != '') && (document.myform.pva_2.value != null) && (document.myform.pva_2.value != '0')) {
		document.getElementById("pva_2_div").innerHTML = (Math.round(((document.myform.pva_2.value.toString().replace(/\./g,'')*arfolyam_js)/t)*100))+" %";
   } else {
		document.getElementById("pva_2_div").innerHTML = '&nbsp;';
   }*/
   if (!isNaN(document.myform.pva_3.value.toString().replace(/\./g,'')) && (document.myform.pva_3.value != '') && (document.myform.pva_3.value != null) && (document.myform.pva_3.value != '0')) {
		document.getElementById("pva_3_div").innerHTML = (Math.round((document.myform.pva_3.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_3_div").innerHTML = '&nbsp;';
   }
   if (!isNaN(document.myform.pva_4.value.toString().replace(/\./g,'')) && (document.myform.pva_4.value != '') && (document.myform.pva_4.value != null) && (document.myform.pva_4.value != '0')) {
		document.getElementById("pva_4_div").innerHTML = (Math.round((document.myform.pva_4.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_4_div").innerHTML = '&nbsp;';
   }
   if (!isNaN(document.myform.pva_5.value.toString().replace(/\./g,'')) && (document.myform.pva_5.value != '') && (document.myform.pva_5.value != null) && (document.myform.pva_5.value != '0')) {
		document.getElementById("pva_5_div").innerHTML = (Math.round((document.myform.pva_5.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_5_div").innerHTML = '&nbsp;';
   }
   if (!isNaN(document.myform.pva_6.value.toString().replace(/\./g,'')) && (document.myform.pva_6.value != '') && (document.myform.pva_6.value != null) && (document.myform.pva_6.value != '0')) {
		document.getElementById("pva_6_div").innerHTML = (Math.round((document.myform.pva_6.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_6_div").innerHTML =  '&nbsp;';
   }
   if (!isNaN(document.myform.pva_7.value.toString().replace(/\./g,'')) && (document.myform.pva_7.value != '') && (document.myform.pva_7.value != null) && (document.myform.pva_7.value != '0')) {
		document.getElementById("pva_7_div").innerHTML = (Math.round((document.myform.pva_7.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_7_div").innerHTML = '&nbsp;';
   }
   /*if (!isNaN(document.myform.pva_8.value.toString().replace(/\./g,'')) && (document.myform.pva_8.value != '') && (document.myform.pva_8.value != null) && (document.myform.pva_8.value != '0')) {
		document.getElementById("pva_8_div").innerHTML = (Math.round((document.myform.pva_8.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_8_div").innerHTML =  '&nbsp;';
   }*/
   /*if (!isNaN(document.myform.pva_9.value.toString().replace(/\./g,'')) && (document.myform.pva_9.value != '') && (document.myform.pva_9.value != null) && (document.myform.pva_9.value != '0')) {
		document.getElementById("pva_9_div").innerHTML = (Math.round((document.myform.pva_9.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_9_div").innerHTML =   '&nbsp;';
   }*/
   if (!isNaN(document.myform.pva_10.value.toString().replace(/\./g,'')) && (document.myform.pva_10.value != '') && (document.myform.pva_10.value != null) && (document.myform.pva_10.value != '0')) {
		document.getElementById("pva_10_div").innerHTML = (Math.round((document.myform.pva_10.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_10_div").innerHTML = '&nbsp;';
   }
   /*if (!isNaN(document.myform.pva_11.value.toString().replace(/\./g,'')) && (document.myform.pva_11.value != '') && (document.myform.pva_11.value != null) && (document.myform.pva_11.value != '0')) {
		document.getElementById("pva_11_div").innerHTML = (Math.round((document.myform.pva_11.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_11_div").innerHTML = '&nbsp;';
   }*/
   if (!isNaN(document.myform.pva_12.value.toString().replace(/\./g,'')) && (document.myform.pva_12.value != '') && (document.myform.pva_12.value != null) && (document.myform.pva_12.value != '0')) {
		document.getElementById("pva_12_div").innerHTML = (Math.round((document.myform.pva_12.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_12_div").innerHTML = '&nbsp;';
   }
   /*if (!isNaN(document.myform.pva_13.value.toString().replace(/\./g,'')) && (document.myform.pva_13.value != '') && (document.myform.pva_13.value != null) && (document.myform.pva_13.value != '0')) {
		document.getElementById("pva_13_div").innerHTML = (Math.round((document.myform.pva_13.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_13_div").innerHTML = '&nbsp;';
   }*/
   if (!isNaN(document.myform.pva_14.value.toString().replace(/\./g,'')) && (document.myform.pva_14.value != '') && (document.myform.pva_14.value != null) && (document.myform.pva_14.value != '0')) {
		document.getElementById("pva_14_div").innerHTML = (Math.round((document.myform.pva_14.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_14_div").innerHTML = '&nbsp;';
   }
   /*if (!isNaN(document.myform.pva_15.value.toString().replace(/\./g,'')) && (document.myform.pva_15.value != '') && (document.myform.pva_15.value != null) && (document.myform.pva_15.value != '0')) {
		document.getElementById("pva_15_div").innerHTML = (Math.round((document.myform.pva_15.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_15_div").innerHTML = '&nbsp;';
   }
   if (!isNaN(document.myform.pva_16.value.toString().replace(/\./g,'')) && (document.myform.pva_16.value != '') && (document.myform.pva_16.value != null) && (document.myform.pva_16.value != '0')) {
		document.getElementById("pva_16_div").innerHTML = (Math.round((document.myform.pva_16.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_16_div").innerHTML = '&nbsp;';
   }
   if (!isNaN(document.myform.pva_17.value.toString().replace(/\./g,'')) && (document.myform.pva_17.value != '') && (document.myform.pva_17.value != null) && (document.myform.pva_17.value != '0')) {
		document.getElementById("pva_17_div").innerHTML = (Math.round((document.myform.pva_17.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_17_div").innerHTML = '&nbsp;';
   }
   if (!isNaN(document.myform.pva_17.value.toString().replace(/\./g,'')) && (document.myform.pva_17.value != '') && (document.myform.pva_17.value != null) && (document.myform.pva_17.value != '0')) {
		document.getElementById("pva_17_div").innerHTML = (Math.round((document.myform.pva_17.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_17_div").innerHTML = '&nbsp;';
   }
   if (!isNaN(document.myform.pva_18.value.toString().replace(/\./g,'')) && (document.myform.pva_18.value != '') && (document.myform.pva_18.value != null) && (document.myform.pva_18.value != '0')) {
		document.getElementById("pva_18_div").innerHTML = (Math.round((document.myform.pva_18.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_18_div").innerHTML = '&nbsp;';
   }
   if (!isNaN(document.myform.pva_19.value.toString().replace(/\./g,'')) && (document.myform.pva_19.value != '') && (document.myform.pva_19.value != null) && (document.myform.pva_19.value != '0')) {
		document.getElementById("pva_19_div").innerHTML = (Math.round((document.myform.pva_19.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_19_div").innerHTML = '&nbsp;';
   }*/
   if (!isNaN(document.myform.pva_20.value.toString().replace(/\./g,'')) && (document.myform.pva_20.value != '') && (document.myform.pva_20.value != null) && (document.myform.pva_20.value != '0')) {
		document.getElementById("pva_20_div").innerHTML = (Math.round((document.myform.pva_20.value.toString().replace(/\./g,'')/t)*100))+" %";
   } else {
		document.getElementById("pva_20_div").innerHTML = '&nbsp;';
   }
}
function checkSum() {
	var errors;
	errors = 0;
	if (document.getElementById("full_money").innerHTML !== '&nbsp;') {
	    errors = 0;
	} else {
		errors = 1;
		alert ('Legkevesebb egy alapba be kell fektetni!');
	}
	return (errors == 0);

}


function formatCurrency(num) {

	num = num.toString().replace(/\./g,'');

	if (num == null || num == '')
	{
		return num;
	}
	if (isNaN(num))
	{
		return '';
	}

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num);
}
