function number_format(number, numdec, points){
   var pd, pe;
   number = ""+number; //lo paso a string porsiaka
   number.replace(",",".");
   number = parseFloat(number);
   if (isNaN (number)) number=0;
   number=Math.round(eval(number) * Math.pow(10,numdec));
   aux = "" + number;
   if (numdec >0){
      while(aux.length <= numdec){
         aux = "0" + aux;
      }
      var point = aux.length - numdec;
      pe = aux.substring(0,point);
      pd = aux.substring(point,aux.length);
   }else{
      pe = number.toString();
      pd = "";
   }
   if(points == 1){
      if(pe.length>3){
         res = "";
         cont = 0;
         for(i=pe.length-1;i>=0;i--){
            if(cont++%3 == 0 && i<pe.length-1)
               res = "." + res;
            res = pe.charAt(i) + res;
         }
         pe = res;
      }
   }
   //ya tengo preparada pe y pd
   if(numdec > 0)
      return pe+","+pd;
   else
      return pe;
}
function getOutDecimalSeparators(str){
   var strTemp=str;
   strTemp=strTemp.replace(/\./g,"");
   strTemp=strTemp.replace(/,/g,".");
   return parseInt(strTemp);
}
function showtip(current,text){
   if (document.all){
         current.title=text;
   }
}
function hidetip(){
   if (document.layers)
      document.tooltip.visibility="hidden";
}
function getCookie(NameOfCookie){
 var begin,end;
 if (document.cookie.length > 0) { 
    begin = document.cookie.indexOf(NameOfCookie+"="); 
    if (begin != -1){
       begin += NameOfCookie.length+1; 
       end = document.cookie.indexOf(";", begin);
       if (end == -1) end = document.cookie.length;
       return unescape(document.cookie.substring(begin, end));
    } 
 }
 return null;  
}
function setCookie(NameOfCookie, value, expiredays) {
 var ExpireDate = new Date ();
 ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
 expiredays = null;
 document.cookie = NameOfCookie + "=" + escape(value) +
    ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) +  "; path=/";
}
function delCookie (NameOfCookie) {
   if (getCookie(NameOfCookie)) {
      document.cookie = NameOfCookie + "=" +"; path=/";
   }
}
function getPuntoVisita(){
	str = getCookie(PUNTO_COOKIE);
	if(str == null || str == ''){
		alert("")
		return "javascript:history.go(-1);";
	}else{
    alert(str)
    return unescape(str);
	}
}
function setPuntoVisita(donde){
	setCookie(PUNTO_COOKIE,escape(donde),2000);
}
function verificarCP(valor){
	var codigo=valor;
	var entrada=codigo.substring(0,1);
	if ((codigo.length==4)&&(entrada==1)){
		codigo=0+codigo;
	}
	return codigo;
}
function comprobarCP(valor){
	var codigo=verificarCP(valor);
	if (codigo.length!=5)	{
		return false;
	}
	if (codigo== '') {
		return false;
	}
	if(isNaN(codigo.substring(1,codigo.length))){
		return false;
	}
	return true;
}
//* script para validar fechas en una caja de texto.
//* funcion para comprobar si una año es bisiesto
//* argumento anyo -> año extraido de la fecha introducida por el usuario
function anyoBisiesto(anyo)
{
  //* si el año introducido es de dos cifras lo pasamos al periodo de 1900. Ejemplo: 25 > 1925
  if (anyo < 100)
      var fin = anyo + 1900;
  else
    var fin = anyo ;
    //* primera condicion: si el resto de dividir el año entre 4 no es cero > el año no es bisiesto
    //* es decir, obtenemos año modulo 4, teniendo que cumplirse anyo mod(4)=0 para bisiesto
    if (fin % 4 != 0)
        return false;
    else{
      if (fin % 100 == 0) {
        //* si el año es divisible por 4 y por 100 y divisible por 400 > es bisiesto
        if (fin % 400 == 0){
            return true;
        }else{
          //* si es divisible por 4 y por 100 pero no lo es por 400 > no es bisiesto
          return false;
        }
      }else{
          //* si es divisible por 4 y no es divisible por 100 > el año es bisiesto
          return true;
      }
    }
}
//* funcion principal de validacion de la fecha
//* argumento fecha > cadena de texto de la fecha introducida por el usuario
//* devuelve 0 -> fecha correcta
//* devuelve 1 -> dia incorrecto
//* devuelve 2 -> mes incorrecto
//* devuelve 3 -> anyo incorrectp
function NIF_error ( str, letra ) {
	// el NIF debe ser un numerico mas una letra
	var re_dni = new RegExp ("^[0-9]*$");
	if (!re_dni.test (str)) return true;
	longitud = str.length;
	if ( longitud > 8 ) return true;
	var numero = str;
	resto = numero - (parseInt (numero / 23)) * 23;

	switch ( resto ) {
		case 3:
			if ((letra != "A") && (letra != "a")) return true;
			break;
		case 11:
			if ((letra != "B") && (letra != "b")) return true;
			break;
		case 9:
			if ((letra != "D") && (letra != "d")) return true;
			break;
		case 22:
			if ((letra != "E") && (letra != "e")) return true;
			break;
		case 7:
			if ((letra != "F") && (letra != "f")) return true;
			break;
		case 4:
			if ((letra != "G") && (letra != "g")) return true;
			break;
		case 18:
			if ((letra != "H") && (letra != "h")) return true;
			break;
		case 13:
			if ((letra != "J") && (letra != "j")) return true;
			break;
		case 21:
			if ((letra != "K") && (letra != "k")) return true;
			break;
		case 19:
			if ((letra != "L") && (letra != "l")) return true;
			break;
		case 5:
			if ((letra != "M") && (letra != "m")) return true;
			break;
		case 12:
			if ((letra != "N") && (letra != "n")) return true;
			break;
		case 20:
			if ((letra != "C") && (letra != "c")) return true;
			break;
		case 8:
			if ((letra != "P") && (letra != "p")) return true;
			break;
		case 16:
			if ((letra != "Q") && (letra != "q")) return true;
			break;
		case 1:
			if ((letra != "R") && (letra != "r")) return true;
			break;
		case 15:
			if ((letra != "S") && (letra != "s")) return true;
			break;
		case 0:
			if ((letra != "T") && (letra != "t")) return true;
			break;
		case 17:
			if ((letra != "V") && (letra != "v")) return true;
			break;
		case 2:
			if ((letra != "W") && (letra != "w")) return true;
			break;
		case 10:
			if ((letra != "X") && (letra != "x")) return true;
			break;
		case 6:
			if ((letra != "Y") && (letra != "y")) return true;
			break;
		case 14:
			if ((letra != "Z") && (letra != "z")) return true;
			break;
	}
	return false;
}
function comprobar(dni,letra){
	if (dni.length!=8){
		return false;
	}
	if (dni== '') {
		return false;
	}
	if (letra == '') {
		return false;
	}
	if ((dni.substring(0,1)!='x')&&(dni.substring(0,1)!='X')&&(dni.substring(0,1)!='y')&&(dni.substring(0,1)!='Y')){
		if (NIF_error (dni,letra)) {
			return false;
		}
	}else{
		if ((letra > '0') && (letra < '9')){
			return false;
		}
		if(isNaN(dni.substring(1,dni.length))){
			return false;
	    }
		
		if ((dni.substring(0,1)=='x') ||(dni.substring(0,1)=='X')){
			dni='0'+ dni.substring(1,dni.length);
		}
		if ((dni.substring(0,1)=='y')||(dni.substring(0,1)=='Y')){
			dni='1'+ dni.substring(1,dni.length);
		}
	    if (NIF_error (dni,letra)) {
			return false;
		}
	}
	return true;	
}
function validarFecha(dia, mes, anyo){
 if(anyoBisiesto(anyo))
  febrero=29;
 else
  febrero=28;
  //* si el mes introducido es negativo, 0 o mayor que 12 > alertamos y detenemos ejecucion
  if ((mes<1) || (mes>12)){
    //alert("El mes introducido no es valido. Por favor, introduzca un mes correcto");
    return 2;
  }
  //* si el mes introducido es febrero y el dia es mayor que el correspondiente 
  //* al año introducido > alertamos y detenemos ejecucion
  if ((mes==2) && ((dia<1) || (dia>febrero))){
   //alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
   return 1;
  }
  //* si el mes introducido es de 31 dias y el dia introducido es mayor de 31 > alertamos y detenemos ejecucion
   if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31))){
     //alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
     return 1;
   }
   //* si el mes introducido es de 30 dias y el dia introducido es mayor de 301 > alertamos y detenemos ejecucion
   if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30))){
    //alert("El dia introducido no es valido. Por favor, introduzca un dia correcto");
    return 1;
  }
  //* si el mes año introducido es menor que 1900 o mayor que 2010 > alertamos y detenemos ejecucion
  //* NOTA: estos valores son a eleccion vuestra, y no constituyen por si solos fecha erronea
  if ((anyo<1900) || (anyo>2020)){
   //alert("El año introducido no es valido. Por favor, introduzca un año entre 1900 y 2010");
   return 3;
 }else 
  //* en caso de que todo sea correcto > enviamos los datos del formulario
  //* para ello debeis descomentar la ultima sentencia
  //alert("La fecha introducida es correcta. Gracias por su colaboración");
  return 0;
 }    
function layerObject(id,left) {
  if (bolMover){
    if (ns6) {
      this.obj = document.getElementById(id).style;
      this.obj.left = left;
      return this.obj;
    }else if(ie4) {
      this.obj = document.all[id].style;
      this.obj.left = left;
      return this.obj;
    }else if(ns4) {
      this.obj = document.layers[id];
      this.obj.left = left;
      return this.obj;
    }
  }
}
function layerSetup() {
  //floatLyr = new layerObject('floatLayer', pageWidth * .7);
  window.setInterval("main()", 10)
}
function floatObject(bolMover) {
  if (bolMover){
    if (ns4 || ns6) {
      findHt = window.innerHeight;
    } else if(ie4) {
      findHt = document.body.clientHeight;
    }
  }
} 
function main() {
  if (bolMover){
    if (ns4) {
      this.currentY = document.layers["floatLayer"].top;
      this.scrollTop = window.pageYOffset;
      mainTrigger();
    }else if(ns6) {
   
      this.currentY = parseInt(document.getElementById('floatLayer').style.top);
      this.scrollTop = scrollY;
      mainTrigger();
    } else if(ie4) {
      this.currentY = floatLayer.style.pixelTop;
      this.scrollTop = document.body.scrollTop;
      mainTrigger();
    }
  }
}
function mainTrigger() {
  if (bolMover){
    var newTargetY = this.scrollTop + this.topMargin;
    posPie = getposOffset(document.getElementById('pie'), "top")+50;
    posBottom = newTargetY + document.getElementById('floatLayer').offsetHeight;
	//document.getElementById("textodebug").innerHTML=document.getElementById("textodebug").innerHTML+posPie+" "+posBottom+" ";
    if (posPie<posBottom) { 
    	inicioCapa = posPie-document.getElementById('floatLayer').offsetHeight;
    	if (inicioCapa<0)
    		newTargetY = 0;
    	else 
    		newTargetY = posPie-document.getElementById('floatLayer').offsetHeight-100; 
    }
    if (isNaN(currentY))
    	currentY = 0;
    if ( this.currentY != newTargetY ) {
      if ( newTargetY != this.targetY ) {
        this.targetY = newTargetY;
        floatStart();
      }
      animator();
    }
  }
}
function floatStart() {
  if (bolMover){
	  
    var now = new Date();
    this.A = this.targetY - this.currentY;
    this.B = Math.PI / ( 2 * this.slideTime );
    this.C = now.getTime();
    if (Math.abs(this.A) > this.findHt) {
      this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
      this.A = this.A > 0 ? this.findHt : -this.findHt;
    }else {
      this.D = this.currentY;
    }
  }
}
function animator() {
  if (bolMover){
    var now = new Date();
    var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D - 23 ;   
    newY = Math.round(newY);
    if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {    	
      if ( ie4 )
      {
      document.all.floatLayer.style.pixelTop = newY;
      
      }
      if ( ns4 )
      {document.layers["floatLayer"].top = newY;
       
      }
      if ( ns6 )
      {
		  
      document.getElementById('floatLayer').style.top = newY+ "px";
      
      }
    }
  }
}
//* funcion de captura de pulsación de tecla en Internet Explorer *//
function capturaTecla (e, enterFunction){
  if (!e) e = window.event;
  if (e.keyCode == 13){
    e.cancelBubble = true;
    if (e.returnValue) e.returnValue = false;
    if (e.stopPropagation) e.stopPropagation();
    if (enterFunction) eval(enterFunction);
      return false;
  }else{
    return true;
  }
}