//put 'for' parameter into cookie in case of authentication failure
$(function(){
	if($(document).getUrlParam("for") == null){
		//uh-oh, authentication failure
		$.cookie("for", $.cookie("for"), { expires: 30 });
	}
	else{
		$.cookie("for", $(document).getUrlParam("for"), { expires: 30 });
	}
});

//handle auto-focus on login inputs
var hasFocus = false;
$(function(){
	$("input[name='j_username']").focus(function(){
		hasFocus = true;
	});
	$("input[name='j_password']").focus(function(){
		hasFocus = true;
	});	
	var usernameValue = $("input[name='j_username']").attr("value");
	var passwordValue = $("input[name='j_password']").attr("value");
	if(usernameValue == "" && passwordValue == "" && !hasFocus){
		$("input[name='j_username']").focus();
	} 
});

//handle FAQ link click
$(function(){
	$("a.faq-link").click(function(){
		faqwindow = window.open('','faqwindow','height=500,width=750,scrollbars=yes');
		var tmp = faqwindow.document;
		tmp.write("<html><head><title>Frequently Asked Questions</title><style type='text/css'>li{margin-top:15px;margin-bottom:15px}</style></head><body style='padding:0 0px 10px 0px;color:#333333;font-family:Arial, sans-serif;font-size:13px;'>" + $(".faq-text").html() + "</body></html>");
		tmp.close();
		return false;
	});
});
