// datei forum_funcs_1_3.js
// forum functions

var  my_ajax = {};
// form_id_or_data form_id wo die data abgeholt wird oder array mit data
my_ajax.send_ajax_request = function ( source , ausgabe_element_id , form_id_or_data , json  )
{    
    if (typeof( form_id_or_data ) == "object")
    {      
        var post_data =  form_id_or_data.join('&');
    }
    else
    {
        /*
        var inputs = [];
        $( ':input', '#' + form_id_or_data ).each(function(){ inputs.push(this.name + '=' + encodeURIComponent(this.value)); })
        */     
        var post_data = $('#'+form_id_or_data).serialize();  
      
    }  
    if ( ausgabe_element_id == 'z_netz_standart' || ausgabe_element_id  == '' || ausgabe_element_id == false )
    {
        
    }
    else
    {
        $('#'+ausgabe_element_id).append('<img src="http://www.zahnarzt-empfehlung.de/images/ajax_loader.gif" title="loading" />');
    }
    jQuery.ajax({		
		
		url: site_url + source,
		//data: inputs.join('&'),
		data: post_data,
		type: "POST",
		timeout: 4000,
		error: function(){ console.log("25:Fehler"); },
		success: function(ret){
		        var ausgabe = '';  
		        if ( json )
                {
                    var responseJSON = $.evalJSON(ret);
                    var css_class = '';
                    if ( responseJSON.message.css_class ) css_class  =  'class="' + responseJSON.message.css_class + '"';
                    
                    if (responseJSON.action == 'show_message') ausgabe = '<span '+css_class+'>' +responseJSON.message.text +'</span>';                    
                }
                else
                {  
                    ausgabe = ret;
                }
                if ( ausgabe_element_id == 'z_netz_standart' || ausgabe_element_id  == '' || ausgabe_element_id == false )
                {
                    topx = parseInt(((document.all)?document.body.scrollTop:window.pageYOffset))+20;
                    if ( $('#z_netz_popup_window').length == 0 )
				    $(document.body).append('<div id="z_netz_popup_window" style="margin-top:'+topx+'px" >'+ausgabe+'</div>');                    
                    else 
                    {
                        $('#z_netz_popup_window').css('margin-top' , topx );
                        $('#z_netz_popup_window').html( ausgabe );
                    }
                    $('#z_netz_message_wrapper').draggable();
                    
                    $('#z_netz_popup_window').focus();
                         
                } 
                else
                {
                    $( '#' + ausgabe_element_id ).html( ausgabe );
                }
                
               
                
                						
			}
	});
    return false;
}
patient_mag_des_email_input_popup = function( to_id , item_id , wat , erfolg , target_user_id )
{
    var data = new Array ('to_id='+to_id , 'item_id='+item_id , 'wat='+wat , 'erfolg='+erfolg , 'target_user_id='+target_user_id );
    my_ajax.send_ajax_request( 'ajax_function/patient_mag_des_email_input_popup' , 'z_netz_standart' , data , false );  
}
function save_new_patient_mag_des( user_email ,to_id,item_id,wat,erfolg,target_user_id )
{
    $('#z_netz_popup_window').remove();
    jQuery.ajax({
	
		
		data: 'user_email='+user_email,
		url: site_url+'ajax_function/save_new_patient_mag_des/'+to_id+'/'+item_id+'/'+wat+'/'+target_user_id,
		type: "POST",
		timeout: 10000,
		error: function(){ console.log("25:Fehler"); },
		success: function(ret){
			$('#'+erfolg).html(ret);
		
			}
	});
}
function z_netz_forum_beitrag(  t_id , p_id , kat_id  )
{
    //alert( typeof t_id);
    //console.warn('forum popup');
    data = new Array( 't_id='+t_id , 'p_id='+p_id , 'kat_id='+kat_id , 'source_url='+this_script  );
    /*
    var data = {};
    data.source_url = this_script;
    if (typeof t_id != 'undefined') data.t_id = 't_id='+t_id;
    if (typeof p_id != 'undefined') data.p_id = 'p_id='+p_id;
    if (typeof kat_id != 'undefined') data.kat_id = 'kat_id='+kat_id;
    */
   
    my_ajax.send_ajax_request( controller.forum+'/load_forum_beitrag_view/' , 'z_netz_standart' ,  data );   
}

function switch_display( id )
{
	if ( $('#'+id).css("display")=="none" || $('#'+id).css("display")=="" ) $('#'+id).css( "display" , "block"); else $('#'+id).css( "display" , "none");
}
function thread_new(form_id)
{	
	$('#new_thread_submit_button').css('display','none');
	$('#new_thread_ajax_action').css('display','inline');
	form_data = document.getElementById(form_id);
	form_data.onsubmit = new Function('return false');
	var inputs = [];
	$(':input', form_data).each(function(){ inputs.push(this.name + '=' + encodeURIComponent(this.value)); })
	jQuery.ajax({		
		data: inputs.join('&'),
		url: form_data.action,
		type: "POST",
		timeout: 10000,
		error: function(){ console.log("25:Fehler1"); },
		success: function(ret){ 
			//$('#divAnfrage').html(ret); 
			if ( ret == 0 ) 
			{ 
				$('#new_thread_submit_button').css('display','inline');
				$('#new_thread_ajax_action').css('display','none');
				alert ('Sicherheitscode Falsch!!!');
				
			}else
			if ( ret == 1 ) { window.location.replace(site_url+controller.forum+'/page/1'); 
		
			}else alert (ret);
			  
	
			}
			});	
		return false;
}
function kommentar_new( my_form_id , t_id )
{
	//form_data = document.getElementById(form_id);
	$('#new_kommentar_submit_button').css('display','none');
	$('#new_kommentar_ajax_action').css('display','inline');
	my_form = document.getElementById(my_form_id);
	var inputs = [];
	$(':input', my_form).each(function(){ inputs.push(this.name + '=' + encodeURIComponent(this.value)); })
	jQuery.ajax({
		data: inputs.join('&'),
		url: my_form.action,
		type: "POST",
		timeout: 10000,
		error: function(){ console.log("25:Fehler"); },
		success: function(ret){ 
			//$('#divAnfrage').html(ret); 
			if ( ret == 0 ) {
					$('#new_kommentar_submit_button').css('display','inline');
					$('#new_kommentar_ajax_action').css('display','none');
					alert ('Sicherheitscode Falsch!!!');					
			}
			if ( ret == 1 ) { window.location.replace(site_url+controller.forum+'/thread/'+t_id );   }
			}			 				
	});	
	return false;

}
function z_netz_antwort_auf(  t_id , p_id , kat_id  )
{
    var data = new Array ('p_id='+p_id , 't_id='+t_id , 'kat_id='+kat_id  );
    
    my_ajax.send_ajax_request( 'znetz/z_netz_ajax_functions/load_forum_kommentar_window_popup' , 'z_netz_standart' ,  data );
    
    return;
	$('#p_id').attr('value', p_id );
	if ( $('#new_kommentar_div').css( 'display' )=="none" || $('#new_kommentar_div').css('display') == "" ) $('#new_kommentar_div').css('display' , "block");
	//window.location.replace(this_script+'#new_kommentar_link' );
	$('#captchaImage').html('Wird geladen');
	setTimeout("refresh_captcha_ajax()",1000);
}

