//
// számolásokhoz a tizedesek
var digit=0;
//
// a termék kiválasztása után mit csináljon (0:semmit)
var termek_select_mod=0;
//
// nettó vagy bruttó preferencia
var nbflag=1;
//
var scrollwin='';
//	
var actual=0;
//
// egy oldalon megjelenő több adatlap dialógus azonos nevű input mezőit különíti el
var tetel_dialog='';
//
var search_field='';
//
(function($, window, undefined){
  $.fn.extend({
  	focusNextInputField : function() {
    	return this.each(function() {
        var fields = $(this).parents('form:eq(0),body').find(':input[type!=hidden]:enabled');
        var index = fields.index( this );
        if ( index > -1 && ( index + 1 ) < fields.length ) {
            fields.eq( index + 1 ).focus();
        }
        return false;
    	});
		},
		focusPrevInputField : function() {
	    return this.each(function() {
	        var fields = $(this).parents('form:eq(0),body').find(':input[type!=hidden]:enabled');
	        var index = fields.index( this );
	        if ( index > 0 ) {
	            fields.eq( index - 1 ).focus();
	        }
	        return false;
	    });
		}
	});
}(jQuery, this));
//
//-------------------------------------------------------------
//
// ebben lesz az XMLHttp objektum (vagy sem)
var ajaxRequest = null;
function createXmlHttp()
{
	var request = null;
	// IE7+, Firefox, Chrome, Opera, Safari
	if (window.XMLHttpRequest)
	{
		request = new XMLHttpRequest();
	}
	// IE6, IE5
	else if (typeof ActiveXObject != undefined)
	{
		request = new ActiveXObject('Microsoft.XMLHTTP');
	}
	return request;
}
//
function getAjaxHtml(url,data)
{
	var html=$.ajax({
		type: 'POST',
		url: url,
		data: data,
		async: false
	}).responseText;
	return html;
}
//
//-------------------------------------------------------------
//
// ablak átméretezésekor
function ResizedPage()
{
	// ablak belső mérete
	if (document.documentElement.clientWidth)
	{
		var w=document.documentElement.clientWidth;
		var h=document.documentElement.clientHeight;
	}
	else if (window.innerWidth)
	{
		var w=window.innerWidth;
		var h=window.innerHeight;
	}
	else
	{
		var w=document.body.clientWidth;
		var h=document.body.clientHeight;
	}
	var toph=h-115;
	document.getElementById('netszamla').style.top=toph+'px';
	document.getElementById('cegemblema').style.top=toph+'px';
	var toplogin=h-140;
	document.getElementById('logintxt').style.top=toplogin+'px';
	var netimg=document.getElementById('netszamla_img');
	var ptop=netimg.height;
	if (ptop>0)
	{
		ptop=(70-ptop)/2;
		if (netimg.style.paddingTop)
			netimg.style.paddingTop=ptop+'px';
	}
}
//
function GlobalInit()
{
	// firefox: nyomtatáskor nem rakja ki a nyomtató ablakot (about:config)
	user_pref('print.always_print_silent',false);
	user_pref('browser.offline',false);
}
//
function GetScrollingPos()
{
	var pos=0;
	if (navigator.appName == "Microsoft Internet Explorer")
		pos=document.body.scrollTop;
	else
		pos=window.pageYOffset;
	return pos;
}
//
function ResetScrollingPos()
{
	$(document).scrollTop(0);
}
//
function Select(id,nev)
{
	var actualsor='sor'+actual;
	if (actual!=0)
		document.getElementById(actualsor).style.backgroundColor='#ffffff';
	actual=id;
	actualsor='sor'+actual;
	if (actual!=0)
		document.getElementById(actualsor).style.backgroundColor='#E3E0D8';
}
function SelectView(id)
{
	var actualsor='sor'+actual;
	if (actual!=0)
		document.getElementById(actualsor).style.backgroundColor='#ffffff';
	actual=id;
	actualsor='sor'+actual;
	if (actual!=0)
		document.getElementById(actualsor).style.backgroundColor='#E3E0D8';
	document.listform.mod.value='view';
	document.listform.id.value=actual;
	document.listform.ug.value=GetScrollingPos();
	document.listform.submit();
}
function SelectViewA(id,adf)
{
	actual=id;
	var aform=document.forms[adf];
	aform.mod.value='view';
	aform.id.value=actual;
	aform.ug.value=GetScrollingPos();
	aform.submit();
}
function Mouseover(id,name)
{
	sor=name+id;
	document.getElementById(sor).style.backgroundColor='#9CDB7A';
	document.getElementById(sor).style.cursor='pointer';
}
function Mouseout(id,name)
{
	sor=name+id;
	document.getElementById(sor).style.backgroundColor='transparent';
}
function MouseoutColor(id,name,color)
{
	sor=name+id;
	document.getElementById(sor).style.backgroundColor=color;
}
// lapozás nélküli teljes adatlista
function List()
{
	document.searchform.mod.value='list';
	document.searchform.id.value=actual;
	document.searchform.ug.value=GetScrollingPos();
	document.searchform.sdata.value='';
	document.searchform.submit();
}
// lapozás másik oldalra
function Page(pform,start)
{
	document.forms[pform].mod.value='list';
	document.forms[pform].id.value=0;
	document.forms[pform].ug.value=0;
	document.forms[pform].start.value=start;
	document.forms[pform].submit();
}
// lapozós adatlistánál teljes lista (keresőmező törlése)
function PageList()
{
	document.searchform.mod.value='list';
	document.searchform.id.value=0;
	document.searchform.ug.value=0;
	document.searchform.sdata.value='';
	document.searchform.start.value=0;
	document.searchform.submit();
}
// keresés
function Search()
{
	document.searchform.id.value=0;
	document.searchform.sdata.value=document.searchform.search.value;
	document.searchform.submit();
}
// keresés lapozós listánál
function PageSearch()
{
	document.searchform.id.value=0;
	document.searchform.sdata.value=document.searchform.search.value;
	document.searchform.start.value=0;
	document.searchform.submit();
}
function Ins()
{
	document.listform.mod.value='ins';
	document.listform.ug.value=GetScrollingPos();
	document.listform.submit();
}
function InsA(adf)
{
	var aform=document.forms[adf];
	aform.mod.value='ins';
	aform.ug.value=GetScrollingPos();
	aform.submit();
}
function Mod()
{
	if (actual!=0)
	{
		document.listform.mod.value='mod';
		document.listform.id.value=actual;
		document.listform.ug.value=GetScrollingPos();
		document.listform.submit();
	}
	else
		alert('Nincs kiválasztva semmi!');
}
function Del()
{
	if (actual!=0)
	{
		if (confirm('Biztosan törlöd?'))
		{
			document.listform.mod.value='del';
			document.listform.id.value=actual;
			document.listform.ug.value=GetScrollingPos();
			document.listform.submit();
		}
	}
	else
		alert('Nincs kiválasztva semmi!');
}
function View()
{
	if (actual!=0)
	{
		document.listform.mod.value='view';
		document.listform.id.value=actual;
		document.listform.ug.value=GetScrollingPos();
		document.listform.submit();
	}
	else
		alert('Nincs kiválasztva semmi!');
}
function ViewMod(id)
{
	document.listform.mod.value='mod';
	document.listform.id.value=id;
	document.listform.ug.value=GetScrollingPos();
	document.listform.submit();
}
function ViewModA(id,adf)
{
	var aform=document.forms[adf];
	aform.mod.value='mod';
	aform.id.value=id;
	aform.ug.value=GetScrollingPos();
	aform.submit();
}
function ViewDel(id)
{
	if (confirm('Biztosan törlöd?'))
	{
		document.listform.mod.value='del';
		document.listform.id.value=id;
		document.listform.submit();
	}
}
function ViewDelA(id,adf)
{
	if (confirm('Biztosan törlöd?'))
	{
		var aform=document.forms[adf];
		aform.mod.value='del';
		aform.id.value=id;
		aform.ug.value=GetScrollingPos();
		aform.submit();
	}
}
function Pic()
{
	if (actual!=0)
	{
		document.picform.id.value=actual;
		document.picform.type.value=actual;
		document.picform.submit();
	}
	else
		alert('Nincs kiválasztva semmi!');
}
function PicDet(type,cel)
{
	if (actual!=0)
	{
		document.picform.id.value=actual;
		document.picform.type.value=type;
		document.picform.cel.value=cel;
		document.picform.submit();
	}
	else
		alert('Nincs kiválasztva semmi!');
}
function PicDetId(id,type,cel)
{
	document.picform.id.value=id;
	document.picform.type.value=type;
	document.picform.cel.value=cel;
	document.picform.submit();
}
function PicDetId2(id,type,cel,etxt)
{
	document.picform.id.value=id;
	document.picform.type.value=type;
	document.picform.cel.value=cel;
	document.picform.exittxt.value=etxt;
	document.picform.submit();
}
function PicDetId3(id,type,cel,etxt,ptbl)
{
	document.picform.id.value=id;
	document.picform.type.value=type;
	document.picform.cel.value=cel;
	document.picform.exittxt.value=etxt;
	document.picform.picdba.value=ptbl;
	document.picform.submit();
}
function VideoDetId(id)
{
	document.vidform.cid.value=id;
	document.vidform.submit();
}
function Print()
{
	if (actual!=0)
	{
		document.listform.id.value=actual;
		document.listform.submit();
	}
	else
		alert('Nincs kiválasztva semmi!');
}
function Exit()
{
	document.adatlapform.mod.value='list';
	document.adatlapform.submit();
}
function NoSave()
{
	document.adatlapform.mod.value='nosave';
	document.adatlapform.submit();
}
function Teszt()
{
	if (document.adatlapform.nev.value.length==0)
	{
		document.adatlapform.nev.focus();
		alert('Meg kell adni a megnevezést!');
	}
	else
		document.adatlapform.submit();
}
function Kivalasztas(mod)
{
	if (actual!=0)
	{
		document.hivoform.mod.value=mod;
		document.hivoform.uid.value=actual;
		document.hivoform.submit();
	}
}
function KivalasztasId(id)
{
	document.hivoform.uid.value=id;
	document.hivoform.submit();
}
// fülek váltása
var lastdiv='';
function showTabdata(div,off)
{
	if (lastdiv!='')
	{
		document.getElementById(lastdiv).style.backgroundColor='white';
		document.getElementById('div'+lastdiv).style.display='none';
	}
	var mehet=true;
	if (off==1 && div==lastdiv)
		mehet=false;
	if (mehet)
	{
		document.getElementById(div).style.backgroundColor='#C3C9CF';
		document.getElementById('div'+div).style.display='block';
		lastdiv=div;
	}
	if (off==1 && mehet==false)
		lastdiv='';
}
// fülek váltása2
var lastdiv2='';
function showTabdata2(div,off)
{
	if (lastdiv2!='')
	{
		document.getElementById(lastdiv2).style.backgroundColor='white';
		document.getElementById('div'+lastdiv2).style.display='none';
	}
	var mehet=true;
	if (off==1 && div==lastdiv2)
		mehet=false;
	if (mehet)
	{
		document.getElementById(div).style.backgroundColor='#C3C9CF';
		document.getElementById('div'+div).style.display='block';
		lastdiv2=div;
	}
	if (off==1 && mehet==false)
		lastdiv2='';
}
// rendezés
function OrderData(sn)
{
	document.orderform.sort.value=sn;
	document.orderform.ug.value='0';
	document.orderform.submit();
}
function OrderDataT(sn)
{
	document.orderform.sort.value=sn;
	document.orderform.gpid.value=actual_gpid;
	document.orderform.submit();
}
//
function SetFlag(php,id,ikonid,oksrc,nonesrc)
{
	var resp=getAjaxHtml(php,'id='+id);
	var ikon=document.getElementById(ikonid+id);
	switch (resp)
	{
		case '1':
			ikon.src=oksrc;
			break;
		case '0':
			ikon.src=nonesrc;
			break;
	}
}
// számolások------------------------------------------------------------------
function parseLocalNum(num)
{
	var num=num.replace(",",".").replace(/ /g,"");
	return num;
}
//
function number_format(number, decimals, dec_point, thousands_sep)
{
	number = (number+'').replace(',', '.').replace(/ /g, '');
	var	n = !isFinite(+number) ? 0 : +number, 
			prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
			sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
			dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
			s = '',
			toFixedFix = function (n, prec) {
	    	var k = Math.pow(10, prec);
		    return '' + Math.round(n * k) / k;
			};
	// Fix for IE parseFloat(0.55).toFixed(0) = 0;
	s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
	if (s[0].length > 3) {
		s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
	}
	if ((s[1] || '').length < prec) {
		s[1] = s[1] || '';
		s[1] += new Array(prec - s[1].length + 1).join('0');
	}
	return s.join(dec);
}
// változott a nettó
function NettoChange(netto,brutto,afa)
{
	$(brutto).val(NettoToBrutto(GetAr(netto),GetAfa(afa)));
}
// változott a bruttó
function BruttoChange(netto,brutto,afa)
{
	$(netto).val(BruttoToNetto(GetAr(brutto),GetAfa(afa)));
}
// nettóból bruttó
function NettoToBrutto(netto,afa)
{
	netto*=1;
	afa*=1;
	var brutto=(1*netto)*(100+(1*afa))/100;
	brutto=brutto.toFixed(digit);
	return brutto;
}
// nettóból bruttó megadható tizedesre
function NettoToBruttoD(netto,afa,d)
{
	netto*=1;
	afa*=1;
	d*=1;
	var brutto=(1*netto)*(100+(1*afa))/100;
	brutto=brutto.toFixed(d);
	return brutto;
}
// bruttóból nettó
function BruttoToNetto(brutto,afa)
{
	brutto*=1;
	afa*=1;
	var netto=(100*brutto)/(100+afa);
	netto=netto.toFixed(digit);
	return netto;
}
// alapárból és kedvezmény százalékból kedvezményes ár
function AlapToKedvezmenyes(ar,kedv)
{
	ar*=1;
	kedv*=1;
	var kedvar=((100-kedv)*ar)/100;
	kedvar=kedvar.toFixed(digit);
	return kedvar;
}
// árakból kedvezmény százalék
function ArToKedvezmeny(alapar,kedvar)
{
	var kedv=0;
	kedvar*=1;
	alapar*=1;
	if (kedvar<alapar)
	{
		if (alapar!=0)
		{
			kedv=(kedvar*100.0/alapar);
			kedv=100-kedv;
		}
		kedv=kedv.toFixed(0);
	}
	return kedv;
}
function ArToKedvezmeny2(alapar,kedvar,dg)
{
	var kedv=0;
	kedvar*=1;
	alapar*=1;
	if (kedvar<alapar)
	{
		if (alapar!=0)
		{
			kedv=(kedvar*100.0/alapar);
			kedv=100-kedv;
		}
		kedv=kedv.toFixed(dg);
	}
	return kedv;
}
// áfa kulcs
function GetAfa(id)
{
	var afa=parseInt($(id).val());
	afa=isNaN(afa) ? 0 : afa;
	if (afa<0)
		afa=0;
	if (afa>99)
		afa=99;
	$(id).val(afa);
	return afa;
}
// egységár
function GetAr(id)
{
	var ar=parseFloat(parseLocalNum($(id).val()));
	ar=isNaN(ar) ? 0 : ar;
	ar=ar.toFixed(digit);
	$(id).val(ar);
	return ar;
}
// kedvezmény
function GetKedvezmeny(id)
{
	var kedv=parseInt($(id).val());
	kedv=isNaN(kedv) ? 0 : kedv;
	if (kedv<0)
		kedv=0;
	if (kedv>100)
		kedv=100;
	$(id).val(kedv);
	return kedv;
}
// mennyiség
function GetMennyiseg(id)
{
	var mennyiseg=parseFloat(parseLocalNum($(id).val()));
	mennyiseg=isNaN(mennyiseg) ? 1 : 0 ? 1 : mennyiseg;
	$(id).val(mennyiseg);
	return mennyiseg;
}
// valuta árfolyam
function GetArfolyam()
{
	var arf=parseFloat(parseLocalNum($('#valuta_arfolyam').val()));
	arf=isNaN(arf) ? 0 : arf;
	if (arf<=0)
		arf=1;
	$('#valuta_arfolyam').val(arf);
	return arf;
}
// óra
function GetOra(id)
{
	var ora=parseInt($(id).val());
	ora=isNaN(ora) ? 0 : ora;
	if (ora<0)
		ora=0;
	if (ora>24)
		ora=24;
	$(id).val(ora);
	return ora;
}
// árrés
function GetArres()
{
	var arres=parseInt($('#arres').val());
	arres=isNaN(arres) ? 0 : arres;
	if (arres<0)
		ares=0;
	if (arres>10000)
		arres=100000;
	$('#arres').val(arres);
	return arres;
}
// egész szám
function GetInt(id)
{
	var szam=parseInt($(id).val());
	szam=isNaN(szam) ? 0 : szam;
	szam=szam.toFixed(0);
	$(id).val(szam);
	return szam;
}
// nem egész szám
function GetFloat(id)
{
	var szam=parseFloat(parseLocalNum($(id).val()));
	szam=isNaN(szam) ? 0 : szam;
	$(id).val(szam);
	return szam;
}
// nem egész szám
function GetFloat2(id)
{
	var szam=parseFloat(parseLocalNum($(id).val()));
	szam=isNaN(szam) ? 0 : szam;
	return szam;
}
function GetFloat3(id,dg)
{
	var szam=parseFloat(parseLocalNum($(id).val()));
	szam=isNaN(szam) ? 0 : szam;
	szam=szam.toFixed(dg);
	$(id).val(szam);
	return szam;
}

