//110715 BUGFIX fehlende Events bei Aufruf von Anschlagbrett um Top-Menu
//110609 BUGFIX show bb details
//110516 impl /aj prefix for ajax calls
// Create events for Search results
function createSearchEvents(){
	$(".searchres").click(
			function(event) {
				$.get("/aj/content/getContentFromSearch/", { name: this.getAttribute('id'), key: "2pm" }, function(data) {
			  		$('#contentbox').html(data);
 			 	});
 			});
		//$(".searchres").css("color", "red");	
}
function createMailPostEvent(){//mails for gr
	$(".sendmailkey").click(function(event){
			$.post("/aj/mailer/sendfeedback/",
					$('#mailFeedbackForm').serialize(),
					function(data) 	{
						$('#contentbox').html(data);
					});
			});
}

function createParaMailPostEvent(){//mails for gr
	$(".sendparamailkey").click(function(event){
			$.post("/aj/mailer/sendparafeedback/",
					$('#paramailFeedbackForm').serialize(),
					function(data) 	{
						$('#contentbox').html(data);
					});
			});
}


function createMailTagEvents(){
		$(".mailtag").click(// click mailtag
				function(event){	//ajax load mailform
					$.get("/aj/mailer/mailform/"+this.getAttribute('id'),{ name: this.getAttribute('id')}, function(data) 
						{
							$('#contentbox').html(data);
							createMailPostEvent();// Post klick mailfeedback  transferred
							createParaMailPostEvent();
						});
				});// end click mailtag

		$(".paramailtag").click(// click mailtag
				function(event){	//ajax load mailform
					$.get("/aj/mailer/paramailform/"+this.getAttribute('id'),{ name: this.getAttribute('id')}, function(data) 
						{
							$('#contentbox').html(data);
							createMailPostEvent();// Post klick mailfeedback  transferred
							createParaMailPostEvent();
						});
				});// end click mailtag
}

function createContentPostEvent(){
	$(".contentcommitkey").click(//commit menu
			function(event){
				$.post("/aj/content/commitcontent/",
						$('#contentEditForm').serialize(),
						function(data){$('#contentbox').html(data);});
				});	
}

function createContentEditEvents(){
	$(".contentedittag").click(function(event){	
		event.preventDefault();
		$.get("/aj/content/editcontent/", { id: this.getAttribute('id'), time: "2pm" }, function(data) {
			$('#contentbox').html(data);//load loginform
			createContentPostEvent();
		});
	});
}

function createNewContentEvent(){
	//create Event for new content tag
	$('.newcontenttag').click(function(event) {
		event.preventDefault();
		$.get("/aj/content/createnewcontent/", { id: this.getAttribute('id'), time: "2pm" }, function(data) {
			$('#contentbox').html(data);	
		});
	});	
}

function createAbcEvents(){//create Event for abclist
	$('.abc').click(function(event) {
		event.preventDefault();
		$.get("/aj/content/getAbcContent/", { letter: $(this).html(), idmenu: this.getAttribute('id') }, function(data) {
			$('#subcontentbox').html(data);
			createContentEditEvents();//110429 BUGFIX no events on abc
		});
	});
}
function createDocOrderPostEvent(){
	$(".docorderkey").click(function(event){
			$.post("/aj/mailer/commitDocOrder/",
					$('#docOrderForm').serialize(),
					function(data) 	{
						$('#contentbox').html(data);
					});
			});
}

function createDocorderEvents(){//create Event for abclist
	$('.orderbtngray').click(function(event) {
		event.preventDefault();
		$.get("/aj/mailer/getDocOrderForm/"+this.getAttribute('id'), { iddoc:  this.getAttribute('id') }, function(data) {
			$('#contentbox').html(data);
			createDocOrderPostEvent();
		});
	});
}

function createVorgangDnlLink(){//110519 create link for dnload Vorgang from list
	$('.osline').click(function(event) {
		event.preventDefault();
		window.location.href = '/aj/schalter/pdfOsVorgang/?idvorg='+this.getAttribute('id');
	});
}

function createGoldDnlLink(){//create Events for net download on Bez
	$('.pubdocname').click(function(event) {
		event.preventDefault();
		window.location.href = '/aj/filer/goldDownLoad/?iddoc='+this.getAttribute('id');
	});
	$('.pubdocpdf').click(function(event) {
		event.preventDefault();
		window.location.href = '/aj/filer/goldDownLoad/?iddoc='+this.getAttribute('id');
	});
	
}//testOK

// Onlineschalter Events
//former call createGenericAjaxEvents('.osvorgang','/schalter/getSchalterForm/','#contentbox');// events for onlineschalter

function createSchalterDnloadEvent(){ //110526 get report after posting 
	$('.getreportkey').click(function(event) {
		event.preventDefault();
		window.location.href = '/aj/schalter/pdfOsVorgangUser/?idvorg='+this.getAttribute('id');
	});
}

function createSchalterPostEvent(){// 110526 replace createGenericAjaxPostEvent
	$('.sendvorgangkey').click(function(event) {
		$.post('/aj/schalter/postSchalterData/',$('#onlineSchalterForm').serialize(),
				function(data) 	{
			$('#contentbox').html(data);
			createSchalterDnloadEvent();
		});
	});
}

function createSchalterAdminVorgangEvent(){// 110613 allow to change Vorgang mailaddresse
	$('.sendvorgangadminkey').click(function(event) {
		$.post('/aj/schalter/postAdminMail/',$('#onlineSchalterAdminForm').serialize(),
				function(data) 	{
			$('#contentbox').html(data);
			//createSchalterDnloadEvent();
		});
	});
}

function createLoadSchalterFormEvent(){// set events to create schalter forms, require nongeneric
	//alert('***');
	$('.osvorgang').click(function(event) {
		event.preventDefault();
		$.get('/aj/schalter/getSchalterForm/'+this.getAttribute('id'), { id:  this.getAttribute('id') }, function(data) {
			$('#contentbox').html(data);
			//createGenericAjaxPostEvent('.sendvorgangkey','/aj/schalter/postSchalterData/','#onlineSchalterForm','#contentbox'); 110526 obsolete
			createSchalterPostEvent();
			createSchalterAdminVorgangEvent();//110613
		});
	});
}
function createNewEventEvent(){
	$('#createNewEvent').click(function(event) {
		event.preventDefault();
		 $.get("/aj/event/newEvent/", { id:  this.getAttribute('id') }, function(data) {
			 $('#contentbox').html(data);
			 createCommitEventEvent(); //event fpr POST
		 });
	});
}
function createEventsDropEvent(){//110610
	$('.dropeventtag').click(function(event) {
		var eventname=$(this).parent().parent().find(".evline1").find(".ev1").html();
		var r=confirm("Veranstaltung "+eventname+" löschen?");
		if(r==true){
		event.preventDefault();
			 $.get("/aj/event/dropEvent/", { id:  this.getAttribute('id') }, function(data) {
				 $('#contentbox').html(data);
			 });
		};
	});	
}
function createEventsDropAd(){//110610
	$('.dropadtag').click(function(event) {
		var adname=$(this).parent().find("font").html();
		var r=confirm("Inserat "+adname+" löschen?");
		if(r==true){
			event.preventDefault();
			 $.get("/aj/blackboard/dropAd/", { id:  this.getAttribute('id') }, function(data) {
				 $('#contentbox').html(data);
			 });
		};
	});	
}

function createEventsDetailEvent(){
	$('.evline1').click(function(event) {
		$(".evline2").hide("slow");
		$(".evline1").css({ color: 'black'});
		$(".evline1").css({ fontWeight: 'normal'});
		$(this).parent().find(".evline2").show("slow");
		$(this).css({ fontWeight: 'bold'});
		$(this).css({ paddingTop: '20px'});
		$(this).css({ color: '#149'});
		$(this).parent().find(".evline2").css({ color: '#149'}); //110531
		});
	
}
//Load Eventlist from Aktuell
function createEventCrosslinkEvents(){
	 $(".actevent").click(function(event) {
	 	 $.get("/aj/content/getContentFromMenu/", { name:  this.getAttribute('id') }, function(data) {
	 		$('#contentbox').html(data);
	 		createEventsDetailEvent();
	 		createNewEventEvent();
 			createEventsDropEvent();//110610
	 		createEventsShowBbDetail();
 			createEventsNewBbAd();
 			createEventsBbRules();

	 	 });
 	 });	
}
// 110504 Commit a new Event
function createCommitEventEvent(){
	$(".commiteventkey").click(function(event) {
		event.preventDefault();
		$.post("/aj/event/postEvent/",$("#commitNewEvent").serialize(),
				function(data) 	{
				$('#contentbox').html(data);
		});
	});
}

function createEventDropFile(){//110609
	$(".delfileimage").click(function(event) {
		var filename=$(this).parent().parent().find(".ficol4").html();
		var r=confirm("Datei "+filename+" löschen?");
		if(r==true){
			event.preventDefault();
			 $.get("/aj/filer/dropFile/", { id:  this.getAttribute('id') }, function(data) {
				 $('#contentbox').html(data);
			 });
		};
	});
		
}

//110503 get filelist
function getFileList(){
	$('#menuFileList').click(function(event) {
		event.preventDefault();
		 $.get("/aj/filer/showFileList/", { id:  this.getAttribute('id') }, function(data) {
			 $('#contentbox').html(data);
			 createEventDropFile();//110609
		 });
	});
	
}
//110518 schalter
function getSchalterList(){
	$('#menuSchalterList').click(function(event) {
		event.preventDefault();
		 $.get("/aj/schalter/showSchalterList/", { id:  this.getAttribute('id') }, function(data) {
			 $('#contentbox').html(data);
			 createVorgangDnlLink();
		 });
	});
	
}

function getSiteMap(){
	$('#menuSiteMap').click(function(event) {
		event.preventDefault();
		 $.get("/aj/menu/createSiteMap/", { id:  this.getAttribute('id') }, function(data) {
			 $('#contentbox').html(data);
			 //createVorgangDnlLink();
		 });
	});
	
}

function getPersList(){//110511
	$('#menuPersList').click(function(event) {
		event.preventDefault();
		 $.get("/aj/filer/showPersList/", { id:  this.getAttribute('id') }, function(data) {
			 $('#contentbox').html(data);
		 });
	});
	
}

//110503 uploadFile
function uploadFile(){
	$('#menuFileUpload').click(function(event) {
		event.preventDefault();
		 $.get("/aj/filer/uploadFile/", { id:  this.getAttribute('$(this).parent().find(".adcontent").show("slow");id') }, function(data) {
			 $('#contentbox').html(data);
		 });
	});
}

function showManual(){// Event for Menu Handbuch
	$('#menuManual').click(function(event) {
		event.preventDefault();
		 $.get("/aj/manual/showman/", { id:  this.getAttribute('id') }, function(data) {
			 $('#contentbox').html(data);
		 });
	});
}


// 110504 Create event for show BB Details
function createEventsShowBbDetail(){
	$('.adtitle').click(function(event) {
		event.preventDefault();
		//$(".adcontent").hide("slow");
		$(this).parent().find(".adcontent").show("slow");
		});
	
}

//create a new Ad in BB
function createEventsNewBbAd(){
	$('#bbNewAd').click(function(event) {
		event.preventDefault();
		 $.get("/aj/blackboard/newAd/", { id:  this.getAttribute('id') }, function(data) {
			 $('#contentbox').html(data);
			 createCommitAdEvent();
		 });
		
	});
}

//110505 create Event for Rules Display
function createEventsBbRules(){
	$('#bbShowRules').click(function(event) {
		event.preventDefault();
		 $.get("/aj/blackboard/getBbRules/", { id:  this.getAttribute('id') }, function(data) {
			 $('#contentbox').html(data);
		 });
		
	});
}
//110505 Commit a new Ad
function createCommitAdEvent(){
	$(".commitadtkey").click(function(event) {
		event.preventDefault();
		$.post("/aj/blackboard/bbPostAd/",$("#bbnewadform").serialize(),
				function(data) 	{
				$('#contentbox').html(data);
		});
	});
}
//110506 create Events on Search Result
function createSearchResultEvent(){
	$(".searchmenres").click(function(event) {
		event.preventDefault();	
		$.get("/aj/content/getContentFromMenu/", { id:  this.getAttribute('id') }, 
				function(data) 	{$('#contentbox').html(data);});
	});
}

function createContactLinkEvent(){//110531
	$("#contactlink").click(function(event) {
		event.preventDefault();	
		$.get("/aj/content/getContentFromMenu/", { name: 'main:3', time: "2pm"  }, 
				function(data) 	{$('#contentbox').html(data);});
	});
}

function createBbLinkEvent(){//110609
	$("#bblink").click(function(event) {
		event.preventDefault();	
		$.get("/aj/content/getContentFromMenu/", { name: 'main:8', time: "2pm"  }, 
				function(data) 	{
					$('#contentbox').html(data);
					createEventsShowBbDetail();
					createEventsBbRules();//110715 BUGFIX
					createEventsNewBbAd();//110715 BUGFIX
				});
		
	});
}

function createMobileInstructionEvent(){//110531
	$("#mobilelink").click(function(event) {
		event.preventDefault();	
		$.get("/aj/content/getMobileInstruction/", { name: 'main:3', time: "2pm"  }, 
				function(data) 	{$('#contentbox').html(data);});
	});
}

//getMobileInstruction
//......generic...........................................................................
function createGenericAjaxEvents(selector,target,destination){//par is read from id eg: selector: '.pubdocname' target "/mailer/getDocOrderForm/" destiantion '#contentbox' 
	$(selector).click(function(event) {
		event.preventDefault();
		$.get(target+this.getAttribute('id'), { id:  this.getAttribute('id') }, function(data) {
			$(destination).html(data);
			
		});
	});
}

//
function createGenericAjaxPostEvent(selector,target,formid,destination){ 
	//EG: selector: ".sendmailkey", target: /mailer/sendfeedback/,  formid: '#mailFeedbackForm', dedstination: '#contentbox'
	$(selector).click(function(event) {
		$.post(target,$(formid).serialize(),
				function(data) 	{
			$(destination).html(data);
		});
	});
}

//..................................generic..................

function createMenuEditCommitEvent(){// called from menuedittag
	$(".menucommitkey").click(//commit menu
			function(event){
				$.post("/aj/menu/menucommit/",
						$('#menuEditForm').serialize(),
						function(data){$('#contentbox').html(data);});
				});	
}

function createLoginFormCommitEvent(){ //commit login
	$(".logincommitkey").click(// click mailtag, creata ajaxcall for commit
			function(event){
				$.post("/aj/login/logincommit/",
						$('#loginForm').serialize(),
						
						function(data){
							location.reload();
							//$('#contentbox').html(data);
						});
				});	
}
function showHiddenContentEvent(){// click mailtag, creata ajaxcall for commit
	$(".ctitle_rev").click(function(event) {
		$(".ctitle_rev").css({ color: 'black'});
		$(".ctitle_rev").css('font-weight', 'normal');//110527
		//$(this).css({ color: 'blue'});
		$(this).css('font-weight', 'bold');//110527
		$(this).css('margin-top', '20px;');
    	$(".ccontent").hide("slow");
    	$(this).parent().find("div").show("slow");
    	$(this).css({ color: '#149'});
    	$(this).parent().find("div").css({ color: '#149'}); //110531
		
	});	
}
//jquery ready==============================================================================0  $(this).css({ color: 'blue'});
//==============================================================================0
	$(document).ready(function(){
	  	createContentEditEvents();
		createMailTagEvents();
		createNewContentEvent();
		createAbcEvents();
		createDocorderEvents();
		createGoldDnlLink();
		createEventsDetailEvent();
		createNewEventEvent();
		createEventsDropEvent();//110610
		createEventsShowBbDetail();
		createEventsNewBbAd();
		createEventsBbRules();
		showHiddenContentEvent();//110510
		
		
		//get Maincontent STARTEVENT--------------------------------------------------------------
			/*110517 ausgelagert index >> static content
		  $.get("/aj/content/getContentFromMenu/", { name: 'main:73', time: "2pm" }, function(data) {
    			  $('#contentbox').html(data);
    		  	createContentEditEvents();
  	 			createMailTagEvents();
	 			createNewContentEvent();
	 			createAbcEvents();
	 			createDocorderEvents();
	 			createGoldDnlLink();
	 			createEventsDetailEvent();
	 			createNewEventEvent();
	 			createEventsShowBbDetail();
	 			createEventsNewBbAd();
	 			createEventsBbRules();
	 			showHiddenContentEvent();//110510
		  });
		  */
		  // get Contentright
		  $.get("/aj/content/getContentRight/", { name: 'right:0', time: "2pm" }, function(data) {
			  $('#rightbox').html(data);
			  createEventCrosslinkEvents();// event for Crosslink to Eventslist
	 	 	});
	 	 

		
		// create Event for neu mainmenu
		$('#createMainMenu').click(function(event) {
			event.preventDefault();
			$.get("/aj/menu/createnewmainmenu/", { id: this.getAttribute('id'), time: "2pm" }, function(data) {
				$('#contentbox').html(data);	
			});
		});


			
		//dynamic set events on search results
		//$(".newsearch").live("change",function(){
		//	createSearchEvents();
		//});

		//110501 post schalter event
		//$(".osvorgang").live("click",function(){
		//	createGenericAjaxPostEvent('.sendvorgangkey','/schalter/postSchalterData/','onlineSchalterForm','#contentbox');
		//});

		// suppress displaying secondary menus >> acontent/getContent.php
    	$(".secmenu").css("display","none");

		//show content mainmenu
    	
    	var currentOpenNode = null;
    	$(".men0").click(function(event) 
    	{ // handle mainmenu
    		
     		event.preventDefault();
 //   		$(".secmenu").hide("slow");
 //   		$(this).parent().parent().find("ul").show("slow");
     		if(currentOpenNode != this)
     		{
     			$(".secmenu").slideUp('slow');
     			$(this).parent().parent().find("ul").stop(true,true).slideDown('slow');
     		}
    		
     		$.get("/aj/content/getContentFromMenu/", { name: this.getAttribute('id'), time: "2pm" }, function(data) {
    			  $('#contentbox').html(data);
    			  createContentEditEvents(); 
    			  createNewContentEvent();
    			  createLoadSchalterFormEvent()
    			  createGoldDnlLink(); //dnload of files
    			  showHiddenContentEvent();//110510
    			  
    			  //createGenericAjaxEvents('.osvorgang','/schalter/getSchalterForm/','#contentbox');// events for onlineschalter
    			}); 			    		
     		createEventsBbRules();
     		currentOpenNode = this;
        });

    	//create edit events for menu
    	$(".menuedittag").click(function(event) { 
    		event.preventDefault();
    		$.get("/aj/menu/editmenu/", { id: this.getAttribute('id'), time: "2pm" }, function(data) {
    			$('#contentbox').html(data);//load loginform
    			//%%%
    			createMenuEditCommitEvent()

    		});
    	});
        
		//create event for login
		$("#login00").click(function(event){
			event.preventDefault();
			$.get("/aj/login/loginform", { name: this.getAttribute('id'), time: "2pm" }, function(data) {
				$('#contentbox').html(data);//load loginform
				//%%
				createLoginFormCommitEvent()

				//%%
				});
		});
		//create event for logout
		$("#logout00").click(function(event){
			event.preventDefault();
			$.get("/aj/login/logout", { name: this.getAttribute('id'), time: "2pm" }, function(data) {
				location.reload();
				//$('#contentbox').html(data);//load loginform
			});
		});

		 
    	// create Content event for submenus-------------------------------------------------------------
    	//===================================================================================================
        $(".men1").click(function(event) 
        { // click menu1
        	event.preventDefault();
        	// ........get content...........
    		$.get("/aj/content/getContentFromMenu/", { name: this.getAttribute('id'), time: "2pm" }, function(data) 
    	    {
	  		 	$('#contentbox').html(data);//load mailform  exeptiopn rundgang id: menu:31
	  		 	createContentEditEvents(); // create events for content editor
	 			// create event for content - mailklick--------------
	 			createMailTagEvents();
	 			createNewContentEvent();
	 			createAbcEvents();
	 			createDocorderEvents();
	 			createGoldDnlLink();
	 			createEventsDetailEvent();
	 			createNewEventEvent();
	 			createEventsDropEvent();//110610
	 			createEventsShowBbDetail();
	 			createEventsNewBbAd();
	 			createEventsBbRules();
	 			createEventsDropAd();//110610
				//----------------------------
	  		 	//$(".mailtag").css("color", "red");
    		});
         });
        
		// search control--------------------------------------------------------------------
    	$(".newsearch").keyup(function(event) 
    	{//klickevent for search
    		event.preventDefault();
    		$.get("/aj/search/getSearchResult", { sval: this.value, time: "test" }, function(data) {// class...
     		 	$('#contentbox').html(data);
     		 	createSearchEvents();
       		});
    	});

    	createContactLinkEvent();//110531 horiz menu
    	createBbLinkEvent(); //110608 bblink
    	createMobileInstructionEvent();//110531 Mobile-Instruction
		getFileList();// get filelist
		getSchalterList();
		getSiteMap();//110613 sitemap
		getPersList();
		uploadFile();// upload
		showManual(); // Manual
		
     });//ready event
//========================================jquery===========================================0		
