if (window.jQuery) {

jQuery.noConflict();

(function($) {
		

	$.productDetails = {
	
			checkControlText: function() {
				$.productDetails.checkMatrix();
				
				// Set this variable depending on which matrix form select the customer uses to add a product to their cart
				if ($('#productID1').val().length > 1) {
					var theProduct = $('#productID1').val();
				} else if ($('#productID2').val().length > 1) {
					var theProduct = $('#productID2').val();
				}

				var pars = new Date().getTime();			
				
				$.ajax({
					url: "../ajax/ajax_checkControlText.cfm?ts=" + pars,
					type: "GET",
					async: true,
					dataType: "xml",
					data: {
						prodID: theProduct
					},
					complete: function(request) {
						var xml = request.responseXML;

						$("hascontrol",xml).each(function(id) {
							var hasControlText = $(this).text();

							if (hasControlText == 0) {
								window.location = "../cart/shoppingCart.cfm?a=addMatrix&prodID=" + theProduct;
							} else {
								window.location = "../controlText.cfm?prodID=" + theProduct;
							}
						});

					}
				});	
			},
		
			checkMatrix: function() {
				if ($('#productID1').val().length < 1 && $('#productID2').val().length < 1) {
					alert ("You must first select a product to add to your shopping cart.");
					return false;
				}
			},
			

			estShipCost: function() {
					var url = "";
					
					// Set this variable depending on which matrix form select the customer uses to add a product to their cart
					if ($('#shipCostCountry').val().length == 0 && $('#shipCostState').val().length == 0) {
						alert("You must select either a country or US state before submitting this form.");
						return false;
					} else {
						var pars = new Date().getTime();
						$.ajax({
							url: "../ajax/ajax_estShipCost.cfm?ts=" + pars,
							type: "GET",
							async: true,
							dataType: "xml",
							data: "country=" + $('#shipCostCountry').val() + "&state=" + $('#shipCostState').val(),
							success: function(xml){
								$(xml).find('outputrow').each(function(){
			                         var shipRegion = $(this).find('shipregion').text();
			                         var shipTotal = $(this).find('shipcost').text();
									 var bodyText = $(this).find('bodytext').text();
			
									$.productDetails.returnEstShipCost(shipRegion,shipTotal,bodyText);
			                     }); //close each
							}
						})
					}	
				},

				returnEstShipCost: function(shipRegion,shipTotal,bodyText) {
					$('#estShipChargeDollarAmount').show().html(bodyText);
				},
			
				imageRollover: function(fullImg) {
					$('#theMainImageJawn').attr("src", "/images/rollovers/" + fullImg);
				}

	},
	
	$.shoppingCart = {

		disableProvince: function (formName,fieldName,provinceFieldName,stateFieldName) {
			var docForm = "document.forms." + formName + "." + fieldName;
			var provinceForm = "document.forms." + formName + "." + provinceFieldName;
			var stateForm = "document.forms." + formName + "." + stateFieldName;
		
			if (eval(docForm).value == 0) {
				eval(provinceForm).disabled = 1;
				eval(stateForm).disabled = 0;
			} else {
				eval(provinceForm).disabled = 0;
				eval(stateForm).options[0].selected = 1;
				eval(stateForm).disabled = 1;
			}
		},
		
		expShippingCheckbox: function() {
			if ($('#updateShipOption').is(':checked') && $('#customer_comment').val().length == 0) {
				alert("Write your specific need in the Order Comments box below — by what date and time must it arrive?");
				return false;
			} else {
				$("#finalizeForm").submit(); 
			}
		}
	},




	/*	document.ready shorthand - code within this block gets executed at page load */
	$(document).ready(function(){

		$('#search').focus();

		$('#searchBtn').click(function(){
			if ($('#search').val().length < 1) {
				alert ("Please enter your search criteria before submitting the form.");
				$('#search').focus();
				return false;
			} else {
				return true;
			}
		});
		
		$('img.imgRollover').hover(function() {
			$.productDetails.imageRollover($(this).attr('rel'));
		});
		
		$('#estShipCostFormSubmitBtn').click(function() {
			$.productDetails.estShipCost();
			return false;
		});
		
		$('#addrFormCountry').change(function() {
			$.shoppingCart.disableProvince('addrForm','country','province','state');
			return false;
		});
		
		$('#bcountry').change(function() {
			$.shoppingCart.disableProvince('bigForm','bcountry','bprovince','bstate');
			return false;
		});

		$('#shipcountry').change(function() {
			$.shoppingCart.disableProvince('bigForm','shipcountry','shipprovince','shipstate');
			return false;
		});
		
		$('#shipCostCountry').change(function() {
			$('#shipCostState').val('');
		});

		$('#shipCostState').change(function() {
			$('#shipCostCountry').val('');
		});
		
		$('#productID1').change(function() {
			if ($('#productID1').val().length > 1) {	
				$('#submit1Btn').removeAttr('disabled');
				$('#submit2Btn').attr('disabled', 'disabled');
				$('#wishlist1SubmitBtn').removeAttr('disabled');
			} else {
				$('#submit1Btn').attr('disabled', 'disabled');
				$('#submit2Btn').attr('disabled', 'disabled');
				$('#wishlist1SubmitBtn').attr('disabled', 'disabled');
			}
		});

		$('#productID2').change(function() {
			if ($('#productID2').val().length > 1) {	
				$('#submit2Btn').removeAttr('disabled');
				$('#submit1Btn').attr('disabled', 'disabled');
				$('#wishlist2SubmitBtn').removeAttr('disabled');
			} else {
				$('#submit1Btn').attr('disabled', 'disabled');
				$('#submit2Btn').attr('disabled', 'disabled');
				$('#wishlist2SubmitBtn').attr('disabled', 'disabled');
			}
		});
		
		$('#submit1Btn').click(function() {
			$.productDetails.checkControlText();
			return false;
		});

		$('#submit2Btn').click(function() {
			$.productDetails.checkControlText();
			return false;
		});

		$('#reviewSubmitBtn').click(function() {
			$.shoppingCart.expShippingCheckbox();
			return false;
		});
		
		$('#wishlist1SubmitBtn').click(function() {
			window.location = "../user_account/wishlist.cfm?a=add&ProdID=" + $('#productID1').val();
		});

		$('#wishlist2SubmitBtn').click(function() {
			window.location = "../user_account/wishlist.cfm?a=add&ProdID=" + $('#productID2').val();
		});
		
		$(".defaultText").focus(function(srcc) {
		        if ($(this).val() == $(this)[0].title) {
		            $(this).removeClass("defaultTextActive");
		            $(this).val("");
		        }
	    });
		    
	    $(".defaultText").blur(function() {
		        if ($(this).val() == "") {
		            $(this).addClass("defaultTextActive");
		            $(this).val($(this)[0].title);
		        }
	    });
		    
	    $(".defaultText").blur();  

		
		/* THIS IS THE CREATE ACCOUNT FORM "LEAVE BLANK IF NOT APPLICABLE STUFF!!!!!!!!! */
		loginFormInputs = $("input:text",document.forms.bigForm);
		loginFormInputs.filter("[class=leaveBlank]").css("background","#fff url('/images/leaveBlankText.jpg') no-repeat scroll 4px 4px");
		loginFormInputs.each(function(i) {
			if ($(this).val().length) {
				$(this).css("background","#FFF");
			}
		});
		
		$(".leaveBlank").focus(function() {
			$(this).css("background","#FFF");
		});

		$(".leaveBlank").blur(function() {
			if ($(this).val().length == 0) {
				$(this).css("background","#fff url('/images/leaveBlankText.jpg') no-repeat scroll 4px 4px");
			} else {
				$(this).css("background","#FFF");
			}
		});



	}); /* end document.ready */




})(jQuery);

}



