
function openFolderInTree(linkID) {
var folderObj;
folderObj = findObj(linkID);
folderObj.forceOpeningOfAncestorFolders();
if (!folderObj.isOpen)
 clickOnNodeObj(folderObj);
} 
function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
var defaultFilter = "";
function setdf() 
{
	var hn = window.location.hostname;
	if(hn.search('chicagotribune') != -1)
		defaultFilter = 41127;
	else if(hn.search('baltimoresun') != -1)
		defaultFilter = 41128;
	else if(hn.search('morningcall') != -1)
		defaultFilter = 41129;
	else
		defaultFilter = "";
}
function goToCat(cid, cname, isP) {
	var sfil = gup("scat");
	if(sfil == "")
		sfil = defaultFilter;
	var hn = window.location.hostname;
	if(isP == 1)
	{
		if (defaultFilter == 41127)
			var myURL = "http://www.chicagotribunephotos.com";
		else if (defaultFilter == 41128)
			var myURL = "http://www.baltimoresunphotos.com";
		else if (defaultFilter == 41129)
			var myURL = "http://www.morningcallphotos.com";
		else if (hn == "localhost")
			var myURL = "http://localhost:8500/tribunesite"
		else
			var myURL = "http://www.tribunephotos.com";
			var myURL = myURL+"/category.cfm?catname="+cname+"&catID="+cid+"&scat="+sfil+"&linkname=catTree";
	}
	else
		var myURL = "http://store.tribunephotos.com/store/search.aspx?catID="+cid+"&key="+cid+"+"+cname+"&scat="+sfil;
	pageTracker._link(myURL);
	window.location = myURL;
}
function goToPCat(cid, cname) {
	var sfil = gup("scat");
	if(sfil == "")
		sfil = defaultFilter;
	var myURL = "http://store.tribunephotos.com/store/search.aspx?catID="+cid+"&key="+cname+"&scat="+sfil;
	pageTracker._link(myURL);
	window.location = myURL;
}
function goHome() {
	var sfil = gup("scat");
	if (sfil == 41127 || defaultFilter == 41127)
		var myURL = "http://www.chicagotribunephotos.com";
	else if (sfil == 41128 || defaultFilter == 41128)
		var myURL = "http://www.baltimoresunphotos.com";
	else if (sfil == 41129 || defaultFilter == 41129)
		var myURL = "http://www.morningcallphotos.com";
	else
		var myURL = "http://www.tribunephotos.com";
	pageTracker._link(myURL);
	window.location = myURL;
}
function showDiv(elem)
{	document.getElementById(elem).style.display = "block"; }
function hideDiv(elem)
{	document.getElementById(elem).style.display = "none"; }
function changeHeader(flg)
{
	var divid = flg + "Logo";
	var linkid = flg + "Home";
	document.getElementById(divid).style.display = "block";
	document.getElementById(linkid).style.display = "inline";
}

function showCurrentFilter() 
{
	var curr_sfil = gup("scat");
	if (curr_sfil == "")
		curr_sfil = defaultFilter;
	for(i=0; i<document.getElementById('sfil').length; i++)
	{
		if(document.getElementById('sfil').options[i].value == curr_sfil)
		{
			document.getElementById('sfil').selectedIndex = i;
		}
	}
	if (curr_sfil == "")
		filterFlag = "ALL";
	else if (curr_sfil == 41127)
		filterFlag = "CT";
	else if (curr_sfil == 41128)
		filterFlag = "BS";
	else if (curr_sfil == 41129)
		filterFlag = "MC";
	
	changeHeader(filterFlag);
}
	
function applyFilter(fval) {
	var currURL = document.URL;
	var qPos = currURL.search(/\?/); 
	if(qPos == -1) //if no query string, add scat param
		window.location = currURL + "?scat=" + fval;
	else
	{
		var sPos = currURL.search("scat");
		if(sPos == -1) //if param does not exist
			window.location = currURL + "&scat=" + fval; //just add scat param to existing URL
		else //if scat exists, we have to replace it in the new URL
		{
			var curr_sfil = gup('scat'); //get current value of scat param
			var old = "scat=" + curr_sfil;
			var nw = "scat=" + fval;
			var newURL = currURL.replace(old, nw);
			pageTracker._link(newURL);
			window.location = newURL;
		}
	}
}

function doCASearch()
{
	var curr_sfil = gup("scat");
	if (curr_sfil == "")
		curr_sfil = defaultFilter;
	var qURL = "http://store.tribunephotos.com/store/search.aspx?";
	var qString = document.SearchForm.key.value;
	qURL = qURL + "key=" + qString + "&scat=" + curr_sfil;
	pageTracker._link(qURL);
	window.location = qURL;
}

