/* $Id: tbl_change.js,v 2.18 2005/10/06 09:23:58 nijel Exp $ */


/**
 * Modify from controls when the "NULL" checkbox is selected
 *
 * @param   string   the MySQL field type
 * @param   string   the urlencoded field name
 * @param   string   the md5 hashed field name
 *
 * @return  boolean  always true
 */
function nullify(theType, urlField, md5Field, multi_edit)
{
    var rowForm = document.forms['insertForm'];

    if (typeof(rowForm.elements['funcs' + multi_edit + '[' + urlField + ']']) != 'undefined') {
        rowForm.elements['funcs' + multi_edit + '[' + urlField + ']'].selectedIndex = -1;
    }

    // "SET" field , "ENUM" field with more than 20 characters
    // or foreign key field
    if (theType == 1 || theType == 3 || theType == 4) {
        rowForm.elements['field_' + md5Field + multi_edit + '[]'].selectedIndex = -1;
    }
    // Other "ENUM" field
    else if (theType == 2) {
        var elts     = rowForm.elements['field_' + md5Field + multi_edit + '[]'];
        // when there is just one option in ENUM:
        if (elts.checked) {
            elts.checked = false;
        } else {
            var elts_cnt = elts.length;
            for (var i = 0; i < elts_cnt; i++ ) {
                elts[i].checked = false;
            } // end for

        } // end if
    }
    // Other field types
    else /*if (theType == 5)*/ {
        rowForm.elements['fields' + multi_edit + '[' + urlField + ']'].value = '';
    } // end if... else if... else

    return true;
} // end of the 'nullify()' function


/**
 * Unchecks the "NULL" control when a function has been selected or a value
 * entered
 *
 * @param   string   the urlencoded field name
 *
 * @return  boolean  always true
 */
function unNullify(urlField, multi_edit)
{
    var rowForm = document.forms['insertForm'];

    if (typeof(rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']']) != 'undefined') {
        rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']'].checked = false
    } // end if

    if (typeof(rowForm.elements['insert_ignore_' + multi_edit]) != 'undefined') {
        rowForm.elements['insert_ignore_' + multi_edit].checked = false
    } // end if

    return true;
} // end of the 'unNullify()' function

var day;
var month;
var year;
var hour;
var minute;
var second;
var clock_set = 0;

/**
 * Opens calendar window.
 *
 * @param   string      calendar.php parameters
 * @param   string      form name
 * @param   string      field name
 * @param   string      edit type - date/timestamp
 */
function openCalendar(params, form, field, type) {
    //window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
	self.location.href = "./calendar.php?" + params;
    dateField = eval("document." + form + "." + field);
    dateType = type;
}

/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 * @param   string type of number
 */
function formatNum2(i, valtype) {
    f = (i < 10 ? '0' : '') + i;
    if (valtype && valtype != '') {
        switch(valtype) {
            case 'month':
                f = (f > 12 ? 12 : f);
                break;

            case 'day':
                f = (f > 31 ? 31 : f);
                break;

            case 'hour':
                f = (f > 24 ? 24 : f);
                break;

            default:
            case 'second':
            case 'minute':
                f = (f > 59 ? 59 : f);
                break;
        }
    }

    return f;
}

/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 * @param   int default value
 * @param   string type of number
 */
function formatNum2d(i, default_v, valtype) {
    i = parseInt(i, 10);
    if (isNaN(i)) return default_v;
    return formatNum2(i, valtype)
}

/**
 * Formats number to four digits.
 *
 * @param   int number to format.
 */
function formatNum4(i) {
    i = parseInt(i, 10)
    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
}

/**
 * Initializes calendar window.
 */
function initCalendar(year,month,day,link1,link2,link3,link4, link5, link6, link7, link8, link9, link10, link11, link12, link13, link14, link15, link16, link17, link18, link19, link20, link21, link22, link23, link24, link25, link26, link27, link28, link29, link30, link31) {
	
	   /*year=2007;
	   month=1;
	   day=15;*/	   
	
    if (!year && !month && !day) {
        /* Called for first time */
        /*if (window.opener.dateField.value) {
            value = window.opener.dateField.value;
            if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
                if (window.opener.dateType == 'datetime') {
                    parts   = value.split(' ');
                    value   = parts[0];

                    if (parts[1]) {
                        time    = parts[1].split(':');
                        hour    = parseInt(time[0],10);
                        minute  = parseInt(time[1],10);
                        second  = parseInt(time[2],10);
                    }
                }
                date        = value.split("-");
                day         = parseInt(date[2],10);
                month       = parseInt(date[1],10) - 1;
                year        = parseInt(date[0],10);
            } else {
                year        = parseInt(value.substr(0,4),10);
                month       = parseInt(value.substr(4,2),10) - 1;
                day         = parseInt(value.substr(6,2),10);
                hour        = parseInt(value.substr(8,2),10);
                minute      = parseInt(value.substr(10,2),10);
                second      = parseInt(value.substr(12,2),10);
            }
        }*/
        if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
            dt      = new Date();
            year    = dt.getFullYear();
            month   = dt.getMonth();
            day     = dt.getDate();
        }
        if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
            dt      = new Date();
            hour    = dt.getHours();
            minute  = dt.getMinutes();
            second  = dt.getSeconds();
        }
    } else {
        /* Moving in calendar */
        if (month > 11) {
            month = 0;
            year++;
        }
        if (month < 0) {
            month = 11;
            year--;
        }
    }

    if (document.getElementById) {
        cnt = document.getElementById("calendar_data");
    } else if (document.all) {
        cnt = document.all["calendar_data"];
    }

    cnt.innerHTML = "";

    str = "";    

    str += '<table width="100" height="" border="0" cellPadding="0" cellSpacing="1" bgColor="#ffffff"><tr>';
    for (i = 0; i < 7; i++) {
        str += '<th width="92" height="20" bgcolor="#e0eef7" class="bordaAgenda"><div align="center" class="txtp10b"><B>' + day_names[i] + '</B></div></th>';
    }
    str += "</tr>";

    var firstDay = new Date(year, month, 1).getDay();
    var lastDay = new Date(year, month + 1, 0).getDate();

    str += '<tr class="bordaAgenda">';

    dayInWeek = 0;
    for (i = 0; i < firstDay; i++) {
        str += "<td>&nbsp;</td>";
        dayInWeek++;
    }
    for (i = 1; i <= lastDay; i++) {
        if (dayInWeek == 7) {
            str += '</tr><tr class="bordaAgenda">';
            dayInWeek = 0;
        }

        dispmonth = 1 + month;

        //if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
            //actVal = "" + formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
			//actVal = "" + formatNum2(i, 'day') + "/" + formatNum2(dispmonth, 'month') + "/" + formatNum4(year);
        //} else {
            actVal = "" + formatNum4(year) + formatNum2(dispmonth, 'month') + formatNum2(i, 'day');
        //}
        if (i == day) {
            style = ' class="selected"';
            current_date = actVal;
        } else {
            style = '';
        }
		/*if (dayInWeek==0) {
			cor = "#CCCCCC";
		} else if (dayInWeek==1) {
		   cor = "#FFF8F4";
	    } else if (dayInWeek==2) {
	 	   cor = "#FBFEC2";
		} else if (dayInWeek==3) {
		   cor = "#FFF5E1";  	
		} else if (dayInWeek==4) {
		   cor = "#E1FFF5";	
		} else if (dayInWeek==5) {
		   cor = "#E6E6F7";	
		} else if (dayInWeek==6) {*/
		   cor = "#DDDDDD";	
		//}	
		
		if (i==1) {
			if (!link1) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==2) {
			if (!link2) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==3) {
			if (!link3) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==4) {
			if (!link4) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==5) {
			if (!link5) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==6) {
			if (!link6) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==7) {
			if (!link7) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==8) {
			if (!link8) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==9) {
			if (!link9) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==10) {
			if (!link10) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==11) {
			if (!link11) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==12) {
			if (!link12) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==13) {
			if (!link13) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==14) {
			if (!link14) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==15) {
			if (!link15) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==16) {
			if (!link16) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==17) {
			if (!link17) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==18) {
			if (!link18) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==19) {
			if (!link19) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==20) {
			if (!link20) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==21) {
			if (!link21) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==22) {
			if (!link22) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==23) {
			if (!link23) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==24) {
			if (!link24) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==25) {
			if (!link25) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==26) {
			if (!link26) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==27) {
			if (!link27) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==28) {
			if (!link28) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==29) {
			if (!link29) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==30) {
			if (!link30) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=1040,height=700,left=0,top=0\")'>" + i + "</a></td>";
			}
		}
		
		if (i==31) {
			if (!link31) {
				cor = "#DDDDDD";	
                str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'>" + i + "</td>";
			} else {
			   cor = "#FFFFDD";	
               str += "<td bgcolor='"+cor+"' height='30' valign='top' class='txtp10'><a href='#' onClick='window.open(\"passos_video.asp?dia="+i+"&mes="+month+"&ano="+year+"\", \"Video\", \"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=480,height=403,left=0,top=0\")'>" + i + "</a></td>";
			}
		}		
        dayInWeek++;
    }
    for (i = dayInWeek; i < 7; i++) {
        str += "<td>&nbsp;</td>";
    }

    str += "</tr></table>";
	
	//heading table
    str += '<table class="calendar"><tr><th width="50%">';
    str += '<form name="form_mes" method="POST" action="videos_dia.asp">';
    //str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
    //str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
	str += '<select id="select_month" name="monthsel" onchange="form_mes.submit();">';
    for (i =0; i < 12; i++) {
        if (i == month) selected = ' selected="selected"';
        else selected = '';
        str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
    }
    str += '</select>';
    //str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
	str += ' <input type="hidden" name="yearsel" value="'+year+'">';
    str += '</form>';
    str += '</th><th width="50%">';
    str += '<form name="form_ano" method="POST" action="videos_dia.asp">';
    //str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
    //str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
	str += '<select id="select_year" name="yearsel" onchange="form_ano.submit();">';
    for (i = year - 4; i < year + 25; i++) {
        if (i == year) selected = ' selected="selected"';
        else selected = '';
        str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
    }
    str += '</select>';
    //str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
	str += ' <input type="hidden" name="monthsel" value="'+month+'">';
    str += '</form>';
    str += '</th></tr></table>';

    cnt.innerHTML = str;

    // Should we handle time also?
    //if (window.opener.dateType != 'date' && !clock_set) {

        /*if (document.getElementById) {
            cnt = document.getElementById("clock_data");
        } else if (document.all) {
            cnt = document.all["clock_data"];
        }

        str = '';
        init_hour = hour;
        init_minute = minute;
        init_second = second;
        str += '<form method="NONE" class="clock" onsubmit="returnDate(\'' + current_date + '\')">';
        str += '<input id="hour"    type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_hour, \'hour\'); init_hour = this.value;" value="' + formatNum2(hour, 'hour') + '" />:';
        str += '<input id="minute"  type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_minute, \'minute\'); init_minute = this.value;" value="' + formatNum2(minute, 'minute') + '" />:';
        str += '<input id="second"  type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_second, \'second\'); init_second = this.value;" value="' + formatNum2(second, 'second') + '" />';
        str += '<br />';
        str += '<input type="submit" value="' + submit_text + '"/>';
        str += '</form>';

        cnt.innerHTML = str;
        clock_set = 1;*/
    //}

}

/**
 * Returns date from calendar.
 *
 * @param   string     date text
 */
function returnDate(d) {
    txt = d;
    if (window.opener.dateType != 'date') {
        // need to get time
        h = parseInt(document.getElementById('hour').value,10);
        m = parseInt(document.getElementById('minute').value,10);
        s = parseInt(document.getElementById('second').value,10);
        if (window.opener.dateType == 'datetime') {
            txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
        } else {
            // timestamp
            txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
        }
    }

    window.opener.dateField.value = txt;
    window.close();
}
