
function submit_form(destiny) {
	document.theform.action = destiny;
	document.theform.submit();
}

function createWindow(url, WinName, theWidth, theHeight){
	//var winLeft = (screen.width - theWidth) / 2;
	//var winTop = (screen.height - theHeight) / 2;
	//window.open(url, WinName, 'titlebar.maximize=no, scrollbars=no, resizable=no, width=' + theWidth + ', height=' + theHeight + ', left=' + winLeft + ', top=' + winTop);
	window.open(url, WinName, 'statusbar=no, toolbar=no, menubar=no, titlebar=no, scrollbars=no, resizable=no, width=' +theWidth + ', height=' + theHeight + ', left=100, top=100');
}

function createScrollingWindow(url, WinName, theWidth, theHeight){
        var winLeft = (screen.width - theWidth) / 2;
        var winTop = (screen.height - theHeight) / 2;
        window.open(url, WinName, 'titlebar.maximize=no, scrollbars=yes, resizable=no, width=' + theWidth + ', height=' + theHeight + ', left=' + winLeft + ', top=' + winTop);
}


function num_month(month){
	switch(month){
		case "Janeiro":
			return "01";
			break;
		case "Fevereiro":
			return "02";
			break;
		case "Março":
			return "03";
			break;
		case "Abril":
			return "04";
			break;
		case "Maio":
			return "05";
			break;
		case "Junho":
			return "06";
			break;
		case "Julho":
			return "07";
			break;
		case "Agosto":
			return "08";
			break;
		case "Setembro":
			return "09";
			break;
		case "Outubro":
			return "10";
			break;
		case "Novembro":
			return "11";
			break;
		case "Dezembro":
			return "12";
			break;
	}
}

function make_calendar(baselink, usrdate, usrmonth, usryear, wname){
	monthnames = new Array(
		"Janeiro",
		"Fevereiro",
		"Março",
		"Abril",
		"Maio",
		"Junho",
		"Julho",
		"Agosto",
		"Setembro",
		"Outubro",
		"Novembro",
		"Dezembro");
	
	var linkcount=0;
	linkdays = new Array();
	monthdays = new Array(12);
	monthdays[0]=31;
	monthdays[1]=28;
	monthdays[2]=31;
	monthdays[3]=30;
	monthdays[4]=31;
	monthdays[5]=30;
	monthdays[6]=31;
	monthdays[7]=31;
	monthdays[8]=30;
	monthdays[9]=31;
	monthdays[10]=30;
	monthdays[11]=31;

	todayDate=new Date();
	if (usrmonth != "") {
		usrmonth = usrmonth - 1;
	}
	if (usrdate == 0) {
		usrdate = todayDate.getDate();
	}
	if ((usrmonth != "") && (usryear != "")) {
		todayDate=new Date(usryear,usrmonth,usrdate);
	}
	thisday=todayDate.getDay();
	thismonth=todayDate.getMonth();
	thisdate = todayDate.getDate();
	
	thisyear=todayDate.getYear();
	thisyear = thisyear % 100;
	thisyear = ((thisyear < 50) ? (2000 + thisyear) : (1900 + thisyear));

	//document.write("Dia de hoje: " + thisdate + "<br>");
	
	if (((thisyear % 4 == 0) && !(thisyear % 100 == 0)) || (thisyear % 400 == 0)) 
		monthdays[1]++;

	startspaces=thisdate;
	while (startspaces > 7) 
		startspaces-=7;

	startspaces = thisday - startspaces + 1;
	if (startspaces < 0) 
		startspaces+=7;
	document.write("<table width=\"10%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">");
    document.write("    <tr align=\"center\">  ");
    document.write("      <td width=\"13%\" bgcolor=\"#f5fbff\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">Dom</font></td> ");
    document.write("      <td width=\"17%\" bgcolor=\"#f5fbff\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">Seg</font></td> ");
    document.write("      <td width=\"13%\" bgcolor=\"#f5fbff\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">Ter</font></td> ");
    document.write("      <td width=\"15%\" bgcolor=\"#f5fbff\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">Qua</font></td> ");
    document.write("      <td width=\"13%\" bgcolor=\"#f5fbff\"><font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">Qui</font></td> ");
    document.write("      <td width=\"14%\" bgcolor=\"#f5fbff\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">Sex</font></td> ");
    document.write("      <td width=\"15%\" bgcolor=\"#f5fbff\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">Sab</font></td> ");
    document.write("    </tr> ");


    document.write("    <tr align=\"center\">  ");
	for (s=0;s<startspaces;s++) {
		document.write("<td width=\"13%\" bgcolor=\"#e5e1ee\"><font color=\"#ffffff\" face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"> </td>");
	}
	count=1;
	while (count <= monthdays[thismonth]) {
		for (b = startspaces; b<7; b++) {
			linktrue=false;

			//Aqui abre-se a coluna do dia
			document.write("      <td width=\"13%\" bgcolor=\"#e5e1ee\"><font color=\"#ffffff\" face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"> ");
			//Monta o link correspondente a cada dia...
			if (count <= monthdays[thismonth]) {
				url = baselink + "dia=" + count + "&mes=" + num_month(monthnames[thismonth]) + "&ano=" + thisyear;
				if(wname == ""){
					url = "<a class=\"calend\" href=\"" + url + "\">"
				}
				else{
					url = "<a class=\"calend\" href=\"javascript:createScrollingWindow('" + url + "', '" + wname + "', 640, 480);\">"
				}
				document.write(url + '<font color=#777777>');
				if(usrdate <= 0){
					if (count==thisdate) {
						document.write("<font color=\"#000000\">" + count + "</font>");
					}
					else{
						document.write(count);
					}
				}
				else{
					if (count==usrdate) {
						document.write("<font color=\"#000000\">" + count + "</font>");
					}
					else{
						document.write(count);
					}
				}
				document.write("</a>");
			}
			else {
				document.write("&nbsp;");
			}

			//Fecha a coluna e o dia, e continua...
			document.write("		</td>");
			count++;
		}
		document.write("	</tr>");
	    document.write("    <tr align=\"center\">  ");
		startspaces=0;
	}
	
	document.write("	<tr align=\"center\" bgcolor=\"#f5fbff\"> ");
    document.write("      <td colspan=\"7\"> ");
    document.write("        <div align=\"right\"><font size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#999999\"><b>" + monthnames[thismonth] + "/" + thisyear + "</b></font></div>");
    document.write("      </td>");
    document.write("    </tr>");
	document.write("</table>");
}
