function changeUploadPath(){

	$(document).ready(function() {
	   $("menu").children("'ie:menuitem'").each(function(){
	   
	    if ($(this).attr("onMenuClick")) {
	   
	        var s = $(this).attr("onMenuClick");
	        
	           if (s.indexOf('_layouts/Upload.aspx') > 0)
	           {
	            $(this).attr("onMenuClick", s.replace('_layouts', 'pages'));
	           }
	       }
	   });
	});
}

// Reformats the group headers in document libraries to remove category text
function formatGroupHeaders(stringToReplace)
{

	$(document).ready(function() {
	
			var nodes =  $("#focalPointBody").find("td.ms-gb:contains('" + stringToReplace + "')").each(function(){
			
				var text = $(this).text();
				var link = $(this).children("a")[0];
				text = text.replace(stringToReplace, '');
				
				
				$(this).empty();
				$(this).append(link);
				$(this).children("a").append(text);
														 
			});
	});

}


function toggleEmptyResults(msgToDisplay)
{
    var $table = $("table.ms-summarycustombody");
    var row =  $("tr.ms-viewheadertr");
    
    if ($table.length > 0){
       row.empty();
        var $innerRow = $table.children("tbody").children("tr").children("td.ms-vb:first");
       $innerRow.empty();
       $innerRow.append(msgToDisplay);

    }
  
}

function ExpCollGroup(groupName, imgName)
{
	if (document.getElementById("titl"+groupName)==null)
		return;
	imagelocation = document.getElementById("site").value
	viewTable=document.getElementById("titl"+groupName).parentNode;
	if (viewTable==null)
		return;
	tbodyTags=viewTable.getElementsByTagName("TBODY");
	numElts=tbodyTags.length;
	len=groupName.length;
	img=document.getElementById(imgName);
	if (img==null)
		return;
	srcPath=img.src;
	index=srcPath.lastIndexOf("/");
	imgName=srcPath.slice(index+1);
	var fOpen=false;
	if (imgName=='plus.gif')
	{
		fOpen=true;
		displayStr="";
		img.src='/PublishingImages/' + imagelocation + '/minus.gif';
	}
	else
	{
		fOpen=false;
		displayStr="none";
		img.src='/PublishingImages/' + imagelocation + '/plus.gif';
	}
	for (var i=0;i<numElts;i++)
	{
		var childObj=tbodyTags[i];
		if ( (childObj.id !=null)
					&& (childObj.id.length > len+4)
					&& (groupName==childObj.id.slice(4).substr(0,len)) )
		{
			if (fOpen)
			{
				index=childObj.id.indexOf("_", len+4);
				if (index!=-1)
				{
					index=childObj.id.indexOf("_", index+1);
					if (index!=-1)
						continue;
				}
			}
			
			childObj.style.display=displayStr;
			if (fOpen && childObj.id.substr(0,4)=="titl")
			{
				imgObj=document.getElementById("img_"+childObj.id.slice(4));
				imgObj.src='/PublishingImages/' + imagelocation + '/plus.gif';
			}
		}
	}
	if (!g_ExpGroupParseStage)
	{
		if (g_ExpGroupNeedsState && ExpGroupFetchWebPartID(groupName) !=null)
		{
			if (fOpen)
			{
				AddGroupToCookie(groupName);
			}
			else
			{
				RemoveGroupFromCookie(groupName);
			}
		}
		if (fOpen)
		{
			tbody=document.getElementById("tbod"+groupName+"_");
			if (tbody !=null)
			{
				isLoaded=tbody.getAttribute("isLoaded");
				if (isLoaded=="false")
				{
					ExpGroupFetchData(groupName);
				}
			}
		}
	}
}

/*********************************************************
function    :selectMainNav  
author      :Glenn Littlewood
description :Set the style of the main navigation menu 
             based on the current page
*********************************************************/
var selectMainNav = function selectMainNav() {
    var path = getMainMenuPath();
    var extension = path.slice(path.length - 5, path.length);
    if (path) {
        if (extension != ".aspx") {
            path = path + "/"
        }
        $('#ctl00_ctl12_GlobalNavMenu a[href^="' + path + '"]').parents('li').children('a').attr('class', 'link focused clicked');
        $('#ctl00_ctl12_GlobalNavMenu a[href^="' + path + '"]').attr('class', 'link focused clicked');
    }
};



/*********************************************************
function    :selectSideNav  
author      :Glenn Littlewood
description :Set the style of the side navigation menu 
             based on the current page
*********************************************************/
var selectSideNav = function selectSideNav() {
	var path =  getMenuLink().replace(/%20/g, " ");
	if ( path )
		imageLocation = document.getElementById("site").value;
	    $('#ctl00_PlaceHolderMain_LeftNavMenu a[href$="' + path + '"] span').css({'background-image' : 'url(/PublishingImages/' + imageLocation + '/arrow_down.gif)', 'background-repeat':'no-repeat', 'background-position':'0px 13px'});
} ;

/*********************************************************
function    :expandSideNav  
author      :Glenn Littlewood
description :Expands the currently selected navigation  node
*********************************************************/
var expandSideNav = function expandSideNav() {
	
	
	var panelbar = ctl00_PlaceHolderMain_LeftNavMenu;
	var currentUrl = document.location.href;
	var currentItem = panelbar.FindItemByUrl(currentUrl);

	if (currentItem){
	
	
					currentItem.TextElement.style.fontWeight = "bold";
					var parentItem = currentItem.Parent;
					
					if (parentItem.Level){
									parentItem.Expand();
					}
					
					if (currentItem.Items.length > 0){
									currentItem.Expand();
					}
	}
} ;
/********************************************************** 
function    :getMenuLink 
author      :Glenn Littlewood
description :Get the appropriate main menu link based 
             on the current page
**********************************************************/
var getMenuLink = function getMenuLink (){
	var regexLists = new RegExp("Lists", "i");
	var regexFormA = new RegExp("/DispForm", "i");
	var regexFormB = new RegExp("/fpDispForm", "i");
	var regExEdit = new RegExp("/EditForm", "i");
	var regExNew = new RegExp("/NewForm", "i");
	var regExAll = new RegExp("/AllItems", "i");

	return 	location.pathname.substring(1).
			replace(regexLists, "Pages").
			replace(regexFormA, "").
			replace(regexFormB, "").
			replace(regExEdit, "").
			replace(regExNew, "").
			replace(regExAll, "");
};
/********************************************************** 
function    :getMainMenuPath
author      :Glenn Littlewood
description :Get the appropriate main menu path based 
             on the current page
**********************************************************/
var getMainMenuPath = function getMainMenuPath (){
	var subPaths = location.pathname.split("/");
	return "/" + subPaths[1] + "/" + subPaths[2];
};



		// toggles an answer div from visible to hidden or hidden to visible
		function toggleQAAnswer(answerDivId) {

		    var answerDiv = document.getElementById(answerDivId);
		    var imageDiv = document.getElementById(answerDivId + "_hd");
		    var disp;
		    
		    if ( answerDiv != null)
		    {
		        var currentDisp = answerDiv.style.display
		        disp = ( ( currentDisp == "" || currentDisp == "none" ) ? "block" : "none" );
		        answerDiv.style.display = disp;
		    }
		    
		    
		    if (imageDiv != null)
		    {
		   		        		        
		        if(disp == "block")
		        {
		        	imageDiv.attributes["class"].value = "expandCollapseHeaderDown";
		        }
		        else
		        {
		        	imageDiv.attributes["class"].value = "expandCollapseHeader";
		        }
		        		
		    }
		
		}




		var loadPopUps = function() {
		    $(document).ready(function() {

		        var items = $(".popUp");

		        $(".popUp").each(

    	            function() {

    	                try {

    	                    var link = $(this).attr("href");
    	                    $(this).attr("href", "#");

    	                    $(this).bind("click", function() {
    	                        window.open(link, "norfolk", "width=800, height=550, scrollbars=yes");
    	                    });

    	                }
    	                catch (ex) {
    	                }

    	            }
                );
		    });
		}