var qc = null;
var qc_form = null;
var taslide = null;
var scslide = null;

function init_quickContact () {
	
	qc = $('quick_contact');	
	qc_form = $('qc_form');
	
	qc_form.onsubmit = function () {
		quickContactSubmit();
		return false;
	}
	
	qc_form.qc_message.addEvent('focus', function (e) { 
		if (qc_form.qc_message.value == 'message') {
			qc_form.qc_message.value = ''; 
		}
	});
	
	taslide = new Fx.Slide('qc_form', { duration: 250 });
	scslide = new Fx.Slide('qc_success', {duration: 100 });
	scslide.hide();
	$('qc_success').style.display = 'block';
}

womAdd("init_quickContact();");

function quickContactSubmit () {	
		
	var email = null;
	
	$('qc_submit').disabled = true;
		
	// make sure email was provided
	if ($chk(qc_form.qc_email)) {
		if (qc_form.qc_email.value == '') {
			$('qc_error').innerHTML = 'Please provide a return email address.';
			$('qc_error').style.display = 'inline';
			$('qc_submit').disabled = false;
			return;
		}
		else {
			email = encodeURIComponent(qc_form.qc_email.value);
		}
	}
	
	$('working_img').style.display = 'inline';
		
	var msg = encodeURIComponent(qc_form.qc_message.value);
	var data = { 'msg': msg, 'email': email };
	var ajax = new Ajax("/includes/booker/ajax/quickContact.php", { method: 'post', postBody: Object.toQueryString(data), onComplete: quickContactUpdate }).request();
	
	return false;
}

function quickContactUpdate () {
	
	var r = arguments[0];
	$('working_img').style.display = 'none';

	if (r == 'SUCCESS') {
		$('qc_error').style.display = 'none';
		taslide.toggle();
		scslide.toggle();
	}
	else if (r == 'NO_MESSAGE') {		
		$('qc_error').innerHTML = 'Please write a message.';
		$('qc_error').style.display = 'inline';
		$('qc_submit').disabled = false;
	}
	else if (r == 'BAD_SEND') {
		$('qc_error').innerHTML = 'Error sending email. Please try again later.';
		$('qc_error').style.display = 'inline';
		$('qc_submit').disabled = false;
	}
	else if (r == 'NO_EMAIL_ADDRESS') {
		$('qc_error').innerHTML = 'Error with provided email address. Please try again.';
		$('qc_error').style.display = 'inline';
		$('qc_submit').disabled = false;
	}
}