/*
 * Requires JQuery (Written using ver 1.2.2)
 * Requires jQuery Flash Plugin
 */

$(document).ready(function() { 
  insertFlash();
  clearTextfields();

	$('#register-form').submit(function() {
		$.post('/includes/php/register.php',{
				name: $('#name').val(),
				email: $('#email').val(),
				contact_phone: $('#contact_phone').val(),				
				company: $('#company').val(),				
				enquiry: $('#enquiry').val(),				
				action: 'register'
			}, function(xml) {
		    checkResponse(xml);
		});
		return false;
	});
});

/* 
 * Requires jQuery Flash Plugin
 * http://jquery.lukelutman.com/plugins/flash/
 */
function insertFlash() {
  $('#flash-inner').flash({
    src: '/media/axis.swf',
    width: 960,
    height: 417
  });
}

/* */
function clearTextfields() {
  // Find text fields
  var targets = $('input[type="text"]');
  
  // Set listener on each text field
  jQuery.each(targets, function() {
  
    $(this).one('click', function() {
      $(this).attr({value: ''});
    });
  
  });
}

/* */
function checkResponse(xml) {
 if ($('status', xml).text() != '1') {
   redrawPage();
 }
}

/* */
function redrawPage() {
  $('#register').fadeOut('slow', displayThanks);
}

/* */
function displayThanks() {
  $('#thankyou').fadeIn('slow');
  // Display the new text
  $('#thankyou-message').text('THANK YOU FOR CONTACTING US!');
}
