function $F(fname) {
	return document.forms[fname];	
}

function $TN(str) { // byTagName
	return document.getElementsByTagName(str);	
}

function $N(str) { // byName
	return document.getElementsByName(str);	
}

//Bestaetigungsmeldung - z.B. Loeschen der GB Eintraege
function bestaetigung(meldung,url) {
	if (confirm(meldung)) {
		location.href=url;	
	}
}

function blurElement(element, text) {
	if(element.value=='') {
		element.value=text;
		element.style.color = '#999999';
	}
}

function focusElement(element, text) {
	element.style.color = '#000000';
	if(element.value==text) element.value='';
}

// Login
function AjaxLoader_Login (username, password, urlvars) {

	if(checkLogin() == true) {

		$('username').disabled = true;
		$('password').disabled = true;
		$('loginlink').innerHTML = 'Bitte warten...';
		$('loginlink').disabled = true;

		new Ajax.Request('./login.php?',
			{
				method: 'get',
				parameters: 'action=&username=' + decodeURIComponent(username) + '&password=' + decodeURIComponent(password),
				onSuccess: function(tr) {
					if(tr.responseText == 'okloader') {
						
						window.location.href = "./index.php?" + urlvars;
						
					} else {
						$('username').value = '';
						$('password').value = '';
						alert(tr.responseText);
						setTimeout(Hide_Login, 500);
					}
				},
				onFailure: function(tr) {
					alert("Error "+tr.status+": "+tr.statusText);
				} 
			}
		);
	}
}

// Login Check
function checkLogin () {
	if($('username').value == "") {
		alert("Du hast vergessen, deinen Benutzername anzugeben.");
		return false;
	}
	if($('password').value == "") {
		alert("Du hast vergessen, dein Passwort anzugeben.");
		return false;
	}
	return true;
}

// Statustext Userbar
function setStatus(uid, profilbool, viaUserbar) {
	if (viaUserbar) {
		$('submitStatusButton_Userbar').value = 'Bitte warten...';
		$('submitStatusButton_Userbar').disabled = true;
	} else {
		$('submitStatusButton_Profil').value = 'Bitte warten...';
		$('submitStatusButton_Profil').disabled = true;
	}
	if (viaUserbar) {
		textarea = 'Statustext_UB_textarea';
	} else {
		textarea = 'Statustext_Profil_textarea';
	}
	new Ajax.Request('include/content/profil/ajax_set_statustext.php?',
		{
			method: 'get',
			parameters: 'statustext='+encodeURIComponent($(textarea).value)+'&id='+uid,

			onSuccess: function(tr) {
				if (viaUserbar) {
					$('submitStatusButton_Userbar').value = 'Speichern';
					$('submitStatusButton_Userbar').disabled = false;
					if (profilbool) {
						$('charsleft_Statustext_Profil').innerHTML = $('charsleft_Statustext_Userbar').innerHTML;
						$('Statustext_Profil_textarea').value = $('Statustext_UB_textarea').value;	
					}
					Effect.SlideUp('Status_'+uid,
						{
							duration: 0.5,
							queue: 'end'
						}
					);
				} else {
					$('submitStatusButton_Profil').value = 'Speichern';
					$('submitStatusButton_Profil').disabled = false;
					$('Statustext_UB_textarea').value = $('Statustext_Profil_textarea').value;
					$('charsleft_Statustext_Userbar').innerHTML = $('charsleft_Statustext_Profil').innerHTML;
				}
				$('Statustext_Userbar').innerHTML = tr.responseText;
				
				if($('user_talk_self_statustext')) {
					$('user_talk_self_statustext').innerHTML = tr.responseText;	
				}

				
				
			}
		}
	);
}

function delStatus(uid, profilbool, viaUserbar) {
	
	if (viaUserbar) {
		$('cancelStatusButton_Userbar').value = 'Bitte warten...';
		$('cancelStatusButton_Userbar').disabled = true;
	} else {
		$('cancelStatusButton_Profil').value = 'Bitte warten...';
		$('cancelStatusButton_Profil').disabled = true;	
	}
	
	new Ajax.Request('include/content/profil/ajax_unset_statustext.php?',
		{
			method: 'get',
			parameters: 'id='+uid,
			onSuccess: function(tr) {
				$('Statustext_UB_textarea').value = '';
				
				if (profilbool) {
					$('Statustext_Profil_textarea').value = '';
					$('charsleft_Statustext_Profil').innerHTML = 'Noch 160 Zeichen &uuml;brig.';
				}
				
				if (viaUserbar) {
					$('cancelStatusButton_Userbar').value = 'Löschen';
					$('cancelStatusButton_Userbar').disabled = false;
					Effect.SlideUp('Status_'+uid,
						{
							duration: 0.5,
							queue: 'end'
						}
					);
				} else {
					$('cancelStatusButton_Profil').value = 'Löschen';
					$('cancelStatusButton_Profil').disabled = false;
				}
				
				$('Statustext_Userbar').innerHTML = '';
				
				if($('user_talk_self_statustext')) {
					$('user_talk_self_statustext').innerHTML = '';	
				}
			
				
				$('charsleft_Statustext_Userbar').innerHTML = 'Noch 160 Zeichen &uuml;brig.';
				
			}
		}
	);
}

// Kein Schimmer!!!!

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function centerLayer(obj_width, obj_height) {
	var arrayPageSize = getPageSize();
	var width = arrayPageSize[2];
	var height = arrayPageSize[3];
	var x = '';
	var y = '';
	
	x = ((width/2)-(obj_width))/2;
	y = ((height/2)-(obj_height))/2;
	
	arrCenter = new Array(x, y);
	return arrCenter;
}

var mode;

function bodyonload (cookie, inc, action, isadmin, regflag) {
	
	if (cookie == 1) {		
		if(inc == 'profil' && action == '') {
			mode = '';
		} else if(inc == 'profil' && action == 'inbox') {
			mode = 'inbox';
		} else if(inc == 'profil' && action == 'outbox') {
			mode = 'outbox';
		} else if(inc == 'profil' && action == 'folder') {
			mode = 'folder';
		} else if(inc == 'profil' && action == 'new') {
			mode = 'new';
		} else {
			mode = '';
		}
	}
	
	PreloadHeader(isadmin, inc);
	
	//BilderVorladen(inc); momentan fehlerhaft...
	
	if(regflag == 1) {

		show_box('box_login_register', '800px', '360px', '102px', '70px', 'l_content');
	
	}
	
}

function BilderVorladen(section)
{
	//section array in preloads.js
    document.Vorladen = new Array();

    if(document.images)
    {
        for(var i = 0; i < section.length; i++)
        {
            document.Vorladen[i] = new Image();
            document.Vorladen[i].src = section[i];
        }
    }
}

function MaxLen(Object, MaxLen) {
	return (Object.value.length <= MaxLen);
}

var emot_on = false;

function Status(uid) {
	if($('Status_'+uid).style.display=='none') {
		Effect.SlideDown('Status_'+uid,
						 	{
								duration: 0.5,
								queue: 'end'
							}
						);
	} else {
		Effect.SlideUp('Status_'+uid,
					   		{
								duration: 0.5,
								queue: 'end'
							}
						);
	}
}
