﻿function addLoadEvent(func)
{
    var oldonload = window.onload;
    
    if (typeof window.onload != 'function') 
    {
        window.onload = func;
    } 
    else 
    {
        window.onload = function() 
        {
            oldonload();
            func();
        }
    }
}

function getElementsByClassName2(className, tag, elm)
{
    var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");	        	        	        	        	        
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
	
    for(var i=0; i<length; i++)
    {
        current = elements[i];
        if(testClass.test(current.className))
        {
	        returnElements.push(current);
        }
    }
	
    return returnElements;
}

function attachTabEvents()
{
    var tabElems = getElementsByClassName2("fpTab", "a");   
        
    for(i=0; i< tabElems.length; ++i)
    {
        tabElems[i].style.backgroundPosition = "bottom";
            
        tabElems[i].onclick = function()
        {            
            // do not track the click if tab is already open
            if(this.style.backgroundPosition.indexOf("bottom") > -1)
            {
                trackTabClickWithOmniture(this.id);
            }
                    
            resetTabs();
            this.style.backgroundPosition = "top";       
            
            // reset and hide all tab details
            descElems = getElementsByClassName2("fpTabDetail", "div");                            
            
            for(i=0; i < descElems.length; ++i)
            {
                descElems[i].style.display = "none";
            }
                                    
            // find the clicked tab's index and display matching description                                   
            descIndex = parseInt(this.id.substring(5));            
            descElems[descIndex].style.display = "block";    
            
            // footer fix for IE
            if(navigator.appName.indexOf('Internet Explorer') >= 0)
            {
                document.getElementById('footer').style.bottom = "1px";
                document.getElementById('footer').style.bottom = "0px";
            }                        
        }
    }
    
    tabElems[0].style.backgroundPosition = "top";    
}

function trackTabClickWithOmniture(tabId)
{
    if (!(e = document.getElementById('omnitureCode'))) return;  
    var omnitureCode = e.value;

    switch(tabId)
    {  
        default:
            break;      
        case 'fpTab1':
            omnitureCode = omnitureCode.replace(":features",":specifications");
            break;
        case 'fpTab2':
            omnitureCode = omnitureCode.replace(":features",":accessories");
            break;
        case 'fpTab3':
            omnitureCode = omnitureCode.replace(":features",":support");
            break;                                                      
    }
        
    s.pageName="us:campaign:sta:sta macrosite:microsite:" + omnitureCode;
    s.channel="campaign"
    s.prop9="campaign:sta"
    s.prop10="campaign:sta:sta macrosite"
    s.hier1="us:home>campaign>sta>sta macrosite>microsite>" + omnitureCode;    
    s.events=""
    s.products=""
    s.eVar33=""
    var s_code=s.t();
    if(s_code)document.write(s_code);
}

function trackClickedItemsWithOmniture(clickedItem)
{
    s=s_gi('sssamsung,ssstamacrosite'); 
    s.tl(this,'e', clickedItem);
}

function resetTabs()
{
    var tabElems = getElementsByClassName2("fpTab", "a");
    
    for(i=0; i < tabElems.length; ++i)
    {
        imgElem = tabElems[i];
		imgElem.style.backgroundPosition = "bottom";
    }    
}

//Used to preload images for tabs.
image1 = new Image();
image1.src = "../Images/productDetail/tabProductFeatures.gif";

image2 = new Image();
image2.src = "../Images/productDetail/tabProductSpecifications.gif";

image3 = new Image();
image3.src = "../Images/productDetail/tabProductAccessories.gif";

image4 = new Image();
image4.src = "../Images/productDetail/tabProductSupport.gif";


//Modal Box Script

function modalBox(id)
{
    var  modalBackground = document.getElementById('modalBackground');
    var id = document.getElementById(id);
    if(modalBackground.style.display == "block")
    {
        modalBackground.style.display="none";
        id.style.display = "none";
    } else
    {
        modalBackground.style.display="block";
        id.style.display = "block";
    }

    // Close Modal with close button
    var modalClose = getElementsByClassName2('closeButton', 'input');
    for(var i=0; i<modalClose.length; i++)
    {
        modalClose[i].onclick = function(){
            modalBackground.style.display="none";
            id.style.display = "none";
        }
    }
}

//Track PDFs and other not app driven static items
function TrackItem(trackingDesc)
{
	trackClickedItemsWithOmniture(trackingDesc);
	return true;
}
