ContentPages = function(){}; 
ContentPages.MenuLeft = null; 
ContentPages.DataBridgeObj = null; 

ContentPages.LoadPage = function(subPage)
{
	var initMap = false; 
	ContentPages.MenuLeft = null;
	
	if(subPage == "CommitmentToService")
	{
		$("MasterStatus").style.height = "1400px";
	
	}
	
	switch(subPage)
	{
		case "SpecialCase":
		{
			break; 
		}
		case "ContactUs":
		{
			initMap = true; 
		}		
		default:
		{
			var thisLayout = Layouts.Get(subPage); 	
			
			Globals.UI.Navigation.ResetCrumbTrail(); 
			Globals.UI.Navigation.AddToCrumbTrail("Home","javascript:GoToPage(Page.HomeBase)"); 
			Globals.UI.Navigation.AddToCrumbTrail(thisLayout.GetAttribute("PageMainTitle"),"javascript:GoToPage(Page.ContentPage, '" + subPage + "')"); 
			

			
			Globals.UI.Navigation.LoadPage
			(
				Globals.HtmlEscape(thisLayout.GetAttribute("PageCategory")), 
				Globals.HtmlEscape(thisLayout.GetAttribute("PageMainTitle")), 
				thisLayout.GetDatabridgeMergedContent(),
				"",
				"", 
				ContentPages.MenuLeft
			); 		

			if(UserRoles.HasRights(UserRoles.EDIT_PAGE_CONTENT))
			{
				//$("BottomFooter").style.display = "block";		
				$(Globals.UI.Navigation.BottomFooterId).innerHTML = "<button onclick='ContentPages.EditPage(\"" + subPage + "\");'>Edit Page</button>"; 
			}		
			break;
		}				
	}
	
	if(initMap)
	{
		var map = null;
		var geocoder = null;
		var address = "685 West Center Street,Provo, Utah"; 
		  if (GBrowserIsCompatible()) 
		  {
			map = new GMap2(document.getElementById("map_canvas"));
			map.setCenter(new GLatLng(37.4419, -122.1419), 13);
			geocoder = new GClientGeocoder();
		  }

		  if (geocoder) 
		  {
			geocoder.getLatLng(
			  address,
			  function(point) 
			  {
				if (!point) 
				{
				  alert(address + " not found");
				} 
				else 
				{
				  map.setCenter(point, 13);
				  var marker = new GMarker(point);
				  map.addOverlay(marker);
				  marker.openInfoWindowHtml(address);
				}
			  }
			);
		  }
	}			
};

ContentPages.EditPage = function(pageToEdit)
{	
	Globals.UI.Navigation.ResetCrumbTrail(); 
	Globals.UI.Navigation.LoadPage("Content Editor", "Editing " + pageToEdit); 		
	
	var thisLayout = Layouts.Get(pageToEdit); 	
	var evalString = "ContentPages.LoadPage('" + pageToEdit + "')"; 
	thisLayout.RenderEditor($("MiddleBody"), function(){}, evalString); 	
};

var currentPageEditing = null; 
ContentPages.SaveNewContent = function(pageToEdit)
{	
	currentPageEditing = pageToEdit; 
	var page = Page.Get(pageToEdit);
	page.SetContent(ContentPages.EditPage.Controls.Content.GetValue()); 
	
	var serverData = new ServerData.SenderObject("save", null, "./ServerData/ContentEditor.ashx", ContentPages.EditPage.Form.GetURIFormat() + "&PageUrl=" + page.URL + "&OldPageName=" + page.Name);             
	Globals.ShowSpinner("status", "Saving Content..."); 

	serverData.SendData(function(results)
	{  
		GoToPage(Page.ContentPage, currentPageEditing); 
	});
};

ContentPages.EditPage.Controls = function(){};
