var nllhdr2_currentbanner = 0;

$(document).ready(function()
{
	// all checkboxes with the class .select-all
	// should be named the same as the checkboxes, with _All
	$(".select-all").change(function(){
		var name = this.name;
		var root_name = name.substr(0,name.indexOf("_"));
		if ($("input[name="+name+"]").attr("checked"))
		{
			$("input[name="+root_name+"]").attr("checked", "checked");
		}
		else
		{
			$("input[name="+root_name+"]").removeAttr("checked");
		}
	});
	
	// all items that are expanded views should be hidden
	$(".expanded").hide();
});
// --------------------------------------------------------------------------
function display_conditional(condition, ifTrue, ifFalse)
{
	return (condition) ? ifTrue : ifFalse;
}
// --------------------------------------------------------------------------
function prependZero(fld)
{
	if (fld.value.substr(0,1) == ".") fld.value = "0" + fld.value;
}
// --------------------------------------------------------------------------
function updateFormatDollars(fld)
{
	fld.value = formatDollars(fld.value);
}
// --------------------------------------------------------------------------
function formatDollars(nStr)
{
	nStr = '' + nStr;
	nStr = nStr.replace(/[^\d]/g,'');
	var x = nStr.split('.');
	var x1 = x[0];
	//x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1;
}
// --------------------------------------------------------------------------
function expand(c)
{
	$("."+c).show();
}
// --------------------------------------------------------------------------	
function nllhdr2_rotateBanner()
{
	$("#hdrbnr").fadeOut(160, nllhdr2_showNextBanner);
}
// --------------------------------------------------------------------------
function nllhdr2_showNextBanner()
{
	$("#hdrbnr").removeClass('nllheader-'+nllhdr2_currentbanner);
	nllhdr2_currentbanner++;
	if (nllhdr2_currentbanner >= 9) nllhdr2_currentbanner = 0;
	$("#hdrbnr").addClass('nllheader-'+nllhdr2_currentbanner);
	$("#hdrbnr").fadeIn(600);
}	
// --------------------------------------------------------------------------

//Redirects page to new URL
function redirectURL()
{
	var url = document.redirurl.newurl[document.redirurl.newurl.selectedIndex].value;
	if (url) document.location.href = url;
}

//Removes excessive spaces within a string
function trim(s)
{
	return String(s).replace(/^\s+|\s+$/g,"").replace(/\s+/g," ");
}

//
function editHTML(webpage)
{
	var url = webpage;
	var hWnd = window.open(url, 'editor','width=680,height=525,resizable,scrollbars,status=yes,toolbar=yes,menubar=yes');
	if (window.focus) {hWnd.focus();}
}

function jumpMenu(targ,selObj,restore)
{
	var targetA = "self";
	eval(targetA+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

//
function cellColor(cColor, iFColor)
{
	nada="";
	aCell=event.srcElement;
	if (aCell.tagName=="TR"||aCell.tagName=="TABLE") {return;}
	while(aCell.tagName!="TD") {aCell=aCell.parentElement;}
	if (aCell.style.backgroundColor != cColor && aCell.id == "a") {aCell.parentElement.style.backgroundColor = cColor; }
	if (aCell.style.backgroundColor != cColor && aCell.id == "b") {aCell.parentElement.parentElement.parentElement.style.backgroundColor = cColor; }
	if (aCell.style.backgroundColor != cColor && aCell.id != "c") {aCell.style.backgroundColor = cColor; }
	aCell.style.color = iFColor;
}
	
//
function toggle ( target, imgSrc )
{
	if (document.getElementById)
	{
		target = document.getElementById( target );
		if (target.style.display == "none")
		{
			target.style.display = "";
			imgSrc.src = 'images/bt_showSearch.gif';
		}
		else
		{
			target.style.display = "none";
			imgSrc.src = 'images/bt_hideSearch.gif';
		}
	}
}

//
function toggleBid ( target )
{
	if (document.getElementById)
	{
		target = document.getElementById( target );
		if (target.style.display == "none")
		{
			target.style.display 	= "";
		}
		else
		{
			target.style.display 	= "none";
		}
	}
}

//
function toggleMenu ( target )
{
	if (document.getElementById)
	{
		target = document.getElementById( target );
		if (target.style.display == "none")
		{
			target.style.display 	= "";
		}
		else
		{
			target.style.display 	= "none";
		}
	}
}

//
function navWin(navWin)
{
	openWin = this.open(navWin,"navWin","toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes,width=360,height=480");
}

//
function navWin2(navWin)
{
	openWin = this.open(navWin,"navWin","toolbar=yes,menubar=no,location=no,scrollbars=no,resizable=yes,width=600,height=560");
}

//
function navWin3(navWin)
{
	openWin = this.open(navWin,"navWin","toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes,width=600,height=720");
}