//---------------------------------------------------------------------------
// Fichero: fun_comun.js										
// Objeto : Funciones javascript comunes para las páginas de la aplicación						
// Creado : 07/04/2006														
// Autor  : Doo2Web Solutions S.L.											
// (c) Copyright 2006, Doo2Web Solutions. Todos los derechos reservados.		
//---------------------------------------------------------------------------

function Escribe_Fecha () {
                       var mydate=new Date();
                       var year=mydate.getYear();
                       if (year < 1000)year+=1900;
                       var month=mydate.getMonth()+1;
                       var daym=mydate.getDate();
                       var dia = mydate.getDay(daym);
                       switch (dia){
                                   case 1:
                                        var diaHoy = "lunes";
                                        break;
                                   case 2:
                                        var diaHoy = "martes";
										break;

                                   case 3:
                                        var diaHoy = "mi&eacute;rcoles";
                                        break;
                                   case 4:
                                        var diaHoy = "jueves";
                                        break;
                                   case 5:
                                        var diaHoy = "viernes";
                                        break;
                                   case 6:
						                var diaHoy = "s&aacute;bado";
										break;
                                   case 0:
                                        var diaHoy = "domingo"
										break;
                       }
                       switch (month){
                                  case 1:
                                        var mesHoy = "enero";
										break;
                                  case 2:
                                        var mesHoy = "febrero";
 							            break;
                                   case 3:
                                        var mesHoy = "marzo";
                                        break;
                                   case 4:
                                        var mesHoy = "abril";
										break;
                                   case 5:
                                        var mesHoy = "mayo";
                                        break;
                                   case 6:
                                        var mesHoy = "junio";
										break;
                                   case 7:
                                        var mesHoy = "julio";
                                        break;
                                   case 8:
                                        var mesHoy = "agosto";
										break;
                                   case 9:
                                        var mesHoy = "septiembre";
										break;
                                   case 10:
                                        var mesHoy = "octubre";
                                        break;
                                   case 11:
                                        var mesHoy = "noviembre";
										break;
                                   case 12:
                                   	    var mesHoy = "diciembre";
										break;
                       }                       

                       var fecha = diaHoy +', '+daym +' de '+  mesHoy +' de '+ year;
                      document.write (fecha);
                      //alert (fecha);
}

//-abrirvImg-// Esta función abre una nueva ventana autoresizable al contenido
function abrirvImg(imageURL,imageTitle){
	// Horizontal and vertical position for the popup
	PositionX = (screen.width - 800) / 2;
	PositionY = (screen.height - 580) / 2;
	
	// These value approximately 20 pixels greater than the
	// size of the largest image to be used (needed for Netscape)
	defaultWidth  = 800;
	defaultHeight = 580;
	// Autoclose true to have the window close automatically
	// Autoclose false to allow multiple popup windows
	var AutoClose = true;
	// Background color of the popup window
	var bgColor = "19302D";
	
	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
	writeln('<html><head><meta HTTP-EQUIV="Imagetoolbar" content="no"><meta NAME="MSSmartTagsPreventParsing" CONTENT="true"><title>Cargando...</title><style>body{margin:0px;background-color:#000;font-size: 10px;font-family: Verdana, Helvetica, Arial, sans-serif;}</style>');writeln('<sc'+'ript>');
	writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
	writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
	writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,100);');
	writeln('width=100-(document.body.clientWidth-document.images[0].width-230);');
	writeln('height=100-(document.body.clientHeight-document.images[0].height-40);');
	writeln('window.resizeTo(width,height+30);}');writeln('if (isNN){');       
	writeln('window.innerWidth=document.images["Img"].width+50;');
	writeln('window.innerHeight=document.images["Img"].height+65;');writeln('}');
	writeln('}');
	writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
	if (!AutoClose) writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
	writeln('<center><h1 style="font-size:14px;color:#fff;line-height:15px;">'+imageTitle+'</h1><img name="Img" src=/'+imageURL+' style="border: 1px solid #585858;"></center></body></html>');
	close();
	}
}

//-estaVacio-//Esta función comprueba si un campo está vacío
function estaVacio(campo, etiqueta) {
	if (campo.value.length == 0) {
		alert("Atención, el valor del campo requerido (" + etiqueta.toUpperCase() + ") no puede estar vacío.");
		campo.focus();
		return true;
	}
	return false;
}

//-longitud-//Esta función comprueba la longitud del usuario y el password
function tieneLongitud(campo, etiqueta, valor1, valor2) {
    if (!(campo.value.length == 0))
	{
		if (campo.value.length < valor1 || campo.value.length > valor2) {
			if (valor1 == valor2)
			{
			alert("Atención, el valor del campo requerido (" + etiqueta.toUpperCase() + ") tiene que tener " + valor1 + " caracteres.");
			}
			else {
			alert("Atención, el valor del campo requerido (" + etiqueta.toUpperCase() + ") tiene que tener entre " + valor1 + " y " + valor2 + " caracteres.");
			}

			campo.focus();
			return true;
		}
		return false;
	}
	return false;
}
//-cif - nif valido //Esta función comprueba que el cif se valido (8 numeros y una letra)
function cif_valido (campo, etiqueta) {
   
    if ( 
	(esNum (campo.value.substring(0,8)) || esNum (campo.value.substring(1,8)) ) 
	&& (!esNum (campo.value.substring(0,1)) || !esNum (campo.value.substring(8))) 
	&& !esComilla (campo.value.substring(0,1)) && !esComilla (campo.value.substring(8)))
	{
	return false;
	}
		alert("Atención, el valor del campo requerido (" + etiqueta.toUpperCase() + ") debe ser correcto.\nFormato: 8 números 1 letra, o bien: 1 letra 8 números");
		campo.focus();
		return true;
	
}
//Esta función comprueba si es una dirección valida
	function noEsMail(campo, etiqueta) {
	if (campo.length > 0) {
		var sArroba=/^(.+)@(.+)$/;
		if (campo.value.match(sArroba)==null) {
			alert("ERROR: Campo incorrecto (" + etiqueta.toUpperCase() + ").");
			campo.focus();
			return true;
		}	
		var sPunto=campo.value.match(sArroba)[2];
		var iPunto=sPunto.length;
		var encontrado=0;
		for (i=0;i<iPunto;i++) {
			if (sPunto.charAt(i)==".") {
				encontrado = 1;
			}
		}
		if (!encontrado) {
			alert("ERROR: Campo incorrecto (" + etiqueta.toUpperCase() + ").");
			campo.focus();
			return true;
		}
		return false;
	} else {
		return false;
	}
	
	}
//-sonIguales-//Esta función comprueba que la nueva password sea igual las dos veces
function sonIguales(pass1, pass2) {
	if (pass1.value == pass2.value) {
		return true;
	} else {
		alert("ERROR: La Nueva contraseña no se ha tecleado igual las 2 veces." );
		return false;		
	}
}
//-noNumerico-//Estas funciones comprueban si el campo es numérico
function noNumerico(campo, etiqueta) {
	if (!esNum(campo.value)) {
		alert("Atención, el valor del campo requerido " + etiqueta.toUpperCase() + " debe ser numérico.");
		campo.focus();
		return true;
	}
	return false;
}

function esNum(dato){
	var numchars=0;
	var vabien=true;
	var subdato;
	
		numchars=eval(dato.length);
		for (var c=0;c<numchars;c++){
			subdato = dato.substring(c,c + 1);
			if (esNumero(subdato)==false) {
				vabien = false;
			}
		}
		return(vabien);
}
function esNumero(d){
	if ((d!='0') && (d!='1') && (d!='2') && (d!='3') && (d!='4') && (d!='5') &&
		(d!='6') && (d!='7') && (d!='8') && (d!='9')) {
		return false;
	}else{
		return true;
	}
}
// Ha acepto la clausula
function NoAceptadoClausula (campo, etiqueta) {
	
		if (!campo.checked) {
	 		alert ("Atención, debe aceptar la cláusula de la Ley de Protección de Datos");
			campo.focus();
			return true;
	 	} else {
			return false;
		}
}

