window.onload = inicializar_scripts;

function inicializar_scripts()
{
	montre();
	mostrar_fecha();
	mostrar_hora();
}

/************************************************************************/
/*  FECHA  */
/************************************************************************/
function mostrar_fecha()
{
	var d, dia, x;
	d = new Date();
  	dia = d.getDay();
  	dia2 = d.getDate();
	mes = d.getMonth();
	ano = d.getFullYear();

	var x = new Array("Domingo", "Lunes", "Martes", "Mi&eacute;rcoles","Jueves", "Viernes", "S&aacute;bado");
	var y = new Array("enero", "febrero", "marzo", "abril","mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");
	mydate="<b>"+x[dia]+" "+dia2+" "+y[mes]+" "+ano+"</b>";
	document.getElementById('livefecha').innerHTML=mydate
}

/************************************************************************/
/*  HORA  */
/************************************************************************/
function mostrar_hora()
{
	if (!document.layers&&!document.all&&!document.getElementById)
		return
	var Digital=new Date()
	var hours=Digital.getHours()
	var minutes=Digital.getMinutes()
	var seconds=Digital.getSeconds()
	var dn="AM" 
	if (hours>12)
	{
		dn="PM"
		hours=hours-12
	}
	if (hours==0) hours=12
	if (minutes<=9) minutes="0"+minutes
	if (seconds<=9) seconds="0"+seconds
	myclock="<b>"+hours+":"+minutes+":"+seconds+" "+dn+"</b>"
	document.getElementById('liveclock').innerHTML=myclock
	setTimeout("mostrar_hora()",1000)
}

/************************************************************************/
/*  MENU  */
/************************************************************************/
function montre(id) 
{
	var seccion = document.location.search;
	var visible = 0;
	for (var i = 1; i<=15; i++) 
	{
		if (document.getElementById('smenu'+i)) 
		{
			document.getElementById('smenu'+i).style.display='none';
			var aux = document.getElementById('smenu_ul'+i).childNodes;
			var l1 = aux.length;
			for(var j = 0; j<l1; j++)
			{
				if(aux[j].nodeName == "LI")
				{
					var aux2 = aux[j].childNodes;
					seccion2 = aux2[0].attributes["href"].value.indexOf("?");
					if(aux2[0].attributes["href"].value.substring(seccion2) == seccion)
					{
						visible = i;
						document.getElementById('smenu'+i).style.display='block';
					}
				}
			}
		}
	}

	var d = document.getElementById(id);
	if (d) 
	{
		d.style.display='block';
	}

	for (var i = 1; i<=15; i++) 
	{
		var aux = 'smenu'+i;
		d = document.getElementById('smenu'+i);
		if(d && (aux != id) && (visible!=i))
		{
			d.style.display='none';
		}
	}	
}

/************************************************************************/
/*  Validar HTML  */
/************************************************************************/
function validar_HTML(form_id) 
{
	if (document.all)  //Internet Explorer
	{
		if(document.frames.texto___Frame.document.frames.length > 0)
		{
			codigo = document.frames.texto___Frame.document.frames[0].document.body.innerHTML;
		}
		else
		{
			alert("Por favor, salga del modo 'Fuente HTML'");	
			return;
		}
	}
	else 
	{
		var iframes = document.getElementById("texto___Frame");
		var contenido = iframes.contentDocument.getElementsByTagName("iframe");
		if(contenido.item(0))
		{
			var iframe = contenido.item(0).contentDocument;
		}
		else
		{
			alert("Por favor, salga del modo 'Fuente HTML'");	
			return;
		}
		var codigo = iframe.body.innerHTML;
	}

	codigo = parsearHTML(codigo);

	// Duplicamos formulario para validar
	//Si ya existe el formulario lo eliminamos
	if(document.getElementById('Formulario_W3C'))
	{
		var padre = document.getElementById('Formulario_W3C').parentNode;
		var form = document.getElementById('Formulario_W3C');
		padre.removeChild(form);
	}

	var newForm = document.createElement('form');
	newForm.style.position = 'absolute';
	newForm.name = 'Formulario_W3C';
	newForm.id = 'Formulario_W3C';
	newForm.method = 'post';
	newForm.action = 'http://validator.w3.org/check';
	newForm.target = 'Validar';
	newForm.onsubmit = window.open('http://validator.w3.org/check','Validar','menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,width=700,heigth=300');
	var padre_form = document.getElementById(form_id).parentNode;
	padre_form.appendChild(newForm);

	var fragment = document.createElement('textarea');
	fragment.name = 'fragment';
	fragment.id = 'fragment';
	fragment.value = codigo;
	fragment.style.visibility = 'hidden';
	document.getElementById('Formulario_W3C').appendChild(fragment);

	var prefill = document.createElement('input');
	prefill.type = 'hidden';
	prefill.name = 'prefill';
	prefill.id = 'prefill';
	prefill.value = 1;
	prefill.style.visibility = 'hidden';
	document.getElementById('Formulario_W3C').appendChild(prefill);

	var doctype = document.createElement('input');
	prefill.type = 'hidden';
	doctype.name = 'doctype';
	doctype.id = 'doctype';
	doctype.value = 'HTML 4.01 Transitional';
	doctype.style.visibility = 'hidden';
	document.getElementById('Formulario_W3C').appendChild(doctype);

	newForm.submit();
}

function parsearHTML(codigo) 
{
	var res = '';
	
	var aux = codigo.indexOf('_fcksavedurl');
	if(aux > 0)
	{
		res = codigo.substring(0,aux);
		var aux2 = codigo.indexOf(' ',aux);
		res = res+parsearHTML(codigo.substring(aux2));
	}
	else
	{
		res = codigo;
	}
	return(res);
}

