
function makeToolbarImage() {
	for(var i = 0; i < document.images.length; i++) {
		var image = document.images[i];

		if (image.className == "toolbar" ||
			image.className == "button") {
			addEvent(image, "mouseover", toolbarIconOver);
			addEvent(image, "mouseout", toolbarIconOver);
			addEvent(image, "mousedown", toolbarIconOver);
		}
	}
}

function toggleContact(checkbox) {
	for (n in {'order': '', 'committee': ''}) {
		var element = document.getElementById(n);
		if (!element)
			continue;

		with (element) {
			if (checkbox.checked) {
				removeAttribute('disabled');
				style.background = '';
				continue;
			}

			setAttribute('disabled', 'true');
			style.background = '#d1d1d1';
		}
	}
}

function updateLoginValue() {	
	var nameInput = document.getElementById('nameInput');
	var surnameInput = document.getElementById('surnameInput');
	var loginInput = document.getElementById('loginInput');

	if (surnameInput.value.length != 0 || nameInput.value.length != 0)
		var loginValue = surnameInput.value + "." + nameInput.value;
	else
		var loginValue = "";

	loginInput.value = loginValue.toLowerCase();
}

function addEvent(obj, eventType, funcName)
{
	if (obj.addEventListener) {
		obj.addEventListener(eventType, funcName, true);
	} else if (obj.attachEvent) {
		eventType = "on" + eventType;
		obj.attachEvent(eventType, funcName);
	}
}

function opacity(image, intValue)
{
	if (typeof image.style.filter != 'undefined')
		image.style.filter = "progid:DXImageTransform.Microsoft.Alpha"+
			"(style=0,opacity=" + (intValue * 100) + ")";
	else if (typeof image.style.MozOpacity != 'undefined')
		image.style.MozOpacity = intValue;
	else if (typeof image.style.KhtmlOpacity != 'undefined')
		image.style.KhtmlOpacity = intValue;
	else
		image.style.opacity = intValue;

}

function toolbarIconOver(e)
{
	if (e.target)
		var image = e.target;
	else if (e.srcElement)
		var image = e.srcElement;

	var	type = e.type;

	if (!image)
		return 0;

	if (type.match("mouseover"))
		opacity(image, 0.5);
	else if (type.match("mouseout"))
		opacity(image, 1.5);
	else if (type.match("mousedown"))
		opacity(image, 0.3);
}

function formCalSub(strValue, strInputId)
{
	var input = document.getElementById(strInputId);
	
	if(input)
		input.value = strValue;

	document.getElementById('date').submit();
}

function delay(gap)
{ 
	var then = new Date().getTime();
	var now = then;
	
	while((now-then) < gap) {
		now = new Date().getTime();
	}
}

function showInfoEvent(e)
{
	if (e.target)
		var target = e.target;
	else if (e.srcElement)
		var target = e.srcElement;

	var info = target.getElementsByTagName("div")[0];
	var	type = e.type;

	if (!info)
		return 0;

	var filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader" +
				 "(src='/img/calendar/info-background.png'," +
				 "enabled=true,sizingMethod=scale);";

	if (typeof info.style.filter != 'undefined')
		info.style.filter = filter;
	else		
		info.style.backgroundImage = "url('img/calendar/info-background.png')";

	if (type.match("mouseover")) {
		delay(80);
	}

	if (type.match("mouseover") ||
		type.match("mousemove")) {			
		
		info.style.display = "block";
		var mouse = new Object;
		
		if (e.pageX || e.pageY) {
			mouse.x = e.pageX;
			mouse.y = e.pageY;
		} else if (e.clientX || e.clientY) {
			mouse.x = e.clientX;
			mouse.y = e.clientY;
		}

		if (mouse.x > (document.body.clientWidth / 2))
			margX = -145;
		else
			margX = 5;
		
		if (mouse.y > (document.body.clientHeight / 2))
			margY = -80;
		else
			margY = 10;

		info.style.left = mouse.x + margX;
		info.style.top = mouse.y + margY;
	
	} else if (type.match("mouseout")) {
		info.style.display = "none";
	}
}

function deleteConfirm(sMessage, sLocation)
{
	var retBool = window.confirm(sMessage);
	if (retBool) window.location = sLocation;
}


