﻿//--------------------------------------------------------------------------------------------------------
//SDR Redesign Specific Scripts --------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------

    var divT = -100;
    var divH = 265;
    var toggleScroll = 'down';

    //defaultTab = 'shoppingtab';
    defaultTab = "tab0";
    nowScrolling = false;	
    setID = "";
    executeCheckID = "";
    firstFocus = true;
    interval = 30;
    direction = "right";
    imagePositions = new Array(-235, -90, 55, 200, 345, 490, 635, 780, 925);
    
    var merchLinks = new Array()
    var merchImages = new Array()
    var merchRebates = new Array()

    function GetUserTime()
    {
        var fullDate = new Date();
        var thisDate = fullDate.getDate();
        var thisMonth = fullDate.getMonth();
        
        thisMonth++;
        
        var thisYear = fullDate.getFullYear();
        var thisHour = fullDate.getHours();
        var thisMinute = fullDate.getMinutes();
        
        var AMorPM = "AM";
        
        if (thisHour > 11)
            AMorPM = "PM";
            
        if(thisHour > 12)
            thisHour -= 12;
            
        if(thisHour == 0)
            thisHour = 12;
            
        if(thisMinute < 10)
            thisMinute = "0" + thisMinute;
            
        document.write(thisMonth + "/" + thisDate + "/" + thisYear + " ");
        document.write(thisHour + ":" + thisMinute + " " + AMorPM);
    }
         
    function ClearSearch(thisElement)
    {
        if(firstFocus)
            thisElement.value = "";
    
        firstFocus = false;
    }
    
    function SetUpPassword()
    {
        document.getElementById("PasswordDiv").innerHTML = '<input type="password" id="password" name="password" value="" maxlength="50" style="width: 140px; color: #454545;" />';
        setTimeout('document.getElementById("PasswordDiv").firstChild.focus()', 1); 
    }

    function StartScroll(thisDirection)
    {
        if(!nowScrolling)
        {
            setPosition = "";
            executeCheckPosition = "";
    
            for(i = 0; i <= 8; i++)
            {
                if(thisDirection == "right")
                {
                    setPosition += "imagePositions[" + i + "] += 1;";
                    executeCheckPosition += "if(imagePositions[" + i + "] > 1070) SeedNext('" + i + "', 'right');";
                }
                else
                {
                    setPosition += "imagePositions[" + i + "] -= 1;";
                    executeCheckPosition += "if(imagePositions[" + i + "] < -380) SeedNext('" + i + "', 'left');";
                }
                executeCheckPosition += "document.getElementById('image" + i + "').style.left = imagePositions[" + i + "] + 'px';";
            }

            setID = window.setInterval(setPosition, interval * 2);
            executeCheckID = window.setInterval(executeCheckPosition, interval); 
            nowScrolling = true;
        }
    }

    function StopScroll()
    {
        window.clearInterval(setID);
        window.clearInterval(executeCheckID);
        nowScrolling = false;
    }
    
    function SeedNext(thisID, thisDirection)
    {
        topImage = imageHTML.pop();
        document.getElementById("image" + thisID).innerHTML = topImage;
        imageHTML.unshift(topImage);
        
        if(thisDirection == "right")
            imagePositions[thisID] = -235;
        else
            imagePositions[thisID] = 925;
    }
    
    function SwitchDirection(thisDirection)
    {
        if(thisDirection == "right" && direction == "left")
            direction = "right";
        else if(thisDirection == "left" && direction == "right")
            direction = "left";
            
        StopScroll();
        StartScroll(thisDirection);
    }

    function ShowBenefit(thisBenefit)
    { 
        for(i = 0; i <= 4; i++)
        {
            document.getElementById('summary' + i + 'image').style.display = "none";
            document.getElementById('summary' + i + 'text').style.backgroundColor = "#EAE9E5";
            document.getElementById('summary' + i + 'text').style.textDecoration = "none";
            document.getElementById('summary' + i + 'description').style.display = "none";
            document.getElementById('summarydefault').style.display = "none";
        }
        document.getElementById('summary' + thisBenefit + 'image').style.display = "block";
        document.getElementById('summary' + thisBenefit + 'text').style.backgroundColor = "white";
        document.getElementById('summary' + thisBenefit + 'text').style.textDecoration = "underline";
        document.getElementById('summary' + thisBenefit + 'description').style.display = "block";
    }

    function RevertBenefits(thisBenefit)
    { 
        for(i = 0; i <= 4; i++)
        {
            document.getElementById('summary' + i + 'image').style.display = "none";
            document.getElementById('summary' + i + 'text').style.backgroundColor = "#EAE9E5";
            document.getElementById('summary' + i + 'text').style.textDecoration = "none";
            document.getElementById('summary' + i + 'description').style.display = "none";
        }
        document.getElementById('summarydefault').style.display = "block";
    }
    
    function DisplayMenu(thisItem, recordCount)
    {
       
        //62 Windows Firefox, IE pixels == 63 Windows Safari pixels == 64 Macintosh pixels (WTF?)
	    linkBaseLocation = 27;
	    if(navigator.appVersion.indexOf("Safari") != -1 && navigator.appVersion.indexOf("Windows") != -1)    
            linkBaseLocation = 24;
        else if(navigator.appVersion.indexOf("Macintosh") != -1)
            linkBaseLocation = 25;
        divBaseLocation = 25;
        spaceOffset = 19;


         document.getElementById('menubar').style.top = thisItem.offsetTop + linkBaseLocation + "px";    
         document.getElementById('menucontents').style.top = thisItem.offsetTop + divBaseLocation + "px";
   
         
         document.getElementById(thisItem.id + 'description').style.display = "block";
         document.getElementById('menubar').style.display = "block";
         document.getElementById('menucontents').style.display = "block";

    }

    function HideMenu(thisEvent)
    {
        if(!thisEvent)
            thisEvent = window.event;
            
        thisElement = (thisEvent.toElement) ? thisEvent.toElement : (thisEvent.relatedTarget) ? thisEvent.relatedTarget : null;
        
		if(thisElement)
        {
            if(thisElement.id != 'menubar' && 
               thisElement.id != 'menucontents' && 
               thisElement.className != 'categoriesdescription' && 
               thisElement.className != 'descriptionlink' && 
               thisElement.className != 'menuimage')
            {
                CloseAll();
            }
        }
        else
        {
            CloseAll();
        }
    }
    
    function CloseAll()
    {
		var element = '';

		document.getElementById('menubar').style.display = "none";
        document.getElementById('menucontents').style.display = "none";

		for (var i = 0; i < categories.length; i++)
		{
			element = 'category' + categories[i] + 'description';

			if (document.getElementById(element) != null) {
				document.getElementById(element).style.display = "none";
			}
		}
	}
	
    function ChangeTabs(thisElement)
    {
		var count = parseInt(document.getElementById("hidCategoryCount").value);
		
		for (var i = 0; i < count; i++)
		{
			document.getElementById("tab" + i).className = "unselected";
			document.getElementById("tab" + i + "sub").className = "unselected";
			//document.getElementById("tab" + i).blur();
		}
		
        thisElement.className = "selected";
        document.getElementById(thisElement.id + "sub").className = "selected";
    }

    function RevertTabs(thisEvent)
    {
       return false;
    }
            
    function SetTabHighlighting()
    {
        currentUrl = window.location.href.substring(0, window.location.href.indexOf(".rails"));

        for(i = 1; i < 5; i++)
        {
            hometab = 'tab0';
            if(document.getElementById('tab' + i).innerHTML.match(/Shopping/) != null)
            {
                shoppingtab = 'tab' + i;
                shoppingtabsub = 'tab' + i + 'sub';
            }
            else if(document.getElementById('tab' + i).innerHTML.match(/Protection/) != null)
            {
                protectiontab = 'tab' + i;
                protectiontabsub = 'tab' + i + 'sub';
            }
            else if(document.getElementById('tab' + i).innerHTML.match(/Extra Rewards/) != null)
            {
                rewardstab = 'tab' + i;
                rewardstabsub = 'tab' + i + 'sub';
            }
            else if(document.getElementById('tab' + i).innerHTML.match(/Customer Care/) != null)
            {
                caretab = 'tab' + i;
                caretabsub = 'tab' + i + 'sub';
            }
        }
        
        if(currentUrl.match(/\/Home\/Default/i) != null)
        {
            document.getElementById(hometab).className = 'selected';
            defaultTab = 'tab0';
        }
        else if(currentUrl.match(/\/Features\/Common/i) != null || 
                currentUrl.match(/\/Features\/Profile/i) != null ||
                currentUrl.match(/\/BenefitSummary/i) != null   ||
                currentUrl.match(/Features\/LandingPages\/CustomerCare/i) != null 
               )
        {
            document.getElementById(hometab).className = "unselected";
            document.getElementById(caretab).className = "selected";
            document.getElementById(caretabsub).className = "selected";
            defaultTab = caretab;
        }
        else if(currentUrl.match(/\/Premium\/Default/i) 	 != null ||
                currentUrl.match(/DealOfTheDay/i) 			 != null || 
                currentUrl.match(/USAir500BonusMiles/i) 	 != null ||
                currentUrl.match(/USAir1000BonusMiles/i)     != null ||
				currentUrl.match(/Monthly/)                  != null ||
                currentUrl.match(/\/Reward/)                 != null ||
                currentUrl.match(/Magazine/)             	 != null ||
                currentUrl.match(/Features\/LandingPages\/ExtraRewards/i) != null 
               )  
        {
            document.getElementById(hometab).className = "unselected";
            document.getElementById(rewardstab).className = "selected";
            document.getElementById(rewardstabsub).className = "selected";
            defaultTab = rewardstab;
        }
        else if(currentUrl.match(/BestPriceGuarantee/i)        != null || 
                currentUrl.match(/ExtendedWarranty/i)          != null || 
                currentUrl.match(/DeliveryGuarantee/i)         != null ||
                currentUrl.match(/DamageTheftLossProtection/i) != null ||
                currentUrl.match(/CreditCardFraudProtection/i) != null ||
                currentUrl.match(/DamageTheftLossProtection/i) != null || 
                currentUrl.match(/Features\/LandingPages\/Protection/i) != null      
                )
        {
            document.getElementById(hometab).className = "unselected";
            document.getElementById(protectiontab).className = "selected";
            document.getElementById(protectiontabsub).className = "selected";
            defaultTab = protectiontab;
        }               
        else
        { 
            document.getElementById(hometab).className = "unselected";
            document.getElementById(shoppingtab).className = "selected";
            document.getElementById(shoppingtabsub).className = "selected";
            defaultTab = shoppingtab;
        }
    }
	
	function SetTabHighlighting_GC()
    {
        currentUrl = window.location.href.substring(0, window.location.href.indexOf(".rails"));

        for(i = 1; i < 6; i++)
        {
            hometab = 'tab0';
            if(document.getElementById('tab' + i).innerHTML.match(/Shopping/) != null)
            {
                shoppingtab = 'tab' + i;
                shoppingtabsub = 'tab' + i + 'sub';
            }
            if(document.getElementById('tab' + i).innerHTML.match(/Gift Cards/) != null)
            {
                giftcardtab = 'tab' + i;
                giftcardtabsub = 'tab' + i + 'sub';
            }
            else if(document.getElementById('tab' + i).innerHTML.match(/Protection/) != null)
            {
                protectiontab = 'tab' + i;
                protectiontabsub = 'tab' + i + 'sub';
            }
            else if(document.getElementById('tab' + i).innerHTML.match(/Extra Rewards/) != null)
            {
                rewardstab = 'tab' + i;
                rewardstabsub = 'tab' + i + 'sub';
            }
            else if(document.getElementById('tab' + i).innerHTML.match(/Customer Care/) != null)
            {
                caretab = 'tab' + i;
                caretabsub = 'tab' + i + 'sub';
            }
        }
        
        if(currentUrl.match(/\/Home\/Default/i) != null)
        {
            document.getElementById(hometab).className = 'selected';
            defaultTab = 'tab0';
        }
        else if(currentUrl.match(/\/Features\/Common/i) != null || 
                currentUrl.match(/\/Features\/Profile/i) != null ||
                currentUrl.match(/\/BenefitSummary/i) != null   ||
                currentUrl.match(/Features\/LandingPages\/CustomerCare/i) != null 
               )
        {
            document.getElementById(hometab).className = "unselected";
            document.getElementById(caretab).className = "selected";
            document.getElementById(caretabsub).className = "selected";
            defaultTab = caretab;
        }
        else if(currentUrl.match(/\/Premium\/Default/i) 	 != null ||
                currentUrl.match(/DealOfTheDay/i) 			 != null || 
                currentUrl.match(/USAir500BonusMiles/i) 	 != null ||
                currentUrl.match(/USAir1000BonusMiles/i)     != null ||
				currentUrl.match(/Monthly/)                  != null ||
                currentUrl.match(/\/Reward/)                 != null ||
                currentUrl.match(/Magazine/)             	 != null ||
                currentUrl.match(/Features\/LandingPages\/ExtraRewards/i) != null 
               )  
        {
            document.getElementById(hometab).className = "unselected";
            document.getElementById(rewardstab).className = "selected";
            document.getElementById(rewardstabsub).className = "selected";
            defaultTab = rewardstab;
        }
        else if(currentUrl.match(/BestPriceGuarantee/i)        != null || 
                currentUrl.match(/ExtendedWarranty/i)          != null || 
                currentUrl.match(/DeliveryGuarantee/i)         != null ||
                currentUrl.match(/DamageTheftLossProtection/i) != null ||
                currentUrl.match(/CreditCardFraudProtection/i) != null ||
                currentUrl.match(/DamageTheftLossProtection/i) != null || 
                currentUrl.match(/Features\/LandingPages\/Protection/i) != null      
                )
        {
            document.getElementById(hometab).className = "unselected";
            document.getElementById(protectiontab).className = "selected";
            document.getElementById(protectiontabsub).className = "selected";
            defaultTab = protectiontab;
        }   
         else if(currentUrl.match(/GiftCards/i)  != null  ||
                 currentUrl.match(/Cart/i)       != null)
        {
            document.getElementById(hometab).className = "unselected";
            document.getElementById(giftcardtab).className = "selected";
            document.getElementById(giftcardtabsub).className = "selected";
            defaultTab = giftcardtab;
        }                      
        else
        { 
            document.getElementById(hometab).className = "unselected";
            document.getElementById(shoppingtab).className = "selected";
            document.getElementById(shoppingtabsub).className = "selected";
            defaultTab = shoppingtab;
        }
    }


