function fechaHoy()
{
	var Hoy= new Date();
	
	return (Hoy.getDate()+ "/" + (Hoy.getMonth() + 1)+ "/" + Hoy.getFullYear());
	
}
function cambiaNomFichero(e)
{
	
	var strNombre="";
	if(e.srcElement == null)
	{
		strNombre=e.name;
	}
	else
	{
		strNombre=e.srcElement.name;
	}
	
	strNom=strNombre.substring(strNombre.indexOf("_")+1);
	strObj="txtNomFichero"+strNom;
	strObjA=strNombre ;
	objF=eval("document.getElementById('" + strObjA + "')");
	obj=document.getElementById(strObj);
	obj.value=nombreFichero(objF.value);
}

function cargaOrden()
{
	var cad=QueryString("lstOrden");
		if (cad !=null)
		{
			document.getElementById("lstOrden").value=cad;
		}
}

function cambiaOrden(pag,lst)
{
	if (lst.value ==0 )
		return;
	location.href="home.aspx?opcion=" + pag + "&lstOrden=" + lst.value;
}
function borraFile(e)
{
	nom=e.srcElement.name;
	nom=nom.substring(nom.indexOf("_")+1);
	obj=eval("document.getElementById('divFichero" + nom + "')");
	obj.removeNode(true);
	
}

function borraElementos(e)
{
	var strNombre="";
	if(e.srcElement == null)
	{
		strNombre=e.name;
	}
	else
	{
		strNombre=e.srcElement.name;
	}
	strNombre=strNombre.substring(strNombre.indexOf("_")+1);
	
	//Borramos la fila de Título
	
	obj=eval("document.getElementById('tit_" + strNombre + "')");
	var Tabla = document.getElementById('tablaFicheros');
	Tabla.tBodies[0].removeChild(obj);

	//Borramos el primer separador
	obj=eval("document.getElementById('sepa_" + strNombre + "')");
	Tabla.tBodies[0].removeChild(obj);
	
	//Borramos la fila de Fichero
	obj=eval("document.getElementById('fic_" + strNombre + "')");
	Tabla.tBodies[0].removeChild(obj);
	//Borramos el segundo separador	
	obj=eval("document.getElementById('sepb_" + strNombre + "')");
	Tabla.tBodies[0].removeChild(obj);
}


function creaElementos()
{
	var nf=numFiles()+1;
	//Creamos la fila del titulo
	var Tabla = document.getElementById('tablaFicheros');
	fila=Tabla.tBodies[0].appendChild(document.createElement('TR'));
	fila.setAttribute("id","tit_" + nf);
		celda = document.createElement('TD');
		celda.appendChild(document.createTextNode('Título'));
	fila.appendChild(celda)
		celda = document.createElement('TD');
		var oInput = document.createElement("input");
		oInput.setAttribute("type","text");
		oInput.setAttribute("name","txtTitulo" + nf);
		oInput.setAttribute("size","40");
		oInput.className = "frmIngreso";
		celda.appendChild(oInput);
	fila.appendChild(celda);
	//Fila de Separación
	fila=Tabla.tBodies[0].appendChild(document.createElement('TR'));
	fila.setAttribute("id","sepa_" + nf);
		celda = document.createElement('TD');
		celda.setAttribute("height","5"); 
	fila.appendChild(celda);
	
	//Fila de Fichero
	fila=Tabla.tBodies[0].appendChild(document.createElement('TR'));
	fila.setAttribute("id","fic_" + nf);
		celda = document.createElement('TD');
		celda.appendChild(document.createTextNode('Fichero'));
	fila.appendChild(celda)
		celda = document.createElement('TD');
		var oInputFiles = document.createElement("input");
		oInputFiles.setAttribute("type","file");
		oInputFiles.setAttribute("name","txtFichero_" + nf);
		oInputFiles.setAttribute("id","txtFichero_" + nf);
		oInputFiles.setAttribute("size","40");
		if ((document.all) == null)
		{
			strFuncion="muestraNomFichero('txtNomFichero" + nf + "',this.value)";
			oInputFiles.setAttribute("onchange",strFuncion);
		}
		else
		{
			oInputFiles.attachEvent("onchange",cambiaNomFichero);	
		}
		oInputFiles.className = "frmIngreso";
		celda.appendChild(oInputFiles);
		celda.appendChild(document.createElement('BR'));
		var oInput = document.createElement("input");
			oInput.setAttribute("type","text");
			oInput.setAttribute("name","txtNomFichero" + nf);
			oInput.setAttribute("id","txtNomFichero" + nf);
			oInput.setAttribute("size","40");
			oInput.setAttribute("readonly","readonly");
			oInput.readOnly=true;
			oInput.className = "frmIngreso";
		celda.appendChild(oInput);
		celda.appendChild(document.createTextNode(''));
		var boton=document.createElement("input");
			boton.setAttribute("type","button");
			boton.setAttribute("name","cmd_" + nf);
			boton.className = "frmIngreso";
			boton.setAttribute("value","Eliminar..");
			if ((document.all) == null)
			{
				strFuncion="borraElementos(this)";
				boton.setAttribute("onclick",strFuncion);
			}
			else
			{
				boton.attachEvent("onclick",borraElementos);	
			}
		celda.appendChild(boton);
		//Crear los hidden (Tamaño , Titulo y Fichero anterior)
		var oInput = document.createElement("input");
			oInput.setAttribute("type","hidden");
			oInput.setAttribute("name","txtNomFichero_Tam" + nf);
			celda.appendChild(oInput);
		var oInput = document.createElement("input");
			oInput.setAttribute("type","hidden");
			oInput.setAttribute("name","txtNomFicheroAnt" + nf);	
			celda.appendChild(oInput);
		var oInput = document.createElement("input");
			oInput.setAttribute("type","hidden");
			oInput.setAttribute("name","txtTituloAnt" + nf);	
			celda.appendChild(oInput);	
	fila.appendChild(celda);
	
	//Fila de separación
	fila=Tabla.tBodies[0].appendChild(document.createElement('TR'));
	fila.setAttribute("id","sepb_" + nf);
		celda = document.createElement('TD');
		celda.setAttribute("height","5"); 
	fila.appendChild(celda);
	
}

function creaFile()
{
	var oDiv=document.createElement("div");
	oDiv.setAttribute("id","divFichero2");
	document.getElementById("insFichero").appendChild(oDiv);
	
	var oInputFiles = document.createElement("input");
	oInputFiles.setAttribute("type","file");
	oInputFiles.setAttribute("name","txtFichero2");
	oInputFiles.setAttribute("id","txtFichero2");
	oInputFiles.setAttribute("size","40");
	if ((document.all) == null)
	{
		oInputFiles.setAttribute("onchange","muestraNomFichero('txtNomFichero',this.value)");
	}
	else
	{
		oInputFiles.attachEvent("onchange",nada);	
	}
	oInputFiles.className = "frmIngreso";
	//document.getElementById("insFichero").appendChild(oInputFiles);
	oDiv.appendChild(oInputFiles);
	var oCmd=document.createElement("input");
	oCmd.setAttribute("type","button");
	oCmd.setAttribute("name","cmd_2");
	if ((document.all) == null)
	{
		oCmd.setAttribute("onclick","borraFile()");
	}
	else
	{
		oCmd.attachEvent("onclick",borraFile);	
	}
	//document.getElementById("insFichero").appendChild(oCmd);
	oDiv.appendChild(oCmd);
}

function numFiles()
{
	//calcular cuantos file existen
	objInput=document.getElementsByTagName("input");
	l=objInput.length-1;
	n=0;
	for(i=0;i<=l;i++)
	{
		if(objInput[i].type == "file" )
			n=n+1;
	}
	return n;
}

function nada(e)
{
	
	alert(e.srcElement.value);
}

function nombreFichero(nomFichero)
{
	var pos=0;
	n=nomFichero.length-1;
	for(i=n;i>=0;i--)
	{
		if ( nomFichero.charAt(i)== "\\")
		{
			pos=i;
			break;
		}
	}
	return nomFichero.substring(pos+1);
}

function getExtFichero(nomFichero)
{
	var pos=0;
	n=nomFichero.length-1;
	for(i=n;i>=0;i--)
	{
		if ( nomFichero.charAt(i)== ".")
		{
			pos=i;
			break;
		}
	}
	return nomFichero.substring(pos+1);
}


function muestraNomFichero(strObj,nomFichero)
{
	obj=document.getElementById(strObj);
	obj.value=nombreFichero(nomFichero);
}

function borraNomFichero(strObj)
{
	obj=document.getElementById(strObj);
	obj.value="";
}

function cambiaColor(obj,color)
{
	obj.bgColor=color
}

function cambiaColorLetra(obj,color)
{
	obj.style.color=color;
}
/*Sección de validación de formularios*/

function valida_form(strClase,strForm)
{
	strObj=strClase.substr(0,strClase.indexOf("."));
	if (eval("valida_" + strObj+"()"))
		if (strForm == null)
			document.forms[0].submit()
		else
			document.forms[1].submit()
}

function valida_noticias()
{
	lstCampos="txtFecha:Fecha:1|" +
							"txtTitulo:Alfa:1|" +
							"txtTexto:Alfa:1|" +
							"txtNomFichero:Imagen:0|";
		if (!validaCampo(lstCampos)){
			return true;
		}
	return false
}

function valida_galeria()
{
	lstCampos="txtFecha:Fecha:1|" +
							"txtTitulo:Alfa:1|" +
							"txtAutor:Alfa:1|" +
							"txtBiografia:Alfa:1|" +
							"txtNomFichero:Imagen:0|";
		if (!validaCampo(lstCampos)){
			return true;
		}
	return false
}

function valida_taller()
{
	lstCampos="txtFecha:Fecha:1|" +
							"txtTitulo:Alfa:1|" +
							"txtPresentacion:Alfa:1|" +
							"txtResumen:Alfa:0|";
		if (!validaCampo(lstCampos)){
			return true;
		}
	return false
}

function valida_sugerencias()
{
	lstCampos="txtNombre:Alfa:1|" +
							"txtApellido:Alfa:1|" +
							"txtEmail:Alfa:1|" +
							"txtSugerencia:Alfa:1|";
		if (!validaCampo(lstCampos)){
			return true;
		}
	return false
}

function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}

QueryString_Parse();



//Scroller


/***********************************************
* Pausing updown message scroller- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//configure the below five variables to change the style of the scroller
var scrollerdelay='5000' //delay between msg scrolls. 3000=3 seconds.
var scrollerwidth='500px'
var scrollerheight='75px'
var scrollerbgcolor=''
//set below to '' if you don't wish to use a background image
var scrollerbackground=''

//configure the below variable to change the contents of the scroller
var messages=new Array()
messages[0]=" ";

///////Do not edit pass this line///////////////////////

var ie=document.all
var dom=document.getElementById

if (messages.length>2)
i=2
else
i=0

function move1(whichlayer){
tlayer=eval(whichlayer)
if (tlayer.top>0&&tlayer.top<=5){
tlayer.top=0
setTimeout("move1(tlayer)",scrollerdelay)
setTimeout("move2(document.main.document.second)",scrollerdelay)
return
}
if (tlayer.top>=tlayer.document.height*-1){
tlayer.top-=5
setTimeout("move1(tlayer)",50)
}
else{
tlayer.top=parseInt(scrollerheight)
tlayer.document.write(messages[i])
tlayer.document.close()
if (i==messages.length-1)
i=0
else
i++
}
}

function move2(whichlayer){
tlayer2=eval(whichlayer)
if (tlayer2.top>0&&tlayer2.top<=5){
tlayer2.top=0
setTimeout("move2(tlayer2)",scrollerdelay)
setTimeout("move1(document.main.document.first)",scrollerdelay)
return
}
if (tlayer2.top>=tlayer2.document.height*-1){
tlayer2.top-=5
setTimeout("move2(tlayer2)",50)
}
else{
tlayer2.top=parseInt(scrollerheight)
tlayer2.document.write(messages[i])
tlayer2.document.close()
if (i==messages.length-1)
i=0
else
i++
}
}

function move3(whichdiv){
tdiv=eval(whichdiv)
if (parseInt(tdiv.style.top)>0&&parseInt(tdiv.style.top)<=5){
tdiv.style.top=0+"px"
setTimeout("move3(tdiv)",scrollerdelay)
setTimeout("move4(second2_obj)",scrollerdelay)
return
}
if (parseInt(tdiv.style.top)>=tdiv.offsetHeight*-1){
tdiv.style.top=parseInt(tdiv.style.top)-5+"px"
setTimeout("move3(tdiv)",50)
}
else{
tdiv.style.top=parseInt(scrollerheight)
tdiv.innerHTML=messages[i]
if (i==messages.length-1)
i=0
else
i++
}
}

function move4(whichdiv){
tdiv2=eval(whichdiv)
if (parseInt(tdiv2.style.top)>0&&parseInt(tdiv2.style.top)<=5){
tdiv2.style.top=0+"px"
setTimeout("move4(tdiv2)",scrollerdelay)
setTimeout("move3(first2_obj)",scrollerdelay)
return
}
if (parseInt(tdiv2.style.top)>=tdiv2.offsetHeight*-1){
tdiv2.style.top=parseInt(tdiv2.style.top)-5+"px"
setTimeout("move4(second2_obj)",50)
}
else{
tdiv2.style.top=parseInt(scrollerheight)
tdiv2.innerHTML=messages[i]
if (i==messages.length-1)
i=0
else
i++
}
}

function startscroll(){
if (ie||dom){
first2_obj=ie? first2 : document.getElementById("first2")
second2_obj=ie? second2 : document.getElementById("second2")
move3(first2_obj)
second2_obj.style.top=scrollerheight
second2_obj.style.visibility='visible'
}
else if (document.layers){
document.main.visibility='show'
move1(document.main.document.first)
document.main.document.second.top=parseInt(scrollerheight)+5
document.main.document.second.visibility='show'
}
}

function popup(anUrl, aW, aH, aName) {
	window.open(anUrl, aName, 'height=' + aH + ', width=' + aW + ', location=no, menubar=no, resizable=no, scrollbars=yes, status=yes, toolbar=no');
}

function popupsin(anUrl, aW, aH, aName) {
	window.open(anUrl, aName, 'height=' + aH + ', width=' + aW + ', location=no, menubar=no, resizable=no, scrollbars=YES, status=yes, toolbar=no');
}