
Main.$ = function ()
{
	var Aux  = document.getElementById (arguments [0]);
	var Pars = null;
	
	switch (arguments.length)
	{	case 1: return Aux;
		case 2: return Aux ? Aux [arguments [1]] : null;
		case 3: 
			if (Aux) 
			{	Pars = arguments [1].split ('.');
				for (var i = 0; i < Pars.length - 1; i++) Aux = Aux [Pars [i]];
			  Aux [Pars [i]] = arguments [2]; 
			}
			break;
		default: alert ('$, número de parámetros incorrectos.');
	}
}


Main.AvisoLegal = function ()
{
  var Ventana = new TVentanas ();

  Ventana.Tipo           = 2;
  Ventana.Ancho          = 550;
  Ventana.Alto           = 550;
  Ventana.BarraScroll    = true;
  Ventana.Vars.Plantilla = 'plantillas/tpls/avisolegal.tpl';
  Ventana.CerrarOnVelo   = true;
  Ventana.Cargar ();
}


Main.Captcha = function (sImg)
{
	var Ajax = new TAjax ();
	
  Ajax.onCargar = function (oPeticion) { Main.$ (sImg, 'src', '/lib/fuentes/captcha.php?Id=' + new Date().getTime()); }
  Ajax.Vars.Cambiar = 1;
  Ajax.Cargar ('/lib/fuentes/captcha.php');
}



Main.Evento = function (oElemento, sEvento, oFuncion)
{
	if (oElemento.addEventListener)	oElemento.addEventListener (sEvento, oFuncion, false);
	else if (oElemento.attachEvent) oElemento.attachEvent ('on' + sEvento, oFuncion);
}


Main.EnviarClave = function (oFormulario)
{
	if (Formulario.Validar (oFormulario))
	{	var Ajax = new TAjax ();
		
		Ajax.onCargar = function (oPeticion) 
										{ 
											if (Main.Mensaje (oPeticion.asText ())) 
											{	alert ('Se ha enviado la clave de acceso a su email.');
												TVentanas.Cerrar ();
											}
										}
		Ajax.Vars.Email   = oFormulario.Email.value;
		Ajax.Vars.Captcha = oFormulario.Captcha.value;
		Ajax.Cargar ('/lib/emails/enviarclave.php');
	}
}


Main.flash = function (oflash)
{
	var div = null;

	if (typeof (oflash.contenedor) == 'string') div = document.getElementById (oflash.contenedor);
	else if (typeof (oflash.contenedor) == 'object') div = oflash.contenedor;
	else alert ('No se ha encontrado el contenedor.');

	if (window.ActiveXObject) // IE
	{	div.innerHTML = '<object id="idFlash_' + (Main.idFlash++) + '"' +
		                ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
		                ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9.0.115"' +
		                ' width="' + oflash.ancho + '"' +
		                ' height="' + oflash.alto + '">' +
		                '<param name="movie" value="' + oflash.swf + '">' +
		                '<param name="allowfullscreen" value="true">' +
		                '<param name="allowscriptaccess" value="always">' +
		                '<param name="wmode" value="transparent">' +
		                '</object>';
	} else
	{	var emb = document.createElement ('embed', 'wmode');
		
		emb.setAttribute ('name', 'idFlash_' + (Main.idFlash++));
		emb.setAttribute ('id', 'idFlash_' + (Main.idFlash++));
		emb.setAttribute ('type', 'application/x-shockwave-flash');
		emb.setAttribute ('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
		emb.setAttribute ('width', oflash.ancho);
		emb.setAttribute ('height', oflash.alto);
		emb.setAttribute ('src', oflash.swf);
		emb.setAttribute ('allowfullscreen', 'true');
		emb.setAttribute ('allowscriptaccess', 'always');
		emb.setAttribute ('wmode', 'transparent');
		div.appendChild (emb);
	}
}


Main.Lopd = function ()
{
  var Ventana = new TVentanas ();

  Ventana.Tipo           = 2;
  Ventana.Ancho          = 550;
  Ventana.Alto           = 300;
  Ventana.Vars.Plantilla = 'plantillas/tpls/lopd.tpl';
  Ventana.CerrarOnVelo   = true;
  Ventana.Cargar ();
}


Main.Mensaje = function (sMsg)
{
	if (sMsg == 'OK') return true;
	else if (sMsg.substr (0, 4) == 'MSG:') alert (sMsg.substr (4));
	else alert ('Se ha producido un error.\nPor favor vuelva a intentarlo.');
	return false;
}


Main.RecordarClave = function ()
{
	var Ventana = new TVentanas ();

	Ventana.Tipo  = 2;
	Ventana.Ancho = 500;
	Ventana.Alto  = 320;
 	
 	Ventana.Vars.Plantilla = 'plantillas/tpls/recordarclave.tpl';
 	Ventana.Cargar ();
}


Main.SinImagen = function (oEvento, sSrc)
{
	if (! oEvento) oEvento = window.event;
	var oImg = oEvento.srcElement ? oEvento.srcElement : oEvento.currentTarget;

	if (oImg && oImg.src && oImg.src.substr (oImg.src.length - sSrc.length) != sSrc) oImg.src = sSrc;
}


function Main ()
{
}



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


Main.email = function (identificador)
{
	document.write ('<a href="mailto:' + identificador + '@ametel.es">' + identificador + '@ametel.es</a>');
}





