var curBannerIdx = 0;
var curQuoteIdx = 0;
var bannerCount = 5;
var bannerDelay = 10000;
var quoteDelay = 10000;
var curBannerTimeoutID = 0;
var curQuoteTimeoutID = 0;
var isIEPre9 = /MSIE [6-8]/i.test(navigator.userAgent);
var twitterUser = "vollynow";

// GLOBAL DOCREADY HANDLER
$(function () {
	$(".external").bind("click", function () {
		_gaq.push(['_trackEvent', 'External Link Click', $(this).attr("href"), location.href]);
		return !window.open(this.href);
	});
	$(".download").bind("click", function () {
		_gaq.push(['_trackEvent', 'Download', $(this).attr("title") == "" ? $(this).attr("href") : $(this).attr("title"), location.href]);
	});

	if ($("#broadridgeDialog")[0]) {
		$("#broadridgeDialog").dialog({
			autoOpen: false,
			modal: true,
			draggable: false,
			resizable: false,
			show: "fade",
			hide: "fade",
			width: 620,
			dialogClass: "broadridgeDialog",
			open: function () {
				if ($("#broadridgeDialog video").length == 0) {
					LimelightPlayerUtil.initEmbed('limelight_player_114134');
				}
			},
			beforeClose: function () {
				try {
					DelvePlayer.doPause();
					var myVideo = $("#broadridgeDialog video:visible")[0];
					myVideo.pause();
				} catch (ex) { }
			}
		});
		$(".broadridgeVideoLink").bind("click", function () {
			$("#broadridgeDialog").dialog("open");
			return false;
		});
	}
	
	$(".whatwouldyouwishfor").bind("click", function () {
        btn_whatwouldyouwishfor_overlay_click();
    });
});

// TOP NAV FUNCTIONS
set_topnav_on = function (sel) {
	$(sel).addClass("on");
	if ($(sel).parent().is("li")) {
		var arrow = $("<div>").attr("id", "topNavOnArrow");
		var x = (($(sel).width() + 50) / 2) - 5;
		var y = 57;
		arrow.css("left", x + "px").css("top", y + "px").show();
		$(sel).append(arrow);
	}
}

// INDUSTRY QUOTES
industryquotes_docready = function () {
	if (isIEPre9) Cufon.replace("#aboutQuoteBox h4", { fontFamily: "DIN-Regular" });

	$("#quotesPlayPause").bind("click", function () {
		if ($(this).hasClass("pause")) {
			stop_quote_rotation();
			$(this).removeClass("pause").addClass("play");
		}
		else {
			start_quote_rotation();
			$(this).removeClass("play").addClass("pause");
		}
		return false;
	});

	$("#quotesNext").bind("click", function () {
		var stop = false;
		if ($("#quotesPlayPause").hasClass("play")) stop = true;
		quote_rotate(stop);
		return false;
	});

	$(".quote:first").show();
	start_quote_rotation();
}

start_quote_rotation = function () {
	clearTimeout(curQuoteTimeoutID);
	curQuoteTimeoutID = setTimeout("quote_rotate()", quoteDelay);
}

stop_quote_rotation = function () {
	clearTimeout(curQuoteTimeoutID);
}

quote_rotate = function (stop) {
	curQuoteIdx = (curQuoteIdx + 1) % $(".quote").length;
	quote_skip(curQuoteIdx, stop);
}

quote_skip = function (idx, stop) {
	clearTimeout(curQuoteTimeoutID);
	if ($(".quote:visible")[0]) {
		$(".quote:visible").stop().fadeOut(function () {
			show_quote(idx, stop);
		});
	}
	else {
		show_quote(idx, stop);
	}
}

show_quote = function (idx, stop) {
	$(".quote:eq(" + idx + ")").fadeIn(function () {
		curQuoteIdx = idx;
		clearTimeout(curQuoteTimeoutID);
		if (!stop) curQuoteTimeoutID = setTimeout("quote_rotate()", quoteDelay);
	});
}

// HOMEPAGE
default_load = function () {
    $(".st_email_custom").unbind("click");
}

default_docready = function () {
    var likeButtonURL = "http://www.facebook.com/plugins/like.php?href=" + encodeURI(location.href) + "&layout=button_count&locale=en_US&node_type=link&sdk=joey&show_faces=false&width=90";
    $("#fbCntnr iframe:first").attr("src", likeButtonURL);

    $(".banner:first").show();
    $(".bannerContent:first").show();

	//test-Do NOT remove
    //$(".banner:eq(0)").show();
    //$(".bannerContent:eq(0)").show();

    start_banner_rotation();
	
	
    $(".bannerControl").bind("click", banner_control_click);

    $("#features").jcarousel();
    if ($("#features .feature").length <= 3) {
        $(".jcarousel-prev, .jcarousel-next").hide();
    }

    $(".bannerVideoCloseBtn").bind("click", close_current_video);

    $("#banner2 a").bind("click", function () {
        _gaq.push(['_trackEvent', 'Banner 2', 'Click']);
    });

    $("#banner3 a").bind("click", function () {
        _gaq.push(['_trackEvent', 'Banner 3', 'Click']);
    });

    $("#banner4 a").bind("click", function () {
        _gaq.push(['_trackEvent', 'Banner 4', 'Click']);
    });

    $("#banner5 a").bind("click", function () {
        _gaq.push(['_trackEvent', 'Banner 5', 'Click']);
    });

    $("#contactSalesRepLink").bind("click", function () {
        _gaq.push(['_trackEvent', 'Contact a Sales Rep', 'Click']);
    });

    $(".featureLinks a").bind("click", function () {
        _gaq.push(['_trackEvent', 'Landing Page Module Click', $(this).attr("href")]);
    });

    $("#whatCustomersNeedLink, #ceoMessageLink").bind("click", function () {
        stop_banner_rotation();
        $("#bannerVideoBackdrop").fadeIn(function () {
            $("#banner1Video1Cntnr").fadeIn();
            $.scrollTo($("#topNavCntnr"));
        });
        _gaq.push(['_trackEvent', 'Landing Page Video', 'Connecting You With Your Customers', 'Video Start']);
        return false;
    });

    $("#whatYouNeedLink, #whatIsVollyLink").bind("click", function () {
        stop_banner_rotation();
        $("#bannerVideoBackdrop").fadeIn(function () {
            $("#banner1Video2Cntnr").fadeIn();
            $.scrollTo($("#topNavCntnr"));
        });
        _gaq.push(['_trackEvent', 'Landing Page Video', 'What Is Volly?', 'Video Start']);
        return false;
    });

    if (location.hash == "#whatIsVolly") {
        $("#whatYouNeedLink").click();
        _gaq.push(['_trackEvent', 'Landing Page Video', 'What Is Volly?', 'Direct Link']);
    }
    else if (location.hash == "#connectingYouWithYourCustomers") {
        $("#whatCustomersNeedLink").click();
        _gaq.push(['_trackEvent', 'Landing Page Video', 'Connecting You With Your Customers', 'Direct Link']);
    }

}

close_current_video = function () {
	try {
		DelvePlayer.doPause();
	}
	catch (ex) {
		// iPad Safari?
		var myVideo = $("video:visible")[0];
		myVideo.pause();
	}
	$(".bannerVideoCntnr:visible").fadeOut(function () {
		$("#bannerVideoBackdrop").fadeOut(function () {
			start_banner_rotation();
		});
	});
	return false;
}


var playCount = 0;

// This function must be named delvePlayerCallback to be automatically picked up by the Delve player
delvePlayerCallback = function (playerID, eventName, data) {
    if (eventName == "onPlayerLoad" && (DelvePlayer.getPlayers() == null || DelvePlayer.getPlayers().length == 0)) {
        DelvePlayer.registerPlayer(playerID);
    }

	
	
    if (eventName == "onMediaLoad" && playCount == 0 ) {  
		console.log('mediaLoad');	
		playCount++;
        DelvePlayer.doPlay();
    }

}


btn_whatwouldyouwishfor_overlay_click = function () {    
	
		
	$('.windowContent').show(); //chrome/sa	
	$('#whatwouldyouwishfor').show();
    $('.whatwouldyouwishfor').hide();
    //DelvePlayer.doPlay();
}

banner_control_click = function () {
	if (!$(this).hasClass("bannerControlActive")) {
		var li = $(this).parents("li")[0];
		var idx = $(li).index();
		banner_skip(idx);
	}
	return false;
}

start_banner_rotation = function () {
	curBannerTimeoutID = setTimeout("banner_rotate()", bannerDelay);
}

stop_banner_rotation = function () {
	clearTimeout(curBannerTimeoutID);
}

banner_rotate = function () {
	nextBannerIdx = (curBannerIdx + 1) % bannerCount;
	banner_skip(nextBannerIdx);
}

banner_skip = function (idx) {
	clearTimeout(curBannerTimeoutID);
	//$(".triangle").stop().css({ opacity: 1 }).show().fadeOut("fast");
	//$(".bannerOverlay:visible").stop().show().fadeOut("fast");
	$(".bannerContent").stop().fadeOut("fast");
	$(".banner:eq(" + idx + ")").stop().fadeIn(function () {
		//for (var i = 1; i <= 7; i++) {
		//	setTimeout("triangle_fade(" + i.toString() + ")", (i - 1) * 100);
		//}
		
        //$(".bannerOverlay:eq(" + idx + ")").stop().css({ width: 0 }).show().animate({ width: 726 }, function () {
		//	$(".banner:eq(" + idx + ") .bannerContent").fadeIn(300);
		//});
		
		$(".banner:eq(" + idx + ") .bannerContent").fadeIn(300);
		
	});
	$(".banner:eq(" + curBannerIdx + ")").stop().show().fadeOut();
	$("#bannerControls li a").removeClass("bannerControlActive");
	$("#bannerControls li:eq(" + idx + ") a").addClass("bannerControlActive");
	curBannerIdx = idx;
	curBannerTimeoutID = setTimeout("banner_rotate()", bannerDelay);
}

triangle_fade = function (idx) {
	$("#triangle" + idx).stop().fadeIn(300);
}

consumerreg_docready = function () {
	$("#ddlConsState").sSelect();

	var commentsText = "Let us know which bills, statements, catalogs, and coupons you would like to see included in the Volly digital delivery service.";
	$("#txtConsComments").bind("focus", function () {
		if ($.trim($(this).val()) == commentsText) {
			$(this).val("");
		}
	}).bind("blur", function () {
		if ($.trim($(this).val()) == "") {
			$(this).val(commentsText);
		}
	});
}

// ABOUT VOLLY
about_docready = function () {
	set_topnav_on("#topNavAboutVolly");
	$("#aboutCustomerTabs").tabs({
		select: function (event, ui) {
			_gaq.push(['_trackEvent', 'About Tab Click', 'Customers', (ui.index + 1).toString()]);
		}
	});
	$("#aboutBusinessTabs").tabs({
		select: function (event, ui) {
			_gaq.push(['_trackEvent', 'About Tab Click', 'Business', (ui.index + 1).toString()]);
		}
	});
	$("#aboutIndustryTabs").tabs({
		select: function (event, ui) {
			_gaq.push(['_trackEvent', 'About Tab Click', 'Industry', (ui.index + 1).toString()]);
		}
	});

	$("#forYourCustomers").bind("click", function () {
		if ($(this).hasClass("inactive")) {
			$("#business").hide();
			$("#industry").hide();
			$("#customers").show();
			$(this).removeClass("inactive");
			$("#forYourBusiness").addClass("inactive");
			$("#forYourIndustry").addClass("inactive");
			_gaq.push(['_trackEvent', 'About Tab Click', 'Customers', 'Parent']);
		}
		return false;
	});
	$("#forYourBusiness").bind("click", function () {
		if ($(this).hasClass("inactive")) {
			$("#customers").hide();
			$("#industry").hide();
			$("#business").show();
			$(this).removeClass("inactive");
			$("#forYourCustomers").addClass("inactive");
			$("#forYourIndustry").addClass("inactive");
			_gaq.push(['_trackEvent', 'About Tab Click', 'Business', 'Parent']);
		}
		return false;
	});
	$("#forYourIndustry").bind("click", function () {
		if ($(this).hasClass("inactive")) {
			$("#customers").hide();
			$("#business").hide();
			$("#industry").show();
			$(this).removeClass("inactive");
			$("#forYourCustomers").addClass("inactive");
			$("#forYourBusiness").addClass("inactive");
			_gaq.push(['_trackEvent', 'About Tab Click', 'Industry', 'Parent']);
		}
		return false;
	});
	$("#aboutCustomerTabs .tabJumpLink").bind("click", function () {
		$("#aboutCustomerTabs").tabs("select", $(this).attr("href"));
		$.scrollTo($(".ui-tabs-nav:visible:first"));
		return false;
	});
	$("#aboutBusinessTabs .tabJumpLink").bind("click", function () {
		$("#aboutBusinessTabs").tabs("select", $(this).attr("href"));
		$.scrollTo($(".ui-tabs-nav:visible:first"));
		return false;
	});

	$("#howItWorksDialog").dialog({
		autoOpen: false,
		modal: true,
		draggable: false,
		resizable: false,
		show: "fade",
		hide: "fade",
		width: 919,
		dialogClass: "howItWorksDialog"
	});
	$("#howItWorksLink, #howItWorksLink2").bind("click", function () {
		$("#howItWorksDialog").dialog("open");
		return false;
	});

	$("#securityRegDialog").dialog({
		autoOpen: false,
		modal: true,
		draggable: false,
		resizable: false,
		show: "fade",
		hide: "fade",
		dialogClass: "securityRegDialog"
	});

	$("#securityRegLink, #securityRegLink2").bind("click", function () {
		$("#securityRegDialog").dialog("open");
		return false;
	});

	if (location.hash == "#industry") {
		$("#forYourIndustry").click();
		$.scrollTo($("#aboutMainTabs"));
	}
	else if (location.hash == "#security") {
		$("#forYourCustomers").click();
		$("#aboutCustomerTabs").tabs("select", "#cust5");
		$.scrollTo($(".ui-tabs-nav:visible:first"));
	}
}

top5_docready = function () {
	set_topnav_on("#topNavAboutVolly");
}

// RESOURCES
resources_docready = function () {
	set_topnav_on("#topNavResources");

	$("#securityRegDialog").dialog({
		autoOpen: false,
		modal: true,
		draggable: false,
		resizable: false,
		show: "fade",
		hide: "fade",
		dialogClass: "securityRegDialog"
	});

	$("#securityRegLink").bind("click", function () {
		$("#securityRegDialog").dialog("open");
		return false;
	});
}

pressrelease_docready = function () {
	set_topnav_on("#topNavNews");
}

// FAQs
faqs_docready = function () {
	set_topnav_on("#topNavFAQs");
	$(".headLink").bind("click", function () {
		if ($(this).hasClass("view")) {
			$(this).siblings(".answer").slideDown(400, "linear");
			$(this).removeClass("view").addClass("close");
			$("span.view", $(this)).removeClass("view").addClass("close").text("Close");
			if (isIEPre9) Cufon.replace("span.close", { fontFamily: "DIN-Bold" });
		}
		else {
			$(this).siblings(".answer").slideUp(400, "linear");
			$(this).removeClass("close").addClass("view");
			$("span.close", $(this)).removeClass("close").addClass("view").text("View");
			if (isIEPre9) Cufon.replace("span.view", { fontFamily: "DIN-Bold" });
		}
		return false;
	});
	$("#printThisPage").bind("click", function () {
		window.print();
		return false;
	});
}

// NEWS
news_docready = function () {
	set_topnav_on("#topNavNews");
	getTwitterBoxLatestTweets(2);
}

// CONTACT US
contactus_docready = function () {
	set_topnav_on("#topNavContact");
	$("#ddlState").sSelect();
	$("#ddlConsumerState").sSelect();

	$(".contactInfoTab").bind("click", function () {
		if (!$(this).hasClass("contactInfoTabOn")) {
			$("#consumerContactInfoCntnr").hide();
			$("#contactInfoCntnr").show();
			$(this).addClass("contactInfoTabOn");
			$(".consumerContactInfoTab").removeClass("consumerContactInfoTabOn");
		}
		return false;
	});

	$(".consumerContactInfoTab").bind("click", function () {
		if (!$(this).hasClass("consumerContactInfoTabOn")) {
			show_consumer_tab();
		}
		return false;
	});

	bindblurhandler("#txtFirstName", "First Name");
	bindblurhandler("#txtLastName", "Last Name");
	bindblurhandler("#txtTitle", "Title");
	bindblurhandler("#txtCompany", "Company");
	bindblurhandler("#txtAddress1", "Address Line 1");
	bindblurhandler("#txtAddress2", "Address Line 2");
	bindblurhandler("#txtCity", "City");
	bindblurhandler("#txtZip", "Zip");
	bindblurhandler("#txtPhone", "Phone");
	bindblurhandler("#txtEmail", "E-mail");
	bindblurhandler("#txtComments", "Comments");

	bindblurhandler("#txtConsumerFirstName", "First Name");
	bindblurhandler("#txtConsumerLastName", "Last Name");
	bindblurhandler("#txtConsumerEmail", "E-mail");
	bindblurhandler("#txtConsumerCity", "City");
	bindblurhandler("#txtConsumerZip", "Zip");
	bindblurhandler("#txtConsumerComments", "Let us know which bills, statements, catalogs, and coupons you would like to see included in the Volly digital delivery service.");

	if (location.hash == "#consumer") {
		show_consumer_tab();
	}
}

show_consumer_tab = function () {
	$("#contactInfoCntnr").hide();
	$("#consumerContactInfoCntnr").show();
	$(".consumerContactInfoTab").addClass("consumerContactInfoTabOn");
	$(".contactInfoTab").removeClass("contactInfoTabOn");
}

contactus_validate = function (source, args) {
	clear_validator("#contactUsValidator");
	var valid = true;

	var thisvalid = req_field_validate("#txtFirstName", "First Name", "textboxError");
	if (!thisvalid) add_validator_item("#contactUsValidator", "First Name is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtLastName", "Last Name", "textboxError");
	if (!thisvalid) add_validator_item("#contactUsValidator", "Last Name is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtCompany", "Company", "textboxError");
	if (!thisvalid) add_validator_item("#contactUsValidator", "Company is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtPhone", "Phone", "textboxError");
	if (!thisvalid) add_validator_item("#contactUsValidator", "Phone is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtEmail", "E-mail", "textboxError");
	if (!thisvalid) add_validator_item("#contactUsValidator", "E-mail is required.");
	valid = thisvalid && valid;
	if (thisvalid) {
		thisvalid = regex_field_validate("#txtEmail", /^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$/, "E-mail", "textboxError");
		if (!thisvalid) add_validator_item("#contactUsValidator", "Invalid e-mail.");
		valid = thisvalid && valid;
	}

	thisvalid = regex_field_validate("#txtZip", /^\d{5}(-\d{4})?$/, "Zip", "textboxError");
	if (!thisvalid) add_validator_item("#contactUsValidator", "Invalid zip code.");
	valid = thisvalid && valid;

	if (!valid) {
		show_validator("#contactUsValidator", "Please correct the following errors:");
	}

	args.IsValid = valid;
}

consumercontactus_validate = function (source, args) {
	clear_validator("#consumerContactUsValidator");
	var valid = true;

	var thisvalid = req_field_validate("#txtConsumerFirstName", "First Name", "textboxError");
	if (!thisvalid) add_validator_item("#consumerContactUsValidator", "First Name is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtConsumerLastName", "Last Name", "textboxError");
	if (!thisvalid) add_validator_item("#consumerContactUsValidator", "Last Name is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtConsumerEmail", "E-mail", "textboxError");
	if (!thisvalid) add_validator_item("#consumerContactUsValidator", "E-mail is required.");
	valid = thisvalid && valid;
	if (thisvalid) {
		thisvalid = regex_field_validate("#txtConsumerEmail", /^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$/, "E-mail", "textboxError");
		if (!thisvalid) add_validator_item("#consumerContactUsValidator", "Invalid e-mail.");
		valid = thisvalid && valid;
	}

	thisvalid = req_field_validate("#txtConsumerCity", "City", "textboxError");
	if (!thisvalid) add_validator_item("#consumerContactUsValidator", "City is required.");
	valid = thisvalid && valid;

	thisvalid = req_ddl_field_validate("#ddlConsumerState", "#consumerSZ .newListSelected", "textboxError");
	if (!thisvalid) add_validator_item("#consumerContactUsValidator", "State is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtConsumerZip", "Zip", "textboxError");
	if (!thisvalid) add_validator_item("#consumerContactUsValidator", "Zip is required.");
	valid = thisvalid && valid;
	if (thisvalid) {
		thisvalid = regex_field_validate("#txtConsumerZip", /^\d{5}(-\d{4})?$/, "Zip", "textboxError");
		if (!thisvalid) add_validator_item("#consumerContactUsValidator", "Invalid zip code.");
		valid = thisvalid && valid;
	}

	if (!valid) {
		show_validator("#consumerContactUsValidator", "Please correct the following errors:");
	}

	args.IsValid = valid;
}

summit_docready = function () {
	bindblurhandler("#txtSummitFirstName", "First Name");
	bindblurhandler("#txtSummitLastName", "Last Name");
	bindblurhandler("#txtSummitCompanyName", "Company Name");
	bindblurhandler("#txtSummitEmail", "E-mail");
	bindblurhandler("#txtSummitPhoneNumber", "Phone Number");
	bindblurhandler("#txtSummitZip", "Zip");
	bindblurhandler("#txtSummitColleagueName", "Colleague Name");
	bindblurhandler("#txtSummitColleagueEmail", "Colleague E-mail");

	if ($("#chkSummitColleague").is(":checked")) $("#colleagueCntnr").show();

	$("#chkSummitColleague").bind("change", function () {
		if ($(this).is(":checked")) {
			$("#colleagueCntnr").stop().slideDown(400, "linear", null);
		}
		else {
			$("#colleagueCntnr").stop().slideUp(400, "linear", null);
		}
	});
}

summitregistration_validate = function (source, args) {
	clear_validator("#summitValidator");
	var valid = true;

	var thisvalid = req_field_validate("#txtSummitFirstName", "First Name", "textboxError");
	if (!thisvalid) add_validator_item("#summitValidator", "First Name is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtSummitLastName", "Last Name", "textboxError");
	if (!thisvalid) add_validator_item("#summitValidator", "Last Name is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtSummitCompanyName", "Company Name", "textboxError");
	if (!thisvalid) add_validator_item("#summitValidator", "Company Name is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtSummitEmail", "E-mail", "textboxError");
	if (!thisvalid) add_validator_item("#summitValidator", "E-mail is required.");
	valid = thisvalid && valid;
	if (thisvalid) {
		thisvalid = regex_field_validate("#txtSummitEmail", /^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$/, "E-mail", "textboxError");
		if (!thisvalid) add_validator_item("#summitValidator", "Invalid e-mail.");
		valid = thisvalid && valid;
	}

	thisvalid = req_field_validate("#txtSummitPhoneNumber", "Phone Number", "textboxError");
	if (!thisvalid) add_validator_item("#summitValidator", "Phone Number is required.");
	valid = thisvalid && valid;

	thisvalid = req_field_validate("#txtSummitZip", "Zip", "textboxError");
	if (!thisvalid) add_validator_item("#summitValidator", "Zip is required.");
	valid = thisvalid && valid;
	if (thisvalid) {
		thisvalid = regex_field_validate("#txtSummitZip", /^\d{5}(-\d{4})?$/, "Zip", "textboxError");
		if (!thisvalid) add_validator_item("#summitValidator", "Invalid zip code.");
		valid = thisvalid && valid;
	}

	thisvalid = req_field_validate("#txtSummitColleagueName", "Colleague Name", "textboxError");
	if ($("#txtSummitColleagueName").is(":visible")) {
		if (!thisvalid) add_validator_item("#summitValidator", "Colleague Name is required.");
		valid = thisvalid && valid;
	}

	thisvalid = req_field_validate("#txtSummitColleagueEmail", "Colleague E-mail", "textboxError");
	if ($("#txtSummitColleagueEmail").is(":visible")) {
		if (!thisvalid) add_validator_item("#summitValidator", "Colleague E-mail is required.");
		valid = thisvalid && valid;
		if (thisvalid) {
			thisvalid = regex_field_validate("#txtSummitColleagueEmail", /^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$/, "Colleague E-mail", "textboxError");
			if (!thisvalid) add_validator_item("#summitValidator", "Invalid Colleague E-mail.");
			valid = thisvalid && valid;
		}
	}

	if (!valid) {
		show_validator("#summitValidator", "Please correct the following errors:");
	}

	args.IsValid = valid;
}

bindblurhandler = function (sel, defaultvalue) {
	$(sel).bind("blur", function () {
		if ($.trim($(this).val()) == "") $(this).val(defaultvalue);
	}).bind("focus", function () {
		if ($.trim($(this).val()) == defaultvalue) $(this).val("");
	});
}

req_field_validate = function (sel, defaultval, errorclass) {
	if ($(sel) != null) {
		$(sel).removeClass(errorclass);
		var val = $.trim($(sel).val());
		if (val == defaultval || val == "") {
			$(sel).addClass(errorclass);
			return false;
		}
	}
	return true;
}

req_ddl_field_validate = function (sel, ssSel, errorclass) {
	if ($(sel) != null) {
		$(ssSel).removeClass(errorclass);
		var val = $(sel).val();
		if (val == "-1") {
			if ($(ssSel) != null) {
				$(ssSel).addClass(errorclass);
			}
			else {
				$(sel).addClass(errorclass);
			}
			return false;
		}
	}
	return true;
}

regex_field_validate = function (sel, regex, defaultval, errorclass) {
	if ($(sel) != null) {
		$(sel).remove(errorclass);
		var val = $.trim($(sel).val());
		if (val != "" && val != defaultval && !regex.test(val)) {
			$(sel).addClass(errorclass);
			return false;
		}
	}
	return true;
}

add_validator_item = function (validatorsel, msg) {
	if ($(validatorsel) != null) {
		$(validatorsel + " ul:first").append($("<li>").text(msg));
	}
}

clear_validator = function (validatorsel) {
	if ($(validatorsel) != null) {
		$(validatorsel + " ul:first li").remove();
		$(validatorsel + " h5").text("");
		$(validatorsel).hide();
	}
}

show_validator = function (validatorsel, msg) {
	if ($(validatorsel) != null) {
		$(validatorsel + " h5").text(msg);
		$(validatorsel).show();
	}
}

// TWITTER STUFF

getTwitterBoxLatestTweets = function (numTweets) {
	var url = "http://search.twitter.com/search.json?q=from%3a" + twitterUser + "&rpp=" + numTweets + "&page=1&callback=?";
	var twitterBoxCntnr = $("#tweets");
	$.getJSON(url, function (data) {
		$.each(data.results, function (i, tweet) {
			var tweetCntnr = $("<div class='tweetCntnr'>");
			$("<div class='tweet'>").append($("<p>").html(twitterLinkURLReplace(tweet.text))).appendTo(tweetCntnr);
			$("<div class='tweetDate'>").append($("<p>").html(formatTwitterDateTime(tweet.created_at).toString())).appendTo(tweetCntnr);
			tweetCntnr.hide().appendTo(twitterBoxCntnr).fadeIn();
		});
	});
}

formatTwitterDateTime = function (date) {
	var d = new Date(date);
	var today = new Date();

	// Compare dates.  If the tweet was from today, the string should read "Updated at xx:xx a/pm".  Otherwise, the string should read "Updated on mm/dd/yyyy at xx:xx a/pm".
	var ret = "Updated ";

	if (Math.round((today - d) / (1000 * 60 * 60 * 24)) > 0) { // Calculate the difference between d and today in days
		var month = d.getMonth() + 1;
		var day = d.getDate();
		var year = d.getFullYear();
		ret += " on " + month.toString() + "/" + day.toString() + "/" + year.toString();
	}

	var am = true;
	var h = d.getHours();
	if (d.getHours() > 12) {
		h = d.getHours() - 12;
		am = false;
	}
	var m = (d.getMinutes() < 10 ? "0" : "") + d.getMinutes();
	ret += " at " + h.toString() + ":" + m.toString() + " " + (am ? "AM" : "PM");
	return ret;
}

twitterLinkURLReplace = function (str) {
	str = str.replace(/(http\:.*?)(\s|$)/, "<a href='$1'>$1</a> ").replace(/\@(.*?)(\s|$)/g, " <strong>@<a class='twitterUserLink' href='http://twitter.com/$1'>$1</a></strong> ").replace(/\b(RT)\b/g, "<strong>$1</strong>");
	return str;
}
