﻿// Definition of the namespace SAPUTO
NURUN.namespace("SAPUTO");

SAPUTO.pageLoad = function() {

    var bss = document.getElementById("BrandSitesSelector");
    if (bss != null) new NURUN.widget.LinksDropDown(bss);

    var ls = document.getElementById("LanguagesSelector");
    if (ls != null) new NURUN.widget.LinksDropDown(ls);

    var cp = document.getElementById("changeProfile")
    if (cp != null) new NURUN.widget.LinksDropDown(cp);

    //empty search box on click
    var search = document.getElementById("query");
    var resourceSearch = document.getElementById("FindResources");
    if (search != null) {
        YAHOO.util.Event.addListener(search, "blur", feed, resourceSearch);
        YAHOO.util.Event.addListener(search, "click", empty, resourceSearch);
        
    }
}

function empty(e, obj) {
    if (this.value == obj.value) this.value = "";
}
function feed(e, obj) {
    if (this.value == "") this.value = obj.value;
    this.style.background = 'white';
}

/*
Title:      Main JavaScript	
Updated:    19 Juin 2008
Description: This file contains all the javascript application-specific code written for the site.
This file should always be included last as it possess various dependencies on other components (ex: Yahoo UI).
*/

/*window.SAPUTO = window.SAPUTO || {};

//Activate this to prevent onclick default behavior on custom tagging
//an allow to view console logging
var GoogleAnalyticsDebugMode=false;

///This object is used to track custom events while avoiding the potential errors
// that would occur when analytics is disabled. This occur in local development environment.
SAPUTO.GoogleAnalytics=function()
{
    this.tracker=null;
    
    this.trackCustomEvents=function(trackingInformation)
    {    
        //if analytics is disable, trace the call on the firefox console for debugging purposes
        if(GoogleAnalyticsDebugMode)
        { console.log(trackingInformation.replace(/ /g,'-')); }
        
        //it analytics is enable, use the Google API method to perform the tracking.
        if(this.tracker!=null)
        {
            this.tracker._trackPageview(trackingInformation.replace(/ /g,'-'));
        }                
        return !GoogleAnalyticsDebugMode;
    };    
};

SAPUTO.SelectProduct = function()
{ 
    var selectBoxId=document.getElementById('ddlCountry');
    var actionButton=document.getElementById('countrySelect');
    var productBlocksContainer=document.getElementById('allProductsBlocks');
    var listOfProductBlock = YAHOO.util.Dom.getElementsByClassName('countryProductBlock','div',productBlocksContainer);
    var nbListOfProductBlock = listOfProductBlock.length;
    
    this.init=function()
    { 
        YAHOO.util.Event.addListener(actionButton, "click", this.showProductBlock);
    };
    
    this.showProductBlock=function(ev)
    {
        var selectedCountry = selectBoxId.value;
        
        for(var i=0;i<nbListOfProductBlock;i++)
        {
            if (listOfProductBlock[i].id === "country-" + selectedCountry)
            {
                YAHOO.util.Dom.setStyle(listOfProductBlock[i],"display","block");
            }
            else
            {
                YAHOO.util.Dom.setStyle(listOfProductBlock[i],"display","none");
            }
        }
    };  
};

SAPUTO.SendToFriend = function()
{ 
    var sendToFriendPanel = null;
    var actionButton=document.getElementById('lnkSendToFriend');
    
    this.init=function()
    { 
        sendToFriendPanel = new YAHOO.widget.Panel("send-to-friend-panel",
        { 
            width: "477px",
            height: "471px",
            constraintoviewport: true,  
            //underlay:"shadow",  
            close:true,  
            visible:false,  
            fixedcenter: false,  
            draggable:true,
            zIndex: 9999
        });
        
        //Render the panel for screen
        sendToFriendPanel.render(document.body);
        
        YAHOO.util.Event.addListener(actionButton, "click", this.showSendToFriend);
    };
    
    this.showSendToFriend = function(e)
    {
        e = e || event;
        var link = actionButton.href;
        sendToFriendPanel.setBody("<div class='hd'></div><div class='bd'><iframe width='476' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='471' src='" + link + "'></iframe></div>");
        sendToFriendPanel.render();
        sendToFriendPanel.show();
        YAHOO.util.Event.preventDefault(e);
        YAHOO.util.Event.addListener("hidePanelSendToAFriend", "click", this.hideSendToFriend);
    };
    
    this.hideSendToFriend = function(e)
    {
		e = e || event;
		sendToFriendPanel.render();
	    sendToFriendPanel.hide();
	    YAHOO.util.Event.preventDefault(e);
	};
     
};
*/
