// Loads event handlers
function LoadEvents()
{
	try
	{
		var headings = document.getElementById("newsList_0").getElementsByTagName("tr");
		for (var i=0; i < headings.length; i++)
		{
			if (headings[i].className != 'active')
			{
				headings[i].onmouseover = headings[i].onmouseout = function() { FocusNewsItem(this) };
			}
		}
	}
	catch(e) {};
	
	try
	{
		var pictures = document.getElementById("galeria").getElementsByTagName("img");
		for (var i=0; i < pictures.length; i++)
		{
			pictures[i].onclick = function() { SelectImage(this) };
		}
		
		var links = document.getElementById("galeria").getElementsByTagName("a");
		for (var i=0; i < links.length; i++)
		{
			links[i].onfocus = function() { this.blur() };
		}
	}
	catch(e) {};
}

// Adds mouseover effects to the start page
function FocusNewsItem(sender)
{
	if (sender.getElementsByTagName("h3")[0])
	{
		sender.className = (sender.className != 'active' ? 'active' : '');
	}
	
	if (sender.getElementsByTagName("img")[0])
	{
		var image = sender.getElementsByTagName("img")[0];
		image.className = (image.className != 'blurredImage' ? 'blurredImage' : 'focusedImage');
	}
}

// Selects current image in the gallery
function SelectImage(image)
{
	if (image.id == "activeImage") { return; }
	
	document.getElementById("activeImage").removeAttribute("id");
	image.id = "activeImage";
}

/*Radio Button and checkbox beta version*/
	function Checkbox(name, value, checked, id)
	{
		this.button = null;
		this.checked = checked;
		this.initializedComponent();
		this.button.className = 'hidden_component';
		this.button.name = name;
		this.button.value = value;
		this.button.id = id;
		this.button.defaultChecked = checked;
		
		
		this.custom_button = document.createElement('label');
		this.custom_button.par_button = this.button;
		this.custom_button.className = 'checkbox' + (this.checked ? ' ch_checked' : '');
		this.custom_button.onclick = function(){this.par_button.click();};
		
		this.button.custom_button = this.custom_button;
		this.changeCheckedListener();
	}
	
	Checkbox.prototype.changeCheckedListener = function()
	{
		this.button.onclick = function()
		{
			this.custom_button.className = 'checkbox' + (this.checked ? ' ch_checked' : '');
		}
	}
	
	Checkbox.prototype.writeComponent = function(id_element)
	{
		var obj = document.getElementById(id_element);
		obj.appendChild(this.button);
		obj.appendChild(this.custom_button);
	}
	
	Checkbox.prototype.initializedComponent = function()
	{
		this.button = document.createElement('input');
		this.button.type = 'checkbox';
	}
	
	var radio_button_reference = [];
	function changeRadioButtonChecked(sender)
	{
		if (radio_button_reference[sender.name]) 
		{
			radio_button_reference[sender.name].custom_button.className = 'radio';
			radio_button_reference[sender.name].checked = false;
			radio_button_reference[sender.name].defaultChecked = false;
		}
		
		sender.checked = sender.defaultChecked = true;
		sender.custom_button.className = 'radio r_checked';
		radio_button_reference[sender.name] = sender;
	}
	
	RadioButton.prototype = new Checkbox;
	RadioButton.constructor = RadioButton;
	
	function RadioButton(name, value, checked, id)
	{
		Checkbox.call(this, name, value, checked, id);
		this.custom_button.className = 'radio';
		if (this.checked)
		{
			changeRadioButtonChecked(this.button);
		}
	}
	
	RadioButton.prototype.changeCheckedListener = function()
	{
		this.button.onclick = function()
		{
			changeRadioButtonChecked(this);
		}
	}
	
	RadioButton.prototype.initializedComponent = function()
	{
		this.button = document.createElement((!window.ActiveXObject ? 'input' : '<input type="radio">'));
		this.button.type = 'radio';
	}
/*end radio button and checkbox*/

/*Update Label file field*/
function updateFileField(oFileField, index)
{
	document.getElementById('file[' + index + ']').value = oFileField.value;
}

/* Change default text for username and password fields */
function changeDefaultValue(sender, default_value, change_value, classN)
{
	if (sender.value == default_value)
	{
		sender.value = change_value;
		sender.className = classN;
	}
}

/* Gallery Popups */
var scr_w = window.screen.availWidth;
var scr_h = window.screen.availHeight;

function openPopUpPic(url, width, height)
{
	var left = Math.round((scr_w - width) / 2);
	var top =  Math.round((scr_h - height) / 2);

	if (top < 0)
	{
		top = 0;
		height = scr_h;
	}

	if (left < 0)
	{
		left = 0;
		width = scr_w;
	}

	var pop_up = window.open(url, 'big_galery_pic', 'scrollbars=no');
	pop_up.resizeTo(width, height);
	pop_up.moveTo(left, top);

	pop_up.document.open();
	pop_up.document.write('<style type="text/css">* {margin: 0; padding: 0;}</style><img src="' + url + '" alt="" />');
	pop_up.document.close();
	pop_up.focus();
}
/*end // Gallery Popups*/