animation=true;
clocks=false;

function setLanguage(languageCode) {
	Set_Cookie("currentLanguage",languageCode,365*10,null,null,false);
	window.location = window.location.pathname;
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

newsScrollTimeout = 5000;
newsScrollTimer = null;
newsIndex = 0;
function startNewsscroll() {
	if(animation == false)
		return;
	if(newsScrollTimer == null) {
		index = parseInt(Get_Cookie("newsIndex"));
		if(isNaN(index) || index < 0 || index >= newsscroll.length)
			index = 0;
		newsIndex = index;
	}
	newsScrollTimer = setTimeout("switchNewsscroll()",newsScrollTimeout);
}

function switchNewsscroll() {
	newsIndex++;
	if(newsIndex >= newsscroll.length)
		newsIndex = 0;
	Set_Cookie("newsIndex",newsIndex,null,null,null,false);
	newsscrollDIV = document.getElementById("newsscrollHeadline");
	opacity("newsscroll", 100, 0, 150, newsIndex);
	newsScrollTimer = setTimeout("switchNewsscroll()",newsScrollTimeout);
}

function pauseNewsScroll() {
	if(newsScrollTimer == null)
		return;
	clearTimeout(newsScrollTimer);
}

function opacity(id, opacStart, opacEnd, millisec, newsIndex) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "',"+newsIndex+")",(timer * speed));
			timer++;
		}

        opacStart = 0;
        opacEnd = 100;

		for(i = opacStart; i <= opacEnd; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "',"+newsIndex+")",(timer * speed));
			timer++;
		}
}

//change the opacity for different browsers
function changeOpac(opacity, id, newsIndex) {
	if(opacity == 0 && newsIndex != null) {
		document.getElementById('newsscrollHeadline').innerHTML = newsscroll[newsIndex];
	}
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

//http://es2.php.net/manual/en/timezones.php
clocks = new Array();
function startClocks() {
	if(clocks == false)
		return;
	clockDIVs = (document.getElementById("clocks")).getElementsByTagName("div");
	for(i=0;i<clockDIVs.length;i++) {
		data = clockDIVs[i].getElementsByTagName("span");
		clocks[clockDIVs[i].id] = data[1].innerHTML;
//		alert(clockDIVs[i].id);
	}
	updateClocks();
}

clockTimeout = null;
function updateClocks() {
	myDate=new Date();
	currentOffset = myDate.getTimezoneOffset()/60;
	currentDate = new Date();
	var utc = Date.UTC(myDate.getFullYear(),myDate.getMonth(),myDate.getDate(),myDate.getHours()+currentOffset,myDate.getMinutes(),myDate.getSeconds());
	for(i=0;i<clockDIVs.length;i++) {
		divID = clockDIVs[i].id;
		offset = clocks[divID];
		offset = (parseInt(offset)+parseInt(currentOffset))*3600000;
		myDate.setTime(utc+offset);
		data = clockDIVs[i].getElementsByTagName("span");
		data[2].innerHTML = myDate.getHours() + ":" + zeroPad(myDate.getMinutes()) + ":" + zeroPad(myDate.getSeconds());
		if(myDate.getDate() > currentDate.getDate())
			data[3].innerHTML = "(+1)";
		else if(myDate.getDate() < currentDate.getDate())
			data[3].innerHTML = "(-1)";
	}
	clockTimeout = setTimeout("updateClocks()",1000);
}

String.prototype.pad = function(l, s, t){
    return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
        + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
        + this + s.substr(0, l - t) : this;
};

function zeroPad(number) {
	return (number+"").pad(2,"0",0);
}

function verify(form) {
	invalidFields = false;
	firstField = null;
	fieldList = "";
	for(i=0; i<form.elements.length; i++) {
		for(j=0; j<form.elements[i].attributes.length; j++) {
			if(form.elements[i].type == "text" || form.elements[i].type == "textarea")
				form.elements[i].value = form.elements[i].value.trim();
			if((form.elements[i].attributes[j].nodeName == "required" && form.elements[i].value == "") ||
				(form.elements[i].name == "userPassword" && !verifyPassword(form.elements[i], form.elements[i+1]))) {
				if(firstField == null)
					firstField = form.elements[i];
				form.elements[i].className="red";
				invalidFields = true;
				fieldList = fieldList + (form.elements[i].title ? form.elements[i].title : form.elements[i].name) + "\n";
				break;
			}
			else {
				form.elements[i].className="";
			}
		}
	}
	if(invalidFields) {
		alert("The following fields (highlighted in red) are required!\n\n" + fieldList);
		if(firstField != null)
			firstField.focus();
		return false;
	}
	return true;
}
