function is_all_ws(nod) { return !(/[^\t\n\r ]/.test(nod.data)); }
function is_ignorable(nod) { return (nod.nodeType == 8) || ((nod.nodeType == 3) && is_all_ws(nod)); }

function first_child(par) {
	var res = par.firstChild;
	while(res) {
		if(!is_ignorable(res)) return res;
		res = res.nextSibling;
	}
	return null;
}

function node_after(sib) {
	while ((sib = sib.nextSibling)) {
		if (!is_ignorable(sib)) return sib;
	}
	return null;
}

function last_child(par) {
	var res = par.lastChild;
	while(res) {
		if(!is_ignorable(res)) return res;
		res = res.previousSibling;
	}
	return null;
}

$(document).ready(function(){
	var ff = $.query.get('f');
	var pg = ( ff ) ? "/contribute/" + ff + "/" : "contribute/1/";
	var sid = "#rb" + ff;
	$('#msg1').css('font-weight','bold').addClass("checked");
// check to see if post success passed; if so, display thanks image in container div
	if ($.query.get('success') === 1) {
		$('#fcontent').empty().html('<img src="../../static/wenatcheeworld/images/contribute_thks.jpg" />' );
	} else if ($.query.get('success') === 0) {
		$('#fcontent').empty().html('<h3>Sorry; there\'s been a problem with your submission. You may have forgotten to provide some required information. Please try again.</h3>');	
	} else {
		$("#fcontent").load(pg);		
		$('#msg1').css('font-weight','bold');
		if (ff) {
			$("#rb1").attr("checked", false);
			$("#msg1").css('font-weight','normal').removeClass("checked");
			$(sid).attr("checked", true);
		}
	}
	$('input[type=radio]').prettyCheckboxes();
	$('form.tform').css('display','block');
});

$('input[name=dbform]').live('click', function() {
	$('#loading').css('display','inline');
	var nf = $(this).val();
	var cf = "/contribute/" + nf + "/";
	var mf = "#msg" + nf;
	var ms = $(mf).html();
	$('#fcontent').load(cf,{},function(){
		$('label.fmsg').css('font-weight','normal');
		$(mf).html(ms).css('font-weight','bold');
		$('#loading').hide();	
	});
});

