var langObj_he = new Object();
langObj_he.direction = "rtl";
langObj_he.lang = "he";
langObj_he.days = ["א","ב","ג","ד","ה","ו","ש"];
langObj_he.months = ["ינואר","פברואר","מרץ","אפריל","מאי","יוני","יולי","אוגוסט","ספטמבר","אוקטובר","נובמבר","דצמבר"];
langObj_he.today = "עבור להיום";
langObj_he.restDay = 6;
//--------------------------------------------------
var langObj_en = new Object();
langObj_en.direction = "ltr";
langObj_en.direction = "en";
langObj_en.days = ["S","M","T","W","T","F","S"];
langObj_en.months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
langObj_en.today = "Today";
langObj_en.restDay = 1;

var gifSrc = "/htm-webaxy/multimedia/r1.gif";
//===================================================================
//  
//  createMiniCal: insert miniCal into div 
//  
//===================================================================
function createMiniCal(divid,url,date,lang,restDay) {
	if (!date) {
		date = new Date();
	}
	else if (typeof date == "string") {
		var d = date.split(/\D+/);
		date = new Date(d[2],d[1] - 1,d[0]);
	}
	else if ((typeof date == "object") && date.getTime) {
		// ok...
	}
	else {
		date = new Date();
	}
	date.setHours(12); date.setMinutes(0); date.setSeconds(0); date.setMilliseconds(0);		// summer clock problem fix
	var dd = date.getDate();
	var mm = date.getMonth()+1;
	var yyyy = date.getFullYear();
	var plusYearString = 1+"/"+mm+"/"+(yyyy + 1);
	var plusMonthString = 1+"/"+((mm == 12) ? 1 : mm+1)+"/"+((mm == 12) ? yyyy+1 : yyyy);
	var minusYearString = 1+"/"+mm+"/"+(yyyy - 1);
	var minusMonthString = 1+"/"+((mm == 1) ? 12 : mm - 1)+"/"+((mm == 1) ? yyyy-1 : yyyy);
	
	var div = document.getElementById(divid);
	div.className = "calDiv";
	while (div.firstChild) {
		div.removeChild(div.firstChild);
	}
	
	url = unescUrl(url);
	
	if (!lang) {
		lang = "he";
	}
	
	var langObj = null;
	try {
		langObj = eval("langObj_"+lang);
	}
	catch(e) {
		langObj = langObj_he;
	}
	if (!restDay) {
		restDay = langObj.restDay;
	}
	
	var nowDate = new Date();
	nowDate.setHours(12); nowDate.setMinutes(0); nowDate.setSeconds(0); nowDate.setMilliseconds(0);		// summer clock problem fix
	var now_dd = nowDate.getDate();
	var now_mm = nowDate.getMonth()+1;
	var now_yyyy = nowDate.getFullYear();
	var todayString = now_dd+"/"+now_mm+"/"+now_yyyy;
		
	// table0
	var calTable = document.createElement("table");
	calTable.className = "calTable0";
	calTable.id = divid+calTable.className;
	calTable.style.direction = langObj.direction;
	calTable.setAttribute("cellpadding","0");
	calTable.setAttribute("cellspacing","0");
	// row0
	var newRow = calTable.insertRow(-1);
	newRow.className = "calRow0";
	newRow.id = divid+newRow.className;
	var newTd = newRow.insertCell(-1);
	newTd = newRow.insertCell(-1);
	newTd = newRow.insertCell(-1);
	
	newRow.cells[0].className = "minusTD";
	newRow.cells[0].id = divid+newRow.cells[0].className;
	var gif = document.createElement("img");
	gif.src = gifSrc;
	gif.className = "minusYearGif";
	gif.id = divid+gif.className;
	gif.onclick = new Function("createMiniCal('"+divid+"','"+escUrl(url)+"','"+minusYearString+"','"+lang+"','"+restDay+"')");
	newRow.cells[0].appendChild(gif);
	gif = document.createElement("img");
	gif.src = gifSrc;
	gif.className = "minusMonthGif";
	gif.id = divid+gif.className;
	gif.onclick = new Function("createMiniCal('"+divid+"','"+escUrl(url)+"','"+minusMonthString+"','"+lang+"','"+restDay+"')");
	newRow.cells[0].appendChild(gif);
	
	newRow.cells[1].className = "monthTD";
	newRow.cells[1].id = divid+newRow.cells[1].className;
	//newRow.cells[1].innerHTML = langObj.months[date.getMonth()] + " " + date.getFullYear();
	var cellText = langObj.months[date.getMonth()] + " " + date.getFullYear();
	newRow.cells[1].appendChild(document.createTextNode(cellText));
	newRow.cells[2].className = "plusTD";
	newRow.cells[2].id = divid+newRow.cells[2].className;
	gif = document.createElement("img");
	gif.src = gifSrc;
	gif.className = "plusMonthGif";
	gif.id = divid+gif.className;
	gif.onclick = new Function("createMiniCal('"+divid+"','"+escUrl(url)+"','"+plusMonthString+"','"+lang+"','"+restDay+"')");
	newRow.cells[2].appendChild(gif);
	
	gif = document.createElement("img");
	gif.src = gifSrc;
	gif.className = "plusYearGif";
	gif.id = divid+gif.className;
	gif.onclick = new Function("createMiniCal('"+divid+"','"+escUrl(url)+"','"+plusYearString+"','"+lang+"','"+restDay+"')");
	newRow.cells[2].appendChild(gif);
	div.appendChild(calTable);
	
	// table1
	calTable = document.createElement("table");
	calTable.className = "calTable1";
	calTable.id = divid+calTable.className;
	calTable.style.direction = langObj.direction;
	calTable.setAttribute("cellpadding","0");
	calTable.setAttribute("cellspacing","0");
	// row1
	newRow = calTable.insertRow(-1);
	newRow.className = "nameDayRow";
	newRow.id = divid+newRow.className;
	for (var d = 0; d < 7; d++) {
		newTd = newRow.insertCell(-1);
		newTd.className = (d != restDay) ? "nameDay" : "nameRestDay";
		newTd.id = divid+"nameDay"+d;
		//newTd.innerHTML = langObj.days[d];
		cellText = langObj.days[d];
		newTd.appendChild(document.createTextNode(cellText));
	}
	
	date.setDate(1);
	date.setHours(12); date.setMinutes(0); date.setSeconds(0); date.setMilliseconds(0);		// summer clock problem fix
	
	var idx = date.getDay();
	date.setTime(date.getTime() - 86400000*idx);	// # first day in table
	date.setHours(12); date.setMinutes(0); date.setSeconds(0); date.setMilliseconds(0);		// summer clock problem fix
	
	// days
	var dayClass = "notThisMonthDay";
	for (var week = 0; week < 6; week++) {
		newRow = calTable.insertRow(-1);
		newRow.className = "weekRow";
		newRow.id = divid+newRow.className+week;
		for (var d = 0; d < 7; d++) {
			var day = date.getDate();
			if (day == 1) {
				dayClass = (dayClass == "notThisMonthDay") ? "thisMonthDay" : "notThisMonthDay";
			}
			newTd = newRow.insertCell(-1);
			
			if (nowDate.getTime() == date.getTime()) {
				newTd.className = "todayClass";
			}
			else if (restDay == date.getDay()) {
				newTd.className = "restDay";
			}
			else {
				newTd.className = dayClass;
			}
			newTd.setAttribute("mainClassName",newTd.className);		// for onmouseover
			newTd.id = divid+"_"+week+"_"+d+"_td";
			var dd = date.getDate();
			var mm = date.getMonth()+1;
			var yyyy = date.getFullYear();
			var dateString = dd+"%2F"+mm+"%2F"+yyyy;
			var dayUrl = url.replace(/%%DATE%%/g,dateString);
			newTd.onclick = new Function("goCalUrl('"+escUrl(dayUrl)+"')");
			newTd.onmouseover = new Function("calDayOver(this)");
			newTd.onmouseout = new Function("calDayOut(this)");
			newTd.title = dd+"/"+mm+"/"+yyyy;
			daya = document.createElement("a");
			daya.href = dayUrl;
			daya.onclick = new Function("return false;");
			daya.className = newTd.className+"Link";
			daya.setAttribute("mainClassName",daya.className);		// for onmouseover
			daya.id = divid+"_"+week+"_"+d+"_a";
			//daya.innerHTML = day;
			cellText = day;
			daya.appendChild(document.createTextNode(cellText));
			newTd.appendChild(daya);
			
			date.setTime(date.getTime() + 86400000);	// # next day in table
			date.setHours(12); date.setMinutes(0); date.setSeconds(0); date.setMilliseconds(0);		// summer clock problem fix
		}
	}
	div.appendChild(calTable);
	// table2
	var calTable = document.createElement("table");
	calTable.className = "calTable2";
	calTable.id = divid+calTable.className;
	calTable.style.direction = langObj.direction;
	calTable.setAttribute("cellpadding","0");
	calTable.setAttribute("cellspacing","0");
	// row2
	var newRow = calTable.insertRow(-1);
	newRow.className = "goToTodayTr";
	newRow.id = divid+newRow.className;
	var newTd = newRow.insertCell(-1);
	newTd.className = "goToTodayTd";
	newTd.id = divid+newTd.className;
	var todaya = document.createElement("a");
	
	
	//todaya.innerHTML = langObj.today+" "+todayString;
	cellText = langObj.today+" "+todayString;
	todaya.appendChild(document.createTextNode(cellText));
	todaya.href = "javascript:void(0);";
	todaya.setAttribute("target","_self");
	todaya.className = "goToTodayLink";
	todaya.id = divid+todaya.className;
	todaya.onclick = new Function("createMiniCal('"+divid+"','"+escUrl(url)+"','"+todayString+"','"+lang+"','"+restDay+"')");
	newTd.appendChild(todaya);
	div.appendChild(calTable);
	//alert(div.innerHTML);
}
//===================================================================
//  
//  goCalUrl: do 
//  
//===================================================================
function goCalUrl(url) {
	url = unescUrl(url);
	location.href = url;
}

//===================================================================
//  
//  name: do 
//  
//===================================================================
function calDayOver(td) {
	td.className = "mouseOverDay";
	td.firstChild.className = "mouseOverDayLink";
}
//===================================================================
//  
//  name: do 
//  
//===================================================================
function calDayOut(td) {
	td.className = td.getAttribute("mainClassName");
	td.firstChild.className = td.firstChild.getAttribute("mainClassName");
}
//===================================================================
//  
//  name: do 
//  
//===================================================================
function escUrl(url) {
	url = url.replace(/\"/g,"&#34;");
	url = url.replace(/\'/g,"&#39;");
	return url;
}
//===================================================================
//  
//  name: do 
//  
//===================================================================
function unescUrl(url) {
	url = url.replace(/\&\#34;/g,"\"");
	url = url.replace(/\&\#39;/g,"\'");
	return url;
}


