var helpdownloaded=false;
var helpvisible=false;

function downloadhelp(page)
{
	if (!helpdownloaded)
	{
		var myAjax=new Ajax.Request(
			"gethelp.php?page="+page,
			{
				method: "GET",
				onSuccess: function(req)
				{
					document.getElementById("help_txt").innerHTML=req.responseText;
					helpdownloaded=true;
				}
			}
		);
	}
	
	if (!helpvisible)
	{
		document.getElementById("help_txt").style.display="";
		helpvisible=true;
	}
	else
	{
		document.getElementById("help_txt").style.display="none";
		helpvisible=false;
	}
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else
  {
    return document.getElementById(movieName);
  }
}

function imgviewer_DoFSCommand(command,args)
{
	if (command=="close")
	{
		avatarclose();
	}
}

function getPageScroll()
{
	var yScroll;

	if (self.pageYOffset) yScroll=self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) yScroll=document.documentElement.scrollTop;
	else if (document.body) yScroll=document.body.scrollTop;

	arrayPageScroll=new Array('',yScroll)
	return arrayPageScroll;
}

function getPageSize(){

	var xScroll, yScroll;

	if (document.body.scrollHeight > document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else
	{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight)
	{
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}

	if (yScroll < windowHeight) pageHeight=windowHeight;
	else pageHeight=yScroll;

	if (xScroll < windowWidth) pageWidth=windowWidth;
	else pageWidth=xScroll;

	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight)

	return arrayPageSize;
}

function avatarwin(imgurl)
{
	var arrayPageSize=getPageSize();
	var arrayPageScroll=getPageScroll();

	document.getElementById("avatarbox").style.top=(arrayPageScroll[1]+((arrayPageSize[3]-35-410)/2)+"px");
	document.getElementById("avatarbox").style.left=(((arrayPageSize[0]-40-410)/2)+"px");
	document.getElementById("avatarbox").style.zIndex=101;
	document.getElementById("avatarbox").innerHTML="";

	var s="";
	s=s+"<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"400\" height=\"400\" id=\"imgviewer\" align=\"middle\">\n";
	s=s+"<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n";
	s=s+"<param name=\"movie\" value=\"imgviewer.swf?ver=070115a&imgurl="+escape(imgurl)+"\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#000000\" /><embed src=\"imgviewer.swf?ver=070115a&imgurl="+escape(imgurl)+"\" quality=\"high\" bgcolor=\"#000000\" width=\"400\" height=\"400\" name=\"imgviewer\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n";
	s=s+"</object>\n";

	document.getElementById("avatarbox").innerHTML=s;

	document.getElementById("avataroverlay").style.height=(arrayPageSize[1]+"px");
	document.getElementById("avataroverlay").style.zIndex=100;
	document.getElementById("avataroverlay").style.display="";

	reload_median();
}

function avatarclose()
{
	document.getElementById("avataroverlay").style.display="none";
}

String.prototype.trim=function()
{
	return( this.replace(/^\s+/, '').replace(/\s+$/, '') );
}

function ablak( oldal, w, h )
{
    OpenWin=this.open(oldal, "CtrlWindow", "width="+w+",height="+h+",toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no");
}

function ablak_scroll( oldal, w, h )
{
    OpenWin=this.open(oldal, "CtrlWindow", "width="+w+",height="+h+",toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}

function newImage(arg)
{
	if (document.images)
	{
		rslt=new Image();
		rslt.src=arg;
		return rslt;
	}
}

function changeImages()
{
	if (document.images && (preloadFlag == true))
	{
		for (var i=0; i<changeImages.arguments.length; i+=2)
		{
			document[changeImages.arguments[i]].src=changeImages.arguments[i+1];
		}
	}
}

var preloadFlag=false;
function preloadImages()
{
	if (document.images)
	{
		main1_o=newImage( imglangpath+"home_o.gif" );
		main2_o=newImage( imglangpath+"friends_o.gif" );
		main3_o=newImage( imglangpath+"invitation_o.gif" );
		main4_o=newImage( imglangpath+"messages_o.gif" );
		main5_o=newImage( imglangpath+"search_o.gif" );
		main6_o=newImage( imglangpath+"chat_o.gif" );
		main7_o=newImage( imglangpath+"games_o.gif" );
		main8_o=newImage( imglangpath+"profile_o.gif" );
		main9_o=newImage( imglangpath+"club_o.gif" );
		preloadFlag=true;
	}
}

function konfirm( felirat, cel )
{
	if ( confirm( felirat ) )
		location.href=cel;
}

//Flash hozzáadása IE aktiválás kiküszöbölésével
function addFlash(movieToPlay, containerId)
{
	wrapper = document.getElementById(containerId);

	var agt = navigator.userAgent.toLowerCase();
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

	if (is_ie)
	{
		wrapper.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='550' height='350' id='postcardFlash' align='middle'><param name='movie' value='"+movieToPlay+"' /><param name='quality' value='high' /><embed src='"+movieToPlay+"' quality='high' width='550' height='350' name='postcardFlash' align='middle' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	}
	else
	{
		while (wrapper.hasChildNodes()) wrapper.removeChild(wrapper.firstChild);

		var obj = document.createElement("object");

		obj.type = "application/x-shockwave-flash";
		obj.data = movieToPlay;
		obj.width = "550";
		obj.height = "350";

		var param = document.createElement("param");
		param.name = "movie";
		param.value = movieToPlay;
		obj.appendChild(param);

		wrapper.appendChild(obj);
	}
}
//Cookie kezelés
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function reload_median()
{
	var same=Math.floor(Math.random()*1000000);
	same=same+sameext;
	document.getElementById("median").innerHTML='<img src="http://audit.median.hu/cgi-bin/track.cgi?uc='+mediancode+'&dc=1&mid=322'+medianuser+'&ui='+same+'" width="1" height="1">';
}

function isImageComplete(img)
{
	// During the onload event, IE correctly identifies any images
	// that weren't downloaded as not complete. Others should too.
	// Gecko-based browsers act like NS4 in that they report this
	// incorrectly: they always return true.
	if(!img.complete)
	{
		return false;
	}
	// However, they do have two very useful properties: naturalWidth
	// and naturalHeight. These give the true size of the image. If
	// it failed to load, either of these should be zero.
	if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0)
	{
		return false;
	}
	// No other way of checking: assume it's ok.
	return true;
}
