// Created By: Armando Peņa

function HtmlTime(tid,value)
{
	this.id = tid;
	if(value != null)
	{
		this.hour = value.substr(0,2);
		this.min =value.substr(3,2);
		this.ampm = value.substr(value.length-2,2).toUpperCase();
	}
	else
	{
		this.hour=0;
		this.min=0;
		this.ampm="AM";
	}
	this.format=1;
	this.timeInterval=5;
}

function HtmlTime_GetHtml()
{
	var html="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
	html+="<td><select onchange=\"HtmlTime_Update('" + this.id + "',"+ this.format +")\" class=\"input\" id=\""+ this.id + "_hour\" name=\""+ this.id + "_hour\"><option value=''>00</option><option value='12'>12</option>";
	for(var x=1; x<=11; x++)
		html +="<option " + (x == this.hour ? "selected>" : ">") + (x<10 ? "0" : "")+ x + "</option>";
	html +="</select></td>";
	html+="<td>&nbsp;<select onchange=\"HtmlTime_Update('" + this.id + "',"+ this.format +")\" class=\"input\" id=\""+ this.id + "_min\" name=\""+ this.id + "_min\">";
	for(var x=0; x<=60-this.timeInterval; x+=this.timeInterval)
		html +="<option " + (x == parseInt(this.min) ? "selected>" : ">") + (x<10 ? "0" : "")+ x + "</option>";
	html +="</select></td>";
	html +="<td>&nbsp;<select onchange=\"HtmlTime_Update('" + this.id + "',"+ this.format +")\" class=\"input\" id=\""+ this.id + "_ampm\" name=\""+ this.id + "_ampm\">"
	html +="<option "+ (this.ampm == 'AM' ? "selected" :"") +">AM</option><option "+ (this.ampm == 'PM' ? "selected" :"") +">PM</option></select>";
	html +="</tr></table><input type=\"hidden\" id=\"" + this.id +"\" name=\"" + this.id +"\">";
	return html;
}
HtmlTime.prototype.getHtml = HtmlTime_GetHtml;

function HtmlTime_Refresh()
{
	HtmlTime_Update(this.id,this.format)
}
HtmlTime.prototype.refresh = HtmlTime_Refresh;

function HtmlTime_Update(id,format)
{
	var hl = document.getElementById(id+"_hour");
	var ml = document.getElementById(id+"_min");
	var al = document.getElementById(id+"_ampm");
	
	var time = document.getElementById(id);
	
	time.value = "";
	if(hl.selectedIndex >0)
	{
		time.value = hl.options[hl.selectedIndex].text + ":" + ml.options[ml.selectedIndex].text + " " + al.options[al.selectedIndex].text;
	}
}
