<!--
//** DatePicker class **//
function DatePicker(){
	this.draw = DatePicker_draw;
	this.show = DatePicker_show;
	this.hide = DatePicker_hide;
	this.parseDate = DatePicker_parseDate;
	this.toString = DatePicker_toString;

	if(arguments[0]==null) {alert("No binder object to get/take the result"); return;}
	if(arguments[0].id==null || arguments[0].id.length==0) {alert("No id specified in binder object"); return;}
	if(arguments[0].tagName!="INPUT" || arguments[0].type!="text") {alert("Binder object must be an 'INPUT' tag type 'text'."); return;}
	this.binder = arguments[0];

	this.mindate = this.parseDate(arguments[1]==null ? "1901-01-01" : arguments[1]);
	if(isNaN(this.mindate)) {alert("Invalid date specified in mindate"); return;}

	this.maxdate = this.parseDate(arguments[2]==null ? "2099-12-31" : arguments[2]);
	if(isNaN(this.maxdate)) {alert("Invalid date specified in maxdate"); return;}

	if(typeof(arguments[3])=='undefined'){
		min = "A".charCodeAt(0); 
		range = "z".charCodeAt(0) - min + 1;
		this.instant = "";
		while(this.instant.length<8){
			str = String.fromCharCode(Math.floor(Math.random()*range)+min);
			if(str.match(/[A-Za-z]/)) this.instant += str;
		}
		document.write("<script language=\"JavaScript\">"+this.instant+"=new DatePicker(document.getElementById('"+this.binder.id+"'),'"+this.mindate+"','"+this.maxdate+"','"+this.instant+"');<\/script>");
		eval(this.instant+".draw()");
		eval("document.getElementById('"+this.binder.id+"').onfocus=new Function('"+this.instant+".show()')");
		eval("document.getElementById('"+this.binder.id+"').onblur=new Function('"+this.instant+".hide()')");
		eval("document.getElementById('"+this.binder.id+"').onchange=new Function('"+this.instant+".hide()')");
	}
	else{
		this.pick = DatePicker_pick;
		this.next = DatePicker_next;
		this.prev = DatePicker_prev;
		this.update = DatePicker_update;
	
		this.id = arguments[3];
		this.layer = this.id + "Layer";
		this.hiding = null;

		now = new Date();
		this.sDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		this.cDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		if(this.cDate<this.mindate) this.cDate.setTime(this.mindate.getTime());
		if(this.cDate>this.maxdate) this.cDate.setTime(this.maxdate.getTime());
	}

	this.styleTable = this.id+"_table";
	this.styleCellDefault = this.id+"_cell_default";
	this.styleCellHighlight = this.id+"_cell_highlight";
	this.styleCellInactive = this.id+"_cell_inactive";
	this.styleCellHeader = this.id+"_cell_header";
	this.styleCellDay = this.id+"_cell_day";
}

function DatePicker_draw(){
    if(document.getElementById(this.id)==null){
        html = "<div id=\""+this.layer+"\" style=\"position:absolute; left:0px; top:0px; width:1px; height:1px; z-index:1; visibility: visible; overflow: visible;\"></div>";
		html += "<style type=\"text/css\">";
		html += "."+this.styleTable+"{ background-color: #666666;}";
		html += "."+this.styleCellDefault+"{  font-weight: normal; text-align: right;  vertical-align: bottom; color: #000000; cursor: default;	background-color: #FFFFFF;}";
		html += "."+this.styleCellHighlight+"{font-weight: bold;   text-align: right;  vertical-align: bottom; color: #FFFFFF; cursor: default;	background-color: #999999;}";
		html += "."+this.styleCellInactive+" {font-weight: normal; text-align: right;  vertical-align: bottom; color: #999999; cursor: default; background-color: #FFFFFF;}";
		html += "."+this.styleCellHeader+" {  font-weight: bold;   text-align: center; vertical-align: middle; color: #000000; cursor: default; background-color: #FFFFFF;}";
		html += "."+this.styleCellDay+" {	  font-weight: bold;   text-align: left;   vertical-align: bottom; color: #FFFFFF; cursor: default; background-color: #0C7BC0;}";
		html += "</style>";
        document.write(html);
    }
}

function DatePicker_show(){
	if(this.id==null) { eval(this.instant+".show()"); return;}

	var layer = document.getElementById(this.layer);
    var top = 0, left = 0;
    p = document.getElementById(this.binder.id);
    while(p.tagName!="HTML"){
        if(p.tagName!="FORM" && p.tagName!="TR" && p.tagName!="TBODY"){
            top += p.offsetTop;
            left += p.offsetLeft;
        }
        p = p.parentNode;
    }
	top += document.getElementById(this.binder.id).offsetHeight;
	layer.style.top = top+"px";
	layer.style.left = left+"px";

	if(layer.style.visibility=='visible'){
		clearTimeout(this.hiding);
		this.hiding = null;
	}
	else{
		this.sDate = this.parseDate(this.binder.value);
		if(isNaN(this.sDate)) this.sDate = new Date(this.cDate);
		if(this.sDate<this.mindate){
			this.sDate.setYear(this.mindate.getFullYear());
			this.sDate.setMonth(this.mindate.getMonth());
			this.sDate.setDate(this.mindate.getDate());
		}
		if(this.sDate>this.maxdate){
			this.sDate.setYear(this.maxdate.getFullYear());
			this.sDate.setMonth(this.maxdate.getMonth());
			this.sDate.setDate(this.maxdate.getDate());
		}
		this.cDate.setYear(this.sDate.getFullYear());
		this.cDate.setMonth(this.sDate.getMonth());
		this.cDate.setDate(this.sDate.getDate());
		this.update();
	}

    months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	myText = months[this.sDate.getMonth()]+" "+this.sDate.getFullYear();

	html = "<table width=\"180\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\""+this.styleTable+"\">";
	html += " <tr>";
	html += "  <td colspan=\"7\" nowrap class=\""+this.styleCellHeader+"\">";
    html += "   <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    html += "    <tr>";
    html += "     <td class=\""+this.styleCellDefault+"\" onmouseover=\"this.className='"+this.styleCellHighlight+"'\" onmouseout=\"this.className='"+this.styleCellDefault+"'\" onclick=\""+this.id+".prev()\"><strong>&lt;&lt;</strong></td>";
    html += "     <td width=\"100%\" class=\""+this.styleCellHeader+"\">"+myText+"</td>";
    html += "     <td class=\""+this.styleCellDefault+"\" onmouseover=\"this.className='"+this.styleCellHighlight+"'\" onmouseout=\"this.className='"+this.styleCellDefault+"'\" onclick=\""+this.id+".next()\"><strong>&gt;&gt;</strong></td>";
    html += "    </tr>";
    html += "   </table>";
    html += "  </td>";
    html += " </tr>";
    html += " <tr>";
    html += "  <td width=\"14%\" nowrap class=\""+this.styleCellDay+"\">Su</td>";
	html += "  <td width=\"14%\" nowrap class=\""+this.styleCellDay+"\">Mo</td>";
	html += "  <td width=\"14%\" nowrap class=\""+this.styleCellDay+"\">Tu</td>";
	html += "  <td width=\"14%\" nowrap class=\""+this.styleCellDay+"\">We</td>";
	html += "  <td width=\"14%\" nowrap class=\""+this.styleCellDay+"\">Th</td>";
	html += "  <td width=\"14%\" nowrap class=\""+this.styleCellDay+"\">Fr</td>";
	html += "  <td width=\"14%\" nowrap class=\""+this.styleCellDay+"\">Sa</td>";
	html += " </tr>";

	fdom = new Date(this.sDate.getFullYear(), this.sDate.getMonth(), 1);
	ldom = new Date(fdom.getFullYear(), fdom.getMonth()+1, fdom.getDate()-1);
	ldoc = new Date(ldom.getFullYear(), ldom.getMonth(), ldom.getDate()-ldom.getDay()+6);
	date = new Date(fdom.getFullYear(), fdom.getMonth(), fdom.getDate()-fdom.getDay());
	for(; date<=ldoc; date.setDate(date.getDate()+1)){
		cellClass = (date.getTime()==this.cDate.getTime() ? this.styleCellHighlight : this.styleCellDefault);
		if(date.getDay()==0) html += "  <tr>";
		if(date<fdom || date>ldom || date<this.mindate || date>this.maxdate) html += "    <td nowrap class=\""+this.styleCellInactive+"\">"+date.getDate()+"</td>";
		else html += "    <td nowrap class=\""+cellClass+"\" onmouseover=\"this.className='"+this.styleCellHighlight+"'\" onmouseout=\"this.className='"+cellClass+"'\" onClick=\""+this.id+".pick(this)\">"+date.getDate()+"</td>";
		if(date.getDay()==6) html += "  </tr>";
	}
	html += "</table>";

	layer.innerHTML = html;
	layer.style.visibility = 'visible';
	this.binder.focus();
}

function DatePicker_hide(){
	if(this.id==null) { eval(this.instant+".hide()"); return;}
	this.update();
	this.hiding = setTimeout("document.getElementById('"+this.layer+"').style.visibility='hidden'", 250);
}

function DatePicker_pick(e){
	clearTimeout(this.hiding);
	this.hiding = null;
	document.getElementById(this.layer).style.visibility='hidden';
	this.sDate.setDate(e.innerHTML);
	this.cDate.setYear(this.sDate.getFullYear());
	this.cDate.setMonth(this.sDate.getMonth());
	this.cDate.setDate(this.sDate.getDate());
	this.update();
}

function DatePicker_update(){
	this.binder.value = this.cDate.getFullYear()+"-"+(this.cDate.getMonth()+1)+"-"+this.cDate.getDate();
}

function DatePicker_next(){
	date = new Date(this.sDate.getFullYear(), this.sDate.getMonth()+1, 0);
	if(date<this.maxdate) this.sDate.setMonth(this.sDate.getMonth()+1);
	this.show();
}

function DatePicker_prev(){
	date = new Date(this.sDate.getFullYear(), this.sDate.getMonth(), 1);
	if(date>this.mindate) this.sDate.setMonth(this.sDate.getMonth()-1);
	this.show();
}

function DatePicker_parseDate(dateString){
	array = dateString.split(/-/);
	switch(array.length){
		case 1: date = new Date(dateString); break;
		case 2: array.push(0);
		case 3:
		default: date = new Date(array[0]*1, array[1]*1-1, array[2]*1); break;
	}
	if(!isNaN(date)) date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
	return date;
}

function DatePicker_toString(){
	if(this.binder==null) return "DatePicker: fail to initialize the object.";
	return "DatePicker("+this.binder.id+"):("+this.mindate+"-"+this.maxdate+")";
}
//** end DatePicker class **//
//-->
