// Show/Hide elements
function showElement(elementID,showLinkID) {
	if (document.getElementById(elementID)) {
			document.getElementById(showLinkID).style.display = 'none';
			document.getElementById(elementID).style.display = 'block';
			document.getElementById('ctl00_ctl00_CbFooterContent').childNodes[1].style.marginLeft = '10px';
	}
}

function hideElement(elementID,showLinkID) {
	if (document.getElementById(elementID)) {
			document.getElementById(showLinkID).style.display = 'inline';
			document.getElementById(elementID).style.display = 'none';
			document.getElementById('ctl00_ctl00_CbFooterContent').childNodes[1].style.marginLeft = '0';
	}
}


var prevSearch = ""; 

//search
function NUSearchKeyPress(e) {
    if ((e.keyCode || e.which) == 13) {
        NUSearch(false);
        return false;
    }
    return true;
} 

function NUSearch(clickSearch) {
    var searchString = "";
    
    //determine if it's from keystroke or click
    if(clickSearch == true) {
        searchString = prevSearch;
    } else {
        searchString = $("#searchBox").val();
    }
    
    //search if we've got something to search on.
    if(searchString != null && searchString != "") {
        window.location = "/search.aspx?searchtext=" + searchString;
    }
}

$(document).ready(function() {
    //search box
    $("#searchBox").focus(function() {
        $(this).attr("value","");
    }); 
    
    $("#searchBox").blur(function() {
        prevSearch = $(this).val();
        $(this).attr("value","search this site");
    });
    
    //login box focus
    try {
        $("#user_id").focus();
    } catch(err) {}
    
    //login boxes
    //$("#userName").focus(function() {
        //if($(this).attr("value") == "User ID") {
            //$(this).attr("value","");
        //}
    //});
    
    //$("#password").focus(function() {
        //if($(this).attr("value") == "Password") {
            //$(this).attr("value","");
        //}
    //});
    
    //captcha key listener
    $("#recaptcha_response_field").keypress(function(event) {
        if (event.keyCode == "13") {
            $(".nuFormCaptchaSubmit").trigger("click");
            return false;
        }
    });
    
    //login button click listener
    $("#ctl00_ctl00_loginLink").click(function() {
        try {
            $("#aspnetForm").removeAttr("onsubmit");
        } catch(err) {}
    });
});

// Google Analytics
// Use linker URL when opening a new window
// www.google.com/support/forum/p/Google%20Analytics/thread?tid=1b27094fa6a3d61e&hl=en
function openLinkedWindow(link) {
      _gaq.push(function() {
        var tracker = _gaq._getAsyncTracker(); 
        window.open(tracker._getLinkerUrl(link.href));
      });
      return false;
}
