function openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}
function buildWebmasterEmailAddress(link) {
	var output = 'mailto:';
	output += 'webmaster';
	output += '@';
	output += 'responsiblesports';
	output += '.';
	output += 'com';
	link.href = output;
}
var timeoutElement;
function defaultText(element, defaultText) {
    if (element.value == defaultText) {
        element.value = "http://";
        if (element.createTextRange) { // IE
            var range = element.createTextRange();
            range.move("textedit");
            range.select();
        }
        else if (element.setSelectionRange) { // FF
            timeoutElement = element;
            setTimeout("ffMoveCaret()", 50);
        }
    }
    else if (element.value == "" || element.value == "http://") {
        element.value = defaultText;
    }
}
function ffMoveCaret() {
    timeoutElement.setSelectionRange(timeoutElement.value.length, timeoutElement.value.length);
}

function bookmark(title,url){
    if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "http:www.yourwebsiteurl.com");
    else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
    }
    else if(document.all)// ie
    window.external.AddFavorite(url, title);
}

Date.prototype.setISO8601 = function(dString) {

    var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/;

    if (dString.toString().match(new RegExp(regexp))) {
        var d = dString.match(new RegExp(regexp));
        var offset = 0;

        this.setUTCDate(1);
        this.setUTCFullYear(parseInt(d[1], 10));
        this.setUTCMonth(parseInt(d[3], 10) - 1);
        this.setUTCDate(parseInt(d[5], 10));
        this.setUTCHours(parseInt(d[7], 10));
        this.setUTCMinutes(parseInt(d[9], 10));
        this.setUTCSeconds(parseInt(d[11], 10));
        if (d[12])
            this.setUTCMilliseconds(parseFloat(d[12]) * 1000);
        else
            this.setUTCMilliseconds(0);
        if (d[13] != 'Z') {
            offset = (d[15] * 60) + parseInt(d[17], 10);
            offset *= ((d[14] == '-') ? -1 : 1);
            this.setTime(this.getTime() - offset * 60 * 1000);
        }
    }
    else {
        this.setTime(Date.parse(dString));
    }
    return this;
};

if ($.browser.msie && $.browser.version == "6.0") {
//expand panels
}
else {
    $(function() {
        $(".expando").each(function() {

            var ctx = this;

            if ($(".expando-target", ctx).is(":visible")) {
                $(".expando-toggle", ctx)
                .attr("src", "/common/images/panel_collapse.jpg");
            }
            else {
                $(".expando-toggle", ctx)
                .attr("src", "/common/images/panel_expand.jpg");
            }

            $(".expando-toggle", ctx).click(function() {

                if ($(".expando-target", ctx).is(":visible")) {
                    $(".expando-toggle", ctx)
                    .attr("src", "/common/images/panel_expand.jpg");
                }
                else {
                    $(".expando-toggle", ctx)
                    .attr("src", "/common/images/panel_collapse.jpg");
                }

                $(".expando-target", ctx)
                .slideToggle("normal");
            });
        });
    });
}

function trackEvent(category, action, label) {
    _gaq.push(['_trackEvent',category, action, label]);
}

function isblank(val) {
    if (val == null || val == "") {
        return true;
    }
    else {
        return false;
    }
}
function handleFocus(f) {
 if (f.value == f.defaultValue) {
 f.value = "";
 }
}

function handleBlur(f) {
 if (f.value == "" || f.value == null || isblank(f.value)) {
 f.value = f.defaultValue;
 }
}

function hide(elementID) {
    $("#" + elementID).hide();
}

/* ExactTarget Subscription */
$(function() {
    $(".subscription-ctx").each(function() {

        var ctx = this;

        var wm = $(this).attr("wm");
        var li = $(this).attr("li");

        $(".subscription-link", ctx).click(function() {

            if (confirm("Are you sure you want to subscribe to this mailing list?")) {

                $(ctx)
                    .removeClass("inactive")
                    .addClass("processing");

                $.getJSON("/common/ashx/exacttarget_subscription_handler.ashx?wm=" + wm + "&li=" + li, function(result) {
                    // note: the exacttarget subscription handler returns true if the request was successful; false otherwise
                    if (result) {

                        $(ctx)
                            .removeClass("processing")
                            .addClass("active");

                        $(".subscription-link", ctx)
                            .hide();

                    }
                    else {

                        $(ctx)
                            .removeClass("processing")
                            .addClass("inactive");

                        alert("Your subscription request could not be completed at this time.  Please try again later.");
                    }
                });
            }

        });
    });
});

function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}
function fireDefaultButton(event, target) {
 if (event.keyCode == 13) {
 
	 var src = event.srcElement || event.target;
	 
	 if (!src || (src.tagName.toLowerCase() != "textarea")) {
	 
	 var defaultButton = target;
	 
		 if (defaultButton && typeof(defaultButton.click) != "undefined") {
 			defaultButton.click();
 			event.cancelBubble = true;
		 if (event.stopPropagation) event.stopPropagation();
		 
			return false;
		 }
	 }
 }
 return true;
}

//validation functions
	function showErrorAlert(errors)
	{
		if (errors.length > 0)
		{
			var alertMessage = '';
			var errorindex = 0;
			for (errorindex = 0; errorindex < errors.length; errorindex++)
			{
				var error = errors[errorindex];
				alertMessage = (alertMessage + error + '\n');
			}
			alert(alertMessage);
		}
	}
	
	function validateRequiredField(value, name, errors)
	{	
		if ($.string(value).blank())
		{
			errors.push(name + " is a required field.");
		}
	}
	function validateRequiredSelection(value, name, errors)
	{
		if ($.string(value).blank())
		{
			errors.push(name + " is a required selection.");
		}
	}
	
	function validateEmailAddress(email, emailName, errors)
	{
		if ($.string(email).blank())
		{
			errors.push(emailName + " is a required field.");
		}
		else if (!this.isValidEmailAddress(email))
		{
			errors.push(emailName + " must be a valid email address.");
		}
	}
	
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}
