/*
 * contact: information@wolfgangmarx.net
 * http://wolfgangmarx.net
 */
 
function sendExpress(){
	var strError = '';
	if(trim($('email').value)==''|| checkEmail($('email').value)==false){
		strError = addErrorText(strError, strEmailError);
	}
	if(trim($('vorname').value)==''){
		strError = addErrorText(strError, strVornameError);
	}
	if(trim($('nachname').value)==''){
		strError = addErrorText(strError, strNachnameError);
	}
	if(strError != ''){
		msgbox.info('<h1 class="info">Error</h1><br /><p>'+strError+'</p>');
	} else {
		var pars = 'mType=express&email='+trim($('email').value)+'&vorname='+$('vorname').value+'&nachname='+$('nachname').value;
		pars += '&anreise='+$('anreise').value+'&abreise='+$('abreise').value+'&erwachsene='+$('erwachsene').value+'&kinder='+$('kinder').value;
		new Request.HTML({
			url: BASE_URI+'sendMessages.php',
			method: 'post',
			data: pars,
			update: 'expressmessage',
			evalScripts: true }).send();
	}
}

function addErrorText(strCurentText, strAddText){
	if(trim(strCurentText)!=''){
		strCurentText += '<br />';
	}
	return strCurentText+strAddText
}

function removeNonNumeris(obj){
	obj.value = obj.value.replace(/[^0-9]/g, '');
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || '\\s';
    return str.replace(new RegExp('^[' + chars + ']+', 'g'), '');
}

function rtrim(str, chars) {
    chars = chars || '\\s';
    return str.replace(new RegExp('[' + chars + ']+$', 'g'), '');
}

function checkEmail(strMailAddress) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(strMailAddress)) {
		return false;
	}
	return true;
}