// JavaScript Document
<!--
//variable que valdrá true si se está usando Firefox, para volver a renderizar la página
var firefox = navigator.userAgent.indexOf('Firefox')>-1;

//Comunes
//trim
function trim(inputString) {
  if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { 
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { 
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1){
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
   }
   return retValue; 
}

//validaciones
//validar email
function dircorrecta(direc){
	    var  pos= direc.indexOf("@");

		if (pos<=0) {return false;}	
		else { var pos2=direc.indexOf("@",pos+1);			
			if ((pos2!=-1) | (direc.indexOf(".",pos+1)==-1))
			     { return false}
			else {	return true}
		};
}



function CambiarPagina(url){
//Cambia de pagina a url
	if (url) window.location=url;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//validaciones
//validar fecha con formato dd/mm/aaaa
function validar_fecha(fecha){
	tfecha=fecha.split("/");
	return (tfecha.length==3 &&  tfecha[0]!='' && tfecha[1]!=''  && tfecha[2]!='' && !isNaN(tfecha[0]) && !isNaN(tfecha[1]) && !isNaN(tfecha[2]) && tfecha[0].length==2 && tfecha[1].length==2 && tfecha[2].length==4     ) ? true :false;
}

//validar url
function isURL(argvalue) {

  argvalue = argvalue.substring(7, argvalue.length);
  if (argvalue.indexOf(".") == -1)
    return false;
  else if (argvalue.indexOf(".") == 0)
    return false;
  else if (argvalue.charAt(argvalue.length - 1) == ".")
    return false;

  if (argvalue.indexOf("/") != -1) {
    argvalue = argvalue.substring(0, argvalue.indexOf("/"));
    if (argvalue.charAt(argvalue.length - 1) == ".")
      return false;
  }

  if (argvalue.indexOf(":") != -1) {
    if (argvalue.indexOf(":") == (argvalue.length - 1))
      return false;
    else if (argvalue.charAt(argvalue.indexOf(":") + 1) == ".")
      return false;
    argvalue = argvalue.substring(0, argvalue.indexOf(":"));
    if (argvalue.charAt(argvalue.length - 1) == ".")
      return false;
  }

  return true;
}

//abrir ventana centrada, con foto
//mostrar foto ampliada, partiendo de una url,nombre de la ventana a abrir y pie, si lo tiene
function ShowPhotoDinamica (url,name,foot) {
  var width = 150;
  var height = 150;
  var x=(640 - width)/2
  var y=(480-height)/2

  if(screen) {
	  y=(screen.availHeight - height)/2
	  x=(screen.availWidth - width)/2
  }

  if(screen.availWidht > 1800)
	  x=((screen.availWidth/2) - width)/2

  window.width=width
  window.height=height
  window.x=x
  window.y=y

  estilo="toolbar=0, status=0, location=0, directories=0, menubar=0, scrollbars=0, resize=0,resizable=0";
  url = foot ? url+'&foot='+escape(foot) : url ;
  name = name ? name : 'newwin';

  vn = window.open(url, name, estilo + ",width=" + width + "px,height=" + height + "px,top=" + y + "px,left=" + x + "px");
  vn.focus();
}

//abrir ventana centrada, con foto
function ShowPhotoEstatica(url,lang,width,height,foot) {
	
  if (foot)  height+=30;	
	
  var width = (width) ? width : 150;
  var height = (height) ? height: 150;
  
  var x=(640 - width)/2
  var y=(480-height)/2

  if(screen) {
	  y=(screen.availHeight - height)/2
	  x=(screen.availWidth - width)/2
  }

  if(screen.availWidht > 1800)
	  x=((screen.availWidth/2) - width)/2

  window.width=width
  window.height=height
  window.x=x
  window.y=y

  estilo="toolbar=0, status=0, location=0, directories=0, menubar=0, scrollbars=0, resize=0,resizable=0";
  params ='url='+url+'&lang='+lang ;
  params +=  (foot) ? '&foot='+foot : ''; 

  vn = window.open('modules/photo.php?'+params, 'newwinphoto', estilo + ",width=" + width + "px,height=" + height + "px,top=" + y + "px,left=" + x + "px");
  vn.focus();
}

function ValidateCharsAndNum(text) { 
//valida que text sólo tenga letras y numeros, minimo 8 caracteres
 //recorrer texto y validar
 
 result=true;
 
	if(text.length<8) 
		result=false;
	else{
		for(i=0;i<text.length;i++){
			c=text.charAt(i);
			if( !isCharValid(c)){
				result= false;
				break;
			}		
		}			
	}
	
 return result;
} 

function isCharValid(c)
{//valida c sólo sea letra o numero
	var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	if (c) return( ( chars.indexOf( c ) != -1 ) )
	else return false;
   
}

//abrir ventana centrada
function WindowCenter (url,ancho, alto, stl, name) {
  var width = ancho
  var height = alto
  var x=(640 - width)/2
  var y=(480-height)/2
  var ndate = new Date();

  if(screen) {
	  y=(screen.availHeight - height)/2
	  x=(screen.availWidth - width)/2
  }

  if(screen.availWidht > 1800)
	  x=((screen.availWidth/2) - width)/2

  window.width=width
  window.height=height
  window.x=x
  window.y=y

  estilo = stl ? stl : "toolbar=0, status=0, location=0, directories=0, menubar=0, scrollbars=0, resize=0,resizable=0";
  name = name ? name : 'newwin';

  vn = window.open(url, name, estilo + ",width=" + width + "px,height=" + height + "px,top=" + y + "px,left=" + x + "px");
  vn.focus();
}

//abrir ventana centrada, con foto
function showphoto(url,lang,foot,width,height) {
	
  if (foot)  height+=30;	
	
  var width = (width) ? width : 150;
  var height = (height) ? height: 150;
  
  var x=(640 - width)/2
  var y=(480-height)/2

  if(screen) {
	  y=(screen.availHeight - height)/2
	  x=(screen.availWidth - width)/2
  }

  if(screen.availWidht > 1800)
	  x=((screen.availWidth/2) - width)/2

  window.width=width
  window.height=height
  window.x=x
  window.y=y

  estilo="toolbar=0, status=0, location=0, directories=0, menubar=0, scrollbars=0, resize=0,resizable=0";
  params ='url='+url+'&lang='+lang ;
  params +=  (foot) ? '&foot='+foot : ''; 

  vn = window.open('modules/photo.php?'+params, 'newwinphoto', estilo + ",width=" + width + "px,height=" + height + "px,top=" + y + "px,left=" + x + "px");
  vn.focus();
}


//para paginar
function cambiar_pag(p_salto){
    frm=document.forms['formpaginar'];

    frm.p_act.value=p_salto;
	frm.submit();
}

//para recargar si es necesario
function reload_content()
{
	// Forzamos el renderizado de la página
	document.body.innerHTML=document.body.innerHTML;
}


// Es necesario forzar el renderizado de la página en firefox, debido a problemas en la disposición de las capas.
if (firefox)
	window.onload = reload_content;
//-->