$(function() {
			
			
			
			//$.datepicker.setDefaults($.datepicker.regional['']);
			
			if ( $("#title").val() != '' &&  $("#title").val() != null)
				set_value_in_form('stitle', $("#title").val(), '')
					
				
			if ( $("#teaser").val() != '' &&  $("#teaser").val() != null)
				set_value_in_form('sdesc', $("#teaser").val(), '')
			
			if ( $("#fees").val() != '' &&  $("#fees").val() != null)
				set_value_in_form('sfees', $("#fees").val(), 'Eintritt: ')
				
			if ( $("#location").val() != '' &&  $("#location").val() != null)
				set_value_in_form('slocation', $("#location").val(), 'Ort: ')
			
			if ( $("#promoter").val() != '' &&  $("#promoter").val() != null)
				set_value_in_form('sauthor', $("#promoter").val(), 'Veranstalter:')
				
			if ( $("#links").val() != '' &&  $("#links").val() != null)
				set_value_in_form('slinks', $("#links").val(), '')

			
			
			$("#cn_search").datepicker($.extend({}, 
			$.datepicker.regional["de"], { 
				showStatus: true, 
				showOn: "both", 
				buttonImage: "/fileadmin/cn_calender/events_calender.gif", 
				buttonImageOnly: true,
				dateFormat: "dd.mm.yy" 
			})); 
			
			$("#von").datepicker($.extend({}, 
				$.datepicker.regional["de"], { 
				showStatus: true, 
				showOn: "both", 
				buttonImage: "/fileadmin/cn_calender/events_calender.gif", 
				buttonImageOnly: true,
				dateFormat: "dd.mm.yy" 
			})); 
			//$("#contrib").html("Milian Wolff");
			//$("#basics").datepicker();
			
			$("#bis").datepicker($.extend({}, 
			$.datepicker.regional["de"], { 
				showStatus: true, 
				showOn: "both", 
				buttonImage: "/fileadmin/cn_calender/events_calender.gif", 
				buttonImageOnly: true,
				dateFormat: "dd.mm.yy" 
			})); 
			
			
		});
		
		function prev_day(id){
			
			
			//alert ($('#'+id).val());
			//s_date = $('#'+id).val();
			//s_date_array = s_date.split('.')
			//s_date = s_date_array[0]+'-'+s_date_array[1]+'-'+s_date_array[2];
			//alert (s_date)
			
			$.ajax({
			   type: "POST",
			   url: "/fileadmin/cn_calender/get_date.php",
			   data: "cdate="+$('#'+id).val()+"&type=prev",
			   success: function(msg){
				 //alert( "Data Saved: " + msg );
				 $('#'+id).val(msg)
			   }
			 });
	
	
		}
		function next_day(id){
			
			//Date 
			//alert ($('#'+id).val());
			$s_date = $('#'+id).val();
			
			$.ajax({
			   type: "POST",
			   url: "/fileadmin/cn_calender/get_date.php",
			   data: "cdate="+$('#'+id).val()+"&type=next",
			   success: function(msg){
				 //alert( "Data Saved: " + msg );
				 $('#'+id).val(msg)
			   }
			 });
	
	
		}
		
		function set_value_in_form(id, dvalue, prefix){
			//alert (id)
			if (id != 'slinks'){
				if (dvalue != '' && dvalue != null)
					document.getElementById(id).innerHTML = prefix+dvalue;
				else
					document.getElementById(id).innerHTML = '';
			}
			else{
				
				re = "http://";   
				r = dvalue.search(re); 
				link_prefix = '';
				if (r == -1)
					link_prefix = "http://"
				
				if (dvalue != '' && dvalue != null)
					document.getElementById(id).innerHTML = prefix+'<a href="'+link_prefix+dvalue+'" target="_blank" >'+dvalue + '</a>';
				else
					document.getElementById(id).innerHTML = '';
					
			}
			
			//$.('#'+id).val(''+dvalue);
		}
		
		function test_msg (msg){
			if (msg != '' && msg != null )
				alert (msg);	
		}
		
		function check_event_form(){
			
			  alert_msg = "";
				
				if ( $("#title").val() == '' || $("#title").val() == null ){
						alert_msg += "Der Titel muss mindestens zwei Zeichen haben. \n";
				}
				
				if ( $("#cat").val() == '' ||  $("#cat").val() == null){
					//alert (123);
					alert_msg += "Bitte eine Veranstaltungsart angeben. \n";
				}
				
				if ( $("#von").val() == 'TT.MM.JJJJ' || $("#von").val() == '' || $("#von").val() == null ){
						alert_msg += "Bitte ein Datum in der Zukunft angeben. \n";
				}
				
				if ( $("#bis").val() == 'TT.MM.JJJJ' || $("#bis").val() == '' || $("#bis").val() == null ){
						alert_msg += "Entweder kein Datum oder eines nach dem Beginndatum eingeben. \n";
				}
				
				if ( $("#area").val() == '' ||  $("#area").val() == null){
					alert_msg += "Bitte eine Veranstaltungsregion angeben. \n";
				}
				
			  	if ( $("#location").val() == '' || $("#location").val() == null ){
						alert_msg += "Bitte einen Veranstaltungsort angeben. \n";
				}
				
				if ( $("#promoter").val() == '' || $("#promoter").val() == null ){
						alert_msg += "Bitte geben Sie den Namen des Veranstalters ein. \n";
				}
				
				if ( $("#author").val() == '' || $("#author").val() == null ){
						alert_msg += "Bitte geben Sie Ihren Namen ein. \n";
				}
				if ( $("#authoremail").val() == '' || !email_check($("#authoremail").val()) ){
						alert_msg += "Bitte geben Sie Ihre Email ein. \n";
				}
				
				if ( $("#ticketlink").val() == '' || $("#ticketlink").val() == null ){
						alert_msg += "Bitte geben Sie Ihre Tel. Nr ein. \n";
				}
				
					
				if (alert_msg != '' &&  alert_msg != null){
					alert (alert_msg);
				}
				else{
					return true;
				}
				
				return false;
								
		}
		
		function checkEventForm(){
			
				alert_msg = "";
				
				//Bitte f&uacute;llen Sie das Feld aus;
				
				if ( $("#date_1").val() == 'TT.MM.JJJJ' || $("#date_1").val() == '' || $("#date_1").val() == null ){
						alert_msg += "Bitte füllen Sie das Feld CN / NEZ Anzeigen Datum aus. \n";
				}
				
				if ( $("#date_1").val() == 'TT.MM.JJJJ' || $("#date_2").val() == '' || $("#date_2").val() == null ){
						alert_msg += "Bitte füllen Sie das Feld CH / Hk Anzeigen Datum aus. \n";
				}
				
				if ( $("#input_1").val() == '' || $("#input_1").val() == null ){
						alert_msg += "Bitte füllen Sie das Feld Uberschriff / FettzeilY aus. \n";
				}
				
				if ( $("#input_2").val() == '' || $("#input_2").val() == null ){
						alert_msg += "Bitte füllen Sie das Feld Gundtext / Anzeigente aus. \n";
				}
				
				if ( $("#input_6").val() == '' || $("#input_6").val() == null ){
						alert_msg += "Bitte füllen Sie das Feld Name / Vorname aus. \n";
				}
				
				if ( $("#input_10").val() == '' || $("#input_10").val() == null ){
						alert_msg += "Bitte füllen Sie das Feld E-mail-Address. \n";
				}
				else{
						
						if ( !email_check ($("#input_10").val()) )
							alert_msg += "Geben Sie eine gültige  E-mail-Address. \n";
				}
				
				
				if (alert_msg != '' &&  alert_msg != null){
					alert (alert_msg);
				}
				else{
					return true;
				}
				
				return false;
		}
		
		function email_check(email)
		{
			var emailchar = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			if (emailchar.test(email)){
				return true
			}
			else
			{
				return false;
			}
		}
