// JavaScript Document
<!--

//variables
var ie = navigator.appName.indexOf('Explorer')>-1;

//para el logo
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//para el logo


//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}
		};
}


//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, parertiendo 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();
}


//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();
}

function imprimir_ficha(){
	borrarelementos();
	print();
	window.location=window.location;
}

function borrarelementos(){			
	var elemborrar;		
	if (window.navigator.appName.indexOf("Microsoft")!=-1) {elemborrar=document.all.ocultar;}
	else if (window.navigator.appName.indexOf("Netscape")!=-1){elemborrar= document.getElementById('ocultar');}	
	if (elemborrar!=''&&elemborrar.length==null)	elemborrar.style.display='none'
	else	for (i=0;i<elemborrar.length;i++)		elemborrar[i].style.display='none'
}


//mostrar/ocultar submenu informacion
function ChangeSubMenu(content){
	csubmenu=window.document.getElementById(content);	
	csubmenu.style.display=(csubmenu.style.display=="none")?"table-header-group":"none";	
	csubmenu.style.visibility=(csubmenu.style.visibility=="hidden")?"visible":"hidden";
	
	if(!ie) document.body.innerHTML = document.body.innerHTML;//refresco el body si no es explorer
}

//acciones segun pulse en mapa
function GetContentMap(type,province) {
	//type=1 es colegios
	//type=2 es centros clinicos
	//province es el nombre de la provincia seleccionada
	
	var myConn = new XHConn();
	if (!myConn) alert("Navegador sin soporte AJAX. Por favor utilice un navegador más actual.");

	var fnWhenDone = function (oXML) {
		var dv = document.getElementById('contentmap');		
		dv.innerHTML = oXML.responseText;	
		
		if(!ie) document.body.innerHTML = document.body.innerHTML;//refresco el body si no es explorer
	};
	
	file=(type==2)? 'getclinics.php':'getvassociations.php';

	myConn.connect("../modules/"+file, "POST", "province="+escape(province), fnWhenDone);
}

function ValidateCharsAndNum(text) { 
//valida que text sólo tenga letras y numeros, minimo 6 caracteres
 //recorrer texto y validar
 
 result=true;
 
	if(text.length<6) 
		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;
   
}
-->
