var gbStart=0;
var gbMaxEntriesPerPage=5;
var gbError=new Array();

function helpchange()
{
new Ajax.Updater('gb_entries','gb.php?action=list&start='+gbStart+'&end='+gbMaxEntriesPerPage,{onComplete:function()
	                               		{
	                               			new Effect.Move('gb_entries',{x: (getvfstyle(document.getElementById('gb_entries').style.left)) , y: (50),mode:'absolute'});
  																		new Effect.Appear('gb_entries');
	                               	  },asynchronous:true, evalScripts:true});
}
function changeGbPage(prevNext)
{


  if (prevNext=='next') gbStart=gbStart+4;
  else gbStart=gbStart-4;
  if (gbStart<0) gbStart=0;
  new Effect.Fade('gb_entries'); 
  new Effect.Move('gb_entries',{x:(getvfstyle(document.getElementById('gb_entries').style.left)) , y: (600),mode:'absolute'});
  window.setTimeout("helpchange()",1000);
	
}


function show_gb()
{
	
	element = Builder.node('div',{id: 'gb_entries' ,style:'position:absolute;top:600px;left:'+240+'px;z-index:4;'});
	Ebenen.push(element);
	document.getElementById('yeahbaby').appendChild(element);
  Element.hide('gb_entries');
  new Ajax.Updater('gb_entries', 'gb.php?action=list&start='+gbStart+'&end='+gbMaxEntriesPerPage, {asynchronous:true});
  new Effect.Appear('gb_entries');
  new Effect.Move('gb_entries',{x: (getvfstyle(document.getElementById('gb_entries').style.left)) , y: (50),mode:'absolute',queue:'end'});
  
  
  element = Builder.node('div',{id: 'gb_prev' ,style:'position:absolute;top:50px;left:'+745+'px;z-index:4;'});
	Ebenen.push(element);
	document.getElementById('yeahbaby').appendChild(element);
	Element.hide('gb_prev');	
	element = Builder.node('a',{href: 'javascript:changeGbPage(\'prev\');'});
  nextone = Builder.node('img',{src: 'gb_images/up.gif', border:'0'});
  element.appendChild(nextone);
  document.getElementById('gb_prev').appendChild(element);
 
  element = Builder.node('div',{id: 'gb_next' ,style:'position:absolute;top:500px;left:'+745+'px;z-index:4;'});
	Ebenen.push(element);
	document.getElementById('yeahbaby').appendChild(element);
  Element.hide('gb_next'); 
  element = Builder.node('a',{href: 'javascript:changeGbPage(\'next\');'});
  nextone = Builder.node('img',{src: 'gb_images/down.gif', border:'0'});
  element.appendChild(nextone);
  document.getElementById('gb_next').appendChild(element);
  
  element = Builder.node('div',{id: 'gb_entryform' ,style:'position:absolute;top:600px;left:'+770+'px;z-index:4;'});
	Ebenen.push(element);
	document.getElementById('yeahbaby').appendChild(element);
  Element.hide('gb_entryform');
  new Ajax.Updater('gb_entryform', 'gb.php?action=entryform', {asynchronous:true});
  new Effect.Appear('gb_entryform');
  new Effect.Move('gb_entryform',{x: (getvfstyle(document.getElementById('gb_entryform').style.left)) , y: (50),mode:'absolute',queue:'end'});
 
  new Effect.Appear('gb_next',{queue:'end'});
  new Effect.Appear('gb_prev',{queue:'end'});
} 

function addErrortoList(txt)
{ 
	if (gbError.length >= 8) 
	   for (var i=0; i = gbError.length;i++) document.getElementById('entryformtable').removeChild(gbError.pop());
	help = document.createElement("tr");
	fehlertitle = document.createElement("td");
	fehlerclass = document.createAttribute("class")
  fehlerclass.nodeValue="gb_entryform_title";
  fehlerspan = document.createAttribute("colspan")
  fehlerspan.nodeValue="2";
  fehlertitle.setAttributeNode(fehlerspan);
  fehlertitle.setAttributeNode(fehlerclass);
	fehlertitle.appendChild(document.createTextNode('Error:'));
	help.appendChild(fehlertitle);
  document.getElementById('entryformtable').appendChild(help);
  titletr=help;
  help = document.createElement("tr");
	fehlertitle = document.createElement("td");
	fehlerclass = document.createAttribute("class")
  fehlerclass.nodeValue="gb_entryform_cell";
  fehlerspan = document.createAttribute("colspan")
  fehlerspan.nodeValue="2";
  fehlertitle.setAttributeNode(fehlerspan);
  fehlertitle.setAttributeNode(fehlerclass);
	fehlertitle.appendChild(document.createTextNode(txt));
	help.appendChild(fehlertitle);
	document.getElementById('entryformtable').appendChild(help); 
	gbError.push(help);
	gbError.push(titletr);
}

function addentry()
{
	var ready=0;
	 if (document.getElementById('mail').value.indexOf('.') == -1
    || document.getElementById('mail').value.indexOf('@') == -1) {
	  addErrortoList('Please use a valid emailadress!');
  }else ready++; 
  
  if (document.getElementById('code').value == "" || document.getElementById('code').value == "00000") {
	
     addErrortoList('You have to repeat the given accesscode!');
   
	} else ready++;
	  
	if (ready==2) gbform.submit();
	  
                   
}

function updateEntries()
{
new Effect.Highlight('gb_entries'); 
new Ajax.Updater('gb_entries','gb.php?action=list&start=0&end='+gbMaxEntriesPerPage,{asynchronous:true, evalScripts:true });	
}

function newCode()
{
document.getElementById('cpic').src='gb.php?action=safeimg&rand='+Math.round(Math.random()*100);
}