// JavaScript Document

/*********************************************************************************************************************

 * CONTENT-SPECIFIC FUNCTIONS                       																 *

 *********************************************************************************************************************/

 

     /* Custom Drop Down List */

     function selectOption(selectedText, selectedValue){

     

        var selectedTextSpan;

        var selectedValueSpan;

        

        selectedTextSpan = document.getElementById('selectedOption');

        selectedValueSpan = document.getElementById('selectedValue');

        

        if (selectedTextSpan){

            selectedTextSpan.innerHTML = selectedText;

        }

        if (selectedValueSpan){

            selectedValueSpan.value = selectedValue;

        }

        

        changeClass('optionList','off');

    }

    function redirect(){

        var selectedValueSpan;

        var url;

        selectedValueSpan = document.getElementById('selectedValue');

        url = selectedValueSpan.value;

        if (url == ''){

            alert('Please choose a site');

        }

        else {

            window.location = url;

        }

    }

 

    /* Open popup */

    function popup(){

        // Open the window

        newPopup = window.open('Popup.htm','popupWindow','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=624,height=767');

        return false;

    }

    function openPopup(){

        // Open the window

        newPopup = window.open('/shared/templates/modules/productpopup.htm','popupWindow','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=500');

        //alert('hello');

    }

    

    /* This wires up the popup windows */

    /* I found this sillliness at: http://www.accessify.com/features/tutorials/the-perfect-popup/ */

    window.onload = function() {

        // check to see that the browser supports the getElementsByTagName method	

        // if not, exit the loop 	

        if (!document.getElementsByTagName){

            return false;

        }

        // create an array of objects of each link in the document 	

        var popuplinks = document.getElementsByTagName("a");	

        // loop through each of these links (anchor tags) 		

        for (var i=0; i < popuplinks.length; i++){			

            // if the link has a rel of "popup"...			

            if (popuplinks[i].rel.indexOf("popup")!=-1){



                // add an onclick event on the fly to pass the href attribute				

                // of the link to our second function, openPopUp 				

                popuplinks[i].onclick = function() {				

                    openPopup('/shared/templates/modules/productpopup.htm');				

                    return false;

                }

            }

        }

    } 



    /* Change the selected product detail tab */

	function selectProductTab(elementId){

	    

	    var i=0;

	    var maxlen=220;

	    var ArrTab=new Array(maxlen)



	    for (i=0;i<maxlen; i++) 

	    {

			ArrTab[i]=new Array(3);

		}

		

		var str;

		//Define all the tab names here

		ArrTab[0][0] = "rates";			

	    

	    for (i=0; i<ArrTab.length; i++) 

	    {	    

			// CSS class Name with "Tab"

			ArrTab[i][1] = ArrTab[i][0] + "Tab";



			// Get Element

			ArrTab[i][2] = document.getElementById(ArrTab[i][1]);



			//Reset all the tabs

			if (ArrTab[i][2]) 

			{ 				

				// Handle the class and mouseouts

				if (elementId == ArrTab[i][0]) 

				{ 					

				    ArrTab[i][2].className = 'selected';					

					ArrTab[i][2].onmouseout = function(){this.className = 'selected';} ;					

					

					// Show the selected body

					changeClass(elementId,'selected');

				}

				else

				{	

				    ArrTab[i][2].className = '';

				    ArrTab[i][2].onmouseout = function(){this.className = '';} ;

				    

					// Hide all the bodies

					changeClass(ArrTab[i][0], '');					

				}

			}			

		}

	}

	/* Hover a product detail tab */

	function mouseOverProductTab(elementId){

        // Get a reference to the element

        element = document.getElementById(elementId);

        // Make sure it is not selected already

        if (element.className != 'selected'){

			// Hover the list item

			element.className = 'hover';

		}

	}



    /* The advanced search options */

    function toggleSearch(){

        // Toggle the advanced search menu off/on

        toggleClass('advancedSearch', 'off', 'on');



    }

    function toggleSearchMaskLogin(){

        // Mask the windowed select object (IE6)

        toggleClass('loginSelect', 'unmasked', 'masked');

        // Toggle the advanced search menu off/on

        toggleSearch();



    }

    

    /* The Open/Close link  */

    function toggleLogin(){

        // Toggle the icon next to the Open/Close link

        toggleClass('toggleLogin','down','up');

        // Toggle the link text Open/Close

        toggleText('toggleLogin','Open','Close');

        // Toggle the secure login area

        toggleClass('frmLogin','on','off');

    }



    /* The Open/Close link in the Secure Login Module */

    function toggleSecureLogin(isEnglish){

        // Toggle the icon next to the Open/Close link

        toggleClass('toggleLogin','down','up');

        // Toggle the link text Open/Close

        if (isEnglish)

        {

            toggleText('toggleLogin','Open','Close');

        }

        else

        {

            toggleText('toggleLogin','',''); // TODO:

        }

        // Toggle the secure login area

        toggleClass('frmLogin','on','off');

    }



    function selectOption(linkName, linkUrl){

        window.location = linkUrl;

    }    

    

    /* Hide an element and fill the space it took up */

    function hide(elementId){

        changeClass(elementId, 'off');



    }

    function show(elementId){

        changeClass(elementId, 'on');



    }

    

    /* Hide an element and preserve the space it took up */

    function mask(elementId){

        changeClass(elementId, 'masked');



    }

    function unmask(elementId){

        changeClass(elementId, 'unmasked');



    }

    

    /* Foo */

    function select(elementId){

        changeClass(elementId, 'selected');

    }

    function deselect(elementId){

        changeClass(elementId, '');

    }



/*********************************************************************************************************************

 * UTILITY FUNCTIONS    																							 *

 *********************************************************************************************************************/

 

    /***********************************************************************

     * toggleText           											   *

     ***********************************************************************

     * Switches the innerHTML value of an element between off and on       *

     * Parameters:          											   *

     *   - elementId: The id of the element to switch                      *

     *   - offText: The text for the off state                             *

     *   - onText: The text for the on state                               *

     * Results:             											   *

     *   - If the element was on, it will be off                           *

     *   - If the element was off, it will be on                           *

     ***********************************************************************/

    function toggleText(elementId, offText, onText){

        // Get a reference to the element

        element = document.getElementById(elementId);

        // Make sure the element was on the page

        if (element) {

			// If the element's text is "On"

			if(element.innerHTML == offText){

			    // Turn it "Off"

			    element.innerHTML = onText;

			}

			// If the element's text is "Off"

			else if(element.innerHTML  == onText){

			    // Turn it "On"

			    element.innerHTML = offText;

			}

		}

    }

    

    /***********************************************************************

     * toggleClass          											   *

     ***********************************************************************

     * Switches the className value of an element between off and on       *

     * Parameters:          											   *

     *   - elementId: The id of the element to switch                      *

     *   - offClassName: The class for the off state                       *

     *   - onClassName: The class for the on state                         *

     * Results:             											   *

     *   - If the element was on, it will be off                           *

     *   - If the element was off, it will be on                           *

     ***********************************************************************/

    function toggleClass(elementId, offClassName, onClassName){

        // Get a reference to the element

        element = document.getElementById(elementId);

        // Make sure the element was on the page

        if (element) {

			// If the element's class is "Off"

			if(element.className == offClassName){

			    // Turn it "On"

			    element.className = onClassName;

			}

			// If the element's class is "On"

			else if(element.className == onClassName){

			    // Turn it "Off"

			    element.className = offClassName;

			}

		}

    }

    

    /***********************************************************************

     * changeClass          											   *

     ***********************************************************************

     * Switches the className value of an element                          *

     * Parameters:          											   *

     *   - elementId: The id of the element to switch                      *

     *   - className: The class to set the element to                      *

     * Results:             											   *

     *   - The element will be set to the given class                      *

     ***********************************************************************/

    function changeClass(elementId, className){

        // Get a reference to the element

        element = document.getElementById(elementId);

        // Make sure the element was on the page

        if (element) {

			// Update the element's className property

			element.className = className;

        }

    }

    

    function changeText(elementId, text){

        // Get a reference to the element

        element = document.getElementById(elementId);

        // Make sure the element was found

        if (element) {

			// Update the element's className property

			element.innerHTML = text;

        }

    }

    

    function changeImage(elementId, img) {

        // Get a reference to the element

        element = document.getElementById(elementId)

        // Make sure the element was found

        if (element) {

            // Update the element's path

            element.src = img

        }

    }

    function newImage(arg) {

	    if (document.images) {

		    rslt = new Image();

		    rslt.src = arg;

		    return rslt;

	    }

    }
