function trim(cadena)
	{return cadena.replace(/(^\s*)|(\s*$)/g,"")
	}
function comprovaremail(email)
	{var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	 if (filter.test(email))
		 {testresults=true
		  return true;
		 }
	 else
		 {testresults=false;
		  return false;
		 }
	}
function fechatexto(fecha1)
	{var dia1;
	 var mes1;
	 var anyo1; 
	 dia1=fecha1.substring(0,2);
	 mes1=fecha1.substring(3,5);
	 anyo1=fecha1.substring(6,10);
	 fecha1=anyo1+mes1+dia1;
	 return(fecha1)
	}
	
/*function (fechabdfecha2)
	{var dia2;
	 var mes2;
	 var anyo2; 
	 dia2=fecha2.substring(0,2);
	 mes2=fecha2.substring(3,5);
	 anyo2=fecha2.substring(6,10);
	 fecha2=anyo2+'-'+mes2+'-'+dia2;
	 return(fecha2)
	}*/
		
function IsNumeric(valor) 
	{var log=valor.length; var sw="S"; 
	 for (x=0; x<log; x++) 
		{v1=valor.substr(x,1); 
		 v2 = parseInt(v1); 
		 //Compruebo si es un valor numérico 
		 if (isNaN(v2))
			{sw= "N";
			} 
		} 
	 if (sw=="S")
		{return true;
		}
	 else
		{return false;
		} 
	} 

var primerslap=false; 
var segundoslap=false; 
function formateafecha(fecha) 
	{var long = fecha.length; 
	 var dia;
	 var auxdia;
	 var mes; 
	 var ano; 
	 if ((long>=2) && (primerslap==false))
		{dia=fecha.substr(0,2); 
     if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00"))
			{fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7);
			 primerslap=true;
			} 
		 else
			{fecha="";
			 primerslap=false;
			} 
		} 
	 else 
		{dia=fecha.substr(0,1); 
		 if (IsNumeric(dia)==false) 
			{fecha="";
			} 
		 if ((long<=2) && (primerslap=true))
			{fecha=fecha.substr(0,1);
			 primerslap=false;
			} 
		}
	 if ((long>=5) && (segundoslap==false)) 
		{mes=fecha.substr(3,2);
		 if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00"))
			{if (mes=="04" || mes=="06" || mes=="09" || mes==11)
				{auxdia=fecha.substr(0,2)
				 if (auxdia=="31")
					{fecha=fecha.substr(0,3);
					 segundoslap=false;
					}
				 else
					{fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4);
					 segundoslap=true;
					}
				}
			 else
				{if (mes=="02")
					{auxdia=fecha.substr(0,2)
					 if (auxdia>"29")
						{fecha=fecha.substr(0,3);
						 segundoslap=false;
						}
					 else
						{fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4);
						 segundoslap=true;
						}
					}
				 else
					{fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4);
					 segundoslap=true;
					}
				}
			} 
		 else 
			{fecha=fecha.substr(0,3);
			 segundoslap=false;
			} 
		} 
	 else
		{if ((long<=5) && (segundoslap=true))
			{fecha=fecha.substr(0,4);
			 segundoslap=false; 
			}
		} 
	 if (long>=7) 
		{ano=fecha.substr(6,4); 
		 if (IsNumeric(ano)==false)
			{fecha=fecha.substr(0,6);
			} 
		 else
			{if (long==10)
				{if ((ano==0) || (ano<1900) || (ano>2100))
					{fecha=fecha.substr(0,6);
					}
				}
			} 
		} 
	 if (long>=10) 
		{fecha=fecha.substr(0,10); 
 		 dia=fecha.substr(0,2); 
		 mes=fecha.substr(3,2); 
		 ano=fecha.substr(6,4); 
		 // Año no viciesto y es febrero y el dia es mayor a 28 
		 if ((ano%4 != 0) && (mes ==02) && (dia > 28))
			{fecha=fecha.substr(0,2)+"/";
			}
		 
		} 
	 return (fecha); 
	} 
	
	
var primerdospustos=false; 
function formateahora(fecha) 
	{var long = fecha.length; 
	 var hora;
	 var auxdia;
	 var minutos; 
	 var ano; 
	 if ((long>=2) && (primerdospustos==false))
		{hora=fecha.substr(0,2); 
     if ((IsNumeric(hora)==true) && (hora<=23))
			{fecha=fecha.substr(0,2)+":"+fecha.substr(3,7);
			 primerdospustos=true;
			} 
		 else
			{fecha="";
			 primerdospustos=false;
			} 
		} 
	 else 
		{hora=fecha.substr(0,1); 
		 if (IsNumeric(hora)==false) 
			{fecha="";
			} 
		 if ((long<=2) && (primerdospustos=true))
			{fecha=fecha.substr(0,1);
			 primerdospustos=false;
			} 
		}
	 if ((long>=5)) 
		{minutos=fecha.substr(3,2);
		 if ((IsNumeric(minutos)==true) &&(minutos<=59))
			{fecha=fecha.substr(0,5)+":"+fecha.substr(6,4);
			} 
		 else 
			{fecha=fecha.substr(0,3);
			} 
		} 
	 else
		{if ((long<=5) && (segundodospustos=true))
			{fecha=fecha.substr(0,4);
			}
		} 
	 if (long>=5) 
		{fecha=fecha.substr(0,5); 
 		 hora=fecha.substr(0,2); 
		} 
	 return (fecha); 
	} 
	function gridover(nombrefila,colorfondoover,colorletrafondo){
		var nombrefila;
		var auxfila;
		auxfila=nombrefila;
		nombrefila="M"+nombrefila;
		document.getElementById(nombrefila).bgColor=colorfondoover;
		document.getElementById(nombrefila).style.fontFamily='Verdana, Arial, Helvetica, sans-serif';
		document.getElementById(nombrefila).style.fontSize='11px';
		document.getElementById(nombrefila).style.fontweight='bolder';
		document.getElementById(nombrefila).style.color=colorletrafondo;
		document.getElementById(nombrefila).style.cursor='hand';
		for (i=1;i<=3;i++){
			if (i==1){
				enlace="ENLACEA"+auxfila;
			}
			if (i==2){
				enlace="ENLACEB"+auxfila;
			}
			if (i==3){
				enlace="ENLACEC"+auxfila;
			}
			document.getElementById(enlace).style.textDecoration='none';
			document.getElementById(enlace).style.fontFamily='Verdana, Arial, Helvetica, sans-serif';
			document.getElementById(enlace).style.fontSize='11px';
			document.getElementById(enlace).style.fontweight='bolder';
			document.getElementById(enlace).style.color=colorletrafondo;
		}
	}
	function gridout(nombrefila,colorfondoout,colorletrafondo){
		var nombrefila;
		var auxfila;
		auxfila=nombrefila;
		nombrefila="M"+nombrefila;
		document.getElementById(nombrefila).bgColor=colorfondoout;
		document.getElementById(nombrefila).style.fontFamily='Verdana, Arial, Helvetica, sans-serif';
		document.getElementById(nombrefila).style.fontSize='11px';
		document.getElementById(nombrefila).style.fontweight='bolder';
		document.getElementById(nombrefila).style.color=colorletrafondo;
		document.getElementById(nombrefila).style.cursor='default';
		for (i=1;i<=3;i++){
			if (i==1){
				enlace="ENLACEA"+auxfila;
			}
			if (i==2){
				enlace="ENLACEB"+auxfila;
			}
			if (i==3){
				enlace="ENLACEC"+auxfila;
			}
			document.getElementById(enlace).style.textDecoration='none';
			document.getElementById(enlace).style.fontFamily='Verdana, Arial, Helvetica, sans-serif';
			document.getElementById(enlace).style.fontSize='11px';
			document.getElementById(enlace).style.fontweight='bolder';
			document.getElementById(enlace).style.color=colorletrafondo;
		}
		
		
		
	}
function botonmouseout(nombreboton,nombreclass) {
	/*if ("INPUT"==document.event.srcElement.tagName)
	document.event.srcElement.className=s*/
	document.getElementById(nombreboton).className=nombreclass;
}
function botonmouseover(nombreboton,nombreclass) {
	/*if ("INPUT"==document.event.srcElement.tagName)
	document.event.srcElement.className=s*/
	document.getElementById(nombreboton).className=nombreclass;
}
function gridmenusobre(nombrefila,nombreclass,nombrecambiar){
		//SOBRE LA FILA
		document.getElementById(nombrefila).className=nombreclass;
}
function gridmenufuera(nombrefila,nombreclass){
		//FUERA DE LA FILA
		document.getElementById(nombrefila).className=nombreclass;
}
function caracteresmaximostextarea(nombretextarea,numerocaracteres){
	//var max = 10;
	var txt;
	txt=document.getElementById(nombretextarea);
	var n = txt.value.length;
	if (n>numerocaracteres){  //i is the maxlength of textarea which we have set to 80
		txt.value = txt.value.substring(0,numerocaracteres); 
		return false;
	}
}
function cambiomenuon(codigomenu){
	var numeromenu
	//numerocuadrado="cuadrado"+codigocuadrado;
	//eval("document."+numerocuadrado+".src='imagenes/imagenesfijas/cuadrado_on.jpg'");
	numeromenu="menu"+codigomenu;
	document.getElementById(numeromenu).className="menu1_hover";
}
function cambiomenuoff(codigomenu){
	var numeromenu
	//numerocuadrado="cuadrado"+codigocuadrado;
	//eval("document."+numerocuadrado+".src='imagenes/imagenesfijas/cuadrado.jpg'");
	numeromenu="menu"+codigomenu;
	document.getElementById(numeromenu).className="menu1";
	
}
function abrecalendario(obj,imagen){
		img = document.getElementById(imagen);
	  habFind=true;
		fixedX=findPosX(img)-200;
		fixedY=findPosY(img)-110;
    popUpCalendar(obj, obj, 'dd/mm/yyyy');
		return;
	}
	function cambiocomaporpunto(cadena){
		cadena=cadena.replace(/,/g,".");
		return cadena;
	}
