document.observe('dom:loaded', function() {

		
	//################# Frontend-CMS ##############################//
	//################# by Oliver Wieland 2009
	//################# feel free to modify ;)
	// lastVersion: 07 AUG 2009
	

	
	var login=$('login').value;
	var PATH=$('PATH').value;
	var isPulldownLexikon=false;
	
	
	if(login==1) {

		//CMS-Edit Button
		$$('a.cmsEdit').each(function(element) {
			element.observe('click', function() {
				var elementText;

				//Ajax-Request auf Element-Daten:
				var idx=element.id.split('_');
				var theID=idx[1];
				var sortierung=idx[2];				
				var url=PATH+'getCMSData.php?ID='+theID+'&sortierung='+sortierung;
	
				new Ajax.Request(url, {
					method: 'get',
					onSuccess: function(transport) {
						elementText=transport.responseText;
						
						var uri=top.location.href; 
						var inhalt='<form action="'+PATH+'CMS_doedit.php" method="post">'+
										  '<input type="hidden" name="elementID" value="'+theID+'" />'+
										  '<input type="hidden" name="lastPage" value="'+uri+'" />'+							  
										  '<textarea name="elementText" rows="8" cols="50">'+elementText+'</textarea>'+
										  '<br />Sortierung: <input type="text" size="5" name="sortierung" value="'+sortierung+'" />'+										  
										  '<input type="submit" value="update!" />'+
										  '</form>';
						var container="CMS_Container_"+theID;
						$(container).innerHTML=inhalt;					
					}
				});
			});
		}); // End CMS-Edit

		//CMS-New Button
		$$('a.cmsNew').each(function(element) {
			element.observe('click', function() {
				var elementText;
	
				var idx=element.id.split('_');
				var theID=idx[1];
				var sortierung=parseInt(idx[2])+1;
				var pageID=idx[3];
				var position=idx[4];				

				var uri=top.location.href;
				var inhalt='<form action="'+PATH+'CMS_donew.php" method="post">'+
								  '<input type="hidden" name="sortierung" value="'+sortierung+'" />'+
								  '<input type="hidden" name="position" value="'+position+'" />'+
								  '<input type="hidden" name="pageID" value="'+pageID+'" />'+
								  '<input type="hidden" name="lastPage" value="'+uri+'" />'+								  							  
								  '<textarea name="elementText" rows="8" cols="50">'+
								  '</textarea>'+
								  '<input type="submit" value="hinzufügen!" />'+
								  '</form>';
				var container="CMS_Container_"+theID;
				$(container).innerHTML=inhalt;					
			});
		}); // End CMS-New

		//CMS-Delete Button
		$$('a.cmsDelete').each(function(element) {
			element.observe('click', function() {
				var elementText;
	
				var idx=element.id.split('_');
				var theID=idx[1];

				var uri=top.location.href;
				var inhalt='<form action="'+PATH+'CMS_dodelete.php" method="post">'+
								  '<input type="hidden" name="elementID" value="'+theID+'" />'+
								  '<input type="hidden" name="lastPage" value="'+uri+'" />'+							  
								  'Sicher löschen?&nbsp;'+
								  '<input type="submit" value="Ja!" />'+
								  '</form>';
				var container="CMS_Container_"+theID;
				$(container).innerHTML=inhalt;					
			});
		}); // End CMS-Delete
		
		//CMS Edit Template
		$('CMSTemplates').observe('change', function() {
			var id=$('CMSTemplates').options[$('CMSTemplates').selectedIndex].value;
			top.location.href=PATH+"CMS_EditTemplate.php?ID="+id;
		});

		//CMS Edit Pages
		$('CMSPages').observe('change', function() {
			var id=$('CMSPages').options[$('CMSPages').selectedIndex].value;
			top.location.href=PATH+"CMS_EditSite.php?ID="+id;
		});		
		
	} // end if login

});
