function toggle(o)
{
	if (o==null) return false;

	if (o.style.display!='block')
	{
		hideSelects('hidden')
		o.style.display='block';
	}else{
		hideSelects('visible')
		o.style.display='none';
	}

	return true;
}

function hideSelects(action) {
//documentation for this script at http://www.shawnolson.net/a/1198/
//possible values for action are 'hidden' and 'visible'
if (action!='visible'){action='hidden';}
if (navigator.appName.indexOf("MSIE")) {
for (var S = 0; S < document.forms.length; S++){
for (var R = 0; R < document.forms[S].length; R++) {
if (document.forms[S].elements[R].options) {
document.forms[S].elements[R].style.visibility = action;
}
}
} 
}
}

function radio(o)
{
	o2 = document.all("radiospan");

	if (o==null)
	{
		o2.style.display='none';
		o2.innerHTML=''
		return;
	}

	o2.style.display='block';
	
	o2.style.pixelTop = parent.document.body.scrollTop + 100
	o2.style.pixelLeft = (parent.document.body.clientWidth - o2.clientWidth + parent.document.body.scrollLeft) / 2

	linkfichapuro = "frames[\"getcard\"].document.location.href=\"get.card.php?username=" + o + "\";"
	linkficha = "<a title='Ver ficha del jugador...' href='javascript:" + linkfichapuro + "radio()';>"
	linkinvitar = "location.href=\"add.game.php?type2=5&private=1&guest=" + o +"\";"

	binvitar = "<input style='float:left;margin-left:5;margin-top:3;' type=button class=buttonlarge value='Invitar a jugar' onclick='" + linkinvitar + ";radio()'>"
	//o2.innerHTML = "<span style='margin-left:19;'>Escriba el mensaje para <b>" + o + "</b>:</span><br><table border=0><tr valign=top><td><textarea name=radiospantext style='width:337;height:102;overflow:auto;margin-bottom:9;margin-right:7;margin-top:11' onkeypress=\"if (window.event.keyCode==13) {window.event.cancelBubble=true;window.event.keyCode=0;}else{radioircadvice('" + o + "')};\" onkeydown=\"if (window.event.keyCode==13) {radiodirect('" + o + "');}\"></textarea></td><td>" + linkficha + "<img class=avatar src=cropimage/view.image.php?username=" + o + " style='margin-top:12' style='border:1px solid #5A8DBC;width:100px;height:100px;'></a></td></tr></table>" + parent.document.all("radioemoticons").innerHTML + "<input style='float:right;margin-top:3;' type=button class=buttonbluelarge value=\"Enviar mensaje\" onclick=\"radiodirect('" + o + "')\"><input style='float:left;margin-top:3;' type=button class=button value=Cancelar onclick=\"radio()\"><input style='float:left;margin-left:5;margin-top:3;' type=button class=button value='Ver ficha' onclick='" + linkfichapuro + ";radio()'>" + binvitar;
	o2.innerHTML = "<span style='margin-left:19;'>Escriba el mensaje para <b>" + o + "</b>:</span><br><table border=0><tr valign=top><td><textarea name=radiospantext style='width:337;height:102;overflow:auto;margin-bottom:9;margin-right:7;margin-top:11' onkeypress=\"if (window.event.keyCode==13) {window.event.cancelBubble=true;window.event.keyCode=0;}\" onkeydown=\"if (window.event.keyCode==13) {radiodirect('" + o + "');}\"></textarea></td><td>" + linkficha + "<img class=avatar src=cropimage/view.image.php?username=" + o + " style='margin-top:12' style='border:1px solid #5A8DBC;width:100px;height:100px;'></a></td></tr></table>" + parent.document.all("radioemoticons").innerHTML + "<input style='float:right;margin-top:3;' type=button class=buttonbluelarge value=\"Enviar mensaje\" onclick=\"radiodirect('" + o + "')\"><input style='float:left;margin-top:3;' type=button class=button value=Cancelar onclick=\"radio()\"><input style='float:left;margin-left:5;margin-top:3;' type=button class=button value='Ver ficha' onclick='" + linkfichapuro + ";radio()'>" + binvitar;	
	
	document.all('radiospantext').focus()
}

/*
function radioircadvice(o,o2)
{
	try{
		parent.sendrefresh2flash(o,'PIN\t'+o2);
	}catch (e){
	}
}
*/

function radioemoticon(t,p)
{
	id=t.parentElement.parentElement.id
	id=id.split("_")[2]
	o = document.all('radiospantext')
	if (o)
	{
		o.focus();
		o.value += p;
	}
}

function radiodirect(o)
{
	if (typeof toref!="undefined")
		clearTimeout(toref);

	previa = "Escriba el mensaje para " + o + ":";

	a=document.all("radiospantext").value
	if (a!='')
	{
		url = 'add.radio.php?username=' + escape(o) + '&message=' + escape(a);

		if (document.all('lastmessage')!=null)
			url += '&lastmessage=' + document.all('lastmessage').value;
		if (document.all('lastid')!=null)
			url += '&lastid=' + formmessages.lastid.value;
		if (document.all('lastradio')!=null)
			url += '&lastradio=' + document.all('lastradio').value;

		try{
		if (formmessages.game!=null)
			url += '&game=' + formmessages.game.value;
		}catch(e){}

		radio();
		waiting("Enviando el mensaje a " + o + "...");
		window.open(url,'refresher');
	}
}

function chat(o,subject)
{
	if (a=window.prompt(subject,""))
	{
		url = 'add.message.php?mensaje=' + escape(a);
		if (document.all('lastmessage')!=null)
			url += '&lastmessage=' + document.all('lastmessage').value;
		if (document.all('lastid')!=null)
			url += '&lastid=' + formmessages.lastid.value;

		try{
		if (formmessages.game!=null)
			url += '&game=' + formmessages.game.value;
		}catch(e){}

		waiting("Enviando el mensaje...");
		window.open(url,'refresher');
	}
}

function waiting(s,barw)
{
	o = document.all("waiting");

	o.style.left = document.body.clientWidth / 2 - 125;

	if (s==null)
	{
		o.style.display='none';
	}else{
		sc="<br><span style='float:right'>[<a href=javascript:// onclick=waiting() title=Cerrar>cerrar</a>]</span>"
		ss="[<a href='javascript:location.href=location.href' title=Cerrar class=join>actualizar pantalla</a>]"
		if (barw==null)
			o.innerHTML= "<center><img src=img/loading5.gif style='margin-bottom:6px'><br><b>" + s + "</b><br><img style='margin-top:6px' src=img/loading6.gif></center>" + sc + ss;
		else
			o.innerHTML= "<b>" + s + "</b><br>" + sc + ss;

		o.style.display='block';
	}
}

var connectortimeout;
function connectornews(s,direction)
{
	o = document.all("connectornews");

	if (direction==null) direction='down'

	if (s==null)
	{
		o.style.display='none';
	}else{
		o.innerHTML= '<marquee behavior="slide" scrolldelay="50" direction="' + direction + '" class=connectornewsmarquee scrollamount="1"><span class=connectornewscontent>' + s + '</span></marquee>';

		o.style.left = (document.body.clientWidth - 300) / 2;
		o.style.display='block';
		clearTimeout(connectortimeout);
		connectortimeout = setTimeout("document.all('connectornews').style.display='none';",5000);
	}
}

function banner(s)
{
	o = document.all("banner2");
	if (o.style.display=='block') return;

	o = document.all("banner");

	if (s==null)
		o.style.display='none';
	else
	{
		o.style.left = document.all("0303").offsetLeft;
		o.style.top = document.all("0302").offsetTop;

		try { o.filters[0].apply(); } catch(e) {}
		o.innerHTML= "<a style='float:right' href=javascript:// onclick=banner() title=Cerrar>X</a>" + s;
		o.style.display='block';
		try { o.filters[0].play(); } catch(e) {}

	}
}

function systemmessage(s)
{
	o = document.all("systemmessage");

	if (s==null)
		o.style.display='none';
	else
	{
		try { o.filters[0].apply(); } catch(e) {}
		o.innerHTML= s;
		o.style.display='block';
		try { o.filters[0].play(); } catch(e) {}

		o.style.pixelTop = parent.document.body.scrollTop + 66
		o.style.pixelLeft = (parent.document.body.clientWidth - o.clientWidth + parent.document.body.scrollLeft) / 2 - 5
		o.style.zIndex=1000

	}
}

function resize() {
	o=document.all("messages")
	o.style.height += document.all("board2").style.pixelHeight - document.all("messages").offsetTop - 1;
	o.scrollTop = 0;
	o.scrollTop = o.scrollHeight;
}

function setcookie(name,value) {
        var exp = new Date();
        var oneYear = exp.getTime() + (60000 * 60 * 24 * 365);
	exp.setTime(oneYear);

	document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); 
	document.location.reload();
}


//FUNCIONES DRAE
function showdrae(p)
{
	temp = 'http://buscon.rae.es/draeI/SrvltGUIBusUsual?TIPO_BUS=3&TIPO_HTML=2&LEMA=' + escape(p.toLowerCase());
	showdraespan("<br><IFRAME frameborder=0 src='" + temp + "'></IFRAME>")
}

function showdraespan(s)
{
	o = document.all("draespan");

	if (s==null)
		o.style.display='none';
	else
	{
		o.style.left = document.all("0101").offsetLeft;
		o.style.top = document.all("0101").offsetTop;

		o.innerHTML= "<a style='float:right;margin-bottom:5px' href=javascript:// onclick=showdraespan() title=Cerrar>cerrar</a>" + s;
		o.style.display='block';
	}
}
