// MAIL STUFF

function mail_cancel(){
	
	if(  $.trim($("#contact input[name=mail_name]").val()).length  || $.trim($("#contact input[name=mail_email]").val()).length  ||  $.trim($("#contact input[name=mail_betreff]").val()).length || $.trim($("#contact textarea").val()).length ) {
	
	    if (confirm('CANCEL?')) {
            $('#contact')[0].reset();
        }
	
	}
	}

	
function submit_email_form(){
	
	//alert('mail');
	
   var mail_name = $("#contact input[name=mail_name]").val();
   var mail_email = 	$("#contact input[name=mail_email]").val();
   var mail_betreff = $("#contact input[name=mail_betreff]").val();
   var mail_nachricht = $("#contact textarea[name=mail_nachricht]").val();
   
   
   //alert(mail_name);
   
   
   $('.mail_message #m_message').remove();

   
		 
	var dataString = 'mail_email=' + mail_email + '&mail_name=' + mail_name + '&mail_betreff=' + mail_betreff + '&mail_nachricht=' + mail_nachricht + '&mail_send_mail=true'  ;	 
	
	//alert(dataString);
  
      $.ajax({
		  url: "send_contact_mail.php",
		  global: false,
		  type: "POST",
		  data:  dataString,
		  dataType: "json",
		  async:true,
		 /* error:function(x,e){
									 
									      // $('#loadingmessage').hide();
									 
											if(x.status==0){
											alert('You are offline!!\n Please Check Your Network.');
											}else if(x.status==404){
											alert('Requested URL not found.');
											}else if(x.status==500){
											alert('Internel Server Error.');
											}else if(e=='parsererror'){
											alert('Error.\nParsing JSON Request failed.');
											}else if(e=='timeout'){
											alert('Request Time out.');
											}else {
											alert('Unknow Error.\n'+x.responseText);
											}
										},*/
		  
		  success: function(msg){
		  
		  if(msg.error == '0'){
			  
			  $('#contact')[0].reset();
			 
			 //$('#email_error').hide();
			 $('#email_error .mail_message').html("<span id='m_message' style='font-size:100%; color:#57b109;'>IHRE EMAIL WURDE ERFOLGREICH VERSENDET!<br /><br /></span>");
             
             
             $('#email_error').fadeIn(500);
										
	     }else{
					
				//alert('ERROR!');
			// $('#email_error').hide();
			 $('#email_error .mail_message').html("<span id='m_message' style='font-size:100%; color:#cd0a0a;'>IHRE EMAIL KONNTE NICHT VERSENDET WERDEN!<br />" + msg.error_text + "<br /><br /></span>");
             
             
             $('#email_error').fadeIn(500);  //, function() {
                  //$('#message').append("<img id='checkmark1' alt='checkmark' src='system_img/fail.png' >");
                                      //  });	
					
					
					
					
					
		}// end else
		     
			 
                 $("#email_error").delay(5000).fadeOut(500 , function(){
				    $('.mail_message #m_message').remove();
			     });
             
		     
										
		                       }// end success
		       });//end ajax
  
  
  
  
} // end function submit form	
