function z_netz_pm_from_patient_to_zahnarzt_form_send()
{    
    blende.show();     
    
    var inputs = [];
	$( ':input' , $('#pm_from_patient_to_zahnarzt_form') ).each(function(){ inputs.push(this.name + '=' + encodeURIComponent(this.value)); })
    jQuery.ajax({
    	url: site_url+'znetz/z_netz_ajax_functions/pm_from_patient_to_zahnarzt_send',
    	data: inputs.join('&'),
    	type: "POST",
    	timeout: 4000,
    	error: function(){ blende.hide();  console.log("25:Fehler"); },
    	success: function(ret){
            blende.hide();   	  
            var responseJSON = $.evalJSON(ret);
            if (!responseJSON.captcha_check) 
            { 
                alert('Captcha False');
            }
            else
            {
                $('#z_netz_popup_window').remove();
                alert('Ihre Nachricht wurde erfolgreich gespeichert!\nSie bekommen eine Email wenn Zahnarzt auf Ihre anfrage antwortet.')
            }
    		//$(document.body).append('<div id="fast_post_popup_window" style="margin-top:'+topx+'px" >'+responseJSON.loginhtml+'</div>');						
    	}
    });
}
function z_netz_get_popup_pm_from_patient_to_zahnarzt( loginData )
{    
    topx = parseInt(((document.all)?document.body.scrollTop:window.pageYOffset))+20;
	if ($('#fast_post_popup_window').length==0) 
	{
		var inputs = [];
		for( attr in loginData) { inputs.push( attr + '=' + encodeURIComponent(loginData[attr]));   }
        //$( loginData ).each(function(){ inputs.push(this.name + '=' + encodeURIComponent(this.value)); })
        
		jQuery.ajax({
		// data: 'user_id='+user_id,
		url: site_url+'znetz/z_netz_ajax_functions/get_popup_pm_from_patient_to_zahnarzt',
		data: inputs.join('&'),
		type: "POST",
		timeout: 4000,
		error: function(){ console.log("25:Fehler"); },
		success: function(ret){	
				var responseJSON = $.evalJSON(ret);
                if ( $('#z_netz_popup_window').length == 0 ){
				    $(document.body).append('<div id="z_netz_popup_window" style="margin-top:'+topx+'px" >'+responseJSON.loginhtml+'</div>');		
                }
                else
                {
                    $('#z_netz_popup_window').html( responseJSON.loginhtml );
                }				
			}
	});
		
	}
	else
	{
		$('#fast_post_popup_window').css('margin-top', topx+20+'px');
		$('#fast_post_popup_window').css('display','block');
	}
    
}
function z_netz_send_message_to(to_user_id , pat_conv)
{
    if (pat_conv)
    {
        datastring = 'pm_patient_hash='+to_user_id+'&pm_patient_conversation=true'+'&msg_text='+$('#pm_message_patient').val();
    }
    else
    {
        datastring = 'to_user_id='+to_user_id+'&msg_text='+$('#pm_message').val();
    }
	jQuery.ajax({
		// data: 'user_id='+user_id,
		url: site_url+controller.z_netz+'/send_message_to',
		data: datastring,
		type: "POST",
		timeout: 4000,
		error: function(){ console.log("25:Fehler"); },
		success: function(ret){	
				var responseJSON = $.evalJSON(ret);				
				PmMessagingObj.pm_last_msg_id = responseJSON.pm_last_msg_id;
                if (pat_conv) 
                {
                    var message_get_div = '#pm_message_patient'; 
                    var message_out_div = '#pm_content_message_output_patient';                    
                }
                else  
                {
                    var message_get_div ='#pm_message';
                    var message_out_div = '#pm_content_message_output';
                }
                $( message_get_div ).val('');
				$( message_out_div ).append(responseJSON.pm_quark);
				$( message_out_div ).attr({ scrollTop: $( message_out_div ).attr("scrollHeight")  });
							
			}
	});	
}
function z_netz_messaging_window( to_user_id , from_date /*timestamp*/ )
{
    blende.show();
	topx = parseInt(((document.all)?document.body.scrollTop:window.pageYOffset))+70;
	/*
	
	*/
	jQuery.ajax({
		// data: 'user_id='+user_id,
		url: site_url+controller.z_netz+'/show_pm_window',
		data: 'to_user_id='+to_user_id+'&from_date='+from_date,
		type: "POST",
		timeout: 10000,
		error: function(xhr, ajaxOptions, thrownError){ console.log("Fehler: unknown "+" Status unknown "+thrownError); setTimeout( function () {messaging_window(to_user_id , from_date)}, 3000 ); } ,
		success: function(ret){
		        blende.hide();
				//document.body.style.overflow = 'hidden';
				//$("body").css("overflow", "hidden");
				var responseJSON = $.evalJSON(ret);	
				if ($('#messaging_window').length!=0) 
				{
					$('#messaging_blende').css( 'display' , 'block'); $('#messaging_window').css( 'display' , 'block'); 
					$('#messaging_window').html(responseJSON.pm_content_message_output);
					$('#messaging_window').css( 'top' , topx+'px' );
										
				} else	
				{
					$(document.body).append('<div id="messaging_blende" style="top:'+topx+'px;" >&nbsp;</div>');
					$(document.body).append('<div id="messaging_window" style="top:'+topx+'px;" >'+responseJSON.pm_content_message_output+'</div>');	
					//$('#messaging_blende').css( 'display' , 'block'); $('#messaging_window').css( 'display' , 'block'); 
				} 
				$('#pm_message').focus();
				/* style="margin-top:'+topx+'px"*/
				pmDebugOn();
				$( '#pm_content_message_output').attr({ scrollTop: $('#pm_content_message_output').attr("scrollHeight")  });
				PmMessagingObj.pm_window_opend = true;
				PmMessagingObj.pm_last_msg_id = responseJSON.pm_last_msg_id;
				
				$('#pm_close_button').click( function(){ closeMessagingWindow(); } );
				
				isShift = false; 
				$('.pm_user_teaser_inner').mouseover( function(){ $(this).css('cursor','pointer'); $(this).css('cursor','hand'); } );
				
				$('.pm_user_teaser_inner').click( function(){ messaging_window( $('.pm_left_user_id' , this).val() ); } );
				$('#messaging_window').click( function(e){ if(e.target.id=='messaging_window')	{ closeMessagingWindow(); } } );
				$('#pm_message').keyup ( function(e){ if(e.which == 16 ) isShift=false;  } );
				
				$('#pm_message').keydown (function(e) {
					//alert(e.which);					
					if (e.which == 16) isShift=true;
					if (e.which ==13 && isShift == true)
				  	{
				  		//$('#pm_message').val($('#pm_message').val()+'\n');				  		
				  		//alert('mit shift');
				  	}
					else  
  					if (e.which ==13)
				  	{
				  		if ($('#pm_message').val()!='' && $('#pm_to_user_id').val() && !pm_patient_conversation )
						{  	
							z_netz_send_message_to( $('#pm_to_user_id').val() );
	  			 
						}	
                        else
                        if ( pm_patient_conversation )
                        {
                            z_netz_send_message_to( pm_patient_hash , true );
                        }
						setTimeout( function () {$('#pm_message').val('')}, 100)			  		
				  	}
				  	
  				}); 
				//alert(PmMessagingObj.pm_last_msg_id);
			}
	});	
    
	
}