﻿var IE = document.all ? true : false;
var d = document;
function disableEnter(e) { if (e.keyCode == 13) { return false; } }
function showHideCart() {
	$('#cartExpanded').toggle();
}
function hideAllSelects() {
	for (var i = 0; i < d.forms[0].elements.length; i++) {
		if (d.forms[0].elements[i].type.substr(0, 6) == 'select') {
			d.forms[0].elements[i].style.visibility = 'hidden';
		}
	}
}
function showAllSelects() {
	for (var i = 0; i < d.forms[0].elements.length; i++) {
		if (d.forms[0].elements[i].type.substr(0, 6) == 'select') {
			d.forms[0].elements[i].style.visibility = 'visible';
		}
	}
}
function getLeft(obj) {
	return $(obj).offset().left;
}
function getTop(obj) {
	return $(obj).offset().top;
}
function replaceChars(entry, replace, changeTo) {
	var tmp = "" + entry;
	while (tmp.indexOf(replace) > -1) {
		pos = tmp.indexOf(replace);
		tmp = "" + (tmp.substring(0, pos) + changeTo + tmp.substring((pos + changeTo.length + replace.length - 1), tmp.length));
	}
	return tmp;
}


function scrollToSelector(selector) {
	$('html, body').animate({ scrollTop: $(selector).offset().top }, 500);
}

$(document).ready(function() {
	// replaces default functionality of bookmark links if the 'bookmark-link' css class is applied.
	// scrolling is slow enough to follow rather than snapping-to the desired position.
	$('.bookmark-link').click(function(event) {
		// if href is not null or empty and begins with a '#' character
		if ($(this).attr('href') != null && $(this).attr('href') != '' && $(this).attr('href').substring(0, 1) == '#') {
			scrollToSelector($(this).attr('href'));	
			// return false to override default URL-click functionality.
			return false;
		}
	});
});


(function($) {
	$.fn.trackclick = function(isInput) {
		var d = document;
		var source = d.location.toString();
		return $(this).click(function(e) {
			var $this = $(this);
			var txtNavUrl = '';
			var txtText = '';
			var txtSrc = '';
			var aSync = true;
			var txtClass = $this.attr('class');
			if (!isInput) {
				txtNavUrl = $this.attr('href');
				txtText = $this.html();
				var objClicked = d.createElement("object");
				try { objClicked.innerHTML = $this.html(); } catch (e) { }
				if (objClicked.hasChildNodes) {
					var img = objClicked.firstChild;
					if (img != null && img.attributes != null && img.attributes['src'] != null) {
						txtSrc = img.attributes['src'].value;
					}
				}
			}
			else {
				aSync = false;
				txtSrc = $this.attr('src');
			}
			$.ajax({ type: "POST", url: '/_ajax/trackclick.aspx', async: aSync, data: { url: source, id: ($this.attr('id') != null) ? $this.attr('id') : '', navigateUrl: txtNavUrl, text: txtText, src: (txtSrc != null) ? txtSrc : '', cssClass: txtClass, sID: sGuid} });
			return true;
		})
	}
})(jQuery);
function liveHelp_postBack() {
	var d = document;
	var txtPhoneNumber = d.getElementById('txtAreaCode').value + d.getElementById('txtPrefix').value + d.getElementById('txtDigits').value;
	if (txtPhoneNumber.length == 10) {
		$.inlineObjPost('/_popups/liveHelp.aspx', 'txtPhoneNumber=' + txtPhoneNumber);
	}
	else {
		alert("please enter a valid phone number");
	}
}