document.observe('dom:loaded', function() {

	//Tarifrechner Links

	$$('a.tr').each(function(element) {
		element.observe('click', function() {
			var url="http://www.meine-pflegeversicherung.de/tarifrechner.php?ID="+element.id+"&sec_ref=mpv";
			open(url,"_blank","width=630, height=530, scrollbars=auto");
		});
	}); 
	$('tarifrechner').observe('click', function() {
		var url="http://www.meine-pflegeversicherung.de/tarifrechner.php?ID=ptg_vergleich&sec_ref=mpv";
		open(url,"_blank","width=630, height=530, scrollbars=auto");
	});		
	
	
	//################# Frontend-CMS ##############################//
	//################# by Oliver Wieland 2009
	//################# feel free to modify ;)
	
	var login=$('login').value;
	
	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="getCMSData.php?ID="+theID;
	
				new Ajax.Request(url, {
					method: 'get',
					onSuccess: function(transport) {
						elementText=transport.responseText;
						
						var uri=top.location.href;
						var inhalt='<form action="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 uri=top.location.href;
				var inhalt='<form action="CMS_donew.php" method="post">'+
								  '<input type="hidden" name="sortierung" value="'+sortierung+'" />'+
								  '<input type="hidden" name="pageID" value="'+pageID+'" />'+
								  '<input type="hidden" name="lastPage" value="'+uri+'" />'+								  							  
								  '<textarea name="elementText" rows="8" cols="50">Neuer Text</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="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 News
		$$('a.CMSEditNews').each(function(element) {
			element.observe('click', function() {
				var elementText;

				//Ajax-Request auf Element-Daten:
				var idx=element.id.split('_');
				var theID=idx[1];

				var url="getCMSNewsData.php?ID="+theID;

				new Ajax.Request(url, {
					method: 'get',
					onSuccess: function(transport) {
						elementText=transport.responseText.split('###');
						
						var uri=top.location.href;
						var inhalt='<form action="CMS_doeditNews.php" method="post">'+
										  'Titel: <input size="30" type="text" name="newstitel" value="'+elementText[0]+'" /><br /><br />'+
										  '<input type="hidden" name="elementID" value="'+theID+'" />'+
										  '<input type="hidden" name="lastPage" value="'+uri+'" />'+							  
										  'NewsText: <br /><textarea name="newstext" rows="4" cols="60">'+elementText[1]+'</textarea>'+
										  '<input type="submit" value="News aktualisieren!" />'+
										  '</form><br />';
						var container="CMSNewsEditBox";
						$(container).innerHTML=inhalt;					
					}
				});
			});
		}); // End CMS-Edit
					
		//CMS-Delete News
		$$('a.CMSDeleteNews').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="CMS_dodeleteNews.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="CMSNewsEditBox";
				$(container).innerHTML=inhalt;					
			});
		}); // End CMS-DeleteNews
		
		//CMS-New News Button
		$$('a.newNews').each(function(element) {
			element.observe('click', function() {
				var elementText;
				var uri=top.location.href;
				var inhalt='<form action="CMS_donewNews.php" method="post">'+
								  'Titel: <input size="30" type="text" name="newstitel" value="" /><br /><br />'+
								  '<input type="hidden" name="lastPage" value="'+uri+'" />'+							  
								  'NewsText: <br /><textarea name="newstext" rows="4" cols="60"></textarea>'+
								  '<input type="submit" value="Neue News eintragen!" />'+
								  '</form><br />';
				var container="CMSNewsEditBox";
				$(container).innerHTML=inhalt;					
			});
		}); // End CMS-New News					
			
			

		
		
	} // end if login

});