﻿var xMax    = 0;
var yMax 	= 0;
var how     = null;


if (document.layers)
{
	// When the page scrolls in Netscape
	xMax	= window.innerWidth;
	yMax	= window.innerHeight;
	how 	= "layers";
}
else if (document.all)
{
	// When the page scrolls in IE
	xMax	= document.body.clientWidth;
	yMax	= document.body.clientHeight;
	how	    = "all"; 
}
else if (document.getElementById)
{
	// Netscape 6 behaves the same as Netscape 4 in this regard 
	xMax 	= window.innerWidth;
	yMax 	= window.innerHeight;
	how	    = "byID";
}

function highlightRow(row, how, mount, brandID)
{
    var tr = $get(row);
    tr.className = (how == "on") ? "highlightRow" : "";
    
    mount = (!mount) ? 2 : mount;
    
    var smallImg = $get('xfmrCloseUp');
    var largeImg = $get('xfmrLineArt');
    
    smallImg.src = "images/" + brandID + "/products/mounts/" + mount + "_small.jpg";
    largeImg.src = "images/" + brandID + "/products/mounts/" + mount + ".jpg";
}

function clickCell(item, how)
{
    var rad = document.aspnetForm.xfmrMountID;
    var radLen = rad.length;
    
    for (var i = 0; i < radLen; i++)
    {
        var curValue = rad[i].value;
        
        if (curValue == item)
        {
            rad[i].checked = true;
        }
        else
        {
            rad[i].checked = false;
        }
    }
}

function closeForiFrame()
{
    var obj = $get("ctl00_ContentPlaceHolder1_appPanel");
    obj.style.display = "none";
}

function updateCartQty(configItemID, isExtra, how, origVal)
{
    var msg = "There is no guarantee the system will be properly configured after ";
    msg += (how == "update") ? "modifying quantities." : "removing items.";

    if (isExtra == "0")
    {   
        if (confirm(msg))
        {
            if (how == "remove")
            {
                $get('qty' + configItemID).value = 0;
            }
        
            var itemToUpdate = (isExtra == "1") ? $get('itemToUpdate') : $get('configItemToUpdate');
            var btnHid = $get('buttonAction');
            
            itemToUpdate.value = configItemID;
            btnHid.value = (isExtra == "1") ? "updateExtra" : "updateConfig";
        
            document.aspnetForm.submit();
        }
        else
        {
            $get('qty' + configItemID).value = origVal;
        }
    }
    
    if (isExtra == "1")
    {
        if (how == "remove")
        {
            $get('qty' + configItemID).value = 0;
        }
    
        var itemToUpdate = (isExtra == "1") ? $get('itemToUpdate') : $get('configItemToUpdate');
        var btnHid = $get('buttonAction');
        
        itemToUpdate.value = configItemID;
        btnHid.value = (isExtra == "1") ? "updateExtra" : "updateConfig";
    
        document.aspnetForm.submit();
    }
}

function checkRadioButton(sysID)
{
    var getBtns = document.aspnetForm.systemID;
    var radioLen = getBtns.length;
    
    for (var i = 0; i < radioLen; i++)
    {
        var curValue = getBtns[i].value;
        
        if (curValue == sysID)
        {
            getBtns[i].checked = true;
        }
        else
        {
            getBtns[i].checked = false;
        }
    }
    testSpan('span_' + sysID);
}

function summaryAddSku(f)
{
    var skuQty = $get('skuQty');
    var partName = $get('ctl00_ContentPlaceHolder1_skuPartName');
    var sku = $get('ctl00_ContentPlaceHolder1_skuToAdd');
    var skuErrMsg = $get('ctl00_ContentPlaceHolder1_skuErrMsg');
    var btnHid = $get('buttonAction');
    
    if (!sku.value)
    {
        skuErrMsg.innerHTML = "No SKU was entered.";
    }
    else if (!partName.innerHTML)
    {
        skuErrMsg.innerHTML = "That SKU does not exist.";
    }
    else if (!skuQty.value)
    {
        skuErrMsg.innerHTML = "Enter a quantity.";
    }
    else
    {
        btnHid.value = "addSku";
        skuErrMsg.innerHTML = "";
        
        f.submit();
    }
    
    
}

function GetProperDropDown(sysID, shapeID)
{
    DropDowns.GetShapeLengths(sysID, shapeID, DropDownComplete);    
}
function DropDownComplete(arg)
{
    // Here we're retireving a semi-colon delimited string from the Web service function.
    // The first number in the string is the system id, the rest are the values for the drop down.
    var msg = "";
    var argArr = arg.split(";");
    var systemID = argArr[0];
    var shapeObj = $get('s' + systemID + '_lenID');
    
    if (shapeObj)
    {
        // First clear out the current list...
        for (x = shapeObj.length; x >= 0; x--)
        {
            shapeObj[x] = null;
        }
        
        var i = 0;
        for (x = 1; x < argArr.length; x++)
        {
            shapeObj.options[i] = new Option(argArr[x] + "ft", argArr[x]);
            i++;
        }
    }
}

function GetProductName(sku)
{
    if (sku != "")
    {
        DropDowns.GetProdNameBySku(sku, ProductNameComplete)
    }
}
function ProductNameComplete(arg)
{
    var skuProdName = $get('ctl00_ContentPlaceHolder1_skuToAdd');
    var skuPartName = $get('ctl00_ContentPlaceHolder1_skuPartName');
    
    if (arg && arg != "null")
        skuPartName.innerHTML = arg;
}

function showLineArt()
{
    $get('fixtureLargeID').src = '';
}

function changeColorSw(img, color, colorID, brandID)
{
    var fullImg = $get('fixtureLargeID');
    var colorTxt = $get('colorSelected');
    var colorOptID = $get('colorOptionID');
    
    fullImg.src = brandID + "/products/full/" + img + ".jpg";
    colorTxt.innerHTML = color;
    colorOptID.value = colorID;
    
    var errLbl = $get('errLbl');
    
    //$get('errLbl').innerHTML = '';
}

function changeColorCat(id, color, url)
{
    var fixID = $get('fixFrameID');
    window.location = "02Fixtures.aspx?" + url;
}

//function showOptions(url)
//{
//    var accID = $get('accID');
//    
//    accID.style.visibility = "visible";
//    accID.style.display = "block";
//    accID.src = "Options.aspx?" + url;
//    accID.height = "500px";
//    
//    /*style='scrollbar-face-color:#440077; scrollbar-darkshadow-color:#440077; scrollbar-3dlight-color:#440077; scrollbar-arrow-color:#99ffff; scrollbar-highlight-color:#99ffff; scrollbar-shadow-color:#99ffff; scrollbar-track-color:#000077;' */
//}

function testSpan(spanID)
{
    var tot = 28;
    var sid = $get(spanID);
    
    for (i = 1; i <= tot; i++)
    {
        var div = $get('span_' + i);
        if (div)
        {
            if (spanID != "span_" + i)
            {
                div.style.display = "none";
                div.style.visibility = "hidden";
            }
        }
    }
    
    sid.style.display = "block";
    sid.style.visibility = "visible";
}

function expandCollapseConfig(id, brandID)
{
    var configObj = $get('config' + id + '_ID');
    var imgObj = $get('plusMinus' + id);
    var action = imgObj.alt;
    var path = "http://images.techlighting.com/Configurator/" + brandID + "/buttons/";
    
    if (action == "Expand")
    {
        imgObj.alt = "Collapse";
        imgObj.src = path + "minus.gif";
        configObj.style.visibility = "visible";
        configObj.style.display = "block";
    }
    else
    {
        imgObj.alt = "Expand";
        imgObj.src = path + "plus.gif";
        configObj.style.visibility = "hidden";
        configObj.style.display = "none";
    }
}

function moveCartFrame()
{
    var getFrame = $get('orderFrame');
    
    if (getFrame.style.visibility != "visible")
    {
        var frameWidth = 275;
        var x = 0;
        getFrame.style.top = "28px";
        getFrame.style.visibility = "visible";
        
        if (xMax <= 810)
        {
            x = xMax - frameWidth;
        }
        else
        {
            var calc = (xMax - 800) / 2;
            x = xMax - (frameWidth + calc);
            
        }
        getFrame.style.left = x + "px";
    }
    else
    {
        getFrame.style.visibility = "hidden";
    }
}

function swapSysImg(finish, system, brandID)
{
    var sysImg = $get(system + 'ID');

    var abbr = (finish == "Antique Bronze") ? "bronze" : (finish == "Satin Nickel") ? "nickel" : (finish == "Chrome") ? "chrome" : (finish == "Black") ? "black" : "white";
    img = system + "_" + abbr + ".jpg";
    
    sysImg.src = brandID + "/products/fixed/" + img;
}

function appImg(imgPath)
{
    var imgControl = $get('ctl00_ContentPlaceHolder1_appImg');
    imgControl.src = imgPath;
    
    $find('ctl00_ContentPlaceHolder1_appPanelMPE').show()
}

//function getDesc(obj1, obj2, actn)
//{
//    var isVis;
//    var cartTop;
//    var cartLeft;
//    var tabLeft;

//	tabOBJ	= (document.getElementById) ? document.getElementById(obj1) : eval("document.all[obj1]");
//	cartOBJ	= (document.getElementById) ? document.getElementById(obj2) : eval("document.all[obj2]");
//	
//	if (actn == "click")	// Not scrolling
//	{
//		if (cartOBJ.style.visibility == "hidden" || cartOBJ.style.visibility == "")
//		{
//			isVis		= "visible";
//			cartTop		= (how == "byID") ? 100 + window.pageYOffset : 100 + document.documentElement.scrollTop;
//			cartLeft	= (how == "byID") ? xMax-325 : xMax-290;
//			
//			tabLeft		= (how == "byID") ? xMax-344 : xMax-306;
//		}
//		else
//		{
//			isVis		= "hidden";
//			cartTop		= (how == "byID") ? 100 + window.pageYOffset : 100 + document.documentElement.scrollTop;
//			cartLeft	= (how == "byID") ? xMax-325 : xMax-290;
//			
//			tabLeft		= (how == "byID") ? xMax-40 : xMax-21;
//		}
//	}
//	else	// scrolling
//	{
//		if (cartOBJ.style.visibility == "hidden" || cartOBJ.style.visibility == "")
//		{
//			isVis		= "hidden";
//			cartTop		= (how == "byID") ? 100 + window.pageYOffset : 100 + document.documentElement.scrollTop;
//			cartLeft	= (how == "byID") ? xMax-325 : xMax-290;
//			
//			tabLeft		= (how == "byID") ? xMax-40 : xMax-21;
//		}
//		else
//		{
//			isVis		= "visible";
//			cartTop		= (how == "byID") ? 100 + window.pageYOffset : 100 + document.documentElement.scrollTop;
//			cartLeft	= (how == "byID") ? xMax-325 : xMax-290;
//			
//			tabLeft		= (how == "byID") ? xMax-344 : xMax-306;
//		}
//	}

//	tabOBJ.style.left		    = tabLeft + "px";
//	cartOBJ.style.visibility	= isVis;
//	cartOBJ.style.left		    = cartLeft + "px";
//	cartOBJ.style.top		    = cartTop + "px";	
//	tabOBJ.style.top		    = (how == "byID") ? 100 + window.pageYOffset + "px" : 100 + document.documentElement.scrollTop + "px";
//}

function IsConfigurable(sysID)
{
    DropDowns.IsSystemConfigurable(sysID, IsConfigDone);
}
function IsConfigDone(arg)
{
    
}

function checkForm(action, numFixtures, sess, systemIDNum)
{
    if (!action || action == "1")
    {
        var sysID = $get('systemID');
        var sysLen = document.aspnetForm.systemID.length;
        var myOption = -1;
        var isError = 0;
        var sysSelected = 1;
        var msg = null;
        
        
        // Check to make sure a system is selected
        for (i = sysLen - 1; i > -1; i--)
        {
            if (document.aspnetForm.systemID[i].checked)
            {
                myOption = i;
                i = -1;
            }
        }
        if (myOption == -1)
        {   
            sysSelected = 0;
            isError = 1;
            msg = "- You must choose a system.";
        }
        // End system selection check
        
        // if system is selected, check the finish
        if (sysSelected == 1)
        {
            var selectedID = null;
        
            for (i = 0; i < sysLen; i++)
            {
                if (document.aspnetForm.systemID[i].checked == true)
                    selectedID = document.aspnetForm.systemID[i].value;
            }
            
            if (selectedID == 1 || selectedID == 2 || selectedID == 3 || selectedID == 4 || selectedID == 5 || selectedID == 16 || selectedID == 17 || selectedID == 28 || selectedID == 18 || selectedID == 19 || selectedID == 20 || selectedID == 24)
            {
                myOption = -1;
                var tmp = 's' + selectedID + '_finishID';
                var finishSelection = $get(tmp);
                var finishLen = eval("document.aspnetForm." + tmp + ".length");
                
                for (i = finishLen - 1; i > -1; i--)
                {
                    if (eval("document.aspnetForm." + tmp + "[" + i + "].checked"))
                    {
                        myOption = i;
                        i = -1;
                    }
                }
                if (myOption == -1)
                {
                    msg = "- You must choose a finish for your system.";
                    isError = 1;
                }
            }
        }
        // end finish selection check
    }
    else if (action == "2")
    {
        // Check to make sure a system is selected
        var xfmrLen;
        var fjCanopyLen;
        var whichStep = 1; // 1 - Configurable System; 2 - FreeJack/FusionJack; 3 - NonConfigurable System
        
        var xmObj = $get('xfmrMountID');
        var canObj = $get('canopyID');
        
        if (document.aspnetForm.xfmrMountID)
        {
            xfmrLen = document.aspnetForm.xfmrMountID.length;
            whichStep = 1;
        }
        else if (document.aspnetForm.canopyID)
        {
            fjCanopyLen = document.aspnetForm.canopyID.length;
            whichStep = 2;
        }
        
        var myOption = -1;
        var isError = 0;
        
        if (whichStep == 1)
        {
            if (xfmrLen && xfmrLen != "undefined")
            {
                for (i = xfmrLen - 1; i > -1; i--)
                {
                    if (document.aspnetForm.xfmrMountID[i].checked)
                    {
                        myOption = i;
                        i = -1;
                    }
                }
                if (myOption == -1)
                {   
                    sysSelected = 0;
                    isError = 1;
                    msg = "- You must choose a transformer.";
                }
            }
            // End system selection check
        }
        else if (whichStep == 2)
        {
            for (i = fjCanopyLen - 1; i > -1; i--)
            {
                if (document.aspnetForm.canopyID[i].checked)
                {
                    myOption = i;
                    i = -1;
                }
            }
            if (myOption == -1)
            {
                sysSelected = 0;
                isError = 1;
                msg = "- You must choose a canopy.";
            }
        }
    }
    else if (action == '3')
    {
        var noCont = $get('noContinue');
        
        if (noCont && sess == "false")
        {
            if (noCont.value == "0")
            {
                msg = "- You must choose either heads or pendants.";
                isError = 1;
            }
        }
        else
        {
            if (numFixtures == "-1")
            {
                CheckFixtures();
                exit;
            }
            if (numFixtures == "0")
            {
                msg = "- No fixtures have been chosen.";
                isError = 1;
            }
            else
            {
                msg = "";
                isError = 0;
            }
        }
    }
    else if (action == '4')
    {
        var sysID = $get('ctl00_ContentPlaceHolder1_lengthID');
        
        if (sysID.selectedIndex == 0)
        {
            isError = 1;
            msg = "- You must choose a drop length.";
        }
    }
    
    var errMsg = $get('errMsg');
    
    if (isError == 1)
    {
        errMsg.innerHTML = msg;
        
        if (systemIDNum)
        {
            var sysMsg = $get('errMsg_' + systemIDNum);
            sysMsg.innerHTML = msg;
        }
    }
    else
    {
        if (action == '3')
        {
            window.location = '03Power.aspx';
        }
        else
        {
            errMsg.innerHTML = "";;
            document.aspnetForm.submit();
        }    
    }
}

function CheckFixtures()
{
    DropDowns.CheckFixtures(null, null, FixturesComplete);
}
function FixturesComplete(arg)
{
    if (!arg)
    {
        checkForm("3", "0");
    }
    else
    {  
        checkForm("3", "1");
    }
}

function doFormPost()
{
    var f = $get('aspnetForm');
    f.submit();
}

/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only thing you need to change in this file is the following
variables: checkboxHeight, radioHeight and selectWidth.

Replace the first two numbers with the height of the checkbox and
radio button. The actual height of both the checkbox and radio
images should be 4 times the height of these two variables. The
selectWidth value should be the width of your select list image.

You may need to adjust your images a bit if there is a slight
vertical movement during the different stages of the button
activation.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

/* No need to change anything after this */

document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; z-index: 5; }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
				document.onmouseup = Custom.clear;
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.choose;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;