/******
setHeight should be launched onload
******/
function setHeight() {
	var d = document;
	var box = new Array("navBox","pagecontent"); //list of DIV ids
	var box2 = new Array("navBox","pagecontent"); //list of DIV ids
	for(x=0;x < box.length;x++)//determine the tallest div
	{
		h = d.getElementById(box[x]).offsetHeight;
		for(y=0;y < box.length;y++)
		{
			test_h = d.getElementById(box[y]).offsetHeight;
			if(h<test_h) { h = test_h; }
		}
	}
	if(d.getElementById("rssAlertBlk") != null)
	{	
		h2 = h - 81;
		d.getElementById("pagecontent").style.height = h2 +"px";
		d.getElementById("navBox").style.height = h +"px";
	} 
	else {
		for(x=0;x < box.length;x++)//set the height of all divs to the tallest
		{
			d.getElementById(box[x]).style.height = h +"px";
		}
	}
}

//Execute at loading of document
var j$ = jQuery.noConflict();
j$(document).ready(function () {
	//Get threshold value from a hidden div
	var threshold = j$("#parametric_expand_more_rows_threshold").text();
	
	j$("div#module_SizeGeneral .last p").remove().insertAfter("div#module_SizeGeneral .first p:last");
	
	//Iterate over all elements with a class of valueGroup
	j$(".valueGroup").each(function(i) {
		//Get the id attribute of the first parent element that has a class of module
		var parent = j$(this).closest(".module").attr('id');
		
		var thisThreshold = threshold;
		if(parent == 'module_SizeGeneral') {
			thisThreshold = threshold * 4;
		}
		
		//The size module is displayed differently and is therefore exempt
		if(thisThreshold > 0 && j$("p", this).size() > thisThreshold) {
			//only add this to first column
			if(j$(this).hasClass("first")) {
				j$(this).append('<p id="more_' + parent + '" class="more"><a href="#" class="more">More</a></p>');
				j$("#more_" + parent).show();
			}
			//show the first X rows
			j$("p:lt(" + thisThreshold + ")", this).show();
		} else {
			j$("p", this).show();
		}
	});
	
	
	j$(".valueGroupContainer").each(function(i){
		var parent = j$(this).closest(".module").attr('id');
		if(j$(".valueGroup",this).size() == 2 && parent != 'module_SizeGeneral'){
			j$("p", this).css('width', '64px');
		}
	});

	
	//The "no more filters available" message doesn't have the ability
	//in the global code to specify where it should display (first or last).
	//So this javascript will reorder it
	if(j$("h1.collection").size() > 0) {
		j$(".noFilters").remove().insertAfter("h1.collection");
	}
	

	j$("a.more").live("click", function(){
		j$(this).hide().closest("div.module").find("p").show(function() {
			j$("#navBox #pagecontent").removeAttr("style");
			setHeight();
		});
		
		return false;
	});
});


function sortFormElements(frm) {
	thisForm = frm;
	for (var i = 0; i < thisForm.elements.length; i++) {
		var repValue = thisForm.elements[i].value;
		var percentIndex = repValue.indexOf('%');
		if ( percentIndex > -1) {
			var subString = repValue.substring(0,percentIndex-1);
			subString = subString + " &#037;";
			thisForm.elements[i].value = subString;
		}
	}
}