
function resetCalendar()
{
	var now = new Date
	this.document.calForm.selMonth.value = now.getMonth()
	this.document.calForm.selYear.value = now.getFullYear()
	changeCal(this,true);

}
function display_mini()
{
	
	writeCalendar();


}
function maxDays(mm, yyyy){
var mDay;
	if((mm == 3) || (mm == 5) || (mm == 8) || (mm == 10)){ 
		mDay = 30;
  	}
  	else{
  		mDay = 31
  		if(mm == 1){
   			if (yyyy/4 - parseInt(yyyy/4) != 0){
   				mDay = 28
   			}
		   	else{
   				mDay = 29
  			}
		}
  }
return mDay; 
}

function changeBg(id,calWindow){
	if(!calWindow){calWindow = this;}
	if (eval("calWindow.document.getElementById('"+id+"')").style.backgroundColor != "#B9D1FA"){
		eval("calWindow.document.getElementById('"+id+"')").style.backgroundColor = "#B9D1FA"
	}
	else{
		eval("calWindow.document.getElementById('"+id+"')").style.backgroundColor = "#000000"
	}
}

function writeCalendar(calWindow,mini){


var now = new Date
var dd = now.getDate()
var mm = now.getMonth()
var dow = now.getDay()
var yyyy = now.getFullYear()

var arrM = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var arrY = new Array()
	for (ii=0;ii<=4;ii++){
		arrY[ii] = yyyy + ii
	}
var arrD = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
if(!calWindow){calWindow = this;}
var text = ""

if((selY) || (selM))
{
	dd = seldd
 	mm = selM
 	yyyy = selY
	
}

else
{
	
	var dd = now.getDate()
	var mm = now.getMonth()	
	var yyyy = now.getFullYear() 
	seldd = dd
	selM = mm
	selY = yyyy
	
}

text = "<form name=calForm>"

text += "<table bgcolor='#B9D1FA' cellpadding='0' border=1>"

text += "<tr><td class='user_setting_tableheader'>"
text += "<table width=50% cellpadding='0'><tr>"
text += "<td align=left class='user_setting_tableheader'>"
text += "<select name=selMonth onChange=\"changeCal(this," + mini + ")\">"
	for (ii=0;ii<=11;ii++){
		if (ii==selM)
		{
			 text += "<option value= " + ii + " Selected>" + arrM[ii] + "</option>" 
		}
		else if(ii==mm){
			text += "<option value= " + ii + " Selected>" + arrM[ii] + "</option>"
		}
		else{
			text += "<option value= " + ii + ">" + arrM[ii] + "</option>"
		}
	}
text += "</select>"
text += "</td>"

text += "<td align=right class='user_setting_tableheader'>"
text += "<select name=selYear onChange=\"changeCal(this," + mini + ")\">"
	for (ii=0;ii<=4;ii++){
		//if (ii==0){
		//	text += "<option value= " + arrY[ii] + " Selected>" + arrY[ii] + "</option>"
		//}
                  if(arrY[ii] == selY){
                       text += "<option value= " + arrY[ii] + " Selected>" + arrY[ii] + "</option>"
                 }
		else{		
			text += "<option value= " + arrY[ii] + ">" + arrY[ii] + "</option>"
		}
	}
text += "</select>"
text += "</td>"
text += "</tr></table>"
text += "</td></tr>"

text += "<tr><td>"
text += "<table border=0 cellpadding='0'>"
text += "<tr>"
	for (ii=0;ii<=6;ii++){
		text += "<td align=center><span class=label><font size='1'>" + arrD[ii] + "</span></font></td>"
	}
text += "</tr>"

aa = 0

	for (kk=0;kk<=5;kk++){
		text += "<tr>"
		for (ii=0;ii<=6;ii++){
			text += "<td align=center width=10%><span id=sp" + aa + " onClick='changeBg(this.id)'><font size='1'>1</font></span></td>"
			aa += 1
		}
		text += "</tr>"
	}
text += "</table>"
text += "</td></tr>"
text += "</table>"
text += "</form>"

calWindow.document.write(text)
changeCal(calWindow,mini)

}


function changeCal(calWindow,mini){

var now = new Date
var dd = now.getDate()
var mm = now.getMonth()
var dow = now.getDay()
var yyyy = now.getFullYear()
	
if(!calWindow || calWindow != this){calWindow = this;}


var currM = parseInt(calWindow.document.calForm.selMonth.value)
var prevM
	if (currM!=0){
		prevM = currM - 1
	}
	else{
		prevM = 11
	}

var currY = parseInt(calWindow.document.calForm.selYear.value)


var mmyyyy = new Date()
mmyyyy.setFullYear(currY,currM,1)

var day1 = mmyyyy.getDay()
	if (day1 == 0){
		day1 = 7
	}

var arrN = new Array(41)
var aa

	for (ii=0;ii<day1;ii++){
		arrN[ii] = maxDays((prevM),currY) - day1 + ii + 1
	}

	aa = 1
	for (ii=day1;ii<=day1+maxDays(currM,currY)-1;ii++){	
		arrN[ii] = aa
		aa += 1
	}
	
	aa = 1
	for (ii=day1+maxDays(currM,currY);ii<=41;ii++){
		arrN[ii] = aa
		aa += 1
	}

	for (ii=0;ii<=41;ii++){
		eval("calWindow.document.getElementById('sp"+ii+"')").style.backgroundColor = "#B9D1FA"
	}

var dCount = 0
var month = currM + 1
	for (ii=0;ii<=41;ii++){		
		if (((ii<7)&&(arrN[ii]>20))||((ii>27)&&(arrN[ii]<20))){
			eval("calWindow.document.getElementById('sp"+ii+"')").innerHTML = ""
			eval("calWindow.document.getElementById('sp"+ii+"')").className = "c3"	
		}

		else{

                  if(mini)
                  {
                  	var setDate = '' + arrN[ii] + '/' + month + '/' + currY + '';
                  	
                  	eval("calWindow.document.getElementById('sp"+ii+"')").innerHTML = "<a href=\"javascript:void()\" onClick=\"insertDate('" + setDate + "')\"><font size='1'>" + arrN[ii]+ "</a>"
                  }
                  else
                  {
	                  eval("calWindow.document.getElementById('sp"+ii+"')").innerHTML = "<a href='?page=calendercenter&month=" + month + "&day=" + arrN[ii]+ "&year=" + currY+"'><font size='1'>" + arrN[ii]+ "</a>"
	          }
			if ((dCount==0)||(dCount==6)){
				eval("calWindow.document.getElementById('sp"+ii+"')").className = "c2"
			}
			else{
				eval("calWindow.document.getElementById('sp"+ii+"')").className = "c1"
			}
			
			if ((arrN[ii]==seldd)&&(mm==selM)&&(yyyy==selY)){
				
				eval("calWindow.document.getElementById('sp"+ii+"')").style.backgroundColor="grey"
			}
			if ((arrN[ii]==dd)&&(mm==currM)&&(yyyy==currY)){
				
				//eval("calWindow.document.getElementById('sp"+ii+"')").style.backgroundColor="#90EE90"
			}
			
		}
	dCount += 1
		if (dCount>6){
			dCount=0
		}
	}
}

 

