function irA(atras,nueva){
	if(atras=="true"){
		history.back();
	}else if(atras=="false" && nueva!=""){
		document.location=nueva;
	}
}

function verImg(dire,ancho,alto,scrollB,centrar,titulo){ 
	if(ancho==0 && alto!=0){
		ancho=screen.width-20;
	}else if(alto==0 && ancho!=0){
		alto=screen.height-60;
	}else if(ancho==0 && alto==0){
		ancho=screen.width-20;
		alto=screen.height-60;
	} 
	altura=0;
	if(centrar=="si"){
		altura=(screen.height-alto)/2;
	}
	anchura=(screen.width-ancho)/2;
	var opt="height="+alto+",width="+ancho+",location=no,status=no,menu=no,scrollbars="+scrollB+",top="+altura+",left="+anchura+"";
	window.open(dire,"_new",opt);
}

function tratar(formulario){
	//tratar fecha del proyecto	
	if((document[formulario].name == "form1") || (document[formulario].name == "modificar")){
	correcto=true;
	control=document[formulario].nombre.value;	
	if(control.length=0){
		correcto=false;
		alert("No ha introducido ningún nombre para el Trabajo.");
	}
	control=document[formulario].descripcion.value;
	if(control.length=0){
		respuesta=confirm("No ha introducido descripción para el Trabajo.\n\n¿Desea continuar??");
		if(respuesta==false){correcto=false;}
	}
	control=document[formulario].fecha.value;
	if(control.substr(2,1)!="/" || control.substr(5,1)!="/"){
		correcto=false;
		alert("La fecha del Trabajo no tiene un formato válido.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
	}
	if(control.length!=10){
			correcto=false;
			alert("La fecha del Trabajo no tiene una longitud permitida.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
	}
	//tratar fechas de las imagenes
	j=1
	while(document[formulario]["fecha"+j]=="[object]"){
		control=document[formulario]["fecha"+j].value;
		if(control.substr(2,1)!="/" || control.substr(5,1)!="/"){
			correcto=false;
			alert("La fecha de la imagen Nº: "+j+" no tiene un formato válido.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
		}
		if(control.length!=10){
			correcto=false;
			alert("La fecha de la imagen Nº: "+j+" no tiene una longitud permitida.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
		}
		j++;
	}
	if(correcto==true){
		document[formulario].submit();
		
	}
	}else
	{
	if(!(document[formulario].name == "modificar2")){	
	correcto=true;
	control=document[formulario].modelo.value;	
	if(control.length=0){
		correcto=false;
		alert("No ha introducido ningún modelo para la Maquina.");
	}
	control=document[formulario].descripcion.value;
	if(control.length=0){
		respuesta=confirm("No ha introducido descripción para la Maquina.\n\n¿Desea continuar??");
		if(respuesta==false){correcto=false;}
	}
	control=document[formulario].fecha.value;
	if(control.substr(2,1)!="/" || control.substr(5,1)!="/"){
		correcto=false;
		alert("La fecha no tiene un formato válido.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
	}
	if(control.length!=10){
			correcto=false;
			alert("La fecha no tiene una longitud permitida.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
	}
	//tratar fechas de las imagenes
	j=1
	while(document[formulario]["fecha"+j]=="[object]"){
		control=document[formulario]["fecha"+j].value;
		if(control.substr(2,1)!="/" || control.substr(5,1)!="/"){
			correcto=false;
			alert("La fecha de la imagen Nº: "+j+" no tiene un formato válido.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
		}
		if(control.length!=10){
			correcto=false;
			alert("La fecha de la imagen Nº: "+j+" no tiene una longitud permitida.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
		}
		j++;
	}
	if(correcto==true){
		document[formulario].submit();
		
	}
	}
	//aqui modificar2
	correcto=true;
	control=document[formulario].modelo.value;	
	if(control.length=0){
		correcto=false;
		alert("No ha introducido ningún modelo para la Maquina.");
	}
	control=document[formulario].tipo.value;	
	if(control.length=0){
		correcto=false;
		alert("No ha introducido ningún tipo para la Maquina.");
	}
	control=document[formulario].cantidad.value;	
	if(control.length=0){
		correcto=false;
		alert("No ha introducido ningúna cantidad para la Maquina.");
	}
	
	control=document[formulario].descripcion.value;
	if(control.length=0){
		respuesta=confirm("No ha introducido descripción para la Maquina.\n\n¿Desea continuar??");
		if(respuesta==false){correcto=false;}
	}
	control=document[formulario].fecha.value;
	if(control.substr(2,1)!="/" || control.substr(5,1)!="/"){
		correcto=false;
		alert("La fecha no tiene un formato válido.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
	}
	if(control.length!=10){
			correcto=false;
			alert("La fecha no tiene una longitud permitida.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
	}
	//tratar fechas de las imagenes
	j=1
	while(document[formulario]["fecha"+j]=="[object]"){
		control=document[formulario]["fecha"+j].value;
		if(control.substr(2,1)!="/" || control.substr(5,1)!="/"){
			correcto=false;
			alert("La fecha de la imagen Nº: "+j+" no tiene un formato válido.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
		}
		if(control.length!=10){
			correcto=false;
			alert("La fecha de la imagen Nº: "+j+" no tiene una longitud permitida.\n\nRecuerde: dd/mm/aaa (02/08/2005)");
		}
		j++;
	}
	if(correcto==true){
		document[formulario].submit();
		
	}
	}
}
		
/*
function Abrir_Ventana(pagina,ancho,alto)
{
	
	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 (ancho>w){	
	  byFactor = w / ancho;			
	  ancho = w;
	  alto = ancho * byFactor;
	}
	if (alto>h-adj){
	  byFactor = h / alto;
	  ancho = (ancho * byFactor);
	  alto = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (alto>scrHeight){
  	  alto=alto*lift;
	  ancho=ancho*lift;
	}

	var posLeft=0;
	var posTop=0;


	var scrHeightTemp = alto - 0;
	if (scrHeightTemp < scrHeight) {
	scrHeight = scrHeightTemp;
	} 
	var scrWidthTemp = ancho - 0;
	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 (alto > (h*lift)-adj || ancho > w-adj){
		alto=alto-adj;
		ancho=ancho-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);			
	window.open(pagina,'_new',"HEIGHT='" +alto+ "',WIDTH='" +ancho+ "',TOOLBAR=no,MENUBAR=no,SCROLLBARS=no,RESIZABLE=no,LOCATION=no,DIRECTORIES=no,STATUS=no,left='"+posLeft+"',top='"+posTop);
}*/

function borrarImagen(direccion,identificador,nombreFoto,tipo){
	var opt="";
	var newDireccion="";
	newDireccion=direccion;
	newDireccion=newDireccion.replace("&","!");
	newDireccion=newDireccion.replace("?","@");
	respuesta=confirm("La acción borrará la foto asociada. ¿Desea continuar?");
	if(respuesta==true){
		window.open("delFoto.asp?idf="+identificador+"&nomf="+nombreFoto+"&volver="+newDireccion+"&tipo="+tipo,"_self",opt);
	}
}
function enviarPlanos(identificador,tipo){
	//var opt="";				
		window.open("anadirPlano.asp?idf="+identificador+"&tipo="+tipo,"_blank","status=yes,resizable=no,width=500,height=400");
	
}

function MostrarImagen(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin,bajoFoto) {
	if(mostrar==false){
		return false;
	}
	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="fuente_Verdana fuente_Blanca"><br>' + bajoFoto + '</td></tr>');
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

/*
function validar_fecha(caja){ 
   if (caja){  
      borrar = caja;
      if ((caja.substr(2,1) == "/") && (caja.substr(5,1) == "/")){      
         for (i=0; i<10; i++){	
            if (((caja.substr(i,1)<"0") || (caja.substr(i,1)>"9")) && (i != 2) && (i != 5)){
               borrar = '';
               break;  
			}  
         }
	     if (borrar){ 
	        a = caja.substr(6,4);
		    m = caja.substr(3,2);
		    d = caja.substr(0,2);
		    if((a < 1900) || (a > 2050) || (m < 1) || (m > 12) || (d < 1) || (d > 31))
		       borrar = '';
		    else{
		       if((a%4 != 0) && (m == 2) && (d > 28))	   
		          borrar = '';
			   else{
		          if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29)))
			         borrar = '';	      				  	 
			   }
		    }
         }
      }
	  else
	     borrar = '';
	  if (borrar == '')
	     alert('Debe Introducir una fecha con este formato "dd/mm/yyyy"');
   }
}
function ReplaceCaracter(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function*/