// == Chat Functions



//Default nick on connect

default_nick = '';



// Away form messages

msg0 = 'You are already away!';

msg1 = 'You are not away!';

msg2 = 'I\'m currently away';



// send a string to applet

function SendIt(string)

{

	document.applet.sendString(string);

	document.applet.requestSourceFocus();

}



// send smiley string to applet

function smiley(symbol)

{

	document.applet.setFieldText(document.applet.getFieldText()+symbol+' ');

	document.applet.requestSourceFocus();

}



isaway = false;

// switch nick, set away message

function maway(action, nick)

{

	var away_reason = document.getElementById('away_reason').value;

	switch (action)

	{

		case 'away':

			if (!isaway)

			{

				txt = away_reason;

				if (txt == '') txt = msg2;



				SendIt('/nick '+nick+'|away');

				SendIt('/away '+txt);

				isaway = true;

			} else alert(msg0);

			break;

		case 'back':

			if (isaway)

			{

				SendIt('/nick '+nick);

				SendIt('/away');

				away_reason = '';

				isaway = false;

			} else alert(msg1);

			break;

	}

}



// == Login Page Functions



// Check Form Data

function CheckForm(self)

{

	if (!CheckFormData(document.login.chan, 'Por Favor, escriba una sala')) return false;

	if (!CheckFormData(document.login.host, 'Ingrese un servidor!')) return false;



  	if (document.login.save && document.login.save.checked && document.cookie)

  	{

  		if (!confirm('Sobreescribir Nick Anterior?')) return false;

  	}



	var nick = document.login.nick;



	if (nick.value == '')

	{



      alert ('Necesita ingresar un Nick');

//*		nick.value = default_nick+Math.round(Math.random()*1000);

         

        nick.focus();

		return false;



	}





/*

	else if(!nick.value.match(/^[A-Za-z0-9\[\]\{\}^\\\|\_\-`]{1,32}$/))

	{

		alert('Escriba un nick Válido!');

		nick.value = nick.value.replace(/[^A-Za-z0-9\[\]\{\}^\\\|\_\-`]/g, '');

		nick.focus();

		return false;

	}

*/

//////////////////////

   

	if (document.login.popupenabled && document.login.popupenabled.value)

	{

		document.login.target = 'mypopup';

	}



	if (document.login.layerenabled && document.login.layerenabled.value) LoadLayer('400', '200');

	if (document.login.popupenabled && document.login.popupenabled.value)

	{

		OpenPopup(self, '700', '530');

		window.setTimeout('window.location.href = \''+self+'\'', 10000);

	}



	return true;

}



function CheckFormData(inp, msg)

{

	if (inp)

	{

		if (inp.value == '')

		{

			alert(msg);

			inp.focus();

			return false;

		}

		else return true;

	}

	return true;

}



// write invisible layer

function WriteLayer(message)

{

	var html = '<div id="layerwindow" class="layerwindow">\n';

	html += '\t<table width="400" height="100%"cellspacing="0" cellpadding="0" class="border"><tr>\n';

	html += '\t\t<td align="center" height="100%"><h2>'+message+'<\/h2><\/td>\n';

	html += '\t<\/tr><\/table>\n';

	html += '<\/div>\n';



	return html;

}



// make layer visible, and put it to the center of the browser window

function LoadLayer(x, y)

{

	var divwidth  = x;

	var divheight = y;

	var browserwidth  = window.innerWidth || document.body.clientWidth;

	var browserheight = window.innerHeight || document.body.clientHeight;

	var leftpx = (browserwidth-divwidth)/2;

	var toppx  = (browserheight-divheight)/2;



	document.getElementById('layerwindow').style.top  = '0px';

	// document.getElementById('layerwindow').style.top  = Math.round(toppx)+'px';

	document.getElementById('layerwindow').style.left = Math.round(leftpx)+'px';

	document.getElementById('layerwindow').style.visibility = 'visible';

}



// open chat in popup window

function OpenPopup(url, target)

{

	w = screen.width*(3/4);

	h = screen.height*(5/6);

	l = (screen.width-w)/2;

	t = (screen.height-h)/4;

	values = "width="+w+",height="+h+",left="+l+",top="+t+",menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no,location=no";

	window.open(self,'mypopup',values);

	

}









// check, if java is enabled in browser

function JavaCheck()

{

	var html = '<table width="100%" cellspacing="0" cellpadding="0" class="footer">\n';



	var status = 'No_Instalado';

	if (navigator.javaEnabled()) status = 'OK';



	html += '\t<tr><td align="right">\n';

	html += '\t\tJava Plug-in =&nbsp;<span style="color: yellow;">'+status+'<\/span>\n';



	if (status == 'No_Instalado')

	{

		html += '\t\t<br>Descargalo. <a href="/auto.htm" target="_blank">Click Aqui<\/a>\n';

	}



	html += '\t<\/td><\/tr>\n';

	html += '<\/table>\n';



	return html;

}
