function checkOptionType(oOptions,sProperty,sType,oDefault)
{  
   //alert(sProperty+' :: '+(typeof oOptions[sProperty]));
   if (typeof(oOptions[sProperty]) == sType) return;
   oOptions[sProperty] = oDefault;
}

function EasyDynarchSelected(cal, date) {
  if (cal.applyTo != null) { 
    switch(cal.applyTo.tagName.toUpperCase()) {
	  case 'INPUT': { cal.applyTo.value = date; break; }
	  case 'DIV'  :
	  case 'SPAN' : { cal.applyTo.innerHTML = date; }
	}	
  }
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;

function EasyDynarchDisablePast(date) {
  var today = new Date();
  return date.getTime() < (today.getTime()-DAY);
}

function EasyDynarch(options)
{
   // check options
   if (options==null) { options={} };
   checkOptionType(options,'htmlelement','string',null);
   checkOptionType(options,'weekNumbers','boolean',true);
   checkOptionType(options,'setDateFormat','string','%Y-%m-%d');
   checkOptionType(options,'onSelected','function',EasyDynarchSelected);
   checkOptionType(options,'disablePast','boolean',false);
   checkOptionType(options,'applyTo','string',null);
   checkOptionType(options,'hiliteToday','boolean',false); 
   checkOptionType(options,'hidden','boolean',false);   
   if (options.htmlelement == null || options.htmlelement == "") return;
   htmlElement = document.getElementById(options.htmlelement);
   if (htmlElement==null) return;   
   // show calendar
   cal = new Calendar(1, null, options.onSelected);   
   cal.weekNumbers = options.weekNumbers;
   cal.setDateFormat(options.setDateFormat);     
   cal.hidden = options.hidden; 
   if (options.disablePast) cal.setDisabledHandler(EasyDynarchDisablePast);
   cal.applyTo = (options.applyTo != null)? document.getElementById(options.applyTo): null;   
   cal.create(htmlElement);     
   if (cal.applyTo != null) cal.parseDate(cal.applyTo.value); 
   cal.callHandler();   
   // Attributes
   this.htmlElement = htmlElement;
   this.calendar = cal;
   // Hide/show
   if (cal.hidden) { 
     this.hide(); 
   }
   else {
     cal.show();
   }   
}
EasyDynarch.prototype.hide = function()
{
   this.htmlElement.style.display = 'none';
   this.calendar.hide();
}
EasyDynarch.prototype.show = function()
{
   this.htmlElement.style.display = '';
   this.calendar.show();
}


