
function sleep(ms){
	var zeit=(new Date()).getTime();
	var stoppZeit=zeit+ms;
	while((new Date()).getTime()<stoppZeit){};
}


function loadLoader() {
    loadDiv=document.getElementById('loader');
  	loadDiv.style.display = 'block';
}

function unloadLoader() {
  loadDiv=document.getElementById('loader');
	loadDiv.style.display = 'none';
}

function loadLoaderInfo(info) {
    loadDiv=document.getElementById('loaderInfo');
  	loadDiv.style.display = 'block';
  	document.getElementById('infoText').innerHTML=info;
  	document.getElementById('infoText').style.display = 'block';
}

function unloadLoaderInfo() {
	loadDiv=document.getElementById('loaderInfo');
	loadDiv.style.display = 'none';
	document.getElementById('infoText').innerHTML='';
  	document.getElementById('infoText').style.display = 'none';
}
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

var element_id = '';
var http_request = false;

function makeRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }


	  http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
	  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
	  http_request.send(parameters);



   }

   function alertContents() {
   	
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            unloadLoader();
            document.getElementById(element_id).innerHTML = result;
            return true;
            } else {
            	unloadLoader();
            alert('ERROR: AJAX request status = ' + http_request.status);
		}
      }
   }


function  login_sent(form) {
	loadLoader();
	element_id = 'left';
	var getstr = "nickname=";
	getstr += form.nickname.value+"&password="+form.passwort.value;
	makeRequest('inc/ajax/check_login.php', getstr);
}

function logout()
{
	loadLoader();
	element_id = 'left';
	var getstr = "";
	makeRequest('inc/ajax/logout.php', getstr);
}

function reloadLeftContainer()
{
	loadLoader();
	element_id = 'left';
	var getstr = "";
	makeRequest('con_left.inc.php', getstr);
}
function reloadRightContainer()
{
	loadLoader();
	element_id = 'right';
	var getstr = "";
	makeRequest('con_right.inc.php', getstr);
}



function Side_hidden()
{
    loadContent=document.getElementById('content');
	loadContent.style.visibility = 'hidden';
	
}

function Side_display()
{
    loadContent=document.getElementById('content');
	loadContent.style.visibility = 'visible';
}


// Anmeldeformular
function checkAnmeldeForm(form)
{
	if (form.firstname.value.length<3)
	{
		document.getElementById('errorFirstname').innerHTML = 'mind. 3 Zeichen!';
		return false;
	}
	if (form.lastname.value.length<3)
	{
		document.getElementById('errorLastname').innerHTML = 'mind. 3 Zeichen!';
		return false;
	}
	
	
	if (form.nickname.value.length < 5)
	{
		document.getElementById('errorNickname').innerHTML= "mind. 5 Zeichen";
		return false;
	}
	element_id = 'errorNickname';
	var getstr = "nickname=";
 	getstr += form.nickname.value;
    makeRequest('inc/ajax/checkNickname.php', getstr);
	
	if (form.password1.value.length<4)
	{
		document.getElementById('errorPassword1').innerHTML = "Mind. 5 Zeichen!";
		return false;
	}
	if (form.password2.value != form.password1.value)
	{
		document.getElementById('errorPassword2').innerHTML ='Passwortwiederholung nicht korrekt';
		return false;
	}
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = form.email.value;
	if(reg.test(address) == false) {
	      document.getElementById('errorEmail').innerHTML = 'Invalid Email Address';
	      return false;
	}
	if (form.geschaeft.checked==false)
	{
		document.getElementById('errorGeschaeft').innerHTML = 'Bitte lesen und zustimmen';
		return false;
	}
	if (form.datenschutz.checked==false)
	{
		document.getElementById('errorDatenschutz').innerHTML = 'Bitte lesen und zustimmen';
		return false;
	}
	if (form.captchaCode.value != form.captchaWord.value)
	{
		document.getElementById('errorCaptcha').innerHTML = "falscher Code!";
		return false;
	}
	
	// getRequest
	/**element_id = 'mitte';
	var getstr = "firstname=";
	getstr += form.firstname.value+"&lastname="+form.lastname.value+"&street="+form.street.value+
 		"&zip_code="+form.zip_code.value+"&city="+form.city.value+"&country="+form.country.value+
 		"&email="+form.email.value+
		 "&birthday="+form.birthdayYear.value+"-"+form.birthdayMonth.value+"-"+form.birthdayDay.value+
	  	"&nickname="+form.nickname.value+"&password="+form.password1.value;
     makeRequest('inc/ajax/newUserPost.ajax.php', getstr);	
	**/
	return true;
}

function ts3viewer()
{
	new Ajax.Request('inc/container/ts3_Viewer.ajax.php',
	{
		method:'get',
        onSuccess: function(transport){
       		var mitte = $('ts3viewer');
			var response = transport.responseText || "no response text";
			mitte.update(response);
	    },
		onFailure: function(){ alert('Fehler bei Ajax Request') }
      });
	
}

function adsHit(id)
{
    new Ajax.Request('inc/admin/super_ads_hit.ajax.php',
	{
		method:'post',
        parameters: {id: id},
        onSuccess: function(transport){
       		var response = transport.responseText || "no response text";
		},
		onFailure: function(){ alert('Fehler bei Ajax Request') }
      });
}

function myProfil(uid,sid)
{
	loadLoader();
	element_id = 'mitte';
	var getstr = "&uid=";
	getstr += uid+"&sid="+sid;
	makeRequest('inc/ajax/myProfil.ajax.php', getstr);
}

function reloadZufallsscreenshot()
{
	new Ajax.Request('inc/container/zufallsscreenshot.ajax.php',
    {
		method:'get',
        onSuccess: function(transport){
        	var mitte = $('zufallsScreenshot');
		    var response = transport.responseText || "no response text";
		    mitte.update(response);
		    //info.update("").setStyle({color:'green'});
		},
        onFailure: function(){ alert('Fehler bei Ajax Request') }
     });
}

function newsComm(nid,sid)
{
	loadLoader();
	element_id = 'mitte';
	var getstr = "&nid=";
	getstr += nid+"&sid="+sid;
	makeRequest('inc/ajax/newsComm.ajax.php', getstr);
}

function newsCommAdd(nid,sid,form)
{
	loadLoader();
	element_id = 'mitte';
	var getstr = "&nid=";
	getstr += nid+"&sid="+sid+"&text="+form.commentText.value;
	makeRequest('inc/ajax/newsCommAdd.ajax.php', getstr);
}

function menuDownload(sid,dkid)
{
	loadLoader();
	element_id = 'mitte';
	var getstr = "&dkid=";
	getstr += dkid+"&sid="+sid;
	makeRequest('inc/ajax/downloads.ajax.php', getstr);
}

function divOpenClose(myDivId)
{
    var a = new Date();
	a = new Date(a.getTime() +1000*60*60*24*365);
    if (document.getElementById(myDivId).style.display == 'none')
	{
	    Effect.BlindDown(myDivId, { duration: 1.0 });
        var meindiv2 = document.getElementById( "divChattext" );
		if (meindiv2)
        {
            meindiv2.scrollTop = meindiv2.scrollHeight;
        }
        document.cookie = myDivId+'=open; expires='+a.toGMTString()+';';
	}
	else
	{   
        Effect.BlindUp(myDivId, { duration: 1.0 });
        document.cookie = myDivId+'=close; expires='+a.toGMTString()+';';
    }
    
	 
}

function statisticReload()
{
	new Ajax.Request('inc/container/statistik.ajax.php',
    {
		method:'get',
        onSuccess: function(transport){
        	var mitte = $('statistik');
		    var response = transport.responseText || "no response text";
		    mitte.update(response);
		    
		},
        onFailure: function(){ alert('Fehler bei Ajax Request') }
     });
}

 function getCookie()
    {
    	var a = document.cookie;
        cookie_array = new Array();
        cookie_array = a.split(';');
        //alert(cookie_array);
        for (var x=0;x<cookie_array.length;x++)
        {
            c_array = new Array();
            c_array = cookie_array[x].split('=');
            
            if (c_array[1]=='close' || c_array[1]=='open')
            {
                if (c_array[1]!='open')
            	{
            	   var divId = c_array[0].trim();
                   //alert(document.getElementById(divId)+" : "+divId+" : "+divId.length);
                   if (document.getElementById(divId))
                   {
                        document.getElementById(divId).style.display="none";
                   }
            	   
            		
            	}
            }
        }
    
    }
    

