$(document).ready(function(){

$("#quotebutton").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});

$(".partnobox tr:odd").css("background-color", "#ffffff");

  			$(".partnobox tr:even").css("background-color", "#efefef");



			  $('#enquiry-form').hide();



			  $('a#enquiry-button').click(function() {

				$('#enquiry-form').toggle(400);

				return false;

			  });



			$("a.zoom").fancybox();

 

			$("a.single_image").fancybox({

				'overlayOpacity'	:	0.7,

				'overlayColor'		:	'#FFF'

			});

 

			$("a.zoom2").fancybox({

				'zoomSpeedIn'		:	500,

				'zoomSpeedOut'		:	500

			});

	/* FORM SUBMISSION */
	$(".button-submit").click(function() {
		error = false;
		ErrorString = "ERROR\n\n";
		$(".ErrorMessage").remove();
		$(this).parent().parent().find(".required").each(function(index) {
			TheLength = $(this).val().length;
			TheFieldValue = $(this).val();
			TheFieldName = $(this).parent().find("label").text();
			TheFieldName = TheFieldName.replace("*", "");
			TheFieldName = TheFieldName.replace(":", "");
			if (TheLength < 1)
			{
				error = true;
				$(this).parent().find("label").css("color", "#ff4444");
				ErrorString = ErrorString + "Please enter a value for: " + TheFieldName + "\n";
			}
			else 
			{
				$(this).parent().find("label").css("color", "#efefef");
			}
		});
		/* CHECK IF EMAIL ADDRESS IS VALID */
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		EmailAddress = $(this).parent().parent().find(".email").val();
		if(!emailReg.test(EmailAddress)) {
            ErrorString = "ERROR\n\nPlease enter a valid Email Address\n";
            error = true;
			$(this).parent().parent().find(".email").parent().find("label").css("color", "#ff4444");
        }
		/* CHECK NUMBER FIELDS */
		$("#enquiry-form").find(".number").each(function(index) {
			TheNumber = $(this).val();
			if (TheNumber.length > 0){
				TheNumber = parseFloat(TheNumber);
					TheNumberCheck = isNaN(TheNumber);
				TheFieldName = $(this).parent().find("label").text();
					$(this).parent().find("label").css("color", "#ff4444");
				TheFieldName = TheFieldName.replace("*", "");
				TheFieldName = TheFieldName.replace(":", "");
				if (TheNumberCheck == true) {ErrorString = ErrorString + "Please enter only numbers for: " + TheFieldName + "\n"; error = true;}
			}
		});
		/* SUBMIT FORM IF NO ERRORS */	
		if (error == false){
			$(this).parent().parent().submit();
		}
		/* DISPLAY ALERT IF ERRORS */
		else
		{
			alert (ErrorString);
			$(this).parent().parent().find('p:first').prepend('<strong style="color: #ff4444" class="ErrorMessage">Errors in form submission data, please review the highlighted fields<br /><br /></strong>');
			return false;
		}
	});
	
});
