function send_forms() {

  new Ajax.Request('inc/ajax/functions.php',   {     
    method:'post',
    parameters: $('contact_form').serialize(),   
    onLoading: function() {
      $('contact_submits').style.height = "20px";
      $('contact_submits').style.color  = "#AC0707";
      $('contact_submits').innerHTML    = "Wird versendet ...";
      Effect.Pulsate('contact_submits', { pulses: 20, duration: 10 });
    },
    onSuccess: function(transport) {
    	new Effect.SlideUp('contact_div',{ duration: 1.0, queue: { position: 'front', scope: 'scroller' }, afterFinish: function () {
    		$('contact_div').innerHTML = transport.responseText;                           
    		$('contact_div').setStyle( { height: $('contact_div').getHeight() } );
    		new Effect.BlindDown('contact_div', { duration: 1.0, queue: { position: 'end', scope: 'scroller' }});
    	}});
    	
    },    
    onFailure: function(e){ 
      alert('Something went wrong...'+e.status);
      return false;
    }   
  });

}

function send_contact_form() {
  var send = true;
  
  if (!check_field('from_vorname','Vorname')) {
    send = false;
  } else if (!check_field('from_nachname','Nachname')) {
    send = false;
  } else if (!check_field('from_email','E-Mail')) {
    send = false;
  } else if (!check_field('betreff','Betreff')) {
    send = false;
  } else if (!check_field('content','Nachricht')) {
    send = false;
  }
  
  if (send == true) {
    send_forms()
  }
}

function check_field(f,n,dv) {
  if (dv) {
  	va = dv
  } else {
  	va = "";
  }
  
  if ((typeof tinyMCE) == "object") {
	  if (tinyMCE.get(f)) {
	  	// MCE Check
	  	value = tinyMCE.get(f).getContent({format : 'text'}) // Get only the Text
	  	if (value == va) {
	  		alert("Bitte füllen Sie das Feld \""+n+"\" korrekt aus.");
	  		return false;
	  	}
	  	return true;
	  }
  }
  
  if (!$(f)) {
  	alert("Das Feld \""+n+"\" ist nicht vorhanden, bitte prüfen Sie Ihre Eingaben.");
  	return false;
  }
  
  if ($(f).readAttribute('type') == "checkbox") {
  	if ( $(f).checked ) {
  		return true;
  	} else {
  		alert("Bitte wählen Sie das Feld \""+n+"\" aus.");
  		return false;
  	}
  }
  
  if (trim($(f).value) == va) {
    alert("Bitte füllen Sie das Feld \""+n+"\" korrekt aus.");
    $(f).value = va;
    $(f).focus();
    return false;
  } else {
  	return true;
  }
}

function reloadCaptchaImage() {
	$('captchaImage').src = "inc/antispam.php?" + Math.floor(Math.random()*10000000000)
}

function update_status(transport) {
  var sta = $('status_div');     
  var response = transport.responseText;       
  sta.update(response); 
  Effect.Pulsate('status_div', { pulses: 3, duration: 2 });
}
