function submitComment(captchaCode){
	var focusField = false;
	var error = false;
	$('#name').tipsy("hide");
	$('#vorname').tipsy("hide");
	$('#email').tipsy("hide");
	$('#email').attr('title', 'Bitte geben Sie Ihre E-Mail einl');
	$('#nachricht').tipsy("hide");
	$('#code').tipsy("hide");
	$('#code').attr('title', 'Bitte geben Sie den Code ein');
	
	var i = 0;
	if($('#name').val() == ''){
		focusField = (focusField) ? focusField : 'name';
		$('#name').tipsy("show");
		error = true;
	}
	if($('#vorname').val() == ''){
		focusField = (focusField) ? focusField : 'vorname';
		$('#vorname').tipsy("show");
		error = true;
	}
	if($('#email').val() == ''){
		focusField = (focusField) ? focusField : 'email';
		$('#email').tipsy("show");
		error = true;
	}else if(!checkEmail($('#email').val())){
		focusField = (focusField) ? focusField : 'email';
		$('#email').attr('title', 'Bitte geben Sie eine g\u00FCltige E-Mail ein');
		$('#email').tipsy("show");
		error = true;
	}
	if($('#nachricht').val() == ''){
		focusField = (focusField) ? focusField : 'nachricht';
		$('#nachricht').tipsy("show");
		error = true;	
	}
	if($('#code').val() == ''){
		focusField = (focusField) ? focusField : 'code';
		$('#code').tipsy("show");
		error = true;	
	}else if($('#code').val() != captchaCode){
		focusField = (focusField) ? focusField : 'email';
		$('#code').attr('title', 'Bitte geben Sie den richtigen Code ein');
		$('#code').tipsy("show");
		error = true;
	}
	
	if(focusField){
		switch(focusField){
			case 'name':
				$('#name').focus();	
			break;
			case 'vorname':
				$('#vorname').focus();	
			break;
			case 'email':
				$('#email').focus();	
			break;
			case 'message':
				$('#nachricht').focus();	
			break;
		}
	}
	
	if(error){
		return false;	
	}else{	
		var commentName = $('#name').val();
		var commentVorname = $('#vorname').val();
		var commentEmail = $('#email').val();
		var commentNachricht = $('#nachricht').val();
		
		var ajaxVar = new ajaxVars();
	 	ajaxVar.vars['action'] = "runFunction";
	 	ajaxVar.vars['func'] = "submitComment";
	 	ajaxVar.vars['commentName'] = commentName;			 		
	 	ajaxVar.vars['commentVorname'] = commentVorname;			 		
	 	ajaxVar.vars['commentEmail'] = commentEmail;			 		
	 	ajaxVar.vars['commentNachricht'] = commentNachricht;			 		
	 	ajaxVar.gotoFunction = "submitCommentResponse";
	 	ajaxVar.AjaxPostSQL();
	}
}

function submitCommentResponse(data, fnVars){
	if(data == 'SUCCESS'){
		document.getElementById('guestbookForm').className = 'hiddendiv';
		document.getElementById('guestbookSuccess').className = 'visiblediv';
	}else{
		document.getElementById('guestbookForm').className = 'hiddendiv';
		document.getElementById('guestbookError').className = 'visiblediv';
	}
	
}

function checkEmail(email) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
        return true;
    }else{
        return false;
    }
}
