var indexPageHref = location.protocol + "//www.stuha.net/stuha7/";

function useLoadingMessage(message) {

	var loadingMessage = message || "probíhá přenos dat, čekejte prosím ...";

	dwr.engine.setPreHook(function() {
		var disabledZone = document.getElementById("disabledZone");

		if (!disabledZone) {
			var disabledZone = document.createElement("div");			

			disabledZone.setAttribute("id", "disabledZone");
			document.body.appendChild(disabledZone);

			var messageZone = document.createElement("div");
			messageZone.setAttribute("id", "messageZone");
			disabledZone.appendChild(messageZone);

			var text = document.createTextNode(loadingMessage);
			messageZone.appendChild(text);

		} else {

			document.getElementById("messageZone").innerHTML = loadingMessage;
			disabledZone.style.visibility = "visible";
		}
	});

	dwr.engine.setPostHook(function() {
		document.getElementById("disabledZone").style.visibility = "hidden";
	});
}

String.prototype.unSecureAddress = function () {
	var url = this.replace(":8443/", ":8080/");

	if (url.substring(0, 5) == "https") {
		return "http" + url.substring(5);
	} else {
		return url;
	}
}

String.prototype.securizeAddress = function () {
	var url = this.replace(":8080/", ":8443/");

	if (url.substring(0, 5) == "http:") {
		return "https:" + url.substring(5);
	} else {
		return url;
	}
}

//////////////////////// handy method for clearing contents of the element
//NOT ALLOWED IN IE// Element.prototype.emptyNode = function () {};
function emptyNode(node) {
	while (node.childNodes.length > 0) {
		node.removeChild(node.childNodes[0]);
	}
}


/////////////////////// Date Functions

Date.prototype.getFormatted = function (mode) {
	var date = this;
	var mode = mode || "full";

	var days = new Array ("Wo", "Po", "Út", "St", "Čt", "Pá", "So", "Ne");
	var months = new Array ("ledna", "února", "března", "dubna", "května", "června", "července",
								"srpna", "září", "října", "listopadu", "prosince");
	var dayInWeek = date.getDay();
	if (!dayInWeek) //Sunday
		dayInWeek = 7;
	
	var hod = date.getHours().toString();
	var min = date.getMinutes().toString();
	var sec = date.getSeconds().toString();
	
//	E d. MMMMM yyyy[, HH:mm[:ss]]
	var text = "";
	switch (mode) {
		case "full":
		// adding seconds
			text = ":"
				+ ((sec.length == 1) ? "0" : "")
				+ sec;
		case "no-seconds":
		// adding hours and minutes
			text = ", "
				+ ((hod.length == 1) ? "0" : "")
				+ hod + ":"
				+ ((min.length == 1) ? "0" : "")
				+ min + text;
		case "no-hours":
		// adding date
			text = days[dayInWeek] + " " + date.getDate() + ". " + months[date.getMonth()] + " " + date.getFullYear() + text;
	}
	return text;
}

Date.prototype.getWeek = function() {
	var date = this;

	var date0 = new Date(date.getFullYear(), 0, 1); // 1st January
	return Math.ceil((((date - date0)/86400000) + date0.getDay2())/7);
}
Date.prototype.getDay2 = function() {
	// javascript days (0 - Sunday, ..., 6 - Saturday
	// my days (0 - Monday, 6 - Sunday)
	var day = this.getDay(); 
	return (day === 0) ? '7': (day);
}
Date.prototype.oddWeek = function() {
	return this.getWeek()%2 ? false : true;
}