/************************************************
 * author: 	Mario Luginbühl
 * version:	1.0
 * date:	2007-04-20
 * purpose:	global javascript functions
 * todo's:	-
***********************************************/


<!-- Startfunktion, index.php -->onLoad -->
function startChange()
{
var t=setTimeout("changeOpacity('home', 0, 100, 1000)",3000);
}
function startChange2()
{
var t=setTimeout("changeOpacity('home', 0, 100, 0)",0);
}

<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  }

<!-- passwordfunction -->
//the function starts when the whole site is loaded
window.onload = init2;

function init2() {
	if (Password = document.getElementById('password')) {
	 	Password.style.backgroundImage = "url(pics/tech/password_bg.gif)";
	 	Password.onfocus = emptyValue;
		Password.onblur = refillValue;
	}
	if (User = document.getElementById('user')) {
	 	User.style.backgroundImage = "url(pics/tech/user_bg.gif)";
	 	User.onfocus = emptyValueUser;
		User.onblur = refillValueUser;
	}
}

function emptyValue() {
	if (Password) {
        Password.style.backgroundColor = "#33FF33";
		Password.style.backgroundImage = "none";
	}
}

function refillValue() {
	if (Password.value == "") {
		 Password.style.backgroundColor = "#CCCCCC";
   		 Password.style.backgroundImage = "url(pics/tech/password_bg.gif)";
	}
}
function emptyValueUser() {
	if (User) {
        User.style.backgroundColor = "#33FF33";
		User.style.backgroundImage = "none";
	}
}

function refillValueUser() {
	if (User.value == "") {
		 User.style.backgroundColor = "#CCCCCC";
   		 User.style.backgroundImage = "url(pics/tech/user_bg.gif)";
	}
}

<!-- radio buttons return -->
function getCheckedValue(radioObj) 
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
		if(radioObj.checked)
		{
			return radioObj.value;
		}
		else
		{
			return "";
		}
	}
	for(var i=0; i<radioLength; i++)
	{
		if(radioObj[i].checked) 
		{
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) 
{
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i=0; i<radioLength; i++)
	{
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) 
		{
			radioObj[i].checked = true;
			return radioObj[i].value;
		}
	}
}

function urlOpen(url)
{
	window.open(url,'urlOpen');
}

function setPortrait(pid)
{
	for(var i=0; i < document.all.tags('DIV').length; ++i)
	{
		if (document.all.tags('DIV')[i].id == "portrait_right_bottom")
		{
			if (document.all.tags('DIV')[i].name == pid) // set the new layer visible
			{
				var element = document.all.tags('DIV')[i];
				element.filters.blendTrans.Apply();
				element.style.visibility = 'visible';
				element.filters.blendTrans.Play();
			}
			else // all the others should be hidden
			{
				var element = document.all.tags('DIV')[i];
				element.filters.blendTrans.Apply();
				element.style.visibility = 'hidden';
				element.filters.blendTrans.Play();
			}
		}
	}
}


function showDiv()
{
	for(var i=0; i < document.all.tags('DIV').length; ++i)
	{
		if (document.all.tags('DIV')[i].id == "transparent")
		{
			var element = document.all.tags('DIV')[i];
			//element.filters.blendTrans.Apply();
			element.style.visibility = 'visible';
			//element.filters.blendTrans.Play();
		}
		if (document.all.tags('DIV')[i].id == "loading")
		{
			var element = document.all.tags('DIV')[i];
			//element.filters.blendTrans.Apply();
			element.style.visibility = 'visible';
			//element.filters.blendTrans.Play();
		}
	}
	//alert("Gut");
	//return true;
}

function checkIt()
{
   if(!document.check.verifyed.checked)
	{
	 alert("Bitte löschen bestätigen!");
	 return false;
	}
}

// Mailfunction

// rot13-Algorithmus (für Entschlüsselung in JavaScript)
var map = new Array();
var s = "abcdefghijklmnopqrstuvwxyz";
  
for (var i = 0; i < s.length; i++)
	map[s.charAt(i)] = s.charAt((i + 13) % 26);

for (i = 0; i < s.length; i++)
	map[s.charAt(i).toUpperCase()] = s.charAt((i + 13) % 26).toUpperCase();

function rot13 (str)
{
	var rwert = 'mailto:';
	for (i = 0; i < str.length; i++)
	{
		var b = str.charAt(i);
		if (b == '+')
			rwert += '@';
		else
			rwert += ('A' <= b && b <= 'Z' || 'a' <= b && b <= 'z' ? map[b] : b);
	}
	return rwert;
}


// FADE funktion


function shiftOpacity(id,millisec) 
{
	if(document.getElementById(id).style.opacity == 0) 
		{
			//alert(document.getElementById(id).style.opacity);
			changeOpacity(id,0,90,millisec);
		}
	else if(document.getElementById(id).style.opacity == 0.9) 
		{
			//alert(document.getElementById(id).style.opacity);
			changeOpacity(id,90,0,millisec);
		}
	else 
		{
			//alert(document.getElementById(id).style.opacity);
			changeOpacity(id,90,0,millisec);
		}

}



function changeOpacity(id,opacStart, opacEnd, millisec) 
{
	var speed = Math.round(millisec/100);
	var timer = 0;
	
	if(opacStart > opacEnd) 
		{
		for(i=opacStart; i >= opacEnd; i--) 
			{
			setTimeout("changeOpac(" +i + ",'" +id + "')",(timer * speed));
			timer++;
			}
			document.getElementById('infobutton').innerHTML = "<a id=\"h_toggle\" href=\"javascript:shiftOpacity('info', 500)\">open</a>";
		}
	else if(opacStart < opacEnd)
		{
		for(i=opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" +i + ",'" +id + "')",(timer * speed));
			timer++;
			}
		document.getElementById('infobutton').innerHTML = "<a id=\"h_toggle\" href=\"javascript:shiftOpacity('info', 500)\">close</a>";
		}
}


function changeOpac(opacity, id)
	{
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	}


