// Make the search box text disappear if it's default
function searchBoxFocus(elem) {
	if (elem.value == "keyword or item #")
		elem.value = "";
}

function searchBoxBlur(elem) {
	if (elem.value == "")
		elem.value = "keyword or item #";
}

// Displays the size chart below the passed in element
function displaySizeChart(e) {
	var values = Element.cumulativeOffset(e);
	
	$('size_chart').style.left = values.left + 60;
	$('size_chart').style.top = values.top - 10;
	$('size_chart').style.display = '';
}

function hideSizeChart(e) {
	$('size_chart').style.display = 'none';
}

// Changes the form action to go to the personalize page if they checked the personalize box
function changePersonalizeAction(frm, product) {
	if ($('personalize_order').checked)
		frm.action = "/cart/add/id/" + product + "/personalize/yes";
	else
		frm.action = "/cart/add/id/" + product;
}

// Verifies the product add form that has quantity, personalization, etc.
function verifyProductForm(frm) {
	if ($('item_size') != null && $('item_size').value == "") {
		alert("Please select an item size from the 'Select a Size' dropdown above.");
		return;
	}
	
	frm.submit();
}

// Submits the user's email address to our system to send them a "Forgot password" information email
function sendForgotPassword(email) {
	// Make sure we have some semblance of an email address
	if (!email || email == 'undefined') {
		alert("Please type in your email address below and we will send you a confirmation email if your email is in our system.");
		return;
	}
	
	// Fire off ajax request
	new Ajax.Request("/account/forgot", {
		parameters: 'email=' + email,
		onSuccess: function(res) {
			// Conver the response into JSON
			var obj = eval("(" + res.responseText + ")");
			alert(obj.message);
		}
	});
}

// Submits the user's email address to our system to send them a "Forgot password" information email
function joinMailingList(email) {
	// Make sure we have some semblance of an email address
	if (!email || email == 'undefined') {
		alert("Please enter your email address in order for us to add your name to the mailing list.");
		return;
	}
	
	// Fire off ajax request
	new Ajax.Request("/account/email", {
		parameters: 'email=' + email,
		onSuccess: function(res) {
			$("hidden_join").style.display = 'block';
		}
	});
}

// Save cart info
function saveCartInformation() {
	// Fire off ajax request
	new Ajax.Request("/cart/save", {
		parameters: '',
		onSuccess: function(res) {
			document.getElementById('cart_invoice').value = res.responseText;
			document.getElementById('customerInfoForm').submit();
		}
	});
}
