/*===============================================================================
	CONVIERTE UN NUMERO DE HEXADECIMAL A DECIMAL
	PARAMETRO: cadena a convertir a decimal
===============================================================================*/
function hexdec(f1) {
	cadena=f1;
	cadena = cadena.toUpperCase();
	cadena=cadena.replace("%","");
	rval = parseInt(cadena,16);
	cadena=rval;
	return cadena;
}

/*===============================================================================
	CONTROLA LOS DATOS QUE INTRODUCIMOS POR PANTALLA
		Requiere de la funcion hexdec para funcionar
		PARAMETROS: - tipo: tipo de datos que permitiremos introducir
								- objeto: caja de texto de la cual recogemos los datos
								- separador: caracter utilizado para separar los decimales punto(.) o coma(,)
===============================================================================*/
function tipoDatos(tipo,objeto,separador){
	var contenido=objeto.value;
	contenido=Trim(contenido);
	var longitud=contenido.length;
	codSep=hexdec(escape(separador));
	if(tipo=="numero"){ //SOLO NÚMEROS.
		if(event.keyCode==44 && separador=="."){ //SUSTITUYE LA COMA POR UN PUNTO
			event.keyCode=46;
		}
		if(event.keyCode==46 && separador==","){ //SUSTITUYE EL PUNTO POR UNA COMA
			event.keyCode=44;
		}
		 //SOLO NOR PERMITE UN PUNTO O UNA COMA. ANULA LA INSERCION SI NO HAY NADA EN LA CAJA DE TEXTO
		if(event.keyCode==codSep && (longitud==0 || contenido.indexOf(separador)>-1)){
			event.keyCode=0;
		}
		//SI NO ES UN NUMERO O EL SEPARADOR, ANULA LA INSERCIÓN
		if((event.keyCode<48 || event.keyCode>57) && (event.keyCode!=codSep)){
			event.keyCode=0;
		}
	}else if(tipo=="letrasMin"){ //SOLO LETRAS MINÚSCULAS
		if(event.keyCode<97 || event.keyCode>122){
			event.keyCode=0;
		}
	}
}

function Trim(sString){
	while (sString.substring(0,1)==" "){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length)==" "){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function irA(atras,nueva){
	if(atras=="true"){
		history.back();
	}else if(atras=="false" && nueva!=""){
		document.location=nueva;
	}
}

function MostrarImagenPie(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin,bajoFoto) {
	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("imagen.htm","newWindow","width="+scrWidth+",height="+(scrHeight+100)+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><link rel="stylesheet" type="text/css" href="css/estilos.css"><title>'+alt+'</title><body leftmargin="0" topmargin="'+hugMargin+'" 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="haz click aquí para cerrar" >'); 
	newWindow.document.write('<tr><td class="fuenteVerdana fuente_Blanca"><br>' + bajoFoto + '</td></tr>');
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

function MostrarImagen(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin){
	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("imagen.htm","newWindow","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="haz click aquí para cerrar" >'); 
	newWindow.document.write("</td></tr></table></body></html>");
	newWindow.document.close();
	newWindow.focus();
	}
}

function MostrarPagina(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin){
	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(imageName,"newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.focus();
	}
}
function imprSelec(nombre){
  var ficha = document.getElementById(nombre);
  var ventimp = window.open(' ', 'popimpr','width=700,height=550,location=no,status=no,menu=no,scrollbars=1,top=0,left=0');
	ventimp.document.write('<link href="css/estilos.css" rel="stylesheet" type="text/css">');
  ventimp.document.write( ficha.innerHTML );
	
  ventimp.document.close();
  ventimp.print();
  ventimp.close();
} 
