

var isDOM = document.getElementById ? true : false;
var cont = 1;

/*********************Codigo del Scroll **************************/
//slider's width
var swidth=290
//slider's height
var sheight=36
//slider's speed
var sspeed=2

function start(){
	if (document.all){
		ieslider1.style.top = 18
		iemarquee(ieslider1)
	} else if (document.layers){
		document.ns4slider.document.ns4slider1.top=sheight
		document.ns4slider.document.ns4slider1.visibility='show'
		ns4marquee(document.ns4slider.document.ns4slider1)
	} else if (document.getElementById&&!document.all){
		document.getElementById('ns6slider1').style.top=sheight
		ns6marquee(document.getElementById('ns6slider1'))
	}
}

function iemarquee(whichdiv){
	iediv=eval(whichdiv);
	if (iediv.style.pixelTop > 0 && iediv.style.pixelTop <= sspeed){
		iediv.style.pixelTop = 0
		setTimeout("iemarquee(iediv)",100)
	}
	if (iediv.style.pixelTop >= -60){
		iediv.style.pixelTop -= sspeed
		setTimeout("iemarquee(iediv)",100)
/*		window.status = iediv.style.pixelTop; */
	} else {
		iediv.style.pixelTop = sheight
		iediv.innerHTML=singletext[i]
		if (i == singletext.length - 1) i=0
		else i++
	}
}

function ns4marquee(whichlayer){
	ns4layer=eval(whichlayer)
	if (ns4layer.top>0&&ns4layer.top<=sspeed){
		ns4layer.top=0
		setTimeout("ns4marquee(ns4layer)",100)
	}
	if (ns4layer.top>=sheight*-1){
		ns4layer.top-=sspeed
		setTimeout("ns4marquee(ns4layer)",100)
	} else {
		ns4layer.top=sheight
		ns4layer.document.write(singletext[i])
		ns4layer.document.close()
		if (i==singletext.length-1)	i=0
		else i++
	}
}

function ns6marquee(whichdiv){
	ns6div=eval(whichdiv)
	if (parseInt(ns6div.style.top)>0&&parseInt(ns6div.style.top)<=sspeed){
		ns6div.style.top=0
		setTimeout("ns6marquee(ns6div)",100)
	}
	if (parseInt(ns6div.style.top)>=sheight*-1){
		ns6div.style.top=parseInt(ns6div.style.top)-sspeed
		setTimeout("ns6marquee(ns6div)",100)
	} else {
		ns6div.style.top=sheight
		ns6div.innerHTML=singletext[i]
		if (i==singletext.length-1)	i=0
		else i++ 
	}
}
/********************************************************************/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function paginadeinicio(src, url) {
    src.style.behavior='url(#default#homepage)';
    src.setHomePage(url);
}

function mOvr(src,Color) {
    src.style.cursor = "hand";
    src.bgColor = Color;
}

function mOut(src,Color) {
    src.style.cursor = "default";
    src.bgColor = Color;
}

function mClk(src) {
    window.location = src;
    return false;
}

function mostrarFoto(Archivo) {
    var posi = Archivo.name.charAt(Archivo.name.length - 1);
    var foto = eval("document.F" + posi);
    var nombre = (Archivo.value != "") ?  Archivo.value : "../imagenes/nodisponible.gif";
    foto.src = nombre
    return false;
}

function Modificar(Nf) {
   Modifica = eval("document.FNoticias.Modificar" + Nf);
   Borra = eval("document.FNoticias.Borrar" + Nf);
   Borra.checked = false;
   
   Fotografia = eval("document.FNoticias.Fotografia" + Nf);
   Epigrafe = eval("document.FNoticias.Epigrafe" + Nf);
   Alineacion = eval("document.FNoticias.Alineacion" + Nf);

   Fotografia.enabled = Modifica.checked;
   Epigrafe.enabled = Modifica.checked;
   Alineacion.enabled = Modifica.checked;
   if(Nf == 1) 
   	  document.FNoticias.Entapa.enabled = Modifica.checked;

   if(Modifica.checked)
   	  Mostrar(document.getElementById("Foto" + Nf));
   else
      Ocultar(document.getElementById("Foto" + Nf));	  
  
   return true;	
}

function Borrar(Nf) {
   Modifica = eval("document.FNoticias.Modificar" + Nf);
   Modifica.checked = false;
   Ocultar(document.getElementById("Foto" + Nf));
   return true;
}

function Ocultar(Foto) {
   Foto.style.display = 'none';
   return false;
}

function Mostrar(Foto) {
   if(Foto)
     Foto.style.display = '';
   return false;
}

function VerFoto(Nf) {
    VFoto = eval("document.FNoticias.CF" + Nf);
    if(VFoto.checked)
   	    Mostrar(document.getElementById("VF" + Nf));
    else
        Ocultar(document.getElementById("VF" + Nf));
	return true;
}

function cambiar(Nf) {
   	if(document.FNoticias.Sector.value == 0)
       Mostrar(document.getElementById(Nf));
    else
       Ocultar(document.getElementById(Nf));
	return true;
}

function verificarAr(F) {
   var bien = false;
   for(i = 0; (i < F.elements.length) && !bien; i++) {
       if(F.elements[i]) {
          bien = F.elements[i].checked;
       }
   }
   if(!bien)
      alert('Para enviar al Archivo una Noticia ...' + '\r\n' +
            '¡Primero debe Seleccionar alguna!');
   return bien;
}

function BarraEstado(Mensaje) {
	window.status = Mensaje;
	return true;
}

function Inicio(src, url){
	src.style.behavior='url(#default#homepage)';
	src.setHomePage(url);
	return false;
}

function arelacion(F) {
	var existe = false;
	if(F.Noticias.length > 0) {
		var noti = 	F.Noticias.options[F.Noticias.selectedIndex].value;
		var titulo = F.Noticias.options[F.Noticias.selectedIndex].text;
		for(var i = 0; (i < F.Relacion.length) && (!existe); i++)
			existe = (F.Relacion.options[i].value == noti);
		if(!existe) {
			F.Relacion.options[F.Relacion.length] = new Option(titulo,noti,false,true);
			F.Noticias.options[F.Noticias.selectedIndex] = null;
		}
	}
	return !existe;
}

function qrelacion(F) {
	var existe = false;
	var elegidos = F.Relacion.length - 1;
	for(var i = elegidos; i >= 0; i--) {
		if(F.Relacion.options[i].selected) {
			var noti = 	F.Relacion.options[i].value;
			var titulo = F.Relacion.options[i].text;			
			F.Noticias.options[F.Noticias.length] = new Option(titulo,noti);
			F.Relacion.options[i] = null;
			existe = true;
		}
	}
	return existe;
}

function verificar(F) {
	var tit = F.Titulo.value.length > 0;
	var elegidos = 0;
	if(F.Relacion != null) 
	   elegidos = F.Relacion.length;
	if(!tit) {
		alert("¡Se requiere el Titulo de la Noticia!");	
	} else {
		var coma = "";
		for(var i = 0; i < elegidos; i++) {
			F.NRelacion.value += coma + F.Relacion.options[i].value;
			coma = ",";
			F.Relacion.selectedIndex = -1;
			F.Noticias.selectedIndex = -1;
		}
	}
	return tit;
}

function abrirLink(src) {
	window.open(src,"NuevaVentana","scrollbars=1,status=1,width=650,height=400");
	return false;
}

function agregarOpcion(F) {
	var existe = false;
	if(F.Opcion.value.length > 0) {
		var Tema = 	F.Opcion.value;
		for(var i = 0; (i < F.Opciones.length) && (!existe); i++)
			existe = (F.Opciones.options[i].value == Tema);
		if(!existe) {
			F.Opciones.options[F.Opciones.length] = new Option(Tema,Tema,true,true);
		}
	}
	return !existe;
}

function quitarOpcion(F) {
	var existe = false;
	var elegidos = F.Opciones.length - 1;
	for(var i = elegidos; i >= 0; i--) {
		if(F.Opciones.options[i].selected) {
			F.Opciones.options[i] = null;
			existe = true;
		}
	}
	return existe;
}


function getCookieVal(offset) {
   var endstr = document.cookie.indexOf(";",offset);
   if(endstr == -1) 
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset,endstr));
}

function setCookie(nombre,valor) {
   var argv = setCookie.arguments;
   var argc = setCookie.arguments.length;
   var expira = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : null;
   var domain = (argc > 4) ? argv[4] : null;
   var seguro = (argc > 5) ? argv[5] : null;
   document.cookie = nombre + "=" + escape(valor) + 
		 ((expira == null) ? "" : ("; expires=" + expira.toGMTString())) + 
		 ((path == null) ? "" : ("; path=" + path)) + 
		 ((domain == null) ? "" : ("; domain=" + domain)) +
		 ((seguro == null) ? "" : ("; secure=" + seguro));
}

function getCookie(nombre) {
   var arg = nombre + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   for(var i = 0; i < clen; i++) {
       var j = i + alen;
       if(document.cookie.substring(i,j) == arg) 
	  return getCookieVal(j);
       i = document.cookie.indexOf(" ",i) + 1;
       if(i == 0) break;
   }
   return null;
}

function votaciones(Id,theURL,features) {
  winName = "Encuesta";
  Expira = new Date();
  Expira.setTime(Expira.getTime() + (86400*3650));
  if(getCookie("Voto") == Id) theURL += "&voto=" + Id;
  else setCookie("Voto",Id,Expira); 
  window.open(theURL,winName,features);
  return false;
}

function Reloj() {
	if (!document.layers && !document.all)
		return;
	var runTime = new Date();
	var hours = runTime.getHours();
	var minutes = runTime.getMinutes();
	var seconds = runTime.getSeconds();
	if (minutes <= 9) {
		minutes = "0" + minutes;
	}
	if (seconds <= 9) {
		seconds = "0" + seconds;
	}
	movingtime = hours + ":" + minutes + ":" + seconds;
	if (document.layers) {
		document.layers.clock.document.write(movingtime);
		document.layers.clock.document.close();
	} else if (document.all) {
		clock.innerHTML = movingtime;
	}
	setTimeout("Reloj()", 1000);
}

function verfotos(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  

	if (bgcolor=="") {
		bgcolor="#FFFFFF";
	}
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	if(w<740){
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}
	if (imageWidth>w){	
	  byFactor = w / imageWidth;			
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	if (imageHeight>h-adj){
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (imageHeight>scrHeight){
  	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}

	var posLeft=0;
	var posTop=0;

	if (hugger == "hug image"){
	  if (hugMargin == ""){
	    hugMargin = 0;
	  }
	  var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
	  if (scrHeightTemp < scrHeight) {
		scrHeight = scrHeightTemp;
	  } 
	  var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
	  if (scrWidthTemp < scrWidth) {
		scrWidth = scrWidthTemp;
	  }
	  
	  if (scrHeight<100){scrHeight=100;}
	  if (scrWidth<100){scrWidth=100;}

	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
 	}

	if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
		imageHeight=imageHeight-adj;
		imageWidth=imageWidth-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} else {
	newWindow = window.open("/html/fotos.html","Fotografias","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+'>');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Click en la Ventana para Cerrar" onclick="window.close();">'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

function wordCounter(field, maxlimit) {
   var wordcounter = 0;
   var posi = 0;
   for (x = 0; x < field.value.length; x++) {
      if (field.value.charAt(x) == " ")  {
          wordcounter++;
      }
      if((wordcounter > 0) && (wordcounter <= maxlimit)) {
          posi = x + 1;
      }
   }
   if((wordcounter == 0) && (field.value.length > 0)) {
       wordcounter++;
       posi = field.value.length;
   }
   if(wordcounter > 0) {
      field.value = field.value.substring(0, posi);
   }
   return wordcounter;
}

function controlaraviso(formulario) {
    var correcto = (formulario.Texto.value != "") && (formulario.Titulo.value != "");
    if(wordCounter(formulario.Texto,50) > 50) {
       alert("¡Hay mas de 50 palabras en el Texto ingresado!");
       correcto = false;
    } else if(!correcto) {
        alert("¡Esta faltando completar alguno de los datos obligatorios!");
    }
    return correcto;
}

function controlarComentarios(formulario) { 
	var correcto = (formulario.Comentario.value != "");
    if(!correcto) {
        alert("¡Esta faltando completar algunos de los datos obligatorios!");
    } else {
		correcto = (wordCounter(formulario.Comentario,50) <= 100);
	}
    return correcto;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser una direccion de email.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe ser un numero.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' debe contener un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
  } if (errors) alert('Han ocurrido los siguientes errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function Encuesta(Id) {
	window.open("votar.php?voto=" + Id,"Encuestas","scrollbars=1,status=1,width=500,height=440");
	return false;
}

function Resultados(Id) {
    winName = "Resultados";
    features = "scrollbars=1,status=1,width=550,height=450";
    window.open("resultados.php?voto=" + Id,winName,features);
    return false;
}

function controlarRespuesta(form) {
	Opcion = form.Codigo;
	id = -1;
	if (Opcion.length > 0) //tengo mas de una respuesta
	{
		for (var i=0; i < Opcion.length; i++){
			if (Opcion[i].checked)
				id = Opcion[i].value;
		}
	}
	if(id == -1) {
		window.alert("Seleccione una respuesta");
		return false;
	}
	return true;
}

function actualizar(doc) {
	doc.parent.document.close();
	doc.parent.document.open();
}

function validarclaves(form) {
    var allValid = false;	
    if(form.Clave.value.length > 0) {
    	if(form.Confclave.value.length > 0) {
   	   var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	   var checkStr = form.Clave.value;
	   for(i = 0;  i < checkStr.length;  i++) {
	       ch = checkStr.charAt(i);
	       for(j = 0;  j < checkOK.length;  j++)
	           if (ch == checkOK.charAt(j)) break;
    	   }
    	   if(!(allValid = (i == checkStr.length))) 
    	      alert('Hay caracteres invalidos en la clave!');
 	   else if(!(allValid = (form.Clave.value == form.Confclave.value)))
      		   alert('La clave y su confirmacion no coinciden.');
    	} else {
	  alert('Se requiere la Confirmacion de la Clave!');    	   
	}
   } else {
   	alert('Se requiere la Clave!');
   }
   return allValid;
}


function validartelefono(Tele) {
  allValid = (Tele.value != "");
  if (!allValid) {
     alert("Faltan completar algunos datos necesarios");
  }
  return allValid;
}

function validarelresto(Provincia,Localidad) {
  allValid = ((Provincia.value > 0) && (Localidad.value != ""));
  if(!allValid) {
     alert("Faltan completar algunos datos necesarios");
  }
  return allValid;
}

function validarnombrecuenta(CUENTA) {
  var allValid = true;
  if ((CUENTA.value == "") || (CUENTA.value.length < 4) || (CUENTA.value.length > 15))
  {
    alert("El Nombre de Cuenta debe tener mas de 4 y menos de 15 letras o digitos.");
    CUENTA.focus();
	allValid = false;
  } else {
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	  var checkStr = CUENTA.value;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("El Nombre de Cuenta debe tener mas de 4 letras o digitos validos.");
	    CUENTA.focus();
	  }
  }
  return allValid;
}

function validarnombreyapellido(NOMBRE,APELLIDO) {
    var allValid = (NOMBRE.value.length > 0) && (APELLIDO.value.length > 0);
    if (!allValid) {
        alert("Se requiere el Nombre y el Apellido!.");
        APELLIDO.focus();
    }
    return allValid;
}

function validardni(DNI) {
  var allValid = true;
  if((parseInt(DNI.value) < 100000) || (DNI.value.length < 5)) {
    	alert("El DNI no se ha ingresado correctamente!.");
	allValid = false;
  }
  return allValid;
}

function validaremail(Email) {
    var errores = '';
    if((Email=Email.value)!="") {
     p=Email.indexOf('@');
     if(p < 1 || p == (Email.length-1)) 
        errores += 'Se debe indicar una direccion de E-mail Alternativa valida!.\n';
    } else errores += 'El E-mail Alternativo es requerido.\n'; 
    if(errores) alert(errores);
    return (errores == '');
}

function validaremail2(Email) {
  var errores = '';
  if((Email=Email.value)!="") {
     p=Email.indexOf('@');
     if(p < 1 || p == (Email.length-1)) 
        errores += 'Se debe indicar una direccion de E-mail válida!.\n';
  }; 
  if(errores) alert(errores);
  return (errores == '');
}

function validaraltacorreo(form) {
   return validarnombreyapellido(form.Nombre,form.Apellido) && 
           validardni(form.Dni) && 
           validarnombrecuenta(form.Cuenta) && 
           validaremail(form.Email) &&
           validartelefono(form.Telefono) &&
           validarelresto(form.Provincia.options[form.Provincia.options.selectedIndex],form.Localidad);          
}

function validaradhesion(form) {
   return  validarnombreyapellido(form.Nombre,form.Apellido) && 
           validardni(form.DNI) && 
           validaremail(form.Email) &&
           validarelresto(form.Provincia.options[form.Provincia.options.selectedIndex],form.Localidad);
}

function validarfiscales(form) {
   return  validarnombreyapellido(form.Nombre,form.Apellido) && 
           validardni(form.DNI) && 
           validartelefono(form.FechaNac) &&
           validartelefono(form.Domicilio) &&
           validarelresto(form.Provincia.options[form.Provincia.options.selectedIndex],form.Localidad) &&
           validartelefono(form.Telefono) &&
           validaremail2(form.Email);
}

