/* =====================================
   Intralign™ V1.00 - Released July 2010
   Copyright © 2010, Intraversed Pty Ltd
   Sydney, NSW Australia
   -------------------------------------
   History:
   V1.00 - first release.

   Author: Mark Gavin Atkins
   =====================================
*/
$(document).ready( function ()
	{
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	$('#yourName,#yourEmail,#msgSubject,#msgContent').bind('keyup',
		function(){
			if( emailPattern.test( $('#yourEmail').val() )
			&& $('#yourName').val() != ''
			&& $('#msgSubject').val() != ''
			&& $('#msgContent').val() != ''
			){
			
				$('#contactSubmit').unbind().bind('click',
					function(){
						$.post('./JQcontact.php', { yourName: escape( $('#yourName').val() ),
															yourEmail: escape( $('#yourEmail').val() ),
															yourPhone: escape( $('#yourPhone').val() ),
															msgSubject: escape( $('#msgSubject').val() ),
															msgContent: escape( $('#msgContent').val() )
																								  },
							function(data){
								var msg = ($('#error', data).text());
								if (msg != ''){
									$(this).sms( $('#error', data).html(), true );
								}else{
									$(this).sms(data);
									$('#contactCancel').trigger('click');
								}
						});
				}).parent().removeClass('disabled');
			}else{
				$('#contactSubmit').unbind().bind('click',
					function(){
						if (!emailPattern.test( $('#yourEmail').val() )) $(this).sms('Your email address is invalid!', true);
						if ( $('#yourName').val() == '' )				$(this).sms('Please provided your name! (mandatory field).', true);
						if ( $('#msgSubject').val() == '' )		$(this).sms('Please provided a subject! (mandatory field).', true);
						if ( $('#msgContent').val() == '' )		$(this).sms('The message is empty! (mandatory field).', true);
					}).parent().addClass('disabled');
			}
		});
				
	$('#contactSubmit').unbind().bind('click',
		function(){
			if (!emailPattern.test( $('#yourEmail').val()) ) $(this).sms('Your email address is invalid!', true);
			if ( $('#yourName').val() == '' )			$(this).sms('Please provided your name! (mandatory field).', true);
			if ( $('#msgSubject').val() == '' )		$(this).sms('Please provided a subject! (mandatory field).', true);
			if ( $('#msgContent').val() == '' )		$(this).sms('The message is empty! (mandatory field).', true);
		}).parent().addClass('disabled');

	$('#contactCancel').bind('click',
		function(){
			$('#yourName,#yourEmail,#yourPhone,#msgSubject,#msgContent').val('');
			return false;
		});
	
	$('#javaWarn').text('');

// send any alerts to the msgpopup area
	if($('#msgpopup p:first').text() != ''){
		var loadmsg = $('#msgpopup p:first').html();
		$('#msgpopup p:first').html('')
		$(this).sms(loadmsg);
	}

// end of the document ready code	
	});
