addLoadEvent(setMenu);

/*
JSSelect osztďż˝ly
	az osszes select tag-et lecserďż˝li, UL ďż˝s LI tag-ekre, ďż˝s lďż˝thatatlannďż˝ teszi azokat
*/

function JSDDMenu(menuTags,elementHeight)
{
	this.elementDis=elementHeight;
	this.tags=new Array();
	var menuElements=menuTags.getElementsByTagName("LI");
	this.tags.push(menuTags.parentNode.parentNode);		//	gyoker elem
	
	//	almenu elemeit egy IFRAME-be pakoljuk
	
	
	this.menuShim=document.createElement("IFRAME");
	this.menuShim.setAttribute("scrolling","no");
	this.menuShim.setAttribute("frameBorder","0");
	this.menuShim.frameBorder =0;
	this.menuShim.setAttribute("FRAMEBORDER","0");
	this.menuShim.setAttribute("SCROLLING","NO");
	
	function copyFunction(func, arg){
        return function(){
            func(arg);
            return false;
        }
    }
	
	this.menuShim.onload = copyFunction(i_onload, this);
	this.loaded = (isIE)? true : false;
	function i_onload(obj)
	{
		obj.loaded = true;
	}
	
	this.menuShim.style.display="none";
	menuTags.parentNode.parentNode.appendChild(this.menuShim);
	
	var txt="<link href=\"/sites/bet/css/bet.css\" type=\"text/css\" rel=\"stylesheet\">";
	txt+="<div id='menuTop' class=\"topMenuUL\">";
	
	for(m=0; m<menuElements.length; m++)				//	almenu elemei
	{
		txt+="<div class=\"visibleMenu\">"+menuElements[m].innerHTML+"</div>";
		menuElements[m].style.display="none";
	}	
	txt+="</div>";
	this.doc = (this.menuShim.contentDocument)?this.menuShim.contentDocument:this.menuShim.contentWindow.document;
	this.doc.open();
	this.doc.write(txt);
	this.doc.close();
	
	

	this.isResized=false;
	
	this.isOpen=false;
	this.initMenu();
	
}

JSDDMenu.prototype.hideMe=function()
{
    this.menuShim.style.display="none";
    this.isOpen=false;
}

JSDDMenu.prototype.initMenu=function()
{	
	var t=this;
	
	var hideAllow=true;
	
	function copyFunction(func, arg){
        return function(){
            func(arg);
        }
    }
	
	function mouseOver(obj)
	{
		if(obj.loaded)
		{
			hideAllow=false;
			if(!obj.isOpen)
			{
			    hideAllMenu();
			    obj.menuShim.style.display="block";
			    obj.menuShim.style.position="absolute";
			  //  if(!t.isResized)
				obj.resizeShim();
			}
			
			obj.isOpen=true;
		}
	}
	
	this.tags[0].onmouseover=copyFunction(mouseOver, this);
	
	if(!window.opera)
	{
		function hideMenu()
		{
			if(hideAllow)
			{
				t.isOpen=false;
				t.menuShim.style.display="none";
			}
		}
	    this.tags[0].onmouseout=function()
	    {
			hideAllow=true;
			setTimeout(hideMenu,20);
	    }
	}
	else
	{
	    var close=true;
	    function hideOpera()
	    {
		if(close)
		{
		    t.menuShim.style.display="none";
		    t.isOpen=false;
		}
	    }
		
		var _oldOnmouseOver = t.menuShim.parentNode.onmouseover;
		t.menuShim.parentNode.onmouseover=function()
		{
			_oldOnmouseOver();
			close=false;
		}
		t.menuShim.parentNode.onmouseout=function()
		{
		    close=true;
		    setTimeout(hideOpera,500);
		}
		
	    var divs=this.doc.getElementsByTagName("DIV");
	    for(d=0; d<divs.length; d++)
	    {
		divs[d].onmouseover=function()
		{
		    close=false;
		}
		divs[d].onmouseout=function()
		{
		    close=true;
		    setTimeout(hideOpera,500);
		}
	    }
	}
}

JSDDMenu.prototype.resizeShim=function()
{
	//	Szelesseg beallitasa
	var lis=this.doc.getElementsByTagName("div");
	var max=0; 
	var full_h=0;
	for(l=1; l<lis.length; l++)
	{
		var ptag=lis[l].getElementsByTagName("A")[0];
		if(!isIE)ptag.parentNode.style.paddingTop=3+"px";
		//	EVENTEK TARSITASA
		lis[l].onmouseover=function(){this.className+=" visibleMenuOn";}
		lis[l].onmouseout=function(){this.className="visibleMenu";}
		lis[l].onmousedown=function()
		{
		    window.location=this.getElementsByTagName("A")[0].href;
		}
		ptag.onclick=function(){return false;}
		
		if(!isIE)
		{
			max=(lis[l].offsetWidth>max)?lis[l].offsetWidth:max;
			full_h+=lis[l].offsetHeight;
		}
		else
		{
			max=(ptag.offsetWidth>max)?ptag.offsetWidth:max;
			full_h+=ptag.offsetHeight;
		}
	}
	if(max==0) this.resizeShim();
	else
	{
		if(isIE)max+=6;
		if(window.opera) max-=4;
		this.menuShim.style.width=max+"px";
		//this.resizeShim=true;
		//	Magassag beallitasa
		if(!isIE)this.menuShim.style.height=(lis.length-1)*22+"px";
		else if(window.opera)this.menuShim.style.height=(lis.length-1)*22+"px";
		else this.menuShim.style.height=(lis.length-1)*20+"px";
	}
}
function hideAllMenu()
{
    for(m=0; m<menuList.length; m++)
    {
	menuList[m].hideMe();
    }
}
//	MAIN FUGGVďż˝NY, AMI Lďż˝TREHOZZA A JSselect-ket

var menuList=Array;
function setMenu()
{
	var tables=document.getElementsByTagName("table");
	var menus;
	var menuTable;
	if(tables)
	{
		
		for(t=0; t<tables.length; t++) 
		{
			if(tables[t].className=="TopMenuPortlet")
			{
				menus=tables[t].getElementsByTagName("SPAN");
				menuTable=tables[t];
				break;
			}
		}		
		try{
			if(menus)
			{
				menuList=new Array;
				//	1 menut tďż˝rol, amivel meghivja  a JSDDmenu-t	
				for(i=0; i<menus.length; i++)
				{
					if(menus[i].className=="subMenu")
					{
						menuList.push(new JSDDMenu(menus[i],20));
					}
				}
			}
			menuTable.style.display="block";
		}catch(e)
		{
			menuTable.style.display="block";
		}
	}
	
}

//addLoadEvent(setResizeEvent);
var everInFS=false;
window.onresize=function()
{
	if(window.location.href.indexOf("/print/")==-1)
	{
		var por=document.getElementById("portalmain");
		var browser=navigator.appName;
		var version=parseFloat(navigator.appVersion);
		por.style.position="absolute";
		por.style.position="relative";
		
		if((browser.indexOf("Explorer")>-1)&&(version<=4))
		{
			if(window.screenLeft==-2)
			{
				everInFS=true;
				por.style.position="absolute";
			}
			else if(everInFS)
			{
				por.style.position="absolute";
			}
		}
	}
}

function windowPositioner(){
	var por=document.getElementById("portalmain");
	por.style.position="relative";
	por.style.left=0+"px";
	por.style.top=0+"px";
}

function doResize()
{
	var sizeNow=document.body.offsetWidth*document.body.offsetHeight;
	if(sizeNow==resizeEvent)
		//window.location.reload();

	resizeEvent=sizeNow;
	setTimeout("doResize()", 200);
}


/*###########################	CHECKBOX*/
//<input name="forgalmi_reszveny_c1" type="checkbox">
addLoadEvent(replaceCheckBoxes);
function checkBoxReplace(element,className)
{
	this.element=element;
	this.ClickEvent=element.onclick;
	this.parentDiv=element.parentNode;
	this.classNm=className;
	this.checkBox=document.createElement("div");		// az uj checkBox
	this.parentDiv.appendChild(this.checkBox);
	this.replace();
  return this;
}
checkBoxReplace.prototype.checkSate=function()
{
	if(this.element.checked==true) this.checkBox.className=this.classNm+"_checked";
	else this.checkBox.className=this.classNm+"_unchecked";
}
checkBoxReplace.prototype.replace=function()
{

	this.element.style.display="none";
	this.checkBox.className=this.classNm+"_unchecked";
	this.checkBox.style.width=12+"px";
	this.checkBox.style.height=12+"px";
	var p=this;
	
	this.checkBox.onclick=function()
	{
	    if(this.disabled==false || this.disabled==undefined)
	    {
		if(this.className==p.classNm+"_unchecked")
		{
			this.className=p.classNm+"_checked";
			p.element.checked=true;
      
		      reInitCheckBoxes();
		}
		else
		{
		    if(this.className.indexOf("CheckBx")>-1)
		    {
			this.className=p.classNm+"_unchecked";
			p.element.checked=false;
		    }
      
		      reInitCheckBoxes(); 
		}
	        try {
                     p.ClickEvent();
		} catch (e) {}
	    }
	}
}
var checkBx=new Array();
function replaceCheckBoxes()
{
	var inputs=document.getElementsByTagName("input");
	var t=0;
	checkBx=new Array();
	for(i=0; i<inputs.length; i++)
	{
		if(inputs[i].type=="checkbox")
		{		
			checkBx.push(new checkBoxReplace(inputs[i],"CheckBx"));
			t++;
		}
		else if(inputs[i].type=="radio")
		{		
			checkBx.push(new checkBoxReplace(inputs[i],"Radio"));
			t++;
		}
	}
	reInitCheckBoxes();
}

function reInitCheckBoxes()
{
  for(i=0; i<checkBx.length; i++)
	{
    if(checkBx[i].element.checked==true) checkBx[i].checkBox.className=checkBx[i].classNm+"_checked";
    else checkBx[i].checkBox.className=checkBx[i].classNm+"_unchecked";
  }
}


/*###########################	LOGIN*/
addLoadEvent(initLogin);
var Lbase=null;
var Ltop=null;
var Lfoot=null;
var Lheight=0;
var Lref=0;
var Ldst=0;
var Lenabled=true;
var pos;
var Lstep=15;
var Lbg=null;
var Lparheight=0;
function initLogin()
{
	Lbase=document.getElementById("BejelentkezesB");
	Ltop=document.getElementById("AuthLogin");
	Lfoot=document.getElementById("loginFoot");
	
	Lheight=Lbase.clientHeight;
	Lparheight=Lfoot.clientHeight+Ltop.clientHeight;
  
  if(document.getElementById("LogoutForm") != null) {
    addLoadEvent(onMouseOverAction);
  }

	Ltop.onclick=onMouseOverAction;
	pos=0;
	
	Lfoot.style.position="relative";

	Lbase.style.position="absolute";
	Lref=0;
	Ldst=Lheight+getAbsoluteTop(Lfoot);
	if(window.location.href.indexOf("login=failure")!=-1)
	{
		Lbase.style.visibility="visible";
		Lfoot.style.top=Lheight+"px";
		Lfoot.parentNode.style.height=Lparheight+Lheight+"px";
		pos=Lheight;
	}
	else
	{
		Lbase.style.visibility="hidden";
		Lbase.style.left=getAbsoluteLeft(Lfoot)+"px";
	}
  
}

function onMouseOverAction()
	{
		turnOffResize();
		if(Lenabled)
		{
			if(pos==0)
			{
				Lenabled=false;
				//Lbase.style.visibility="visible";
				Lbase.parentNode.onmouseover="";
				openLogin();
			}
			else
			{
				/*Lenabled=false;
				Lbase.style.visibility="hidden";
				hideLogin();*/
			}
		}
	}

function openLogin()
{

  if(getAbsoluteTop(Lfoot)<=Ldst) 
	{
		pos=pos+Lstep;
		Lfoot.style.top=parseInt(pos)+"px";
		Lfoot.parentNode.style.height=Lparheight+pos+"px";
		setTimeout("openLogin()",20);
	}
	else
	{
		Lbase.style.left=3+"px";
		Lbase.style.visibility="visible";
		pos=Lheight;
		Lenabled=true;
		turnOnResize();
	}
}

function hideLogin()
{
	if(pos>=0) 
	{
		pos=pos-Lstep;
		Lfoot.style.top=parseInt(pos)+"px";
		Lfoot.parentNode.style.height=Lparheight+pos+"px";
		setTimeout("hideLogin()",20);
	}
	else
	{
		//Lfoot.style.top=-20+"px";
		pos=0;
		Lbase.style.visibility="hidden";
		Lenabled=true;
	}
}

//############################		FLV PLAYER

function addFLVPlayer()
{
	var swheight=null;
	var swwidth=null;
	var swportal_path=null;
	var swvideo_path=null;
	var swthumb_path=null;


	var flvDiv=document.getElementById("flv_player_div");	
	swportal_path=flvDiv.className;
	paths=swportal_path.split('#');
	swportal_path=paths[0];
	swportal_path=swportal_path.substring(0,swportal_path.length);		//	/portal levĂĄgĂĄsa
	if(swportal_path.indexOf("/portal")>-1)
	{
		swportal_path=swportal_path.split("portal")[0];
	}
	swvideo_path=paths[1];
	swvideo_path=swvideo_path.substring(1,swvideo_path.length-3)+"flv";
	swvideo_path=swportal_path+swvideo_path;
	
	swthumb_path=swvideo_path;
	swthumb_path=swthumb_path.substring(0,swthumb_path.lastIndexOf('/'))+"/thumbnail.jpg";

	swwidth=paths[2];
	swheight=paths[3];
	
	var iframe=document.createElement('IFRAME');
	iframe.setAttribute("scrolling","NO");
	iframe.setAttribute("frameBorder","0");

	var parameters="?video_path="+swvideo_path;
	parameters+="&thumb_path="+swthumb_path;
	parameters+="&width="+swwidth;
	parameters+="&height="+swheight;
	parameters+="&portal_path="+swportal_path;
	
	iframe.setAttribute( 'src', 'sites/bet/html/flashPlayer.html'+parameters );
	
	var p=document.getElementById("player1");
	p.appendChild(iframe);
	p.id="player1_m";
	swwidth=parseInt(swwidth);
	iframe.style.width=swwidth+"px";
	
	swheight=parseInt(swheight);
	iframe.style.height=swheight+"px";
	flvDiv.parentNode.removeChild(flvDiv);
	
}

/**
	Debug Div
*/
var debug=null;
var debugState=false;
var logs="";
addLoadEvent(debugInit);

function debugInit()
{
	debug=new debugDiv();
	debug.addLog("Debug Console");
	debug.addLog("------------------------");
}

function debugDiv()
{
	this.win=document.createElement("DIV");
	this.win.style.width=0+"px";
	this.win.style.height=0+"px";
	this.win.style.left=0+"px";
	this.win.style.top=0+"px";
	this.win.style.position="absolute";
	this.win.style.border="1px solid white";
	this.win.style.zIndex=2000;
	this.win.style.background="black";
	this.win.style.color="white";
	this.win.style.overflowY="scroll";
	this.win.style.overflowX="scroll";
	if(debugState)
	{
	this.win.onclick=function()
	{
		this.style.height=500+"px";
		this.style.width=300+"px";
		this.innerHTML=logs;
	}
	
	var t=this;
	var press=false;
	this.win.onmousedown=function()
	{
		press=true;
	}
	this.win.onmouseup=function()
	{
		press=false;
	}
	
	this.win.onmousemove=function(e)
	{
		if(press)
		{
			x=0;y=0;
			if(isIE)
			{
				x=event.clientX;
				y=event.clientY;
			}
			else
			{
				x=e.pageX;
				y=e.pageY;
			}
			if(parseInt(this.style.height)>5)
			{
				this.style.left=x-150+"px";this.style.top=y-250+"px";
			}
		}
	}
	
	var win=this.win;
	document.getElementById("portalmain").appendChild(win);
	}
}
debugDiv.prototype.activate=function()
{
	this.style.height=500+"px";
		this.style.width=300+"px";
		this.innerHTML=logs;
}
debugDiv.prototype.addLog=function(msg)
{
//	log=document.createElement("DIV");
//	log.appendChild(document.createTextNode(msg));
	logs+="<div>"+msg+"</div>";
	if(parseInt(this.win.style.height)>5)
	{
	this.win.innerHTML=logs;
	}
}


/**
	IE flash activator
*/
addLoadEvent(activateFlash);
function activateFlash()
{
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
	    objects[i].outerHTML = objects[i].outerHTML;
	}
}



