// JavaScript Document
var isParent = function(current,filter)
{
	var obj = current;
	var index = [];
	var content = [];
	var bool = false;
	for(i in filter)
	{	
		index.push(i);
		content.push(filter[i]);
	}
	while(obj != null)
	{	
		for(var i=0;i<index.length;i++)
		{
			eval('var src = obj.'+index[i]+';');
			if(src == content[i]) bool = true;
		}
	
		obj = obj.parentNode; 
	}
	return bool;
}


var randomWord = function(len)
{
	if(!len) len = 6;
	var abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q'];
    var index = Math.floor(Math.random()*Number(abc.length));
}


var scrollcontent = {
	cache:{},
	style:function()
	{
		this.cssText = false;
		this.border = false;
		this.borderTop = false;
		this.borderBottom = false;
		this.borderLeft = false;
		this.borderRight = false;
		this.borderColor = false;
		this.backgroundColor = false;
		this.backgroundImage = false;
		this.backgroundRepeat = false;
		this.backgroundPosition = false;
		this.textAlign = false;
		this.fontSize = false;
		this.font = false;
		this.width = false;
		this.height = false;
		this.position = false;
		this.textDecoration = false;
		this.color = false;
		this.top = false;
		this.left = false;
		this.right = false;
		this.bottom = false;
		this.cursor = false;
		this.zIndex = false;
		this.display = false;
		this.overflow = false;
		this.padding = false;
		this.paddingTop = false;
		this.paddingBottom = false;
		this.paddingLeft = false;
		this.paddingRight = false;
		this.margin = 0;
		this.marginTop = false;
		this.marginBottom = false;
		this.marginLeft = false;
		this.marginRight = false;
		this.listStyle = false;
		this.float = false;
		this.scaleUnit = 'px';
		this.html = function()
		{
			var s = '';
			if(this.cssText) s+=this.cssText;
			if(this.backgroundImage) s+='background-image:url('+this.backgroundImage+');';
			if(this.backgroundRepeat) s+='background-repeat:'+this.backgroundRepeat+';';
			if(this.backgroundPosition) s+='background-position:'+this.backgroundPosition+';';
			if(this.float) s+='float:'+this.float+';';
			if(this.listStyle) s+='list-style:'+this.listStyle+';';
			if(this.borderTop) s+='border-top:'+this.borderTop+';';
			if(this.borderBottom) s+='border-bottom:'+this.borderBottom+';';
			if(this.borderLeft) s+='border-left:'+this.borderLeft+';';
			if(this.borderRight) s+='border-right:'+this.borderRight+';';
			if(this.padding) s+='padding:'+this.padding+';';
			if(this.paddingTop) s+='padding-top:'+this.paddingTop+this.scaleUnit+';';
			if(this.paddingBottom) s+='padding-bottom:'+this.paddingBottom+this.scaleUnit+';';
			if(this.paddingLeft) s+='padding-left:'+this.paddingLeft+this.scaleUnit+';';
			if(this.paddingRight) s+='padding-right:'+this.paddingRight+this.scaleUnit+';';
			if(this.margin) s+='margin:'+this.margin+';';
			if(this.marginTop) s+='margin-top:'+this.marginTop+this.scaleUnit+';';
			if(this.marginBottom) s+='margin-bottom:'+this.marginBottom+this.scaleUnit+';';
			if(this.marginLeft) s+='margin-left:'+this.marginLeft+this.scaleUnit+';';
			if(this.marginRight) s+='margin-right:'+this.marginRight+this.scaleUnit+';';
			if(this.display) s+='display:'+this.display+';';
			if(this.overflow) s+='overflow:'+this.overflow+';';
			if(this.zIndex) s+='z-index:'+this.zIndex+';';
			if(this.font) s+='font-family:'+this.font+';';
			if(this.border) s+='border:'+this.border+';';
			if(this.backgroundColor) s+='background-color:'+this.backgroundColor+';';
			if(this.textAlign) s+='text-align:'+this.textAlign+';';
			if(this.fontSize) s+='font-size:'+this.fontSize+this.scaleUnit+';';
			if(this.width) s+='width:'+this.width+this.scaleUnit+';';
			if(this.height) s+='height:'+this.height+this.scaleUnit+';';
			if(this.position) s+='position:'+this.position+';';
			if(this.textDecoration) s+='text-decoration:'+this.textDecoration+';';
			if(this.color) s+='color:'+this.color+';';
			if(this.top) s+='top:'+this.top+this.scaleUnit+';';
			if(this.left) s+='left:'+this.left+this.scaleUnit+';';
			if(this.right) s+='right:'+this.right+this.scaleUnit+';';
			if(this.bottom) s+='bottom:'+this.bottom+this.scaleUnit+';';
			if(this.cursor) s+='cursor:'+this.cursor+';';
			if(this.borderColor) s+='border-color:'+this.borderColor+';';
			var dbl = new RegExp(';;','gi');
			s = s.replace(dbl,'');
			return s;
		}
	},
	obj:function(prefix)
	{
		this.prefix = prefix;
		this.relativePath = '';
		this.speed = 10;
		this.step = 1.5;
		this.value = 0;
		this.id = false;
		this.content = {};
		this.core = {};
		this.core.content = {};
		this.core.up = {};
		this.core.down = {};
		this.container = false;
		
		
		this.onCheck = function(){};
		
		
		this.style = new scrollcontent.style;
		
		this.style.width = 80;
		this.style.height = 60;
		this.style.border = '1px solid #000000';
		this.style.overflow = 'hidden';
		
		this.content.style = new scrollcontent.style;
		this.content.style.float = 'left';
		this.content.style.overflow = 'hidden;width:85%;';
		this.content.obj = false;
		
		
		this.core.style = new scrollcontent.style;
		this.core.style.float = 'right';
		this.core.style.scaleUnit = '%';
		this.core.style.width = 15;
		this.core.style.height = 100;
		this.core.style.border = '';
		
		this.core.content.style = new scrollcontent.style;
		this.core.content.style.fontSize = 20;
		
		
		this.core.up.style = new scrollcontent.style;
		this.core.down.style = new scrollcontent.style;
		
		
		this.method = new Object();
		this.method.innerHTML = false;
		this.method.ADDinnerHTML = false;
		this.method.createElement = false;
		this.method.documentWrite = false;
		this.method.returnHTML = true;
		this.method.targetHTML = false;
		this.method.cssWritten = false;
		this.method.cssDomObj = false;
		this.method.cssContent = '';
		
		this.method.check = function()
		{
			if(this.innerHTML)
			{
				this.createElement = false;
				this.documentWrite = false;
				this.ADDinnerHTML = false;
			} else
			if(this.ADDinnerHTML)
			{
				this.innerHTML = false;
				this.documentWrite = false;
				this.createElement = false;
			} else
			if(this.createElement)
			{
				this.innerHTML = false;
				this.documentWrite = false;
				this.ADDinnerHTML = false;
			} else
			if(this.documentWrite)
			{
				this.innerHTML = false;
				this.createElement = false;
				this.ADDinnerHTML = false;
			}
		}
		this.method.writeHTML = function(html)
		{
			if(this.innerHTML)
			{
				var target = document.body;
				if(this.targetHTML)
				{
					var obj = document.getElementById(this.targetHTML);
					if(obj) target = obj;
				}
				target.innerHTML = html;
			} else
			if(this.ADDinnerHTML)
			{
				var target = document.body;
				if(this.targetHTML)
				{
					var obj = document.getElementById(this.targetHTML);
					if(obj) target = obj;
				}
				target.innerHTML+=html;
			} else
			if(this.createElement)
			{
				var div = document.createElement('DIV');
					document.body.appendChild(div);
					div.innerHTML = html;
			} else
			if(this.documentWrite)
			{
				document.write(html);
			} else 
			if(this.returnHTML) return html;
		}
		this.method.writeCSS = function(css)
		{
			if(this.cssWritten) return this.cssContent;
			if(this.innerHTML)
				document.body.innerHTML+= css;
			else if(this.documentWrite) document.write(css);	
			else if(this.returnHTML) {this.cssContent = css;return css;}
			this.cssWritten = true;
		}
		this.css = function()
		{
			var html = '<style type="text/css">';
					html+= '.scrollcontent_container {font-weight:normal;'+this.style.html()+'}';
					html+= '.scrollcontent_content {margin-top:20px;'+this.content.style.html()+'}';
					html+= '.scrollcontent_scroll {'+this.core.style.html()+'}';
					html+= '.scrollcontent_scrollcontent {'+this.core.content.style.html()+'}';
					html+= '.scrollcontent_up div {'+this.core.up.style.html()+'}';
					html+= '.scrollcontent_down div {'+this.core.down.style.html()+'}';
				html+= '</style>';
			return html;	
		}
		this.html = function()
		{
			var html = '<div class="scrollcontent_container" style="position:absolute;visibility:hidden;top:-13px;" id="container'+this.prefix+'">';
					html+= '<div class="scrollcontent_content" id="content'+this.prefix+'"><div>'+this.content.innerHTML+'</div></div>';
					html+= '<div class="scrollcontent_scroll" id="scroll'+this.prefix+'">';
						html+= '<table class="scrollcontent" id="scrollcontent'+this.prefix+'" cellpadding="0" cellspacing="0" border="0" style="width:100%;height:100%;">';
							html+= '<tr><td class="scrollcontent_up" style="cursor:pointer;background-image:url('+this.relativePath+'kernel/img/arrow-up.gif);background-repeat:no-repeat;background-position:50% 12%;background-color:#E5E5E5;border:2px solid #ffffff;border-bottom:0px;" align="center" id="up" valign="top"  onmouseover="scrollcontent.cache.'+this.prefix+'.down(this);" onmouseout="scrollcontent.cache.'+this.prefix+'.erase();">&nbsp;</td></tr>';
							html+= '<tr><td class="scrollcontent_down" style="cursor:pointer;background-image:url('+this.relativePath+'kernel/img/arrow-down.gif);background-repeat:no-repeat;background-position:50% 87%;background-color:#E5E5E5;border:2px solid #ffffff;border-top:0px;" align="center" id="down" valign="bottom" onmouseover="scrollcontent.cache.'+this.prefix+'.up(this);" onmouseout="scrollcontent.cache.'+this.prefix+'.erase();">&nbsp;</td></tr>';
						html+= '</table>';
					html+= '</div>';
				html+= '</div>';
			return html;
		}
		this.create = function()
		{
			this.method.check();
			this.method.writeCSS(this.css());
			var html = this.method.writeHTML(this.html());
			this.check();
			scrollcontent.cache[this.prefix] = this;
			return html;
		}
		this.check = function(html)
		{
			this.container = document.getElementById('container'+this.prefix);
			if(!this.container) return false;
			this.container.style.visibility = 'visible';
			
			this.content.obj = jsFirstChild(document.getElementById('content'+this.prefix));
			if(!this.content.obj) return false;		
			
			this.container.height = Number(this.container.offsetHeight);
			this.content.obj.height = Number(this.content.obj.offsetHeight);
			this.container.offset = Math.abs(this.content.obj.height - this.container.height);
			
			if(this.content.obj.height < this.container.height) document.getElementById('scroll'+this.prefix).style.display = 'none';
			 else this.container.parentNode.style.marginTop = '';
			this.content.obj.style.marginTop = this.value + 'px'; 
			
			this.erase(); 
			this.onCheck(this);
		}
		this.up = function(obj)
		{
			this.check();
			if(this.content.obj.height < this.container.height) return false;
			this.id = window.setInterval("scrollcontent.cache['"+this.prefix+"'].execute('up')",this.speed);
		}
		this.down = function(obj)
		{	
			this.check();
			if(this.content.obj.height < this.container.height) return false;
			this.id = window.setInterval("scrollcontent.cache['"+this.prefix+"'].execute('down')",this.speed);
		}
		this.execute = function(option)
		{
			if(option == 'up') 
			{
				if(Math.abs(this.value) >= (this.container.offset+20)){this.value = -(this.container.offset+20);this.erase();return false;};
				this.value=this.value-this.step;
			} else if(option == 'down')
			{	
				if(Number(this.content.obj.style.marginTop.split('px')[0]) >= 0){this.erase();return false;};
				this.value=this.value+this.step;
			}
			this.content.obj.style.marginTop = this.value + 'px';
		}
		this.erase = function(){if(this.id)window.clearInterval(this.id);}	
	}
}


function Now() {return new Date();}

// Global Constants
var JANUARY   = 0;
var FEBRUARY  = 1;
var MARCH     = 2;
var APRIL     = 3;
var MAY       = 4;
var JUNE      = 5;
var JULY      = 6;
var AUGUST    = 7;
var SEPTEMBER = 8;
var OCTOBER   = 9;
var NOVEMBER  = 10;
var DECEMBER  = 11;

var SUNDAY    = 0;
var MONDAY    = 1;
var TUESDAY   = 2;
var WEDNESDAY = 3;
var THURSDAY  = 4;
var FRIDAY    = 5;
var SATURDAY  = 6;

// Conversion factors as varants to eliminate all the multiplication
var SECONDS_CF     = 1000;
var MINUTES_CF     = 60000;          // 60 * 1000
var HOURS_CF       = 3600000;        // 60 * 60 * 1000
var DAYS_CF        = 86400000;       // 24 * 60 * 60 * 1000
var WEEKS_CF       = 604800000;      // 7 * 24 * 60 * 60 * 1000
var FORTNIGHTS_CF  = 1209600000;     // 14 * 24 * 60 * 60 * 1000
var MONTHS_CF      = 2592000000;     // 30 * 24 * 60 * 60 * 1000  (approx = 1 month)
var QUARTERS_CF    = 7776000000;     // 90 * 24 * 60 * 60 * 1000  (approx = 3 months)
var YEARS_CF       = 31557600000;    // 365 * 24 * 60 * 60 * 1000 (approx = 1 year)
var DECADES_CF     = 315576000000;   // 10 * 365 * 24 * 60 * 60 * 1000 (approx = 1 decade)
var CENTURIES_CF   = 3155760000000;  // 100 * 365 * 24 * 60 * 60 * 1000 (approx = 1 century)

// Non-destructive instance methods
Date.prototype.addMilliseconds = function(ms){  
  return new Date(new Date().setTime(this.getTime() + (ms)));  
}
Date.prototype.addSeconds = function(s){
  return this.addMilliseconds(s * SECONDS_CF);
}
Date.prototype.addMinutes = function(m){
  return this.addMilliseconds(m * MINUTES_CF);
}
Date.prototype.addHours = function(h){
  return this.addMilliseconds(h * HOURS_CF);
}
Date.prototype.addDays = function(d){
  return this.addMilliseconds(d * DAYS_CF);  
}
Date.prototype.addWeeks = function(w){
  return this.addMilliseconds(w * WEEKS_CF);  
}
Date.prototype.addFortnights = function(w){
  return this.addMilliseconds(w * FORTNIGHTS_CF);  
}
Date.prototype.addMonths = function(mm){
  return this.addMilliseconds(mm * MONTHS_CF);  
}
Date.prototype.addYears = function(yy){
  return this.addMilliseconds(yy * YEARS_CF);  
}
Date.prototype.subtractMilliseconds = function(ms){  
  return new Date(new Date().setTime(this.getTime() - (ms)));   
}
Date.prototype.subtractSeconds = function(s){
  return this.subtractMilliseconds(s * SECONDS_CF);
}
Date.prototype.subtractMinutes = function(m){
  return this.subtractMilliseconds(m * MINUTES_CF);
}
Date.prototype.subtractHours = function(h){
  return this.subtractMilliseconds(h * HOURS_CF);
}
Date.prototype.subtractDays = function(d){
  return this.subtractMilliseconds(d * DAYS_CF);  
}
Date.prototype.subtractWeeks = function(w){
  return this.subtractMilliseconds(w * WEEKS_CF);  
}
Date.prototype.subtractFortnights = function(w){
  return this.subtractMilliseconds(w * FORTNIGHTS_CF);  
}
Date.prototype.subtractMonths = function(mm){
  return this.subtractMilliseconds(mm * MONTHS_CF);  
}
Date.prototype.subtractYears = function(yy){
  return this.subtractMilliseconds(yy * YEARS_CF);  
}

// Destructive instance methods (change the value of the current Date object)
Date.prototype._addMilliseconds = function(ms){  
  this.setTime(this.getTime() + (ms));  
  return this;
}
Date.prototype._addSeconds = function(s){
  return this._addMilliseconds(s * SECONDS_CF);  
}
Date.prototype._addMinutes = function(m){
  return this._addMilliseconds(m * MINUTES_CF);
}
Date.prototype._addHours = function(h){
  return this._addMilliseconds(h * HOURS_CF);
}
Date.prototype._addDays = function(d){
  return this._addMilliseconds(d * DAYS_CF);  
}
Date.prototype._addWeeks = function(w){
  return this._addMilliseconds(w * WEEKS_CF);  
}
Date.prototype._addFortnights = function(w){
  return this._addMilliseconds(w * FORTNIGHTS_CF);  
}
Date.prototype._addMonths = function(mm){
  return this._addMilliseconds(mm * MONTHS_CF);  
}
Date.prototype._addYears = function(yy){
  return this._addMilliseconds(yy * YEARS_CF);  
}
Date.prototype._subtractMilliseconds = function(ms){  
  this.setTime(this.getTime() - (ms));  
  return this;
}
Date.prototype._subtractSeconds = function(s){
  return this._subtractMilliseconds(s * SECONDS_CF);
}
Date.prototype._subtractMinutes = function(m){
  return this._subtractMilliseconds(m * MINUTES_CF);
}
Date.prototype._subtractHours = function(h){
  return this._subtractMilliseconds(h * HOURS_CF);
}
Date.prototype._subtractDays = function(d){
  return this._subtractMilliseconds(d * DAYS_CF);  
}
Date.prototype._subtractWeeks = function(w){
  return this._subtractMilliseconds(w * WEEKS_CF);  
}
Date.prototype._subtractFortnights = function(w){
  return this._subtractMilliseconds(w * FORTNIGHTS_CF);  
}
Date.prototype._subtractMonths = function(mm){
  return this._subtractMilliseconds(mm * MONTHS_CF);  
}
Date.prototype._subtractYears = function(yy){
  return this._subtractMilliseconds(yy * YEARS_CF);  
}
Date.prototype.getMonthName = function() {
  var index = (0 == arguments.length) ? this.getMonth() : arguments[0];
  switch(index)
  {
    case JANUARY: 
      return "January";
    case FEBRUARY: 
      return "February";
    case MARCH: 
      return "March";
    case APRIL: 
      return "April";
    case MAY: 
      return "May";
    case JUNE: 
      return "June";
    case JULY: 
      return "July";
    case AUGUST: 
      return "August";
    case SEPTEMBER: 
      return "September";
    case OCTOBER: 
      return "October";
    case NOVEMBER: 
      return "November";
    case DECEMBER: 
      return "December";
    default:
      throw "Invalid month index: " + index.toString();
  }
}
Date.prototype.getMonthAbbreviation = function() {
  var index = (0 == arguments.length) ? this.getMonth() : arguments[0];
  switch(index)
  {
    case JANUARY: 
      return "Jan";
    case FEBRUARY: 
      return "Feb";
    case MARCH: 
      return "Mar";
    case APRIL: 
      return "Apr";
    case MAY: 
      return "May";
    case JUNE: 
      return "Jun";
    case JULY: 
      return "Jul";
    case AUGUST: 
      return "Aug";
    case SEPTEMBER: 
      return "Sep";
    case OCTOBER: 
      return "Oct";
    case NOVEMBER: 
      return "Nov";
    case DECEMBER: 
      return "Dec";
    default:
      throw "Invalid month index: " + index.toString();
  }
}
Date.prototype.getDayName = function() {
  var index = (0 == arguments.length) ? this.getDay() : arguments[0];
  switch(index)
  {
    case SUNDAY: 
      return "Sunday";
    case MONDAY: 
      return "Monday";
    case TUESDAY: 
      return "Tuesday";
    case WEDNESDAY: 
      return "Wednesday";
    case THURSDAY: 
      return "Thursday";
    case FRIDAY: 
      return "Friday";
    case SATURDAY: 
      return "Saturday";    
    default:
      throw "Invalid day index: " + index.toString();
  }
}
Date.prototype.getDayAbbreviation = function() {
  var index = (0 == arguments.length) ? this.getDay() : arguments[0];
  switch(index)
  {
    case SUNDAY: 
      return "Sun";
    case MONDAY: 
      return "Mon";
    case TUESDAY: 
      return "Tue";
    case WEDNESDAY: 
      return "Wed";
    case THURSDAY: 
      return "Thu";
    case FRIDAY: 
      return "Fri";
    case SATURDAY: 
      return "Sat";
    default:
      throw "Invalid day index: " + index.toString();
  }
}
Date.prototype.getCivilianHours = function() {
  return (this.getHours() < 12) ? this.getHours() : this.getHours() - 12;
}
Date.prototype.getMeridiem = function() {
  return (this.getHours() < 12) ? "AM" : "PM";
}
Date.prototype.to_s = Date.prototype.toString;


/* 
    Ultra-flexible date formatting

    %YYYY = 4 digit year         (2005)
    %YY   = 2 digit year         (05)
    %MMMM = Month name           (March)
    %MMM  = Month abbreviation   (March becomes Mar)
    %MM   = 2 digit month number (March becomes 03)
    %M    = 1 or 2 digit month   (March becomes 3)
    %DDDD = Day name             (Thursday)
    %DDD  = Day abbreviation     (Thu)
    %DD   = 2 digit day          (09) 
    %D    = 1 or 2 digit day     (9)
    %HH   = 2 digit 24 hour      (13)
    %H    = 1 or 2 digit 24 hour (9)
    %hh   = 2 digit 12 Hour      (01)
    %h    = 1 or 2 digit 12 Hour (01)
    %mm   = 2 digit minute       (02)
    %m    = 1 or 2 digit minute  (2)
    %ss   = 2 digit second       (59)
    %s    = 1 or 2 digit second  (1)
    %nnn  = milliseconds
    %p    = AM/PM indicator
*/
Date.prototype.format = function(fs) {

   fs = fs.replace(/%YYYY/, this.getFullYear().toString());
   fs = fs.replace(/%YY/, this.getFullYear().toString().substr(2,2));
   
   fs = fs.replace(/%MMMM/, this.getMonthName(this.getMonth()).toString());
   fs = fs.replace(/%MMM/, this.getMonthAbbreviation(this.getMonth()).toString());
   fs = fs.replace(/%MM/, (this.getMonth() + 1) > 9 ? (this.getMonth() + 1).toString() : "0" + (this.getMonth() + 1).toString());
   fs = fs.replace(/%M/, (this.getMonth() + 1).toString());
   
   fs = fs.replace(/%DDDD/, this.getDayName(this.getDay()).toString());
   fs = fs.replace(/%DDD/, this.getDayAbbreviation(this.getDay()).toString());
   fs = fs.replace(/%DD/, this.getDate() > 9 ? this.getDate().toString() : "0" + this.getDate().toString());
   fs = fs.replace(/%D/, this.getDate().toString());
   
   fs = fs.replace(/%HH/, this.getHours() > 9 ? this.getHours().toString() : "0" + this.getHours().toString());
   fs = fs.replace(/%H/, this.getHours().toString());
   fs = fs.replace(/%hh/, this.getCivilianHours() > 9 ? this.getCivilianHours().toString() : "0" + this.getCivilianHours().toString());
   fs = fs.replace(/%h/, this.getCivilianHours());

   fs = fs.replace(/%mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : "0" + this.getMinutes().toString());
   fs = fs.replace(/%m/, this.getMinutes().toString());

   fs = fs.replace(/%ss/, this.getSeconds() > 9 ? this.getSeconds().toString() : "0" + this.getSeconds().toString());
   fs = fs.replace(/%s/, this.getSeconds().toString());

   fs = fs.replace(/%nnn/, this.getMilliseconds().toString());
   fs = fs.replace(/%p/, this.getMeridiem());
   return fs;
}

Date.prototype.getDaysInMonth = function () {

  switch(this.getMonth())
  {
    case JANUARY:
      return 31;
    case FEBRUARY:
      return this.isLeapYear() ? 29 : 28;
    case MARCH:
      return 31;
    case APRIL:
      return 30;
    case MAY:
      return 31;
    case JUNE:
      return 30;
    case JULY:
      return 31;
    case AUGUST:
      return 31;
    case SEPTEMBER:
      return 30;
    case OCTOBER:
      return 31;
    case NOVEMBER:
      return 30;
    case DECEMBER:
      return 31;
  }
}

// Give toString more flexibility
Date.prototype.toString = function() {
  if (0 == arguments.length || 1 < arguments.length) return this.to_s();
  return this.format(arguments[0].toString());
} 

Date.prototype.isLeapYear = function() {
  if (0 == this.getFullYear() % 400) return true;
  if (0 == this.getFullYear() % 100) return false;
  return (0 == this.getFullYear() % 4) ? true : false;
}

Date.prototype.zeroTime = function() {
  var dt = this.clone();
  dt.setHours(0);
  dt.setMinutes(0);
  dt.setSeconds(0);
  dt.setMilliseconds(0);
  return dt;
}

Date.prototype.noon = function() {
  var dt = this.clone();
  dt.setHours(12);
  dt.setMinutes(0);
  dt.setSeconds(0);
  dt.setMilliseconds(0);
  return dt;
}

Date.prototype.firstDayOfMonth = function() {  
  return new Date(this.getFullYear(), this.getMonth(), 1, 12, 0, 0);
}
Date.prototype.lastDayOfMonth = function() {  
  return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth(), 12, 0, 0);
}

Date.prototype.clone = function() {
  var dt = new Date();
  dt.setTime(this.getTime());  
  return dt;
}

// Static methods
Date.yesterday = function()
{  
  return new Date().noon().subtractDays(1);
}
Date.today = function()
{  
  return new Date().noon();
}
Date.tomorrow = function()
{  
  return new Date().noon().addDays(1);
}
Date.lastWeek = function()
{  
  return new Date().noon().subtractWeeks(1);
}
Date.nextWeek = function()
{  
  return new Date().noon().addWeeks(1);
}
Date.lastMonth = function()
{  
  return new Date().noon().subtractMonths(1);
}
Date.nextFortnight = function()
{  
  return new Date().noon().addFortnights(1);
}
Date.lastFortnight = function()
{  
  return new Date().noon().subtractFortnights(1);
}
Date.nextMonth = function()
{   
  return new Date().noon().addMonths(1);
}
Date.lastYear = function()
{  
  return new Date().noon().subtractYears(1);
}
Date.nextYear = function()
{
  return new Date().noon().addYears(1);
}

// Number class instance methods (Rails-inspired)
Number.prototype.millisecondsFromNow = function() {
  return new Date().addMilliseconds(this);  
}
Number.prototype.millisecondFromNow = function() {
  return this.millisecondsFromNow();  
}
Number.prototype.secondsFromNow = function() {
  return new Date().addSeconds(this);  
}
Number.prototype.secondFromNow = function() {
  return this.secondsFromNow();  
}
Number.prototype.minutesFromNow = function() {
  return new Date().addMinutes(this);  
}
Number.prototype.minuteFromNow = function() {
  return this.minutesFromNow();  
}
Number.prototype.daysFromNow = function() {
  return new Date().addDays(this);  
}
Number.prototype.dayFromNow = function() {
  return this.daysFromNow();  
}
Number.prototype.weeksFromNow = function() {
  return new Date().addWeeks(this);  
}
Number.prototype.weekFromNow = function() {
  return this.weeksFromNow();  
}
Number.prototype.fortnightsFromNow = function() {
  return new Date().addFortnights(this);  
}
Number.prototype.fortnightFromNow = function() {
  return this.fortnightsFromNow();  
}
Number.prototype.monthsFromNow = function() {
  return new Date().addMonths(this);  
}
Number.prototype.monthFromNow = function() {
  return this.monthsFromNow();  
}
Number.prototype.yearsFromNow = function() {
  return new Date().addYears(this);  
}
Number.prototype.yearFromNow = function() {
  return this.yearsFromNow();  
}

Number.prototype.millisecondsAgo = function() {
  return new Date().subtractMilliSeconds(this);  
}
Number.prototype.millisecondAgo = function() {
  return this.millisecondsAgo();  
}
Number.prototype.secondsAgo = function() {
  return new Date().subtractSeconds(this);  
}
Number.prototype.secondAgo = function() {
  return this.secondsAgo();  
}
Number.prototype.minutesAgo = function() {
  return new Date().subtractMinutes(this);  
}
Number.prototype.minuteAgo = function() {
  return this.minutesAgo();  
}
Number.prototype.hoursAgo = function() {
  return new Date().subtractHours(this);  
}
Number.prototype.hourAgo = function() {
  return this.hoursAgo();  
}
Number.prototype.daysAgo = function() {
  return new Date().subtractDays(this);  
}
Number.prototype.dayAgo = function() {
  return this.daysAgo();  
}
Number.prototype.weeksAgo = function() {
  return new Date().subtractWeeks(this);  
}
Number.prototype.weekAgo = function() {
  return this.weeksAgo();  
}
Number.prototype.fortnightsAgo = function() {
  return new Date().subtractFortnights(this);  
}
Number.prototype.fortnightAgo = function() {
  return this.fortnightsAgo();  
}
Number.prototype.monthsAgo = function() {
  return new Date().subtractMonths(this);  
}
Number.prototype.monthAgo = function() {
  return this.monthsAgo();  
}
Number.prototype.yearsAgo = function() {
  return new Date().subtractYears(this);  
}
Number.prototype.yearAgo = function() {
  return this.yearsAgo();  
}

// TimeSpan class exposes helper methods 
// for rounding milliseconds to other granularities of time
// Note: These measurements are subject to subtle rounding errors!

// var d1 = (1).dayFromNow();
// var d2 = (10).daysFromNow(); 
// var ts = new TimeSpan(d2 - d1);
// assert(9 == ts.days);
// var ts2 = new TimeSpan(d1 - d2); // order doesn't matter!
// assert(9 == ts2.days); 

function TimeSpan(ms) {
  this.milliseconds = Math.abs(ms);
  this.seconds      = Math.round(this.milliseconds / SECONDS_CF);
  this.minutes      = Math.round(this.milliseconds / MINUTES_CF);
  this.hours        = Math.round(this.milliseconds / HOURS_CF);
  this.days         = Math.round(this.milliseconds / DAYS_CF);
  this.weeks        = Math.round(this.milliseconds / WEEKS_CF);  
  this.fortnights   = Math.round(this.milliseconds / FORTNIGHTS_CF);  
  this.months       = Math.round(this.milliseconds / MONTHS_CF);      // rounding errors!
  this.quarters     = Math.round(this.milliseconds / QUARTERS_CF);    // rounding errors!
  this.years        = Math.round(this.milliseconds / YEARS_CF);       // rounding errors!
  this.decades      = Math.round(this.milliseconds / DECADES_CF);     // rounding errors!  
  this.centuries    = Math.round(this.milliseconds / CENTURIES_CF);   // rounding errors!
}

TimeSpan.prototype.toString = function() {
  return this.milliseconds.toString();
}

var jscalendar = {};
	jscalendar.cache = new Array();
	jscalendar.style = function()
	{
		this.cssText = false;
		this.border = false;
		this.borderTop = false;
		this.borderBottom = false;
		this.borderLeft = false;
		this.borderRight = false;
		this.backgroundColor = false;
		this.backgroundImage = false;
		this.backgroundRepeat = false;
		this.backgroundPosition = false;
		this.textAlign = false;
		this.fontSize = false;
		this.font = false;
		this.width = false;
		this.height = false;
		this.position = false;
		this.textDecoration = false;
		this.color = false;
		this.top = false;
		this.left = false;
		this.right = false;
		this.bottom = false;
		this.cursor = false;
		this.zIndex = false;
		this.display = false;
		this.overflow = false;
		this.padding = false;
		this.paddingTop = false;
		this.paddingBottom = false;
		this.paddingLeft = false;
		this.paddingRight = false;
		this.margin = 0;
		this.marginTop = false;
		this.marginBottom = false;
		this.marginLeft = false;
		this.marginRight = false;
		this.listStyle = false;
		this.float = false;
		this.scaleUnit = 'px';
		this.html = function()
		{
			var s = '';
			if(this.cssText) s+=this.cssText;
			if(this.backgroundImage) s+='background-image:url('+this.backgroundImage+');';
			if(this.backgroundRepeat) s+='background-repeat:'+this.backgroundRepeat+';';
			if(this.backgroundPosition) s+='background-position:'+this.backgroundPosition+';';
			if(this.float) s+='float:'+this.float+';';
			if(this.listStyle) s+='list-style:'+this.listStyle+';';
			if(this.borderTop) s+='border-top:'+this.borderTop+';';
			if(this.borderBottom) s+='border-bottom:'+this.borderBottom+';';
			if(this.borderLeft) s+='border-left:'+this.borderLeft+';';
			if(this.borderRight) s+='border-right:'+this.borderRight+';';
			if(this.padding) s+='padding:'+this.padding+';';
			if(this.paddingTop) s+='padding-top:'+this.paddingTop+this.scaleUnit+';';
			if(this.paddingBottom) s+='padding-bottom:'+this.paddingBottom+this.scaleUnit+';';
			if(this.paddingLeft) s+='padding-left:'+this.paddingLeft+this.scaleUnit+';';
			if(this.paddingRight) s+='padding-right:'+this.paddingRight+this.scaleUnit+';';
			if(this.margin) s+='margin:'+this.margin+';';
			if(this.marginTop) s+='margin-top:'+this.marginTop+this.scaleUnit+';';
			if(this.marginBottom) s+='margin-bottom:'+this.marginBottom+this.scaleUnit+';';
			if(this.marginLeft) s+='margin-left:'+this.marginLeft+this.scaleUnit+';';
			if(this.marginRight) s+='margin-right:'+this.marginRight+this.scaleUnit+';';
			if(this.display) s+='display:'+this.display+';';
			if(this.overflow) s+='overflow:'+this.overflow+';';
			if(this.zIndex) s+='z-index:'+this.zIndex+';';
			if(this.font) s+='font-family:'+this.font+';';
			if(this.border) s+='border:'+this.border+';';
			if(this.backgroundColor) s+='background-color:'+this.backgroundColor+';';
			if(this.textAlign) s+='text-align:'+this.textAlign+';';
			if(this.fontSize) s+='font-size:'+this.fontSize+this.scaleUnit+';';
			if(this.width) s+='width:'+this.width+this.scaleUnit+';';
			if(this.height) s+='height:'+this.height+this.scaleUnit+';';
			if(this.position) s+='position:'+this.position+';';
			if(this.textDecoration) s+='text-decoration:'+this.textDecoration+';';
			if(this.color) s+='color:'+this.color+';';
			if(this.top) s+='top:'+this.top+this.scaleUnit+';';
			if(this.left) s+='left:'+this.left+this.scaleUnit+';';
			if(this.right) s+='right:'+this.right+this.scaleUnit+';';
			if(this.bottom) s+='bottom:'+this.bottom+this.scaleUnit+';';
			if(this.cursor) s+='cursor:'+this.cursor+';';
			var dbl = new RegExp(';;','gi');
			s = s.replace(dbl,'');
			return s;
		}
	}
	jscalendar.obj = function(prefix)
	{
		this.dia = 1;
		this.mes = 2;
		this.ano = 1970;
		this.highlight_day = false;
		
		this.dia_min = 1;
		this.mes_min = 1;
		this.ano_min = 1900;
		this.limit = false;

		this.mes_step = new Array(1,2,3);
		this.ano_step = new Array(1,2,5,10,50);
		
		this.time = false;
		this.diadasemana = false;

		this.name = '';
		this.prefix = prefix;
		this.relativePath = '';
		this.selectBoxObj = false;
		this.firstTimeCreated = true;
		this.browser = jscalendar.customSelectBox.browser();
		
		this.selectBoxMonth = {
					obj:this,
					div:function(mes,obj)
					{
						
						var domobj = document.getElementById(this.obj.prefix+'_selectBoxMonth_div');
						if(!domobj) obj.innerHTML+= '<div id="'+this.obj.prefix+'_selectBoxMonth_div" class="cssjscalendar_head_'+this.obj.prefix+'_mes_select"></div>';	// 
						
						//domobj = document.getElementById(this.obj.prefix+'_selectBoxMonth_div');
						var domobj = this.visibility();
						
						//domobj.style.visibility = 'visible';
						var yearbox = document.getElementById(this.obj.prefix+'_selectBoxYear_div');
						if(yearbox) yearbox.style.visibility = 'hidden';
						
						var html = '';
						
						var items = this.obj.languagecontent[this.obj.language];
					
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(1);"><div '+(this.obj.mes==1?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['1']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(2);"><div '+(this.obj.mes==2?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['2']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(3);"><div '+(this.obj.mes==3?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['3']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(4);"><div '+(this.obj.mes==4?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['4']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(5);"><div '+(this.obj.mes==5?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['5']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(6);"><div '+(this.obj.mes==6?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['6']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(7);"><div '+(this.obj.mes==7?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['7']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(8);"><div '+(this.obj.mes==8?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['8']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(9);"><div '+(this.obj.mes==9?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['9']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(10);"><div '+(this.obj.mes==10?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['10']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(11);"><div '+(this.obj.mes==11?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['11']+'</div></div>';
						html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxMonth.month(12);"><div '+(this.obj.mes==12?'class="cssjscalendar_head_'+this.obj.prefix+'_mes_select_middle"':'class="cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal" onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_mes_middle_normal\';"')+'">'+items['12']+'</div></div>';
						
						domobj.innerHTML = html;
						
						this.obj.onHeadFocus();
					},
					month:function(mes)
					{
						
						var domobj = document.getElementById(this.obj.prefix+'_selectBoxMonth_div');
							domobj.style.visibility = 'hidden';	
						this.obj.selectMonth(mes);
					},
					visibility:function()
					{
						var domobj = document.getElementById(this.obj.prefix+'_selectBoxMonth_div');
						if(!domobj) return false;
						var state = domobj.style.visibility;
						
						if(state == 'hidden' || state == '')
							domobj.style.visibility = 'visible';
							else domobj.style.visibility = 'hidden';
						return 	domobj;			
					},
					hide:function()
					{
						var domobj = document.getElementById(this.obj.prefix+'_selectBoxMonth_div');
						if(!domobj) return false;
						domobj.style.visibility = 'hidden';
					}
		}
		this.selectBoxYear = {
					obj:this,	
					get:function(index)
					{
						var a = new Array();
						while(value = this.obj.ano_step.next()){a.push(index+value);}
						a.reverse();
						a.push(index);
						var b = new Array();
						while(value = this.obj.ano_step.next()){b.push(index-value);}
						//b.reverse();
						return a.concat(b);
					},
					div:function(ano,obj)
					{
						var anos = this.get(ano);
						//var domobj = document.getElementById(this.obj.prefix+'_selectBoxYear_div');
						var domobj = this.visibility();
						
						if(!domobj)
						{
							obj.innerHTML+= '<div id="'+this.obj.prefix+'_selectBoxYear_div" class="cssjscalendar_head_'+this.obj.prefix+'_ano_select"></div>';
							domobj = document.getElementById(this.obj.prefix+'_selectBoxYear_div');
							this.visibility();
						}
						var monbox = document.getElementById(this.obj.prefix+'_selectBoxMonth_div');
						if(monbox) monbox.style.visibility = 'hidden';
						//this.visibility();
						
						var html = '',step = false,plus = this.obj.ano_step.copy(),minus = this.obj.ano_step.copy();
						plus.reverse();
						var arr = plus.concat('',minus),plus = '+';
						anos.internalCounter = 0;
						while(value = anos.next())
						{
							if(arr[anos.internalCounter-1] == '') plus = '-';
							step = plus+arr[anos.internalCounter-1];
							if(step == '-') step = '';
							html+= '<div onclick="jscalendar.cache[\''+this.obj.prefix+'\'].selectBoxYear.year('+value+');"><div '+(value==this.obj.ano?'class="cssjscalendar_head_'+this.obj.prefix+'_ano_select_middle cssjscalendar_head_'+this.obj.prefix+'_ano_select_div"':'class="cssjscalendar_head_'+this.obj.prefix+'_ano_select_div"  onmouseover="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_ano_middle_hover\';" onmouseout="this.className = \'cssjscalendar_head_'+this.obj.prefix+'_ano_middle_normal\';"')+'><span id="step">'+step+'</span>&nbsp;<span id="value">'+value+'</span></div></div>';
						}
						domobj.innerHTML = html;
						this.obj.onHeadFocus();
					},
					year:function(ano)
					{
						var domobj = document.getElementById(this.obj.prefix+'_selectBoxYear_div');
							domobj.style.visibility = 'hidden';
						this.obj.selectYear(ano);
					},
					visibility:function()
					{
						var domobj = document.getElementById(this.obj.prefix+'_selectBoxYear_div');
						if(!domobj) return false;
						
						var state = domobj.style.visibility;
						if(state == 'hidden' || state == '')
							domobj.style.visibility = 'visible';
							else domobj.style.visibility = 'hidden';
			
						return domobj;			
					},
					hide:function()
					{
						var domobj = document.getElementById(this.obj.prefix+'_selectBoxYear_div');
						if(!domobj) return false;
						domobj.style.visibility = 'hidden';
					}
		}
		
		this.onReady = function(){};
		this.onSelectDay = function(){};
		this.onSelectMonth = function(){};
		
		this.onHeadFocus = function(){};
		
		this.onSelectYear = function(){};
		this.onCreate = function(){};
		this.onUpdate = function(){};
		this.onInternalEvent = function(){};
		this.onChange = function(){};
		this.onRightClick = function(){};
		this.onQuery = function(){};
		
		this.createTriggered = false;
		this.selectDayTriggered = false;
		this.selectMonthTriggered = false;
		this.selectYearTriggered = false;
		this.readyTriggered = false;
		this.updateTriggered = false;
		this.changeTriggered = false;
		this.mouseOverTriggered = true;
		
		this.nextEvent = true;
		this.previousEvent = true;
		
		this.closeOnSelect = false;
		
		this.mode = {
			'selectBox':true,
			'standAlone':false
		}
		
		this.method = new Object();
		this.method.innerHTML = false;
		this.method.ADDinnerHTML = false;
		this.method.createElement = false;
		this.method.documentWrite = true;
		this.method.targetHTML = false;
		this.method.cssWritten = false;
		
		this.method.check = function()
		{
			if(this.innerHTML)
			{
				this.createElement = false;
				this.documentWrite = false;
				this.ADDinnerHTML = false;
			} else
			if(this.ADDinnerHTML)
			{
				this.innerHTML = false;
				this.documentWrite = false;
				this.createElement = false;
			} else
			if(this.createElement)
			{
				this.innerHTML = false;
				this.documentWrite = false;
				this.ADDinnerHTML = false;
			} else
			if(this.documentWrite)
			{
				this.innerHTML = false;
				this.createElement = false;
				this.ADDinnerHTML = false;
			}
		}
		this.method.writeHTML = function(html)
		{
			if(this.innerHTML)
			{
				var target = document.body;
				if(this.targetHTML)
				{
					var obj = document.getElementById(this.targetHTML);
					if(obj) target = obj;
				}
				target.innerHTML = html;
			} else
			if(this.ADDinnerHTML)
			{
				var target = document.body;
				if(this.targetHTML)
				{
					var obj = document.getElementById(this.targetHTML);
					if(obj) target = obj;
				}
				target.innerHTML+=html;
			} else
			if(this.createElement)
			{
				var div = document.createElement('DIV');
					document.body.appendChild(div);
					div.innerHTML = html;
			} else
			if(this.documentWrite)
			{
				document.write(html);
			}
		}
		this.method.writeCSS = function(css)
		{
			if(this.cssWritten) return false;
			if(this.innerHTML)
				document.body.innerHTML+= css;
			else if(this.documentWrite) document.write(css);	
			this.cssWritten = true;
		}
		
		this.dateformat = 'd / M / Y';
		
		this.language = 'pt';
		this.languagecontent = {
			'pt':{
					'Sun':'Dom',
					'Mon':'Seg',
					'Tue':'Ter',
					'Wed':'Qua',
					'Thu':'Qui',
					'Fri':'Sex',
					'Sat':'Sab',
					
					'sunday':'dom',
					'monday':'seg',
					'tuesday':'ter',
					'wednesday':'qua',
					'thursday':'qui',
					'friday':'sex',
					'saturday':'sab',
					'Jan':'Jan',
					'Feb':'Fev',
					'Mar':'Mar',
					'Apr':'Abr',
					'May':'Mai',
					'Jun':'Jun',
					'Jul':'Jul',
					'Aug':'Aug',
					'Sep':'Set',
					'Oct':'Out',
					'Nov':'Nov',
					'Dec':'Dez',
					
					'1':'Janeiro',
					'2':'Fevereiro',
					'3':'Março',
					'4':'Abril',
					'5':'Maio',
					'6':'Junho',
					'7':'Julho',
					'8':'Agosto',
					'9':'Setembro',
					'10':'Outubro',
					'11':'Novembro',
					'12':'Dezembro',
					
					
					'January':'Janeiro',
					'February':'Fevereiro',
					'March':'Março',
					'April':'Abril',
					'May':'Maio',
					'June':'Junho',
					'July':'Julho',
					'August':'Agosto',
					'September':'Setembro',
					'October':'Outubro',
					'November':'Novembro',
					'December':'Dezembro'
				},
			'en':{
					'Sun':'Sun',
					'Mon':'Mon',
					'Tue':'Tue',
					'Wed':'Wed',
					'Thu':'Thu',
					'Fri':'Fri',
					'Sat':'Sat',
					
					'sunday':'sun',
					'monday':'mod',
					'tuesday':'tue',
					'wednesday':'wed',
					'thursday':'thu',
					'friday':'fri',
					'saturday':'sat',
					'Jan':'Jan',
					'Feb':'Fev',
					'Mar':'Mar',
					'Apr':'Apr',
					'May':'May',
					'Jun':'Jun',
					'Jul':'Jul',
					'Aug':'Aug',
					'Sep':'Sep',
					'Oct':'Oct',
					'Nov':'Nov',
					'Dec':'Dec',
					
					'1':'January',
					'2':'February',
					'3':'March',
					'4':'April',
					'5':'May',
					'6':'June',
					'7':'July',
					'8':'August',
					'9':'September',
					'10':'October',
					'11':'November',
					'12':'December',
					
					
					'January':'January',
					'February':'February',
					'March':'March',
					'April':'April',
					'May':'May',
					'June':'June',
					'July':'July',
					'August':'August',
					'September':'September',
					'October':'October',
					'November':'November',
					'December':'December'
				}	
		}
		
		this.style = new jscalendar.style();
	//	this.style.scaleUnit = '%';
	//	this.style.width = '0';
		
		this.table = {style:new jscalendar.style()};
		this.head = {
			style:new jscalendar.style(),
			mes:{style:new jscalendar.style()},
			ano:{style:new jscalendar.style()},
			anterior:{style:new jscalendar.style()},
			anterior_hover:{style:new jscalendar.style()},
			seguinte:{style:new jscalendar.style()},
			seguinte_hover:{style:new jscalendar.style()},
			semana:{
				style:new jscalendar.style(),
				div:{style:new jscalendar.style()}
			},
			mes_select:{
					style:new jscalendar.style(),
					normal:{style:new jscalendar.style()},
					middle:{style:new jscalendar.style()},
					step:{style:new jscalendar.style()},
					value:{style:new jscalendar.style()},
					hover:{style:new jscalendar.style()}
			},
			ano_select:{
					style:new jscalendar.style(),
					normal:{style:new jscalendar.style()},
					middle:{style:new jscalendar.style()},
					step:{style:new jscalendar.style()},
					value:{style:new jscalendar.style()},
					hover:{style:new jscalendar.style()}
			},
			validate:{
					style:new jscalendar.style(),
					dia:{style:new jscalendar.style()},
					mes:{style:new jscalendar.style()},
					ano:{style:new jscalendar.style()}
			}
		}
		this.content = {
			style:new jscalendar.style(),
			parent:this,
			normal:{style:new jscalendar.style()},
			anterior:{style:new jscalendar.style()},
			hightlight:{style:new jscalendar.style()},
			negado:{style:new jscalendar.style()},
			static:{style:new jscalendar.style()},  //qd passas o rato por cima de cada dia
			hover:{style:new jscalendar.style()},	// qd sais do dia
			dia:{
					style:new jscalendar.style(),
					topLeft:{style:new jscalendar.style()},
					topRight:{style:new jscalendar.style()},
					bottom:{style:new jscalendar.style()},
					numero:{style:new jscalendar.style()},
					hover:{style:new jscalendar.style()},
					div:{style:new jscalendar.style()}
			},
			data:new Array(1),
			datafunctions:new Array(1),
			datacontent:new Array(1),
			add:function(index,css,scss,position)
			{
				if(!position) position = 'left';
				var index = new Date(Number(index[2]),Number(index[1])-1,Number(index[0]));
				this.data[index] = {css:css,position:position,secondcss:scss};
			},
			edit:function(index,css,scss,position)
			{
				var index = new Date(Number(index[2]),Number(index[1])-1,Number(index[0]));
				this.data[index] = {css:css,position:position,secondcss:scss};
			},
			remove:function(index)
			{
				var index = new Date(Number(index[2]),Number(index[1])-1,Number(index[0]));			
				this.data.splice(index,1);
			},
			addfunction:function(index,str,events)
			{
				if(!events) events = 'onclick';
				var obj = {
					eventTrigger:events,
					obj:this.parent,
					str:str
				}
				var index = new Date(Number(index[2]),Number(index[1])-1,Number(index[0]));
				this.datafunctions[index] = obj;
			},
			addcontent:function(index,html)
			{
				var index = new Date(Number(index[2]),Number(index[1])-1,Number(index[0]));
				this.datacontent[index] = html;
			}
		}
		this.hightlight = {
			normal:[],
			hover:[],
			active:[],
			obj:function()
			{
				this.id = '';
				this.style = '';
				this.className = '';
				
				this.normal = false;
				this.active = false;
				this.hover = false;
				
				this.domobj = false;
				this.classString = '';
				
				this.render = function()
				{
					var a = this.normal?this.normal:'';
					var b = this.active?this.active:'';
					var c = this.hover?this.hover:'';
					this.domobj.className = a+' '+b+' '+c;
					this.classString = this.domobj.className;
				}
				this.decode = function()
				{
					var str = this.domobj.className.split(' ');
					this.normal = str[0]?str[0]:false;
					this.active = str[1]?str[1]:false;
					this.hover = str[2]?str[2]:false;
				}
			}
		}
		
		this.head.mes.style.cssText = 'font-size:11px;text-align:left;cursor:pointer;';
		this.head.ano.style.cssText = 'font-size:11px;text-align:right;cursor:pointer;';
		//this.head.semana.style.cssText = 'font-size:9px;font-family:arial;margin:0px;text-align:center;width:10px;';

		this.head.mes_select.style.cssText = 'z-index:100;position:absolute;width:50px;background-color:#ffffff;border:1px solid #000000;padding:2px;text-align:right;margin-left:-2px;';
		this.head.ano_select.style.cssText = 'z-index:100;position:absolute;width:50px;background-color:#ffffff;border:1px solid #000000;padding:2px;text-align:right;';
		
		this.head.mes_select.middle.style.cssText = 'background-color:#00CCFF;';
		this.head.ano_select.middle.style.cssText = 'background-color:#00CCFF;';
		
		this.head.ano_select.step.style.cssText = 'font-size:11px;';
		this.head.ano_select.value.style.cssText = '';
		this.head.ano_select.normal.style.cssText = 'text-decoration:none;cursor:pointer;color:#000000;';
		this.head.ano_select.hover.style.cssText = 'text-decoration:none;cursor:pointer;background-color:#c9c9c9;';
		
		this.head.mes_select.step.style.cssText = 'font-size:11px;';
		this.head.mes_select.value.style.cssText = '';
		this.head.mes_select.normal.style.cssText = 'text-decoration:none;cursor:pointer;width:60px;color:#000000;';
		this.head.mes_select.hover.style.cssText = 'text-decoration:none;cursor:pointer;background-color:#c9c9c9;';
	
		this.head.validate.style.cssText = '';
		this.head.validate.dia.style.cssText = 'text-align:center;width:20px;border:0px;margin:0px;padding:0px;font-size:9px;';
		this.head.validate.mes.style.cssText = 'text-align:center;width:20px;border:0px;margin:0px;padding:0px;font-size:9px;';
		this.head.validate.ano.style.cssText = 'text-align:center;width:33px;border:0px;margin:0px;padding:0px;font-size:9px;';
		
		this.content.normal.style.cssText = 'font-size:12px;color:#000000;text-decoration:none;';		
		this.content.hightlight.style.cssText = 'font-weight:bold;background-color:#ffffff;font-size:12px;color:#ff0000;text-decoration:none;text-align:center;cursor:pointer;';
		this.content.negado.style.cssText = 'background-color:#c9c9c9;';
		
		
		this.getRelativePath = function(script)
		{
			var scripts = document.getElementsByTagName('SCRIPT');
			if(!scripts) return false;
			var regexp = new RegExp(script,"gi");
			for(var i = 0; i<scripts.length; i++)
			{
				if(String(scripts.item(i).src).match(regexp))
					this.relativePath = scripts.item(i).src.replace(regexp,'');
			}
		}
		this.create = function()
		{
			
			if(this.relativePath == '') this.getRelativePath('jscalendar.js');
			this.method.check();
			
			this.head.anterior.style.cssText = 'cursor:pointer;background-image:url('+this.relativePath+'img/tras.gif);background-repeat:no-repeat;background-position:20% 50%;height:15px;';
			this.head.seguinte.style.cssText = 'cursor:pointer;background-image:url('+this.relativePath+'img/frente.gif);background-repeat:no-repeat;background-position:80% 50%;height:15px;';
			this.head.anterior_hover.style.cssText = 'cursor:pointer;background-image:url('+this.relativePath+'img/tras_over.gif);background-repeat:no-repeat;background-position:20% 50%;height:15px;';
			this.head.seguinte_hover.style.cssText = 'cursor:pointer;background-image:url('+this.relativePath+'img/frente_over.gif);background-repeat:no-repeat;background-position:80% 50%;height:15px;';
			
			if(this.mode.selectBox)
			{
				this.head.style.cssText = 'text-align:center;';
				this.selectBoxObj = new jscalendar.customSelectBox.obj(this.prefix+'_selectbox');
				this.selectBoxObj.relativePath = this.relativePath;
				this.selectBoxObj.domobj = this;
				this.selectBoxObj.name = 'selectbox'; 
				this.selectBoxObj.head.style.width = 81;
				this.selectBoxObj.head.style.textAlign = 'center';
				this.selectBoxObj.content.style.backgroundColor = '#ffffff';
				this.selectBoxObj.head.style.cssText = this.head.style.cssText;
	
				this.selectBoxObj.method.innerHTML = this.method.innerHTML;
				this.selectBoxObj.method.createElement = this.method.createElement;
				this.selectBoxObj.method.documentWrite = this.method.documentWrite;
				
				this.selectBoxObj.create();
			}
			
			var html = '<div id="'+this.prefix+'_jscalendar" style="'+this.style.html()+'"></div>';
			
			this.method.writeCSS(this.generateStyleContent());
			this.method.writeHTML(html);
				
			jscalendar.cache[this.prefix] = this;
			this.createTriggered = true;
			this.time = new Date(this.ano,this.mes-1,1);			
			this.highlight_day = new Date(this.ano,this.mes-1,this.dia);
			this.limit = new Date(this.ano_min,this.mes_min-1,this.dia_min+1);

			
			this.query();
			return html;
		}
		this.refresh = function()
		{
			this.time = new Date(this.ano,this.mes-1,1);			
			this.highlight_day = new Date(this.ano,this.mes-1,this.dia);
			this.limit = new Date(this.ano_min,this.mes_min-1,this.dia_min+1);
			this.updateTriggered = true;
			this.createTriggered = false;
			this.changeTriggered = false;
			this.query();	
		}
		this.close = function()
		{
			if(this.mode.selectBox) this.selectBoxObj.visibility(this.selectBoxObj.prefix);
		}
		this.generateStyleContent = function()
		{
			var browser = jscalendar.browser();
			
			var html = '<style type="text/css">';
				html+= '.cssjscalendar_'+this.prefix+'_main {'+this.style.html()+'}';
			
				html+= '.cssjscalendar_'+this.prefix+'_table {'+this.table.style.html()+'}';
				
				html+= '.cssjscalendar_'+this.prefix+'_head_tr_semana {}';
				html+= '.cssjscalendar_'+this.prefix+'_head_tr_semana td {'+this.head.semana.style.html()+'}';
				
				html+= '.cssjscalendar_'+this.prefix+'_head_td_mes {'+this.head.mes.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_head_td_ano {'+this.head.ano.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_head_td_mes_hover {'+this.head.mes.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_head_td_ano_hover {'+this.head.ano.style.html()+'}';
				
				html+= '.cssjscalendar_'+this.prefix+'_head_td_div {'+this.head.semana.div.style.html()+'}';
											
				html+= '.cssjscalendar_'+this.prefix+'_content_td_normal {'+this.content.normal.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_content_td_previous {'+this.content.anterior.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_content_td_hightlight {'+this.content.hightlight.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_content_td_denied {'+this.content.negado.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_content_td_vazio {font-size:1px;margin:0px;padding:0px;}';
				
				html+= '.cssjscalendar_'+this.prefix+'_content_td_a '+(browser=='IE'?'':'div')+' {}';
				
				html+= '.cssjscalendar_'+this.prefix+'_content_td_div {margin:1px;'+this.content.dia.style.html()+'}';
				
				html+= '.cssjscalendar_'+this.prefix+'_content_td_diva {'+this.content.dia.topLeft.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_content_td_divb {'+this.content.dia.topRight.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_content_td_divc {'+this.content.dia.numero.style.html()+'}';
				html+= '.cssjscalendar_'+this.prefix+'_content_td_divd {'+this.content.dia.bottom.style.html()+'}';
				
				html+= '.cssjscalendar_'+this.prefix+'_content_td_a_hover div#daynumber {'+this.content.dia.hover.style.html()+'}';
				
			
				for(var i=0;i<this.content.data.length;i++)
				{
					if(this.content.data[i])html+= '.cssjscalendar_'+this.prefix+'_content_td_'+this.content.dataindex[i]+' div#cssjscalendar_'+this.content.data[i].position+' {'+this.content.data[i].css+'}';
				}	
				
				html+= '.cssjscalendar_head_'+this.prefix+'_mesanterior {}';
				html+= '.cssjscalendar_head_'+this.prefix+'_messeguinte {}';
				html+= '.cssjscalendar_head_'+this.prefix+'_mesanterior_div {'+this.head.anterior.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_messeguinte_div {'+this.head.seguinte.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_mesanterior_div_hover {'+this.head.anterior_hover.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_messeguinte_div_hover {'+this.head.seguinte_hover.style.html()+'}';

				html+= '.cssjscalendar_head_'+this.prefix+'_mes_select {'+this.head.mes_select.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_mes_select_middle {'+this.head.mes_select.middle.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_ano_select {'+this.head.ano_select.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_ano_select_middle {'+this.head.ano_select.middle.style.html()+'}';

				html+= '.cssjscalendar_head_'+this.prefix+'_ano_select_div span#step {'+this.head.ano_select.step.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_ano_select_div span#value {'+this.head.ano_select.value.style.html()+'}';
			
				
				//html+= 'a#'+this.prefix+'_mes_select {}';
				html+= '.cssjscalendar_head_'+this.prefix+'_mes_middle_normal {'+this.head.ano_select.normal.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_mes_middle_hover {'+this.head.mes_select.hover.style.html()+'}';
				
				//html+= 'a#'+this.prefix+'_ano_select {}';
				html+= '.cssjscalendar_head_'+this.prefix+'_ano_middle_normal {'+this.head.ano_select.normal.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_ano_middle_hover {'+this.head.ano_select.hover.style.html()+'}';
				
				
				html+= '.cssjscalendar_head_'+this.prefix+'_validate {'+this.head.validate.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_validate_dia {'+this.head.validate.dia.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_validate_mes {'+this.head.validate.mes.style.html()+'}';
				html+= '.cssjscalendar_head_'+this.prefix+'_validate_ano {'+this.head.validate.ano.style.html()+'}';
				
				html+= '</style>';
					
			return html;
		}
		this.previous = function()
		{
			if(!this.previousEvent) return false;
			this.time = this.time.subtractDays(this.time.subtractDays(1).getDaysInMonth());
			this.selectMonthTriggered = true;
			this.selectDayTriggered = false;
			this.updateTriggered = false;
			this.changeTriggered = true;
			this.query();
			var daysinmonth = parseInt(this.time.getDaysInMonth());
			this.selectday(this.dia>daysinmonth?daysinmonth:this.dia);
		}
		this.next = function()
		{	
			if(!this.nextEvent) return false;
			var days = this.time.getDaysInMonth();
			this.time = this.time.addDays(days+1);
			this.selectMonthTriggered = true;
			this.selectDayTriggered = false;
			this.updateTriggered = false;
			this.changeTriggered = true;
			this.query();
			var daysinmonth = parseInt(this.time.getDaysInMonth());
			this.selectday(this.dia>daysinmonth?daysinmonth:this.dia);
		}
		this.selectday = function(dia,obj)
		{
			this.dia = dia;
			if(this.mode.selectBox)
			{
				this.selectBoxObj.valueText = this.parseDate();
				this.selectBoxObj.showOnTop();
			}
			this.highlight_day = dia;
			this.query();
		}
		this.selectMonth = function(mes)
		{
			this.time = new Date(mes+'/1/'+this.ano);	
			this.updateTriggered = false;
			this.selectDayTriggered = false;
			this.selectMonthTriggered = false;
			this.changeTriggered = true;
			this.query();
			var daysinmonth = parseInt(this.time.getDaysInMonth());
			this.selectday(this.dia>daysinmonth?daysinmonth:this.dia);
		}
		this.selectYear = function(ano)
		{
			this.time = new Date(this.mes+'/1/'+ano);	
			this.updateTriggered = false;
			this.selectDayTriggered = false;
			this.selectMonthTriggered = false;
			this.changeTriggered = true;
			this.query();
			var daysinmonth = parseInt(this.time.getDaysInMonth());
			this.selectday(this.dia>daysinmonth?daysinmonth:this.dia);
		}
		this.eventMouseOverTrigger = function(dia,func)
		{	
			if(!this.mouseOverTriggered) return false;
			this.onInternalEvent = func;
			this.updateTriggered = false;
			this.mouseOverTriggered = false;
			this.query();
		}
		this.daysofweek = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
		
		this.rightClickTriggered = function(e)
		{
			if(!e) e = window.event;
			
			if(e.button == 2)
			{
				this.onRightClick(this);
			} else this.onSelectDay(this);	
		}																
		this.query = function()
		{	
			var daysinmonth = parseInt(this.time.getDaysInMonth());
			var firstday = this.time.firstDayOfMonth();
			var diadasemana = firstday.format('%DDD');
			this.ano = this.time.format('%YYYY');
			this.mes = this.time.format('%MM');
			var mes_nome = this.time.format('%MMMM');
			var weekday = new Date(this.ano,this.mes,this.dia);
			this.diadasemana = weekday.getDay();
			
			var html = '<table border="0" align="center" cellspacing="0" cellpadding="0" class="cssjscalendar_'+this.prefix+'_table">';
				html+= '<tr>';
					html+= '<td><a class="cssjscalendar_head_'+this.prefix+'_mesanterior" onclick="jscalendar.cache.'+this.prefix+'.previous()"><div class="cssjscalendar_head_'+this.prefix+'_mesanterior_div" onmouseout="jscalendar.cache.'+this.prefix+'.swapLeftArrow(this);" onmouseover="jscalendar.cache.'+this.prefix+'.swapLeftArrowOver(this);"></div></a></td>';
					html+= '<td colspan="5"><table border="0" width="100%" cellspacing="0"><tr><td class="cssjscalendar_'+this.prefix+'_head_td_mes" onclick="jscalendar.cache.'+this.prefix+'.selectBoxMonth.div('+this.mes+',this);">'+(this.languagecontent[this.language][mes_nome])+'</td><td class="cssjscalendar_'+this.prefix+'_head_td_ano" onclick="jscalendar.cache.'+this.prefix+'.selectBoxYear.div('+this.ano+',this);">'+this.ano+'</td></tr></table></td>';
					html+= '<td><a class="cssjscalendar_head_'+this.prefix+'_messeguinte" onclick="jscalendar.cache.'+this.prefix+'.next()"><div class="cssjscalendar_head_'+this.prefix+'_messeguinte_div" onmouseout="jscalendar.cache.'+this.prefix+'.swapRightArrow(this);" onmouseover="jscalendar.cache.'+this.prefix+'.swapRightArrowOver(this);"></div></a></td>';
				html+= '</tr>';
				html+= '<tr class="cssjscalendar_'+this.prefix+'_head_tr_semana">';
					html+= '<td class="cssjscalendar_'+this.prefix+'_head_td_domingo"><div class="cssjscalendar_'+this.prefix+'_head_td_div">'+(this.languagecontent[this.language][this.daysofweek[0]])+'</div></td>';
					html+= '<td class="cssjscalendar_'+this.prefix+'_head_td_segunda"><div class="cssjscalendar_'+this.prefix+'_head_td_div">'+(this.languagecontent[this.language][this.daysofweek[1]])+'</div></td>';
					html+= '<td class="cssjscalendar_'+this.prefix+'_head_td_terca"><div class="cssjscalendar_'+this.prefix+'_head_td_div">'+(this.languagecontent[this.language][this.daysofweek[2]])+'</div></td>';
					html+= '<td class="cssjscalendar_'+this.prefix+'_head_td_quarta"><div class="cssjscalendar_'+this.prefix+'_head_td_div">'+(this.languagecontent[this.language][this.daysofweek[3]])+'</div></td>';
					html+= '<td class="cssjscalendar_'+this.prefix+'_head_td_quinta"><div class="cssjscalendar_'+this.prefix+'_head_td_div">'+(this.languagecontent[this.language][this.daysofweek[4]])+'</div></td>';
					html+= '<td class="cssjscalendar_'+this.prefix+'_head_td_sexta"><div class="cssjscalendar_'+this.prefix+'_head_td_div">'+(this.languagecontent[this.language][this.daysofweek[5]])+'</div></td>';
					html+= '<td class="cssjscalendar_'+this.prefix+'_head_td_sabado"><div class="cssjscalendar_'+this.prefix+'_head_td_div">'+(this.languagecontent[this.language][this.daysofweek[6]])+'</div></td>';
				html+= '</tr>';
				html+= '<tr>';
			
			var theday = parseInt(this.daysofweek.indexOf(diadasemana));
			
			for(var i = 0;i < theday;i++){html+= '<td class="cssjscalendar_'+this.prefix+'_content_td_vazio"></td>';}
			var css = '',secondcss= '';
			
			var content  = this.content.datacontent[time]?this.content.datacontent[time]:'';
			
			for(var i = 1;i <= daysinmonth;i++)
			{
				
				var selecionado = '';				
				var time = new Date(this.ano,this.mes-1,i);
				
				//console.log(time.getTimeZoneOffset());
				var current = new Date(this.ano,this.mes-1,this.dia);
				if(String(time) == String(current)){selecionado = 'cssjscalendar_'+this.prefix+'_content_td_hightlight';}
				f_time = time.getFullYear()+'-'+time.getMonth()+'-'+time.getDate();
				
				if(this.content.data[f_time])
				{
					secondcss = this.content.data[f_time].secondcss;
					css = this.content.data[f_time].css;
				} else {
					
					secondcss = '';
					css = '';
					
				}
				if(this.limit>time.getTime())
				{
					secondcss = '';
					css = this.content.negado.style.html();
				}
			

				html+= '<td align="center" onmousedown="javascript:jscalendar.cache.'+this.prefix+'.selectday('+i+',this);jscalendar.cache.'+this.prefix+'.Internalonclick(\''+time+'\');jscalendar.cache.'+this.prefix+'.rightClickTriggered(event);"  onmouseout="javascript:jscalendar.cache.'+this.prefix+'.mouseOverTriggered = true;jscalendar.cache.'+this.prefix+'.swapContent(this);" onmouseover="javascript:jscalendar.cache.'+this.prefix+'.swapContentOver(this);" class="none none none">';
				html+= '<div class="cssjscalendar_'+this.prefix+'_content_td_div " onmouseover="jscalendar.cache.'+this.prefix+'.Internalonmouseover(\''+time+'\');" onmouseout="jscalendar.cache.'+this.prefix+'.Internalonmouseout(\''+time+'\');"><div id="daynumber" style="height:100%;'+css+'"><div class="'+selecionado+'" style="'+this.content.dia.div.style.html()+secondcss+'">'+i+'</div><div style="position:absolute;margin-left:3px;font-weight:normal;">'+content+'</div></div></div>';
				html+= '</td>';
				if (theday == 6){html+= '</tr><tr>';theday = -1;}
				theday++;
			}
			
			var left = 7 - theday;
			for(var i = 0;i < left;i++){html+= '<td class="cssjscalendar_'+this.prefix+'_content_td_vazio"></td>';} 
			html+= '</tr></table>';
		
			
			var obj = document.getElementById('jscalendar_'+this.prefix+'_selectbox_dynamictable');
			if(obj) obj.innerHTML = html; 
			
			if(this.mode.selectBox)
			{
				this.selectBoxObj.onDropStart = function(selectbox)
				{
					var div = document.createElement('DIV');
						document.body.appendChild(div);
						div.innerHTML = '<div id="jscalendar_'+selectbox.prefix+'_dynamictable">'+html+'</div>';
						div.id = selectbox.prefix+'asdasdasdasd123';
						selectbox.data.content.pop();
						selectbox.addanddelete(selectbox.prefix+'asdasdasdasd123');
				}
				this.selectBoxObj.onDropEnd = function(){for(i in scrollcontent.cache){scrollcontent.cache[i].check();};}
				this.selectBoxObj.valueText = this.parseDate();
				this.selectBoxObj.showOnTop();
			} else {
				var obj = document.getElementById('jscalendar_'+this.prefix+'_dynamictable');
				if(obj) obj.innerHTML = html; 
					else this.method.writeHTML('<div id="jscalendar_'+this.prefix+'_dynamictable" class="cssjscalendar_'+this.prefix+'_main">'+html+'</div>');
			}
			
			for(i in scrollcontent.cache){scrollcontent.cache[i].check();};
			
			if(this.selectMonthTriggered) this.onSelectMonth(this);
			if(this.selectYearTriggered) this.onSelectYear(this);
			if(this.changeTriggered) this.onChange(this);
			this.createTriggered = false;
			this.selectDayTriggered = false;
			this.selectMonthTriggered = false;
			this.selectYearTriggered = false;
			this.updateTriggered = false;
			this.changeTriggered = false;
			
			if(this.mode.selectBox)this.validate.setevents();
			
			if(this.validate.id) var obj = document.getElementById(this.validate.id);
			try {if(obj) {obj.focus();obj.focus();obj.value = obj.value;}} catch(e){};
			
			if(this.firstTimeCreated)
			{
				this.firstTimeCreated = false;
				this.onCreate(this);
			}
			this.onQuery(this);
		}
	
		this.validate = {
			parent:this,
			id:false,
			day:function(obj)
			{
				var day = obj;
				var month = obj.nextSibling.nextSibling;
				var year = month.nextSibling.nextSibling;
				
				this.parent.time = new Date(month.value+'/1/'+year.value);
				this.parent.highlight_day = Number(String(parseInt(day.value))+String(parseInt(month.value))+String(parseInt(year.value)));
				this.parent.dia = day.value;
				this.parent.changeTriggered = true;
				//this.parent.query();	
			},
			month:function(obj)
			{
				var day = obj.previousSibling.previousSibling;
				var month = obj;
				var year = obj.nextSibling.nextSibling;
				
				this.parent.time = new Date(month.value+'/1/'+year.value);
				this.parent.highlight_day = Number(String(parseInt(day.value))+String(parseInt(month.value))+String(parseInt(year.value)));
				this.parent.mes = month.value;
				this.parent.changeTriggered = true;
				//this.parent.query();
			},
			year:function(obj)
			{
				var month = obj.previousSibling.previousSibling;
				var year = obj;
				var day = month.previousSibling.previousSibling;
				
				this.parent.time = new Date(month.value+'/1/'+year.value);
				this.parent.highlight_day = Number(String(parseInt(day.value))+String(parseInt(month.value))+String(parseInt(year.value)));
				this.parent.ano = year.value;
				this.parent.changeTriggered = true;
				//this.parent.query();				
			},
			blurtab:function(e)
			{
				if (!e) var e = window.event;
				var obj = e.srcElement?e.srcElement:e.target;
				var prefix = obj.id.split('_')[1];
				var dom = jscalendar.cache[prefix];
				
				if(obj.id == 'jscalendar_'+prefix+'_validate_dia') 
				{
					dom.validate.id = 'jscalendar_'+prefix+'_validate_mes';
					dom.validate.day(obj);
				}
				if(obj.id == 'jscalendar_'+prefix+'_validate_mes')
				{
					dom.validate.id = 'jscalendar_'+prefix+'_validate_ano';
					dom.validate.month(obj);
				}
				if(obj.id == 'jscalendar_'+prefix+'_validate_ano')
				{
					dom.validate.id = false;
					dom.validate.year(obj);
				}
				dom.query();
			},
			entertab:function(e)
			{
				if (!e) var e = window.event;
				if (e.keyCode) code = e.keyCode;
					else if (e.which) code = e.which;
			
				var obj = e.srcElement?e.srcElement:e.target;
				var prefix = obj.id.split('_')[1];
				var dom = jscalendar.cache[prefix];
			
				if(code == 13 || code == 9)
				{
				
					if(obj.id == 'jscalendar_'+prefix+'_validate_dia') 
					{
						dom.validate.id = 'jscalendar_'+prefix+'_validate_mes';
						dom.validate.day(obj);
					}
					if(obj.id == 'jscalendar_'+prefix+'_validate_mes')
					{
						dom.validate.id = 'jscalendar_'+prefix+'_validate_ano';
						dom.validate.month(obj);
					}
					if(obj.id == 'jscalendar_'+prefix+'_validate_ano')
					{
						dom.validate.id = false;
						dom.validate.year(obj);
					}
					dom.query();
					if(dom.browser == 'IE') e.keyCode = 9;
				}
			},
			setevents:function()
			{
				var dia = document.getElementById('jscalendar_'+this.parent.prefix+'_validate_dia');
				var mes = document.getElementById('jscalendar_'+this.parent.prefix+'_validate_mes');
				var ano = document.getElementById('jscalendar_'+this.parent.prefix+'_validate_ano');
				
				if(window.addEventListener)
				{
					dia.addEventListener('keydown',this.entertab,false);
					mes.addEventListener('keydown',this.entertab,false);
					ano.addEventListener('keydown',this.entertab,false);
					
					dia.addEventListener('blur',this.blurtab,false);
					mes.addEventListener('blur',this.blurtab,false);
					ano.addEventListener('blur',this.blurtab,false);
				} else {	
					dia.attachEvent("onkeydown",this.entertab);
					mes.attachEvent("onkeydown",this.entertab);
					ano.attachEvent("onkeydown",this.entertab);
					
					dia.attachEvent("onblur",this.blurtab);
					mes.attachEvent("onblur",this.blurtab);
					ano.attachEvent("onblur",this.blurtab);
				}
			}
		}
		this.parseDate = function()
		{
			var items = this.languagecontent[this.language];
			var html = '<span class="cssjscalendar_head_'+this.prefix+'_validate">';
					html+= '<input id="jscalendar_'+this.prefix+'_validate_dia" class="cssjscalendar_head_'+this.prefix+'_validate_dia"  type="text" value="'+(this.dia<10?'0'+Number(this.dia):this.dia)+'" />/'; //onblur="jscalendar.cache[\''+this.prefix+'\'].validate.day(this)"
					html+= '<input id="jscalendar_'+this.prefix+'_validate_mes" class="cssjscalendar_head_'+this.prefix+'_validate_mes"  type="text" value="'+this.mes+'" />/'; //onblur="jscalendar.cache[\''+this.prefix+'\'].validate.month(this)"
					html+= '<input id="jscalendar_'+this.prefix+'_validate_ano" class="cssjscalendar_head_'+this.prefix+'_validate_ano"  type="text" value="'+this.ano+'" />'; //onblur="jscalendar.cache[\''+this.prefix+'\'].validate.year(this)"
				html+= '</span>';
			return html;
		}
		this.swapLeftArrow = function(obj)
		{
			obj.className = 'cssjscalendar_head_'+this.prefix+'_mesanterior_div';
		}
		this.swapRightArrow = function(obj)
		{
			obj.className = 'cssjscalendar_head_'+this.prefix+'_messeguinte_div';
		}
		this.swapLeftArrowOver = function(obj)
		{
			obj.className = 'cssjscalendar_head_'+this.prefix+'_mesanterior_div_hover';
		}
		this.swapRightArrowOver = function(obj)
		{
			obj.className = 'cssjscalendar_head_'+this.prefix+'_messeguinte_div_hover';
		}
		
		this.Internalonclick = function(index)
		{
			var events = this.content.datafunctions[index];
			var d = events?(events.eventTrigger=='onclick'?events.str(this):false):false;
		}
		this.Internalonmouseover = function(index)
		{
			var events = this.content.datafunctions[index];
			var d = events?(events.eventTrigger=='onmouseover'?events.str(this):false):false;		
		}
		this.Internalonmouseout = function(index)
		{
			var events = this.content.datafunctions[index];
			var d = events?(events.eventTrigger=='onmouseout'?events.str(this):false):false;
		}
		
		
		this.swapContent = function(obj)
		{
			var obj = this.hightlight.hover.pop();
			if(obj)
			{
				obj.decode();
				obj.hover = false;
				obj.render();
			}
		}
		this.swapContentOver = function(obj)
		{
			var _obj_ = new this.hightlight.obj();
				_obj_.domobj = obj;
				_obj_.decode();
			this.hightlight.hover.push(_obj_);	
				_obj_.hover = 'cssjscalendar_'+this.prefix+'_content_td_a_hover';
				_obj_.render();	
				
			this.selectBoxMonth.hide();	
			this.selectBoxYear.hide();	
		}
		
	}
	jscalendar.browser = function() 
	{
		var browser = new String(navigator.appName);
		if(browser.match('Microsoft Internet Explorer')) return String('IE');
		if(browser.match('Netscape')) return String('MOZ');
		if(browser.match('Opera')) return String('OPERA');
	}
	jscalendar.customSelectBox=new Object();
	jscalendar.customSelectBox.cache=Array();
	jscalendar.customSelectBox.style = function()
	{
		this.border = false;
		this.borderTop = false;
		this.borderBottom = false;
		this.borderLeft = false;
		this.borderRight = false;
		this.backgroundColor = false;
		this.backgroundImage = false;
		this.backgroundRepeat = false;
		this.backgroundPosition = false;
		this.textAlign = false;
		this.fontSize = false;
		this.font = false;
		this.width = false;
		this.height = false;
		this.position = 'static';
		this.textDecoration = false;
		this.color = false;
		this.top = false;
		this.left = false;
		this.right = false;
		this.bottom = false;
		this.cursor = false;
		this.zIndex = false;
		this.display = false;
		this.overflow = false;
		this.padding = false;
		this.paddingTop = false;
		this.paddingBottom = false;
		this.paddingLeft = false;
		this.paddingRight = false;
		this.margin = 0;
		this.marginTop = false;
		this.marginBottom = false;
		this.marginLeft = false;
		this.marginRight = false;
		this.listStyle = false;
		this.usefloat = false;
		this.scaleUnit = 'px';
		this.cssText = false;
		this.html = function()
		{
			var s = '';
			
			if(this.backgroundImage) s+='background-image:url('+this.backgroundImage+');';
			if(this.backgroundRepeat) s+='background-repeat:'+this.backgroundRepeat+';';
			if(this.backgroundPosition) s+='background-position:'+this.backgroundPosition+';';
			if(this.usefloat) s+='float:'+this.usefloat+';';
			if(this.listStyle) s+='list-style:'+this.listStyle+';';
			if(this.borderTop) s+='border-top:'+this.borderTop+';';
			if(this.borderBottom) s+='border-bottom:'+this.borderBottom+';';
			if(this.borderLeft) s+='border-left:'+this.borderLeft+';';
			if(this.borderRight) s+='border-right:'+this.borderRight+';';
			if(this.padding) s+='padding:'+this.padding+';';
			if(this.paddingTop) s+='padding-top:'+this.paddingTop+this.scaleUnit+';';
			if(this.paddingBottom) s+='padding-bottom:'+this.paddingBottom+this.scaleUnit+';';
			if(this.paddingLeft) s+='padding-left:'+this.paddingLeft+this.scaleUnit+';';
			if(this.paddingRight) s+='padding-right:'+this.paddingRight+this.scaleUnit+';';
			if(this.margin) s+='margin:'+this.margin+';';
			if(this.marginTop) s+='margin-top:'+this.marginTop+this.scaleUnit+';';
			if(this.marginBottom) s+='margin-bottom:'+this.marginBottom+this.scaleUnit+';';
			if(this.marginLeft) s+='margin-left:'+this.marginLeft+this.scaleUnit+';';
			if(this.marginRight) s+='margin-right:'+this.marginRight+this.scaleUnit+';';
			if(this.display) s+='display:'+this.display+';';
			if(this.overflow) s+='overflow:'+this.overflow+';';
			if(this.zIndex) s+='z-index:'+this.zIndex+';';
			if(this.font) s+='font-family:'+this.font+';';
			if(this.border) s+='border:'+this.border+';';
			if(this.backgroundColor) s+='background-color:'+this.backgroundColor+';';
			if(this.textAlign) s+='text-align:'+this.textAlign+';';
			if(this.fontSize) s+='font-size:'+this.fontSize+this.scaleUnit+';';
			if(this.width) s+='width:'+this.width+this.scaleUnit+';';
			if(this.height) s+='height:'+this.height+this.scaleUnit+';';
			if(this.position) s+='position:'+this.position+';';
			if(this.textDecoration) s+='text-decoration:'+this.textDecoration+';';
			if(this.color) s+='color:'+this.color+';';
			if(this.top) s+='top:'+this.top+this.scaleUnit+';';
			if(this.left) s+='left:'+this.left+this.scaleUnit+';';
			if(this.right) s+='right:'+this.right+this.scaleUnit+';';
			if(this.bottom) s+='bottom:'+this.bottom+this.scaleUnit+';';
			if(this.cursor) s+='cursor:'+this.cursor+';';
			if(this.cssText) s+= this.cssText;
			var dbl = new RegExp(';;','gi');
			s = s.replace(dbl,'');
			return s;
		}
	}
	jscalendar.customSelectBox.obj = function(prefix)
	{
		//defini&ccedil;&otilde;es gerais da componente;
		this.prefix=prefix;
		this.className = '';
		this.domobj = false;
		this.cache = new Array();
		
		this.content = new Object();
		this.head = new Object();
		
		this.head.style = new jscalendar.customSelectBox.style();
		this.head.content = new Object();
		
		this.content.style = new jscalendar.customSelectBox.style();
		this.content.row = new Object();
		
		this.editableContent = new Object();
		this.editableContent.defaultValue = '';
		this.editableContent.style = new jscalendar.customSelectBox.style();
		
		this.content.style.borderColor = '#7F9DB9';
		this.content.style.border = '1px solid '+this.content.style.borderColor;
		this.content.style.color = '#000000';
		this.content.style.backgroundColor = '#ffffff';
		//this.content.style.height = 200;
		this.content.style.font = 'Times New Roman';
		this.content.style.fontSize = 12;
		this.content.style.margin = 0;
		
		this.style = new jscalendar.customSelectBox.style();
		this.style.height = 0;
		this.style.overColor = '#8BBBED';
		//this.style.overColor='#ff0000';
		this.style.selectedColor = '#CDE4FC';
		this.style.borderColor = '#7F9DB9';
		this.style.backgroundColor = '#ffffff';
		this.style.font = 'Times New Roman';
		this.style.fontSize = 12;
		//this.style.border='1px solid '+this.style.borderColor;
		this.style.width = 0;
		this.style.color = '#000000';
		
		this.relativePath='';
		this.showIndex=false;
		this.refreshEvent=false;
		this.htmlFormat = false;
		this.name = '';
		this.value = false;
		this.valueText = '';
		this.scrollvalue = 0;
		
		//objecto que vai guardar todas as rows que introduzir na componente
		this.data = new Object();
		this.data.content = new Array();	
		this.data.contentIndex = new Array();
			
		this.state='hidden';
		this.headHTML='';
		this.contentHTML='';
		this.firstTime = 0;
		this.ArrowImage = 'img/calendicon.gif';
		this.resumeonclick = true;
		this.resumeonDblClick = false;
		this.editable = false;
		this.HTMLcontentObjs = new Object();
		this.htmlfunctions = new jscalendar.customSelectBox.dom();
		
		this.onChange = function(){};
		this.onclick = function(){};
		this.onmouseover = function(){};
		this.onmouseout = function(){};
		this.onmouseup = function(){};
		this.onmousedown = function(){};
		this.onDropStart = function(){};
		this.onDropEnd = function(){};
		this.onLift = function(){};
		
		
		this.method = new Object();
		this.method.innerHTML = true;
		this.method.createElement = false;
		this.method.documentWrite = false;
		this.method.check = function()
		{
			if(this.innerHTML)
			{
				this.createElement = false;
				this.documentWrite = false;
			} else
			if(this.createElement)
			{
				this.innerHTML = false;
				this.documentWrite = false;
			} else
			if(this.documentWrite)
			{
				this.innerHTML = false;
				this.createElement = false;
			}
		}
		this.method.writeHTML = function(html)
		{
			if(this.innerHTML)
			{
				document.body.innerHTML+=html;
			} else
			if(this.createElement)
			{
				var div = document.createElement('DIV');
					document.body.appendChild(div);
					div.innerHTML = html;
			} else
			if(this.documentWrite)
			{
				document.write(html);
			}
		}
		this.method.writeCSS = function(css)
		{
			
			if(this.innerHTML)
				document.body.innerHTML+= css;
			else if(this.documentWrite) document.write(css);	
			
		}
		
		this.replaceStr = function(str,rexp,subs)
		{
			if(!str)return false;
			var result = String(str);
			while(result.search(rexp) != -1){result = result.replace(rexp,subs);}
			return result;
		}
		this.add=function(id)
		{
			var content = document.getElementById(id);
			if(!content) return false;
			this.htmlfunctions.cleanWhitespace(document.getElementById(id));
			this.getdivwidth(document.getElementById(id).firstChild.offsetWidth);
			this.data.content.push(document.getElementById(id).innerHTML);
		}
		this.addanddelete=function(id)
		{
			var content = document.getElementById(id);
			if(!content) return false;
			//this.getdivwidth(document.getElementById(id).firstChild.offsetWidth);
			this.data.content.push(document.getElementById(id).innerHTML);
			content.parentNode.removeChild(content);
		}
		this.getdivwidth = function(width)
		{
			if(width && (width > this.style.width)) this.style.width = width;
		}
		this.getRelativePath = function(script)
		{
			var scripts = document.getElementsByTagName('SCRIPT');
			if(!scripts) return false;
			var regexp = new RegExp(script,"gi");
			for(var i = 0; i<scripts.length; i++)
			{
				if(String(scripts.item(i).src).match(regexp))
					this.relativePath = scripts.item(i).src.replace(regexp,'');
			}
		}
		this.parseCSS = function(css)
		{
			var arr = String(css).split(';'),value = false,obj = new Array();
			while(arr.length > 0){value = arr.pop();if(value){obj.push(value);}}
			return obj;
		}
		//creates the jscalendar.customSelectBox for the first time
		this.create=function()
		{	
			this.getRelativePath('jscalendar.js');
			jscalendar.customSelectBox.cache[this.prefix] = this;
			this.method.check();
			var paddingtop = '',expwidth = 0,margintop = '',regexp = new RegExp("\"|'","gi"),browser = jscalendar.customSelectBox.browser();
			if(browser == 'IE') paddingtop = 'padding-top:1px;';
			if(browser == 'MOZ' || browser == 'OPERA') margintop = 'margin-top:1px;margin-bottom:0px;';
			
			this.head.style.overflow = 'auto';
			
			this.head.content.table = 'background-color:'+this.style.backgroundColor+';border-width:1px;border-style:solid;border-color:'+this.style.borderColor+';height:'+this.style.height+';'+this.head.style.html();
			this.head.content.td = 'background-color:'+this.style.backgroundColor+';margin:0px;padding:0px;';
			this.head.content.div = 'position:static;padding:0;margin:0;overflow:hidden;color:'+this.style.color+';font-family:'+this.style.font+';font-size:'+this.style.fontSize+'px;'+this.head.style.html();//+(this.head.style.width?this.head.style.html():this.style.width+'px')+
			this.head.content.arrow = 'position:static;margin:0px;padding:0px;background-image:url('+this.relativePath+this.ArrowImage+');width:30px;height:19px;background-repeat:no-repeat;cursor:pointer;background-position:50% 2px;';
			
			var s = '<table id="'+this.prefix+'_jscalendar.customSelectBoxTable" style="'+this.head.content.table+'" cellpadding="0" cellspacing="0">';
					s+= '<tr style="vertical-align:middle;">';
						s+= '<td id="'+this.prefix+'_selectedIndex" style="'+this.head.content.td+'padding:0px;margin:0px;"><div style="'+this.head.content.div+'" '+(this.editable?'onclick="jscalendar.customSelectBox.cache[\''+this.prefix+'\'].addNewRow(this);"':'')+'>'+this.valueText+'</div></td>';
						s+= '<td style="padding:0px;margin:0px;"><div id="'+this.prefix+'_jscalendar.customSelectBoxButton" style="'+this.head.content.arrow+'" onclick="jscalendar.customSelectBox.cache[\''+this.prefix+'\'].visibility()" onmouseover="jscalendar.customSelectBox.cache[\''+this.prefix+'\'].swapOverArrowImg(this)" onmouseout="jscalendar.customSelectBox.cache[\''+this.prefix+'\'].swapArrowImg(this)"></div></td>';
					s+= '</tr>';
				s+= '</table>';	
			this.headHTML = s;
			
			this.content.div = this.content.style.html()+'margin:0px;padding:2px;margin-top:-1px;position:absolute;z-index:999;border:1px solid '+this.style.borderColor+(this.state=='visible'?';display:inline;':';display:none;');
			
			var html = '<div onscroll="jscalendar.customSelectBox.getscrollvalue.get(this,\''+this.prefix+'\')" style="'+this.content.div+'">';
				html+= '<table id="'+this.prefix+'_jscalendar.customSelectBoxContentTable" cellpadding="0" cellspacing="0" border="0">';
			if(this.state=='visible') 
			{
				this.onDropStart(this);
				for(var x=0;x<this.data.content.length;x++)
				{html+= '<tr style="cursor:pointer;"><td '+(browser == 'IE'?'align="center"':'')+'><div id="'+this.prefix+'_'+x+'">'+this.data.content[x]+'</div></td></tr>';}
			}
			this.contentHTML = html+'</table></div>';
			if(this.firstTime == 1) this.onLift(this);
			this.outputHTML(); 
			if(this.state=='visible') this.onDropEnd(this);
		}
		this.outputHTML=function()
		{
			var html = this.headHTML+this.contentHTML,obj = false;
			var div = document.getElementById(this.prefix);
			
			if(!div) this.method.writeHTML('<div id="'+this.prefix+'" style="margin:0px;padding:0px;">'+html+'</div>'); else div.innerHTML=html;	
			//for(var x=0;x<this.data.content.length;x++){obj = document.getElementById(this.prefix+'_'+x);if(obj) obj.innerHTML = this.data.content[x];}
		}
		this.visibility = function()
		{	
			var div = document.getElementById(this.prefix);
			var table = document.getElementById(this.prefix+'_jscalendar.customSelectBoxTable');
			if(!div)return false;
			this.firstTime=1;
			if(this.state=='visible') this.state='hidden'; else {this.state='visible';this.firstTime = 0;}
			this.create();
			var table = document.getElementById(this.prefix+'_jscalendar.customSelectBoxTable');		
			if(!table) return false;
			table.style.borderBottom = '1px solid '+this.style.borderColor;	
			
			this.domobj.validate.setevents();
		}
		this.clear = function()
		{
			this.data.content = new Array();
			this.value = false;
			this.valueText = false;
			this.create();
		}
		this.showOnTop = function()
		{
			var obj = document.getElementById(this.prefix+'_selectedIndex');
			if(!obj) return false;
			obj.firstChild.innerHTML = this.valueText;
		}
		this.close = function()
		{
			this.visibility();
		}
		this.swapOverArrowImg=function(obj)
		{
			if(!obj) return false;
			obj.style.backgroundImage = 'url('+this.relativePath+this.ArrowImage+')';
		}
		this.swapArrowImg=function(obj)
		{
			if(!obj) return false;
			obj.style.backgroundImage = 'url('+this.relativePath+this.ArrowImage+')';
		}
	}
	jscalendar.customSelectBox.dom = function(obj)
	{
		this.root = obj;
		this.element = false;
		this.notWhitespace = /\S/
		this.get = function(row,col)
		{
			if(!this.root) return false;
			if(this.root.nodeName != 'TABLE') return false;
			if(this.root.firstChild.nodeName == 'TBODY') 
				this.element = this.root.firstChild.firstChild;	
			var y = 0;
			while(y < row && this.element){this.element = this.element.nextSibling;y++;}
			
			if(this.node(this.element,col)) return this.node(this.element,col); 
					else return false;
		}
		this.node = function(obj,index)
		{
			if(!obj) return false;
			var obj = obj.firstChild?obj.firstChild:false;
			if(index == 0) return obj;
			var x = 0;
			while(x < index){obj = obj.nextSibling;x++;}
			return obj;
		}
		this.cleanWhitespace = function(node) 
		{	  
			  for (var x = 0; x < node.childNodes.length; x++) {
				var childNode = node.childNodes[x]
				if ((childNode.nodeType == 3)&&(!this.notWhitespace.test(childNode.nodeValue))) {
			// that is, if it's a whitespace text node
				  node.removeChild(node.childNodes[x])
				  x--
				}
				if (childNode.nodeType == 1) {
			// elements can have text child nodes of their own
				  this.cleanWhitespace(childNode)
				}
			  }
		}
		this.getExactDimensions = function(obj)
		{
			var type = typeof obj;
			if(type == 'undefined') return false;
			if(type == 'string') var obj = document.getElementById(obj);
			if(!obj) return false;
			var browser = this.browser();
			var coords = new this.IQGetPageCoordsObj(obj);
			var dim = {
				padding: {
					horizontal:Number(String(obj.style.paddingLeft).split(/px|pt/)[0])+Number(String(obj.style.paddingRight).split(/px|pt/)[0]),
					vertical:Number(String(obj.style.paddingTop).split(/px|pt/)[0])+Number(String(obj.style.paddingBottom).split(/px|pt/)[0])
				},
				margin: {
					horizontal:Number(String(obj.style.marginLeft).split(/px|pt/)[0])+Number(String(obj.style.marginRight).split(/px|pt/)[0]),
					vertical:Number(String(obj.style.marginTop).split(/px|pt/)[0])+Number(String(obj.style.marginBottom).split(/px|pt/)[0])
				},
				border: {
					horizontal:Number(String(obj.style.borderLeftWidth).split(/px|pt/)[0])+Number(String(obj.style.borderRightWidth).split(/px|pt/)[0]),
					vertical:Number(String(obj.style.borderTopWidth).split(/px|pt/)[0])+Number(String(obj.style.borderBottomWidth).split(/px|pt/)[0])
				},
				x:coords.x,
				y:coords.y,
				width:false,
				height:false
			}
			dim.width = obj.offsetWidth - dim.padding.horizontal - dim.margin.horizontal;
			dim.height = obj.offsetHeight - dim.padding.vertical - dim.margin.vertical;
			if(browser == 'MOZ'){dim.width+=2;dim.height+=1;}
			return dim;
		}
		this.IQGetPageCoordsObj = function(obj) {var coords = {x: 0, y: 0};do {coords.x += obj.offsetLeft;coords.y += obj.offsetTop;}while ((obj = obj.offsetParent));return coords;}
		this.browser = function() 
		{
			var browser = new String(navigator.appName);
			if(browser.match('Microsoft Internet Explorer')) return String('IE');
			if(browser.match('Netscape')) return String('MOZ');
			if(browser.match('Opera')) return String('OPERA');
		}
	}
	jscalendar.customSelectBox.getscrollvalue = new Object();
	jscalendar.customSelectBox.getscrollvalue.value = new Array();
	jscalendar.customSelectBox.getscrollvalue.get = function(obj,prefix){jscalendar.customSelectBox.getscrollvalue.value[prefix] = obj.scrollTop;}
	jscalendar.customSelectBox.tempfunc = null;
	jscalendar.customSelectBox.browser = function() 
	{
		var browser = new String(navigator.appName);
		if(browser.match('Microsoft Internet Explorer')) return String('IE');
		if(browser.match('Netscape')) return String('MOZ');
		if(browser.match('Opera')) return String('OPERA');
	}	

