//***********************************************************************************************
// Script made by Marcio Zaiosc Almeida - zaiosk@yahoo.com.br
//***********************************************************************************************
//
function Select_Day(param,def_value,style)
	{
	document.write("<select name=\"d_" + param + "\" size=\"1\" " + style + " onChange=\"Change_All(this.form,'" + param + "')\">")
	for (i = 1; i < 32; i++)
		{
		if (i == def_value) selected = "selected"; else selected = ""
		if (i < 10) show = "0" + i; else show = i
		document.write("<option value=\"" + show + "\" " + selected + ">" + show + "</option>")
		}
	document.write("</select>")
	}
//
//***********************************************************************************************
//
function Select_Month(param,def_value,style)
	{
	document.write("<select name=\"m_" + param + "\" size=\"1\" " + style + " onChange=\"Change_All(this.form,'" + param + "')\">")
	for (i = 1; i < 13; i++)
		{
		if (i == def_value) { selected = "selected" } else { selected = "" }
		if (i < 10) show = "0" + i; else show = i
		document.write("<option value=\"" + show + "\" " + selected + ">" + show + "</option>")
		}
	document.write("</select>")
	}
//
//***********************************************************************************************
//
function Select_Year(param,def_value,style)
	{
	var today = new Date()
	document.write("<select name=\"y_" + param + "\" size=\"1\" " + style + " onChange=\"Change_All(this.form,'" + param + "')\">")
	for (i = today.getFullYear() - 14; i <= (today.getFullYear() + 1); i++)
		{
		if (i == def_value) selected="selected"; else selected="";
		document.write("<option value=" + i + " " + selected + ">" + (i + "").substring(2,4) + "</option>")
		}
	document.write("</select>")
	}
//
//***********************************************************************************************
//
function Datapicker_CE(param, date_mysql, style)
{
    var today = new Date();
    if (date_mysql == 0) {
        day = today.getDate()
        month = today.getMonth() + 1
        year = today.getFullYear();
    } else {
        year = date_mysql.substring(0,date_mysql.indexOf("-"));
        month = date_mysql.substring(date_mysql.indexOf("-") + 1,date_mysql.lastIndexOf("-")) - 0;
        day = date_mysql.substring(date_mysql.lastIndexOf("-") + 1,date_mysql.length) - 0;
    }
    // Corrigindo dia, mês e ano
    if (day < 10) day = "0" + day;
    if (month < 10) month = "0" + month;
    if (year < 10) year = "0" + year;
    // Criando os seletores
    Select_Day(param,day,style);
    Select_Month(param,month,style);
    Select_Year(param,year,style);
    // Criando o campo hidden
    document.write("<input type=\"hidden\" name=\"date_" + param + "\" value=\"" + year + "-" + month + "-" + day + "\">");
    //alert("<input type=\"hidden\" name=\"date_" + param + "\" value=\"" + year + "-" + month + "-" + day + "\"")
}
//
//***********************************************************************************************
//
function Change_All(form_obj,param)
	{
	form_name = form_obj.name
	day = document[form_name]["d_" + param].value
	month = document[form_name]["m_" + param].value
	year = document[form_name]["y_" + param].value
	//
	// Número de dias do mês selecionado
	//
	if (month == "01"|| month == "03"|| month == "05"|| month == "07"|| month == "08"|| month == "10"|| month == "12")
		monthdays = 31
	else if (month == "04" || month == "06" ||month == "09" ||month == 11)
		monthdays = 30
	else
		{
		if (year % 4 == 0)
			monthdays = 29
		else
			monthdays = 28
		}
	//
	// Corrigir o dia se este for superior ao máximo para aquele mês e ano
	//
	if (eval(day) > monthdays)
		{
		document[form_name]["d_" + param].selectedIndex = monthdays - 1
		day = monthdays
		}
	//
	// Atualizando o hidden
	document[form_name]["date_" + param].value = year + "-" + month + "-" + day
	}
//
//***********************************************************************************************
//
function DTP_Disable(form_obj,param,statement)
	{
	form_name = form_obj.name
	prefix = Array("d","m","y")
	for (i = 0; i < 3; i++)
		document[form_name][prefix[i] + "_" + param].disabled = statement
	}

