function CreateNewCaptcha()
{
	url = 'captcha_create.php';
	new Ajax.Request(url,{
			method: 'get',
			onSuccess: CreateNewCaptchaOK,
			onFailure: AjaxError
			});
}

function CreateNewCaptchaOK(request)
{
	var captchaID = request.responseText;
	$('ctheCaptcha').src = 'captcha.php?id=' + captchaID;
	$('btheCaptcha').src = 'captcha.php?id=' + captchaID;
}

function CreateContactMail()
{
	var thename = encodeURIComponent($('cname').value);
	var themail = encodeURIComponent($('cemail').value);
	var thesubj = encodeURIComponent($('csubject').value);
	var themsg  = encodeURIComponent($('cmsg').value);
	var targ = 'c';

	if (thename.length == 0) { alert('Please insert a name'); return; }
	if (themsg.length == 0) { alert('Please insert a message'); return; }

	var pars = '' +
		'username=' + thename +
		'&mail=' + themail +
		'&subj=' + thesubj +
		'&targ=' + targ +
		'&msg=' + themsg +
		'';

	if ($('ccaptcha'))
	{
		if ($('ccaptcha').value.length = 0)
		{
			alert('Please enter the Captcha');
			$('ccaptcha').focus
			return;
		}
		else
		{
			pars += '&captcha=' + $('ccaptcha').value;
		}
	}

	// Set Ajax Request
	var url = './contact_send.php';

	new Ajax.Request(url,{
				method: 'post',
				parameters: pars,
				onSuccess: CreateContactMailOK,
				onFailure: AjaxError
				});
}

function CreateContactMailOK(request)
{
	var return_code = request.responseText;
	if (return_code == '0') // Wrong Capture
	{
		// Somehow tell the user!
		alert('Wrong capture code!\nPlease try again');
		$('captcha').focus
		//Create new Code
		CreateNewCaptcha();
	}
	else if (return_code == 'true')
	{
		alert('E-Mail has been send');
		$('bform').style.display = 'none';
		var thename = $('cname').value;
		var themail = $('cemail').value;
		var thesubj = $('csubject').value;
		var themsg  = $('cmsg').value;
		deleteRow($('ctrsend'));
		deleteRow($('ctrcaptcha1'));
		deleteRow($('ctrcaptcha2'));
		$('ctdname').innerHTML = thename;
		$('ctdemail').innerHTML = themail;
		$('ctdsubject').innerHTML = thesubj;
		$('ctdmsg').innerHTML = themsg;
	}
	else
	{
		alert('Error sending EMail');
	}
}

function CreateBookingMail()
{
	var thename = encodeURIComponent($('bname').value);
	var themail = encodeURIComponent($('bemail').value);
	var thesubj = encodeURIComponent($('bsubject').value);
	var themsg  = encodeURIComponent($('bmsg').value);
	var targ = 'b';

	if (thename.length == 0) { alert('Please insert a name'); return; }
	if (themsg.length == 0) { alert('Please insert a message'); return; }

	var pars = '' +
		'username=' + thename +
		'&mail=' + themail +
		'&subj=' + thesubj +
		'&targ=' + targ +
		'&msg=' + themsg +
		'';

	if ($('bcaptcha'))
	{
		if ($('bcaptcha').value.length = 0)
		{
			alert('Please enter the Captcha');
			$('bcaptcha').focus
			return;
		}
		else
		{
			pars += '&captcha=' + $('bcaptcha').value;
		}
	}

	// Set Ajax Request
	var url = './contact_send.php';

	new Ajax.Request(url,{
				method: 'post',
				parameters: pars,
				onSuccess: CreateBookingMailOK,
				onFailure: AjaxError
				});
}

function CreateBookingMailOK(request)
{
	var return_code = request.responseText;
	if (return_code == '0') // Wrong Capture
	{
		// Somehow tell the user!
		alert('Wrong capture code!\nPlease try again');
		$('bcaptcha').focus
		//Create new Code
		CreateNewCaptcha();
	}
	else if (return_code == 'true')
	{
		alert('E-Mail has been send');
		$('cform').style.display = 'none';
		var thename = $('bname').value;
		var themail = $('bemail').value;
		var thesubj = $('bsubject').value;
		var themsg  = $('bmsg').value;
		deleteRow($('btrsend'));
		deleteRow($('btrcaptcha1'));
		deleteRow($('btrcaptcha2'));
		$('btdname').innerHTML = thename;
		$('btdemail').innerHTML = themail;
		$('btdsubject').innerHTML = thesubj;
		$('btdmsg').innerHTML = themsg;
	}
	else
	{
		alert('Error sending EMail');
	}
}
