$().ready(function () {
	initInput();
	footnoteLinks();
});

function initInput()
{
	$("#search, #user").each(
		function(i) {
			$(this)
				.focus(
					function () {
						if($(this).attr("defaultValue") == $(this).attr("value")) {
							$(this).attr("value", "");
							$(this).attr({style:'color:#000000;'});
						}
					}
				)
			
				.blur(
					function () {
						if($(this).attr("value") == "") {
							$(this).attr("value", $(this).attr("defaultValue"));
							$(this).attr({style:'color:#888888;'});
						}
					}
				)
				
				.attr({style:'color:#888888'});
		}
	);
		
	$("#hdnpass")
		.focus(
			function() {
				$(this).hide();
				$("#pass")
					.show()
					.focus();
			}
		)
		.show();
	
	$("#pass")
		.blur(
			function() {
				if ($(this).attr('value') == '') {
					$(this).hide();
					$("#hdnpass").show();
				}
			}
		)
		.hide();
}

function footnoteLinks() {
	var target = $("#footnotes");
	var elements = $("#content *, #footer *")
		.not("#menu *")
		.not("#pnl_right *")
		.not("#pnl_left *")
		.not("#page_left_pnl *")
		.not(".dsponly *");

	var links = [];
	var list = $(document.createElement('ol'));
	var num = 1;
	
	elements.each(function (i) {
		if ($(this).attr('href') || $(this).attr('cite')) {
			var link = $(this).attr('href') ? $(this).attr('href') : $(this).attr('cite');
			
			if (link.toLowerCase().indexOf('javascript:') != -1)
				return;
						
			if (link.toLowerCase().indexOf(':') == -1)
			{
				switch(link.substr(0, 1))
				{
					case '/':
						link = 'http://' + location.host + link;
						break;
					case '#':
						link = location.href + link;
						break;
					default:
						var path = location.pathname;
						var idx = path.lastIndexOf('/');
						
						if (idx == -1)
							link = 'http://' + location.host + '/' + link;
						else
							link = 'http://' + location.host + path.substr(0, idx + 1) + link;
							
						break;
				}
			}
				
			lnknum = $.inArray(link, links);
			
			if (lnknum == -1) {
				// link not found in array
				links[links.length] = link;
				lnknum = num;
				num++;
				list.append('<li>' + link + '</li>');
			} else {
				lnknum++;
			}
			
			$(this).after('<sup class="inprtonly">' + lnknum + '</sup>');
		}
	});
	
	if (num > 1) {
		target.append('<h2>Links</h2>');
		target.append(list);
	} else {
		target.remove();
	}
	
	$('html').addClass('noted');
}

function openWindow(url, title, options) {
  window.open(url, title, options);
}

