var aLinks = new Array();

function AddItem2Cart(oForm)
        {
         /*---------------------------------------------------------------------------------------------------------------*\
         | AddItem2Cart - Add selected item to shopping cart  (Subroutine).                                                |
         |                                                                                                                 |
         | Gather all the form elements associated with the selected item and send them off to the server as a POST type   |
         | request via an AJAX call.  Wait for a response, if the item was successfully added the response text will begin |
         | with "SUCCESS:", followed by the new shopping cart subtotal, which can be pasted onto the page in the dedicated |
         } display area, otherwise we'll get something else.                                                               |
         |                                                                                                                 |
         | Entry Parameters: oForm = form object.                                                                          |
         |                                                                                                                 |
         |          Returns: None.                                                                                         |
         |                                                                                                                 |
         | Globals Affected: None.                                                                                         |
         |                                                                                                                 |
         | Calls - External: createRequest, open, send, WriteDebugMsg.                                                     |
         |                                                                                                                 |
         |         Internal: EncodeFormElements, HideElement, UnhideElement.                                               |
         |                                                                                                                 |
         |          Library: alert, getElementById, getElementByTagName, setTimeout, split, substr.                        |
         \*---------------------------------------------------------------------------------------------------------------*/

         // Prepare form data for sending to server:

         var sPostData = EncodeFormElements(oForm);

         var sUrl      = "/cgi-bin/store/commerce.cgi";
         var sMethod   = "post";
         var oRequest  = zXmlHttp.createRequest();


         // Hide the 'Buy Now' button:

         var sProdId = oForm.id.substr(5);

         var sDivId = "BUTTON_" + sProdId;

         HideElement(sDivId);


         // Show the 'Adding to cart' message:

         sDivId = "MSG_" + sProdId;

         document.getElementById(sDivId).innerHTML = "Adding item to cart . . .";

         UnHideElement(sDivId);


         // Take away the document's ability to be clicked:

         var oOrigClickHandler = document.onclick;

         document.onclick = function ()
                                    {
                                     return(true);
                                    };


         // Create function to receive and process AJAX response:

         oRequest.onreadystatechange = function ()
                                               {
                                                if (4 != oRequest.readyState)
                                                  {
                                                   return;
                                                  }


                                                // AJAX response complete, re- enable clicking:

                                                document.onclick = oOrigClickHandler;

                                                if (200 != oRequest.status)
                                                  {
                                                   alert("Server Error: " + oRequest.statusText);

                                                   return;
                                                  }


                                                // Got a valid response, response text should contain 'SUCCESS:subtotal', get
                                                // and separate them:

                                                var sRspTxt = oRequest.responseText.split(":");

                                                if ("SUCCESS" == sRspTxt[0])
                                                  {
                                                   // Update cart subtotal display:

                                                   document.getElementById('CartSubTot').innerHTML = sRspTxt[1];


                                                   // Display 'added to cart' message, for a while then re-hide it:

                                                   var sProdId = oForm.id.substr(5);

                                                   var sSpanId = "MSG_" + sProdId;

                                                   var sCmdStr = "HideElement('" + sSpanId + "')";

                                                   document.getElementById(sSpanId).innerHTML = "Item added to cart!";


                                                   // Re-show 'Buy Now' button:

                                                   UnHideElement(sSpanId);

                                                   setTimeout(sCmdStr, 1000);

                                                   var sCmdStr2 = "UnHideElement('" + "BUTTON_" + sProdId + "')";

                                                   setTimeout(sCmdStr2, 1000);

                                                   return;
                                                  }

                                                alert("There was a problem with your selection.");
                                               };


         // Try to send request to the server:

         try {
              oRequest.open(sMethod, sUrl, true);
             }

         catch (oError)
              {
               alert("xZmlHttp.open error (URL: " + sUrl + ")");

               document.onclick = oOrigClickHandler;
              }


         try {
              oRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
             }

         catch (oError)
              {
               alert("xZmlHttp.srq error (URL: " + sUrl + ")");

               document.onclick = oOrigClickHandler;
              }


         try {
              oRequest.send(sPostData);
             }

         catch (oError)
              {
               alert("xZmlHttp.send error (URL: " + sUrl + ")");

               document.onclick = oOrigClickHandler;
              }


         return(true);
        }

function ChkCartForm()
        {
         var bOK2DispApplyButton = false;

         var oForm = document.forms[0];

         for (var i=0; i<oForm.elements.length; ++i)
            {
             // Ignore disabled fields, buttons, images and submits:

             if ("text" == oForm.elements[i].type)
               {
                if ("EditQuan" == oForm.elements[i].id.substring(0, 8))
                  {
                   if ("" != oForm.elements[i].value)
                     {
                      bOK2DispApplyButton = true;

                      break;
                     }
                  }
               }
            }

         if (true == bOK2DispApplyButton)
           {
            UnHideElement('ApplyChangesDiv');
           }
          else
              {
               HideElement('ApplyChangesDiv');
              }

       }

function ClrQuan(sElementId)
        {
         var sDelId      = "Del"      + sElementId;
         var sEditQuanId = "EditQuan" + sElementId;

         if (true == document.getElementById(sDelId).checked)
           {
            document.getElementById(sEditQuanId).value    = 0;
            document.getElementById(sEditQuanId).readOnly = true;
           }
          else
              {
               document.getElementById(sEditQuanId).value    = "";
               document.getElementById(sEditQuanId).readOnly = false;
              }

         ChkCartForm();

        }

function DisableElement(sElementId)
        {
         document.getElementById(sElementId).disabled = true;
        }

function DispPage(sPage)
        {
         document.getElementById('Page2Disp').value = sPage;

         document.getElementById('cart').submit();

         return(false);
        }

function EnableApplyButton(sElementId)
        {
         sElementId = "EditQuan" + sElementId;

         var sValue = document.getElementById(sElementId).value;

         if ("" != sValue)
           {
            if (true != ValidateField("vNumeric", sValue))
              {
               ForceFocus(sElementId);

               HideElement('ApplyChangesDiv');
              }
             else
                 {
                  ChkCartForm();
                 }
          }

        }

function EnableElement(sElementId)
        {

         document.getElementById(sElementId).disabled = false;

        }

function EncodeFormElement(oElement)
        {
         var sRV = encodeURIComponent(oElement.name);

         if ("" != oElement.value)
           {
            sRV += "=" + encodeURIComponent(oElement.value);
           }

         return(sRV);
        }

function EncodeFormElements(oForm)
        {

         var aEncodedElements = new Array();

         for (var iElementNdx=0; iElementNdx<oForm.elements.length; ++iElementNdx)
            {
             var oElement = oForm.elements[iElementNdx];

             switch (oElement.type)
                   {
                    case "button":
                    case "reset":
                    case "submit":
                        {
                         // No-op.
                        }
                        break;

                    case "checkbox":
                    case "radio":
                        {
                         if (true == oElement.cheched)
                           {
                            aEncodedElements.push(EncodeFormElement(oElement));
                           }
                        }
                        break;

                    default:
                            {
                             aEncodedElements.push(EncodeFormElement(oElement));
                            }
                            break;
                   }
            }

         var sRV = aEncodedElements.join("&");

         return(sRV);
        }

function ForceFocus(sElementId)
        {
         var sCmdStr = "document.getElementById('" + sElementId + "').focus()";

         setTimeout(sCmdStr, 10);
        }

function getDocumentHeight()
        {
         var iHeight = 0;

         if ('number' == typeof(window.innerHeight))
           {
            // Non-IE

            iHeight = window.innerHeight;
           }
          else if (document.documentElement && document.documentElement.clientHeight)
                 {
                  // IE 6+ in 'standards compliant mode'

                  iHeight = document.documentElement.clientHeight;
                 }
                else if (document.body && document.body.clientHeight)
                    {
                     // IE 4 compatible

                     iHeight = document.body.clientHeight;
                    }

         return(iHeight);
        }

function getDocumentWidth()
        {
         var iWidth = 0;

         if ('number' == typeof(window.innerWidth))
           {
            // Non-IE

            iWidth = window.innerWidth;
           }
          else if (document.documentElement && document.documentElement.clientWidth)
                 {
                  // IE 6+ in 'standards compliant mode'

                  iWidth = document.documentElement.clientWidth;
                 }
                else if (document.body && document.body.clientWidth)
                       {
                        // IE 4 compatible

                        iWidth = document.body.clientWidth;
                       }

         return(iWidth);
        }


function GetLinkCoords(sLinkId)
        {

         if (document.getElementById)
           {
            var anchor = document.getElementById(sLinkId);

            var coords = {x: 0, y: 0};

            while (anchor)
                 {
                  coords.x += anchor.offsetLeft;
                  coords.y += anchor.offsetTop;

                  anchor = anchor.offsetParent;
                 }

            return(coords);
           }
        }



function getScrollX()
        {
         var iScrollX = 0;

         if (window.pageXOffset)
           {
            iScrollX = window.pageXOffset;
           }
          else if (document.documentElement && document.documentElement.scrollLeft)
                 {
                  iScrollX = document.documentElement.scrollLeft;
                 }
                else if (document.body && document.body.scrollLeft)
                       {
                        iScrollX = document.body.scrollLeft;
                       }

         return(iScrollX);
        }

function getScrollY()
        {
         var iScrollY = 0;

         if (window.pageYOffset)
           {
            iScrollY = window.pageYOffset;
           }
          else if (document.documentElement && document.documentElement.scrollTop)
                 {
                  iScrollY = document.documentElement.scrollTop;
                 }
                else if (document.body && document.body.scrollTop)
                       {
                        iScrollY = document.body.scrollTop;
                       }

         return(iScrollY);
        }

function GotoStore(sProduct, sDispCat)
        {
         document.getElementById('product').value = sProduct;
         document.getElementById('DispCat').value = sDispCat;

         document.getElementById('cart').action = "/cgi-bin/store/commerce.cgi"

         document.getElementById('cart').submit();

         return(false);
        }

function HideElement(sElementId)
        {
         document.getElementById(sElementId).style.visibility = "hidden";
         document.getElementById(sElementId).style.display    = "none";
        }

function ImageInfo(sImgSrc)
        {
         /*--------------------------------------------------------------------*\
         | ImageInfo - Create an instance of a ImageInfo object  (Constructor). |
         |                                                                      |
         | Entry Parameters: ImgSrc = URL of image source.                      |
         |                                                                      |
         |          Returns: Instance of a ImageInfo object.                    |
         |                                                                      |
         | Globals Affected: None.                                              |
         |                                                                      |
         | Calls - External: None.                                              |
         |                                                                      |
         |         Internal: None.                                              |
         |                                                                      |
         |          Library: None.                                              |
         \*--------------------------------------------------------------------*/

         this.oImg = new Image();

         this.oImg.src = sImgSrc;
        }


function InitCartLink(sCartID)
        {
         document.getElementById('CartSubTotLink').href = "/cgi-bin/store/commerce.cgi"
                                                        + "?action=DispCart"
                                                        + "&cart_id="
                                                        +  document.getElementById('CartID').value;

         var sUrl     = "/cgi-bin/store/commerce.cgi?action=GetCartSubTotal&cart_id=" + sCartID;
         var sMethod  = "get";
         var oRequest = zXmlHttp.createRequest();


         // Take away the document's ability to be clicked:

         var oOrigClickHandler = document.onclick;

         document.onclick = function ()
                                    {
                                     return(true);
                                    };

         oRequest.onreadystatechange = function ()
                                               {
                                                if (4 == oRequest.readyState)
                                                  {
                                                   document.onclick = oOrigClickHandler;

                                                   if (200 == oRequest.status)
                                                     {
                                                      document.getElementById('CartSubTot').innerHTML = oRequest.responseText;
                                                     }
                                                    else
                                                        {
                                                         alert("Server Error: " + oRequest.statusText);
                                                        }
                                                  }
                                               };

         try {

              oRequest.open(sMethod, sUrl, true);
             }

         catch (oError)
              {
               alert("xZmlHttp.open error (URL: " + sUrl + ")");

               document.onclick = oOrigClickHandler;
              }


         try {
              oRequest.send(null);
             }

         catch (oError)
              {
               alert("xZmlHttp.send error (URL: " + sUrl + ")");

               document.onclick = oOrigClickHandler;
              }

         return(false);
        }


function InitBackLinks(aBackLinks)
        {
         /*----------------------------------------------------------*\
         | InitLinks - Initialize page links  (Subroutine).           |
         |                                                            |
         | Entry Parameters: BackLinks = array of LinkInfo object(s). |
         |                                                            |
         |          Returns: None.                                    |
         |                                                            |
         | Globals Affected: None.                                    |
         |                                                            |
         | Calls - External: WriteDebugMsg.                           |
         |                                                            |
         |         Internal: InitCartLink.                            |
         |                                                            |
         |          Library: encodeURICompinent, getElementById.      |
         \*----------------------------------------------------------*/

         var sLink = "";

         for (iLinkNdx=0; iLinkNdx<aBackLinks.length; ++iLinkNdx)
            {

            if (iLinkNdx == aBackLinks.length - 1)
			 	{
					sLink += '<a class="backlinklast" href=\"' + aBackLinks[iLinkNdx].sLinkURL + '\">' + aBackLinks[iLinkNdx].sLinkId + '</a>';
				}
			else
				{
             		sLink += '<a class="backlink" href=\"' + aBackLinks[iLinkNdx].sLinkURL + '\">' + aBackLinks[iLinkNdx].sLinkId + '</a>';
				}

             if (aBackLinks.length > 0 && iLinkNdx != aBackLinks.length - 1)
               {
                sLink += "&#8594;";
               }
            }

         if ("undefined" != typeof(document.getElementById('BackLink')))
           {
            document.getElementById('BackLink').innerHTML = sLink;
           }
        }

function InitLegacyLinks(aLinks)
        {
         /*------------------------------------------------------*\
         | InitLegacyLinks - Initialize page links  (Subroutine). |
         |                                                        |
         | Entry Parameters: Links = array of LinkInfo object(s). |
         |                                                        |
         |          Returns: None.                                |
         |                                                        |
         | Globals Affected: None.                                |
         |                                                        |
         | Calls - External: WriteDebugMsg.                       |
         |                                                        |
         |         Internal: InitCartLink.                        |
         |                                                        |
         |          Library: encodeURICompinent, getElementById.  |
         \*------------------------------------------------------*/

         for (iLinkNdx=0; iLinkNdx<aLinks.length; ++iLinkNdx)
            {

             var sLink = aLinks[iLinkNdx].sLinkURL;

             document.getElementById(aLinks[iLinkNdx].sLinkId).href = sLink;
            }

         InitCartLink(document.getElementById('CartID').value);
        }


function InitLinks(aLinks)
        {
         /*------------------------------------------------------*\
         | InitLinks - Initialize page links  (Subroutine).       |
         |                                                        |
         | Entry Parameters: Links = array of LinkInfo object(s). |
         |                                                        |
         |          Returns: None.                                |
         |                                                        |
         | Globals Affected: None.                                |
         |                                                        |
         | Calls - External: WriteDebugMsg.                       |
         |                                                        |
         |         Internal: InitCartLink.                        |
         |                                                        |
         |          Library: encodeURICompinent, getElementById.  |
         \*------------------------------------------------------*/

         for (iLinkNdx=0; iLinkNdx<aLinks.length; ++iLinkNdx)
            {

             var sLink = ""
                       + (aLinks[iLinkNdx].sLinkURL);

             document.getElementById(aLinks[iLinkNdx].sLinkId).href = sLink;
            }

//         InitCartLink(document.getElementById('CartID').value);

        }


function InitProdForm(aLinks)
        {
         /*---------------------------------------------------------------------------------------*\
         | InitProdForm - Initialize product form  (Subroutine).                                   |
         |                                                                                         |
         | Entry Parameters: Links = array of LinkInfo object(s).                                  |
         |                                                                                         |
         |          Returns: None.                                                                 |
         |                                                                                         |
         | Globals Affected: None.                                                                 |
         |                                                                                         |
         | Calls - External: appendChild, createElement, createRequest, open, send, WriteDebugMsg. |
         |                                                                                         |
         |         Internal: InitLinks.                                                            |
         |                                                                                         |
         |          Library: getElementById, getElementByTagName.                                  |
         \*---------------------------------------------------------------------------------------*/

         if (!document.getElementById('CartID'))
           {

            // Get a shopping Cart:

            var sUrl     = "/cgi-bin/store/getcartid.cgi"
            var sMethod  = "get";
            var oRequest = zXmlHttp.createRequest();


            // Take away the document's ability to be clicked:

            var oOrigClickHandler = document.onclick;

            document.onclick = function ()
                                       {
                                        return(true);
                                       };

            oRequest.onreadystatechange = function ()
                                                  {
                                                   if (4 != oRequest.readyState)
                                                     {
                                                      return;
                                                     }

                                                   document.onclick = oOrigClickHandler;

                                                   if (200 != oRequest.status)
                                                     {
                                                      alert("Server Error: " + oRequest.statusText);

                                                      return;
                                                     }


                                                   var sCartId = oRequest.responseText;

                                                   var oForm = document.createElement('form');

                                                   oForm.action = '/index.cgi';
                                                   oForm.id     = 'CartForm';
                                                   oForm.method = 'post';
                                                   oForm.name   = 'cart';

                                                   document.getElementsByTagName("body")[0].appendChild(oForm);


                                                   var oInput = document.createElement('input');

                                                   oInput.id    = 'CartID';
                                                   oInput.name  = 'cart_id';
                                                   oInput.type  = 'hidden';
                                                   oInput.value = sCartId;

                                                   oForm.appendChild(oInput);


                                                   oInput = document.createElement('input');

                                                   oInput.id    = 'action';
                                                   oInput.name  = 'action';
                                                   oInput.type  = 'hidden';
                                                   oInput.value = 'DispPage';

                                                   oForm.appendChild(oInput);


                                                   oInput = document.createElement('input');

                                                   oInput.id    = 'Page2Disp';
                                                   oInput.name  = 'Page2Disp';
                                                   oInput.type  = 'hidden';
                                                   oInput.value = '/led_prods.html';

                                                   oForm.appendChild(oInput);


                                                   oInput = document.createElement('input');

                                                   oInput.id    = 'product';
                                                   oInput.name  = 'product';
                                                   oInput.type  = 'hidden';
                                                   oInput.value = '/led_prods.html';

                                                   oForm.appendChild(oInput);


                                                   oInput = document.createElement('input');

                                                   oInput.id    = 'DispCat';
                                                   oInput.name  = 'DispCat';
                                                   oInput.type  = 'hidden';
                                                   oInput.value = 'all';

                                                   oForm.appendChild(oInput);

                                                   InitLinks(aLinks);
                                                  };

            try {
                 oRequest.open(sMethod, sUrl, true);
                }

            catch (oError)
                 {
                  alert("xZmlHttp.open error (URL: " + sUrl + ")");

                  document.onclick = oOrigClickHandler;
                 }


            try {
                 oRequest.send(null);
                }

            catch (oError)
                 {
                  alert("xZmlHttp.send error (URL: " + sUrl + ")");

                  document.onclick = oOrigClickHandler;
                 }

           }
          else
              {
               InitLinks(aLinks);
              }
         }




function IsFileName(sString)
        {
         if (0 == sString.length)
           {
            return(false);
           }

         for (var i=0; i<sString.length; ++i)
            {
             if (-1 == ("_-0123456789abcdefghijklmnopqrstuvwxyz").indexOf(sString.charAt(i).toLowerCase()))
               {
                return(false);
               }
            }

         return(true);
        }

function IsNumeric(sString)
        {
         if (0 == sString.length)
           {
            return(false);
           }

         for (var i=0; i<sString.length; ++i)
            {
             if (-1 == ("0123456789").indexOf(sString.charAt(i)))
               {
                return(false);
               }
            }

         return(true);
        }

function LinkInfo(sLinkId, sLinkURL)
        {
         /*------------------------------------------------------------------*\
         | LinkInfo - Create an instance of a LinkInfo object  (Constructor). |
         |                                                                    |
         | Entry Parameters: LinkID  = Link ID.                               |
         |                   LinkURL = URL to page.                           |
         |                                                                    |
         |          Returns: Instance of a LinkInfo object.                   |
         |                                                                    |
         | Globals Affected: None.                                            |
         |                                                                    |
         | Calls - External: None.                                            |
         |                                                                    |
         |         Internal: None.                                            |
         |                                                                    |
         |          Library: None.                                            |
         \*------------------------------------------------------------------*/

         this.sLinkId  = sLinkId;
         this.sLinkURL = sLinkURL;
        }

function RUSure(sPhrase)
        {
         if (confirm(sPhrase))
           {
            return(true);
           }
         return(false);
        }

function ScrollWindow(coords, iOffset)
        {
         window.scrollTo(0, coords.y - iOffset);
        }


function ShowA2C(sBgColor, sBorderColor, sProduct, sDispCat, sCartID, sWidth, sHeight, sPage)
        {
         /*---------------------------------------------------------------------------------------------------------*\
         | ShowA2C - Show 'Add to Cart' popover  (Subroutine).                                                       |
         |                                                                                                           |
         | Display popover containing products for purchase according to the Product and Display categories provided |
         | by the caller, along with buttons pertaining thereto, using either a default or caller supplied template  |
         | file (name) to dynamically generate the content display.                                                  |
         |                                                                                                           |
         | The popover is populated using AJAX methods.                                                              |
         |                                                                                                           |
         | Entry Parameters: sBgColor      = Background color, #rrggbb | default                            REQUIRED |
         |                   sBorderColor  = Border color,     #rrggbb | default                            REQUIRED |
         |                   sProduct      = Product category name string.                                  REQUIRED |
         |                   sDispCat      = Display category string.                                       REQUIRED |
         |                   sCartID       = Cart ID string (use document.getElementById('CartID').value).  REQUIRED |
         |                   sWidth        = Popover width  (pixels).                                       OPTIONAL |
         |                   sHeight       = Popover height (pixels).                                       OPTIONAL |
         |                   sTemplateFile = Name of template file (productPage.inc if omitted).            OPTIONAL |
         |                                   Width and height required in order to specify sTemplateFile.            |
         |                                                                                                           |
         |          Returns: false (always, to prevent triggering following a link when attached to an onclick       |
         |                          handler in an <a> tag).                                                          |
         | Globals Affected: None.                                                                                   |
         |                                                                                                           |
         | Calls - External: createRequest, hide, open, send, setContent, show, Vignette, WriteDebugMsg.             |
         |                                                                                                           |
         |         Internal: None.                                                                                   |
         |                                                                                                           |
         |          Library: alert, getScrollX, getScrollY, parseInt, typeof.                                        |
         \*---------------------------------------------------------------------------------------------------------*/
		 var productPage = location.href;
		 setCookie('productpage', '', -1);
		 setCookie('productpage', productPage, 1);
		 
		 var url = "/cgi-bin/store/commerce.cgi?product=" + sProduct;
		 
		 if (sDispCat.indexOf(" ") != -1) 
		 	{
		 		var pAnchor = "#" + sDispCat.substr(0, sDispCat.indexOf(" "));
			}
		 else 
		 	{
				var pAnchor =  "#" + sDispCat;
			}
		 sCartID=getCookie('cart');
		 if (sCartID != 0 && sCartID != "" && sCartID != "null")
		 	{
				url = url + "&cart_id=" + sCartID;
			}
		 if (sPage == "gtnp")
		 	{
				url = url + "&next=50" + pAnchor;
			}
		 else
		 	{
				url = url + pAnchor;
			}
		 window.location.href=url;

         return(false);
        }

function ValidateField(sType, sValue)
        {
         var  bRetVal = true;

         switch (sType)
               {
                case "vFName":
                    {
                     if (false == IsFileName(sValue))
                       {
                        alert("File names may contain only 'A=Z', 'a-z', '0-9', '_' and/or '-'");

                        bRetVal = false;
                       }
                    }
                    break;

                case "vNumeric":
                    {
                     if (false == IsNumeric(sValue))
                       {
                        alert("Value must be a number.");

                        bRetVal = false;
                       }
                    }
                    break;

                default:
                        {
                        }
               }

         return(bRetVal);
        }

function ThumbnailSelect(sImageName, sImageUrl, sParentNode, sSpanId, sDispCat, sHOffset, sVOffset, sShow)
        {
         /*-----------------------------------------------------------------------------------------------------------------*\
         | ThumbnailSelect - Perform action when thumbnail image selected  (Subroutine).                                     |
         |                                                                                                                   |
         | When a thumbnail image is clicked, toggle the display of an image identified by a name passed by the caller. At   |
         | the same time, change the target URL of the <a> link which contains the thumbnail, change the global display      |
         | category to change the behavior of the button contained within a <span> element identified by its ID passed by    |
         | the caller. The caller also passes the relative offsets of the button to position it within the containing <div>. |
         | The caller may toggle the button display on or off by passing a hide|show flag.                                   |
         |                                                                                                                   |
         |                                                                                                                   |
         | Entry Parameters: sImageName  = String containing name of image tag.                                              |
         |                   sImageUrl   = String containing URL of image to be displayed.                                   |
         |                   sParentNode = String containing the parent node.                                                |
         |                   sSpanId     = String containing ID of span tag where button resides                             |
         |                   sDispCat    = String containing list of Display Categories.                                     |
         |                   sHOffset    = String containing horizontal offset for button.                                   |
         |                   sVOffset    = String containing vertical offset for button.                                     |
         |                   sShow       = String containing either "hide" or "show" to conditionally display the button.    |
         |                                                                                                                   |
         |          Returns: None.                                                                                           |
         |                                                                                                                   |
         | Globals Affected: None.                                                                                           |
         |                                                                                                                   |
         | Calls - External: WriteDebugMsg.                                                                                  |
         |                                                                                                                   |
         |         Internal: HideElement, UnHideElement.                                                                     |
         |                                                                                                                   |
         |          Library: getElementById.                                                                                 |
         \*-----------------------------------------------------------------------------------------------------------------*/

         document.images[sImageName].src             = sImageUrl;
         document.images[sImageName].parentNode.href = sParentNode;

         if ("show" != sShow)
           {
            HideElement(sSpanId);

            return;
           }

         document.getElementById(sSpanId).style.left = sHOffset + "px";
         document.getElementById(sSpanId).style.top  = sVOffset + "px";

         document.getElementById('DispCat').value = sDispCat;

         UnHideElement(sSpanId);

        }

function UnHideElement(sElementId)
        {
         document.getElementById(sElementId).style.visibility = "visible";
         document.getElementById(sElementId).style.display    = "block";
        }
function ThumbnailSelect2(sImageName, sImageUrl, sMoreInfoID, sMoreInfoUrl, sSpanId, sDispCat, sIsDefault, sPage)
        {
         /*----------------------------------------------------------------------------------------------------------------*\
         | ThumbnailSelect - Perform action when thumbnail image selected  (Subroutine).                                    |
         |                                                                                                                  |
         | When a thumbnail image is clicked, toggle the display of an image identified by a name passed by the caller. At  |
         | the same time, change the taerget URL of the <a> link which contains the thumbnail, change the global display    |
         | category to change the behavior of the button contained within a <span> element identified by its ID passed by   |
         | the caller. The caller also passes the relative offsets of the button to psition it within the containing <div>. |
         | The caller may toggle the button display on or off by passing a hide|show flag.                                  |
         |                                                                                                                  |
         |                                                                                                                  |
         | Entry Parameters: sImageName  = String containing name of image tag.                                             |
         |                   sImageUrl   = String containing URL of image to be displayed.                                  |
         |                   sParentNode = String containing the parent node.                                               |
         |                   sSpanId     = String containing ID of span tag where button resides                            |
         |                   sDispCat    = String containing list of Display Categories.                                    |
         |                   sHOffset    = String containing horizontal offset for button.                                  |
         |                   sVOffset    = String containing vertical offset for button.                                    |
         |                   sShow       = String containing either "hide" or "show" to conditionally display the button.   |
         |                                                                                                                  |
         |          Returns: None.                                                                                          |
         |                                                                                                                  |
         | Globals Affected: None.                                                                                          |
         |                                                                                                                  |
         | Calls - External: WriteDebugMsg.                                                                                 |
         |                                                                                                                  |
         |         Internal: HideElement, UnHideElement.                                                                    |
         |                                                                                                                  |
         |          Library: getElementById.                                                                                |
         \*----------------------------------------------------------------------------------------------------------------*/

         document.images[sImageName].src             = sImageUrl;
         document.getElementById(sMoreInfoID).href = sMoreInfoUrl;

         /*if ("show" != sShow)
           {
            HideElement(sSpanId);

            return;
           }

         /*document.getElementById(sSpanId).style.left = sHOffset + "px";
         document.getElementById(sSpanId).style.top  = sVOffset + "px";*/

         document.getElementById('DispCat').value = sDispCat;
		 document.getElementById('Page').value = sPage;

         UnHideElement2(sSpanId, sIsDefault);
        }

function UnHideElement2(sElementId, sDefault)
        {
                 if (sDefault == "yes")
                 {
                 document.getElementById(sElementId).style.visibility = "hidden";
         document.getElementById(sElementId).style.display    = "none";
                 document.getElementById(sElementId).previousSibling.style.display="block";
                 document.getElementById(sElementId).previousSibling.style.visibility="visible";
                 }
                 else
                 {
         document.getElementById(sElementId).style.visibility = "visible";
         document.getElementById(sElementId).style.display    = "block";
                 document.getElementById(sElementId).previousSibling.style.display="none";
                 document.getElementById(sElementId).previousSibling.style.visibility="hidden";
                 }

       }
function getCookie(c_cart)
	{
		if (document.cookie.length>0)
  			{
  				c_start=document.cookie.indexOf(c_cart + "=");
  				if (c_start!=-1)
    				{ 
    					c_start=c_start + c_cart.length+1; 
    					c_end=document.cookie.indexOf(";",c_start);
    					if (c_end==-1) c_end=document.cookie.length;
    					return unescape(document.cookie.substring(c_start,c_end));
    				} 
  			}
		return 0;
	}
function checkCookie(cart)
	{
		cart=getCookie('cart');
		if (cart!=null && cart!="")
  			{
  				return cart;
  			}
		else
			return 0;
	}
function setCookie(c_cart,value,expiredays)
	{
		var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_cart+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
