    var campaignId=(window.location.host.indexOf("cbe.atfingertips.com") >= 0 || window.location.host.indexOf("bhima") >= 0 ? 1 : (window.location.host.indexOf("mcstage.atfingertips.com") >= 0 || window.location.host.indexOf("skavamp.com") >= 0  ? 70 : 37));
    var CHANNEL_WEB = 1;
    var CHANNEL_FACEBOOK = 3;
    var MEDIATYPE_VIDEO = 2;

    var auth = {1: 'sdjhfs@sdfsdf', 70: 'sdjhfs@sdfsdf', 37: 'keeptyler456cook'};
    var maileridSMS = {1: 1, 70: 5, 37: 9};
    var maileridEmail = {1: 2, 70: 7, 37: 11};
    var maileridSTW = {1: 3, 70: 6, 37: 10};
    var maileridRegisterEmail = {1: 4, 70: 8, 37: 12};    
    var maileridForgotPwd = {1: 5, 70: 9, 37: 13};        
    var maileridContestInfo = {1: 6, 70: 12, 37: 16};
    var maileridBB = {1: 7, 70: 13, 37: 17};
    
    var gaId = "UA-5477042-6";
    var coremetricspdn = {70: false, 37: true}
    
    var sessionId = null;

    var rssURL = {1: 'http://skava.stage.store.atfingertips.com.s3.amazonaws.com/',
        70: 'http://skava.stage.store.atfingertips.com.s3.amazonaws.com/',
        37: 'http://macys1.store.atfingertips.com.s3.amazonaws.com/'};
            
    var faceboookAppAddURL = {1: 'http://www.facebook.com/add.php?api_key=a0c0b2468b0c2fc7a43b8b44c33c6dc7&pages',
        70: 'http://www.facebook.com/add.php?api_key=a0c0b2468b0c2fc7a43b8b44c33c6dc7&pages',
        37: 'http://www.facebook.com/add.php?api_key=bba8225aabeb115b5d4fa548c228a28c&pages'};

    var iphoneAppDirUrl = "http://www.apple.com/iphone/appstore/";
    
    var maxAwsSize = 20971520;//5242880;
    var carrierNames = {"31009":"Alltel", "31002":"AT&T", "31008":"Boost_Prepaid", "31011":"Boost_Unlimited", "31006":"Cellular_One", "31007":"Nextel", "31005":"Sprint", "31004":"T-Mobile", "31012":"US_Cellular", "31003":"Verizon_Wireless", "31010":"Virgin_Mobile", "0":"Dont_Know"};
    
    var curPageIdx = 0;
    var prevPageIdx = 0;
    var prevEntryId = 0;
    
    var facebookDescription = " Please watch this Macy's Keeps America Cooking contest video and rate it. To vote, please click on the link above.";
    var sessionExpiryString = "Your session has expired. Please login to continue.";
    
    var serverprefix = "";

    var bundleNames = null;
    var latestPodcastEntries= null, latestSubmissionEntries = null, podcastEntries = null, myVideos = null, allVideos = null, comments = null, ratings = null, currentPodcastEntry = null, welcomeVideoEntry=null;
    var shortlistedData = null, winnerVideos = null; // stage 3 and 4
    
    var userNames = null, nextPrevPaths = null, allVideoPagination = null, usernamesSubmission = null, usernameWinners = null;

    var currentPodcastEntryId = 1, currentEntryId = 0;
    var contestDate = new Date("Apr 10 2009 00:00:00");
    var Number1 = new Array(""," Hundred");
    var Number2 = new Array("","One","Two", "Three","Four","Five"," Six"," Seven", "Eight"," Nine","Ten");
    var Number3 = new Array("", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty","Ninety");
    var Number4 = new Array("", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen");
        
    var socialUrls = "";
    var parentPath = null;
    var extraParams = null;
    var blogContent = 'Tyler Your Content here';
    var DEFAULT_SEARCH_STRING = 'enter video title or author';

    var comments = null; 
    var stats = null;
    
    var LATEST_VIDEO_SUBMISSIONS_TAB_IDX = 0;
    var TOP_VIEWED_VIDEOS_TAB_IDX = 1;
    var TOP_RATED_VIDEOS_TAB_IDX = 2;
    var ORNAMENTS_TAB_IDX = 3; 
    var KIC_WELCOME_VIDEO_TAB_IDX = 4;
    var KIC_MY_VIDEO_TAB_IDX = 5;    
    var KIC_WINNER_VIDEO_TAB_IDX = 6;    
    var KIC_VIDEO_START_TAB_IDX = 7;    

    var uploadalert = null;

    var userName = null;
    var fUserId = 0;
    
    //app variables
    var numCommentIdx = 3;
    var numCommentsInPage = 5;

    var curEntry = null;

    var animCount=0
    var appendText = '';
    var timer;
    var isSTW = false, isContestInfo = false;

    var ct_prop_finalist = "finalist";
    var ct_prop_grandprize = "grand prize";
    var ct_prop_runnerup = "runner up";
    
    function uploadAnim()
    {
        if(animCount < 10)
        {
            animCount++;
            appendText += '.';
        }
        else
        {
            appendText = '';
            animCount=0;
        }
        _toggleDiv('uplodStatusDiv', true);
        _toggleDiv('uplodInfoDiv', false);
        _toggleDiv('forgotPassworderrorText', false); 
        document.getElementById('uplodStatus').innerHTML='Uploading, please wait'+appendText;
        timer=setTimeout("uploadAnim()",100);
    }

     function startForgotPasswordAnim()
    {
        if(animCount < 10)
        {
            animCount++;
            appendText += '.';
        }
        else
        {
            appendText = '';
            animCount=0;
        }
        _toggleDiv('sendStatus', true);

        var forgotPassworderrorText= document.getElementById("forgotPassworderrorText");
        forgotPassworderrorText.innerHTML = "";

        var sendStatus = document.getElementById('sendStatus');
        if(sendStatus)
        {
            sendStatus.innerHTML='Validating information, please wait' + appendText;
            timer=setTimeout("startForgotPasswordAnim()",100);
        }
    }
    
    function stopUploadAnim()
    {
        clearTimeout(timer);
        _toggleDiv('uplodStatusDiv', false); 
        _toggleDiv('sendStatus', false); 
        _toggleDiv('forgotPassworderrorText', true); 
        _toggleDiv('uplodInfoDiv', true);
        timer = null;
    }
    
    function getNumber(number)
    {
        var str ;
        
        if (number % 100 < 10)
        {
            str = Number2[number % 100];
            number = Math.floor(number/100);
        }
        else
        {
            if( (number % 10) == 0)
            {
                return Number3[number / 10];
            }
            else
            {
                if((number % 10) < 10)
                {
                    str = Number3[Math.floor(number / 10)];
                    number %=10;
                }
                else
                {
                    str = Number2[number % 10];
                    number = Math.floor(number/10);
                }
                
                if (number == 0) return str ;
                return str + " " + Number2[number] ;
            }
        }

        if (number == 0) return str;
        return Number2[number] + "hundred" + str;
    }

    function convert( number) 
    {
        if (number == 0)
        {
            return "zero";
        }

        var pre = "";
        var str1 = "";
        var i = 0;
        
        if((number > 10 && number < 19))
        {
            return Number4[ number % 10];
        }
        else
        {
            do 
            {
                var n = number % 100;
                
                if (n != 0)
                {
                    var s = getNumber(n);
                    str1 = s + Number1[i] + " " + str1;
                }
                
                i++;
                number = Math.floor(number/100);
            }while (number > 0);
        }

        return (pre + str1);
    }

    function checkCurrentPage(callback, param1, param2, param3)
    {
        //checking login
        checkLogin(checkCurrentPage1, callback, param1, param2, param3);
    }
    
    function checkCurrentPage1(callback, param1, param2, param3)
    {
        var url = new String(document.location);
        var lastIndex = url.lastIndexOf('/') + 1;
        var fileName;
        var showDiv = null;

        if(url.lastIndexOf('?') > 0)
        {
            fileName = url.substring(lastIndex, url.lastIndexOf('?')); 
        }
        else
        {
            fileName = url.substring(lastIndex, url.length); 
        }

        if(channelId == CHANNEL_WEB)
        {

            if(fileName == "home.html")
            {
                var imageId = document.getElementById("homeImage");
                imageId.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/home_sel.jpg";
                curPageIdx = HOMEIDX;
            }
            else if(fileName == "podcast.html")
            {
                var imageId = document.getElementById("podcastImage");
                imageId.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/podcasts_sel.jpg";
                curPageIdx = PODCASTIDX;            
            }
            else if(fileName == "contestinfo.html")
            {
                var imageId = document.getElementById("contestinfoImage");
                imageId.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/contest_info_sel.jpg";
                curPageIdx = CONTESTIDX;            
            }
            else if(fileName == "myvideos.html")
            {
                var imageId = document.getElementById("viewImage");
                imageId.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/views_sel.jpg";
                curPageIdx = SUBMISSIONIDX;            
            }
            else if(fileName == "checklist.html")
            {
                var imageId = document.getElementById("ProductFavoriteImage");
                imageId.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/shop_featured_products_sel.png";
                curPageIdx = PRODUCTFAVORITE;
            }
            //var userName = checkLogin();
            var innerHtml;

            if(userName)
            {
                innerHtml = '<font class="mainTabItemFontBlack">Welcome&nbsp;'+userName+'&nbsp;</font>'+
                                    '<font class="mainTabItemFontRed">(<a href="javascript:false" onclick="logoutUser();return false;" class="mainTabItemFontRed underline">Logout</a>)</font>&nbsp;&nbsp;';            
            }
            else
            {
                innerHtml = '<font class="mainTabItemFontBlack">Welcome,&nbsp;</font>'+
                                    '<a href="contestinfo.html?div_id=1"><font class="mainTabItemFontRed underline">Login</font></a>&nbsp;&nbsp;&nbsp;';
                                    // removed login for stage 2
                                    /*'<font class="mainTabItemFontBlack">&nbsp;or&nbsp;</font>'+
                                    '<a href="contestinfo.html?div_id=2"><font class="mainTabItemFontRed underline">Register</font></a>&nbsp;&nbsp;'; */
            }

            var loginhead = document.getElementById("loginhead");
            loginhead.innerHTML = innerHtml;
        }
        else if(channelId == CHANNEL_FACEBOOK)
        {
            var pageIdx = 0;
            var qs = new Querystring();

            prevEntryId = qs.get('entry_id'); 
            pageIdx = qs.get('pageidx'); 
            var tabId = qs.get('tabid'); 
            prevPageIdx = pageIdx;
            curSharePageIdx = pageIdx; 
            
            if(fileName == "kicappshareforms.html")
            {
                curPageIdx = APP_SHAREIDX;
                isSTW = qs.get('isSTW');
                isContestInfo = qs.get('isContestInfo');
                if(isContestInfo)
                {
                    var shareFormheading = document.getElementById("sentEmailHeading");
                    shareFormheading.innerHTML = "Share This Contest";
                }                
            }
             showDiv = qs.get('divid');
            
            if(fileName == "kicappcontestinfo.html" || pageIdx == APP_CONTESTIDX)
            {
                var imageId = document.getElementById("contestImage");
                imageId.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/appimages/button_contest_info_sel.jpg";
                curPageIdx = (fileName == "kicappcontestinfo.html" ? APP_CONTESTIDX : curPageIdx);
            }
            else if(fileName == "kicapppodcast.html" || pageIdx == APP_PODCASTIDX)
            {
                var imageId = document.getElementById("podcastImage");
                imageId.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/appimages/button_view_pod_sel.jpg";
                curPageIdx =(fileName == "kicapppodcast.html" ? APP_PODCASTIDX : curPageIdx);
            }
            else if(fileName == "kicappsubmission.html" || pageIdx == APP_SUBMISSIONIDX)
            {
                var imageId = document.getElementById("submissionImage");
                imageId.src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/appimages/button_view_sub_sel.jpg";
                if(fileName == "kicappsubmission.html")
                {
                    curPageIdx = APP_SUBMISSIONIDX;
                    if(showDiv)
                    {
                        loadDefaultSubmission = false;
                    }
                }
            }

            if(showDiv)
            {
                if(curPageIdx == APP_SHAREIDX)
                {
                    currentEntryId = prevEntryId;
                    //curTabSubmission =  tabId;
                }
                setCurrent(curPageIdx, true, showDiv, (fileName == "kicappcontestinfo.html" ? 1 : null));
            }
        }

        if(callback)
        {
            if(!(fileName == "kicappcontestinfo.html" && showDiv))
            {
                callback(param1, param2, param3);
            }
        }    
    }

    function _toggleDiv(elid, showDiv, fncbk)
    {
        var el = document.getElementById(elid);
        if(el != null)
        {
            if (showDiv)
            {
                el.style.display = 'block'; 
            }
            else
            {
                el.style.display = 'none'; 
            }
        }

        if(fncbk)
        {
            fncbk();
        }
    }

    function submitForm(id) // Remove this if not needed
    {
        var form = document.getElementById(id);     

        if(submitForm)
        {
            form.submit();
        }
    }

    function getHtmlSnippet(tagId, fileUrl)
    {
        var html= "";
        if (fileUrl && tagId == "_idCurItem")
        {
            var flashvars = null;
            if(channelId == CHANNEL_WEB)
            {
                if(!swfobject.getFlashPlayerVersion().major ||swfobject.getFlashPlayerVersion().major<9)
                {
                     html = "<div class='welcomeContentsubHeadingFontRed' align='center'>Flash Player version 9 or greater is required. Click <a href='http://get.adobe.com/flashplayer' class='underline welcomeContentsubHeadingFontRed'>here</a> to install it.</div>";
                }
                else
                {
                    flashvars = "videourl=" + fileUrl;
                    html = getPlayerHtml("_idMediaPlayer", 496, 415, 'http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/player_491x368_496x415_3.swf', null, false, flashvars, flashvars);
                    pageTracker._trackPageview('web/viewVideo?entry_id='+currentEntryId);
                }
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                if(!swfobject.getFlashPlayerVersion().major ||swfobject.getFlashPlayerVersion().major<9)
                {
                     html = "<div class='redTextColor arial12' align='center'>Flash Player version 9 or greater is required. Click <a href='http://get.adobe.com/flashplayer' class='underline welcomeContentsubHeadingFontRed'>here</a> to install it.</div>";
                }
                else
                {
                    var url = 'http://'+document.domain+'/mc/static';
                    html = getEntryHtml("_idMediaPlayer", 253, 190, 253, 190, fileUrl, url, MEDIATYPE_VIDEO, "border='1'", false, null);
                    pageTracker._trackPageview('facebook/viewVideo?entry_id='+currentEntryId);
                }
            }
        }
        return html;
    }

    function Class_Base()
    {
    }

    Class_Base.prototype.currentSnippets;

    Class_Base.prototype._setCurrent = function(fileurl, label, description)
    {
        var curItem = document.getElementById("_idCurItem");
        if(curItem &&  fileurl)
        {
            curItem.innerHTML = getHtmlSnippet("_idCurItem", fileurl);
        }

        curItem = document.getElementById("_idCurItemTitle");
        if(curItem && label)
        {
            curItem.innerHTML = label;
        } 
        else if(curItem)
        {
            curItem.innerHTML = "";
        }

        curItem = document.getElementById("_idCurItemDesc");
        if(curItem &&  description)
        {
            curItem.innerHTML = description;
        }    
        else if(curItem)
        {
            curItem.innerHTML = "";
        }
    }

    function updateViews(afterUpdateFn)
    {
        var afterUpload = function(result)
        {
            var response = parseResult(result);
            var responseMessage = response["X-Skava-ResponseMessage"];
            var responseCode = response["X-Skava-ResponseCode"]; 
            afterUpdateFn();
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = serverprefix + "/mc/social";
        var queryParamString = "?campaign_id=" + campaignId +
            "&X-Skava-Authorization=" + escape(auth[campaignId]) + 
            "&variableresponse=1" + 
            "&op=view"+ 
            "&entry_id="+currentEntryId;
        
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk); 
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function showUploadAlert()
    {
        if(!uploadalert || (uploadalert == null))
        {
            var qs = new Querystring();
            uploadalert = qs.get('showuploadalert'); 
        }
        
        if(uploadalert && uploadalert == 'true')
        {
            uploadalert = 'false';
            if(channelId == CHANNEL_WEB)
            {
                showMyVideos();
                _toggleDiv('uploadVideoSubTr', true);
                _toggleDiv('uplodAlert', true);
                pageTracker._trackPageview('web/upload');                
            }
            else(channelId == CHANNEL_WEB)
            {
                pageTracker._trackPageview('facebook/upload');
            }            
        } 
    }

    function loadLatestPodcastData()
    {
        var afterUpload = function(result)
        {
            latestPodcastEntries = JSON.parse(result);
            parentPath = latestPodcastEntries.parentpath;
            socialUrls = latestPodcastEntries.socialurls;
            extraParams = latestPodcastEntries.extraParams;
            latestPodcastEntries = JSON.parse(latestPodcastEntries.entries);
            var innerHtml = '<table class="latestPodCastsImages" cellspacing="0" cellpadding="0"><tr>';
            
            for(id=0; latestPodcastEntries && id < latestPodcastEntries.length && latestPodcastEntries[id]; id++)
            {
                if(latestPodcastEntries[id][0])
                {
                    //var aTag = '<a href="javascript:false" onclick="setCurrent('+HOMEIDX+', false, null, null, latestPodcastEntries['+id+'][0], \''+parentPath+'\');return false;">';
                    var aTag = '<a href="podcast.html?entry_id='+latestPodcastEntries[id][0].entry_id+'">';
                    
                    innerHtml += '<td class="latestPodCastsThumbsTD alignTop">'+
                                        '<table class="latestPodCastsSingleItemTable"  cellspacing="0" cellpadding="0">'+
                                        '<tr><td class="latestPodCastsThumbsImagesTD">'+
                                        aTag + '<img class="imgBorder latestPodcastIconSize" src="'+latestPodcastEntries[id][0].entry_iconurl+'"></img></a>'+
                                        '</td></tr>'+
                                        '<tr><td><font class="latestPodCastsSingleItemFontRed">&nbsp;</font></tr></td>'+
                                        '<tr><td>'+
                                        aTag +
                                        '<font class="latestPodCastsSingleItemFontRed underline textBold">'+doWhiteSpaceEncode(latestPodcastEntries[id][0].entry_label1, 45, 10)+'</font></a>'+
                                        '</td></tr>'+
                                        '<tr><td>'+
                                        '<div class="latestPodCastsSingleItemFontBlack textBold" style="width:115px;overflow:auto;">' +doWhiteSpaceEncode(latestPodcastEntries[id][0].entry_comment, 80, 10)+'</div>'+
                                        '</td></tr>'+
                                        '</table></td>';
                
                    if(id < (latestPodcastEntries.length-1))
                    {
                        innerHtml += '<td><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/horozontalLine.jpg"></img></td>';
                    }
                }    
            }                       
                                    
            innerHtml += '</tr></table>';
            var node = document.getElementById('latestpodcast');

            if(node != null)
            {
                node.innerHTML = innerHtml;                
            }

            loadWelcomeVideo();
            //setCurrent(1, false, null, null, latestPodcastEntries[0][0], parentPath);
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=latestpodcasts"+
            "&numentry=3";
    
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk)
    }

    function loadPodcastData()
    {
        var afterUpload = function(result)
        {            
            if(result)
            {
                podcastEntries = JSON.parse(result);
                parentPath = podcastEntries.parentpath;
                socialUrls = podcastEntries.socialurls;
                extraParams =podcastEntries.extraParams;
            }    

            if(podcastEntries && podcastEntries.entries)
            {
                podcastEntries = JSON.parse(podcastEntries.entries);
            }
            
            var qs = new Querystring();
            var entryId = qs.get('entry_id'); 
            if(!entryId)
            {
                entryId = qs.get('fbshare_id');
            }
            
            if(channelId == CHANNEL_WEB)
            {
                var innerHtml = '<table class="fullwidth" cellspacing="0" cellpadding="5">';    
                var podcastEntry = 0;

                for(id=0; podcastEntries && id < podcastEntries.length; id++)
                {
                    innerHtml += '<tr><td class="fullwidth horozontalLine">'+
                                        '<table class="podCastsTableTDContentsTable" cellspacing="0" cellpadding="5">'+
                                        '<tr><td class="latestVideoThumbs">' +
                                        '<a href="#" onclick="setCurrent('+PODCASTIDX+', true, null, null, podcastEntries['+id+'][0], \''+parentPath+'\', podcastEntries['+id+']);return false;"><img class="imgBorder latestPodcastIconSize" src="'+podcastEntries[id][0].entry_iconurl+'"></img></a>' +
                                        '</td><td class="latestVideoDiscription">' +
                                        '<table cellspacing="0" cellpadding="0">' +
                                        '<tr><td><a href="#" onclick="setCurrent('+PODCASTIDX+', true, null, null, podcastEntries['+id+'][0], \''+parentPath+'\', podcastEntries['+id+']);return false;"><font class="latestPodCastsSingleItemFontRed underline textBold">'+getDisplayText(podcastEntries[id][0].entry_label1, 20)+'</font>' +
                                        '</td></tr><tr><td>'+
                                        '<font class="latestPodCastsSingleItemFontBlack textBold">'+doWhiteSpaceEncode(podcastEntries[id][0].entry_comment, 80)+'</font>' +
                                        '</td></tr></table></td></tr>'+
                                        '</table></td></tr>';
                }                      

                innerHtml += '</table>';
                var node = document.getElementById('allpodcasts');
                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }
                hideSignIn();            

                if(entryId && entryId != 0)
                {
                    for(id=0; id < podcastEntries.length; id++)
                    {
                        if(entryId == podcastEntries[id][0].entry_id)
                        {
                            podcastEntry = id;
                            break;
                        }
                    }
                }
                if(podcastEntries && podcastEntries[podcastEntry])
                {
                    setCurrent(PODCASTIDX, false, null, null, podcastEntries[podcastEntry][0], parentPath, podcastEntries[podcastEntry]);
                }    
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                
                var appQueryParamEntryid = null;                
                if(entryId && entryId != 0)
                {
                    for(var id=0; podcastEntries && id < podcastEntries.length; id++)
                    {
                        if(entryId == podcastEntries[id][0].entry_id)
                        {
                            appQueryParamEntryid = id;
                            break;
                        }
                    }
                }
                
                if(podcastEntries && podcastEntries[0] && podcastEntries[0][0])
                {
                    if(!appQueryParamEntryid)
                    {
                        appQueryParamEntryid = 0;
                    }
                    setCurrent(APP_PODCASTIDX, false, null, null, podcastEntries[appQueryParamEntryid][0]);
                } 
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=allpodcasts";
    
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function loadWelcomeVideo(isContestInfo)
    {
        var afterUpload = function(result)
        {            
            welcomeVideoEntry = JSON.parse(result);
            welcomeVideoEntry = JSON.parse(welcomeVideoEntry.entries);
        
            var afterLoadData = function()
            {
                if(isContestInfo)
                {                
                    var loadAfterOrnament = function()
                    {
                       setCurrent(CONTESTIDX, false, null, null, welcomeVideoEntry[0][1], null, welcomeVideoEntry[0][1]);
                    }
                    loadOrnament(loadAfterOrnament);
                }
                else
                {
                    setCurrent(HOMEIDX, false, null, null, welcomeVideoEntry[0][0], null, welcomeVideoEntry[0][0]);
                }
            }

            //loadSubmissionData(isContestInfo, afterLoadData);//for stage 3
            loadShotrlistedUserVideos(isContestInfo, afterLoadData);
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString=  "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=homevideo"+
            "&bundle_entryPath=/"+bundleNames[KIC_WELCOME_VIDEO_TAB_IDX];

        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function loadComments(entryId, startIdx, isFirstTime)
    {
        if(!startIdx)
        {
            startIdx = 0;
        }

        if(channelId == CHANNEL_FACEBOOK && !entryId)
        {
            entryId = currentEntryId;
        }
        
        var numItems ;
        var afterUpload = function(result)
        {  
            if(result) 
            {
                comments = JSON.parse(result);
                numItems = comments.ratingsStats;
                if(comments.stats)
                {
                    stats = JSON.parse(comments.stats);
                }
                if(comments.ratings)
                {
                    comments= JSON.parse(comments.ratings);   
                }
            }

            if(channelId == CHANNEL_WEB)
            {
                if(!isFirstTime || isFirstTime == false)
                {
                    var ratingSub = document.getElementById("ratingSub");
                    if(ratingSub)
                    {
                        if(stats && stats[0])
                        {
                            var flr = Math.floor(stats[0][0].entrystats_avgrating);
                            var rnd = Math.round(stats[0][0].entrystats_avgrating);
                            var numraters = (stats[0][0].entrystats_sknumraters + stats[0][0].entrystats_ytnumraters);
                            
                            ratingSub.innerHTML = "<font class='myriadPro11 textBold'>Overall Rating&nbsp;</font><img src='http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/star_rating"+(flr + (flr == rnd ? "0" : "5"))+".jpg'></img><font class='myriadPro11 textBold'>("+numraters+")</font>";
                        }
                        else
                        {
                            ratingSub.innerHTML = "<font class='myriadPro11 textBold'>Overall Rating&nbsp;</font><img src='http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/star_rating00.jpg'></img><font class='myriadPro11 textBold'>(0)</font>";  
                        }
                    }
                    
                    //var userRatingSub = document.getElementById("userRatingSub");
                    if(ratingSub)
                    {
                        var userid = getUserId();

                        var loggedUserRating = null;
                        if(userid && userid > 0 && comments && comments[0])
                        {
                            for(var i=0;i<comments[0].length; i++)
                            {
                                if(comments[0][i].rating_userid == userid)
                                {
                                    loggedUserRating = comments[0][i];
                                    break;
                                }
                            }
                        }    
                    }   
                }
                var innerHtml = '<div class="commentDiv"><table class="fullWidth" cellspacing="0" cellpadding="0"  border="0">';
                var commentPageIdx = '';
                var statusHtml = '';
                
                if(comments && comments[0])
                {
                    var commentPageIdx = '<font class="commentStatusBoxFont">'+(startIdx+1) +' - '+((startIdx+5) > numItems ? numItems : startIdx+5)+' of '+numItems+' Comments</font>';
                    
                    for(id= 0; id <  comments[0].length; id++)
                    {
                        var commentUserString = comments[0][id].rating_username;
                        var reviewString = comments[0][id].rating_review;
                        
                        innerHtml += '<tr><td class="commentItemsBoxSingleComment ">'+
                                            '<table class="commentsWidth2 commentItemsBoxSingleCommentItem" cellspacing="0" cellpadding="0"><tr>' +
                                            '<td class="commentsWidth2"><font class="commentStatusUserNameFont textBold">'+htmlEncode(commentUserString)+'</font></td><td align="right">'+
                                            '<a href="#" onclick="reportAbuse(\''+escape(htmlEncode(reviewString))+'\'); return false;"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/link_report_abuse.jpg"></img></a>'+
                                            '</td></tr><tr><td colspan="2">'+
                                            '<font class="commentStatusCommentFont textBold alignTop">'+((reviewString.length>0) ? doWhiteSpaceEncode(reviewString, null, 15): "")+'</font> '+
                                            '</td></tr>'+
                                            '</table></td></tr>';
                    }
                    innerHtml += '</table></div>';

                    statusHtml = '<table class="fullWidth commentStatusPageIndex commentStatusPageIndexHeight" cellspacing="0" cellpadding="0"><tr><td class="commentStatusBoxStatusLeft" ><font class="commentStatusPageIndexFont textBold">Page: </font>';

                    var statusstartIdx = 0;
                    
                    for(var i=0;i<=startIdx; i+=50)
                    {
                        statusstartIdx = i/50;
                    }
                    
                    statusstartIdx = statusstartIdx*10;
                    
                    var totalstatusIdx = numItems/5;
                    
                    if(statusstartIdx > 0)
                    {
                        statusHtml += '<a href="javascript:false" onclick="loadComments('+entryId+','+((statusstartIdx-10)*5)+','+true+'); return false;"><font class="commentStatusPageIndexFont underline">&lt;&lt;</font>&nbsp;</a>';
                    }
                    var selectedidx = 0;
                    for(i=statusstartIdx; i<totalstatusIdx && i < statusstartIdx+10; i++)
                    {
                        if(i == (startIdx/5))
                        {
                            selectedidx = i;
                            statusHtml += '<font class="commentStatusPageIndexFont textBold">'+(i+1)+'</font>&nbsp;';
                        }
                        else
                        {
                            statusHtml += '<a href="#" onclick="loadComments('+entryId +','+(i*5)+','+true+'); return false;"><font class="commentStatusPageIndexFont underline">'+(i+1)+'</font>&nbsp;</a>';
                        }
                    }

                    if((statusstartIdx+10) < totalstatusIdx)
                    {
                        statusHtml += '<a href="javascript:false" onclick="loadComments('+entryId +','+((statusstartIdx+10)*5)+','+true+'); return false;"><font class="commentStatusPageIndexFont underline">&gt;&gt;</font>&nbsp;</a>';
                    }
                    
                    statusHtml += '</td><td class="commentStatusBoxStatusActionRight">';
                    if(selectedidx > 0)
                    {
                        statusHtml += '<a href="javascript:false" onclick="loadComments('+entryId+','+((selectedidx-1)*5)+','+true+'); return false;"><font class="commentStatusPageIndexFont underline">previous</font></a>&nbsp;&nbsp;&nbsp;';
                    }            

                    if(selectedidx+1 < totalstatusIdx)
                    {
                        statusHtml += '<a href="javascript:false" onclick="loadComments('+entryId+','+((selectedidx+1)*5)+','+true+'); return false;"><font class="commentStatusPageIndexFont underline">next</font></a>';
                    }
                    statusHtml +='</td></tr></table>';
                }
                else
                {
                    innerHtml += '<tr><td class="noComments"><font class="commentsWidth commentStatusUserNameFont textBold">No Comments posted yet.</font></td></tr>';
                    statusHtml = '&nbsp;';
                    commentPageIdx = '&nbsp;';
                }
                
                var node = document.getElementById('commentsPodcast');
                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }

                var node2 = document.getElementById("commentPageIdx");
                if(node2 && commentPageIdx)
                {
                    node2.innerHTML = commentPageIdx;
                }

                var node3 = document.getElementById('commentBoxStatus');
                if(node3 && statusHtml)
                {
                    node3.innerHTML = statusHtml;
                }   
                    
                loadOrnament(); // timing issue -network call
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                var innerHtml = '<div class="commentBoxDim overflowScroll borderTop"><table cellpadding="0" cellspacing="0">';
                var commentPageIdx = '';
                var statusHtml = '';
                
                statusHtml = '<font class="myriadPro10 textBold color6">Pages: ';
                
                var statusstartIdx = 0;
                        
                for(var i=0;i<=startIdx; i+=(numCommentIdx * numCommentsInPage))
                {
                    statusstartIdx = i/(numCommentIdx * numCommentsInPage);
                }
                
                statusstartIdx = statusstartIdx*numCommentIdx;
                
                var totalstatusIdx = numItems/numCommentsInPage;

                 if(statusstartIdx > 0)
                {
                    statusHtml += '</font><a href="javascript:false" onclick="loadComments(null, '+((statusstartIdx-numCommentIdx)*numCommentsInPage)+'); return false;" class="myriadPro10 textBold color6 noDecorations">&lt;&lt;</a>&nbsp;';
                }
                var selectedidx = 0;
                for(i=statusstartIdx; i<totalstatusIdx && i < statusstartIdx+numCommentIdx; i++)
                {
                    if(i == (startIdx/numCommentsInPage))
                    {
                        selectedidx = i;
                        statusHtml += '<font class="myriadPro10 textBold color6">'+(i+1)+'</font>&nbsp;';
                    }
                    else
                    {
                        statusHtml += '<a href="#" onclick="loadComments(null, '+(i*numCommentsInPage)+'); return false;" class="myriadPro10 textBold color6 underline">'+(i+1)+'</a>&nbsp;';
                    }
                }

                if((statusstartIdx+numCommentIdx) < totalstatusIdx)
                {
                    statusHtml += '<a href="javascript:false" onclick="loadComments(null,'+((statusstartIdx+numCommentIdx)*numCommentsInPage)+'); return false;" class="myriadPro10 textBold color6 noDecorations">&gt;&gt;</a>&nbsp;';
                }
                if(comments && comments[0])
                {
                    var commentPageIdx = '<font class="myriadPro10 textBold color6">Showing '+(startIdx+1) +' - '+((startIdx+numCommentsInPage) > numItems ? numItems : startIdx+numCommentsInPage)+' of '+numItems+' Comments</font>';
                    
                    for(id= 0; id <  comments[0].length; id++)
                    {
                        var commentUserString = comments[0][id].rating_username;
                        var reviewString = comments[0][id].rating_review;
                        innerHtml += '<tr><td class="borderBottom"><table cellpadding="0" cellspacing="0"><tr><td class="innerPageWidth arial11 redTextColor leftPadding8">'+
                            htmlEncode(commentUserString)+'</td></tr><tr><td class="arial11 color6 leftPadding8 topPadding1 bottomPadding1">'+((reviewString.length>0) ? doWhiteSpaceEncode(reviewString, null, 35): "")+'</td></tr></table></td></tr>';
                    }
                    innerHtml += '</table></div>';
                }
                else
                {
                    innerHtml += '<tr><td class="arial11 redTextColor textBold leftPadding8">No Comments posted yet.</font></td></tr>';
                    commentPageIdx = '&nbsp';
                    statusHtml = '&nbsp';
                }
                
                var node = document.getElementById('commentsPodcast');
                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }
                
                var node1 = document.getElementById('commentPageIdx');
                if(node1 != null)
                {
                    node1.innerHTML = commentPageIdx;
                }

                var node2 = document.getElementById('commentBoxStatus');
                if(node2 && statusHtml)
                {
                    node2.innerHTML = statusHtml;
                }   
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?entry_id="+entryId+
            "&campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=ratingsandstats" +
            "&ratstartIdx="+startIdx;
        
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }


    function loadSubmissionData(loadDefaultEntry, callbck, bundleEntryPath, curEntryId)
    {        
        var entryId = null;
        if(!bundleEntryPath)
        {
            entryId = parseInt(qs.get('entry_id')); 
            if(!entryId)
            {
                entryId = parseInt(qs.get('fbshare_id'));
            }
        }    
        var appQueryParamEntryid = 0;
                
        var afterUpload = function(result)
        {
            if(result)
            {
                latestSubmissionEntries = JSON.parse(result);  
            }
            parentPath = null;
            if(latestSubmissionEntries)
            {
                userNames = latestSubmissionEntries.usernames;
                parentPath = latestSubmissionEntries.parentpath;
                nextPrevPaths = latestSubmissionEntries.nextprevpaths;
                socialUrls = latestSubmissionEntries.socialurls;        
                usernamesSubmission = latestSubmissionEntries.usernames;  
                extraParams = latestSubmissionEntries.extraParams;
                ratings = JSON.parse(latestSubmissionEntries.entrystats);
                
                if(latestSubmissionEntries.entrystats)
                {
                    stats = JSON.parse(latestSubmissionEntries.entrystats);
                }    

                if(latestSubmissionEntries.entries)
                {
                    latestSubmissionEntries = JSON.parse(latestSubmissionEntries.entries);  
                }    
            
            }

            if(channelId == CHANNEL_WEB)
            {
                var innerHtml = '<div  class="latestVideoSubmissionDiv">'+
                                            '<table class="latestVideoListTable" cellspacing="0" cellpadding="0">';            
                    
                for(id=0; latestSubmissionEntries && latestSubmissionEntries[0] && id < latestSubmissionEntries[0].length; id++)
                {
                    var flr = Math.floor(stats[0][id].entrystats_avgrating);
                    var rnd = Math.round(stats[0][id].entrystats_avgrating);
                    
                    innerHtml += '<tr>'+
                                            '<td class="">'+ /* removed the boder style (class latestVideoListTableTD) for case 11699*/
                                                '<table class="latestVideoSingleItemsTable" cellspacing="0" cellpadding="0">'+
                                                    '<tr>'+
                                                        '<td class="latestVideoListTableTD">'+
                                                            '<table class="latestVideoSingleItemsTable leftPadding5" cellspacing="0" cellpadding="0">'+
                                                                '<tr>'+
                                                                    '<td class="latestVideoThumbs">'+
                                                                        //'<a href="javascript:false" onclick="setCurrent('+HOMEIDX+', false, null, null, latestSubmissionEntries[0]['+id+'], \''+parentPath+'\');return false;"><img class="imgBorder latestPodcastIconSize" src="'+latestSubmissionEntries[0][id].entry_iconurl+'"></img></a>'+
                                                                        '<a href="myvideos.html?entry_id='+latestSubmissionEntries[0][id].entry_id+'"><img class="imgBorder latestPodcastIconSize" src="'+latestSubmissionEntries[0][id].entry_iconurl+'"></img></a>'+
                                                                    '</td>'+
                                                                    '<td class="latestVideoDiscription">'+
                                                                        '<table cellspacing="0" cellpadding="0">'+
                                                                            '<tr>'+
                                                                                '<td>'+
                                                                                    //'<a href="javascript:false" onclick="setCurrent('+HOMEIDX+', false, null, null, latestSubmissionEntries[0]['+id+'], \''+parentPath+'\');return false;">'+
                                                                                    '<a href="myvideos.html?entry_id='+latestSubmissionEntries[0][id].entry_id+'">'+
                                                                                    '<font class="latestPodCastsSingleItemFontRed underline textBold">'+getDisplayText(latestSubmissionEntries[0][id].entry_label1, 20)+'</font></a>'+
                                                                                '</td>'+
                                                                            '</tr>'+
                                                                            '<tr>'+
                                                                                '<td>'+
                                                                                    '<font class="latestPodCastsSingleItemFontBlack">'+doWhiteSpaceEncode(latestSubmissionEntries[0][id].entry_comment, 80)+'</font>'+
                                                                                '</td>'+
                                                                            '</tr>'+
                                                                            '<tr>'+
                                                                                '<td>'+
                                                                                '<font class="latestPodCastsSingleItemFontBlack textBold">Submitted By:&nbsp;</font><font class="latestPodCastsSingleItemFontRed textBold">'+getDisplayText(userNames[id], 10, true)+'</font>'+
                                                                            '</td>'+
                                                                        '</tr>'+            
                                                                            '<tr>'+
                                                                                '<td class="topPadding7">'+
                                                                                    '<img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/star_rating'+(flr + (flr == rnd ? "0" : "5"))+'.jpg"></img>'+
                                                                                '</td>'+
                                                                            '</tr>'+                                                                                            
                                                                        '</table>'+
                                                                    '</td>'+
                                                                '</tr>'+
                                                            '</table>'+
                                                        '</td>'+
                                                    '</tr>'+
                                                '</table>'+
                                            '</td>'+
                                        '</tr>';                
                }                       
                                        
                innerHtml += '</div></table>';
                var node = document.getElementById('latestVideoSubmissionData');
                
                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }

                if(loadDefaultEntry)
                {
                    hideSignIn();
                }

                if(callbck)
                {
                    callbck();
                }    
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                allVideoPagination = nextPrevPaths;
                
                if((entryId && entryId != 0) ||  currentEntryIdOtherVideos != 0 || curEntryId)
                {
                    if(currentEntryIdOtherVideos != 0)
                    {
                        entryId = currentEntryIdOtherVideos;
                    }
                    
                    if(curEntryId)
                    {
                        entryId = curEntryId;
                    }
                    for(var id=0; latestSubmissionEntries && id < latestSubmissionEntries[0].length; id++)
                    {
                        if(entryId == latestSubmissionEntries[0][id].entry_id)
                        {
                            appQueryParamEntryid = id;
                            break;
                        }
                    }
                }
                
                if(latestSubmissionEntries && latestSubmissionEntries[0] && latestSubmissionEntries[0][0])
                {
                    if(loadDefaultSubmission)
                    {
                        // if bundle entry path is present then we set the next and previous path for pagination on same page. so we set the prev/next page start idx there itself else want to find from entry_id
                        //setCurrent(APP_SUBMISSIONIDX,  false, null, null, latestSubmissionEntries[0][appQueryParamEntryid], appQueryParamEntryid, -1, null, (bundleEntryPath ? true: null)); // this is not a default division for stage 3
                        setCurrent(APP_SUBMISSIONIDX,  false, null, null , latestSubmissionEntries[0][appQueryParamEntryid], appQueryParamEntryid, -1, subTabsArr[1], (bundleEntryPath ? true: null));
                    }
                }
                else
                {
                    displaySubmissionData(-1);
                }
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=latestsubmission";
        
        if(entryId)
        {
            queryParamString += "&entry_id="+entryId;
        }

        if(bundleEntryPath)
        {
            queryParamString += "&bundle_entryPath=/"+bundleEntryPath;
        }
        else
        {
            queryParamString += "&bundle_entryPath=/"+bundleNames[LATEST_VIDEO_SUBMISSIONS_TAB_IDX];
        }    

        if(curEntryId)
        {
             queryParamString += "&entry_id="+curEntryId;
        }
        
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function loadShotrlistedUserVideos(loadDefaultEntry, callbck, bundleEntryPath, curEntryId) // for stage 3 and 4
    {
        var entryId = null;
        if(!bundleEntryPath)
        {
            entryId = parseInt(qs.get('entry_id')); 
            if(!entryId)
            {
                entryId = parseInt(qs.get('fbshare_id'));
            }
        }
        var appQueryParamEntryid = 0;
        var afterUpload = function(result)
        {
            if(result)
            {
                shortlistedData = JSON.parse(result);  
            }
            parentPath = null;
            if(shortlistedData)
            {
                userNames = shortlistedData.usernames;
                parentPath = shortlistedData.parentpath;
                nextPrevPaths = shortlistedData.nextprevpaths;
                socialUrls = shortlistedData.socialurls;        
                usernamesSubmission = shortlistedData.usernames;  
                extraParams = shortlistedData.extraParams;
            }

            if(shortlistedData && shortlistedData.entrystats)
            {
                stats = JSON.parse(shortlistedData.entrystats);
            }   

            if(shortlistedData && shortlistedData.entries)
            {
                shortlistedData = JSON.parse(shortlistedData.entries);  
            }  
            
            if(channelId == CHANNEL_WEB)
            {
                var innerHtml = '<div  class="latestVideoSubmissionDiv">'+
                                            '<table class="latestVideoListTable" cellspacing="0" cellpadding="0">';            
                    
                for(id=0; shortlistedData && shortlistedData[0] && id < shortlistedData[0].length; id++)
                {
                    var flr = Math.floor(stats[0][id].entrystats_avgrating);
                    var rnd = Math.round(stats[0][id].entrystats_avgrating);
                    
                    innerHtml += '<tr>'+
                                            '<td class="">'+ /* removed the boder style (class latestVideoListTableTD) for case 11699*/
                                                '<table class="latestVideoSingleItemsTable" cellspacing="0" cellpadding="0">'+
                                                    '<tr>'+
                                                        '<td class="latestVideoListTableTD">'+
                                                            '<table class="latestVideoSingleItemsTable leftPadding5" cellspacing="0" cellpadding="0">'+
                                                                '<tr>'+
                                                                    '<td class="latestVideoThumbs">'+
                                                                        //'<a href="javascript:false" onclick="setCurrent('+HOMEIDX+', false, null, null, shortlistedData[0]['+id+'], \''+parentPath+'\');return false;"><img class="imgBorder latestPodcastIconSize" src="'+shortlistedData[0][id].entry_iconurl+'"></img></a>'+
                                                                        '<a href="myvideos.html?entry_id='+shortlistedData[0][id].entry_id+'"><img class="imgBorder latestPodcastIconSize" src="'+shortlistedData[0][id].entry_iconurl+'"></img></a>'+
                                                                    '</td>'+
                                                                    '<td class="latestVideoDiscription">'+
                                                                        '<table cellspacing="0" cellpadding="0">'+
                                                                            '<tr>'+
                                                                                '<td>'+
                                                                                    //'<a href="javascript:false" onclick="setCurrent('+HOMEIDX+', false, null, null, shortlistedData[0]['+id+'], \''+parentPath+'\');return false;">'+
                                                                                    '<a href="myvideos.html?entry_id='+shortlistedData[0][id].entry_id+'">'+
                                                                                    '<font class="latestPodCastsSingleItemFontRed underline textBold">'+getDisplayText(shortlistedData[0][id].entry_label1, 20)+'</font></a>'+
                                                                                '</td>'+
                                                                            '</tr>'+
                                                                            '<tr>'+
                                                                                '<td>'+
                                                                                    '<font class="latestPodCastsSingleItemFontBlack">'+doWhiteSpaceEncode(shortlistedData[0][id].entry_comment, 80)+'</font>'+
                                                                                '</td>'+
                                                                            '</tr>'+
                                                                            '<tr>'+
                                                                                '<td>'+
                                                                                '<font class="latestPodCastsSingleItemFontBlack textBold">Submitted By:&nbsp;</font><font class="latestPodCastsSingleItemFontRed textBold">'+getDisplayText(userNames[id], 10, true)+'</font>'+
                                                                            '</td>'+
                                                                        '</tr>'+            
                                                                            '<tr>'+
                                                                                '<td class="topPadding7">'+
                                                                                    '<img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/star_rating'+(flr + (flr == rnd ? "0" : "5"))+'.jpg"></img>';

                                                                                    if(shortlistedData[0][id].entry_entryprops && shortlistedData[0][id].entry_entryprops.ct_prop_2)
                                                                                    {
                                                                                        innerHtml += '&nbsp;&nbsp;&nbsp;<font class="finalistBannerDim1 finalystDisp textBold alignCenter">&nbsp;';
                                                                                        if(shortlistedData[0][id].entry_entryprops.ct_prop_2 == ct_prop_grandprize)
                                                                                        {
                                                                                            innerHtml +='&nbsp;GRAND PRIZE WINNER&nbsp;'
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            innerHtml +='&nbsp;RUNNER UP WINNER&nbsp;'
                                                                                        }
                                                                                        innerHtml += '&nbsp;</font>'
                                                                                    }            

                                                innerHtml +=            '</td>'+
                                                                            '</tr>'+                                                                                            
                                                                        '</table>'+
                                                                    '</td>'+
                                                                '</tr>'+
                                                            '</table>'+
                                                        '</td>'+
                                                    '</tr>'+
                                                '</table>'+
                                            '</td>'+
                                        '</tr>';                
                }                       
                                        
                innerHtml += '</div></table>';
                var node = document.getElementById('finalistVideosData');
                
                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }

                if(loadDefaultEntry)
                {
                    hideSignIn();
                }

                if(callbck)
                {
                    callbck();
                }    
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                // adding for stage 4
                var tempEntriesGp = new Array();
                var tempEntriesRu = new Array();
                var j= 0; k = 0;
                for(var i = 0; i < shortlistedData[0].length; i++)
                {
                    if(shortlistedData[0][i].entry_entryprops.ct_prop_2 == ct_prop_grandprize)
                    {
                        tempEntriesGp[j] = shortlistedData[0][i];
                        j++;
                    }
                    else if(shortlistedData[0][i].entry_entryprops.ct_prop_2 == ct_prop_runnerup)
                    {
                        tempEntriesRu[k] = shortlistedData[0][i];
                        k++;
                    }
                }

                shortlistedData[0] = tempEntriesGp.concat(tempEntriesRu);

                if((entryId && entryId != 0) ||  currentEntryIdshortlistedVideos != 0 || curEntryId)
                {
                    if(currentEntryIdshortlistedVideos != 0)
                    {
                        entryId = currentEntryIdshortlistedVideos;
                    }
                    
                    if(curEntryId)
                    {
                        entryId = curEntryId;
                    }
                    for(var id=0; shortlistedData && id < shortlistedData[0].length; id++)
                    {
                        if(entryId == shortlistedData[0][id].entry_id)
                        {
                            appQueryParamEntryid = id;
                            break;
                        }
                    }
                }
                
                if(shortlistedData && shortlistedData[0] && shortlistedData[0][0])
                {
                    //if(shortlistedData)
                    {
                        // if bundle entry path is present then we set the next and previous path for pagination on same page. so we set the prev/next page start idx there itself else want to find from entry_id
                        setCurrent(APP_SUBMISSIONIDX,  false, null, null, shortlistedData[0][appQueryParamEntryid], appQueryParamEntryid, -1, subTabsArr[0], (bundleEntryPath ? true: null));
                    }
                }
                else
                {
                    displayShortlistedData(-1);
                }
            }
        }
        
        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=getwinner";

        if(entryId)
        {
            queryParamString += "&entry_id="+entryId;
        }

        if(bundleEntryPath)
        {
            queryParamString += "&bundle_entryPath=/"+bundleEntryPath;
        }
        else
        {
            //queryParamString += "&bundle_entryPath=/"+bundleNames[LATEST_VIDEO_SUBMISSIONS_TAB_IDX]; // for stage 3
            queryParamString += "&bundle_entryPath=/"+bundleNames[KIC_WINNER_VIDEO_TAB_IDX];
        }    

        if(curEntryId)
        {
             queryParamString += "&entry_id="+curEntryId;
        }
        
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }
    
    function loadMyVideos(bundlePath)
    {
        var myvideosdata = document.getElementById('myvideosdata');

        var appEntryid = 0;

        if(myvideosdata != null)
        {
            myvideosdata.innerHTML = "";
        }
        
        var afterUpload = function(result)
        {
            myVideos = JSON.parse(result);  
            parentPath = myVideos.parentpath;
            nextPrevPaths = myVideos.nextprevpaths;
            socialUrls = myVideos.socialurls;        
            usernamesSubmission = myVideos.usernames;
            extraParams = myVideos.extraParams;
            ratings = JSON.parse(myVideos.entrystats);
            
            myVideos = JSON.parse(myVideos.entries);  
            var innerHtml = ''; 

            if(channelId == CHANNEL_WEB)
            {
                
                if(myVideos && myVideos[0] && myVideos[0].length != 0)
                {
                    if(myVideos[0].length > 5)
                    {
                        innerHtml += '<div  class="overflowScroll allvideoDim">';
                    }
                    innerHtml += '<table class="fullWidth" cellspacing="0" cellpadding="0">'; 
                    
                    for(id=0; id < myVideos[0].length; id++)
                    {
                       var flr = Math.floor(ratings[0][id].entrystats_avgrating);
                       var rnd = Math.round(ratings[0][id].entrystats_avgrating);
                       
                       innerHtml += '<tr><td class="horozontalLine">'+
                                            '<table class="latestVideoSingleItemsTable" cellspacing="0" cellpadding="0">'+
                                            '<tr><td class="latestVideoThumbs"><a href="javascript:false" onclick="setCurrent('+SUBMISSIONIDX+',false, null, null, myVideos[0]['+id+'], \''+parentPath+'\');return false;">'+
                                            '<img class="imgBorder latestPodcastIconSize" src="'+myVideos[0][id].entry_iconurl+'"></img></a></td>'+
                                            '<td class="latestVideoDiscription">'+
                                            '<table cellspacing="0" cellpadding="0">'+
                                            '<tr><td><a href="javascript:false" onclick="setCurrent('+SUBMISSIONIDX+', false, null, null, myVideos[0]['+id+'], \''+parentPath+'\');return false;"><font class="latestPodCastsSingleItemFontRed underline">'+getDisplayText(myVideos[0][id].entry_label1, 20)+'</font></a></td></tr>'+
                                            '<tr><td><font class="latestPodCastsSingleItemFontBlack">'+doWhiteSpaceEncode(myVideos[0][id].entry_comment, 80)+'</font></td></tr>'+
                                            '<tr><td class="topPadding3"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/star_rating'+(flr + (flr == rnd ? "0" : "5"))+'.jpg"></img></td></tr>'+
                                            '</table>'+
                                            '</td><tr>'+
                                            '</table>'+
                                            '</td></tr>';
                    }         

                    innerHtml += '</table>';
                    
                    if(myVideos[0].length > 5)
                    {
                        innerHtml += '</div>';
                    }
                }      
                else
                {
                    innerHtml += '<table class="fullWidth fullHeight" cellspacing="0" cellpadding="0" valign="top">';
                    //change for stage 2 // innerHtml +='<tr><td class="fullWidth mainTabItemFontRed leftPadding5 topPadding5 bottomPadding3">You have not uploaded a video yet. Please use the "upload a video" option to upload your videos.</td></tr>';
                    innerHtml +='<tr><td class="fullWidth mainTabItemFontRed leftPadding5 topPadding5 bottomPadding3">You have not uploaded a video yet.</td></tr>';
                    innerHtml += '</table>';
                }

                setMyVideosLogin();
                /*var userName = checkLogin(); 
                
                if(userName)
                {
                    setMyVideos(4, userName);
                    if(!myVideos || !myVideos[0] || myVideos[0].length == 0)
                    {
                        _toggleDiv("spreadSubTr", false);
                    }
                }
                else
                {
                    setCurrent(SUBMISSIONIDX, true, 'loginCommonSubmissionTr', 3);
                    _toggleDiv("allVideosSubTr", false);
                    _toggleDiv("usernamesTr", false); 

                    hideUserAccessible();
                }*/
                
                if(myvideosdata != null)
                {
                    myvideosdata.innerHTML = innerHtml;
                }
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                if(currentEntryIdMyVideos != 0)
                {
                    for(var id=0; myVideos && id < myVideos[0].length; id++)
                    {
                        if(currentEntryIdMyVideos == myVideos[0][id].entry_id)
                        {
                            appEntryid = id;
                            break;
                        }
                    }
                }
                
                if(myVideos && myVideos[0] && myVideos[0].length != 0)
                {
                    setCurrent(APP_SUBMISSIONIDX, false, null, null, myVideos[0][appEntryid], appEntryid, -1, 'myVideosID');
                }
                else
                {
                    setCurrent(APP_SUBMISSIONIDX, true, "myVideosID", 1, null, null, -1, 'myVideosID');
//                    displayMyvideoData(startIdxMyVideos);
                }
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=myvideos";

        if(bundlePath)
        {
            queryParamString += "&bundle_entryPath=/"+bundlePath;
        }
        else
        {
            queryParamString += "&bundle_entryPath=/"+bundleNames[KIC_MY_VIDEO_TAB_IDX];
        }

        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

     function loadContestVideos(bundlePath)
    {
        var winnerdata = document.getElementById('winnerdata');

        var appEntryid = 0;

        if(winnerdata != null)
        {
            winnerdata.innerHTML = "";
        }
        
        var afterUpload = function(result)
        {
            winnerVideos = JSON.parse(result);  
            parentPath = winnerVideos.parentpath;
            nextPrevPaths = winnerVideos.nextprevpaths;
            socialUrls = winnerVideos.socialurls;        
            usernameWinners = winnerVideos.usernames;
            extraParams = winnerVideos.extraParams;
            ratings = JSON.parse(winnerVideos.entrystats);
            
            winnerVideos = JSON.parse(winnerVideos.entries);  
            var innerHtml = ''; 

            if(channelId == CHANNEL_WEB)
            {
                
                if(winnerVideos && winnerVideos[0] && winnerVideos[0].length != 0)
                {
                    if(winnerVideos[0].length > 5)
                    {
                        innerHtml += '<div  class="overflowScroll allvideoDim winnerBorder">';
                    }
                    innerHtml += '<table class="fullWidth" cellspacing="0" cellpadding="0">'; 
                    
                    for(id=0; id < winnerVideos[0].length; id++)
                    {
                       var flr = Math.floor(ratings[0][id].entrystats_avgrating);
                       var rnd = Math.round(ratings[0][id].entrystats_avgrating);
                       
                       innerHtml += '<tr><td class="horozontalLine">'+
                                            '<table class="latestVideoSingleItemsTable" cellspacing="0" cellpadding="0">'+
                                            '<tr><td class="latestVideoThumbs"><a href="javascript:false" onclick="setCurrent('+SUBMISSIONIDX+',false, null, null, winnerVideos[0]['+id+'], \''+parentPath+'\');return false;">'+
                                            '<img class="imgBorder latestPodcastIconSize" src="'+winnerVideos[0][id].entry_iconurl+'"></img></a></td>'+
                                            '<td class="latestVideoDiscription">'+
                                            '<table cellspacing="0" cellpadding="0">'+
                                            '<tr><td><a href="javascript:false" onclick="setCurrent('+SUBMISSIONIDX+', false, null, null, winnerVideos[0]['+id+'], \''+parentPath+'\');return false;"><font class="latestPodCastsSingleItemFontRed underline">'+getDisplayText(winnerVideos[0][id].entry_label1, 20)+'</font></a></td></tr>'+
                                            '<tr><td><font class="latestPodCastsSingleItemFontBlack">'+doWhiteSpaceEncode(winnerVideos[0][id].entry_comment, 80)+'</font></td></tr>'+
                                             '<tr><td><font class="latestPodCastsSingleItemFontBlack textBold">Submitted By:&nbsp;</font><font class="latestPodCastsSingleItemFontRed textBold">'+getDisplayText(usernameWinners[id], 10, true)+'</font></td></tr>'+
                                            '<tr><td class="topPadding3" class="finalistBannerDim1"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/star_rating'+(flr + (flr == rnd ? "0" : "5"))+'.jpg"></img>';

                                            if(winnerVideos[0][id].entry_entryprops && winnerVideos[0][id].entry_entryprops.ct_prop_2)
                                            {
                                                innerHtml += '&nbsp;&nbsp;&nbsp;<font class="finalistBannerDim1 finalystDisp textBold alignCenter fullWidth">&nbsp;';
                                                if(winnerVideos[0][id].entry_entryprops.ct_prop_2 == ct_prop_grandprize)
                                                {
                                                    innerHtml +='GRAND PRIZE WINNER'
                                                }
                                                else
                                                {
                                                    innerHtml +='RUNNER UP WINNER'
                                                }
                                                innerHtml += '&nbsp;</font>'
                                            }    
                                            
                        innerHtml += '</td></tr>'+
                                            '</table>'+
                                            '</td><tr>'+
                                            '</table>'+
                                            '</td></tr>';
                    }         

                    innerHtml += '</table>';
                    
                    if(winnerVideos[0].length > 5)
                    {
                        innerHtml += '</div>';
                    }
                }      
                else
                {
                    innerHtml += '<table class="fullWidth fullHeight" cellspacing="0" cellpadding="0" valign="top">';
                    innerHtml +='<tr><td class="fullWidth mainTabItemFontRed leftPadding5 topPadding5 bottomPadding3">You have not uploaded a video yet. Please use the "upload a video" option to upload your videos.</td></tr>';
                    innerHtml += '</table>';
                }

                if(winnerdata != null)
                {
                    winnerdata.innerHTML = innerHtml;
                }
                setCurrent(SUBMISSIONIDX, true, "winnerVideoSubTr", 3, winnerVideos[0][0]);
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                if(currentEntryIdMyVideos != 0)
                {
                    for(var id=0; winnerVideos && id < winnerVideos[0].length; id++)
                    {
                        if(currentEntryIdMyVideos == winnerVideos[0][id].entry_id)
                        {
                            appEntryid = id;
                            break;
                        }
                    }
                }
                
                if(myVideos && myVideos[0] && myVideos[0].length != 0)
                {
                    setCurrent(APP_SUBMISSIONIDX, false, null, null, myVideos[0][appEntryid], appEntryid, -1, 'myVideosID');
                }
                else
                {
                    setCurrent(APP_SUBMISSIONIDX, true, "myVideosID", 1, null, null, -1, 'myVideosID');
//                    displayMyvideoData(startIdxMyVideos);
                }
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };

        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId +
            '&method=getwinner';            

        if(bundlePath)
        {
            queryParamString += "&bundle_entryPath=/"+bundlePath;
        }
        else
        {
            queryParamString += "&bundle_entryPath=/"+bundleNames[KIC_WINNER_VIDEO_TAB_IDX];
        }

        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }


    function setMyVideosLogin()
    {
        //alert('setMyVideos');
        checkCurrentPage(setMyVideosLogin1);
    }
    
    function setMyVideosLogin1()
    {
        if(userName)
        {
            setMyVideos(4, userName);
            if(!myVideos || !myVideos[0] || myVideos[0].length == 0)
            {
                _toggleDiv("spreadSubTr", false);
            }
        }
        else
        {
            setCurrent(SUBMISSIONIDX, true, 'loginCommonSubmissionTr', 3);
            _toggleDiv("allVideosSubTr", false);
            _toggleDiv("usernamesTr", false); 
            _toggleDiv("winnerVideoSubTr", false);  // for stage 3
            
            hideUserAccessible();
        }
    }
    
    function loadAllVideos(searchString, sortBy, bundleEntryPath, isNotFirstTime, isPlayingVideo)
    {
        var qs = new Querystring();
        var entryId = qs.get('entry_id');

        if(!entryId)
        {
            entryId = qs.get('fbshare_id');
        }

        var afterUpload = function(result)
        {
            if(result)
            {
                allVideos = JSON.parse(result);  
                parentPath = allVideos.parentpath;
                socialUrls = allVideos.socialurls;        
                extraParams = allVideos.extraParams;
                userNames = allVideos.usernames;  
                nextPrevPaths = allVideos.nextprevpaths;  
            }
            else
            {
                allVideos = null;
            }
            
            if(allVideos && allVideos.entrystats)
            {
                ratings = JSON.parse(allVideos.entrystats);
            }

            if(allVideos && allVideos.entries)
            {
                allVideos = JSON.parse(allVideos.entries);  
            }    
            
            var selectentry =0;
            if(entryId && entryId > 0)
            {
                for(id=0; allVideos && allVideos[0] && id < allVideos[0].length; id++)
                {
                    if(entryId == allVideos[0][id].entry_id)
                    {
                        selectentry = id;
                        break;
                    }
                }
            }

            var innerHtml = '';
            if(channelId == CHANNEL_WEB)
            {
                if(allVideos && allVideos[0] && allVideos[0].length != 0)
                {
                    if(allVideos[0].length > 5)
                    {
                        innerHtml += '<div  class="overflowScroll allvideoDim">';
                    }
                    innerHtml += '<table class="fullWidth fulHeigh" cellspacing="0" cellpadding="0" valign="top">';           
                    var nextPageLink = '';
                    
                    if(nextPrevPaths && nextPrevPaths.length > 0)
                    {
                        nextPageLink += '<tr><td class="fullWidth"><table class="fullWidth" cellspacing="3" cellpadding="0"><tr>';
                        nextPageLink +='<td class="leftPadding10 rightPadding10 halfWidth" align="right">';
                        if(nextPrevPaths[0] != null)
                        {
                            nextPageLink += '<a href="javascript:false" onclick="loadAllVideos(\''+searchString+'\',\''+sortBy+'\',\''+nextPrevPaths[0]+'\', false, true); return false;"><font class="commentStatusPageIndexFont underline textBold">prev</font></a>&nbsp;&nbsp;&nbsp;';
                        }
                        if(nextPrevPaths[1])
                        {
                            nextPageLink += '<a href="javascript:false" onclick="loadAllVideos(\''+searchString+'\',\''+sortBy+'\',\''+nextPrevPaths[1]+'\', false, true); return false;"><font class="commentStatusPageIndexFont underline textBold">next</font></a>&nbsp;&nbsp;&nbsp;';
                        }
                        nextPageLink +='</td>';
                        nextPageLink += '</tr></table></td></tr>';
                    }

                    innerHtml += nextPageLink;

                    for(id=0; id < allVideos[0].length; id++)
                    {
                       var flr = Math.floor(ratings[0][id].entrystats_avgrating);
                       var rnd = Math.round(ratings[0][id].entrystats_avgrating);
                        
                       innerHtml += '<tr><td class="fullWidth horozontalLine"><table class="latestVideoSingleItemsTable" cellspacing="0" cellpadding="0">'+
                                            '<tr><td class="latestVideoThumbs"><a href="javascript:false" onclick="setCurrent('+SUBMISSIONIDX+', false, null, null, allVideos[0]['+id+'], \''+parentPath+'\');return false;"><img class="imgBorder latestPodcastIconSize" src="'+allVideos[0][id].entry_iconurl+'"></img></a></td>'+
                                            '<td class="latestVideoDiscription"><table cellspacing="0" cellpadding="0">'+
                                            '<tr><td><a href="javascript:false" onclick="setCurrent('+SUBMISSIONIDX+', false, null, null, allVideos[0]['+id+'], \''+parentPath+'\');return false;"><font class="latestPodCastsSingleItemFontRed underline">'+getDisplayText(allVideos[0][id].entry_label1, 20)+'</font></a></td></tr>'+
                                            '<tr><td><font class="latestPodCastsSingleItemFontBlack">'+doWhiteSpaceEncode(allVideos[0][id].entry_comment, 80)+'</font></td></tr>'+
                                            '<tr><td><font class="latestPodCastsSingleItemFontBlack textBold">Submitted By:&nbsp;</font><font class="latestPodCastsSingleItemFontRed textBold">'+getDisplayText(userNames[id], 10, true)+'</font></td></tr>'+            
                                            '<tr><td class="topPadding3"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/star_rating'+(flr + (flr == rnd ? "0" : "5"))+'.jpg"></img>';

                       //for stage 4 web 
                        if(allVideos[0][id].entry_entryprops && allVideos[0][id].entry_entryprops.ct_prop_2)
                        {
                            innerHtml += '&nbsp;&nbsp;&nbsp;<font class="finalistBannerDim1 finalystDisp textBold fullWidth alignCenter">&nbsp;';
                            //4TODO: add this for stage 4 and
                            if(allVideos[0][id].entry_entryprops.ct_prop_2 == ct_prop_grandprize)
                            {
                                innerHtml += 'GRAND PRIZE WINNER';
                            }
                            else if(allVideos[0][id].entry_entryprops.ct_prop_2 == ct_prop_runnerup)
                            {
                                innerHtml += 'RUNNER UP WINNER';
                            }  
                            /*else if(allVideos[0][id].entry_entryprops.ct_prop_1 == ct_prop_finalist)
                            {
                                innerHtml += 'FINALIST';
                            }*/
                            innerHtml+= '&nbsp;</font>';
                        }

                       innerHtml += '</td></tr></table></td><tr></table></td></tr>';
                    }
                    
                    
                    innerHtml += nextPageLink;
                    innerHtml += '</table>';
                    
                    if(allVideos[0].length > 5)
                    {
                        innerHtml += '</div>';
                    }
                }    
                else
                {
                    innerHtml += '<table class="fullWidth fulHeigh" cellspacing="0" cellpadding="5" valign="top">';
                                    
                    if(isNotFirstTime && isNotFirstTime == true)
                    {
                        innerHtml +='<tr><td class="fullWidth"><font class="statusFont">Your search terms did not match any videos.</font></td></tr>';
                    }
                    innerHtml += '</table>';
                }
            
                var node = document.getElementById('videosearchResult');

                if(allVideos && allVideos[0]&& allVideos[0].length > 5)
                {
                    node.style.height = "500px";
                }
                
                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }

                if(allVideos && allVideos[0] && allVideos[0].length > 0)
                {
                    setCurrent(SUBMISSIONIDX, true, 'allVideosSubTr', 3, ((isPlayingVideo)?null:allVideos[0][selectentry]),  parentPath);
                }
                else
                {
                    loadOrnament();
                }
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                if(allVideos && allVideos[0] && allVideos[0].length != 0)
                {
                    innerHtml = '<div class="searchResultTable overflowScroll" ><table cellpadding="0" cellspacing="0" border="0" class="fullWidth fullHeight">';
                    for(id=0; id < allVideos[0].length; id++)
                    {
                        var flr = Math.floor(ratings[0][id].entrystats_avgrating);
                        var rnd = Math.round(ratings[0][id].entrystats_avgrating);
                        
                        innerHtml += '<tr>'
                            +'<td class="iconTd itemHeight topPadding12 alignTop alignRight">'
                                +'<a href="#" onclick="selectSearchEntry(allVideos[0]['+id+'], '+id+'); return false;"><img class="searchThumDim" border="0" src="'+allVideos[0][id].entry_iconurl+'"></img></a>'
                            +'</td>'
                            +'<td class="topPadding12 itemHeight leftPadding19 alignTop">'
                                +'<a class="arial10 textBold redTextColor underline" href="#" onclick="selectSearchEntry(allVideos[0]['+id+'], '+id+'); return false;">'+getDisplayText(allVideos[0][id].entry_label1, 20)+'</a><br>'
                                +'<font class="arial10 color3">'+doWhiteSpaceEncode(allVideos[0][id].entry_comment, 80)+'</font><br>'
                                +'<font class="arial10 textBold color3">Submitted By:&nbsp;</font><font class="arial10 textBold redTextColor">'+getDisplayText(userNames[id], 10, true)+'</font></br>'
                                +'<img class="starDim" src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/appimages/star'+(flr + (flr == rnd ? "0" : "5"))+'.jpg"></img>';
                                
                                //adding for stage 3 and 4
                                if(allVideos[0][id].entry_entryprops && (/*allVideos[0][id].entry_entryprops.ct_prop_1 ||*/ allVideos[0][id].entry_entryprops.ct_prop_2)) // removed for stage 4
                                {
                                    if(ct_prop_grandprize == allVideos[0][id].entry_entryprops.ct_prop_2)
                                    {
                                        innerHtml += '<font class="gpBannerDim1 colorWhite arial11 alignCenter textBold">';
                                        innerHtml +=  '&nbsp;GRAND PRIZE&nbsp;';
                                    }
                                    else if(ct_prop_runnerup == allVideos[0][id].entry_entryprops.ct_prop_2)
                                    {
                                        innerHtml += '<font class="ruBannerDim1 colorWhite arial11 alignCenter textBold">';
                                        innerHtml +=  '&nbsp;RUNNER UP&nbsp;';
                                    }
                                    //removing for stage 4
/*                                    else if(ct_prop_finalist == allVideos[0][id].entry_entryprops.ct_prop_1)
                                    {
                                        innerHtml += '<font class="finalistBannerDim1 colorWhite arial11 alignCenter">';
                                        innerHtml +=  'FINALIST';
                                    }                                   */
                                                
                                       innerHtml += '</font>';
                                }
                            innerHtml +='</td>'
                        +'</tr>';
                    }
                    if(nextPrevPaths && nextPrevPaths.length > 0)
                    {
                        
                        innerHtml += '<tr>';
                        innerHtml +='<td class="leftPadding14" align="left">';
                        if(nextPrevPaths[0] != null)
                        {
                            innerHtml += '<a href="javascript:false" onclick="loadAllVideos(\''+searchString+'\',\''+sortBy+'\',\''+nextPrevPaths[0]+'\'); return false;"><font class=" arial11 colorBlack underline textBold">prev</font></a>&nbsp;&nbsp;&nbsp;';
                        }
                        innerHtml +='</td><td class="rightPadding14" align="right">';
                        if(nextPrevPaths[1])
                        {
                            innerHtml += '<a href="javascript:false" onclick="loadAllVideos(\''+searchString+'\',\''+sortBy+'\',\''+nextPrevPaths[1]+'\'); return false;"><font class=" arial11 colorBlack underline textBold">next</font></a>&nbsp;&nbsp;&nbsp;';
                        }
                        innerHtml +='</td>';
                        innerHtml += '</tr>';
                    }
                    innerHtml += '</table></div>';
                    
                }
                else
                {
                    innerHtml +='<table cellpadding="0" cellspacing="0" border="0"><tr><td class="fullWidth"><font class="arial11 redTextColor TextBold">Your search terms did not match any videos.</font></td></tr></table>';
                }

                var node=document.getElementById("searchResult");
                if(node)
                {
                    node.innerHTML = innerHtml;
                }
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var suffix = '';
        if(bundleEntryPath)
        {
            suffix = suffix+"&bundle_entryPath="+bundleEntryPath;
            entryId = 0;
        }
        
        if(sortBy == 'topviewed')
        {
            suffix = suffix + "&method=topviewed";
                
            if(!bundleEntryPath && (isNotFirstTime || entryId <= 0))
            {
                suffix = suffix+"&bundle_entryPath=/"+bundleNames[TOP_VIEWED_VIDEOS_TAB_IDX];
                entryId = 0;
            }
        }
        else if(sortBy == 'toprated')
        {
            suffix = suffix +"&method=toprated";
            if(!bundleEntryPath && (isNotFirstTime || entryId <= 0))
            {
                suffix = suffix+"&bundle_entryPath=/"+bundleNames[TOP_RATED_VIDEOS_TAB_IDX];
                entryId = 0;
            }
        }
        else/* if(sortBy = 'latestsubmission') */
        {
            suffix = suffix + "&method=latestsubmission";
            if(!bundleEntryPath && (isNotFirstTime || entryId <= 0))
            {
                suffix = suffix+"&bundle_entryPath=/"+bundleNames[LATEST_VIDEO_SUBMISSIONS_TAB_IDX];
                entryId = 0;
            }
        }
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&search="+searchString +
            "&entry_id="+entryId;
        
        queryParamString += suffix;
        
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function selectSearchEntry(entry, id)
    {
        var afterloadsubmissiondata = function()
        {
            setCurrent(4, false, null, null, entry, id, -1);
        }
        clearSearchText(document.getElementById('searchString'), true);
        resetCombo('sortby');   
        loadSubmissionData(null, afterloadsubmissiondata, null, entry.entry_id);
    }

    function resetCombo(sortIdElmt)
    {
        var sortId = document.getElementById(sortIdElmt);
        if(sortId)
        {
            sortId.value = 'latestsubmission';
        } 
    }
    
    function loadAllTabs()
    {
        var afterUpload = function(result)
        {
            if(result)
            {
                bundleNames = JSON.parse(result);  
                bundleNames = bundleNames.bundlepaths;
                afterLoadTabs();
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=getTabs";
        
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function clearSearchElements(inputId, sortId)
    {
        var inputBox = document.getElementById(inputId);
        inputBox.value= DEFAULT_SEARCH_STRING;
        var sortId = document.getElementById(sortId);
        sortId.value = 'latestsubmission';
    }
    function showAllVideosSearch(inputId, sortId)
    {
        var inputBox = document.getElementById(inputId);
        var searchString = (inputBox.value == DEFAULT_SEARCH_STRING ? "" : inputBox.value);
        var sortId = document.getElementById(sortId);
        var sortBy = sortId.value;

        loadAllVideos(searchString ,sortBy, null, true);
    }

    function loadProductData()
    {
        var afterUpload = function(result)
        {       
            if(result)
            {
                podcastEntries = JSON.parse(result);
                parentPath = podcastEntries.parentpath;
                socialUrls = podcastEntries.socialurls;
                extraParams =podcastEntries.extraParams;
            }
            if(podcastEntries && podcastEntries.entries)
            {
                podcastEntries = JSON.parse(podcastEntries.entries);
            }
           
            if(channelId == CHANNEL_WEB)
            {
                var innerHtml = '';
                var qs = new Querystring();
                var entryId = qs.get('entry_id'); 
                if(!entryId)
                {
                    entryId = podcastEntries[0][0].entry_id;
                }
                setProductList(entryId);
                innerHtml = '<table class="" cellspacing="0" cellpadding="0">';

                for(id=0; podcastEntries && id < podcastEntries.length; id++)
                {
                    innerHtml += '<tr><td><table class="checlListItemTable" cellspacing="0" cellpadding="0">'+
                               '<tr><td><a href="javascript:false" onclick="setProductList('+podcastEntries[id][0].entry_id+'); return false;"> <font class="checlListItemFont underline">'+getDisplayText(podcastEntries[id][0].entry_label1, 25)+'</font></td></tr>'+
                               '</table></td></tr>';
                }
                                    
                innerHtml += '</table>';
                var node = document.getElementById('featuredproducts');

                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                setProductList(currentEntryId);
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=allpodcasts";
    
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function postComment(hideId)
    {
        //alert('postComment');
        if(channelId != CHANNEL_FACEBOOK)
        {
            checkCurrentPage(postComment1, hideId);
        }
        else
        {
            checkLogin(postComment1, hideId);
        }
    }

    function postComment1(hideId)
    {
        var afterUpload = function(result)
        {    
            document.getElementById('textareaPodcastComment').value = "";                    
            if(channelId == CHANNEL_WEB)
            {
                loadComments(currentEntryId);
                _toggleDiv(hideId, false);
                _toggleDiv('rateDropDown', true); // TO show the ratethis dropdown  right below the video
                pageTracker._trackPageview('web/comments');
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                 setCurrent(curPageIdx, true, "videoScreens", 0, curEntry, curEntryArrIdxForSubmisson);
                 setCurrent(curPageIdx, true, "commentsID", 1);        
                 loadComments(null, 0);
                 pageTracker._trackPageview('facebook/comments');
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };

        var userRating = 5;

        if((channelId == CHANNEL_WEB && curPageIdx == SUBMISSIONIDX) || (channelId == CHANNEL_FACEBOOK && curPageIdx == APP_SUBMISSIONIDX))
        {
            var dropdown = document.getElementById('rateDropDown1');
            userRating = dropdown.options[dropdown.selectedIndex].value;
        }

        var review = document.getElementById('textareaPodcastComment').value;
        if(review.length > 0)
        {
            var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
            var queryParamString = "?campaign_id=" + campaignId +
                "&channel_id=" + channelId + 
                getActionSuffix()+
                "&resptype=inline"+
                "&rating_rating="+ userRating +
                "&rating_review=" + escape(review)+
                "&entry_id="+currentEntryId;
        
            //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
            encodeSessionId(url, queryParamString, afterUpload, errcbk);
        }
    }

    function getActionSuffix()
    {
        //var userName = checkLogin();        
        var actionsuffix;
        
        if(userName)
        {
            actionsuffix = "&aid=3";
        }
        else
        {
            actionsuffix = "&aid=20";
        }

        return actionsuffix;
    }

    function doRating(formId)
    {
        //alert('doRating');
        if(channelId != CHANNEL_FACEBOOK)
        {
            checkCurrentPage(doRating1, formId);
        }
        else
        {
            checkLogin(doRating1, formId);
        }    
    }
    
    function doRating1(formId)
    {
        var afterUpload = function(result)
        {
            var resultJson = JSON.parse(result); 
            var successMsg = resultJson.lastSuccessMsg;
            var showText;

            if(successMsg)
            {  
                if(channelId == CHANNEL_WEB)
                {
                    loadComments(currentEntryId);
                    pageTracker._trackPageview('web/rating');
                    //have to load  either one
    /*                loadAllVideos();
                    loadMyVideos(); */
                }
                else if(channelId == CHANNEL_FACEBOOK)
                {
                    pageTracker._trackPageview('facebook/rating');
                    if(curTabSubmission == 3)// 3 is myvideos tab
                    {
                        loadMyVideos();
                    }
                    else
                    {
                        loadSubmissionData(null, null, null, currentEntryId);
                    }
                }
            }
        }

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };

        var  dropDown = document.getElementById('rateDropDown');
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            getActionSuffix()+
            "&resptype=inline"+
            "&rating_rating="+ dropDown.options[dropDown.selectedIndex].value+
            "&rating_review=" + 
            "&entry_id="+currentEntryId;

        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);  
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }
    
    function doChangePassword(formid)
    {
        var afterUpload = function(result, xmlhttp)
        {
            var resultJson = JSON.parse(result); 
            var successMsg = resultJson.lastSuccessMsg;
            var showText;

            if(successMsg)
            {  
                showText = successMsg;
            }
            else
            {
                showText = resultJson.lastErrorMsg;
            }
            
            var errortext = document.getElementById("changePassworderrorText");
            errortext.innerHTML = showText;
        }    

        var errcbk = function(msg)
        {
            //alert(msg);
        };

        var form = document.getElementById(formid); 
        var userPassword = form.elements['user_password'].value;
        
        if((trim(userPassword)).length < 1)
        {
            var errortext = document.getElementById("changePassworderrorText");
            errortext.innerHTML = "Please enter a valid password.";
        }
        else
        {
            var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
            var queryParamString = "?campaign_id=" + campaignId +
                            "&channel_id=" + channelId + 
                            "&aid=21" + 
                            "&resptype=inline" +                         
                            "&user_password=" + form.elements['user_password'].value +
                            "&new_pwd=" + form.elements['new_pwd'].value+
                            "&confirm_pwd=" + form.elements['confirm_pwd'].value;                        

            //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk); 
            encodeSessionId(url, queryParamString, afterUpload, errcbk);
        }
    }

     function showUpdateProfile()
    {
        checkCurrentPage(showUpdateProfile1);
    }

    function showUpdateProfile1()
    {
        if(userName)
        {
            setCurrent(CONTESTIDX, true, 'changePwdTr', 3);    
        }
        else
        {
            sessionLoggedOutScreen();
        }
    }

    function getUserProfile()
    {
        var afterUpload = function(result, xmlhttp)
        {
            var resultJson = JSON.parse(result);
            resultJson = JSON.parse(resultJson.userprofile);
            var form = document.getElementById('idupdateform'); 

            if(form)
            {
                form.elements['user_email'].value = resultJson[0].user_email;            
                form.elements['user_name'].value = resultJson[0].user_name;
                form.elements['reguser_password'].value = resultJson[0].user_password;
                form.elements['fname'].value = ((resultJson[0].user_userprops)?resultJson[0].user_userprops.fname:"");
                form.elements['lname'].value =  ((resultJson[0].user_userprops)?resultJson[0].user_userprops.lname:"");
                form.elements['dob'].value =  ((resultJson[0].user_userprops)?resultJson[0].user_userprops.dob:"");
                form.elements['zip'].value =  ((resultJson[0].user_userprops)?resultJson[0].user_userprops.zip:"");
                form.elements['partnermails'].value =  ((resultJson[0].user_userprops)?resultJson[0].user_userprops.partnermails:"0");
            }
            
            
            //var errortext = document.getElementById("changePassworderrorText");
            //errortext.innerHTML = showText;
        }    

        var errcbk = function(msg)
        {
            //alert(msg);
        };

        
        var userId = null;
        if(channelId == CHANNEL_WEB)
        {
            userId = ((readCookie('user_id'))?readCookie('user_id'):'0');
        }
        else
        {
            userId = fUserId;
        }
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
                        "&channel_id=" + channelId + 
                        "&user_id=" + userId +
                        "&method=getProfile";                        

        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk); 
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function doForgotPassword(formid)
    {
        var form = document.getElementById(formid);     
        var emailId = form.elements['user_email'].value
        
        var afterUpload = function(result, xmlhttp)
        {
            var resultJson = JSON.parse(result); 
            stopUploadAnim();
            var successMsg = resultJson.lastSuccessMsg;
            var showText;

            if(successMsg)
            {  
                showText = 'Your password has been sent to you at '+ emailId +'.';
            }
            else
            {
                showText = 'You have entered an incorrect email address. Please check the input and try again.';
            }
            
            var errortext = document.getElementById("forgotPassworderrorText");
            errortext.innerHTML = showText;
        }    

        var errcbk = function(msg)
        {
            stopUploadAnim();
            //alert(msg);
        };

        
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
                        "&channel_id=" + channelId + 
                        "&aid=22" + 
                        "&resptype=inline" +                         
                        "&user_email=" + emailId +
                        "&mailer_id="+maileridForgotPwd[campaignId];
        startForgotPasswordAnim();
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk); 
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function setProductList(entryId)
    {
        var id = 0;
        var innerHtml = "";
            
        for(id=0; id < podcastEntries.length; id++)
        {
            if(podcastEntries[id][0].entry_id == entryId)
            {
                break;
            }
        }

        if(id < podcastEntries.length)
        {
            if(channelId == CHANNEL_WEB)
            {
                var heading = document.getElementById("heading");
                if(heading)
                {
                    heading.innerHTML = getDisplayText(podcastEntries[id][0].entry_label1, 40);
                }

                innerHtml = '<table cellspacing="0" cellpadding="0" class="fullWidth fullHeight">'+
                                        '<tr>'+
                                            '<td class="productListHeight" colspan="2">'+                                
                                                '<table cellspacing="0" cellpadding="0" class="fullWidth fullHeight">'+
                                                    '<tr>'+
                                                        '<td width="30%" valign="top" align="center"><img class="imgBorder fullPodcastIconSize" src="'+podcastEntries[id][0].entry_iconurl+'"></img></td>'+
                                                        '<td width=70% height = 100% valign="top">'+
                                                            '<table cellspacing="0" cellpadding="0" class="alignTop">'+
                                                                '<tr>'+
                                                                    '<td><font class="mainHeadingFont">'+getDisplayText(podcastEntries[id][0].entry_label1, 50)+'</font></td>'+
                                                                '</tr>'+
                                                                '<tr>'+
                                                                    '<td><font class="checlListdescriptionFont textBold">'+doWhiteSpaceEncode(podcastEntries[id][0].entry_comment, 200)+'</font></td>'+
                                                                '</tr>'+
                                                            '</table>'+
                                                        '</td>'+
                                                    '</tr>'+
                                                '</table>'+
                                            '</td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td class="width30p">'+
                                            '</td>'+
                                            '<td class="backtoPodcastHeight">'+
                                                '<a href="podcast.html?entry_id='+podcastEntries[id][0].entry_id+'"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/button_backtopodcasts.jpg"></img></a>'+
                                                '<span class="leftPadding10"></span><a href="javascript:print()"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/button_printlist.jpg"></img></a>'+
                                            '</td>'+
                                        '</tr>'+
                                    '</table>';
                                                
                                       
                var node = document.getElementById('productvideoinfo');
            
                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }

                innerHtml = '<table class="" cellspacing="0" cellpadding="0">';

                for(var i=1; i<podcastEntries[id].length; i++)
                {
                    var reg = ((podcastEntries[id][i].entry_entryprops.pfeed_retailprice)? podcastEntries[id][i].entry_entryprops.pfeed_retailprice:"");
                    var sale = ((podcastEntries[id][i].entry_entryprops.pfeed_saleprice)? podcastEntries[id][i].entry_entryprops.pfeed_saleprice:"");
                    var giftUrl = (podcastEntries[id][i].entry_entryprops.ct_prop_2 ? trim(podcastEntries[id][i].entry_entryprops.ct_prop_2) : "");
                    var registryUrl = (podcastEntries[id][i].entry_entryprops.ct_prop_3 ? trim(podcastEntries[id][i].entry_entryprops.ct_prop_3) : "");

                    if(podcastEntries[id][i].entry_entryprops.pfeed_saleprice && podcastEntries[id][i].entry_entryprops.pfeed_retailprice && 
                        (podcastEntries[id][i].entry_entryprops.pfeed_saleprice == podcastEntries[id][i].entry_entryprops.pfeed_retailprice))
                    {
                        sale = "";
                        reg = '<br/>Price $'+ reg;
                    }
                    else
                    {
                        reg = (reg ? '<br/>Reg. $'+ reg : reg);
                        sale = (sale ? '<br/>Sale $'+ sale : sale);
                    }
                    
                    innerHtml += '<tr><td valign="top" class="bottomPadding10"><table class="checlListProductTable" cellspacing="0" cellpadding="0" border="0">'+
                                '<tr><td class="checlListProductTableItemImage"><img src="'+podcastEntries[id][i].entry_cdnfileurl+'" class="highlightImage"></img></td>'+
                                '<td class="checlListProductTableItemImageDesc"  valign="top"><table class="checlListProductTableItemTable" cellspacing="10" cellpadding="0">'+
                                '<tr><td><font class="checlListProductItemHeadingFont">'+getDisplayText(podcastEntries[id][i].entry_label1, 100)+reg+'</font><font class="checlListProductItemHeadingFont redTextColor">'+sale+'</font></td></tr>'+
                                '<tr><td><font class="checlListProductItemActionsDescFont textBold">'+doWhiteSpaceEncode(podcastEntries[id][i].entry_comment, 300)+'</td></tr>'+
                                '<tr><td><font class="checlListProductItemDescFont"></font></td></tr>'+
                                '<tr><td><a target="_blank" href="' + (podcastEntries[id][i].entry_entryprops.ct_prop_4 == null || (trim( podcastEntries[id][i].entry_entryprops.ct_prop_4)).length == 0 ?  podcastEntries[id][i].entry_itemurl1 : podcastEntries[id][i].entry_entryprops.ct_prop_4)+ '"><font class="checlListProductItemActionFont underline textBold">Shop This Product at macys.com</font></a></td></tr>'+
                                '</table></td><td class="disableForPrint"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/images/checkListLine.jpg"></img></td>'+
                                '<td class="checlListProductTableItemActions disableForPrint" valign="top"><table class="checlListProductTableItemTable" cellspacing="0" cellpadding="10">'+
                                '<tr><td><font class="checlListProductItemActionsHeadingFont">Shopping for a wedding present?</font><br>'+
                                '<font class="checlListProductItemActionsDescFont textBold"  valign="top">Surprise the happy couple with a gift hand-picked by Tyler Florence! You can also add this product to your registry.</font></td></tr>'+
                                '<tr><td><table cellspacing="0" cellpadding="0">'+
                                (giftUrl.length > 0 ? '<tr><td><a target="_blank"  href="' + giftUrl + '" class="checlListProductItemActionsActionFont underline textBold">Give This Product as a Gift</a></td></tr>' : '') +
                                (registryUrl.length > 0 ? '<tr><td><br><a target="_blank" href="' + registryUrl + '" class="checlListProductItemActionsActionFont underline textBold">Add This Product to a Registry</a></td></tr>' : '')+
                                '<tr><td><br><a target="_blank" href="http://macys.weddingchannel.com/catalog/fds/macysDivisionalHome.action?cm_mmc=tyler-_-create-_-n-_-n" class="checlListProductItemActionsActionFont underline textBold">Register at macysweddingchannel.com</a></td></tr>'+
                                '<tr><td><br><a target="_blank" href="http://macys.weddingchannel.com/catalog/fds/macysDivisionalHome.action?cm_mmc=tyler-_-findguest-_-n-_-n" class="checlListProductItemActionsActionFont underline textBold">View your favorite couple\'s registry</a></td></tr>'+
                                '</table></td></tr></table></td></tr></table></td></tr>';
                }            

                innerHtml += '</table>';
                node = document.getElementById('productIteminfo');
            
                if(node != null)
                {
                    node.innerHTML = innerHtml;
                }
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                var node =  document.getElementById("checklistVideoIcon");
                if(node)
                {
                    node.src = podcastEntries[id][0].entry_iconurl;
                }
                
                node = document.getElementById("checklistTitle");
                if(node)
                {
                    node.innerHTML = doWhiteSpaceEncode(podcastEntries[id][0].entry_label1, 25, 15);
                }

                node = document.getElementById("checklistDesc");
                if(node)
                {
                    node.innerHTML = doWhiteSpaceEncode(podcastEntries[id][0].entry_comment, 150, 15);
                }


                var innerHtml = "";
                if(podcastEntries && podcastEntries[id])
                {
                    innerHtml ='<table cellpadding="0" cellspacing="0" class="fullWidth">';
                    for(var i=1; i<podcastEntries[id].length; i++)
                    {

                        var reg = ((podcastEntries[id][i].entry_entryprops.pfeed_retailprice)? podcastEntries[id][i].entry_entryprops.pfeed_retailprice:"");
                        var sale = ((podcastEntries[id][i].entry_entryprops.pfeed_saleprice)? podcastEntries[id][i].entry_entryprops.pfeed_saleprice:"");
                        var giftUrl = (podcastEntries[id][i].entry_entryprops.ct_prop_2 ? trim(podcastEntries[id][i].entry_entryprops.ct_prop_2) : "");
                        var registryUrl = (podcastEntries[id][i].entry_entryprops.ct_prop_3 ? trim(podcastEntries[id][i].entry_entryprops.ct_prop_3) : "");

                        if(podcastEntries[id][i].entry_entryprops.pfeed_saleprice && podcastEntries[id][i].entry_entryprops.pfeed_retailprice && 
                            (podcastEntries[id][i].entry_entryprops.pfeed_saleprice == podcastEntries[id][i].entry_entryprops.pfeed_retailprice))
                        {
                            sale = "";
                            reg = 'Price $'+ reg;
                        }
                        else
                        {
                            reg = (reg ? 'Reg. $'+ reg : reg);
                            sale = (sale? 'Sale $'+ sale : sale);
                        }
                        innerHtml += '<tr>'
                                                +'<td class="padding8 borderBottom fullWidth">'
                                                    +'<table cellpadding="0" cellspacing="0" class="fullWidth">'
                                                        +'<tr>'
                                                            +'<td class="checklistImageTd">'
                                                                +'<img class="checkListImageDim" src="'+podcastEntries[id][i].entry_cdnfileurl+'"></img>'
                                                            +'</td>'
                                                            +'<td class="leftPadding8 alignTop checklistDescTd">'
                                                                +'<table cellpadding="0" cellspacing="0">'
                                                                    +'<tr>'
                                                                        +'<td class="arial11 textBold">'
                                                                            + doWhiteSpaceEncode(podcastEntries[id][i].entry_label1, 50, 15)+'<br>'+reg+'&nbsp;<br><font class="redTextColor">'+sale+'</font>'
                                                                        +'</td>'
                                                                    +'</tr>'
                                                                   /* +'<tr>'
                                                                        +'<td class="arial11 redTextColor textBold">'
                                                                            +sale
                                                                        +'</td>'
                                                                    +'</tr>'*/
                                                                    +'<tr>'
                                                                        +'<td class="arial11 redTextColor underline">'
                                                                            +'<a target="_blank" href="'+(podcastEntries[id][i].entry_entryprops.ct_prop_4 == null || (trim( podcastEntries[id][i].entry_entryprops.ct_prop_4)).length == 0 ?  podcastEntries[id][i].entry_itemurl1 : podcastEntries[id][i].entry_entryprops.ct_prop_4)+'"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/appimages/link_shop_at_macys.jpg"</img></a>'
                                                                        +'</td>'
                                                                    +'</tr>'
                                                                    +'<tr>'
                                                                        +'<td class="arial11 redTextColor underline">'
                                                                            +(giftUrl.length > 0 ? '<a target="_blank" href="'+giftUrl+'"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/appimages/link_give_as_gift.jpg"</img></a>' : '')
                                                                        +'</td>'
                                                                    +'</tr>'
                                                                    +'<tr>'
                                                                        +'<td class="arial11 redTextColor underline">'
                                                                            +(registryUrl.length > 0 ? '<a target="_blank" href="'+registryUrl+'"><img src="http://d3pnveezgteiph.cloudfront.net/kic/v200905280138/appimages/link_add_to_registry.jpg"</img></a>' : '')
                                                                        +'</td>'
                                                                    +'</tr>'
                                                                +'</table>'
                                                            +'</td>'
                                                        +'</tr>'
                                                    +'</table>'
                                                +'</td>'
                                            +'</tr>';
                    }
                    innerHtml += '</table>';
                }

                node = document.getElementById("checklistPdtList");
                if(node)
                {
                    node.innerHTML = innerHtml;
                }


            }
        }   
    }

    function registerKIC(formId)
    {
        var errortext = document.getElementById("errortext");
        errortext.innerHTML = "<br>This process may take few seconds. Please wait...";
        var form = document.getElementById(formId); 
         
        var afterUpload = function(result, xmlhttp)
        {
            var responseCode = xmlhttp.getResponseHeader("X-Skava-ResponseCode");
            var errorMessage = JSON.parse(result); 
            
            if(responseCode == 0)
            {      
                if(channelId == CHANNEL_WEB)
                {   
                    pageTracker._trackPageview('web/userregister');
                    checkCurrentPage(afterregisterKIC);
                }   
                else if(channelId == CHANNEL_FACEBOOK)
                {
                    afterregisterKIC(form);
                    pageTracker._trackPageview('facebook/userregister');
                }
                errortext.innerHTML = "";
            }
            else
            {                
                errortext.innerHTML = "Registration failed. This user may already be present in the system, or some data that you provided is invalid.  Please check your input and try again.";
            }
        }    

        var errcbk = function(msg)
        {
            //alert(msg);
        };

       
        var userName = form.elements['user_name'].value;
        var userPassword = form.elements['reguser_password'].value;
        var fname = form.elements['fname'].value;
        var lname = form.elements['lname'].value;
        var dob = form.elements['dob'].value;
        var zip = form.elements['zip'].value;
        var errortext = document.getElementById("errortext");
        
        if(trim(userName).length <= 0 || trim(fname).length <= 0 || trim(lname).length <= 0 || trim(dob).length <= 0 || trim(zip).length <= 0)
        {
            errortext.innerHTML = "Required fields cannot be left blank; please check your inputs and try again.";
        }
        else if(!validateUserName(userName))
        {
            errortext.innerHTML = "You have used some special characters in your name that are not permitted.";
        }
        else if((trim(userPassword)).length < 1)
        {
            errortext.innerHTML = "Please enter a valid password.";
        }
        else
        {
            var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
            var queryParamString = "?campaign_id=" + campaignId +
                            "&channel_id=" + channelId + 
                            "&aid=19" + 
                            "&user_email=" + form.elements['reguser_email'].value+
                            "&user_name=" + userName +
                            "&user_password=" + userPassword +
                            "&fname=" + fname +
                            "&lname=" +lname +
                            "&dob=" + dob+
                            "&zip=" + zip+ 
                            "&partnermails=" + form.elements['partnermails'].value +
                            "&resptype=inline"+
                            "&mailer_id=" + maileridRegisterEmail[campaignId];
        
            //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk); 
            encodeSessionId(url, queryParamString, afterUpload, errcbk);
        }
    }

    function afterregisterKIC(form)
    {
        if(channelId == CHANNEL_WEB)
        {   
            setCurrent(CONTESTIDX, true, "thanksRegisterTr", 3);   
            timer=setTimeout("setUserScreenAfter1min()",3000);
        }   
        else if(channelId == CHANNEL_FACEBOOK)
        {
            //window.open("kicappsubmission.html?divid=uploadScreen", "_parent");
            form.action = "kicappsubmission.html?divid=uploadScreen&sessionid="+sessionId;
            form.method = "POST";
            form.submit();
        }
    }

    function setUserScreenAfter1min()
    {
        setCurrent(CONTESTIDX, true, "contestloginsucess", 3);
        //setCurrent(CONTESTIDX, true, "idEnterContestTr", 3);
        timer = null;
    }
    
    function UpdateProfile(formId)
    {
        checkCurrentPage(UpdateProfile1, formId);
    }
    
    function UpdateProfile1(formId)
    {
        var afterUpload = function(result, xmlhttp)
        {
            var responseCode = xmlhttp.getResponseHeader("X-Skava-ResponseCode");
            var errorMessage = JSON.parse(result); 
            var errortext = document.getElementById("updateerrortext");
            
            if(responseCode == 0)
            {            
                if(channelId == CHANNEL_WEB)
                {
                    createCookie("user_name", form.elements['user_name'].value);
                }
                else
                {
                    userName = form.elements['user_name'].value;
                }
                
                var afterCCP = function()
                {
                    setCurrent(CONTESTIDX, true, "contestloginsucess", 3);
                    //setCurrent(CONTESTIDX, true, "idEnterContestTr", 3);                    
                }
                checkCurrentPage(afterCCP);
            }
            else
            {                
                errortext.innerHTML = errorMessage.lastErrorMsg;
            }
        }    

        var errcbk = function(msg)
        {
            //alert(msg);
        };

        var form = document.getElementById(formId); 
        var userName1 = form.elements['user_name'].value;
        var userPassword = form.elements['reguser_password'].value;
        var fname = form.elements['fname'].value;
        var lname = form.elements['lname'].value;
        var dob = form.elements['dob'].value;
        var zip = form.elements['zip'].value;
        var errortext = document.getElementById("updateerrortext");
        
        if(trim(userName1).length <= 0 || trim(fname).length <= 0 || trim(lname).length <= 0 || trim(dob).length <= 0 || trim(zip).length <= 0)
        {
            errortext.innerHTML = "Required fields cannot be left blank; please check your inputs and try again.";
        }
        else if(!validateUserName(userName1))
        {
            errortext.innerHTML = "Username cannot have special characters. Please enter a valid username.";
        }
        else if((trim(userPassword)).length < 1)
        {
            errortext.innerHTML = "Please enter a valid password.";
        }
        else
        {
            var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
            var queryParamString = "?campaign_id=" + campaignId +
                            "&channel_id=" + channelId + 
                            "&aid=23" + 
                            "&user_email="+form.elements['user_email'].value +
                            "&user_name=" + form.elements['user_name'].value+
                            "&user_password=" + userPassword +
                            "&fname=" + form.elements['fname'].value +
                            "&lname=" +form.elements['lname'].value +
                            "&dob=" + form.elements['dob'].value +
                            "&zip=" + form.elements['zip'].value + 
                            "&partnermails=" + form.elements['partnermails'].value +
                            "&resptype=inline";
            
            if(userName)
            {
                //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk); 
                encodeSessionId(url, queryParamString, afterUpload, errcbk);
            }
            else
            {
                sessionLoggedOutScreen();
            }
        }
    }
    
    function loginUser(formId, emailId, pwdId)
    {
        var form = document.getElementById(formId);
        
        var afterUpload = function(result, xmlhttp)
        {
            var responseCode = xmlhttp.getResponseHeader("X-Skava-ResponseCode");

            if(responseCode == 0)    
            {

                var node = document.getElementById("loginerrormsg");
                if(node)
                {
                    _toggleDiv('loginerrormsg', false);
                }
            }
            else
            {
                _toggleDiv('loginerrormsg', true);
            }  

            if(responseCode == 0)    
            {
                var username = JSON.parse(result);
               
                if(channelId == CHANNEL_WEB)
                {
                    createCookie("user_name", username.user);
                    createCookie("user_id", username.userid);
                    checkCurrentPage(afterLoginUser);
                }
                else if(channelId == CHANNEL_FACEBOOK)
                {
                    userName = username.user;
                    fUserId = username.userid;
                    pageTracker._trackPageview('facebook/loginuser');
                    //window.open("kicappsubmission.html?divid=uploadScreen", "_parent");
                    //form.action = "kicappsubmission.html?divid=uploadScreen&sessionid="+sessionId; // changed to default submission page for stage2
                    form.action = "kicappsubmission.html?sessionid="+sessionId;
                    form.method = "POST";
                    form.submit();
                }

                var node = document.getElementById("loginerrormsg");
                if(node)
                {
                    _toggleDiv('loginerrormsg', false);
                }
                
                node = document.getElementById("loginerrormsg1");
                if(node)
                {
                    _toggleDiv('loginerrormsg1', false);
                }
            }
            else
            {
                var loginError = document.getElementById('loginerrormsg');      
                if(loginError)
                {
                    _toggleDiv('loginerrormsg', true);
                }
                loginError = document.getElementById('loginerrormsg1'); 
                
                if(loginError)
                {
                    _toggleDiv('loginerrormsg1', true);
                }
            }            
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };

           
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
                        "&channel_id=" + channelId + 
                        "&aid=1"+
                        "&method=login"+
                        "&user_email="+form.elements[emailId].value+
                        "&user_password="+form.elements[pwdId].value+
                        "&restype=inline";
    
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function afterLoginUser()
    {
        if(curPageIdx == CONTESTIDX)
        {
            if(welcomeVideoEntry &&  welcomeVideoEntry[0] && welcomeVideoEntry[0][1])
            {
                setCurrent(curPageIdx, true, "contestloginsucess", 3, welcomeVideoEntry[0][1]);
                //setCurrent(curPageIdx, true, "idEnterContestTr", 3, welcomeVideoEntry[0][1]);
            }
            else
            {
                setCurrent(curPageIdx, true, "contestloginsucess", 3);
                //setCurrent(curPageIdx, true, "idEnterContestTr", 3);                
            }
        }
        else if(curPageIdx == SUBMISSIONIDX)
        {
           setMyVideos(curPageIdx, userName);
           loadMyVideos();
        }

        var node = document.getElementById("loginerrormsg");
        if(node)
        {
            _toggleDiv('loginerrormsg', false);
        }
        node = document.getElementById("loginerrormsg1");
        if(node)
        {
            _toggleDiv('loginerrormsg1', false);
        }
        
        pageTracker._trackPageview('web/loginuser');
    }
    
    function loginRateUser(formId)
    {
        var afterUpload = function(result, xmlhttp)
        {
            var responseCode = xmlhttp.getResponseHeader("X-Skava-ResponseCode")

            if(responseCode == 0)    
            {
                var username = JSON.parse(result);
                
                if(channelId == CHANNEL_WEB)
                {
                    createCookie("user_name", username.user);
                    createCookie("user_id", username.userid);
                }
                else
                {
                    userName = username.user;
                    fUserId = username.userid;
                }
                
                hideSignIn();
                setCurrent(PODCASTIDX, true, null, 2);
                setCurrent(SUBMISSIONIDX, true, null, 2);
                checkCurrentPage();
                pageTracker._trackPageview('web/loginuser');
            }
            else
            {
                var loginError = document.getElementById('loginerrormsg');                   
                loginError.style.display = 'block'; 
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };

        var form = document.getElementById(formId);    
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
                        "&channel_id=" + channelId + 
                        "&aid=1"+
                        "&method=login"+
                        "&user_email="+form.elements['user_email'].value+
                        "&user_password="+form.elements['user_password'].value+
                        "&restype=inline";
    
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
    }

    function loadOrnament(cbkOrnament, showId)
    {     
        var afterLoadOrnament = function(result)
        {  
            var ornament = JSON.parse(result);
            parentPath = ornament.parentpath;
            socialUrls = ornament.socialurls;        
            extraParams = ornament.extraParams;
            
            ornament= JSON.parse(ornament.entries);

            if(channelId == CHANNEL_WEB)
            {
                /* for stage 2 */
                if(showId)
                {
                    var showIn = document.getElementById(showId);
                    if(showIn)
                    {
                        //showIn.src = ornament[0][3].entry_cdnfileurl;// for stage 2
                        showIn.src = ornament[0][9].entry_cdnfileurl;// for stage 4
                    }
                }
                
                var contestExtraCreditImg =  document.getElementById('contestExtraCreditImg');
                if(contestExtraCreditImg)
                {
                    //contestExtraCreditImg.src = ornament[0][4].entry_cdnfileurl; // for stage 2
                    contestExtraCreditImg.src = ornament[0][10].entry_cdnfileurl;// for stage 4
                }
                
                contestExtraCreditImg = document.getElementById('contestExtraCreditImg1');            
                if(contestExtraCreditImg)
                {
                    //contestExtraCreditImg.src = ornament[0][4].entry_cdnfileurl; // for stage 2
                    contestExtraCreditImg.src = ornament[0][10].entry_cdnfileurl;// for stage 4
                }

                if(cbkOrnament)
                {
                    cbkOrnament();
                }
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                var node = null;
                if(showId == 'registerScreen')
                {
                    node = document.getElementById('credit3');
                    // node.src = ornament[0][2].entry_cdnfileurl; 
                    node.src = ornament[0][11].entry_cdnfileurl; //ornament for stage 4
                }
                else
                {
                    if(showId == 'loginScreen')
                    {
                        node = document.getElementById('credit2');
                    }
                    else
                    {
                        node = document.getElementById('credit1');
                    }
                    //node.src = ornament[0][1].entry_cdnfileurl; 
                    node.src = ornament[0][11].entry_cdnfileurl;      //ornament for stage 4                                   
                }
            }
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=ornaments"+
            "&bundle_entryPath=/"+bundleNames[ORNAMENTS_TAB_IDX];

        //jx.load(url, afterLoadOrnament, "application/x-www-form-urlencoded", "POST", errcbk);    
        encodeSessionId(url, queryParamString, afterLoadOrnament, errcbk);
    }

    function appendSession(anc, url)
    {
        anc.href = url+"?sessionid="+sessionId;
        return true;
    }

    function setSessionId()
    {
        var qs = new Querystring();
        sessionId = qs.get("sessionid");
    }

    function encodeSessionId(uri, queryParamString, callbk, errcbk)
    {
        var queryStr = (!queryParamString ? "": queryParamString);
        
        if(channelId == CHANNEL_FACEBOOK)
        {
            var encodeSessionIdcbk = function(result, xmlhttp)
            {
                sessionId = xmlhttp.getResponseHeader("X-Skava-SessionId");
                callbk(result, xmlhttp);
            }

            var encodeErrCbk = function(err)
            {
                //alert(err);
                errcbk(err);
            }
            
            if(sessionId)
            {
                var newUrl  =uri +  ';jsessionid='+sessionId + queryStr;
                jx.load(newUrl, encodeSessionIdcbk, "application/x-www-form-urlencoded", "POST", encodeErrCbk);
            }
            else
            {
                jx.load(uri+queryStr, encodeSessionIdcbk, "application/x-www-form-urlencoded", "POST", encodeErrCbk);
            }
        }
        else
        {
            jx.load(uri+queryStr, callbk, "application/x-www-form-urlencoded", "POST", errcbk);
        }
    }
    
    function clearErrorText()
    {
        var node = document.getElementById("smserror");
        if(node)
        {
            node.innerHTML  = "";
        }
        
        node = document.getElementById("errortext1");
        if(node)
        {
            node.innerHTML  = "";
        }

        node = document.getElementById("errorTextMail");
        if(node)
        {
            node.innerHTML  = "";
        }
        
        node = document.getElementById("smserror1");
        if(node)
        {
            node.innerHTML  = "";
        }
    }
    
    function doSendActionSMS(idform, imageCaptchaId, idSmsError, showRating, sendBBLink, forceCheckEntryID)
    {
        var form = document.getElementById(idform); 
        var fromVal = form['idFrom'];
        var mailerparamsstr = JSON.stringify({'FROM': ((fromVal) ? fromVal.value: "dummy"), 'TO': form['idPhone1'].value + form['idPhone2'].value + form['idPhone3'].value, 'ENTRYID': currentEntryId, 'SHOWR':0, 'SERVER':document.domain});// removed rating for stage4
        var mailerparams = JSON.parse(mailerparamsstr);
        var smsError = document.getElementById(idSmsError);  
        
        if(form['idCarrier'].value == '-100')
        {
            smsError.innerHTML = 'Please select your carrier.';
        }
        else
        {
            if(!forceCheckEntryID || currentEntryId > 0)/*if(currentEntryId > 0)    {*/            
            {
                sendSocial( 
                    form['idPhone1'].value + form['idPhone2'].value + form['idPhone3'].value, 
                    ((fromVal)? fromVal.value : "dummy"), 
                    form['idCarrier'].value, 
                    (form['idTerms'].checked ? form['idTerms'].value : null), 
                    form['idCaptcha'].value, 
                    mailerparams, 
                    (sendBBLink ? maileridBB[campaignId] : maileridSMS[campaignId]), 
                    true,
                    idform,
                    imageCaptchaId,
                    smsError);
            }                    
        }
        return false;
    }

    function clearForm(idform)
    {
        var form = document.getElementById(idform); 
        form.reset();
        /*for (var i=0; i<form.elements.length; i++)
        {
            form.elements[i].value='';
        }*/
    }
    
    function doSendActionEmail(idform, imageCaptchaId,  isSTW, idEmailError, isContestInfo, forceCheckEntryID)
    {
        var form = document.getElementById(idform); 
        var pageUrl = null;
        
        if(channelId  == CHANNEL_WEB)
        {
            pageUrl =((isSTW)?thispage.substr(0, thispage.lastIndexOf('/'))+'/myvideos.html':thispage);
        }
        else
        {
            /*var tempfacebookurl = facebookurl[campaignId];

            if(tempfacebookurl.indexOf('?') == -1)
            {
                pageUrl = tempfacebookurl + "?page_id="+curSharePageIdx;
            }
            else
            {
                pageUrl = tempfacebookurl + "&page_id="+curSharePageIdx;
            }*/
            //pagesArr[prevPageIdx]+"?entry_id="+prevEntryId;

            pageUrl  = facebookurl[campaignId] + "&page_id="+curSharePageIdx;
            
        }
        
        if(currentEntryId)
        {
            if(channelId  == CHANNEL_FACEBOOK)
            {
                pageUrl = pageUrl + "&entry_id="+currentEntryId;
            }
            else
            {
                if(pageUrl.indexOf('?') == -1)
                {
                    pageUrl = pageUrl + "?entry_id="+currentEntryId;
                }
                else
                {
                    pageUrl = pageUrl + "&entry_id="+currentEntryId;
                }
            }
        }
        
        var mailerparamsstr = JSON.stringify({'FROM': form['idFrom'].value, 'TO': form['idTo'].value , 'LINK': ((isContestInfo && (isContestInfo == true || isContestInfo == 'true')) ? faceboookAppAddURL[campaignId]: (pageUrl+'&ga=email')), 'LINK2': 'http://'+document.domain+'/keepitcooking/home.html'});
        var mailerparams = JSON.parse(mailerparamsstr);
        var emailError = document.getElementById(idEmailError);  
        var mailer = ((isSTW && (isSTW == true || isSTW == 'true')) ? maileridSTW[campaignId] : ((isContestInfo && (isContestInfo == true || isContestInfo == 'true')) ? maileridContestInfo[campaignId] : maileridEmail[campaignId]));
        if(!forceCheckEntryID || currentEntryId > 0)
        {
        sendSocial(
            form['idToAddress'].value, //toaddress
            form['idFrom'].value, //fromname, 
            form['idFromAddress'].value, //fromaddress, 
            (form['idTerms'].checked ? form['idTerms'].value : null), 
            form['idCaptcha'].value, 
            mailerparams, 
            mailer,
            false,
            idform,
            imageCaptchaId,
            emailError);              
        }
        
        return false;
    }

    function sendSocial(toaddress, fromname, carriercode, terms, captcha, mailerparams, mailerid, isSms, idform, imageCaptchaId, idstatus)
    {
        var afterUpload = function(result)
        {
            var response = parseResult(result);
            var responseMessage = response["X-Skava-ResponseMessage"];
            var responseCode = response["X-Skava-ResponseCode"];            
            if(idstatus)
            {
                if(responseCode == 0)
                {
                    clearForm(idform);
                    idstatus.innerHTML = ((isSms) ? "Your Message has been successfully sent." : "The email was sent successfully.");
                    if(channelId == CHANNEL_WEB)
                    {
                        pageTracker._trackPageview(((isSms)?'web/send_to_mobile/'+carrierNames[carriercode]:'web/email_this'));
                    }
                    else
                    {
                        pageTracker._trackPageview(((isSms)?'facebook/'+(prevPageIdx == APP_CONTESTIDX ? 'contestinfo/' : '')+'send_to_mobile/'+carrierNames[carriercode]:'facebook/'+(prevPageIdx == APP_CONTESTIDX ? 'contestinfo/' : '')+'email_this'));
                    }
                }
                else
                {
                    idstatus.innerHTML = urldecode(responseMessage);
                }
            }

            loadCaptchaImage(imageCaptchaId);
            var form = document.getElementById(idform);
            form[imageCaptchaId].value = "";

        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = serverprefix + "/mc/social;jsessionid=" + (channelId == CHANNEL_FACEBOOK ? sessionId : readCookie('JSESSIONID')) + "?campaign_id=" + campaignId +
            "&X-Skava-Authorization=" + escape(auth[campaignId]) + 
            "&variableresponse=1" + 
            "&op=" + (isSms ? "txt" : "mail") +  
            "&mailer_id=" + mailerid+ 
            "&user_name=" + escape(fromname) + 
            "&eto=" + escape(toaddress) + 
            "&erto=" + escape(carriercode) + 
            "&terms=" + escape(terms) + 
            "&cv=" + escape(captcha) + 
            "&mailer_params="+escape(JSON.stringify(mailerparams));
        
        //alert("3: " + mailerparams + " " + url);
        jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);    
    }

    function parseResult(result)
    {
        var qsParm = new Array();
        if(result)
        {
            var parms = result.split('&');
            for (var i=0; i<parms.length; i++) 
            {
                var pos = parms[i].indexOf('=');
                if (pos > 0) 
                {
                    var key = parms[i].substring(0,pos);
                    var val = parms[i].substring(pos+1);
                    qsParm[key] = unescape(val);
                }
            } 
        }
        return qsParm;
    }

    function urldecode(msg)
    {
        // unescape does not unescape a string this : hello+world
        return (msg ? unescape(msg.replace(/\+/g, "%20")) : msg);
    }

    function escapeNewLine(str)
    {
        var replaceStr = str;
        
        while(replaceStr && replaceStr.indexOf('\\n') != -1)
        {
            replaceStr = replaceStr.replace('\\n', '<br/>');
        }
        
        return replaceStr;
    }

    function loadPodcastRecipe()
    {
        if(currentPodcastEntry[0].entry_entryprops)
        {
            var numRecipes = 4;
            for(var loop = 0; loop < numRecipes; loop ++)
            {
                var loopStartIdx = loop * 3;
                var prop1 = "ct_prop_" + (loopStartIdx + 1);
                var prop2 = "ct_prop_" + (loopStartIdx + 2);
                var prop3 = "ct_prop_" + (loopStartIdx + 3);
                var recipeTitleStr = trim((currentPodcastEntry[0].entry_entryprops[prop1])?getDisplayText(currentPodcastEntry[0].entry_entryprops[prop1], 45) : "");
                var recipeIngredientsStr = trim((currentPodcastEntry[0].entry_entryprops[prop2])?escapeNewLine(currentPodcastEntry[0].entry_entryprops[prop2]): "");
                var recipeDirectionStr = trim((currentPodcastEntry[0].entry_entryprops[prop3])?escapeNewLine(currentPodcastEntry[0].entry_entryprops[prop3]) : "");
                
                document.getElementById("recipeTitle" + (loop + 1)).innerHTML = recipeTitleStr;

                document.getElementById("recipeIngredients" + (loop + 1) + "Title").innerHTML = (recipeIngredientsStr.length > 0 ? "Ingredients" : "");
                document.getElementById("recipeIngredients" + (loop + 1)).innerHTML = recipeIngredientsStr;

                document.getElementById("recipeDirection" + (loop + 1) + "Title").innerHTML = (recipeDirectionStr.length > 0 ? "Direction" : "");
                document.getElementById("recipeDirection" + (loop + 1)).innerHTML = recipeDirectionStr;
            }
        }
    }

    function setMyVideos(page, username)
    {
        var loginCommonSubmissionTr = document.getElementById("loginCommonSubmissionTr");
        if(loginCommonSubmissionTr)
        {
            var loginForm = document.getElementById("login");
            loginForm.elements[0].value = "";
            loginForm.elements[1].value = "";        
        }
        
        _toggleDiv("loginCommonSubmissionTr", false);
        hideSignIn();
        if(myVideos &&  myVideos[0] && myVideos[0][0])
        {
            setCurrent(SUBMISSIONIDX, true, "myVideosSubTr", 3, myVideos[0][0]);
        }
        else
        {
            setCurrent(SUBMISSIONIDX, true, "myVideosSubTr", 3);
        }
        _toggleDiv("usernamesTr", true);
        var usernamesTd = document.getElementById("usernamesTd");
        usernamesTd.innerHTML = "<font class='myriadPro11 textBold'>&nbsp;&nbsp;"+getDisplayText(username, 10, true)+"\'s Videos</font>";
        _toggleDiv("spreadSubTr", false);
    }

    function showMyVideos()
    {
        var myVideosSub = document.getElementById("myVideosSub");
        var allVideosSub = document.getElementById("allVideosSub");
        var finalistVideosSub = document.getElementById("finalistVideosSub"); // for stage 4
        
        clearSearchText(document.getElementById("searchString"), true);
        _toggleDiv('loginerrormsg', false);
        
        myVideosSub.innerHTML = "<font class='subTabLeftFont redTextColor'>&nbsp;&nbsp;MY VIDEOS&nbsp;&nbsp;</font>";
        allVideosSub.innerHTML = "<font class='subTabLeftFont'>&nbsp;ALL VIDEOS&nbsp;</font>";
        var html = '<table cellpadding="0" cellspacing="0" class="tabSmallItemBorder">'
                                                        +'<tr>'
                                                            +'<td>'
                                                                +'<a href="#" onclick="showFinalistVideos(); return false;"><font class="subTabLeftFont">&nbsp;CONTEST WINNERS&nbsp;</font></a>'
                                                            +'</td>'
                                                        +'</tr>'
                                                    +'</table>';
        finalistVideosSub.innerHTML = html;
        
        _toggleDiv("searchControlTr", false);
        _toggleDiv("allVideosSubTr", false);
        _toggleDiv("winnerVideoSubTr", false); //stage 4 web
        loadMyVideos();
    }

    function showAllVideos()
    {
        var myVideosSub = document.getElementById("myVideosSub");
        var allVideosSub = document.getElementById("allVideosSub");
        var finalistVideosSub = document.getElementById("finalistVideosSub"); // stage 4 web 
        
        myVideosSub.innerHTML = "<font class='subTabLeftFont'>&nbsp;&nbsp;MY VIDEOS&nbsp;&nbsp;</font>";
        allVideosSub.innerHTML = "<font class='subTabLeftFont redTextColor'>&nbsp;ALL VIDEOS&nbsp;</font>";
        var html  = '<table cellpadding="0" cellspacing="0" class="tabSmallItemBorder">'
                                                        +'<tr>'
                                                            +'<td>'
                                                                +'<a href="#" onclick="showFinalistVideos(); return false;"><font class="subTabLeftFont">&nbsp;CONTEST WINNERS&nbsp;</font></a>'
                                                            +'</td>'
                                                        +'</tr>'
                                                    +'</table>';
                                                    
        finalistVideosSub.innerHTML = html;
        
        hideUserAccessible();
        _toggleDiv("allVideosSubTr", true);
        _toggleDiv('searchControlTr', true); 
        _toggleDiv("winnerVideoSubTr", false); //stage 4 web
        _toggleDiv("usernamesTr", false);
        loadAllVideos('' ,'latestsubmission'); 

        _toggleDiv("usernamesTr", false);
    }

    function showFinalistVideos() // stage 4 web
    {
        var myVideosSub = document.getElementById("myVideosSub");
        var allVideosSub = document.getElementById("allVideosSub");
        var finalistVideosSub = document.getElementById("finalistVideosSub");
        
         var html = '<table cellpadding="0" cellspacing="0" class="winnerItemBorder">'
                                                        +'<tr>'
                                                            +'<td>'
                                                                +'<a href="#" onclick="showFinalistVideos(); return false;"><font class="winnerTabLeftFont">&nbsp;CONTEST WINNERS&nbsp;</font></a>'
                                                            +'</td>'
                                                        +'</tr>'
                                                    +'</table>';
                                                    
        finalistVideosSub.innerHTML = html;
                                                    
        myVideosSub.innerHTML = "<font class='subTabLeftFont'>&nbsp;&nbsp;MY VIDEOS&nbsp;&nbsp;</font>";
        allVideosSub.innerHTML = "<font class='subTabLeftFont'>&nbsp;ALL VIDEOS&nbsp;</font>";
        
        hideUserAccessible();
        _toggleDiv("allVideosSubTr", false);
        _toggleDiv('searchControlTr', false); 
        _toggleDiv("usernamesTr", false);
        _toggleDiv("myVideosSubTr", false);        
        loadContestVideos();
        
        _toggleDiv("usernamesTr", false);
    }

    function hideUpload()
    {
        _toggleDiv('uplodAlert', false);
        var node = document.getElementById("contestUploadTr");
        if(!node)
        {
            node = document.getElementById("uploadVideoSubTr");
             _toggleDiv('uploadVideoSubTr', false);
        }
        else
        {
             setCurrent(CONTESTIDX, true, 'contestloginsucess', 3);
        }
    }

    function hideForgotPassword()
    {
        if(curPageIdx == SUBMISSIONIDX)
        {
            setCurrent(curPageIdx, true, 'loginCommonSubmissionTr', 3);
        }
        else if(curPageIdx == CONTESTIDX)
        {
            setCurrent(curPageIdx, true, "trloginformcommon1", 3);
        }
    }

    function checkLogin(callback, param1, param2, param3, param4)
    {
        var afterUpload = function(result, xmlhttp)
        {
            if(channelId != CHANNEL_FACEBOOK)
            {
                eraseCookie('user_name');
                eraseCookie('user_id');
            }
            
            var responseCode = xmlhttp.getResponseHeader("X-Skava-ResponseCode");

            if(responseCode == 0)    
            {
                if(result)
                {
                    var username = JSON.parse(result);
                    if(username.user)
                    {
                        userName =  username.user;
                        if(channelId == CHANNEL_WEB)
                        {
                            createCookie("user_name", username.user);
                        }
                    }
                    if(username.userid)
                    {
                        if(channelId == CHANNEL_FACEBOOK)
                        {
                            fUserId = username.userid;
                        }
                        else
                        {
                            createCookie("user_id", username.userid);
                        }
                    }    
                }    
            }                
            
            if(callback)
            {
                callback(param1, param2, param3, param4);
            }    
        }    

        var errcbk = function(msg)
        {
            //alert("error"+msg);
        };
        
        var url = "http://"+document.domain+"/mc/templates/macys/kic/kic.jsp";
        var queryParamString = "?campaign_id=" + campaignId +
            "&channel_id=" + channelId + 
            "&method=getLoggedInUser";
        
        //jx.load(url, afterUpload, "application/x-www-form-urlencoded", "POST", errcbk);
        encodeSessionId(url, queryParamString, afterUpload, errcbk);
        
    }
    
    /*function checkLogin()
    {
        var userName;
        userName =  readCookie('user_name');
        return userName;
    }*/

    function getUserId()
    {
        return readCookie('user_id');
    }

    function loadCaptchaImage(elname)
    {
        var el = document.getElementById(elname);
        
        if(el)
        {
            var sessionid =  (channelId == CHANNEL_FACEBOOK ? sessionId : readCookie('JSESSIONID'));
            var url = serverprefix + '/mc/captcha;jsessionid='+sessionid+'?timeforreload="' + (new Date()).getTime() + '"';
            el.src = url;
        }
    }

    function showForgotPwd()
    {
        var forgotPassworderrorText= document.getElementById("forgotPassworderrorText");
        forgotPassworderrorText.innerHTML = "";
        if(channelId == CHANNEL_WEB)
        {
            setCurrent(curPageIdx, true, "forgotPwdTr", 3);
        }
        else 
        {
            setCurrent(APP_CONTESTIDX, true, "forgotPwdScreen", 1);
        }
    }

    function createCookie(name,value) 
    {        
        document.cookie = name+"="+value+"; path=/";
    }

    function readCookie(name) 
    {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        
        for(var i=0;i < ca.length;i++) 
        {
            var c = ca[i];
            
            while (c.charAt(0)==' ') 
            {
                c = c.substring(1,c.length);
            }
            
            if (c.indexOf(nameEQ) == 0) 
            {
                return c.substring(nameEQ.length,c.length);
            }
        }
        return null;
    }

    function eraseCookie(name) 
    {
        createCookie(name,"",-1);
    }

    function setOtherElementEntryIds(entryid, parentPath, entryObj)
    {
        var entryIdEls = ["_idEid1", "_idEid2", "_idEid3", "_idEid4", "_idEidSocial"];
        for(var h = 0; h < entryIdEls.length; h++)
        {
            var el = document.getElementById(entryIdEls[h]);
            if(el)
            {
                el.value = entryid;
            }

            el = document.getElementById(entryIdEls[h] + "Path");
            if(el)
            {
                el.value = parentPath + entryid;
            }

            el = document.getElementById(entryIdEls[h] + "JSON");
            if(el)
            {
                el.value = JSON.stringify(entryObj);
            }
        }
    
    }
    
    function getDisplayText(string, length, donotEncode)
    {
        var toRet = "";

        if(string && string.length > length)
        {
            toRet = string.substr(0, length) + "...";
        }
        else
        {
            toRet = string;
        }

        if(!donotEncode)
        {
               toRet = htmlEncode(toRet);
        }
        
        return (toRet ? toRet : "");        
    }

    function checkLimit(evt, control, limit) 
    {
        evt = (evt) ? evt : window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if (charCode > 31 && charCode != 127) 
        {
            if(control.value.length >= limit)
            {
                return false;
            }
        }        
        return true;
    }

    function doSocialBookmarkPost(gaurl, webUrlString, campaignUrl, campaignName, defaultDescription, containerUrl, rssurl, entryPathWeb, basePath, fbShareURL, customURL, customTitle, customDescription, customHTMLDescription)
    {
        var doPost = false;
        var ourUrl = campaignUrl;
        var title = campaignName;
        var description = defaultDescription;
        var simpleDescription = null;
        var enclosureurl = null, enclosuretype =  null;
        var tinyweburl = null;
        //var iframeDesc = null;
        var doCall = true;
        var documentLocation = new String(document.location);
        documentLocation = ((documentLocation.indexOf('?') == -1)?documentLocation: documentLocation.substring(0, documentLocation.indexOf('?')));
        containerUrl =  documentLocation + containerUrl.substring(containerUrl.indexOf('?'), containerUrl.length);
        if(customURL)
        {
            containerUrl = customURL;
        }
        if(channelId == CHANNEL_FACEBOOK)
        {
            ourUrl = containerUrl + "&entry_id="+currentEntryId;
        }
        else
        {
            if(containerUrl.indexOf('?') == -1)
            {
                ourUrl = containerUrl + "?entry_id="+currentEntryId;
            }
            else
            {
                ourUrl = containerUrl + "&entry_id="+currentEntryId;
            }
        }    

        ourUrl = ourUrl + "&ga=" + gaurl;
        var el = document.getElementById('_idEidSocialJSON');
        if(el && el.value)
        {
            var entry = JSON.parse(el.value);        
            if(entry)
            {
                if(entry.entry_label1)
                {
                    title = entry.entry_label1;
                }
                var id = new Date().getTime() + "_" + Math.floor(Math.random()*10000);
                var centerImageW = 200, centerImageH = 200;
                //var basePath = '<%=cs.getFQDNUrl(request, cs.apacheBaseUrl)%>';
                
                var entryHtml = getEntryHtml("_idMediaPlayer" + id, centerImageW, centerImageH, 
                    centerImageW, null, entry.entry_fileurl, 
                    basePath, 
                    entry.entry_mediatype, "border='1'", false, null);

                description = '<a href=' + ourUrl + '>' + (entryHtml ? entryHtml : defaultDescription)  + "</a><br/>" + 
                    (entry.entry_comment ? htmlEncode(entry.entry_comment) : '');

                simpleDescription = entry.entry_comment;
                
                var enclosure = getEntryEnclosure(entry.entry_fileurl, 
                    basePath, 
                    entry.entry_mediatype, entry.entry_mediacontenttype);
                
                if(enclosure)
                {
                    enclosureurl = enclosure[0];
                    enclosuretype = enclosure[1];
                }
                
                fbShareURL = fbShareURL + '?' +
                    'entry_id=' + escape(entry.entry_id) +
                    '&campaign_id=' + entry.entry_campaignid + 
                    '&time=' + (new Date().getTime());

                if(customDescription)
                {
                    fbShareURL = fbShareURL+'&entry_comment='+escape(htmlEncode(customDescription));
                }

                if(customTitle)
                {
                    fbShareURL = fbShareURL+'&entry_label1='+escape(htmlEncode(customTitle));
                }
                
                fbShareURL = fbShareURL + '&webUrl=' + escape(ourUrl+"&fbshare_id="+entry.entry_id); 

            }
        }
        else
        {
            if(customDescription)
            {
                fbShareURL = fbShareURL + '?' + 
                    '&campaign_id=' + campaignId;

                fbShareURL = fbShareURL+'&entry_comment='+escape(htmlEncode(customDescription));

                description = customHTMLDescription;
            }
            else
            {
                doCall = false;
            }    

            if(customTitle)
            {
                fbShareURL = fbShareURL+'&entry_label1='+escape(htmlEncode(customTitle));
                title = customTitle;
            }
            
            if(customURL)//this should be the last one.
            {
                fbShareURL = fbShareURL + '&webUrl=' + escape(customURL); 
            }
        }
        
        var link = webUrlString;
        if(fbShareURL)
        {
            link = link.replace(/%fbShareURL%/g, escape(fbShareURL));
        }

        tinyweburl = ourUrl.replace(/main.jsp/g, "t.jsp");    
        if(tinyweburl != ourUrl)
        {
            // only if it was going to main.jsp,  change it to go to tiny.jsp. If it is going to a parent container, then dont change.
            tinyweburl = tinyweburl.replace(/campaign_id/g, "c");
            tinyweburl = tinyweburl.replace(/channel_id/g, "i");
            tinyweburl = tinyweburl.replace(/bundle_entryPath/g, "b");
        }
        
        link = link.replace(/%webUrl%/g, escape(ourUrl));
        link = link.replace(/%title%/g, escape(htmlEncode(title)));
        link = link.replace(/%tinywebUrl%/g, escape(tinyweburl));

        if(simpleDescription)
        {
            link = link.replace(/%simpleDesc%/g, escape(htmlEncode(simpleDescription)));
        }
        if(description)
        {
            // myspace changes </img> to <img/> which makes the browser show a missing image ... busted!!!
            var myspacedescription = description.replace('</img>', '');
            link = link.replace(/%description%/g, escape(description));
            link = link.replace(/%myspacedescription%/g, escape(myspacedescription));
        }
        if(enclosureurl)
        {
            link = link.replace(/%enclosureurl%/g, escape(enclosureurl));
        }
        if(enclosuretype)
        {
            link = link.replace(/%enclosuretype%/g, escape(enclosuretype));
        }
        if(rssurl)
        {
            link = link.replace(/%rssURL%/g, rssurl);
        }
        /*
        if(iframeDesc)
        {
            link = link.replace(/%iframeDesc%/g, escape(iframeDesc));
        }
        */
        doPost = (link.indexOf("%dopost%") >= 0);
        if(doPost)
        {
            link = link.replace(/%dopost%/g, '');
        }
        
        if(doCall )
        {
            return (doPost ? toPost(link, true) : openInNewTab(link));
        }
    }

    function getBlogContents(gaurl, campaignUrl, defaultDescription, containerUrl, basePath, customURL, defaultDescription, defaultHTMLDescription)
    {
        if(defaultHTMLDescription)
        {
            return defaultHTMLDescription;
        }
        else
        {
            var ourUrl = campaignUrl;
            var description = defaultDescription;
            //var iframeDesc = null;
            var documentLocation = new String(document.location);
            documentLocation = ((documentLocation.indexOf('?') == -1)?documentLocation: documentLocation.substring(0, documentLocation.indexOf('?')));
            containerUrl =  documentLocation + containerUrl.substring(containerUrl.indexOf('?'), containerUrl.length);
            
            if(customURL)
            {
                containerUrl = customURL;
            }
            if(containerUrl.indexOf('?') == -1)
            {
                ourUrl = containerUrl + "?entry_id="+currentEntryId;
            }
            else
            {
                ourUrl = containerUrl + "&entry_id="+currentEntryId;
            }

            ourUrl = ourUrl + "&ga=" + gaurl;
            
            var el = document.getElementById('_idEidSocialJSON');
            if(el && el.value)
            {
                var entry = JSON.parse(el.value);        
                if(entry)
                {
                    var id = new Date().getTime() + "_" + Math.floor(Math.random()*10000);
                    var centerImageW = 200, centerImageH = 200;
                    //var basePath = '<%=cs.getFQDNUrl(request, cs.apacheBaseUrl)%>';
                    
                    var entryHtml = getEntryHtml("_idMediaPlayer" + id, centerImageW, centerImageH, 
                        centerImageW, null, entry.entry_fileurl, 
                        basePath, 
                        entry.entry_mediatype, "border='1'", false, null);

                    description = '<a href=' + ourUrl + '>' + (entryHtml ? entryHtml : defaultDescription)  + "</a><br/>" + 
                        (entry.entry_comment ? htmlEncode(entry.entry_comment) : '');
                }
            }    
            return description;
        }
    }

    //(gaurl, webUrlString, campaignUrl, campaignName, defaultDescription, containerUrl, rssurl, curChannel, statsId, statsUrl, basePath, fbShareURL, customURL, defaultTitle, defaultDescription, defaultHTMLDescription, eId)
    function loadBlogPostcontents(gaurl, campaignUrl, defaultDescription, containerUrl, basePath, customURL, defaultDescription, defaultHTMLDescription, contentElemID)
    {
        var elPath = document.getElementById('_idEidSocialPath');
                                        
        var blogContents = getBlogContents(gaurl, campaignUrl, defaultDescription, containerUrl, basePath, customURL, defaultDescription, defaultHTMLDescription)
            //(gaurl, webUrlString, campaignUrl, campaignName, defaultDescription, containerUrl, rssurl, null, basePath, fbShareURL, customURL, defaultTitle, defaultDescription, defaultHTMLDescription);
        var elmt = document.getElementById(contentElemID);
        elmt.value = blogContents;
        return (blogContents)? true: false;
    }
    
    function doSocialBookmark(gaurl, webUrlString, campaignUrl, campaignName, defaultDescription, containerUrl, rssurl, curChannel, statsId, statsUrl, basePath, fbShareURL, customURL, defaultTitle, defaultDescription, defaultHTMLDescription)
    {
        var returnResult = false;
        // if u come from a different channel, the path may no tbe valid
        var elPath = document.getElementById('_idEidSocialPath');
        returnResult = doSocialBookmarkPost(gaurl, webUrlString, campaignUrl, campaignName, defaultDescription, containerUrl, rssurl, null, basePath, fbShareURL, customURL, defaultTitle, defaultDescription, defaultHTMLDescription);
       
        var elstats = document.getElementById(statsId);
        if(elstats)
        {
            statsUrl = statsUrl.replace(/%bundle_entryPath%/g, escape(elPath.value));
            elstats.innerHTML = statsUrl;
        }
        
        return returnResult;
    }

    function openInNewTab(link)
    {
        var newWindow = window.open(link, '_blank');
        newWindow.focus();
        return false;    
    }

    function validateUserName(userName)
    {   
        var isValid = true;
        if(userName)
        {
            var asciiVal = 0;
            for(var i = 0; i < userName.length; i++)
            {
                asciiVal = userName.charCodeAt(i);
                //space 32
                // '-' 45
                // '.' 46
                // '_' 95
                // 48 to 57 -> 0 to  9
                //65 to 90 -> A to z
                // 97 to 122 -> a to z
                //alert(asciiVal);
                if(asciiVal == 32 || asciiVal == 45 ||  asciiVal == 46 || asciiVal == 95 || 
                    (asciiVal >= 48 && asciiVal <= 57) || (asciiVal >= 65 && asciiVal <= 90) ||
                    (asciiVal >= 97 && asciiVal <= 122) )
                {
                    continue;
                }
                else
                {
                    isValid = false;
                    break;
                }
            }
        }
        return isValid;
    }

    Querystring.prototype.get = function(key, defaultStr) 
    {
        var value = this.params[key];
        return (value != null) ? value : defaultStr;
    }

    Querystring.prototype.contains = function(key) 
    {
        var value = this.params[key];
        return (value != null);
    }

    function Querystring(qs) 
    { 
        // optionally pass a querystring to parse
        this.params = {};
        
        if (qs == null) 
        {
            qs = location.search.substring(1, location.search.length);
        }
        
        if (qs.length == 0) 
        {
            return;
        }

        // Turn <plus> back to <space>
        // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
        qs = qs.replace(/\+/g, ' ');
        var args = qs.split('&'); // parse out name/value pairs separated via &
        
        // split out each name=value pair
        for (var i = 0; i < args.length; i++) 
        {
            var pair = args[i].split('=');
            var name = decodeURIComponent(pair[0]);           
            var value = (pair.length==2)? decodeURIComponent(pair[1]): name;           
            this.params[name] = value;
        }
    }    

    function doCreateEntry(idFormCreateEntry, idForm, campaignId, thisPage)
    {
        //alert("idFormCreateEntry = "+idFormCreateEntry+"    idForm = "+idForm+"   campaignId = "+campaignId+"    thisPage"+thisPage);
        var url = null;
        if(channelId == CHANNEL_WEB)
        {
            url = "/mc/user/upload?campaign_id="+campaignId+"&resptype=inline&maxsize="+maxAwsSize+"&skipentryid=true&redirurl="+thisPage+"?showuploadalert=true";
        }
        else
        {
            url = "/mc/user/upload;jsessionid="+sessionId+"?campaign_id="+campaignId+"&resptype=inline&maxsize="+maxAwsSize+"&skipentryid=true&appendSid=true&redirurl="+thisPage+"?sessionid="+sessionId+"&showuploadalert=true";
        }
        
        var form = document.getElementById(idFormCreateEntry);
        var suffix="&"+urlEncode({'entry_itemurl1':form.entry_itemurl1.value,'entry_label1':form.entry_label1.value,'entry_comment':form.entry_comment.value});
        _toggleDiv('uplodAlert', false);
        uploadAnim();
        doAWSUpload(idForm,url+suffix, doCreateEntryErrorcbk);
    }

    function doCreateEntryErrorcbk(responseCode, responseMsg)
    {
        stopUploadAnim();
        if(responseCode == 404 && responseMsg == "/mc/login.jsp")
        {
            checkCurrentPage(sessionLoggedOutScreen);
        }
        else
        {
            alert(responseMsg);
        }
    }

    function sessionLoggedOutScreen()
    {
         if(curPageIdx == SUBMISSIONIDX)
        {
            setCurrent(curPageIdx, true, 'loginCommonSubmissionTr', 3);
            _toggleDiv('loginerrormsg', true);
            _toggleDiv('uploadVideoSubTr', false);
            _toggleDiv('usernamesTr', false);     
            _toggleDiv("spreadSubTr", false);
            
            document.getElementById('loginerrormsg').innerHTML= sessionExpiryString;

        }
        else if(curPageIdx == CONTESTIDX)
        {
            setCurrent(curPageIdx, true, "trloginformcommon1", 3);
            _toggleDiv('loginerrormsg1', true);
            document.getElementById('loginerrormsg1').innerHTML= sessionExpiryString;
        }        
    }
    function trim(s)
    {
        return rtrim(ltrim(s));
    }

    function ltrim(s)
    {
        var l=0;
        
        while(l < s.length && s[l] == ' ')
        {
            l++; 
        }
        
        return s.substring(l, s.length);
    }

    function rtrim(s)
    {
        var r=s.length -1;
        
        while(r > 0 && s[r] == ' ')
        {
            r-=1;
        }
        
        return s.substring(0, r+1);
    }
    
    function checkIsNumber(evt, control, limit) 
    {
        evt = (evt) ? evt : window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) 
        {
            return false;
        }        
        else if(charCode > 31 && control != null && limit != null)
        {
            if (control.value.length >= limit) 
            {
                return false;
            } 
        }
        return true;
    }

    function changImage(imgid, image)
    {
        var imageId = document.getElementById(imgid);
        if(imageId)
        {
            imageId.src=image;
        }
    }

    function doFBcall()
    {
        doSocialBookmark('facebook', 'http://www.facebook.com/share.php?u=%fbShareURL%', socialUrls[4],socialUrls[0],blogContent, extraParams[0], socialUrls[6],extraParams[1], 'stats_blog_twitter', extraParams[2]+'blog.twitter'+extraParams[3],extraParams[4], extraParams[5], stwURL, null, facebookDescription);    
    }

    function clearSearchText(idText, clearText)
    {
        if(idText)
        {
            if(channelId == CHANNEL_WEB && (idText.value == DEFAULT_SEARCH_STRING || clearText))
            {
                idText.value = '';
            }
            else if(channelId == CHANNEL_FACEBOOK)
            {
                 idText.value = (clearText ? "" :DEFAULT_SEARCH_STRING);
            }
        }
    }

    function doWhiteSpaceEncode(strToEncode, numChars, breakAt)
    {
        var toRet = "";
        var tempStr = (numChars ? getDisplayText(strToEncode, numChars, true) : strToEncode);
        var wordsArr = tempStr.split(' ');
        var tempArr = null;
        var wbrAt = (breakAt ? breakAt : 15);
      
        for(i=0; i<wordsArr.length; i++)
        {
            if(wordsArr[i].length > wbrAt)
            {
                 tempArr = new Array();
                for(j=0; j+wbrAt < wordsArr[i].length; j+=wbrAt)
                {
                    tempArr.push(htmlEncode(wordsArr[i].substr(j, wbrAt)));
                }
                
                if(wordsArr[i].substr(j))
                {
                    tempArr.push(htmlEncode(wordsArr[i].substr(j)));
                }
                wordsArr[i] = tempArr.join('<font size="0"><wbr></font>');
            }
            else
            {
                wordsArr[i] = htmlEncode(wordsArr[i]);
            }
        }

        toRet = wordsArr.join(' ');
        return toRet;
   }

    function reportAbuse(comment)
    { 
        var email = "abuse@skava.net"; 
        var errorMsg = (curEntry ? curEntry.entry_id : "Unknown entry; please provide the title for this entry in your report"); 
        var subject = "Abuse Report";
        var body_message = "%0D%0D%0D%0DThank you for submitting this to us. Please tell us in the space above your thoughts about this entry.%0D%0DEntry Id: "+errorMsg + ". Campaign Id: "+campaignId + (comment ? ".  Comment text: "+comment : ""); 

        var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message; 

        var newwin = window.open(mailto_link,'_blank');  
        if(newwin && newwin.open &&!newwin.closed) 
        {
            newwin.close(); 
        }
    } 

    function printRecipe()
    {
        var recipePrintTitle = document.getElementById("recipePrintTitle");
        var fullRecipe = document.getElementById("fullRecipe");
        var printRecipe =  document.getElementById("printRecipe");
        printRecipe.innerHTML = recipePrintTitle.innerHTML + fullRecipe.innerHTML;
        print();
    }


    var timeout         = 500;
    var closetimer      = 0;
    var ddmenuitem      = 0;

    function mopen(id)
    {   
        mcancelclosetime();

        if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

        ddmenuitem = document.getElementById(id);
        ddmenuitem.style.visibility = 'visible';

    }

    function mclose()
    {
        if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
    }

    function mclosetime()
    {
        closetimer = window.setTimeout(mclose, timeout);
    }

    function mcancelclosetime()
    {
        if(closetimer)
        {
            window.clearTimeout(closetimer);
            closetimer = null;
        }
    }

    document.onclick = mclose; 
