var bugRiddenCrashPronePieceOfJunk = (navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1);
var W3CDOM = (!bugRiddenCrashPronePieceOfJunk && document.getElementsByTagName && document.createElement);
var esMSIE = (navigator.userAgent.indexOf('MSIE') != -1);
var iniArray = Array ();

function js_inicializar ()
{if (W3CDOM){
	for (var i=0; i<iniArray.length; i++)
	{
		eval (iniArray [i]);
	}
}}

function js_estrella ()
{
	ene = Math.round (Math.random ()*11) +1;
	if (ene > 11) ene = 11;
	else if (ene < 1) ene = 1;
	ene = ene.toString (10)
	if (ene.length < 2) ene = '0'+ene;
	oEstrella = document.createElement ('div');
	oEstrella.style.position = 'absolute';
	oEstrella.style.top = '0';
	oEstrella.style.background = 'url(img/cab_'+ ene +'_drcab.gif) no-repeat right bottom';
	oEstrella.style.borderRight = '#0A0A6A solid 1px';
	oEstrella.style.marginLeft = '300px';
	oEstrella.style.width = '680px';
	oEstrella.style.height = '103px';
	oEstrella.style.zIndex = '5';
	oEstrella.innerHTML = '<img src="img/cab_'+ ene +'_drcar.gif" align="right" alt="adorno" />';
	$('contenedor').appendChild (oEstrella);
}

function js_forms ()
{
	oInputs = document.getElementsByTagName ('input');
	oSelects = document.getElementsByTagName ('select');
	oTextareas = document.getElementsByTagName ('textarea');
	
	for (i=0; i<oInputs.length; i++)
	{
		oInputs [i].onfocus = js_formCtrlFocus;
		oInputs [i].onblur = js_formCtrlBlur;
		if (oInputs [i].type == 'submit')
		{
			oInputs [i].onclick = function ()
			{
				this.disabled = true;
				this.value = 'Espere, por favor...';
				var oSelects = document.getElementsByTagName ('SELECT');
				if (oSelects)
				{
					for (var i=0; i<oSelects.length; i++)
					{
						if (oSelects [i].multiple)
						{
							if (oSelects [i].name) oSelects [i].name += '[]';
							for (var j=0; j<oSelects [i].options.length; j++)
							{
								oSelects [i].options [j].selected = true;
							}
						}
					}
				}
				this.form.submit ();
			}
		}
	}
	
	for (i=0; i<oSelects.length; i++)
	{
		oSelects [i].onfocus = js_formCtrlFocus;
		oSelects [i].onblur = js_formCtrlBlur;
	}
	
	for (i=0; i<oTextareas.length; i++)
	{
		oTextareas [i].onfocus = js_formCtrlFocus;
		oTextareas [i].onblur = js_formCtrlBlur;
	}
}

function js_formCtrlFocus () { this.style.backgroundColor = '#ffffff'; }
function js_formCtrlBlur () { this.style.backgroundColor = '#f6f6ff'; }

iniArray.push ('js_estrella ()');
iniArray.push ('js_forms ()');
window.onload = js_inicializar;