﻿function FixProfileScrollDiv(windowWidth)
{
	var profileScrollDiv = document.getElementById('ProfileScrollDiv');
	if (profileScrollDiv != null)
	{
		if (windowWidth < 1000)
			profileScrollDiv.style.left = 20;
		else
			profileScrollDiv.style.left = 850;
	}
}
function resizeMainDiv()
{
	if (document.location.href.toLowerCase().indexOf('vocuspopup=') >= 0)
		return;
	if (pr4Mode)
	{
  	if (!IsBrowserIE())
			  window.scrollTo(0,0);
	}
	var mainDiv = document.getElementById('mainDiv');
	var toolbarDiv = document.getElementById('toolbarDiv');
	var navDiv = document.getElementById('navDiv');
	var settingsDiv = document.getElementById('settingsDiv');
	var tabDiv = document.getElementById('tabDiv');
				
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	
	FixProfileScrollDiv(windowWidth);
	
	if (navDiv != null)
	{
		var navWidth = Number(navDiv.style.width.replace('px',''));
		
		if (navWidth == 0)
		{
			navWidth = 150;
		}
		if (settingsDiv != null)
		{
			var settingsWidth = Number(settingsDiv.style.width.replace('px',''));
		
			settingsWidth = 225;
			
			if (!IsBrowserIE())
			{
				mainDiv.style.paddingLeft = "20px";					
   			if (borderWidth > 20)
   				mainDiv.style.paddingRight = (borderWidth) + "px";
   			else
   				mainDiv.style.paddingRight = "20px";
 				mainDiv.style.width = windowWidth - navWidth - settingsWidth - Number(mainDiv.style.paddingLeft.toUpperCase().replace('PX','')) - Number(mainDiv.style.paddingRight.toUpperCase().replace('PX','')) + 20 + 'px';
			}
			else
			{
				mainDiv.style.width = windowWidth - navWidth - settingsWidth + 'px';
			}
			
			if (!IsBrowserIE())
			{		
				settingsDiv.style.width = settingsWidth - 20 + 'px';
				settingsDiv.style.left = Number(mainDiv.style.width.replace('px','')) + navWidth + 30 + 'px';
			}
			else
			{
				settingsDiv.style.width = settingsWidth + 'px';
				settingsDiv.style.left = Number(mainDiv.style.width.replace('px','')) + navWidth + 'px';
			}
			
			settingsDiv.style.display = "inline";
		}
		else
		{
			if (pr4Mode)
			{
				navDiv.style.left = 0 + 'px';				
				navWidth = 150;
									
				var borderWidth = (windowWidth - defaultWindowWidth);

  			viewPortWidth = windowWidth - navWidth - 60 - 4; // Remove another 60 for the padding.
  				
  			if (!IsBrowserIE())
  			{
 					mainDiv.style.paddingLeft = "20px";					
    			if (borderWidth > 20)
    				mainDiv.style.paddingRight = (borderWidth) + "px";
    			else
    				mainDiv.style.paddingRight = "20px";
  				mainDiv.style.width = windowWidth - navWidth - Number(mainDiv.style.paddingLeft.toUpperCase().replace('PX','')) - Number(mainDiv.style.paddingRight.toUpperCase().replace('PX','')) + 20 + 'px';
    		}
   			else			
   			{
    			mainDiv.style.width = windowWidth - navWidth + 'px';
  				if (borderWidth > 40)
  				{
  					mainDiv.style.paddingLeft = "20px";					
  					mainDiv.style.paddingRight = (borderWidth - 20) + "px";					
  				}
  				else
  				{					
  					mainDiv.style.paddingLeft = "20px";					
  					mainDiv.style.paddingRight = "20px";
  				}		
    		}
				
				if (toolbarDiv != null)
				{
					toolbarDiv.style.borderLeft =  navWidth + "px solid " + skinColorToolbar;
					
					if (borderWidth > 33)
						toolbarDiv.style.borderRight = (borderWidth - 33) + "px solid " + skinColorToolbar;						
					else
						toolbarDiv.style.borderRight = "20px solid " + skinColorToolbar;						
				
				}
			}
			else
			{
				if (!IsBrowserIE())
				{
					mainDiv.style.width = windowWidth - navWidth - 10 + 'px';
				}
				else
				{
					mainDiv.style.width = windowWidth - navWidth + 'px';
				}
			}
		}
		if (tabDiv != null)
		{
			tabDiv.style.width = mainDiv.style.width;
		}
	}
	else
	{
		mainDiv.style.left = 0 + 'px';			
	
		if (pr4Mode)
		{								
			var borderWidth = (windowWidth - defaultWindowWidth);
			
			if (borderWidth <= 0)
			{
				borderWidth = 20;
			}
			
			viewPortWidth = windowWidth - borderWidth - 4;
			
			mainDiv.style.marginLeft = "0px";
			mainDiv.style.marginRight = "0px";
			mainDiv.style.paddingLeft = "20px";
			
			if (!IsBrowserIE())
			{
    			if (borderWidth > 20)
    				mainDiv.style.paddingRight = (borderWidth) + "px";
    			else
    				mainDiv.style.paddingRight = "20px";
  				mainDiv.style.width = windowWidth - Number(mainDiv.style.paddingLeft.toUpperCase().replace('PX','')) - Number(mainDiv.style.paddingRight.toUpperCase().replace('PX','')) + 20 + 'px';
	  		}
 			else			
 			{
  				mainDiv.style.width = windowWidth + 'px';
  				
    			if (borderWidth > 20)
    				mainDiv.style.paddingRight = (borderWidth - 20) + "px";
    			else
    				mainDiv.style.paddingRight = "20px";
  			}

			if (toolbarDiv != null)
			{
				toolbarDiv.style.backgroundColor = skinColorToolbar;
				toolbarDiv.style.paddingLeft =  "20px";
				
				if (borderWidth > 33)
					toolbarDiv.style.paddingRight = (borderWidth - 33) + "px";					
				else
					toolbarDiv.style.paddingRight = "20px";			
			}	
			
		}
		else
		{
			if (!IsBrowserIE())
			{
				mainDiv.style.width = windowWidth - 10 + 'px';
			}
			else
			{
				mainDiv.style.width = windowWidth + 'px';
			}
		}
					
		if (tabDiv != null)
		{
			tabDiv.style.left = 0 + 'px';		
			tabDiv.style.width = mainDiv.style.width;
		}
	}
	
	if (document.getElementById("viewPortDiv") != null)
	{
		document.getElementById("viewPortDiv").style.width = "950px";
	}
	
	var addHeight = 0;
		
	if (toolbarDiv != null)
	{	
		if (toolbarDiv.style.display != "none")
		{
			var toolbarHeight = Number(toolbarDiv.style.height.replace('px',''));
			
			if (toolbarHeight == 0)
			{
				toolbarHeight = 20;
			}
			
			addHeight += toolbarHeight;
			
			if (!IsBrowserIE())
			{
				var toolBarWidth = 0;
    		if (borderWidth > 20)
    			toolbarDiv.style.paddingRight = (borderWidth) + "px";
    		else
    			toolbarDiv.style.paddingRight = "20px";
  			toolBarWidth = windowWidth - Number(mainDiv.style.paddingLeft.toUpperCase().replace('PX','')) - Number(mainDiv.style.paddingRight.toUpperCase().replace('PX','')) + 20;
				toolbarDiv.style.width = toolBarWidth + 'px';
	  	}
	  	else
	  	{
				toolbarDiv.style.width = windowWidth + 'px';
	  	}
		}
	}

	if (navDiv != null)
	{
		navDiv.style.top = addHeight + 'px';
		if (!IsBrowserIE())
		{
			navDiv.style.height = windowHeight - addHeight + 20 + 'px';
		}
		else
		{
			navDiv.style.height = windowHeight - addHeight + 'px';
		}
	}

	if (tabDiv != null)
	{
		tabDiv.style.top = addHeight + 'px';
	}

	if (tabDiv != null)
	{	
		if (tabDiv.style.display != "none")
		{
			var tabHeight = Number(tabDiv.style.height.replace('px',''));
			
			if (tabHeight == 0)
			{
				tabHeight = 58;
			}
			
			addHeight += tabHeight + 20; // 10 for top padding of tabDiv & 10 to simulate top padding for mainDiv
		}
	}
	
	mainDiv.style.top = addHeight + 'px';
	
	if (IsBrowserIE())
	{
	  if (windowHeight - addHeight > 0)
	  {
		  mainDiv.style.height = windowHeight - addHeight + 'px';
		}
  }
  else
  {
    //addHeight += Number(mainDiv.style.paddingTop.replace('px',''));
    //addHeight += Number(mainDiv.style.paddingBottom.replace('px',''));
    //mainDiv.style.paddingTop = '0px';
    //mainDiv.style.paddingBottom = '0px';
    //addHeight += mainDiv.offsetTop;
    //addHeight += mainDiv.offsetBottom;
	  if (windowHeight - addHeight > 0)
	  {
		  mainDiv.style.height = windowHeight - addHeight + 'px';
		}
  }
	
	if (settingsDiv != null)
	{	
		settingsDiv.style.top = addHeight + 'px';
		
		if (windowHeight - addHeight > 0)
			settingsDiv.style.height = windowHeight - addHeight + 'px';
	}

	if (navDiv != null)
	{
		navDiv.style.overflowY = 'auto';
		navDiv.style.overflowX = 'hidden';
	}

	if (pr4Mode)
	{
		mainDiv.style.overflow = 'auto';
		if (document.getElementById("toolbarTable"))
		{
			document.getElementById("toolbarTable").style.visibility = "visible";
		}
		
		SynchHeaderFrame();
	}
	updatePicklists();
};

function updatePicklists()
{
	try
	{
		for (i=0; i<currentPicklists.length; i++)
		{
		  if (document.getElementById('iframe'+currentPicklists[i]))
  		{
  			if (document.getElementById('iframe'+currentPicklists[i]).style.display != 'none')
  			{
    			setPickListPosition(currentPicklists[i]);
	    		document.getElementById('iframe'+currentPicklists[i]).contentWindow.resizePickList();
      		document.getElementById('iframe'+currentPicklists[i]).contentWindow.refreshPickList();
      	}
      }
		}
	} catch (e)
	{
	}	
}

function SynchHeaderFrame()
{
	if (currentHeaderTab != "")
	{
		if (top != null )
		{
			if (top.frames["frameHeader"] != null)
			{
				try
				{
					top.frames["frameHeader"].customEval("ChangeTab(\'" + currentHeaderTab + "\', \'\')");
				}
				catch (e) {}
			}
		}
	}
};

function WizardResize()
{
  	if (!IsBrowserIE())
			  window.scrollTo(0,0);

	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();

	var mainDiv = document.getElementById('mainDiv');
	
	mainDiv.style.height = (windowHeight - 110) + "px";
	mainDiv.style.width = (windowWidth - 150) + "px";
	mainDiv.style.overflow = 'auto';
};

function WizardNoNavResize()
{
  	if (!IsBrowserIE())
			  window.scrollTo(0,0);

	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();

	var mainDiv = document.getElementById('mainDiv');
	
	mainDiv.style.height = (windowHeight - 25) + "px";
	mainDiv.style.width = (windowWidth - 25) + "px";
	mainDiv.style.overflow = 'auto';
};
