    var channelId = 1;

    var HOMEIDX = 1;
    var PODCASTIDX = 2;
    var CONTESTIDX = 3;
    var SUBMISSIONIDX = 4;
    var PRODUCTFAVORITE = 5;

    var PODCAST = null;
    var CONTEST_INFO = null;
    var MY_VIDEOS = null;

    var highlightImageFrequency = new Array();
    var highlightImageOrder = new Array();
    var imgProduct = new Array();
    
    function Podcast()
    {
    }

    Podcast.prototype = new Class_Base();
    Podcast.prototype.currentSnippets = ["", "idCurItemTr", "", "", ""];
    Podcast.prototype.displayDivisions = function(isNotDefault, showId, hideIdx, fileurl)
    {
        if(isNotDefault)
        {
           if(showId || hideIdx)
            {
                _toggleDiv(this.currentSnippets[hideIdx], false);
                if(showId)
                {
                    this.currentSnippets[hideIdx] = showId;
                    _toggleDiv(this.currentSnippets[hideIdx], true);
                }
            }
            else if(fileurl != null)
            {
                this._setCurrent(fileurl);
            }
        }
        else
        {
            for(i=0;i < this.currentSnippets.length;i++)
            {
                _toggleDiv(this.currentSnippets[i], true);
            }
            
            this._setCurrent(fileurl);
        } 
    }

    function Contest_Info()
    {
    }

    Contest_Info.prototype = new Class_Base();
    Contest_Info.prototype.currentSnippets = ["", "idCurItemTr", "idContestInfoTr", "idEnterContestTr", "idLatestVideosTr"];
    Contest_Info.prototype.displayDivisions = function(isNotDefault, showId, hideIdx, fileurl)
    {
        if(isNotDefault)
        {
            if(showId == "phoneTr" || showId == "emailTr")
            {
                  _toggleDiv('formsTableContest', false);
                  _toggleDiv('socialActionTableContest', true);
                  _toggleDiv(this.currentSnippets[hideIdx], false);
                  this.currentSnippets[hideIdx] = showId;
                  _toggleDiv(this.currentSnippets[hideIdx], true);
                  loadOrnament(null, true);
            }
            else
            {
                _toggleDiv('formsTableContest', true);
                _toggleDiv('socialActionTableContest', false);
                if(showId || hideIdx)
                {
                    _toggleDiv(this.currentSnippets[hideIdx], false);
                    if(showId)
                    {
                        this.currentSnippets[hideIdx] = showId;
                        _toggleDiv(this.currentSnippets[hideIdx], true);
                    }
                }
                else if(fileurl != null)
                {
                    this._setCurrent(fileurl);
                }
            }
        }
        else
        {
            if(showId)
            {
                _toggleDiv(this.currentSnippets[hideIdx], false);
                this.currentSnippets[hideIdx] = showId;    
            }
            
            for(i=0;i < this.currentSnippets.length;i++)
            {
                _toggleDiv(this.currentSnippets[i], true);
            }

            this._setCurrent(fileurl);
        }
    }

    function MyVideos()
    {
    }
 
    MyVideos.prototype = new Class_Base();
    //change for stage 3 // MyVideos.prototype.currentSnippets = ["", "idCurItemTr", "", "allVideosSubTr", ""]; 
    MyVideos.prototype.currentSnippets = ["", "idCurItemTr", "", "winnerVideoSubTr", ""];
    MyVideos.prototype.displayDivisions = function(isNotDefault, showId, hideIdx, fileurl)
    {
        if(isNotDefault)
        {
            if(showId || hideIdx)
            {
                _toggleDiv(this.currentSnippets[hideIdx], false);
                if(showId)
                {
                    this.currentSnippets[hideIdx] = showId;
                    _toggleDiv(this.currentSnippets[hideIdx], true);
                }
            }

            if(fileurl != null)
            {
                this._setCurrent(fileurl);
            }
        }
        else
        {
            for(i=0;i < this.currentSnippets.length;i++)
            {
                _toggleDiv(this.currentSnippets[i], true);
            }
            
            this._setCurrent(fileurl);
        } 
    }

    function setCurrent(pageIdx, isNotDefault, showId, hideIdx, entry, parentPath, podcastEntry, skipQueryParam)
    {
        //alert("pageid: "+pageIdx+", showId: "+showId+"   entry = "+entry);
        var afterUpdateViews = function() 
        {        
            switch(pageIdx)
            {
                case 1:
                {
                    var curItem = document.getElementById("_idCurItem");
                    
                    if(curItem != null)
                    {
                        curItem.innerHTML = getHtmlSnippet("_idCurItem", ((entry)?entry.entry_cdnfileurl:null));
                    }
                }
                break;
                    
                case 2:
                {
                    if(!PODCAST)
                    {
                        PODCAST = new Podcast();
                    }

                    PODCAST.displayDivisions(isNotDefault, showId, hideIdx, ((entry)?entry.entry_cdnfileurl:null));

                    // commenting out this as anonymous rating and social actions are allowed

    /*             //Login shown if user not logged in and want to post a comment or to use social actions

                    var userName = checkLogin();
                    if(showId && !userName)
                    {
                        PODCAST.displayDivisions(isNotDefault, "loginFormPodcastTr", hideIdx, ((entry)?entry.entry_cdnfileurl:null));
                    }
                    else
                    {
                        PODCAST.displayDivisions(isNotDefault, showId, hideIdx, ((entry)?entry.entry_cdnfileurl:null));
                    }      */

                    if(podcastEntry)
                    {                    
                        currentPodcastEntry = podcastEntry;
                        currentPodcastEntryId = 1;
                        var productListInfo = document.getElementById('productListInfo');

                        if(productListInfo)
                        {
                            productListInfo.innerHTML = '<a href="checklist.html?entry_id='+currentPodcastEntry[0].entry_id+'"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/button_shop_featured_products.png"></img></a>';
                        }
                        
                        imgProduct = new Array();

                        for(var i=1; i<currentPodcastEntry.length; i++)
                        {
                            var imgProd = new Image();
                            imgProd.src = currentPodcastEntry[i].entry_cdnfileurl;
                            imgProduct.push(imgProd);
                        }

                        setRightVideoDescription(false, currentPodcastEntry[0].entry_comment, (entry.entry_entryprops && entry.entry_entryprops.ct_props_2 ? entry.entry_entryprops.ct_props_2 : null));
                        getHighlightImageOrder(currentPodcastEntry[0].entry_id);
                        if(imgProduct[0])
                        {
                            var itemUrl = (currentPodcastEntry[currentPodcastEntryId].entry_entryprops.ct_prop_4 == null || (trim(currentPodcastEntry[currentPodcastEntryId].entry_entryprops.ct_prop_4)).length == 0 ?  currentPodcastEntry[currentPodcastEntryId].entry_itemurl1 :  currentPodcastEntry[currentPodcastEntryId].entry_entryprops.ct_prop_4)
                            setProductHighlightImage(imgProduct[0].src, currentPodcastEntry[currentPodcastEntryId].entry_label1, itemUrl, currentPodcastEntry[currentPodcastEntryId].entry_entryprops.pfeed_saleprice, currentPodcastEntry[currentPodcastEntryId].entry_entryprops.pfeed_retailprice);
                        }
                        setProductHighlightData();
                        loadBlogPostcontents('copypasteshare', socialUrls[4], blogContent, extraParams[0], extraParams[4], null, null, null, 'blogContents');
                    }
                    
                    if(entry)
                    {
//                        changeCommentsReceipe('commentsBoxTr', true);
                        changeCommentsReceipe('recipeBoxTr', true);
                        loadComments(entry.entry_id);
                    }
                }
                break;
                
                case 3:
                {
                    if(!CONTEST_INFO)
                    {
                        CONTEST_INFO = new Contest_Info();
                    }

                    var afterCheckLogin = function()
                    {
                        if(userName)
                        {                            
                            if(!isNotDefault)
                            {
                                if(!uploadalert || (uploadalert == null))
                                {
                                    var qs = new Querystring();
                                    uploadalert = qs.get('showuploadalert'); 
                                }
                                if(uploadalert && uploadalert == 'true')
                                {
                                    CONTEST_INFO.displayDivisions(isNotDefault, "videoUploadSuccesTr", 3, ((entry)?entry.entry_cdnfileurl:null)); 
                                    uploadalert = 'false';
                                }  
                                else
                                {
                                    CONTEST_INFO.displayDivisions(isNotDefault, "contestloginsucess", 3, ((entry)?entry.entry_cdnfileurl:null)); 
                                    //changing the after success login for stage 2
                                    //CONTEST_INFO.displayDivisions(isNotDefault, "idEnterContestTr", 3, ((entry)?entry.entry_cdnfileurl:null));  //idEnterContestTr is vote for your favourite
                                }    
                            }
                            else
                            {
                                CONTEST_INFO.displayDivisions(isNotDefault, showId, 3, ((entry)?entry.entry_cdnfileurl:null));  
                            }

                            if(showId == 'changePwdTr')
                            {
                                getUserProfile();
                            }
                            
                            setUserName(userName);
                        }
                        else
                        {
                            var qs = new Querystring();
                            var divId = qs.get('div_id'); 
                            var showDivId = showId;
                            
                            if(isNotDefault == false)
                            {
                                if(divId == 1 || skipQueryParam)
                                {
                                    showDivId = "trloginformcommon1";
                                }
                                else if (divId == 2)
                                {
                                    showDivId =  "idRegisterContestTr";
                                }
                                hideIdx = 3;
                            }

                            CONTEST_INFO.displayDivisions(isNotDefault, showDivId, hideIdx, ((entry)?entry.entry_cdnfileurl:null));
                        }
                    }

                    checkLogin(afterCheckLogin);
                }
                break;

                case 4:
                {
                    if(!MY_VIDEOS)
                    {
                        MY_VIDEOS = new MyVideos();
                    }                
                    
                    if(entry)
                    {
                        setRightVideoDescription(false, entry.entry_comment, (entry.entry_entryprops && entry.entry_entryprops.ct_prop_2 ? entry.entry_entryprops.ct_prop_2 : null));
                        loadComments(entry.entry_id);
                        loadBlogPostcontents('copypasteshare', socialUrls[4], blogContent, extraParams[0], extraParams[4], null, null, null, 'blogContents');
                    }
                    else
                    {
                        loadOrnament();
                    }

                    MY_VIDEOS.displayDivisions(isNotDefault, showId, hideIdx, ((entry)?entry.entry_cdnfileurl:null));
                    
                }
                break;
            }
        }

        if(entry)
        {
            curEntry = entry;
            currentEntryId = entry.entry_id;
            setOtherElementEntryIds(entry.entry_id, parentPath, entry);
            var heading = document.getElementById("heading");
            if(heading)
            {
                heading.innerHTML = getDisplayText(entry.entry_label1, 40);
            }

            updateViews(afterUpdateViews);
        }
        else
        {
            afterUpdateViews();
        }             
    }
    
    function hideSignIn(showlogin)
    {
        //var userName = checkLogin();
/*        if(userName)
        {
                _toggleDiv('commentSignIn', false);
                _toggleDiv('commentAlone', true);
        }
        else
        { 
                _toggleDiv('commentSignIn', true);
                _toggleDiv('commentAlone', false); */
                
        if(!userName)
        {                
                var qs = new Querystring();
                var divId = qs.get('div_id'); 
                
                if(divId ||showlogin)
                {
                    //setCurrent(pageIdx,       isNotDefault, showId, hideIdx, entry, parentPath, podcastEntry, skipQueryParam)
                    setCurrent(CONTESTIDX, false, "idEnterContestTr", 3, null, null, null, true);
                }
                else
                {
                    setCurrent(CONTESTIDX, true, "idEnterContestTr", 3);
                }
        }
    }

    function countDown(callbck) //change for stage 2
    {
        /*var current = new Date();    
        var days = (contestDate - current) / 1000 / 60 / 60 / 24;
        var daysRound = Math.floor(days);
        var countDownId = document.getElementById('countdown');
        countDownId.innerHTML = convert(daysRound) + " More Days"; */
        loadOrnament(callbck, 'countdown');
    }

    function getHighlightImageOrder(entryId)
    {
        var highlightImageFreq = new Array();
        var highlightImageItemsFreq = new Array(currentPodcastEntry.length);                        

        //split and get the values
        for(var i=1; i<currentPodcastEntry.length; i++)
        {
            var entryArray =  null;

            if(currentPodcastEntry[i].entry_entryprops && currentPodcastEntry[i].entry_entryprops.ct_prop_1)
            {
                entryArray = JSON.parse(currentPodcastEntry[i].entry_entryprops.ct_prop_1);                
                var propStr = entryArray[entryId];

                if(propStr)
                {   
                    for(var j=0; j<propStr.length; j++)
                    {
                        highlightImageFreq.push(propStr[j]);
                    }
                    
                    highlightImageItemsFreq[i-1] = propStr;         
                }
            }
        }

        //sort the array according to time
        highlightImageFreq.sort(sortNumber);
        highlightImageFrequency = highlightImageFreq;
        
        //get highlight array according to the sorted frequency array  
        var i, j, k, id=-1;
        highlightImageOrder = new Array(highlightImageFreq.length);
        
        for(i=0; i<highlightImageFreq.length; i++)
        {
            id = -1;

            for(j=0; j<highlightImageItemsFreq.length && id == -1; j++)
            {
                if(highlightImageItemsFreq[j])
                {
                    for(k=0; k<highlightImageItemsFreq[j].length && id == -1; k++)
                    {
                        if(highlightImageItemsFreq[j][k] == highlightImageFreq[i])
                        {
                            id = j;
                        }
                    }
                }
            }

            if(id != -1)
            {
                highlightImageOrder[i] = id;
            }
        }
    }

    function sortNumber(a,b)
    {
        return a - b;
    }

    function onPlayheadUpdate(elapsedSecs)
    {           
        var url = new String(document.location);
        var startIndex = url.lastIndexOf('/') + 1;
        var lastIndex = ((url.indexOf('?') == -1)?url.length:url.indexOf('?'));
        var fileName = url.substring(startIndex, lastIndex); 

        if(fileName == "podcast.html")
        {     
            var itemUrl = "";
            if(Math.floor(elapsedSecs) == 0)
            {
                itemUrl = (currentPodcastEntry[1].entry_entryprops.ct_prop_4 == null || (trim(currentPodcastEntry[1].entry_entryprops.ct_prop_4)).length == 0 ?  currentPodcastEntry[1].entry_itemurl1 :  currentPodcastEntry[1].entry_entryprops.ct_prop_4);
                setProductHighlightImage(currentPodcastEntry[1].entry_cdnfileurl, currentPodcastEntry[1].entry_label1, itemUrl, currentPodcastEntry[1].entry_entryprops.pfeed_saleprice, currentPodcastEntry[1].entry_entryprops.pfeed_retailprice);
                currentPodcastEntryId = 1;
            }
            else
            {
                var i=1;
                var id=-1;              

                for(i=0; i<highlightImageOrder.length && id == -1; i++)
                {
                    if(elapsedSecs >= highlightImageFrequency[i] && (((i+1) >= highlightImageOrder.length) || elapsedSecs < highlightImageFrequency[i+1]))
                    {
                        id = (highlightImageOrder[i]+1);
                        break;
                    }
                }

                if(id != -1 && id < currentPodcastEntry.length && currentPodcastEntryId != id)
                {       
                    itemUrl = (currentPodcastEntry[id].entry_entryprops.ct_prop_4 == null || (trim(currentPodcastEntry[id].entry_entryprops.ct_prop_4)).length == 0 ?  currentPodcastEntry[id].entry_itemurl1 :  currentPodcastEntry[id].entry_entryprops.ct_prop_4)
                    setProductHighlightImage(imgProduct[id-1].src, currentPodcastEntry[id].entry_label1, itemUrl, currentPodcastEntry[id].entry_entryprops.pfeed_saleprice, currentPodcastEntry[id].entry_entryprops.pfeed_retailprice);
                    currentPodcastEntryId = id;
                }
                
            }
        }
    }

    function setRightVideoDescription(isScroll, description, entryProps)
    {
        var html = "";
        var podcastVideoDescription = document.getElementById("podcastVideoDescription");
        if(description || description == '')
        {
            if(entryProps == ct_prop_grandprize)
            {
                html =  '<font class="subTabLeftFont redTextColor textBold">GRAND PRIZE WINNER</font><br>';
            }
            else if(entryProps == ct_prop_runnerup)
            {
                html =  '<font class="subTabLeftFont redTextColor textBold">RUNNER UP WINNER</font><br>';
            }
            
            if(isScroll)
            {
                html += '<div class="productHighLightDesctiption overflowScroll">' +
                        '<font class="currentItemHeading textBold">' + unescape(description) +
                        '</font><div>';
            }
            else
            {
                html += '<font class="currentItemHeading textBold">'+
                doWhiteSpaceEncode(description, 200)+'&nbsp;</font>';

                if(description.length > 200)
                {
                   html +=  "<a href='javascript:false' onclick='setRightVideoDescription("+true+", \"" + escape(htmlEncode(description)) +"\"); return false;'><font class='linkRed underline textBold'>more</font></a>";
                }
            }
            podcastVideoDescription.innerHTML = html;
        }
    }

    function setUserName(userName)
    {
        var welcome = "Welcome, "+getDisplayText(userName, 10, true);
        var userNameId = document.getElementById('contestUserName');
        userNameId.innerHTML = welcome;
        userNameId = document.getElementById('contestUserName1');
        userNameId.innerHTML = welcome;
        userNameId = document.getElementById('contestUserName2');
        userNameId.innerHTML = welcome;
        userNameId = document.getElementById('contestUserName3');
        userNameId.innerHTML = welcome;
        userNameId = document.getElementById('contestUserName4');
        userNameId.innerHTML = welcome;
        userNameId = document.getElementById('contestUserName5');
        userNameId.innerHTML = welcome;
    }

    function setProductHighlightImage(imageUrl, description, itemURL, salePrice, regPrice)
    {               
        var imageId = document.getElementById("highlightImage");
        if(imageId)
        {
            imageId.src=imageUrl;  
        }
        
        var textId = document.getElementById("highlightText");
        if(textId)
        {
            var sale = ((salePrice && regPrice && (salePrice == regPrice)) ? "<br>Price: $" + regPrice : (salePrice ? "<br>Sale: $" + salePrice :""));
            textId.innerHTML='<a target="_blank" class="productHighLightDescriptionFont underline" href="'+itemURL+'">'+doWhiteSpaceEncode(unescape(description), 50)+'</a>'+sale;          
        }
    }

    function setProductHighlightData()
    {
        var innerHtml = '<table cellspacing="0" cellpadding="4" class="fullWidth">';
        var itemUrl = "";

        for(var i=1; i<currentPodcastEntry.length; i++)
        {   
            itemUrl = (currentPodcastEntry[i].entry_entryprops.ct_prop_4 == null || (trim(currentPodcastEntry[i].entry_entryprops.ct_prop_4)).length == 0 ?  currentPodcastEntry[i].entry_itemurl1 :  currentPodcastEntry[i].entry_entryprops.ct_prop_4);
            innerHtml += '<tr><td class="productHighLightHeadingItem">'+                   
                                '<a href="#" onclick="setProductHighlightImage(\'' + currentPodcastEntry[i].entry_cdnfileurl + '\',\'' +escape(currentPodcastEntry[i].entry_label1) +'\', \'' +  itemUrl + '\',\'' + currentPodcastEntry[i].entry_entryprops.pfeed_saleprice + '\',\'' + currentPodcastEntry[i].entry_entryprops.pfeed_retailprice +'\'); return false;"><font class="productHighLightHeadingItemFont underline">'+doWhiteSpaceEncode(currentPodcastEntry[i].entry_label1)+'</font></a>'+
                                '</td></tr>';
        }

        innerHtml += '</table>';
        var curItem = document.getElementById("productHighlights");
        curItem.innerHTML = innerHtml;
    }

    function loadCaptcha(pageId, isNotDefault, showd, regionId)
    {
        setCurrent(pageId, isNotDefault, showd, regionId);

        if(showd == 'mobileFormWebTr')
        {
            loadCaptchaImage('idimgcaptchaVideo');
        }
        else if(showd == 'emailFormShareWebTr')
        {
            loadCaptchaImage('idimgEmailcaptcha1');                
        }        
        else if(showd == 'emailTr')
        {
            loadCaptchaImage('idimgEmailcaptcha');
        }
        else if(showd == 'phoneTr')
        {
            loadCaptchaImage('idimgCommoncaptcha');            
        }
        clearErrorText();
    } 

    function hideEmail()
    {
        if(curPageIdx == CONTESTIDX)
        {
            setCurrent(curPageIdx, true, "contestSpreadTr", 3);
        }
        else
        {
           _toggleDiv("emailTr", false);  
        }
    }
    
    function hidePhone()
    {
        if(curPageIdx == CONTESTIDX)
        {
            setCurrent(curPageIdx, true, "contestSpreadTr", 3);
        }
        else
        {
           _toggleDiv("phoneTr", false);  
        }
    }

    function changeCommentsReceipe(elid, showDiv)
    {
        var commentsImg = document.getElementById("commentsImg");
        var recipeImg = document.getElementById("recipeImg");
        
        if(elid == "commentsBoxTr")
        {
            commentsImg.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/comments_tabsel.jpg";
            recipeImg.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/view_recipedesel.jpg";
            _toggleDiv('recipeBoxTr', false);
        }
        else
        {
            commentsImg.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/comments_tabdesel.jpg";
            recipeImg.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/view_recipesel.jpg";
            loadPodcastRecipe();
            _toggleDiv('commentsBoxTr', false);
        }
        _toggleDiv(elid, showDiv);        
    }   

    function hideUserAccessible()
    {
        _toggleDiv('spreadSubTr', false); 
        _toggleDiv('emailTr', false); 
        _toggleDiv('phoneTr', false);
        hideUpload();
    }

    function logoutUser()
    {
        var afterUpload = function(result, xmlhttp)
        {
            eraseCookie('user_name');
            eraseCookie('user_id');
            checkCurrentPage(afterlogoutUser);
            userName =  null;
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp?"+
                "campaign_id=" + campaignId +
                "&channel_id=" + channelId + 
                "&aid=2"+
                "&resptype=inline";        
        jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);
    }

    function afterlogoutUser()
    {
        hideSignIn(true);
        if(curPageIdx == SUBMISSIONIDX)
        {
            //showAllVideos(); // stage 3
            showFinalistVideos();
        }
        else if(curPageIdx == CONTESTIDX)
        {
            setCurrent(curPageIdx, true, "idEnterContestTr", 3);
            
        }
    }

    //for stage 2
    function goToMyVideos(anc)
    {
        anc.href = "myvideos.html?entry_id"+currentEntryId;
        return true;
    }

