function findChildNodeByName(elm, name) {
	var i, x;

	for (i = 0; i < elm.childNodes.length; i++) {
		if (elm.childNodes[i].nodeName == name) {
			return elm.childNodes[i];
		}
		if (elm.childNodes[i].hasChildNodes) {
			if (x = findChildNodeByName(elm.childNodes[i], name)) return x;
		}
	}
	return null;
}

/* show colors on schedule pages */
function showColor(col, row, val){
	var elm;
	strCell = col + "_" + row;
	if (elm = document.getElementById(strCell)) {
		switch (val) {
			case 0:
				elm.style.backgroundColor = "#DBE6EB";
				break;
			case 1:
				elm.style.backgroundColor = "#C2D3A7";
				break;
			case 2:
				elm.style.backgroundColor = "#E6C09F";
				break;
			case 3:
				elm.style.backgroundColor = "#F1D47A";
				break;
			default:
				break;
		}
	}
	return;
}

function generateOpeningHoursTable() {
	var s = "", row, col, strStyle = "";
	var hours = new Array;

	for (var i = 0; i < 7; i++) {
	    hours[i] = eval("str" + i).split(",");
	}
	// ******** fix for IE 7 browsers ********
	var isIE = (navigator.userAgent.toLowerCase().indexOf("msie") > 0) ? 1:0;
	var isFire = (navigator.userAgent.toLowerCase().indexOf("firefox") > 0) ? 1:0;
	var IE7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? 0: 1;
	var SceHeight3 = "";
	var SceHeight4 = "";

	if(!IE7 && !isFire ) {
		strStyle = " style=\"height:15px;\" ";
		SceHeight3 = "Height3 ";
		SceHeight4 = "Height4 ";
	} else if(!IE7 && isFire ) {
		strStyle = " style=\"height:17px;\" ";
		SceHeight3 = "Height6 ";
		SceHeight4 = "Height6 ";
	} else {
		strStyle = " style=\"height:14px;\" ";
		SceHeight3 = "Height6 ";
		SceHeight4 = "Height6 ";
	}
	// ********
	s += "<table id=\"openingHoursGrid\"><thead><tr>";
	s += "<th class=\"empty\"" + strStyle +"></th>"
	s += "<th" + strStyle +">"+arrWeekday[0]+"</th><th" + strStyle +">"+arrWeekday[1]+"</th><th" + strStyle +">"+arrWeekday[2]+"</th><th" + strStyle +">"+arrWeekday[3]+"</th><th" + strStyle +">"+arrWeekday[4]+"</th><th" + strStyle +">"+arrWeekday[5]+"</th><th" + strStyle +">"+arrWeekday[6]+"</th>";
	s += "</tr></thead><tbody>";
	for (row = 0; row < 48; row++) {
		s += "<tr><td class=\"empty\"></td>";
		for (col = 0; col < 7; col++) {
			s += "<td class=\"serviceType" + hours[col][row] + "Color";
			if ((row + 1) % 2) {
				s += " noBottomBorder " + SceHeight3 ;
			} 
			else {
				s += " " + SceHeight4 ;
			}
			x = row;
			s += "\" title=\"";
			s += (x / 2 > 9.5) ? Math.floor(x / 2) : "0" + Math.floor(x / 2);
			s += (x / 2 == Math.floor(row / 2)) ? ":00" : ":30";
			s += " - ";
			x = row + 1;
			s += (x / 2 > 9.5) ? Math.floor(x / 2) : "0" + Math.floor(x / 2);
			s += (x / 2 == Math.floor(x / 2)) ? ":00" : ":30";
			s += "\"></td>";
		}
		s += "<td class=\"lastColumn\"></td></tr>\n";
	}
	s += "<tr class=\"lastRow\"><td colspan=\"8\"></tr></table>";
//	if (elm = document.getElementById("gridTableBody")) {
	if (elm = document.getElementById("openingHoursGridPlaceHolder")) {
		elm.innerHTML = s;
	}
	return;
}

function setGridColors() {
	var strCol, str, arr;
	for (i = 1; i < 8; i++) {
		switch(i) {
			case 1:
				strCol = "a";
				break;
			case 2:
				strCol = "b";
				break;
			case 3:
				strCol = "c";
				break;
			case 4:
				strCol = "d";
				break;
			case 5:
				strCol = "e";
				break;
			case 6:
				strCol = "f";
				break;
			case 7:
				strCol = "g";
				break;
			default:
				break;
		}
		str = eval("str" + i);
		arr = str.split(",");
		for(j = 0; j < arr.length; j++) {
			showColor(strCol, j, arr[j]);
		}
	}
	return;
}

function init() {
	if (document.getElementById("openingHoursGridPlaceHolder")) {
		generateOpeningHoursTable()
		// setGridColors();
	}
	return;
}

window.onload = init;


