var isDOM = document.getElementById ? true : false;
var cont = 1;

function preloadImages() {
    var d=document;
    if(d.images){ 
        if (!d.MM_p) 
            d.MM_p = new Array();
        var i, j = d.MM_p.length, a = 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 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) {
   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 = "";
		if(F.NRelacion.value.length == 0) {
			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=620,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 Resultados(Id) {
    winName = "Resultados";
    features = "scrollbars=1,status=1,width=550,height=340";
    window.open("resultados.php?voto=" + Id,winName,features);
    return false;
}

function Encuesta(Id) {
	window.open("votar.php?voto=" + Id,"Encuestas","scrollbars=1,status=1,width=550,height=340");
	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.htm","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+' onBlur="self.close()" onClick="self.close()">');  
	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">'); 
	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,200) <= 200);
	}
    return correcto;
}

function verFotoGaleria(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin,publi) {
// 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.htm","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+' onBlur="self.close()" onClick="self.close()">');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="/muestrafoto.php?fo='+ imageName + '\&di=' + publi +'" width='+imageWidth+' height='+imageHeight+' alt="Click en la Ventana para Cerrar">');
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}


