//	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 esFechaValidaB(value) {
	      if (value=="") return true;
      	var pos = value.indexOf("/");
      	if (pos == -1) return false;
      	var d = parseInt(value.substring(0,pos));
      	value = value.substring(pos+1, 999);
      	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;
}        
