
		$(document).ready(function(){			
			$('#frmCallback').ajaxForm( { beforeSubmit: validateCallBackForm, success: handleResponse } ); 
			$('#frmCatalogue').ajaxForm( { beforeSubmit: validateCatalogueForm, success: handleResponse } ); 
			$('#frmSignup').ajaxForm( { beforeSubmit: validateSignupForm, success: handleResponse } );
			$('#frmSample').ajaxForm( { beforeSubmit: validateSampleForm, success: handleResponse } );
			$('#frmQuickQuote').ajaxForm( { beforeSubmit: validateQQForm, success: handleResponse } );			
			$('#frmContact').ajaxForm( { beforeSubmit: validateContactForm, success: handleResponse } );	
		
			$("#frmDateFrom").datepicker( { dateFormat: 'yy-mm-dd' });
			$("#frmDateTo").datepicker( { dateFormat: 'yy-mm-dd' });

			try {
				$(".validate").prev().append(" <span class=\"required\">*</span>");
			} catch(e) { }

		});
				

		$(function() {
			$('.lightbox').lightBox();
		});
				

		
		function validateForm(frmID, isAjax) 
		{
			var bError = false;
			var msg = '';
			

				$('#' + frmID + ' .validate').each(function(){
												if ($(this).val() == '') {
													$(this).focus();
													if ($(this).prev().text() == '*') {
														msg = 'field';
													}
													else {
														msg = $(this).prev().text();
													}																	
													alert('Please enter a value for ' + msg);													
													bError = true;													
													//throw true;
													return false;
												}										
										});
			


				if (!bError) {
					$("#" + frmID + " .email").each(function(){
												if ($(this).val().match(/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/) == null) {
													$(this).focus();
													if ($(this).prev().text() == '*') {
														msg = 'field';
													}
													else {
														msg = $(this).prev().text();
													}
													alert('Please enter a valid address for ' + msg);
													bError = true;
													//throw true;
													return false;
												}										
										});
				}
				
				if (!bError) {
						$("#" + frmID + " .numeric").each(function(){
												$(this).focus();
												if ($(this).val().match(/^\d+$/) == null) {
													$(this).focus();
													if ($(this).prev().text() == '*') {
														msg = 'field';
													}
													else {
														msg = $(this).prev().text();
													}
													alert('Please enter a numerical value for ' + msg);
													bError = true;
													//throw true;
													return false;
												}										
										});
				}
			
			
			
			//alert(bError);

			if (bError)	{				 
				return false;
			}
			else {
				if (!isAjax) {
					$('#' + frmID).submit();
					return false;
				}			
				else {
					return true;
				}
			}
		}


		function clearField(obj, str_default)
		{
			if ($(obj).val() == str_default)
			{
				$(obj).val('');
			}
			else if($(obj).val() == '') {
				$(obj).val(str_default);
			}

			
		}

		function resetForm(objId)
		{
			$('#' + objId).find(':input[type=text]').each(function() { $(this).val(''); });
		}

		function validateQQForm(formData, jqForm, options) {
			return validateForm('frmQuickQuote', true);			
		}

		function validateCallBackForm(formData, jqForm, options) {
			return validateForm('frmCallback', true);			
		}

		function validateCatalogueForm(formData, jqForm, options) {
			return validateForm('frmCatalogue', true);			
		}

		function validateSignupForm(formData, jqForm, options) {
			return validateForm('frmSignup', true);			
		}

		function validateSampleForm(formData, jqForm, options) {
			return validateForm('frmSample', true);			
		}

		function validateContactForm(formData, jqForm, options) {
			return validateForm('frmContact', true);			
		}

			
		function toggleVisibility(objId, obj) 
		{
			if (document.getElementById(objId).style.display == 'none' || document.getElementById(objId).style.display == '') {
				if ($(obj).children('span')) {
					$(obj).children('span').text('Hide');
				}				
				$('#' + objId).show("slide", { direction: "up" }, 1000);

			}
			else {
				if ($(obj).children('span')) {
					$(obj).children('span').text('Show');
				}								
				$('#' + objId).hide("slide", { direction: "up" }, 1000);			

			}
			return false;			
		}


		function handleResponse(responseXML) {
			var code = $('code', responseXML).text(); 
			if (code != 0)	{
				var message = $('message', responseXML).text(); 
				alert(message);
			}
			else 
			{
				var message = $('message', responseXML).text(); 
				alert(message);		
				tb_remove();
				
				$('#frmCallback').find(':input[type=text]').each(function() { $(this).val(''); });
				$('#frmCatalogue').find(':input[type=text]').each(function() { $(this).val(''); });
				$('#frmSignup').find(':input[type=text]').each(function() { $(this).val(''); });
				$('#frmSample').find(':input[type=text]').each(function() { $(this).val(''); });
				$('#frmContact').find(':input[type=text]').each(function() { $(this).val(''); });
				
			}		
			return false;
		}

		function checkEmail(strEmail) {
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(strEmail)) {
				return false;
			}
			return true;
		}

		function initialize() {
			var latlng = new google.maps.LatLng(50.749232,-1.805513);

			var myOptions = {
			  zoom: 12,
			  center: latlng,
			  mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

			var marker = new google.maps.Marker({
				position: latlng, 
				map: map,
				title:"Springfield Promotions"
			});  
		  }		
		 
