<!--
// scripts you call below are being run within body onload.

// *** Help Module Functions *** \\\

var removeFromHTML;
removeFromHTML = "Remove<BR>From<BR>Design<BR>Center";
	
function DoHelp(iNm)
{
  var H;
  var sWD;
  H = screen.availHeight-29;
  sWD="toolbar=0,status=0,menubar=0,width=180,height="+H+",left="+(screen.availWidth-190)+",top=0,resizable=0";
  h_win = window.open('/global/pageFunctions/help/helppane.asp?id='+iNm,'FMM_help',sWD);
}

function reMax()
{
  h_win = window.opener	
  h_win.top.window.resizeTo(screen.availWidth, screen.availHeight);
  h_win.top.window.moveTo(0,0);
}

function SizeforHelp()
{
  h_win = window.opener	
  h_win.top.window.resizeTo(screen.availWidth - 190, screen.availHeight);
  h_win.top.window.moveTo(0,0);  
}

function LoadPH()
{
  SizeforHelp();
  ph.location.replace("/system/help/frameset.asp" + self.location.search);
}
// *** Help Module Functions *** \\\


// *** Web Site Functions *** \\\
  function mOvr(src,style)
  {
    var element;
    element = document.getElementById(src);
    element.className=style;
    element.style.cursor='hand';
  }

  function mOut(src,style,subId)
  {
    var element;
    if(subId != src)
    {
      element = document.getElementById(src);
      element.className=style;
    }
  }
  
  function noSpam(userName)
	{
		window.location="mailto:" + userName + "@anglesondesign.com";
	}
	
function subnav(menuName, buttonName)
{
	var menuName;
	if (!document.getElementById) return;

	menuName = document.getElementById(menuName);
	if (menuName.style.display == "none")
	{
		menuName.style.display = "";
		buttonName.className = stringReplace(buttonName.className, "menu", "menu-s");
	}
	else
	{
		menuName.style.display = "none";
		buttonName.className = stringReplace(buttonName.className, "menu-s", "menu");
	}
}

function stringReplace(theString, replaceMe, withMe)
{
	var rExp;
  var temp = "";
  var newReplaceMe = "";
  
  for (var x = 0 ; x < replaceMe.length ; x++)
  {
  	temp = replaceMe.substr(x, 1);
    if(temp == "$" || temp == "^" || temp == "*" || temp == "(" || temp == ")" || temp == "+" || temp == "?" || temp == "\\")
    {
    	temp = "\\" + temp;
		}
    newReplaceMe += temp
	}
  rExp = new RegExp(newReplaceMe, "gi");
  results = theString.replace(rExp, withMe);
  return results;
}	

function getCamera(strCam)
{
	document.write(unescape(strCam));
}


var g_ActivePopup = null;
var g_DefaultButton = null;
var g_CurrentButton = null;

function showLivePopup(popupName, defaultButtonId)
{
	// Make sure we only display 1 popup at a time
	if(g_ActivePopup != null)
		hideLivePopup();

	// Save the default button	
	g_DefaultButton = document.getElementById(defaultButtonId);
	g_CurrentButton = g_DefaultButton;

	// Display the Popup
	DisplayPopup(popupName);	
}

function hideLivePopup()
{
	if(g_ActivePopup != null)
	{
		g_ActivePopup.className = "hidden";
		document.getElementById("popupDisable").className = "hidden";

		// Detach our Tab trap
		document.detachEvent("onkeydown", onPopupKeyDown);

		g_ActivePopup = null;
		g_DefaultButton = null;
		g_CurrentButton = null;
	}
}

function DisplayPopup(popupName)
{
	// Find the Popup Window
	g_ActivePopup = document.getElementById(popupName);
	if(g_ActivePopup)
	{
		// Get the dimensions of the client area of the browser
		var windowHeight = getWindowHeight();
		var windowWidth = getWindowWidth();

		// We need to take into account the current scroll position of the window
		var vScrollPos = getScrollTop();
		var hScrollPos = getScrollLeft();

		// Display the popup
		g_ActivePopup.className = "popupVisible";

		// Position the Active Popup in the middle of the client area of the browser		
		g_ActivePopup.style.top = (vScrollPos + ((windowHeight - g_ActivePopup.offsetHeight) / 2)) + "px";
		g_ActivePopup.style.left =  (hScrollPos + ((windowWidth - g_ActivePopup.offsetWidth) / 2)) + "px";

		// Display the disabling DIV
		document.getElementById("popupDisable").className = "popupDisable";
	
		// Position the Disable Div
		PositionOverlays();
		
		// Attach our Tab trap
		document.attachEvent("onkeydown", onPopupKeyDown);
		
		// Set the focus to the first element in the popup
		focusFirstElement();
	}
}

function focusFirstElement()
{
	// Sets the focus to the first focusable element in the popup (if any)
	var element = getFirstElement();
	if(element)
		element.focus();
}

function focusLastElement()
{
	// Sets the focus to the last focusable element in the popup (if any)
	var element = getLastElement();
	if(element)
		element.focus();
}

function getFirstElement()
{
	// Returns the first focusable element in the popup
	if(g_ActivePopup)
	{	
		// Get the Popup's Content DIV
		var content = document.getElementById(g_ActivePopup.id + "Content");
		
		// Find the first focussable element within the Popup's content
		if(content)
		{
			var element = content.firstChild;
			while(element != null)
			{
				if(isFocusable(element))
					return element;
				else
					element = element.nextSibling;
			}
		}
	}
}

function getLastElement()
{
	// Returns the last focusable element in the active popup
	if(g_ActivePopup)
	{
		// Get the Popup's Content DIV
		var content = document.getElementById(g_ActivePopup.id + "Content");
		
		// Find the last focussable element within the Popup's content
		if(content)
		{
			var element = content.lastChild;
			while(element != null)
			{
				if(isFocusable(element))
					return element
				else
					element = element.previousSibling;
			}
		}	
	}
	
	return null;
}

function isFocusable(element)
{
	// Returns TRUE if we can set focus to the element type
	switch(element.tagName)
	{
		case "BUTTON":
		case "A":
		case "INPUT":
		case "TEXTAREA":
			return true;
		default:
			return false;
	}
}

function onPopupKeyDown(ev)
{
	if((g_ActivePopup != null) && (g_CurrentButton != null) && (ev.keyCode == 13))
	{
		g_CurrentButton.onclick();
		return false;
	}
	
	// Check if we're displaying a Popup and the key pressed was TAB
	if((g_ActivePopup != null) && (ev.keyCode == 9))
	{
		// Check if we're tabbing forwards or backwards
		// and if we're about to step off the popup
		if(ev.shiftKey)
		{
			// Tabbing backwards
			if(ev.srcElement == getFirstElement())
			{
				focusLastElement();
				return false;
			}		
		}
		else
		{
			// Tabbing forwards
			if(ev.srcElement == getLastElement())
			{
				focusFirstElement();
				return false;
			}
		}
	}
}

function PositionOverlays()
{
	if (g_ActivePopup != null)
	{
		// Get the dimensions of the client area of the browser
		var windowHeight = getWindowHeight();
		var windowWidth = getWindowWidth();

		// We need to take into account the current scroll position of the window
		var vScrollPos = getScrollTop();
		var hScrollPos = getScrollLeft();

		if (g_ActivePopup != null)
		{
			// Position the disabling DIV so that it exactly covers
			// the current client area of the browser
			var disableDiv = document.getElementById("popupDisable");
			disableDiv.style.top = vScrollPos + "px";
			disableDiv.style.left = hScrollPos + "px";
			disableDiv.style.height = windowHeight + "px";
			disableDiv.style.width = windowWidth + "px";
		}	
	}
}

// Add the resize event
if (window.attachEvent)
{
	// IE
	window.attachEvent("onresize", PositionOverlays);
	window.attachEvent("onscroll", PositionOverlays);	
}
else if (window.addEventListener)
{
	// Firefox etc
	window.addEventListener("resize", PositionOverlays, false);
	window.addEventListener("scroll", PositionOverlays, false);	
}

function getScrollTop()
{
	var pos = 0;
	if(document.body && document.body.scrollTop)
		pos = parseInt(document.body.scrollTop, 10);
	if(pos == 0 && document.documentElement && document.documentElement.scrollTop)
		pos = parseInt(document.documentElement.scrollTop, 10);
	return pos;
}

function getScrollLeft()
{
	var pos = 0;
	if(document.body && document.body.scrollLeft)
		pos = parseInt(document.body.scrollLeft, 10);
	if(pos == 0 && document.documentElement && document.documentElement.scrollLeft)
		pos = parseInt(document.documentElement.scrollLeft, 10);
	return pos;
}

function getWindowHeight()
{
	if (window.innerHeight != window.undefined)
		return window.innerHeight;
		
	if (document.compatMode == 'CSS1Compat')
		return document.documentElement.clientHeight;
		
	if (document.body)
		return document.body.clientHeight;
		
	return window.undefined; 
}
function getWindowWidth()
{
	if (window.innerWidth != window.undefined)
		return window.innerWidth; 
		
	if (document.compatMode == 'CSS1Compat')
		return document.documentElement.clientWidth; 
		
	if (document.body)
		return document.body.clientWidth; 
		
	return window.undefined; 
}

function onViewFullSize()
{
	showLivePopup("viewFullSizeDlg", "viewFullSize");
}

function closeImgWindow()
{
	hideLivePopup();
}


function imgSwap(URL)
{
	document['itemImg'].src=URL;
	document['zoomImgWindow'].src=URL;
	return false;
}

function designCenterClick(itemDetailId)
{
  var http_request = false;

  if (window.XMLHttpRequest)
  {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType)
    {
      http_request.overrideMimeType('text/xml');
    }
  }
  else if (window.ActiveXObject)
  {
    try
    {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!http_request)
  {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
  }
  	
	if (document.getElementById("designCenterBtn").innerHTML == removeFromHTML)
	{
		urlForFetch = "/mods/designCenter/itemRemote.asp?itemDetailId=" + itemDetailId + "task=remove";
		document.getElementById("designCenterBtn").innerHTML = "Removing<BR>Item";
	}
	else
	{
		urlForFetch = "/mods/designCenter/itemRemote.asp?itemDetailId=" + itemDetailId + "task=add";
		document.getElementById("designCenterBtn").innerHTML = "Adding<BR>Item";
	}  

  http_request.onreadystatechange = function() { getResultsFromItemRemote(http_request); };
  http_request.open('get', urlForFetch, true);
  http_request.send(null);
}

function getResultsFromItemRemote(http_request)
{
  if (http_request.readyState == 4)
  {
    if (http_request.status == 200)
    {
			document.getElementById("designCenterBtn").innerHTML = http_request.responseText;
    }
  }
  else
	{
		document.getElementById("designCenterBtn").innerHTML = "Sorry, An<BR>error<BR>has<BR>occured";
	}
}

// *** Web Site Functions *** \\\
// -->