
function OnlyNumberJS(sCadena){
	var strCheck = '0123456789';
	var aux = "";
  if (sCadena=="") return sCadena;
	for (i=0;i<sCadena.length;i++){
    if (sCadena.charAt(i)==",") return aux;		
		if (strCheck.indexOf(sCadena.charAt(i)) != -1) {
	      aux = aux + sCadena.charAt(i);
	  }	  
	}
	return aux;
} 



function formatMiles(nNmb,sep){ 
    var sRes = ""; 
    for (var j, i = nNmb.length - 1, j = 0; i >= 0; i--, j++) 
     sRes = nNmb.charAt(i) + ((j > 0) && (j % 3 == 0)? sep: "") + sRes; 
    return sRes; 
   }

 function formatearSignos(mNum) {
 	var sRes = "";
 	var aux = "";

		if (mNum.indexOf(',') != -1) {
	      aux = OnlyNumberJS(mNum.substring(mNum.indexOf(',')+1, mNum.length));
	  } 	
 	sRes = formatMiles(OnlyNumberJS(mNum),'.');
 	if (aux!="") sRes = sRes + ',' + aux;
 	return sRes;
 }	
 
//	Pone visible el objeto que tiene la id pasada como parametro

function muestra(que){ 
			w=400; 
			h=250;
			if (window.screen) { 
  			w = window.screen.availWidth/2 - 150; 
  			h = window.screen.availHeight/2 - 50;
			} 

  		var ofy=document.body.scrollTop;
		  document.getElementById(""+que).style.top = h + ofy - 50;//event.clientY+ofy+11;
		  document.getElementById(""+que).style.left = w;		
		  hideElementProcesando("SELECT");  
      document.getElementById(""+que).style.visibility='visible';  
	document.getElementById(""+que).style.visibility="visible";
}

function hideElementProcesando(elmID)
{
	if (!document.all) {
		return;
	}
	x = parseInt(document.all.divOculto.style.left);
	y = parseInt(document.all.divOculto.style.top);
	xxx = parseInt(document.all.divOculto.offsetWidth);
	yyy = parseInt(document.all.divOculto.offsetHeight);
		
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent || obj.id=="divOculto")
			continue;

		// Find the element's offsetTop and offsetLeft relative to the BODY tag.
		objLeft   = obj.offsetLeft;
		objTop    = obj.offsetTop;
		objParent = obj.offsetParent;
		while (objParent.tagName.toUpperCase() != "BODY")
		{
			objLeft  += objParent.offsetLeft;
			objTop   += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}
										
		// Adjust the element's offsetTop relative to the dropdown menu
		//objTop = objTop - y;
	
		if (x > (objLeft + obj.offsetWidth) || objLeft > (x + xxx))
			;
		else if (objTop > y + yyy)
			;
		else if (y > (objTop + obj.offsetHeight))
			;
		else
			obj.style.visibility = "hidden";
	}
}

function esMayorFechaStr(fecha1, fecha2) {
	var Year='';
	var Mes='';
	var diaMes='';

 	var pos = fecha1.indexOf("/"); 	
	if (pos != -1) diaMes = fecha1.substring(0,pos);
	fecha1 = fecha1.substring(pos+1, 999);	
	pos = fecha1.indexOf("/");
	if (pos!=-1) Mes = fecha1.substring(0,pos);
	fecha1 = fecha1.substring(pos+1, 999);
	Year = fecha1;
		
	var mDate1=new Date(Year, Mes - 1, diaMes,'23','59','59');
	Year='';
	Mes='';
	diaMes='';	
		
 	pos = fecha2.indexOf("/"); 	
	if (pos != -1) diaMes = fecha2.substring(0,pos);
	fecha2 = fecha2.substring(pos+1, 999);	
	pos = fecha2.indexOf("/");
	if (pos!=-1) Mes = fecha2.substring(0,pos);
	fecha2 = fecha2.substring(pos+1, 999);
	Year = fecha2;
		
	var mDate2=new Date(Year, Mes - 1, diaMes,'23','59','59');
	
	var msegFecha2 = mDate2.getTime();
	var msegFecha1 = mDate1.getTime();
	var Diferencia = msegFecha2 - msegFecha1;
	Diferencia /= 86400000;
	if (Diferencia < 0) {
    return true;
	} else {
    return false;
	}
}      

	    function esFechaValidaB(value) {
	      if (value=="") return true;
	        if (value.substring(0,1)=='0') {
		          value=value.substring(1,value.length);		     
		      }
	      	var pos = value.indexOf("/");
	      	if (pos == -1) return false;		      
	      	var d = parseInt(value.substring(0,pos));
	      	value = value.substring(pos+1, 999);
	        if (value.substring(0,1)=='0') {
		        value=value.substring(1,value.length);		
		      } 
	      	pos = value.indexOf("/");
	      	if (pos==-1) return false;		           
	      	var m = parseInt(value.substring(0,pos));
	      	value = value.substring(pos+1, 999);
	      	var y = parseInt(value);    		    	 	    		    	
	      	if (isNaN(d)) return false;	
	      	if (isNaN(m)) return false;	
	      	if (isNaN(y)) return false;   	      	
	      		
	      	return isValidDate(d,m,y);	
	    }

	    function isValidDate(day, month, year) {
        	if (!isNumber(day)) return false;	
        	if (!isNumber(month)) return false;	
        	if (!isNumber(year)) return false;		        
	        if (month < 1 || month > 12) {
                    return false;
                }
                if (day < 1 || day > 31) {
                    return false;
                }
                if ((month == 4 || month == 6 || month == 9 || month == 11) &&
                    (day == 31)) {
                    return false;
                }
                if (month == 2) {
                    var leap = (year % 4 == 0 &&
                               (year % 100 != 0 || year % 400 == 0));
                    if (day>29 || (day == 29 && !leap)) {
                        return false;
                    }
                }
                return true;
            }
            
// Return true if value is a number
function isNumber(value) {
	if (value=="") return false;

	var d = parseInt(value);
	if (!isNaN(d)) return true; else return false;		

}

function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked )
    // if we add this call we close the calendar on single-click.
    // just to exemplify both cases, we are using this only for the 1st
    // and the 3rd field, while 2nd and 4th will still require double-click.
    cal.callCloseHandler();
}


function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}


function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(1, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}        

<!--
// begin JavaScript utilities

// SLIDESHOW CON CONTROLES

function doNextPic()    {    
this.imgObj=eval(this.theImgObj);
(this.n == (this.theImg.length-1)) ? this.n = 0 : this.n++;
this.imgObj.src = this.theImg[this.n];
if (this.theBoolText[this.n] == "yes") 	document.getElementById(this.theTextObj).innerHTML=this.theText[this.n];
this.thePic = this.n;
}

function doPrevPic()    {
this.imgObj=eval(this.theImgObj);
(this.n == 0) ? this.n = this.theImg.length-1 : this.n--;
this.imgObj.src = this.theImg[this.n];
if (this.theBoolText[this.n] == "yes") 	document.getElementById(this.theTextObj).innerHTML=this.theText[this.n]; 
this.thePic = this.n;
}

function doPic(thePicNum)    {
this.imgObj=eval(this.theImgObj);
this.imgObj.src = this.theImg[thePicNum];
if (this.theBoolText[thePicNum] == "yes") 	document.getElementById(this.theTextObj).innerHTML=this.theText[thePicNum]; 
this.n = thePicNum;
this.thePic = thePicNum;
}

function doStop() 	{
clearTimeout(this.timerID);
this.timerInterval=0;
			}

function goPic() {
if (this.theOpenInPopup[this.thePic] == "yes") 	{
var newWin = window.open(this.theLink[this.thePic]);
	} else {
top.location=this.theLink[this.thePic];
		}
}

function slideObj()     {
this.theImgObj = "";
this.theTextObj = "";
this.thePic = 0;
this.n = 0;
this.timerID=0;
this.LGtimerInterval=1000*3; //---Timer works well at 6--- Set the number to the right of the asterisc to the number of seconds you want the Features box to wait before auto-rotating
this.SMtimerInterval=1000*0; //Set the number to the right of the asterisc to the number of seconds you want the Exclusives box to wait before auto-rotating
this.theImg = new Array();
this.theLink = new Array();
this.theOpenInPopup= new Array();
this.theBoolText= new Array();
this.theText = new Array();

this.doNextPic = doNextPic;
this.doPrevPic = doPrevPic;
this.doPic = doPic;
this.doStop = doStop;
this.goPic = goPic;                       }

//document.thePicSmallHotSpots1.src=theImg[0];

// SLIDESHOW CON CONTROLES

// ROLLOVER HEADER
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// ROLLOVER HEADER

// ROLLOVER CENTROS

function Iluminar(num)
{
	eval("document.all.Cel"+num+".style.border = 'solid 1px #A72E24'");	
}

function Apagar(num)
{
	eval("document.all.Cel"+num+".style.border = 'solid 1px #FFFFFF'");	
}

// ROLLOVER CENTROS
//-->

function validarCIF(cif)
{
par = 0
non = 0
letras="ABCDEFGHJKLMNPQRSUVW"
let=cif.charAt(0)

if (!isNaN(let))
  {
    return false; 
  }

if (cif.length!=9)
  {
  return false
  }

if (letras.indexOf(let.toUpperCase())==-1)
  {
  return false
  }

for (zz=2;zz<8;zz+=2)
  {
  par = par+parseInt(cif.charAt(zz))
  }

for (zz=1;zz<9;zz+=2)
  {
  nn = 2*parseInt(cif.charAt(zz))
  if (nn > 9) nn = 1+(nn-10)
  non = non+nn
}

parcial = par + non

control = (10 - ( parcial % 10))

if (control==10) control=0

if (control!=cif.charAt(8))
  {
  return false
  }
  return true; 
  
}    
    
    function validarNIF(nif){  
      letras = new Array();
      letras[0]  = "T";
      letras[1]  = "R";
      letras[2]  = "W";
      letras[3]  = "A";
      letras[4]  = "G";
      letras[5]  = "M";
      letras[6]  = "Y";
      letras[7]  = "F";
      letras[8]  = "P";
      letras[9]  = "D";
      letras[10] = "X";
      letras[11] = "B";
      letras[12] = "N";
      letras[13] = "J";
      letras[14] = "Z";
      letras[15] = "S";
      letras[16] = "Q";
      letras[17] = "V";
      letras[18] = "H";
      letras[19] = "L";
      letras[20] = "C";
      letras[21] = "K";
      letras[22] = "E";
        
      let=nif.charAt(0)
      
      if (let=="x" || let=="X") {
          nif = nif.substring(1,nif.length) 
      }  

      if (nif.length!=9)
        {
        return false
        }          
        
      nif = nif.toUpperCase();  

      nif=TrimJS(nif);
         
      esLetra=nif.charAt(nif.length-2);

      if (isNaN(parseInt(esLetra))) {
        return false; 
      }

      dni=nif.substring(0,nif.length-1);

      dni=parseInt(dni,10);

      letra=nif.charAt(nif.length-1);
      letraCorrecta = letras[ dni % 23];
    
      if (dni > 99999999){ 
        return false;
      } else if(letra!=letraCorrecta) {
        return false;
      }
    
      return true;

    }  
    
function TrimJS(sCadena){
	var SpaceChar  = " ";
	var aux = "";

	for (i=0;i<sCadena.length;i++){
	  if (sCadena.charAt(i) != SpaceChar) {
	      aux = aux + sCadena.charAt(i);
	  }	  
	}
	return aux;
} 

function checkCampoHoras(horas){
 if(/^(00|0|1|01|2|02|3|03|4|04|5|05|6|06|7|07|8|08|9|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23):([0-5]0|[0-5][1-9])$/.test(horas)){
   return true;
}
return false;
}

	function comparaFechas(fec1, fec2){
		
		var esMayor=true;
		var dia1 = fec1.substr(0 , 2);
		var mes1 = fec1.substr(3 , 2); 
		var anno1= fec1.substr(6 , 4);
    var dia2 = fec2.substr(0 , 2); 
    var mes2 = fec2.substr(3 , 2); 
		var anno2= fec2.substr(6 , 4);
		if (anno1>anno2)esMayor=false;
		else{
			if (anno1==anno2){
				if (mes1>mes2) esMayor=false;
				else{
					if (mes1==mes2){
						if (dia1>dia2) esMayor=false;
					}
				}
			}
		}
		return esMayor;
	}
	    function validaMail(cadena){
      if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(cadena)){
       return (true)
      } else {
       return (false);
      }
    }
