function sendForm() {
	var firstTimestamp = new Date().getTime();

	 	$('input[type=submit]').click(function(){
	    	$('#thema').val($(this).attr('value'));
	    });
	
	jQuery.fn.addEvent = jQuery.fn.bind;
	$('#contactForm').addEvent('submit',function(event){ 

		event.preventDefault();

		var secTimestamp = new Date().getTime();
		if (typeof(firstTimestamp) == undefined || secTimestamp - firstTimestamp < 10000) {
			var msg = 'Zur Abwehr von Spambots wird eine Zeitsperre eingesetzt. Bitte warten Sie einen Moment.';
			$('#log_res').append(msg);
			$('#log').css({display:'block'});
			var dispTime = ((secTimestamp - firstTimestamp)  > 6000) ? 4000 : 10000 - (secTimestamp - firstTimestamp);
			setTimeout("clearLog();", dispTime);
			return false;
		}
		
		if (!checkdata()) {
			return false;
		} else {

			//Empty the log and show the spinning indicator.
			var log = $('#log_res').empty().addClass('ajax-loading');

			// the callback function that tells us what the server-side process had to say
			var callback = function(dataReceived){
				$this.hide();
				$('#log').css({borderColor:'#fff'});
				$('#log').css({display:'block'});
				log.removeClass('ajax-loading');
				log.append(dataReceived);
				firstTimestamp = new Date().getTime();
			};
			
			// store reference to the form
			var $this = $(this);
			// grab the url from the form element
			var url = "include/contact.php";
			// prepare the form data to send
			var dataToSend = $this.serialize();
			// type of data to receive (in our case we're expecting an HTML snippet)
			var typeOfDataToReceive = 'text';			
			//Send the form.
			$.post( url, dataToSend, callback, typeOfDataToReceive );
			
		}		
	
	
	 });
};
	
function preventDefault(e) {
    e = e || window.event;
   (e.preventDefault)? 
       e.preventDefault() : e.returnValue = false;
}
	

function clearLog() {
	$('#log').css({display:'none'});
}

function checkdata () {
	var checked = "true";
	var check_email = /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-\.]+(\.[a-zA-Z]{2,3}){1,2}$/;
	var company  = $('#company').val();	
	var apname  = $('#apname').val();
	var phone  = $('#phone').val();	
	var message  = $('#message').val();	
	var email   = $('#email').val();
	
	if (!company) {
		$('#company').css({backgroundColor: '#6c6c6e'});
		
		checked = 'company';
	}
	if (!apname) {
		$('#apname').css({backgroundColor: '#6c6c6e'});
		checked = 'apname';
	}
	if (!email || ((check_email.test(email)) == false)) {
		$('#email').css({backgroundColor: '#6c6c6e'});
		checked = 'email';
	}	

	if (checked == "true") {
		return true;
	} else {
		var msg = 'Bitte &uuml;berpr&uuml;fen Sie Ihre Eingaben.';
		$('#log_res').empty().append(msg);
		$('#log').css({display:'block'});
		return false;
	}
}	

// Ein Layer beschreiben
function writeInto(obj, text, win) {
	if(!obj) return;
	if(typeof obj == "string") obj = getById(obj, win);
	
	if(typeof obj.innerHTML != 'undefined') {
  		obj.innerHTML = text;
	} else if(typeof document.layers != 'undefined') {
		obj.document.open('text/html');
    	obj.document.write(text);
     	obj.document.close();
	}
}
	
// getById(id [, win])
function getById(id, win) {
	var doc = window.document;
   	if(win) doc = win.document;

   	if(typeof id == 'undefined') return null;
	
	var obj = null;
	if(document.getElementById) obj = doc.getElementById(id);
	else if(typeof document.layers != 'undefined')  obj = _findObj_(id, doc);
	else if(document.all) obj = doc.all[id];

	return obj;
}
