function showDiv(divName) 
{ 
	if (angezeigt)
	{
		document.getElementById(divName).style.display = 'none';
		angezeigt = false;
	}
	else
	{
		document.getElementById(divName).style.display = 'block';
		angezeigt = true;
	}
} 

if( requestList == undefined ||requestList == null )
{
	var requestList = new XAjaxRequestList();
}

function showAjax(phpFile, divName) {
	xGetElementById(divName).innerHTML = '<img src="/images/ajax-loader.gif" />';
	var request = requestList.x_getRequest();
	request.requestType = "POST";
    request.contentType = "text/xml";
    request.target = phpFile;
    request.async = true;
	request.x_send();
	
	// on success
    request.x_onSuccess = function loaded( antwort ){
	     xGetElementById(divName).innerHTML = antwort;
	}

    // on error
    request.x_onError = function error( msg, nr ){
    	alert(msg);
	}
}

function voteOver(id) { 
	for(i=1;i<=id;i++){
		document.images['vote'+i].src = '/images/stern.gif';	
	}
	id++;
	for(i=id;i<=5;i++){
		document.images['vote'+i].src = '/images/stern-grau.gif';	
	}
}	

function voteOut(id) { 
	for(i=1;i<=5;i++){
		document.images['vote'+i].src = '/images/stern-grau.gif';	
	}
}	

function voteSubmit(id, vote) {
	showAjax('/php/voting/vote.php?id=' + id + '&vote=' + vote,'vote');
}

function commentSubmit() {
	showAjax('/php/comments/comment.php?id=' + xGetElementById('id').value + '&kommentar=' + encodeURI(xGetElementById('kommentarfeld').value), 'commentform');
	showAjax('/php/comments/refreshcomments.php?id=' + xGetElementById('id').value + '&start=0','comment');
}

function clearField(fld) {
  if (fld.value == "username") fld.value = "";
}

function messageSubmit() {
	showAjax('/php/messagesubmit.php?id=' + xGetElementById('user_id').value + '&title=' + xGetElementById('title').value + '&message=' + encodeURI(xGetElementById('message').value),'messagebox');
}

function einloggen() {
	showAjax('/php/login.php?username=' + xGetElementById('username').value + '&passwort=' + xGetElementById('passwort').value,'login');
	showAjax('/php/messageform.php','messagebox');
	refreshComments(xGetElementById('id').value,'0');
	showAjax('/php/comments/commentform.php?id=' + xGetElementById('id').value ,'commentform');
	showAjax('/php/voting/voteform.php?id=' + xGetElementById('id').value ,'vote');

}

function ausloggen() {
	showAjax('/php/logout.php','login');
	showAjax('/php/messageform.php','messagebox');
	deactivateComment();
	showAjax('/php/voting/voteform.php?id=' + xGetElementById('id').value ,'vote');
}

function activateComment() {
	xGetElementById('kommentarabschicken').removeAttribute('disabled');
	xGetElementById('kommentarfeld').removeAttribute('disabled');
	xGetElementById('kommentarfeld').value = '';
}


function refreshComments(id, start) {
	showAjax('/php/comments/refreshcomments.php?id=' + id + '&start=' + start,'comment');
}

function ladeEmpfehlungen() {
	showAjax('/php/ladeempfehlungen.php','empfohlen');
}

function refreshUserVideos(id, username, start) {
	showAjax('/php/refreshuservideos.php?id=' + id + '&username=' + username + '&start=' + start,'uservideos');
}

function favorit(id, action) {
	showAjax('/php/videofavorit.php?id=' + id + '&action=' + action,'favoritbox');
}

function empfehlung(id, action) {
	showAjax('/php/videoempfehlung.php?id=' + id + '&action=' + action,'empfehlungsbox');
}

function deletevideo(id) {
	showAjax('/php/deletevideo.php?id=' + id, 'loeschen');
}

function videobearbeiten(id) {
	document.getElementById('layer').style.display='inline';
	showAjax('/php/editvideo.php?id=' + id, 'layer');
}

function deactivateComment() {
	xGetElementById('kommentarabschicken').setAttribute('disabled','disabled');
	xGetElementById('kommentarfeld').setAttribute('disabled','disabled');
	xGetElementById('kommentarfeld').value = 'Du musst eingeloggt sein um einen Kommentar zu verfassen!';
}

function activateMessage() {
	xGetElementById('title').removeAttribute('disabled');
	xGetElementById('message').removeAttribute('disabled');
	xGetElementById('absenden').removeAttribute('disabled');
}


function registrieren() {
	xGetElementById('anmeldenbutton').setAttribute('disabled','disabled');
	xGetElementById('anmeldenbutton').value = 'Bitte warten...';
	var username = xGetElementById('benutzername').value;
	var mail = xGetElementById('email').value;
	var form = xGetElementById('formular').value;
	var akzeptiert = '';
	var geschlecht = '';
	if(xGetElementById('maennlich').checked) geschlecht = 'maennlich';
	if(xGetElementById('weiblich').checked) geschlecht = 'weiblich';
	if(xGetElementById('bedingungen').checked) akzeptiert = 'akzeptiert';

	showAjax("/php/anmeldeformular.php?username=" + username + "&email=" + mail + "&geschlecht=" + geschlecht + "&formular=" + form + "&bedingungen=" + akzeptiert, "form");
}

function inputFocus(input){
	input.style.backgroundColor='#ffffff'; 
}

function inputBlur(input){
	input.style.backgroundColor='#c7d9e7';
}

function Zeitberechnung()
{
	var AktuelleZeit = new Date();
	Differenz = parseInt((AktuelleZeit.getTime() - Aufrufzeit.getTime()) / 1000);
	setTimeout("Zeitberechnung()", 1000);
}

function OnlineZeitSpeichern(video_id, user_id)
{
	Differenz = String(Differenz);
	showAjax("/php/videoviewtime.php?duration=" + Differenz + "&video_id=" + video_id + "&user_id=" + user_id, "onlinetime");
}


