/*
	global
	prefix: none
	functions:
	getFileType();
	nextSameSibling();
	nextTagSibling();
	getChildByTagName();
	trim();
	hideElement();
	showElement();
	hideElementById();
	showElementById();
	submitFormAction();
	redirect();
*/

function confirmLink (s_text, s_link)
{
	if (confirm(s_text) == true)
	{
		document.location = s_link;
	}
}

function toggleID (s_id, s_expand, s_collapse)
{
	o_toggle = document.getElementById(s_id);
	o_img    = document.getElementById('i_' + s_id);
	
	if (o_toggle.style.display == 'none')
	{
		o_toggle.style.display = '';
		o_img.src = s_collapse;
		return;
	}
	
	o_toggle.style.display = 'none';
	o_img.src = s_expand;
}

function redirect (s_position)
{
	document.location = s_position;
}

function getFileType (s_filename)
{
	i_index = s_filename.lastIndexOf('.');
	
	if (i_index == -1)
	{
		return '';
	}
	
	return s_filename.substr(i_index + 1);
}

function nextTagSibling(o_sibling, s_tagName)
{
	o_sibling = o_sibling.nextSibling;
	
	while(o_sibling != null)
	{
		if (o_sibling.tagName == s_tagName) 
		{
			return o_sibling;
		}
		
		o_sibling = o_sibling.nextSibling;
	}
	
	return false;
}

function nextSameSibling (o_sibling)
{
	s_name = o_sibling.tagName;

	o_sibling = o_sibling.nextSibling;
	while (o_sibling != null)
	{
		if (o_sibling.tagName == s_name)
		{
			return o_sibling;
		}
		
		o_sibling = o_sibling.nextSibling;
	}
	
	return false;
}

function getChildByTagName (o_node, s_name)
{
	for (i = 0; i < o_node.childNodes.length; i++)
	{
		if (o_node.childNodes[i].tagName == s_name)
		{
			return o_node.childNodes[i];
		}
	}
	
	return false;
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function hideElementById(s_name)
{
	hideElement(document.getElementById(s_name));
}

function showElementById(s_name)
{
	showElement(document.getElementById(s_name));
}

function hideElement (o_element)
{
	o_element.style.display = 'none';
}

function showElement (o_element)
{
	o_element.style.display = '';
}

function confirmFormAction (s_text, s_formname, s_action)
{
	if (confirm(s_text) == false)
	{
		return;
	}
	o_form = document.forms[s_formname];
	o_form.action = o_form.action + s_action;
	o_form.submit();
}

function submitFormAction (s_formname, s_action)
{
	o_form = document.forms[s_formname];
	o_form.action = o_form.action + s_action;
	o_form.submit();
}

/*
	image gallery
	prefix:
		ig_
	functinons:
*/

function ig_openImage (s_target)
{
	var s_settings = "width=500,height=500,resizable=yes,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no";
			
	var o_window   = window.open(s_target, "window_image", s_settings);
	
	o_window.focus();
}

function ig_resize (i_width, i_height)
{
	window.resizeTo(i_width + 20, i_height + 110);
}

/*
	global trash
	prefix:
	functinons:
		focus_clear();
		tick_clock();
		generateClockStr();
*/

function font_size (s_style) {
	var i_i, a_objects
	
	a_objects = document.getElementsByTagName("link");
	
	for (i_i = 0; i_i < a_objects.length; i_i++)
	{
		if((a_objects[i_i].getAttribute("rel").indexOf("style") != -1) && 
		    (a_objects[i_i].getAttribute("title"))) 
		{
			a_objects[i_i].disabled = true;
			
			if (a_objects[i_i].getAttribute("title") == s_style)
			{
				a_objects[i_i].disabled = false;
			}
		}
	}
	
}

function tag_font_size (s_tag, i_size)
{
	a_element = document.getElementsByTagName("table");
	
	for (i_i = 0; i_i < a_element.length; i_i++)
	{
		a_element[i_i].style.fontSize = (i_size) + 'pt';
	}
}

function focus_clear (o_field, s_value)
{
	if (o_field.value == s_value)
	{
		o_field.value = '';
	}
}

function tick_clock ()
{
	o_clock = document.getElementById('time');
	
	o_one = getChildByTagName(o_clock, 'SPAN');
	o_two = nextSameSibling(o_one);
	
	if (o_one.style.display == 'none')
	{
		o_one.style.display = '';
		o_two.style.display = 'none';
		
		sdate.setSeconds(sdate.getSeconds() + 1);
		o_two.innerHTML = generateClockStr(sdate);
		return;
	}
	
	if (o_two.style.display == 'none')
	{
		o_two.style.display = '';
		o_one.style.display = 'none';
		
		sdate.setSeconds(sdate.getSeconds() + 1);
		o_one.innerHTML = generateClockStr(sdate);
		return;
	}
	
	o_one.innerHTML = generateClockStr(sdate);
	
	o_two.style.display = 'none';
	sdate.setSeconds(sdate.getSeconds() + 1);
	o_two.innerHTML = generateClockStr(sdate);	
	
}

function generateClockStr (o_date)
{
	var a_days  = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
	var a_month = new Array("Jänner", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
	
	var s_day   = a_days[sdate.getDay()];
	var s_month = a_month[sdate.getMonth()];

	var s_hour     = '' + sdate.getHours();
	var s_minute   = '' + sdate.getMinutes();
	var s_seconds  = '' + sdate.getSeconds();
	
	if (s_hour.length == 1)
	{
		s_hour = '0' + s_hour;
	}
	
	if (s_minute.length == 1)
	{
		s_minute = '0' + s_minute;
	}
	
	if (s_seconds.length == 1)
	{
		s_seconds = '0' + s_seconds;
	}

	var s_clock = s_day + ', ' + sdate.getDate() + '.' + s_month + '.' + sdate.getFullYear();
	s_clock += ' - ';
	s_clock += s_hour + ':' + s_minute + ':' + s_seconds;
	
	return s_clock;
}
