﻿/* javascript included to all pages */
$(document).ready(function() {
	// allow watermark on textboxes
	swapValues = [];
	$(".swap").each(function(i) {
		swapValues[i] = $(this).val();
		$(this).focus(function() {
			if ($(this).val() == swapValues[i]) $(this).val("")
		}).blur(function() {
			if ($.trim($(this).val()) == "") $(this).val(swapValues[i])
		})
	});
	// awesome-persand-ize
	$("h1:contains('&'),h2:contains('&')").contents().each(function() {
		if (this.nodeType == 3) {
			$(this).replaceWith(this.nodeValue.replace(/&/g, "<span class=\"amp\">&</span>"));
		}
	});
	// validate newsletter sign up email address
	$("#newsletter .button").click(function() {
		var emailBox = $("#email");
		var verifier = /\s*[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+\.[a-zA-Z]+\s*/;
		if (!emailBox.val() || !verifier.test(emailBox.val())) {
			alert("Please enter a valid email.");
			emailBox.focus();
			return false;
		}
	});
	prettifyTables();
	// add "last" class to every third div in /brands
	$(".brands-item-style div").each(function(i) {
		if (i % 3 == 2) $(this).addClass("last");
	});
	// add third css class to every third column in /all
	$("#everything>.ul:eq(2),#everything>.ul:eq(5),#everything>.ul:eq(8),#everything>.ul:eq(11)").addClass("third");
	// make immediate children clickable
	$(".children-clickable > *").click(function() {
		var links = $(this).find("a");
		if (links.length > 0 && links.attr("href") != null)
			document.location = links.attr("href");
	});
	try { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(prettifyTables); }
	catch (ex) { }
	var topMessageToggle = $("#top-message a");
	var visible = false;
	topMessageToggle.click(function() {
		$("#top-message div").toggle();
		visible = !visible;
		topMessageToggle.html(visible ? "Hide" : "Info");
		return false;
	});
});
function prettifyTables() {
    // add alt css class to alternate columns of tables
    $("div.copy table tr").each(function() {
		$(this).children("td:odd").addClass("alt");
		$(this).children("th:odd").addClass("alt");
	});
    // assign a css class to the first column
	$("div.copy table tr").each(function () {
		$(this).children("td:first").addClass("first");
	});
	// toggle the colors of the rows
    $("div.copy table:not(.reset) tbody tr").mouseenter(function() {
		var t = $(this);
		t.css("background-color", "#ffffe3");
		t.children("td:odd").css("background-color", "#eff3d2");
		t.mouseleave(function() {
			t.removeAttr("style");
			t.children("td:odd").removeAttr("style");
		});
	});
}
function startChat() {
	// if location unspecified, use URL
	var chatLocation = window._chatLocation == undefined ? null : _chatLocation;
	if (!chatLocation) {
		try {
			var extractor = new RegExp("^http://.+?(/.+?)((\\?|#).+)?$");
			var matches = extractor.exec(window.location);
			chatLocation = "Page: " + matches[1];
		} catch (err) {}
	}
	if (track) pageTracker._trackEvent("Chat", "Start", chatLocation);
	// open chat window
	window.open('https://server.iad.liveperson.net/hc/30432315/?cmd=file&file=visitorWantsToChat&site=30432315&imageUrl=https://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/General/1a/&referrer='
		+ escape(document.location),'chat30432315','width=472,height=320,resizable=yes').focus();
}
function setupHomePage() {
	$("h2 span").click(homepageTabClick);
}
// handles homepage tab click event
function homepageTabClick() {
	var jTab = $(this);
	if (jTab.hasClass("selected")) return;
	
	var jIndex = ":eq(" + jTab[0].id.replace("tab", "") + ")";
	
	$("h2 span").removeClass("selected");
	$("h2 span" + jIndex).addClass("selected");
	$("table.group").hide();
	$("table.group" + jIndex).show();
	$("h2 strong").hide();
	$("h2 strong" + jIndex).show();
}