function setLayer(id,str){
  if(document.all){
    document.all[id].innerHTML=str
  }else if(document.getElementById){
    document.getElementById(id).innerHTML=str
  }
}

function getLayer(id){
  if(document.all && document.all[id]){
    return document.all[id]
  }else if(document.getElementById && document.getElementById(id)){
    return document.getElementById(id)
  }
 	return false
}

function setVaros(county_id){
	setLayer('select_varos',setVarosCommon(county_id))
}

function setVarosForgalmazo(county_id){
	setLayer('select_varos_forg',setVarosCommon(county_id))
}

function setVarosCommon(county_id){
	var strSelect=''
	if(county_id==0){
		strSelect+='<select name="kerulet"><option value="">Összes kerület</option>'
		for(var i=0;i < window.kerulet.length;i++){
			var row=window.kerulet[i].split(';')
			strSelect+='<option value='+row[0]+'>'+row[1]+'. kerület</option>'
		}
		strSelect+='</select>'
	}else{
		strSelect+='<select name="varos"><option value="">Összes település</option>'
		for(var i=0;i < window.varos[county_id].length;i++){
			strSelect+='<option value="'+window.varos[county_id][i]+'">'+window.varos[county_id][i]+'</option>'
		}
		strSelect+='</select>'
	}

	return strSelect
}

function setVarosFormCommon(mid,strVaros,strKerulet,strKeres,formName){
	strKerulet=parseInt(strKerulet,10)
	with(document.forms[formName]){
		for(var i=0;i<megye.length;i++){
			if(megye[i].value==mid){
				megye[i].selected=true
				break
			}
		}
		
		if(formName=="forgalmazo"){
			setVarosForgalmazo(mid)
		}else{
			setVaros(mid)
		}

		if((mid==0) && (strKerulet>0)){
			for(var i=0;i<kerulet.length;i++){
				if(kerulet[i].value==strKerulet){
					kerulet[i].selected=true
					break
				}
			}
		}else if(strVaros!=""){
			for(var i=0;i<varos.length;i++){
				if(varos[i].value==strVaros){
					varos[i].selected=true
					break
				}
			}
		}
		if(strKeres!=""){
			k.value=strKeres
		}
	}
}

function setVarosForm(mid,strVaros,strKerulet,strKeres){
	setVarosFormCommon(mid,strVaros,strKerulet,strKeres,'boltkereso')
}
function setVarosFormForgalmazo(mid,strVaros,strKerulet,strKeres){
	setVarosFormCommon(mid,strVaros,strKerulet,strKeres,'forgalmazo')
}

function Forgalmazo(){
	this.m=99
	this.bk=0
	this.v=""
	this.k=""

	this.itemNum=0
	this.itemNumMax=0
	this.start=1
}

Forgalmazo.prototype.list=function(){
	this.start=1
	with(document.forms['forgalmazo']){
		this.m=megye[megye.selectedIndex].value
		this.bk=0
		this.v=""
		this.k=k.value
		this.x=item_extra

		if(this.m==0){
			this.bk=kerulet[kerulet.selectedIndex].value
		}else{
			this.v=varos[varos.selectedIndex].value
		}
	}
	loadXML('bforg.php?i='+window.arukod+'&m='+this.m+'&v='+this.v+'&bk='+this.bk+'&k='+this.k+'&x='+this.x,'forgalmazo')
}

Forgalmazo.prototype.goPage=function(s){
	if(s > 0){
		this.start=s
	}else{
		this.start=1
	}
	loadXML('bforg.php?i='+window.arukod+'&m='+this.m+'&v='+this.v+'&bk='+this.bk+'&s='+this.start+'&k='+this.k+'&x='+this.x,'forgalmazo')
}

Forgalmazo.prototype.setStepLayer=function(){
	var str=""

	if(this.itemNumMax>5){
		var start=this.start

		if(start>5){
			start-=5
		}
		var end=start+14

		if(end>this.itemNumMax){
			if((start > 1) && ((this.start+5)>this.itemNumMax)){start-=5}
			end=this.itemNumMax
		}

		for(var i=start;i<=end;i+=5){
			if((i+4)<=end){
				strEnd=i+4
			}else{
				strEnd=end
			}

			if(i==this.start){
				str+='<b>'+i+'-'+strEnd+'</b>'
			}else{
				str+='<span onclick="FORG.goPage('+i+')">'+i+'-'+strEnd+'</span>'
			}
			if((i+4)<end){
				str+='&nbsp;|&nbsp;';
			}
		}
	}else
		str="&nbsp;";

	setLayer('forgstep',str);
}

function XML_forgalmazo(){
	if(xmlDoc.getElementsByTagName("L").length>0){
  	var str=""

		FORG.itemNumMax=xmlDoc.getElementsByTagName("N")[0].firstChild.nodeValue

		if(FORG.itemNumMax > 0){
	   	FORG.itemNum=xmlDoc.getElementsByTagName("I").length
	
	  	for(var i=0;i < FORG.itemNum;i++){
				var sor=xmlDoc.getElementsByTagName("I")[i].firstChild.nodeValue.split(';')
				var rowAr=sor[4].split('X')

				if(rowAr[1]!=''){
					strAr='<span class="akcio">'+rowAr[1]+'&nbsp;Ft</span><br><s>'+rowAr[0]+'&nbsp;Ft</s>'
				}else{
					strAr=rowAr[0]+'&nbsp;Ft'
				}
	    	str+=
	    		'<div class="item">'+
	    		'<div class="data"><a class="nev" href="http://'+sor[3]+'">'+sor[1]+'</a><br>'+sor[2]+'</div>'+
					'<div class="kosar"><div class="ar">'+strAr+'</div><a href="index.php?s=kosar&amp;id='+window.arukod+'&amp;bolt='+sor[0]+'"><img src="i/button/kosarba.gif" alt=""></a></div>'+
	    		'</div>'
	
				if((i+1)<FORG.itemNum){
		    	str+='<div class="sep"></div>'
				}
	  	}
		}else{
			str='<div class="nores">Nincs a keresési feltételnek megfelelő bolt.</div>'
		}

		setLayer('forgres','Találatok száma: <b>'+FORG.itemNumMax+'</b>&nbsp;db')
		FORG.setStepLayer()
		setLayer('forglist',str)
	}
}

// LOGIN START
function loginFocus(i){
	l=layer('jelszo');
	l2=layer('jelszotext');
	l2.style.display='none';
	l.style.display='inline';

	if(document.forms['belep'].login.value=="Felhasználónév"){
		document.forms['belep'].login.value=""
	}

	if(document.forms['belep'].jelszo.value=="Jelszó"){
		document.forms['belep'].jelszo.value=""
	}
	if(i.name=="login"){
		document.forms['belep'].login.focus()
	}else{
		document.forms['belep'].jelszo.focus()
	}
}

function loginBlur(i){
	if(document.forms['belep'].login.value==""){
		document.forms['belep'].login.value="Felhasználónév"
	}

	if(document.forms['belep'].jelszo.value==""){
		document.forms['belep'].jelszotext.value="Jelszó"
	}

	if((i.name=="jelszo") && (i.value=="")){
		l=layer('jelszo');
		l2=layer('jelszotext');
		l.style.display='none';
		l2.style.display='inline';
	}
}
function loginCheck(f){
	if((f.login.value=='')||(f.login.value=='Felhasználónév')){
		alert("Kérjük, adja meg felhasználónevét!")
		return false
	}else if((f.jelszo.value=='')||(f.jelszo.value=='Jelszó')){
		alert("Kérjük, adja meg jelszavát!")
		return false
	}
}
// LOGIN END

// JELSZO MODOSITAS START
function checkPasswordModify(f){
	if(f['regijelszo'].value==""){
		alert('A régi jelszó megadása kötelező!')
		return false
	}else if(f['jelszo'].value==""){
		alert('Az új jelszó megadása kötelező!')
		return false
	}else if(f['jelszo'].value!=f['jelszoconfirm'].value){
		alert('A két új jelszó különbözik!')
		return false
	}
	return true
}
// JELSZO MODOSITAS END

// SMS START
function checkSMS(f){
	if(!f['tel'].value.match(/\d{7}/)){
		alert('A megadott telefonszám érvénytelen!')
		return false
	}
	return true
}
//SMS END


function loadXML(URL,fname){
	ct=new Date()
	if(window.ActiveXObject){
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
		xmlDoc.async=false
		xmlDoc.load(URL+'&ct='+ct.getTime())
		eval('XML_'+fname+'()')
	}else if (document.implementation && document.implementation.createDocument){
		xmlDoc=document.implementation.createDocument("","",null)
		xmlDoc.load(URL+'&ct='+ct.getTime())
		eval('xmlDoc.onload=XML_'+fname)
	}else{
		alert('Elnézését kérjük, de az Ön böngészője nem támogatja ezt a funkciót.')
	}
}

// PUBCAT bal oldali kategoria lista START
var PC_activeID=""
var tm={'PC':0,'main':0}

function PC_createMenu(){
	var str=''
	for(var i=0;i<tblPC.length;i++){
		if(tblPC[i][3].length > 0){
			str+='<div class="pcmenusub" id="pcsub'+tblPC[i][0]+'" onmouseover="PC_cancelCloseMenu();return true" onmouseout="PC_initHideMenu('+"'"+tblPC[i][0]+"'"+');return true">'

			for(var j=0;j<tblPC[i][3].length;j++){
				if((j+1)<tblPC[i][3].length){
					strClass="item"
				}else{
					strClass="item last"
				}
				str+='<div id="pcsubitem'+tblPC[i][3][j][0]+'" class="'+strClass+'" onclick="location='+"'index.php?s=item&s2=list&pid="+tblPC[i][3][j][0]+"'"+'"  onmouseover="PC_overSubMenu('+"'"+tblPC[i][3][j][0]+"'"+')" onmouseout="PC_outSubMenu('+"'"+tblPC[i][3][j][0]+"'"+')">'+tblPC[i][3][j][1]+'</div>'
			}
			
			str+='</div>'
		}
	}
	document.writeln(str)
}

function PC_displayMenu(isMain){
	var str=''
	var tmpTblPC=new Array()

	if(isMain){
		for(var i=0;i < tblPC.length;i++){
			if(tblPC[i][2]){
				tmpTblPC[tmpTblPC.length]=tblPC[i]
			}
		}
	}else{
		tmpTblPC=tblPC
	}

	maxItemNum=tmpTblPC.length

	for(var i=0;i < maxItemNum;i++){
		str+='<div class="item" id="pc'+tmpTblPC[i][0]+'" onmouseover="PC_overMenu('+"'"+tmpTblPC[i][0]+"'"+')" onmouseout="PC_initHideMenu('+"'"+tmpTblPC[i][0]+"'"+')" onclick="location='+"'"+'index.php?s=item&s2=list&pid='+tmpTblPC[i][0]+"'"+'">'+tmpTblPC[i][1]+'</div>';
		if((i+1) < maxItemNum){
			str+='<div style="float: left;font-size: 1px;height: 1px"><img src="i/box/pubcat/sep.gif" alt=""></div>'
		}
	}
	if(isMain){
		str+='<div id="PC_button" onclick="PC_displayMenu(false)"><img src="i/box/pubcat/button.gif" alt=""></div>'
	}else{
		str+='<div><img src="i/box/pubcat/bottom.jpg" alt=""></div>'
	}
	setLayer("pcmenu",str)
}

function PC_overMenu(id){
	PC_cancelCloseMenu()
	if(PC_activeID!=""){
		PC_outMenu(PC_activeID)
	}
	PC_activeID=id
	l=layer("pc"+id)
	sl=layer('pcsub'+id)
	if(sl.isExist()){
		cancelCloseMenu()
		if(isMSIE){
			ml=layer('megyelayer')
			if(ml.isExist()){
				ml.hide()
			}
		}
		sl.style.display="block"
		sl.moveTo(l.getAbsoluteLeft()+180,l.getAbsoluteTop()+2)
		sl.show()
	}
	l.style.background='#5BC64E url(i/box/pubcat/pont_over.gif) 6px 5px no-repeat'
}

function PC_outMenu(id){
	l=layer("pc"+id)
	sl=layer('pcsub'+id)
	if(sl.isExist()){
		sl.hide()
		if(isMSIE){
			ml=layer('megyelayer')
			if(ml.isExist()){
				ml.show()
			}
		}
	}
	l.style.background='#93E36C url(i/box/pubcat/pont.gif) 6px 5px no-repeat'
}

function TA_overMenu(id){
	l=layer("ta"+id)
	l.style.background='#F99494 url(i/box/topajanlat/pont_over.gif) 6px 5px no-repeat'
}

function TA_outMenu(id){
	l=layer("ta"+id)
	l.style.background='#F44E4E url(i/box/topajanlat/pont.gif) 6px 5px no-repeat'
}

function PC_cancelCloseMenu(){
	if(tm.PC){
		clearTimeout(tm.PC)
		tm.PC=0
	}
}

function PC_initHideMenu(id){
	tm.PC=setTimeout('PC_outMenu("'+id+'")',400)
}

function PC_overSubMenu(id){
//	PC_cancelCloseMenu()
	l=layer("pcsubitem"+id)
	l.style.backgroundColor='#5BC64E'
	l.style.color='#FFFFFF'
}

function PC_outSubMenu(id){
//	PC_initHideMenu(id.substr(0,2))
	l=layer("pcsubitem"+id)
	l.style.backgroundColor='#E2FFD4'
	l.style.color='#44B536'
}

// PUBCAT bal oldali kategoria lista START

// NAV menu START

var activeMenuID=""
function showMenu(id)
{
	Menu_Over(menu_tbl[id-1][0][0])
	activeMenuID=id
	cancelCloseMenu()

	menu=layer('menu_'+id)
	button=layer('button_'+id)

	menu.moveTo(button.getAbsoluteLeft()+menu_tbl[id-1][0][2],140)
	menu.style.display="block";
	menu.show()
}

function cancelCloseMenu(){
	if(tm.main){
		clearTimeout(tm.main)
		tm.main=0
	}
}

function initiateHideMenu(id){
	tm.main=setTimeout('menu=layer("menu_'+id+'");menu.hide();Menu_Out("'+menu_tbl[id-1][0][0]+'")',400)
}

function Menu_Over(id){
	if(activeMenuID!=""){
		t_menu=layer('menu_'+activeMenuID)
		t_menu.hide()
		Menu_Out(menu_tbl[activeMenuID-1][0][0])
		activeMenuID=""
	}
	eval('document.menu_'+id+'_img.src="i/menu/'+dirMenuImage+id+'_on.jpg"');
}

function Menu_Out(id){
	eval('document.menu_'+id+'_img.src="i/menu/'+dirMenuImage+id+'.jpg"');
}

function Menu_Item_Over(i,j){
	l=layer('sm_'+i+'_'+j)
	l.style.backgroundColor="#FF9933"
	l.style.color="#FFFFFF"
	if(window.status!=null) window.status=menu_tbl[i-1][j][1];
}

function Menu_Item_Over_Out(i,j){
	l=layer('sm_'+i+'_'+j)
	l.style.backgroundColor="#FFFFFF"
	l.style.color="#FF9900"
	if(window.status!=null) window.status='';
}

function displayMenu(){
	if((menu_tbl)&&(menu_tbl.length>0)){
  	for(i=1;i<=menu_tbl.length;i++){
			var image_load=new Image()
			image_load.src='i/menu/'+dirMenuImage+menu_tbl[i-1][0][0]+'_on.jpg';

  		str=
  			'<div id="menu_'+i+'" class="menu" onmouseover="cancelCloseMenu(); return true" onmouseout="initiateHideMenu('+i+'); return true" style="left:'+menu_tbl[i-1][0][1]+'px">'+
  			'<div class="img"><img src="i/menu/'+dirMenuImage+menu_tbl[i-1][0][0]+'_top.gif" alt=""></div>'+
  			'<div class="content">'

  		var strLast=''
  		for(j=1;j < menu_tbl[i-1].length;j++){
  			if((j+1) == menu_tbl[i-1].length){strLast=' last'}

	  		str+='<div onclick="location=menu_tbl['+(i-1)+']['+j+'][1]" class="menu_item'+strLast+'" id="sm_'+i+'_'+j+'" onmouseover="Menu_Item_Over('+i+','+j+')" onmouseout="Menu_Item_Over_Out('+i+','+j+')">'+menu_tbl[i-1][j][0]+'</div>'
  		}

  		str+=
  			'</div>'+
  			'<div class="img"><img src="i/menu/bottom.gif" alt=""></div>'+
  			'</div>'

			document.writeln(str)
  	}
  }
}

// NAV menu END

function xmlNotify(){
	window.xmlNotifyDoc=null;
}


xmlNotify.prototype.xmlCheck=function(){
	if(xmlNotifyDoc.getElementsByTagName("N").length>0){
	 	var str=xmlNotifyDoc.getElementsByTagName("M")[0].firstChild.nodeValue
		if(str=="0"){
			setTimeout("notify.load()",30000)
		}else{
			var row=str.split(";")
			str=''
			if(row[0]==1){
				str='<img src="i/jel.gif" width=18 height=28 align="left" alt=""><a href="index.php?s=pubrendel&amp;id='+row[1]+'">Új rendelés<br>érkezett!</a>'
			}else if(row[0]==2){
				str='<img src="i/jel.gif" width=18 height=28 align="left" alt=""><a href="index.php?s=korabbirendeles&id='+row[1]+'">Új számla<br>érkezett!</a>'
			}else if(row[0]==3){
				str='<img src="i/jel.gif" width=18 height=28 align="left" alt=""><a href="index.php?s=korabbirendeles&id='+row[1]+'">Új visszaigazolás<br>érkezett!</a>'
			}
			setLayer('notify',str)
		}
	}
}

xmlNotify.prototype.load=function(){
	var ct=new Date()

	if(window.ActiveXObject){
		xmlNotifyDoc = new ActiveXObject("Microsoft.XMLDOM")
		xmlNotifyDoc.async=false
		xmlNotifyDoc.load('n.php?ct='+ct.getTime())
		this.xmlCheck()
	}else if (document.implementation && document.implementation.createDocument){
		xmlNotifyDoc=document.implementation.createDocument("","",null)
		xmlNotifyDoc.load('n.php?ct='+ct.getTime())
		xmlNotifyDoc.onload=this.xmlCheck
	}else{
		alert('Elnézését kérjük, de az Ön böngészője nem támogatja ezt a funkciót.')
	}
}

var notify=new xmlNotify();

function initPage(){
	displayMenu()
	if(hskosar_cookie!="undefined"){
		setTimeout('notify.load()',2000);
		kosar.setForms()
		kosar.setLeft()
	}
}
