// JavaScript Document

	addLoadEvent(checkIncomingVariables);
	
	// Selector Variables
	
	var lightboxWidth		= "";
	var lightboxHeight		= "";
	var lightboxSize		= "";  // For use with Simple version only!
	var lightboxUse			= "";	
	var lightboxCaseDepth	= "";
	var lightboxChassis		= "";
	var lightboxLeadTime	= "";
	var lightboxUL			= "";
	var lightboxBrightness	= "";
	var lightboxSided		= "";
	var lightboxFrameWidth	= "";
	var lightboxFinishOption = "";
	var lightboxFinishColor	= "";
	
	var selectorType		= "";
	var selectorVariables	= "";
	var firstRun = true;
	
	function checkIncomingVariables()
	{
		var shipToday		= getElement("shipToday").value;
		var selectorMode 	= getElement("selectorMode").value;
		var lightboxWidth 	= getElement("lightboxWidth").value;
		var lightboxHeight 	= getElement("lightboxHeight").value;
		
		setMode(selectorMode);
		
		if (shipToday == "yes") { updateVariable("lightboxLeadTime", "1"); }
		if (lightboxWidth != "") { updateVariable("lightboxWidth", lightboxWidth); }
		if (lightboxHeight != "") { updateVariable("lightboxHeight", lightboxHeight); }
		
		getSelectorLightboxes();
	}
	
	function updateVariable(variableId, variableValue)
	{
		
		if (variableId == "lightboxWidth")
		{
			if (validateNumber("Lightbox Size: Width is INVALID!", variableValue))
			{
				// Add leading zeros
				if (variableValue != "")
				{
					if (variableValue.length <= 1)
					{
						variableValue = "0" + variableValue;
					}
				}
				
				lightboxWidth = variableValue;
				getElement("lightboxWidth").value = variableValue;
			}
			else
			{
				// Clear out bad values
				document.getElementById("lightboxWidth").value = "";
				lightboxWidth = "";
			}
		}
		
		
		if (variableId == "lightboxHeight")
		{
			if (validateNumber("Lightbox Size: Height is INVALID!", variableValue))
			{
				// Add leading zeros
				if (variableValue != "")
				{
					if (variableValue.length <= 1)
					{
						variableValue = "0" + variableValue;
					}
				}
				
				lightboxHeight = variableValue;
				getElement("lightboxHeight").value = variableValue;
			}
			else
			{
				// Clear out bad values
				document.getElementById("lightboxHeight").value = "";
				lightboxHeight = "";
			}
		}
		
		if (variableId == "lightboxSize") 		{ lightboxSize = variableValue; }
		if (variableId == "lightboxUse") 		{ lightboxUse = variableValue; }
		if (variableId == "lightboxCaseDepth") 	{ lightboxCaseDepth = variableValue; }
		if (variableId == "lightboxChassis") 	{ lightboxChassis = variableValue; }
		if (variableId == "lightboxLeadTime") 	{ lightboxLeadTime = variableValue; }
		if (variableId == "lightboxUL") 		{ lightboxUL = variableValue; }
		if (variableId == "lightboxBrightness") { lightboxBrightness = variableValue; }
		if (variableId == "lightboxSided") 		{ lightboxSided = variableValue; }
		if (variableId == "lightboxFrameWidth") { lightboxFrameWidth = variableValue; }
		if (variableId == "lightboxFinishOption") { lightboxFinishOption = variableValue; }
		if (variableId == "lightboxFinishColor") { lightboxFinishColor = variableValue; }
		
	}
	
	function getSelectorLightboxes()
	{
			selectorVariables = "&lightboxWidth=" + lightboxWidth
			selectorVariables = selectorVariables + "&lightboxHeight=" + lightboxHeight
			selectorVariables = selectorVariables + "&lightboxSize=" + lightboxSize
			selectorVariables = selectorVariables + "&lightboxUse=" + lightboxUse
			selectorVariables = selectorVariables + "&lightboxCaseDepth=" + lightboxCaseDepth
			selectorVariables = selectorVariables + "&lightboxChassis=" + lightboxChassis
			selectorVariables = selectorVariables + "&lightboxLeadTime=" + lightboxLeadTime
			selectorVariables = selectorVariables + "&lightboxUL=" + lightboxUL
			selectorVariables = selectorVariables + "&lightboxBrightness=" + lightboxBrightness
			selectorVariables = selectorVariables + "&lightboxSided=" + lightboxSided
			selectorVariables = selectorVariables + "&lightboxFrameWidth=" + lightboxFrameWidth
			selectorVariables = selectorVariables + "&lightboxFinishOption=" + lightboxFinishOption
			selectorVariables = selectorVariables + "&lightboxFinishColor=" + lightboxFinishColor
		
			// Check Lightbox Size -------------------------
			setAjaxUrl("selectorResults", "ajax_lightbox_selector.asp?selectorType=" + selectorType + selectorVariables , "getElement('loadingGraphicProducts').innerHTML='<img src=/images/loadingGraphic1.gif>';", "getElement('loadingGraphicProducts').innerHTML='';");
	}
	
	function resetRadioForm(variableName)
	{
		// Sets the form value back to default
		if (document.getElementsByName(variableName)[0])
		{
			document.getElementsByName(variableName)[0].checked = "yes";	
		}	
	}
	
	function validateNumber(messageText, numberValue)
	{
		var regEx = new RegExp("^[0-9]*$", "i"); // Only allows numbers
		
		if (regEx.test(numberValue))
		{
			return true;
		}
		else if (numberValue != "")
		{
			alert(messageText);
			return false;
		}
		
		
	}
	
	function checkLightboxSize()
	{
		if ((lightboxWidth != "") & (lightboxHeight != ""))
		{
			getSelectorLightboxes();
		}
	}
	
	function showLoadingGraphic()
	{
		document.getElementById("loadingGraphic").innerHTML = "<img src='/images/loadingGraphic1.gif'>";
	}
	
	function hideLoadingGraphic()
	{
		document.getElementById("loadingGraphic").innerHTML = "";
	}
	
	function setMode(modeValue)
	{
		if (modeValue == "simple")
		{
			document.getElementById("selectorAdvanced").style.display = "none";
			document.getElementById("selectorSimple").style.display = "block";
			getElement("selectorModeSimple").checked = true;
		}
		
		if (modeValue == "advanced")
		{
			document.getElementById("selectorSimple").style.display = "none";
			document.getElementById("selectorAdvanced").style.display = "block";
			getElement("selectorModeAdvanced").checked = true;
		}
		
		if (!firstRun)
		{
			resetSelector();
		}
		
		firstRun = false;
	}
	
	function resetSelector()
	{
		lightboxWidth		= "";
		lightboxHeight		= "";
		lightboxSize		= ""; 
		lightboxUse			= "";	
		lightboxCaseDepth	= "";
		lightboxChassis		= "";
		lightboxLeadTime	= "";
		lightboxUL			= "";
		lightboxBrightness	= "";
		lightboxSided		= "";
		lightboxFrameWidth	= "";
		lightboxFinishOption = "";
		lightboxFinishColor	= "";
		
		// Set all checkboxes back to default
		getElement("lightboxWidth").value = "";
		getElement("lightboxHeight").value = "";
		resetRadioForm("lightboxSize");
		resetRadioForm("lightboxUse");
		resetRadioForm("lightboxCaseDepth");
		resetRadioForm("lightboxChassis");
		resetRadioForm("lightboxLeadTime");
		resetRadioForm("lightboxUL");
		resetRadioForm("lightboxBrightness");
		resetRadioForm("lightboxSided");
		resetRadioForm("lightboxFrameWidth");
		resetRadioForm("lightboxFinishOption");
		resetRadioForm("lightboxFinishColor");
		
		resetRadioForm("lightboxUseSimple");
		resetRadioForm("lightboxCaseDepthSimple");
		resetRadioForm("lightboxChassisSimple");
		resetRadioForm("lightboxLeadTimeSimple");
		resetRadioForm("lightboxSidedSimple");
		resetRadioForm("lightboxFinishColorSimple");
		
		getSelectorLightboxes();
	}