(function($) {

	// Global functions that need to run on every page to setup various interface elements
	$(function() {
	
		/* Setup the main navigation
		----------------------------------------------------*/
		(function(){
		
			var subNavTimer;
			
			var globalNav = $("#navGlobal");
			
			//var selectedTimer;
			
			//var currentSelectedNavItem = $("#navGlobal > li.topLevel > a.selected");
			
		
			$("#navGlobal > li").bind("mouseover", function() {
			
				$(this).addClass("over");

				//temporarily unselect the currentSelectedNavItem & make sure it doesn't get re-selected by the timeout
				//currentSelectedNavItem.removeClass("selected");
				//console.log($(this).attr("id") + " mouseover");
				//clearTimeout(navTimer);
				//clearTimeout(selectedTimer);

			}).bind("mouseout", function(event) {
			
				$(this).removeClass("over");
				//console.log($(this).attr("id") + " mouseout")
				
				/*
				console.log($(this).attr("id") + " mouseout");
				selectedTimer = setTimeout(function() {
					currentSelectedNavItem.addClass("selected");
				}, 500);
				*/
				
				//currentSelectedNavItem.addClass("selected");
				
				//console.log("Added class 'selected' to " + currentSelectedNavItem.parent().attr("id"));
				
			});
			
			globalNav.find("ul.subNav li").bind("mouseover", function() {
				$(this).addClass("over");
				$(this).siblings().removeClass("over");
				clearTimeout(subNavTimer);
				
			}).bind("mouseout", function() {
				var subNavItem = $(this);
				subNavTimer = setTimeout(function(){
					subNavItem.removeClass("over");
				}, 100);
			});
			
			//Add focus handling to aid in keyboard navigation
			var navTimer;
			
			globalNav.find("li a").bind("focus", function() {
			
				//If it's a sub-menu link, make sure the sub-menu stays open and the main nav item still shows as "over"
				if ($(this).parents(".subNav").length > 0) {
					$(this).parent().trigger("mouseover");
					clearTimeout(navTimer);
				}

				$(this).parent().trigger("mouseover");			
				
			}).bind("blur", function() {
			
				var navItem = $(this);
				//Set a slight delay before firing the mouseout event for this nav item (which will remove the "over" class and cause the sub menu to be hidden again). This delay will be cancelled out if the next item to get focus is still inside the currently visible sub menu.
				navTimer = setTimeout(function() {
					navItem.parent().trigger("mouseout");
				}, 50);
				
			});			
	
		})();
		
		
		/* Setup Chat Offline Tooltip for Global Header
		----------------------------------------------------*/
		(function() {

			// Configure tooltip
			$("#chatOffline").setupComponents();
			$("#chatTooltip").tooltip({belowAnchor: true});
			setTimeout(function() {
					$("#chatOffline").hide();
				}, 1);
			
			// Holiday hours
			$(".chatHolidayHours").hide();
			$("#showChatHolidayHours").live("click", function(event) {
				event.preventDefault();
				$(".chatHolidayHours").toggle("fast");												  
			});
			
		})();
		
		/* Setup the Search form in the nav
		----------------------------------------------------*/
		(function() {
			
			var searchLabel = $("#frmSearch label");
			var searchField = $("#frmSearch #txtSearch");
			
			searchLabel.hide();
			searchField.val(searchLabel.text());
	
			//Event handlers
			searchField.bind("focus", function() {
				if ($(this).val() == searchLabel.text()) {
					//Clear the text field
					searchField.val("");
				}
			});
			searchField.bind("blur", function() {
				if ($.trim($(this).val()) == "") {
					searchField.val(searchLabel.text());
				}
			});
			
		})();
		
	
		
		/* Hide the Site Map and setup the events for it
		----------------------------------------------------*/
		
		(function() {
		
			var siteMapForm = $("#siteMap div.siteMapColSignUp form");
			
			siteMapForm.find('input[type=text]').focus(function(){
				var target = $(this);
				target.attr('value', '');
			});
			
			/*
			siteMapForm.find('input[type=text]').blur(function(){
				var target = $(this);
				var targetLabalText = target.prev('label').text();
				
				if((target.attr('value') == '')){
					target.attr('value', targetLabalText);
				}
			});
			*/
			
			siteMapForm.find('input[type=submit]').unbind('click').bind('click', function(){
				
				var target = $(this);
				
				var	signUpForEmailForm = target.closest('#siteMapEmailSignupForm');
				
				signUpForEmailForm.find("label.error").remove();
				
				var signUpEmailFormFields = {
					emailAddress: {
						name: "signUpEmailAddress",
						type: "emailAddress",
						required: true,
						emptyErrorMessage: Sprint.content.formFieldErrors.emailAddressEmpty[Sprint.currentLanguage],
						invalidErrorMessage: Sprint.content.formFieldErrors.emailAddressInvalid[Sprint.currentLanguage]
					},
					zipCode: {
						name: "signUpZipCode",
						type: "zipCode",
						required: true,
						emptyErrorMessage: Sprint.content.formFieldErrors.zipCodeEmpty[Sprint.currentLanguage],
						invalidErrorMessage: Sprint.content.formFieldErrors.zipCodeInvalid[Sprint.currentLanguage]
					}
				};
				
				var validForm = Sprint.fn.validateForm(signUpForEmailForm, signUpEmailFormFields);
			
				if(validForm == true){
				
					signUpForEmailForm.submit();
					
				} else {
				
					signUpForEmailForm.showFormErrors({
                        showInline: true,
                        showSummary: false,
                        errorData: validForm
                    });
                    
                    return false;
					
					/*
					if(validForm.signUpEmailAddress != null){
						if($('#siteMapEmailSignupForm span.'+validForm.signUpEmailAddress.name).length == 0){						
							signUpForEmailForm.find('input[name='+validForm.signUpEmailAddress.name+']').before(
								'\<span class="'+validForm.signUpEmailAddress.name+'"\>! '+validForm.signUpEmailAddress.errorMessage+'\</\span\>'
							);
						}
					} else {
						if(signUpForEmailForm.find('span.signUpEmailAddress').length > 0){						
							signUpForEmailForm.find('span.signUpEmailAddress').remove();
						}
					}
					
					if(validForm.signUpZipCode != null){
						if($('#siteMapEmailSignupForm').find('span.'+validForm.signUpZipCode.name).length == 0){
							signUpForEmailForm.find('input[name='+validForm.signUpZipCode.name+']').before(
								'\<span class="'+validForm.signUpZipCode.name+'"\>! '+validForm.signUpZipCode.errorMessage+'\</\span\>'
							);
						}
					} else {
						if(signUpForEmailForm.find('span.signUpZipCode').length > 0){
							signUpForEmailForm.find('span.signUpZipCode').remove();
						}
					}
					return false;
					*/
				}
				
			});
			
			/*
			// commented out for the latest release of footer, did not delete in case the use case changes
			var siteMap = $("#siteMap");

			siteMap.hide();
			
			//setup event handling for the sitemap link
			$("#siteMapLink").bind("click", function() {
			
				var siteMapLink = $(this);
				
				if(siteMap.is(".open")) {
					siteMap.slideUp(1000, function() {
		
						siteMapLink.removeClass("open");
					
					}).removeClass("open");
				}
				else {
					siteMap.slideDown(50, function() {
					
						//scroll to the siteMapLink (which will make sure that the sitemap is in view)
						siteMapLink.scrollTo({
							speed: 1000,
							afterScroll: function() {
								siteMapLink.addClass("open");
							}
						});
					
					}).addClass("open");
				}
				
				return false;
			
			});
			*/
			
		})();
		
		
		
		/* Convert low-res buttons to high-res buttons
		----------------------------------------------------*/
		$(".sprint input[type='submit'], .sprint input[type='button'], .sprint a.button1, .sprint a.button2, .sprint a.button3, .sprint a.button4, .sprint a.flyout").createHighResButtons();


		/* Setup all default components with default values except for buttons
		----------------------------------------------------*/
		$().setupComponents({
			modals: true,
			buttons: false
		});

		
		
		/* Adds Print button to container
		----------------------------------------------------*/
		$(".printButtonContainer").show();
		
		

		/* Default Error Messaging Behaviour
		----------------------------------------------------*/
		$("ul.formErrors li a").live("click", function() {
		
			//Find the anchor target that this error links to
			var anchorTarget = $(this).attr("href");
			
			//strip off everything before the "#"
			anchorTarget = anchorTarget.substr(anchorTarget.indexOf("#"));
			
			$(anchorTarget).scrollTo({speed: "slow"});
			
			//Set focus to the field that the label represents and select any text that may be inside
			$("#"+$(anchorTarget).attr("for")).trigger("focus").trigger("select");
			
			return false;
		
		});
		
		
		
		/* Sign-In
		-------------------------------------------------*/
		(function() {
		
			var submitLoginForm = false;
			var frmUserLogin = $("#frmUserLogin");
		
			//Make sure form submission goes through the Sign In button.
			frmUserLogin.bind("submit", function(event) {

				if (!submitLoginForm) {
					event.preventDefault();
					
					frmUserLogin.find("#btnLoginSubmit").trigger("click");
				}
				
			});
			/*
			frmUserLogin.find("#btnLoginSubmitEmailVerification").unbind("click").bind("click", function(event)) {
				event.preventDefault();
				
				var submitButton = $("#btnLoginSubmitEmailVerification").clone(true);
				
			}*/
			
			frmUserLogin.find("#btnLoginSubmit").unbind("click").bind("click", function(event) {
				event.preventDefault();
				
				//Submit the form using an AJAX request.
				var formPath = frmUserLogin.attr("action");
				
				$.ajax({
					
					data: frmUserLogin.serialize(),
					type: "POST",
					url: formPath,
					dataType: "json",
					
					success: function(data) {
						
						//Remove any previous error messages
						frmUserLogin.find("ul.formErrors").remove();
						frmUserLogin.find(".error").removeClass("error");

						if (data.validated) {										
							//Submit the registration form.
							window.location = data.nextPage;
						}
						else if (data.accountLocked) {
							//Account locked, show account locked message.
							var errorList = $("<ul class=\"formErrors\"><li>"+data.accountLockedErrorHeader+"</li></ul><p>"+data.accountLockedErrorMessage+"</p>");
							
							//Empty the form, change it's action, put in the new fields
							frmUserLogin.attr("action", data.accountResetPath);
							frmUserLogin.find("fieldset").html(errorList);
							
							//Reset checkbox
							var resetCheck = $("<div><label for=\"chkLoginAccountReset\" id=\"lblLoginAccountReset\"><input type=\"checkbox\" class=\"check\" name=\"chkLoginAccountReset\" id=\"chkLoginAccountReset\" /> "+data.accountLockedResetLabel+"</label></div>");
							
							resetCheck.appendTo(frmUserLogin.find("fieldset"));							
							
							//Put in the new submit button.
							var newSubmitButton = $("<input type=\"submit\" class=\"button1\" id=\"btnLoginSubmit\" value=\""+data.accountResetButtonLabel+"\" />");
							
							newSubmitButton.appendTo(frmUserLogin.find("fieldset"));
							
							newSubmitButton.wrap("<div class=\"buttons\"></div>");
							
							newSubmitButton.createHighResButtons();
							
							$("#btnLoginSubmit").unbind("click").bind("click", function(event) {
								
								event.preventDefault();
								
								//if the reset account checkbox is checked, submit the form. If not, do nothing.
								if ($("#chkLoginAccountReset").is(":checked")) {
									submitLoginForm = true;
									
									frmUserLogin.eq(0).submit();
								}
								
							});
						} 
						/*
						// GT: Email verification needed
						else if (data.emailVerificationNeeded) {
						
							//var submitButton = $("#btnLoginSubmitDL").clone(true);
							var submitButton2 = $("#btnLoginSubmit").clone(true);*/
							/*
							// Show email verification message.
								$.get(data.responseUrl, function(content) {
							
								// Remove previous messages/errors
								$("#userLogin").find(".updateMessage").remove();
								$("#userLogin").find(".formErrors").remove();
												
								$("#frmUserLogin").find("fieldset").empty().append($(content));
								
								$("#frmUserLogin").showFormErrors({
									errorData: {
										txtEmailDL: {
											name: "txtEmailDL",
											errorMessage: "Your email was not verified"
										}
									},
									summaryAnchor: $("#userLogin").find("#frmUserLogin"),
									scrollToSummar: false,
									showInline: false
								});
								
								var tmp = $("#frmUserLogin").find("ul.formErrors");
								tmp.remove();
								$("#frmUserLogin").before(tmp);
								
								$("#btnLoginSubmitDL").createHighResButtons();
								$("#txtEmail").val(data.emailAddress);
								*/
										
								/*$("#btnLoginSubmit").unbind("click").bind("click", function(event) {
									event.preventDefault();
															
									var formPathEmailVerification = frmUserLogin.attr("action");
									
									$.ajax({
										data: frmUserLogin.serialize() + "&emailVerification=true",
										type: "POST",
										url: formPathEmailVerification,
										dataType: "json",
											
										success: function(data) {
											if (data.validated) {
												$.get("/global/_includes/userNav_unauthenticated.html", function(signin_content) {
													$("#frmUserLogin").empty().append($(signin_content));
													$("#frmUserLogin").html($("#frmUserLogin").find("form").html());
													
													// Remove previous messages/errors
													$("#userLogin").find(".updateMessage").remove();
													$("#userLogin").find(".formErrors").remove();
													
													var updateMessage = $("<div class=\"updateMessage\"><img class=\"messageIcon\" src=../_scripts/\"/global/images/icons/ico_confirmation_med.gif\" alt=\"Success\" /><div class=\"updateText\">"+data.validationMessage+"</div></div>");
													
													updateMessage.prependTo("#frmUserLogin > fieldset");
													
													var submitParent = $("#userLoginContent").find("div.buttons");
													submitParent.empty().append(submitButton2);
												});
											}
											else {
												
												// Remove previous messages/errors
												$("#userLogin").find(".updateMessage").remove();
												$("#userLogin").find(".formErrors").remove();
													
												$("#frmUserLogin").showFormErrors({
													errorData: {
														txtEmail: {
															name: "txtEmail",
															errorMessage: data.errorMessage
														}
													},
													summaryAnchor: $("#userLogin").find("#userLoginContent"),
													scrollToSummar: false,
													showInline: false
												});
											}
										} // end success
										
										//error: Sprint.fn.ajaxError
									}); //end ajax
										
								}); // end $("#btnLoginSubmitDL").unbind("click").bind("click", function(event)
									
							//}); 
									
						}*/
					
					else {
						
						//Build the error message list
						var errorList = $("<ul class=\"formErrors\"></ul>");
						
						for (i = 0; i < data.errors.length; i++) {
							var errorItem = $("<li><a href=\"#"+data.errors[i].field+"\">"+data.errors[i].errorMessage+"</a></li>");
							errorItem.appendTo(errorList);
							
							$("#"+data.errors[i].field).addClass("error");
						}
						
						errorList.find("a").bind("click", function() {
							//Find the anchor target that this error links to
							var anchorTarget = $(this).attr("href");
							
							//strip off everything before the "#"
							anchorTarget = anchorTarget.substr(anchorTarget.indexOf("#"));
							
							//Set focus to the field that the label represents and select any text that may be inside
							$(anchorTarget).trigger("focus").trigger("select");
							
							return false;
						});
						
						//Show the error message list.
						frmUserLogin.find("fieldset").prepend(errorList);
					}
						
				},
					
					error: function(event) {
						alert("error communicating with server\n\nStatus: "+event.status);
					}
				
				});
				
			});
		
			$("#userLoginContent").addRoundedCorners();
				
			var userLogin = $("#userLogin");
			var signInLink = $("#signInLink");
			var signInLinkOriginalWidth = signInLink.width();

			var showImmediately = false;

			//Show fred immediately if requested, or for first time visitors on the home page
			if (userLogin.hasClass("startOpen") || $("#sprintHome.firstTimeVisitor").length > 0) {
				showImmediately = true;
			}
			
			var startClosed = true;
			
			if (showImmediately) {
				startClosed = false;
			}
		
			userLogin.disclosure({
				startClosed:     startClosed,
				titleClickable:  false,
				speed:           "fast",
				openedText:      Sprint.content.userLoginDisclosure.openedText[Sprint.currentLanguage],
				closedText:      Sprint.content.userLoginDisclosure.closedText[Sprint.currentLanguage],
				
				openCallback:    function() {
					userLogin.addShim(); //Add an iframe shim (for IE6)
					
					function removeShim() {
						userLogin.removeShim(); //Remove iframe shim (for IE6)
						
						//Once the shim has been removed, get rid of the click function
						userLogin.find(".disclosureToggle").unbind("click", removeShim);
					}
					
					userLogin.find(".disclosureToggle").bind("click", removeShim);
					
					sprintHomePageModuleOpen = true; //Disable promo animation on the home page

				},
				
				closeCallback:   function() {
					var navButton = signInLink.parent().parent();
					userLogin.hide();
					navButton.removeClass("expanded");
					signInLink.animate({width: signInLinkOriginalWidth});
					
					sprintHomePageModuleOpen = false; //Re-enable promo animation on the home page
				}
				
			}).hide();
		
			signInLink.bind("click", function() {
											  						  
				//$(this).parent().width($(this).outerWidth());
				
				var navButton = signInLink.parent().parent();
				
				var animationSpeed = "normal";
				
				if (showImmediately) {
					animationSpeed = 0;
				}
	
				signInLink.animate({width: "226px"}, animationSpeed, function() {
					navButton.addClass("expanded");
					userLogin.show();
					if (!showImmediately) {
						userLogin.find(".disclosureToggle").trigger("click");
					}
					
					showImmediately = false; //Reset flag so that it's only shown immediately on page load.
				});
				
				return false;
			});
			
			//Show fred immediately if needed
			if (showImmediately) {
				signInLink.trigger("click");
			}
			
			$("#navUser a.signInCookied").bind("click", function(event) {
				
				event.preventDefault();
				
				var navButton = $(this).parent().parent();
			
				if (navButton.hasClass("expanded")) {
					navButton.removeClass("expanded");
					userLogin.find(".disclosureToggle").trigger("click");
				}
				else {
					navButton.addClass("expanded");
					userLogin.show();
					userLogin.find(".disclosureToggle").trigger("click");
				}
				
				return false;
				
			});
		
		})();



		/* Signed In User Nav
		-------------------------------------------------*/
		(function() {
		
			var userLoggedIn = $("#userLoggedIn");
			var signOutLink = $("#signOutLink");
			var navUser = $("#navUser");
			var loggedInUserLink = navUser.find("li.loggedInUser a");
		
			$("#userLoggedInContent").addRoundedCorners();
			userLoggedIn.hide();
			
  			
			loggedInUserLink.bind("click", function(event) {
				
				event.preventDefault();
				
				var navButton = loggedInUserLink.parent().parent();
				var hasExpandedClass = navButton.hasClass("expanded");
				
				// expanded class should always be added first and removed last
				if (!hasExpandedClass) {
					navButton.addClass("expanded");
					
					sprintHomePageModuleOpen = true; //Disable promo animation on the home page
				}
				userLoggedIn.slideToggle("fast", function() {
					if (hasExpandedClass) {
						navButton.removeClass("expanded");
						
						sprintHomePageModuleOpen = false; //Re-enable promo animation on the home page
					}
				});
			});
			
		
		})();
				
		
		/* Account Flipper - When switch betwen multiple accounts
		----------------------------------------------------------*/
		(function() {
			
			$("#selUserAccount").bind("change", function(event) {
				$(this).parents("form:first").submit();			 
			});
		
		})();
		
		/* MyTools Tabs in Global Fred
		-----------------------------------------------------------*/
		$(function() {
			
			// Initalize
			var tabLinks = $("#navUser ul.myToolsTabs li a");
			
			
			// Hide content for all tabs except the selected one
			tabLinks.each(function() {
				
				var tabLink = $(this);
								   
				if (!tabLink.parent().hasClass("selected")) {
					$(tabLink.attr("href")).hide();
				}
			});
			
				   
			// Add click event handler to all tabs
			tabLinks.bind("click", function(event) {
				
				event.preventDefault();
				
				var tabLink = $(this);
				var tab = tabLink.parent();
				
				// Don't process a tab that's already selected
				if (tab.hasClass("selected")) {
					return false;	
				}
				
				// Remove selected class from other tabs
				tab.parent().find("li.selected").removeClass("selected");
				
				// Add class to the selected tab
				tab.addClass("selected");
				
				// Hide content for other tabs
				$("#navUser #myTools .myToolsTabContent").hide();
				
				// Show content for selected tab
				$(tabLink.attr("href")).show();
			
			});
		});
		
		
		
		/* Change Location Modal 
		-------------------------------------------------------*/
		$(function() {
			
			// Display modal dialog
			$("a.showModalChangeLocation").bind("click", function(event) {
				
				event.preventDefault();
				
				var locationModal = $("#changeLocationModal");
				
				locationModal.openModal({
					width:275,
					openCallback: function() {
						// Make sure sIFR is properly applied
						locationModal.setupComponents({buttons:false});
					}
				});
			});
			
			
			// Change location submit handling
			$("#frmChangeLocation").bind("submit", function(event) {
															
				event.preventDefault();
				$("#btnChangeLocation").trigger("click", event);
			
			});
			
			
			$("#btnChangeLocation").unbind("click").bind("click", function(event) {
				event.preventDefault();
				
				// When we change location we need to submit the new location to the store locator
				$("#txtFindStoreAddress").val($("#txtNewLocation").val());
				$("#btnFindStore").trigger("click");
				
				// Once submitted we can close the modal
				$("#changeLocationModal").closeModal();
				
			});
		});


		/* Find a Store Form (in the Contact Us module in the side bar)
		-------------------------------------------------*/
		(function() {
		
			var frmFindStore = $("#frmFindStore");
			
			if (frmFindStore.length > 0) {
			
				var locationDisplay = $("#locationDisplay");
				
				locationDisplay.hide();
				
				locationDisplay.find("ul.storeLocatorLink li a").bind("click", function(event) {
				
					event.preventDefault();
					
					if ($(this).is(".changeLocation")) {
						locationDisplay.hide();
						frmFindStore.parent().show();
						
						frmFindStore.find("#btnFindStore").removeClass("disabled");
						
						frmFindStore.find("#txtFindStoreAddress").focus().select();
					}
					else if ($(this).is(".seeAll")) {
						
						/*
						$("#frmViewAllStores").find("input[name='r']").val(frmFindStore.find("#hidFindStoreRadius").val());
						$("#frmViewAllStores").find("input[name='addr']").val($.trim(frmFindStore.find("#txtFindStoreAddress").val()));						
						
						$("#frmViewAllStores").trigger("submit");						
						*/
					}
				
				});
				
				frmFindStore.bind("submit", function(event) {
				
					event.preventDefault();
					
					frmFindStore.find("#btnFindStore").trigger("click");
				
				});
			
				function findStores(event, supressErrors){
					if(event){	event.preventDefault();	}
					
					if( supressErrors==null ){ supressErrors=false;}
					
					if ($(this).is(".disabled")) {
						return false;
					}
					
					var searchString = $.trim(frmFindStore.find("#txtFindStoreAddress").val());
					
					$(this).addClass("disabled");
				
					
					var errorFunction = Sprint.fn.ajaxError;
					if(supressErrors){
						errorFunction = function(){return true};
					}
					
					//Send an AJAX request to get the store data for the address entered.
					$.ajax({
					
						url: frmFindStore.attr("action"),
						
						data: {
							addr: searchString,
							r: frmFindStore.find("#hidFindStoreRadius").val()
						},
						
						type: "GET",
						
						dataType: "json",
						
						success: function(data) {
						
							//Remove any previous results
							locationDisplay.find(".storeLocation").remove();
							locationDisplay.find(".errorHolder").remove();
						
							if (data.error) {
								if(data.error[0].noSearchKeyFound){
									$('#locationDisplay').hide();
									$('#contactFind').show();
								}
																
							}
							else if (data.stores) {
							
								var outputString = "";
							
								//No errors, output the first 2 results
								$.each(data.stores, function(i) {
								
									if (i >= 2) {
										return;
									}
									// added <b> tag to make phone nubmer bold
									outputString = outputString+"<div class=\"storeLocation\"><h5>"+data.stores[i].name+"</h5><div class=\"locationTelephone\"><em><b>"+data.stores[i].phone+"</b></em></div><div class=\"locationAddress01\">"+data.stores[i].address+"</div></div>";
									
								});
							
								locationDisplay.prepend(outputString);
								frmFindStore.parent().hide();							
								locationDisplay.show();
							}
						},
						
						error: function(){
							locationDisplay.find(".storeLocation").remove();
							locationDisplay.find(".errorHolder").remove();
							locationDisplay.prepend('<div class="errorHolder"><ul class="formErrors"><li>'+"Please enter valid Street, city, state, and/or ZIP"+'</li></ul></div>');
							frmFindStore.parent().hide();
							locationDisplay.show();
							if($("#OmnitureCalls").val() == "false"){
								//Omniture tracking the error message when go is clicked
								Analytics.Support.trackError("user","Please enter valid Street, city, state, and/or ZIP");
							}
						}
					});
						
				}//end of findStores
			
				frmFindStore.find("#btnFindStore").unbind("click").bind("click", function(event) {
					var checkNullVal = $.trim(frmFindStore.find("#txtFindStoreAddress").val());

					if($("#OmnitureCalls").val() == "false"){
						//Start : Added to track the onlick event of go button in the find a store.
						
							Analytics.Support.trackGoStoreSelector();
					}
						
						//End : Added to track the onlick event of go button in the find a store.
				
							


					if(checkNullVal != "") {
						findStores(event);
					} else {
						event.preventDefault(event);
					
						locationDisplay.find(".storeLocation").remove();
						locationDisplay.find(".errorHolder").remove();
						locationDisplay.prepend('<div class="errorHolder"><ul class="formErrors"><li>'+"Oops, you forgot to enter your address"+'</li></ul></div>');
						frmFindStore.parent().hide();
						locationDisplay.show();
						if($("#OmnitureCalls").val() == "false"){
							//Omniture tracking the error message when go is clicked
							Analytics.Support.trackError("user","Oops, you forgot to enter your address");
						}


					}
				});
			
				$(window).load( function(){
					//initialize the store locator, but supress error messages
					findStores(null, true);
				});
			}
			

		
		})();
		
		
		
		/* Form Enter-key support for Internet Explorer (because buttons are hidden, enter doesn't submit the form, this fixes that) */
		if ($.browser.msie) {
			$(document).bind("keydown", function(event) {
				if (event.keyCode == 13) {
				
					sourceElement = $(event.srcElement);
					parentForm = sourceElement.parents("form");
				
					if (parentForm.length > 0) {
					
						event.preventDefault();
						
						//Submit this item's parent form.
						parentForm.trigger("submit");
					
					}

				}
			});			
		}



		//Setup link handling for any "forgot password" links
		(function() {
		
			var forgotPasswordFields = {
				txtForgotPasswordUsername: {
					name: "txtForgotPasswordUsername",
					type: "username",
					required: true,
					emptyErrorMessage: Sprint.content.formFieldErrors.usernameEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.formFieldErrors.usernameInvalid[Sprint.currentLanguage]
				},
				radForgotPasswordDestinationEmail: {
					name: "radForgotPasswordDestinationEmail",
					type: "radioButton",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.passwordDestinationEmpty[Sprint.currentLanguage]
				},
				radForgotPasswordDestinationEmail: {
					name: "radForgotPasswordDestinationText",
					type: "radioButton",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.passwordDestinationEmpty[Sprint.currentLanguage]
				},
				txtForgotPasswordCode: {
					name: "txtForgotPasswordCode",
					type: "ESN,MEID,BAN,phoneNumber",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.passwordCodeEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.forgotPasswordErrors.passwordCodeInvalid[Sprint.currentLanguage]
				},
				txtForgotPasswordNewPassword: {
					name: "txtForgotPasswordNewPassword",
					type: "password",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.newPasswordEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.forgotPasswordErrors.newPasswordInvalid[Sprint.currentLanguage]
				},
				txtForgotPasswordConfirmPassword: {
					name: "txtForgotPasswordConfirmPassword",
					type: "match",
					required: true,
					mustMatch: "txtForgotPasswordNewPassword",
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.newPasswordConfirmEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.forgotPasswordErrors.newPasswordConfirmInvalid[Sprint.currentLanguage]
				},
				txtForgotPasswordEmail: {
					name: "txtForgotPasswordEmail",
					type: "emailAddress",
					required: false,
					invalidErrorMessage: Sprint.content.formFieldErrors.emailAddressInvalid[Sprint.currentLanguage],
					customValidationRule: function(field) {
						var fieldValue = field.val();
						var secondaryFieldValue = $("#txtForgotPasswordPhone").val();
						
						if (fieldValue != "" && secondaryFieldValue == "") {
							forgotPasswordFields.txtForgotPasswordPhone.required = false;
							return Sprint.formFieldTypes.emailAddress.test(fieldValue);
						} else {
							return true;
						}
					}
				},
				txtForgotPasswordPhone: {
					name: "txtForgotPasswordPhone",
					type: "phoneNumber",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.phoneNumberAndEmailEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.formFieldErrors.phoneNumberInvalid[Sprint.currentLanguage]
				}
			};
			
			// Bind the cancel button to trigger the click event on the modal chrome close button.
			function bindCancelButton() {
				$("#forgotPasswordModal").find("#btnForgotPasswordCancel").bind("click", function(event) {
					event.preventDefault();
					Sprint.modal.elem.find("a.modalChromeCloseButton").trigger("click");
				});
			}
			
			// Bind the submit button to do client-side validation on the form fields, if that passes then
			// call ajax query to get the next page in the flow.
			function bindSubmitButton() {
				var forgotPasswordModal = $("#forgotPasswordModal");
				var frmForgotPassword   = forgotPasswordModal.find("#frmForgotPassword");
								
				forgotPasswordModal.find("#btnForgotPasswordSubmit").unbind("click").bind("click", function(event) {
					event.preventDefault();
					
					// Client-side validation
					var validationRules = Sprint.fn.cloneObject(forgotPasswordFields);
					var validForm = Sprint.fn.validateForm(forgotPasswordModal.find("#frmForgotPassword"), forgotPasswordFields);
					if (validForm == true) {
						$.ajax({
							data: "ajax=true&" + frmForgotPassword.serialize(),
							url: frmForgotPassword.attr("action"),
							type: "GET",								
							async: false,
							dataType: "json",
							
							success: function(data) {
								if (data.validated) {
									Sprint.modal.elem.loadModalContent(data.responseUrl, forgotPasswordModal);
									bindCancelButton();
									bindSubmitButton();
									bindEnterToSubmitEvent();
									setFocusToFirstField();
									if (data.securityQuestion) {
										forgotPasswordModal.find("span.securityQuestion").text(data.securityQuestion);
									}
									if (data.emailAddress) {
										forgotPasswordModal.find("span.sendToEmail").text(data.emailAddress);
									}
									if (data.phoneNumber) {
										forgotPasswordModal.find("span.sendToPhone").text(data.phoneNumber);
									}
								} else {
									//Remove previous error messages.
									forgotPasswordModal.find(".headerWrapperPrimary").find(".formErrors").remove();
									forgotPasswordModal.find(".error").removeClass("error");
				
									//Form has errors, show messages.
									forgotPasswordModal.find("#frmForgotPassword").showFormErrors({
										errorData: {
											txtValidationCode: {
												name: data.errorField,
												errorMessage: data.errorMessage
											}
										},
										summaryAnchor: forgotPasswordModal.find(".headerWrapperPrimary"),
										showInline: false,
										scrollToSummary: false
									});
								}
							},
														
							error: Sprint.fn.ajaxError	
						});
					} else {
						//Remove previous error messages.
						forgotPasswordModal.find(".headerWrapperPrimary").find(".formErrors").remove();
						forgotPasswordModal.find(".error").removeClass("error");
				
						//Form has errors, show messages.
						forgotPasswordModal.find("#frmForgotPassword").showFormErrors({
							errorData: validForm,
							summaryAnchor: forgotPasswordModal.find(".headerWrapperPrimary"),
							showInline: false,
							scrollToSummary: false
						});
					}
					
					// Reset the validation rules
					forgotPasswordFields = validationRules;
				});
			}
			
			//Make sure that the form submit goes through the submit button click event
			function bindEnterToSubmitEvent() {
				$("#frmForgotPassword").bind("submit", function(event) {
					event.preventDefault();
					$("#forgotPasswordModal").find("#btnForgotPasswordSubmit").trigger("click");
				});
			}
			
			// Bind the forgot username link to an event that will load content into the modal.
			function bindForgotUsernameLink() {
				$("#forgotPasswordModal").find("a.forgotUsername").unbind("click").bind("click", function(event) {
					event.preventDefault();
					Sprint.modal.elem.loadModalContent("/global/common/modals/forgot_username.php", $("#forgotPasswordModal"));
					bindCancelButton();
					bindSubmitButton();
					bindEnterToSubmitEvent();
					setFocusToFirstField();
				});
			}
			
			// Set the focus on the first input field, not the first item which would be the close button.
			function setFocusToFirstField() {
				Sprint.modal.elem.focusFirstElement({
					focusableElements: "input[type!='hidden'], submit, button",
					containFocus: false
				});
			}
			
			// Bind the forgot password link to open the modal and display the contents.
			$("a.forgotPassword").die("click").live("click", function(event) {
				event.preventDefault();
				
				var modalExists = $("#deepLinkSignIn").length > 0;
				if (modalExists) {
					$("a.closeModal").trigger("click");
				}
				
				var forgotPasswordModal = $("#forgotPasswordModal");
				
				if (forgotPasswordModal.length < 1) {
					var newModal = $("<div class=\"modal\"></div>");
					forgotPasswordModal = $("<div id=\"forgotPasswordModal\"></div>");
					forgotPasswordModal.appendTo(newModal);
					newModal.appendTo("div.sprint div.body").hide();
				}
				
				// Open the modal from the initial forgot password state
				forgotPasswordModal.openModal({
					ajaxContent: true,
					ajaxPath: "/global/common/modals/forgot_password.php",
					
					openCallback: function() {
						bindCancelButton();
						bindSubmitButton();
						bindEnterToSubmitEvent();
						bindForgotUsernameLink();
						setFocusToFirstField();
						if (modalExists) {
							bindDeepLinkEvent();
						}
					}
				});
			});
			
			// Bind the forgot username link to open the modal and display the contents.
			$("div.forgot > a.forgotUsername").die("click").live("click", function(event) {
				event.preventDefault();
				
				var modalExists = $("#deepLinkSignIn").length > 0;
				if (modalExists) {
					$("a.closeModal").trigger("click");
				}
				
				var forgotPasswordModal = $("#forgotPasswordModal");
				
				if (forgotPasswordModal.length < 1) {
					var newModal = $("<div class=\"modal\"></div>");
					forgotPasswordModal = $("<div id=\"forgotPasswordModal\"></div>");
					forgotPasswordModal.appendTo(newModal);
					newModal.appendTo("div.sprint div.body").hide();
				}
				
				// Open the modal from the initial forgot password state
				forgotPasswordModal.openModal({
					ajaxContent: true,
					ajaxPath: "/global/common/modals/forgot_username.php",
					
					openCallback: function() {
						bindCancelButton();
						bindSubmitButton();
						bindEnterToSubmitEvent();
						setFocusToFirstField();
						if (modalExists) {
							bindDeepLinkEvent();
						}
					}
				});
			});
			
			// If the user got to this modal from the deep link signin modal, then closing
			// this modal should re-open the signin modal.
			function bindDeepLinkEvent() {
				$("#modalHolder a.closeModal").unbind("click").bind("click", function(event) {
					event.preventDefault();
					Sprint.modal.elem.closeModal();
					deepLinkSignInModal();
				});
			}
			
			// Check for the reset temporary password link, if it exists then do a trigger
			// on the event, which causes the modal to show.
			$("a.resetTemporaryPassword").unbind("click").bind("click", function(event) {
				event.preventDefault();
				
				var resetPasswordModal = $("#forgotPasswordModal");
				
				if (resetPasswordModal.length < 1) {
					var newModal = $("<div class=\"modal\"></div>");
					resetPasswordModal = $("<div id=\"forgotPasswordModal\"></div>");
					resetPasswordModal.appendTo(newModal);
					newModal.appendTo("div.sprint div.body").hide();
				}
				
				// Open the modal from the initial forgot password state
				resetPasswordModal.openModal({
					ajaxContent: true,
					ajaxPath: "/global/common/modals/reset_temporary_password.php",
					
					openCallback: function() {
						resetPasswordModal.find("#btnResetPasswordSubmit").unbind("click").bind("click", function(event) {
							event.preventDefault();
							
							// Client-side validation
							var validationRules = Sprint.fn.cloneObject(forgotPasswordFields);
							var frmResetPassword = resetPasswordModal.find("#frmResetPassword");
							var validForm = Sprint.fn.validateForm(frmResetPassword, forgotPasswordFields);
							if (validForm == true) {
								$.ajax({
									data: "ajax=true&" + frmResetPassword.serialize(),
									url: frmResetPassword.attr("action"),
									type: "GET",								
									async: false,
									dataType: "json",
									
									success: function(data) {
										if (data.validated) {
											Sprint.modal.elem.loadModalContent(data.responseUrl, resetPasswordModal);
											
											// After the modal is loaded, pressing Done, Enter or closing the modal shouldn't
											// do anything but close it.
											resetPasswordModal.find("#btnResetTemporaryPassDone").live("click", function(event) {
												event.preventDefault();
												Sprint.modal.elem.closeModal();
											});
										}
										else {
											//Remove previous error messages.
											resetPasswordModal.find(".headerWrapperPrimary").find(".formErrors").remove();
											resetPasswordModal.find(".error").removeClass("error");
									
											//Form has errors, show messages.
											frmResetPassword.showFormErrors({
												errorData: {
													txtResetPassword: {
														errorMessage: data.errorMessage
													}
												},
												summaryAnchor: resetPasswordModal.find(".headerWrapperPrimary"),
												showInline: false,
												scrollToSummary: false
											});
										}
									},
									
									error: Sprint.fn.ajaxError
								});
							}
							else {
								//Remove previous error messages.
								resetPasswordModal.find(".headerWrapperPrimary").find(".formErrors").remove();
								resetPasswordModal.find(".error").removeClass("error");
						
								//Form has errors, show messages.
								frmResetPassword.showFormErrors({
									errorData: validForm,
									summaryAnchor: resetPasswordModal.find(".headerWrapperPrimary"),
									showInline: false,
									scrollToSummary: false
								});
							}
						});
						
						// Bind the enter key to the submit button
						$("#frmResetPassword").bind("submit", function(event) {
							event.preventDefault();
							$("#forgotPasswordModal").find("#btnResetPasswordSubmit").trigger("click");
						});
						
						// Closing the modal should redirect them to logout
						$("#modalHolder a.closeModal").unbind("click").bind("click", function() {
							var frmResetPass = resetPasswordModal.find("#frmResetPassword");
							frmResetPass.attr("action", "/entrycheck/logout.fcc");
							frmResetPass.append("<input type=\"hidden\" name=\"TARGET\" value=\"/global/mysprint/global/index.jsp?smlogout=true\" />")
							frmResetPass.unbind("submit").submit();
						});
						
						// Clicking cancel should redirect them to logout
						resetPasswordModal.find("#btnResetPasswordCancel").unbind("click").bind("click", function(event) {
							event.preventDefault();
							$("#modalHolder a.closeModal").trigger("click");
						});
						
						// Pressing escape key should redirect them to logout
						$(document).unbind("keydown").bind("keydown", function(event) {
							if (event.keyCode == 27) {
								event.preventDefault();
								$("#modalHolder a.closeModal").trigger("click");
							}
						});
					}
				});
			}).click();
		
			/* GT: Deep link landing page sign in 
			Note: this is different from the regular sign in function because the form IDs have to be different in order for 
			the 2 sign in forms to be present on the page.  All form IDs on this form have "DL" appended to it. eg: #frmUserLoginDL
			instead of #frmUserLogin.
			--------------------------------------------------*/
		
			function signInFormProcess() {

				var submitLoginForm = false;
				var frmUserLogin = $("#frmUserLoginDL");
				
				//Make sure form submission goes through the Sign In button.
				frmUserLogin.bind("submit", function(event) {
	
					if (!submitLoginForm) {
						event.preventDefault();
						
						frmUserLogin.find("#btnLoginSubmitDL").trigger("click");
					}
					
				});
				
				// This handles the email verification scenario for deep linking signin for both the modal and the landing page.
				frmUserLogin.find("#btnLoginSubmitEmailVerificationDL").unbind("click").bind("click", function(event) { 
					
					event.preventDefault();
					var submitButton = $("#btnLoginSubmitEmailVerificationDL").clone(true);
					
					var formPathEmailVerification = frmUserLogin.attr("action");
					
				// Email validation
				var signUpEmailFormFields = {
					emailAddress: {
						name: "txtEmailDL",
						type: "emailAddress",
						required: true,
						emptyErrorMessage: Sprint.content.formFieldErrors.emailAddressEmpty[Sprint.currentLanguage],
						invalidErrorMessage: Sprint.content.formFieldErrors.emailAddressInvalid[Sprint.currentLanguage]
					}
				};
				var dataToValidate = Sprint.fn.cloneObject(signUpEmailFormFields);
				var validForm = Sprint.fn.validateForm(frmUserLogin, signUpEmailFormFields);
				
				if(validForm == true){
					
					$.ajax({
						data: frmUserLogin.serialize() + "&emailVerification=true",
						type: "POST",
						url: formPathEmailVerification,
						dataType: "json",
						
						success: function(data) {
							if (data.validated) {
								if ($("#deepLinkTriggerSignIn").length > 0) { // The sign in process is happening through the modal
									
									$.get("/global/common/modals/deeplink_signin.php?ajax=true", function(signin_content) {
										$("#signInDeepLinkModal").empty().append($(signin_content));
										
										
										var header = $("#deepLinkSignIn").find(".headerWrapperPrimary");
										
										// Remove any current success/error messages
										header.find(".updateMessage").remove();
										
										// Show success message
										var updateMessage = $("<div class=\"updateMessage\"><img class=\"messageIcon\" src=\"/global/images/icons/ico_confirmation_med.gif\" alt=\"Success\" /><div class=\"updateText\">"+data.validationMessage+"</div></div>");
										updateMessage.appendTo(header);
										
										// Append the submit button
										var submitParent = $("#signInDeepLinkModal").find("div.buttons");
										submitParent.empty().append(submitButton);
										
									}); // end get
								} 
								else { // The sign in process is happening through the landing page
								
									$.get("/global/_includes/deeplink_landing_signin.html", function(signin_content) {
									
										$("#deepLinkSignIn").empty().append($(signin_content));
										
										var header = $("#deepLinkSignIn").find("#userLoginDL");
										
										// Remove any current success/error messages
										header.find(".updateMessage").remove();
										
										// Show success message
										var updateMessage = $("<div class=\"updateMessage\"><img class=\"messageIcon\" src=\"/global/mysprint/_images/icons/ico_success_updatemessage.gif\" alt=\"Success\" /><div class=\"updateText\">"+data.validationMessage+"</div></div>");
										updateMessage.prependTo(header);
										
										// Append the submit button
										//var submitParent = $("#deepLinkSignIn").find("div.buttons");
										//submitParent.empty().append(submitButton);
										
										var submitParent = $("#deepLinkSignIn").find("div.buttons");
										
										var newSubmitButton = $("<input type=\"submit\" class=\"button1\" id=\"btnLoginSubmitEmailVerificationDL\" value=\"Sign In\" />");
										submitParent.empty().append(newSubmitButton);
										newSubmitButton.createHighResButtons();
										
										frmUserLogin.attr("action", data.nextPage);
										
										$("#btnLoginSubmitEmailVerificationDL").unbind("click").bind("click", function(event) {
											event.preventDefault();
											window.location = data.nextPage;
										});
										
										
									}); // end get								
								}
							} 
							else { // Error
							
								if ($("#deepLinkTriggerSignIn").length > 0) { // The sign in process is happening through the modal
								
									$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".updateMessage").remove();
									$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".formErrors").remove();
								
									$("#frmUserLoginDL").showFormErrors({
										errorData: {
											txtEmailDL: {
												name: "txtEmailDL",
												errorMessage: data.errorMessage
											}
										},
										summaryAnchor: $("#deepLinkSignIn").find(".headerWrapperPrimary"),
										scrollToSummar: false,
										showInline: false
									});
								} 
								else { // The sign in process is happening through the landing page
									
									// Remove any current success/error messages
									$("#deepLinkSignIn").find("#userLoginDL").find(".updateMessage").remove();
									$("#deepLinkSignIn").find("#userLoginDL").find(".formErrors").remove();
									
									$("#frmUserLoginDL").showFormErrors({
										errorData: {
											txtEmailDL: {
												name: "txtEmailDL",
												errorMessage: data.errorMessage
											}
										},
										summaryAnchor: $("#deepLinkSignIn").find("#userLoginDL").find("#verificationErrors"),
										scrollToSummar: false,
										showInline: false
									});
								}
							}
						}
					}); // end ajax
					
					}
					else {
						
						if ($("#deepLinkTriggerSignIn").length > 0) { // The sign in process is happening through the modal
						
							$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".updateMessage").remove();
							$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".formErrors").remove();
							$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".error").removeClass("error");
							
							frmUserLogin.showFormErrors({
		                        showInline: false,
		                        summaryAnchor: $("#deepLinkSignIn").find(".headerWrapperPrimary"),
		                        showSummary: true,
		                        errorData: validForm
		                    });
		                    return false;
							
		                } else {
		                
							//Remove previous error messages.
							$("#deepLinkSignIn").find("#userLoginDL").find(".formErrors").remove();
							$("#deepLinkSignIn").find("#userLoginDL").find(".error").removeClass("error");
							$("#deepLinkSignIn").find("#userLoginDL").find(".updateMessage").remove();
							
							frmUserLogin.showFormErrors({
		                        showInline: false,
		                        summaryAnchor: $("#deepLinkSignIn").find("#userLoginDL").find("#verificationErrors"),
		                        showSummary: true,
		                        errorData: validForm
		                    });
		                    return false;		                	
		                }
					} // end email validation
					
				}); // end frmUserLogin.find("#btnLoginSubmitEmailVerificationDL")...
				
				frmUserLogin.find("#btnLoginSubmitDL").unbind("click").bind("click", function(event) {
					event.preventDefault();

					//Submit the form using an AJAX request.
					var formPath = frmUserLogin.attr("action");
					
					$.ajax({
						
						data: frmUserLogin.serialize(),
						type: "POST",
						url: formPath,
						dataType: "json",
						
						success: function(data) {
							
							//Remove any previous error messages
							frmUserLogin.find("ul.formErrors").remove();
							frmUserLogin.find(".error").removeClass("error");
	
							if (data.validated) {										
								//Submit the registration form.
								window.location = data.nextPage;
							}
							else if (data.accountLocked) {
								//Account locked, show account locked message.
								var errorList = $("<ul class=\"formErrors\"><li>"+data.accountLockedErrorHeader+"</li></ul><p>"+data.accountLockedErrorMessage+"</p>");
								
								//Empty the form, change it's action, put in the new fields
								frmUserLogin.attr("action", data.accountResetPath);
								frmUserLogin.find("fieldset").html(errorList);
								
								//Reset checkbox
								var resetCheck = $("<div><label for=\"chkLoginAccountResetDL\" id=\"lblLoginAccountResetDL\"><input type=\"checkbox\" class=\"check\" name=\"chkLoginAccountReset\" id=\"chkLoginAccountResetDL\" /> "+data.accountLockedResetLabel+"</label></div>");
								
								resetCheck.appendTo(frmUserLogin.find("fieldset"));							
								
								//Put in the new submit button.
								var newSubmitButton = $("<input type=\"submit\" class=\"button1\" id=\"btnLoginSubmitDL\" value=\""+data.accountResetButtonLabel+"\" />");
								
								newSubmitButton.appendTo(frmUserLogin.find("fieldset"));
								
								newSubmitButton.wrap("<div class=\"buttons\"></div>");
								
								newSubmitButton.createHighResButtons();
								
								$("#btnLoginSubmitDL").unbind("click").bind("click", function(event) {
									
									event.preventDefault();
									
									//if the reset account checkbox is checked, submit the form. If not, do nothing.
									if ($("#chkLoginAccountResetDL").is(":checked")) {
										submitLoginForm = true;
										
										frmUserLogin.eq(0).submit();
									}
									
								});
							} // GT: Email verification needed - NOTE: This is being handled separately now since tech wanted
							  // to eliminate ajax calls and do straight form submission.
							/*
							else if (data.emailVerificationNeeded) {
								var submitButton = $("#btnLoginSubmitDL").clone(true);
								// Show email verification message.
								
								$.get(data.responseUrl, function(content) {
									$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".updateMessage").remove();
									$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".formErrors").remove();
												
									$("#frmUserLoginDL").find("fieldset").empty().append($(content));
									$("#frmUserLoginDL").showFormErrors({
										errorData: {
											txtEmailDL: {
												name: "txtEmailDL",
												errorMessage: "Your email was not verified"
											}
										},
										summaryAnchor: $("#deepLinkSignIn").find(".headerWrapperPrimary"),
										scrollToSummar: false,
										showInline: false
									});
									$("#btnLoginSubmitDL").createHighResButtons();
									
									$("#txtEmailDL").val(data.emailAddress);
										
									$("#btnLoginSubmitDL").unbind("click").bind("click", function(event) {
										
										event.preventDefault();
															
										var formPathEmailVerification = frmUserLogin.attr("action");
										
										$.ajax({
											data: frmUserLogin.serialize() + "&emailVerification=true",
											type: "POST",
											url: formPathEmailVerification,
											dataType: "json",
											
											success: function(data) {
												if (data.validated) {
													$.get("/global/common/modals/deeplink_signin.php?ajax=true", function(signin_content) {
														$("#signInDeepLinkModal").empty().append($(signin_content));
														
														//Show success message:
														var header = $("#deepLinkSignIn").find(".headerWrapperPrimary");
														
														//Remove any current success/error messages
														header.find(".updateMessage").remove();
														
														var updateMessage = $("<div class=\"updateMessage\"><img class=\"messageIcon\" src=\"/global/images/icons/ico_confirmation_med.gif\" alt=\"Success\" /><div class=\"updateText\">"+data.validationMessage+"</div></div>");
														
														updateMessage.appendTo(header);
														
														var submitParent = $("#signInDeepLinkModal").find("div.buttons");
														submitParent.empty().append(submitButton);
													});
												}
												else {
													$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".updateMessage").remove();
													$("#deepLinkSignIn").find(".headerWrapperPrimary").find(".formErrors").remove();
												
													$("#frmUserLoginDL").showFormErrors({
														errorData: {
															txtEmailDL: {
																name: "txtEmailDL",
																errorMessage: data.errorMessage
															}
														},
														summaryAnchor: $("#deepLinkSignIn").find(".headerWrapperPrimary"),
														scrollToSummar: false,
														showInline: false
													});
												}
											},
											error: Sprint.fn.ajaxError
										}); //end ajax
										
									});
									
								});
									
							}
							*/
							else {
								
								//Build the error message list
								var errorList = $("<ul class=\"formErrors\"></ul>");
								
								var numberOfErrors = data.errors.length;
								
								for (i = 0; i < numberOfErrors; i++) {
									var errorItem = $("<li><a href=\"#"+data.errors[i].field+"\">"+data.errors[i].errorMessage+"</a></li>");
									errorItem.appendTo(errorList);
									
									$("#"+data.errors[i].field).addClass("error");
								}
								
								errorList.find("a").bind("click", function() {
									//Find the anchor target that this error links to
									var anchorTarget = $(this).attr("href");
									
									//strip off everything before the "#"
									anchorTarget = anchorTarget.substr(anchorTarget.indexOf("#"));
									
									//Set focus to the field that the label represents and select any text that may be inside
									$(anchorTarget).trigger("focus").trigger("select");
									
									return false;
								});
								
								//Show the error message list.
								frmUserLogin.find("fieldset").prepend(errorList);
							}
							
						},
						
						error: function(event) {
							alert("error communicating with server\n\nStatus: "+event.status);
						}
					});
				});
				
			} // end signInFormProcess
		
			function deepLinkSignInModal() {
				if ($("#deepLinkTriggerSignIn").length > 0) { // The sign in process is happening through the modal
	
		            var signInDeepLinkModal = $("#signInDeepLinkModal");
					
					if (signInDeepLinkModal.length < 1) {
						//Because this modal is being loaded via AJAX, it won't exist in the markup already. Create the modal on the fly
						var newModal = $("<div class=\"modal\"></div>").appendTo("div.sprint div.body").hide();
			
						signInDeepLinkModal = $("<div id=\"signInDeepLinkModal\"></div>").appendTo(newModal);
						
					}
					
					signInDeepLinkModal.openModal({
						ajaxContent: true,
						ajaxPath: $("#deepLink_signInDLModal").attr("href"),
						
						openCallback: function() {
							
							signInFormProcess();
						}
					});
				} else { // The sign in is happening through the landing page
					signInFormProcess();
				}
			}
			
			deepLinkSignInModal();
			
			/* GT: END - Deep link landing page sign in 
			--------------------------------------------------*/
		
		})();
		
		// Forgot username/password scenario from external domain
		(function() {
			
			var forgotPasswordFields = {
				txtForgotPasswordUsername: {
					name: "txtForgotPasswordUsername",
					type: "username",
					required: true,
					emptyErrorMessage: Sprint.content.formFieldErrors.usernameEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.formFieldErrors.usernameInvalid[Sprint.currentLanguage]
				},
				radForgotPasswordDestinationEmail: {
					name: "radForgotPasswordDestinationEmail",
					type: "radioButton",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.passwordDestinationEmpty[Sprint.currentLanguage]
				},
				radForgotPasswordDestinationEmail: {
					name: "radForgotPasswordDestinationText",
					type: "radioButton",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.passwordDestinationEmpty[Sprint.currentLanguage]
				},
				txtForgotPasswordCode: {
					name: "txtForgotPasswordCode",
					type: "ESN,MEID,BAN,phoneNumber",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.passwordCodeEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.forgotPasswordErrors.passwordCodeInvalid[Sprint.currentLanguage]
				},
				txtForgotPasswordNewPassword: {
					name: "txtForgotPasswordNewPassword",
					type: "password",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.newPasswordEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.forgotPasswordErrors.newPasswordInvalid[Sprint.currentLanguage]
				},
				txtForgotPasswordConfirmPassword: {
					name: "txtForgotPasswordConfirmPassword",
					type: "match",
					required: true,
					mustMatch: "txtForgotPasswordNewPassword",
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.newPasswordConfirmEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.forgotPasswordErrors.newPasswordConfirmInvalid[Sprint.currentLanguage]
				},
				txtForgotPasswordEmail: {
					name: "txtForgotPasswordEmail",
					type: "emailAddress",
					required: false,
					invalidErrorMessage: Sprint.content.formFieldErrors.emailAddressInvalid[Sprint.currentLanguage],
					customValidationRule: function(field) {
						var fieldValue = field.val();
						var secondaryFieldValue = $("#txtForgotPasswordPhone").val();
						
						if (fieldValue != "" && secondaryFieldValue == "") {
							forgotPasswordFields.txtForgotPasswordPhone.required = false;
							return Sprint.formFieldTypes.emailAddress.test(fieldValue);
						} else {
							return true;
						}
					}
				},
				txtForgotPasswordPhone: {
					name: "txtForgotPasswordPhone",
					type: "phoneNumber",
					required: true,
					emptyErrorMessage: Sprint.content.forgotPasswordErrors.phoneNumberAndEmailEmpty[Sprint.currentLanguage],
					invalidErrorMessage: Sprint.content.formFieldErrors.phoneNumberInvalid[Sprint.currentLanguage]
				}
			};
			
			bindExternalForgotUserPassSubmitButton();
			bindExternalForgotUserPassCancelButton();
			bindExternalForgotUserPassEnterToSubmitEvent();
			
			function bindExternalForgotUserPassEnterToSubmitEvent() {
				$("#externalForgotUsernamePassword").find("#frmForgotPassword").unbind("submit").bind("submit", function(event) {
					event.preventDefault();
					$("#btnForgotPasswordSubmit").trigger("click");
				});
			}
			
			function bindExternalForgotUserPassCancelButton() {
				$("#externalForgotUsernamePassword").find("#btnForgotPasswordCancel").unbind("click").bind("click", function(event) {
					event.preventDefault();
					window.location = "#";
				});
			}
			
			function bindExternalForgotUserPassSubmitButton() {
				var externalPage      = $("#externalForgotUsernamePassword");
				var frmForgotPassword = externalPage.find("#frmForgotPassword");
								
				externalPage.find("#btnForgotPasswordSubmit").unbind("click").bind("click", function(event) {
					event.preventDefault();
					
					// Client-side validation
					var validationRules = Sprint.fn.cloneObject(forgotPasswordFields);
					var validForm = Sprint.fn.validateForm(frmForgotPassword, forgotPasswordFields);
					if (validForm == true) {
						$.ajax({
							data: "ajax=true&" + frmForgotPassword.serialize(),
							url: frmForgotPassword.attr("action"),
							type: "GET",								
							async: false,
							dataType: "json",
							
							success: function(data) {
								if (data.validated) {
									//Remove previous error messages.
									externalPage.find(".headerWrapperPrimary").find(".formErrors").remove();
									externalPage.find(".error").removeClass("error");
									
									$.get(data.responseUrl, function(content) {
										externalPage.find("div.containerThreeColumn").empty().append($(content)).find("div.headerWrapperPrimary").remove();
										if (data.emailAddress) {
											externalPage.find("span.sendToEmail").text(data.emailAddress);
										}
										if (data.securityQuestion) {
											externalPage.find("span.securityQuestion").text(data.securityQuestion);
										}
										if (data.emailAddress) {
											externalPage.find("span.sendToEmail").text(data.emailAddress);
										}
										if (data.phoneNumber) {
											externalPage.find("span.sendToPhone").text(data.phoneNumber);
										}
										
										$(".sprint input[type='submit'], .sprint input[type='button'], .sprint a.button1, .sprint a.button2").createHighResButtons();
										
										bindExternalForgotUserPassSubmitButton();
										bindExternalForgotUserPassCancelButton();
										bindExternalForgotUserPassEnterToSubmitEvent();
									});
								} else {
									//Remove previous error messages.
									externalPage.find(".headerWrapperPrimary").find(".formErrors").remove();
									externalPage.find(".error").removeClass("error");
				
									//Form has errors, show messages.
									externalPage.find("#frmForgotPassword").showFormErrors({
										errorData: {
											txtValidationCode: {
												name: data.errorField,
												errorMessage: data.errorMessage
											}
										},
										summaryAnchor: externalPage.find(".headerWrapperPrimary"),
										showInline: false,
										scrollToSummary: false
									});
								}
							},
														
							error: Sprint.fn.ajaxError	
						});
					} else {
						//Remove previous error messages.
						externalPage.find(".headerWrapperPrimary").find(".formErrors").remove();
						externalPage.find(".error").removeClass("error");
				
						//Form has errors, show messages.
						externalPage.find("#frmForgotPassword").showFormErrors({
							errorData: validForm,
							summaryAnchor: externalPage.find(".headerWrapperPrimary"),
							showInline: false,
							scrollToSummary: false
						});
					}
					
					// Reset the validation rules
					forgotPasswordFields = validationRules;
				});
			}

		})();
		
		/* GT: Deep Linking Trigger Functionality
		---------------------------------------- */
          (function() {

	           var deepLinkTrigger = $("#deepLinkTrigger");
	          
	           if (deepLinkTrigger.length > 0) {

                    //Check for specific cases
                    if ($("#deepLink_addPhoneModal").length > 0) {
                   
                         $(window).bind("load", function() {
                              $("#deepLink_addPhoneModal").trigger("click");
                         });
     
                    }
                    else if ($("#deepLink_swapPlanModal").length > 0) {
                   
	                     $(window).bind("load", function() {
	                          $("#deepLink_swapPlanModal").trigger("click");
                         });
                    
                    }
	           }
          })();
		
		// GT: Email verification scenario from external domain
		(function() {
			var externalPage = $("#externalEmailVerification");
			var frmEmailVerf = externalPage.find("#frmEmailVerification");
								
			externalPage.find("#btnLoginSubmitDL").unbind("click").bind("click", function(event) {
				event.preventDefault();
				
				// Email validation
				var signUpEmailFormFields = {
					emailAddress: {
						name: "txtEmailDL",
						type: "emailAddress",
						required: true,
						emptyErrorMessage: Sprint.content.formFieldErrors.emailAddressEmpty[Sprint.currentLanguage],
						invalidErrorMessage: Sprint.content.formFieldErrors.emailAddressInvalid[Sprint.currentLanguage]
					}
				};
				var dataToValidate = Sprint.fn.cloneObject(signUpEmailFormFields);
				var validForm = Sprint.fn.validateForm(frmEmailVerf, signUpEmailFormFields);
				
				if(validForm == true){
				
					$.ajax({
						data: "ajax=true&" + frmEmailVerf.serialize()+ "&emailVerification=true",
						url: frmEmailVerf.attr("action"),
						type: "GET",								
						async: false,
						dataType: "json",
						
						success: function(data) {
							if (data.validated) {
								
								//Remove previous error messages.
								externalPage.find(".headerWrapperPrimary").find(".formErrors").remove();
								externalPage.find(".error").removeClass("error");
								externalPage.find(".headerWrapperPrimary").find(".updateMessage").remove();
							
								var updateMessage = $("<div class=\"updateMessage\"><img class=\"messageIcon\" src=\"/global/images/icons/ico_confirmation_med.gif\" alt=\"Success\" /><div class=\"updateText\">" + data.validationMessage + "</div></div>");
								updateMessage.appendTo(externalPage.find(".headerWrapperPrimary"));
								setTimeout(function() {
									window.location = "#"
								}, 2000);
							}
							else {
								//Remove previous error messages.
								externalPage.find(".headerWrapperPrimary").find(".formErrors").remove();
								externalPage.find(".error").removeClass("error");
								externalPage.find(".headerWrapperPrimary").find(".updateMessage").remove();
						
								//Form has errors, show messages.
								frmEmailVerf.showFormErrors({
									errorData: {
												txtEmailDL: {
													name: "txtEmailDL",
													errorMessage: data.errorMessage
												}
											},
									summaryAnchor: externalPage.find(".headerWrapperPrimary"),
									showInline: false,
									scrollToSummary: false
								});
							}
						},
						error: Sprint.fn.ajaxError
					}); // end ajax
				 }
				 else {
				 
					//Remove previous error messages.
					externalPage.find(".headerWrapperPrimary").find(".formErrors").remove();
					externalPage.find(".error").removeClass("error");
					externalPage.find(".headerWrapperPrimary").find(".updateMessage").remove();
					
					frmEmailVerf.showFormErrors({
                        showInline: false,
                        summaryAnchor: externalPage.find(".headerWrapperPrimary"),
                        showSummary: true,
                        errorData: validForm
                    });
                    return false;
                 }
                 // End email validation
			});
			
		})();

	});
	
})(jQuery);