function toggleRecommnededListOprah(link) {
    var thisTabPage = link.id.substr(0, link.id.length - 6);
    if (link !== $('ka_playerVideoList_mostRelated_title')) {
        if ($j('#ka_playerVideoList_newMedia > div').html() === '') {
            $j('#ka_playerVideoList_newMedia > div,#ka_playerVideoList_mostRated > div,#ka_playerVideoList_mostPopular > div').html('<image alt="loading..." src="' + Ka.Info.AUDIOPHOTOSERVERPATH + '/loading-barber.gif" style="display:block; margin:0 auto;" />');
            KickAppsBizComponent.getAllRelatedMediaForPlayPage(Ka.Info.AFFILIATESITEID, Ka.Info.MEDIATYPE, Ka.Info.MEDIAID,
            function(a) {
                $j('#ka_playerVideoList_newMedia > div,#ka_playerVideoList_mostRated > div,#ka_playerVideoList_mostPopular > div')
                    .html('<div class="ka_playerMediaList_table"><ul id="ka_relatedList"></ul></div>');
                $j.each(a.NEWMEDIALIST, function(i, n) {
                    n.name = Ka.String.encodeDoubleQuotes(n.name);
                    $j('#ka_playerVideoList_newMedia > div > div > ul')
                        .append('<li><a title="' + n['name'] + '" href="/kickapps/_' + n['name'].replace(' ', '_') + '/' + n.entityType.toLowerCase() + '/' + n.id + '/' + Ka.Info.AFFILIATESITEID + '.html?b="><span style="background: rgb(0, 0, 0) url(' + Ka.Info.AUDIOPHOTOSERVERPATH + n.pathToPreview100X75 + ') no-repeat scroll center;" id="ka_letterboxRelated"></span></a><div class="ka_thumbdetails"><a title="' + n['name'] + '" href="/kickapps/_' + n['name'].replace(' ', '_') + '/' + n.entityType.toLowerCase() + '/' + n.id + '/' + Ka.Info.AFFILIATESITEID + '.html?b=">' + Ka.Util.wbr(n.name, 7) + '</a><br /><span class="">By ' + n.uploadedBy + '</span><br/>' + n.formattedDate + '</div></li>');
                });

                $j.each(a.MOSTRATEDLIST, function(i, n) {
                    n.name = Ka.String.encodeDoubleQuotes(n.name);
                    $j('#ka_playerVideoList_mostRated > div > div > ul')
                        .append('<li><a title="' + n['name'] + '" href="/kickapps/_' + n['name'].replace(' ', '_') + '/' + n.entityType.toLowerCase() + '/' + n.id + '/' + Ka.Info.AFFILIATESITEID + '.html?b="><span style="background: rgb(0, 0, 0) url(' + Ka.Info.AUDIOPHOTOSERVERPATH + n.pathToPreview100X75 + ') no-repeat scroll center;" id="ka_letterboxRelated"></span></a><div class="ka_thumbdetails"><a title="' + n['name'] + '" href="/kickapps/_' + n['name'].replace(' ', '_') + '/' + n.entityType.toLowerCase() + '/' + n.id + '/' + Ka.Info.AFFILIATESITEID + '.html?b=">' + Ka.Util.wbr(n.name, 7) + '</a><br /><span class="">By ' + n.uploadedBy + '</span><br/>' + n.averageRating + ' stars</div></li>');
                });

                $j.each(a.MOSTPOPULARLIST, function(i, n) {
                    n.name = Ka.String.encodeDoubleQuotes(n.name);
                    $j('#ka_playerVideoList_mostPopular > div > div > ul')
                        .append('<li><a title="' + n['name'] + '" href="/kickapps/_' + n['name'].replace(' ', '_') + '/' + n.entityType.toLowerCase() + '/' + n.id + '/' + Ka.Info.AFFILIATESITEID + '.html?b="><span style="background: rgb(0, 0, 0) url(' + Ka.Info.AUDIOPHOTOSERVERPATH + n.pathToPreview100X75 + ') no-repeat scroll center;" id="ka_letterboxRelated"></span></a><div class="ka_thumbdetails"><a title="' + n['name'] + '" href="/kickapps/_' + n['name'].replace(' ', '_') + '/' + n.entityType.toLowerCase() + '/' + n.id + '/' + Ka.Info.AFFILIATESITEID + '.html?b=">' + Ka.Util.wbr(n.name, 7) + '</a><br /><span class="">By ' + n.uploadedBy + '</span><br/>' + n.views + ' views</div></li>');
                });
            });
        }
    }
    $j('#ka_relatedWrap div.ka_related').hide();
    $j('#' + thisTabPage).show();
    $j('#ka_relatedTabs > li > a').css({
        'textDecoration': 'underline'
    }).removeClass('active');
    $j(link).css({
        'textDecoration': 'none',
        'className': 'active'
    }).addClass('active');
}



$j('.ka_addMedia a').html('Add Your Video');
$j('#ka_mkpMyMedia a').html('My Videos');
//$j('.ka_login_auth a').html('Log In'); 
$j('#emailArea a').html('Email a Friend');
$j('.ka_add a').html('Add Your Video');
//$j('li.ka_signout_auth a').html('Log Out');
$j('.ka_more a').html('More Videos');

//add class to name
if (Ka.Info.PAGE == "pages/commentDetails.jsp") {
    var cites = $j('#ka_playPageComments .ka_bubble cite');
    for (var i = 0; i < cites.length; i++) {
        $j(cites[i]).find('a:eq(0)').attr("class", "noLink");
        $j(cites[i]).find('a:eq(1)').hide('');
        $j(cites[i]).find('a:eq(3)').hide('');
    }
}
if (Ka.Info.PAGE == "pages/manageVideo.jsp") {
    $j("li#ka_mkpMyMedia a").attr('href', '/kickapps/view/displayManageVideo.kickAction?as=45960')
    $j('.ka_listEditDelete a[@name="update"]').hide();
}

if (Ka.Info.PAGE == "pages/commentDetails.jsp") {
    $j("li#ka_mkpMyMedia a").attr('href', '/kickapps/view/displayManageVideo.kickAction?as=45960')
}


if (Ka.Info.PAGE == "pages/newVideoUpload.jsp") {
    $j("#termsOfUse").attr("checked", "");
    $j('#ka_singleTitle label').html('*Video Title:');
    $j('#ka_descWrap label strong').html('*Brief Description');
    $j('#ka_postalCity strong').html('*City');
    $j('#ka_geoUpload label strong:eq(0)').html('*Country');
    $j('#postalProvince').attr('do-not-validate', true);

    $j('#videoUpload').before('<p class="disclaimer">Your personal information will not be displayed or shared with the public. It is only so that we can contact you to be on The Oprah Winfrey Show!</p>');
}

//Add H3 Header to every page
$j('#ka_header').after('<h3 id="worldsSmartestKids">Oprah\'s Search for the World\'s Smartest and Most Talented Kids</h3>');

if (Ka.Info.PAGE == "pages/manageVideo.jsp") {
    $j('#ka_manageSubNav').after('<h3 id="worldsSmartestKids2">Oprah\'s Search for the World\'s Smartest and Most Talented Kids</h3>');
}

if (Ka.Info.PAGE == "pages/commentDetails.jsp") {
    $j('#ka_manageSubNav').after('<h3 id="worldsSmartestKids2">Oprah\'s Search for the World\'s Smartest and Most Talented Kids</h3>');
}

if (Ka.Info.PAGE == "pages/newVideoUpload.jsp") {
    $j('#ka_manageSubNav').after('<h3 id="worldsSmartestKids2">Oprah\'s Search for the World\'s Smartest and Most Talented Kids</h3>');
}

//Show CSS
$j('#ka_headerLogin, .ka_more a, #emailArea a, #ka_mkpMyMedia a, .ka_addMedia a').show();

switch (Ka.Info.PAGE) {
    case "pages/myPlace.jsp":
        //Redirect Log in on Login
        document.location.href = '/kickapps/view/displayManageMyMedia.kickAction?as=45960';
        break;
    case "pages/newVideoUpload.jsp":
        //Add Different Nav on Video Upload Page
        $j('#ka_manageSubNav').append('<ul id="ka_headerSubNav_list"><li class="ka_addMedia ka_addMedia_video"><a href="/kickapps/service/displayVideoUpload.kickAction?as=45960">Add Your Video</a></li><li id="ka_subMostRecent"><a href="/kickapps/service/searchEverything.kickAction?as=45960&mediaType=video&sortType=recent&tab=yes&includeVideo=on&d-7095067-p=1">most recent</a></li><li id="ka_subHighRate"><a href="/kickapps/service/searchEverything.kickAction?as=45960&mediaType=video&sortType=rating&tab=yes&includeVideo=on&d-7095067-p=1">highest rated</a></li><li id="ka_subMostView"><a href="/kickapps/service/searchEverything.kickAction?as=45960&mediaType=video&sortType=popular&tab=yes&includeVideo=on&d-7095067-p=1">most viewed</a></li></ul>');

        // Pre-select 'Most Talented Kids'
        var html = $j("#categoryFormRow").html();
        $j("#categoryFormRow").remove();

        break;
    case "pages/mediaPlayPage.jsp":
        //Changing info in Ajax windows
        $j('.ka_thumbdetails').find('a:eq(1)').addClass('removeMemberName');

        $j("#ka_relatedTabs a").each(function(i, e) {
            $j(e)[0].onclick = function() { toggleRecommnededListOprah(e); return false; }
        });
        break;

        $j("#descWrap label strong").html("*Description");
}

setTimeout('doCat()', 3000);

function doCat() {
    if (Ka.Info.PAGE == "pages/newVideoUpload.jsp") {
        $j("<li>").html(html)
            .insertBefore($j("#termsOfUse").parent('li'))
            .find('option[value=79491]')
            .attr('required', 'true')[0].selected = "selected"
    }
}

$j(doAddVideo());
function doAddVideo() {
    //Change value of submit button
    if (Ka.Info.PAGE == "affiliate/homePage.jsp") {
        $j(".ka_button").attr("value", "add video");
    }
}
//Show add video button if user not logged in
if (Ka.Info.USERID == '') {
    $j('#ka_aboutContent input:first').hide();
    $j('<input type="button" class="ka_button" value="add video" />')
     .appendTo('#ka_aboutContent')
     .click(function() {
         document.location = document.location.href = 'http://www.oprah.com/mbr/mbr_login.jsp?redirectUrl=%2Fkickapps%2Fservice%2FdisplayVideoUpload.kickAction%3Fas%3D45960';
     });
}

//Add in Video Upload button for logged in user
if (Ka.Info.USERID !== '') {
    $j('body#ka_homepage #ka_aboutModule p.ka_noImage').after('<p class="inputButton"><input class="ka_button" type="button" value="add video" onclick="Javascript: document.location.href=\'http://viewervideo.oprah.com/kickapps/service/displayVideoUpload.kickAction?as=45960\';"/></p>');
    $j('#nav ul li.myMedia').attr("style", "");
    $j('#logoutLink').show();
} else {
}

//Change Intro Text
$j('body#ka_homepage #ka_aboutModule p.ka_noImage').html('Oprah is looking for children with extraordinary talent! Is your child funny or know more about world history than you do? Does she have an amazing voice? Does he have must-see dance moves? If so, we want to see your video! Hit the "add video" button below to upload your video. You can even upload video live from your webcam! Just select "video recording", and you\'ll be on your way. PLEASE NOTE: Parents, if you\'ve submitted a video to oprah.com and you haven\'t seen it posted yet that doesn\'t mean we haven\'t seen it. Our staff is watching every submission but not all of them can be posted immediately.  So please keep them coming! For more information about your video submission click <a target="_blank" href="http://static.oprah.com/popups/mediahelp.html">here</a>.');

/*
//Change Intro Text
$j('body#ka_homepage #ka_aboutModule p.ka_noImage').html('Oprah is looking for children with extraordinary talent! Is your child funny? Does her amazing voice bring tears to your eyes? Does he have dance moves that rival the professionals? Or know more about world history, politics or pop culture than you do? If so, we want to see your video! Hit the "add video" button below to upload your video.  You can even upload video live from your webcam! Just select "video recording", and you\'ll be on your way.');*/
//Stripping links
$j("a[href*=displayKickPlace]").attr('href', '#').click(function() { return false; });



//Login/Logout Create/Manage
if (Ka.Info.USERID == '') {
    $j('#ka_becomeAMember > a:eq(0)').html('Log In');

    //Hiding information for MS and all other browsers
    if ($j.browser.msie) {
        $j('#ka_becomeAMember > a:eq(0)')[0].nextSibling.removeNode();
        $j('#ka_becomeAMember > a:eq(1)').hide()[0].nextSibling.removeNode();
        $j('#ka_becomeAMember > a:eq(2)').hide()[0].nextSibling.removeNode();
    } else {
        $j('#ka_becomeAMember > a:eq(0)')[0].nextSibling.textContent = "";
        $j('#ka_becomeAMember > a:eq(1)').hide()[0].nextSibling.textContent = "";
        $j('#ka_becomeAMember > a:eq(2)').hide()[0].nextSibling.textContent = "";
    }
}

var gUsername = null;

function loginOprah() {
    var username = readCookie('harpo-loggedin');
    if (username != null && username != '') {
        if (Ka.Info.USERNAME == '') {
            var request = 'http://dev.kickapps.com/harpo/register.php?username=' + username;
            aObj = new JSONscriptRequest(request);
            aObj.buildScriptTag();
            aObj.addScriptTag();
        }
    }
}

function userIn(resp) {
    if (window.location.href.indexOf("?") == -1) {
        window.location.href = window.location.href + "?st=" + resp.sessionToken + "&tid=" + resp.transactionId;
    } else {
        window.location.href = window.location.href + "&st=" + resp.sessionToken + "&tid=" + resp.transactionId;
    }
}

$j(loginOprah);


if (document.getElementById('videoOrigFormat') != null && document.getElementById('videoOrigFormat') != '') {

    if (DWRUtil.getValue('userRole') == 'WEBMASTER' || DWRUtil.getValue('userRole') == 'EDITOR') {

        var links = '<br><a href="http://media2.kickapps.com/videos/' + DWRUtil.getValue("mediaId") + '.flv">FLV format</a><br>'; links += '<a href="http://static.kickapps.com/kickapps/images/videos/' + DWRUtil.getValue("mediaId") + DWRUtil.getValue("videoOrigFormat") + '">Original upload</a><br>';

        document.getElementById("ka_playPageDetails").innerHTML =

document.getElementById("ka_playPageDetails").innerHTML + links;

    }

}

//Remove tag cloud links
if (Ka.Info.PAGE == "affiliate/homePage.jsp") {
    $j('#ka_tagModule div a').each(function() {
        this.href = this.href += '&includeVideo=on';
    });
    $j('.ka_tag[@title="sample"]').hide();
} else if (Ka.Info.PAGE == "pages/mediaPlayPage.jsp") {
    $j('#ka_tagsText a').each(function() {
        this.href = this.href += '&includeVideo=on';
    });
}

// make upload fields required and rearrange
if (Ka.Info.PAGE == "pages/newVideoUpload.jsp") {
    // make fields required
    $j('#mediaName, #mediaDescription, #postalCity, #postalProvince').attr('required', true);

	
	// Check for the description
	$j(function(){
		window.validateAddVideo = function(formObj) {
		tinymce.EditorManager.editors['mediaDescription'].save();
		$j(".ka_Error").html(""); 
		Ka.formValidation.actions.disableSubmit(formObj);
		validateTags(formObj); }
	});

    // move to one container
    $j('#fieldVideoUpOpt').children(':not(legend)').appendTo('#fieldVideoUpReq');
    $j('#fieldVideoUpOpt').hide();
    //$j('#fieldVideoUpReq legend:first').text('Form')

    //change text
    var newText = $j('#ka_chooseFormat li:eq(0)').html().replace('Video Upload', 'Upload video');
    $j('#ka_chooseFormat li:eq(0)').html(newText);

    newText = $j('#ka_chooseFormat li:eq(1)').html().replace('Video Recording', 'Record directly from computer');
    $j('#ka_chooseFormat li:eq(1)').html(newText);
}

if (Ka.Info.PAGE == "pages/newVideoUpload.jsp") {
    $j('#ka_descWrap').after('<div id="form_FullName"><label><strong>*Full Name:</strong></label><input  required="true" id="mediaFullName" type="text" maxlength="512" value="" name="mediaFullName" size="30" /></div><div id="form_Age"><label><strong>*Age:</strong></label><input required="true" id="mediaAge" type="text" maxlength="2" value="" name="mediaAge" size="15" /></div><div id="form_ChildName"><label><strong>*Child Name:</strong></label><input required="true" id="mediaChildName" type="text" maxlength="512" value="" name="mediaChildName" size="30" /></div><div id="form_ChildAge"><label><strong>*Age of Child:</strong></label><input required="true" id="mediaChildAge" type="text" maxlength="2" value="" name="mediaChildAge" size="15" /></div>');
}

if (Ka.Info.PAGE == "pages/newVideoUpload.jsp") {
    $j('#ka_emailFriendsWrap').after('<div id="form_StreetAddress"><label><strong>Street Address:</strong></label><input id="mediaStreetAddress" type="text" maxlength="512" value="" name="mediaStreetAddress" size="30" /></div>');
}

if (Ka.Info.PAGE == "pages/newVideoUpload.jsp") {
    $j('#ka_geoUpload').after('<div id="form_EmailAddress"><label><strong>*Email:</strong></label><input required="true" id="mediaEmailAddress" type="text" maxlength="512" value="" name="mediaEmailAddress" size="30" /></div><div id="form_DaytimePhone"><label><strong>*Daytime Phone Number:</strong></label><input required="true" id="mediaDaytimePhone" type="text" maxlength="512" value="" name="mediaDaytimePhone" size="30" /></div><div id="form_CellPhone"><label><strong>Cell Phone Number:</strong></label><input id="mediaCellPhone" type="text" maxlength="512" value="" name="mediaCellPhone" size="30" /></div>');

    $j("#uploadbutton").unbind().click(function() {
        doAdminTags()
        return true;
    })
}

//Add in extra fields to video upload form
function doAdminTags(form) {
    var adminTags = "";

    adminTags = adminTags + "FullName:" + DWRUtil.getValue("mediaFullName").replace(/[^\@\.a-zA-Z0-9]+/g, '_') + " ";
    adminTags = adminTags + "Age:" + DWRUtil.getValue("mediaAge").replace(/[^\@\.a-zA-Z0-9]+/g, '_') + " ";
    adminTags = adminTags + "ChildName:" + DWRUtil.getValue("mediaChildName").replace(/[^\@\.a-zA-Z0-9]+/g, '_') + " ";
    adminTags = adminTags + "ChildAge:" + DWRUtil.getValue("mediaChildAge").replace(/[^\@\.a-zA-Z0-9]+/g, '_') + " ";
    adminTags = adminTags + "STAddress:" + DWRUtil.getValue("mediaStreetAddress").replace(/[^\@\.a-zA-Z0-9]+/g, '_') + " ";
    adminTags = adminTags + "EmailAddress:" + DWRUtil.getValue("mediaEmailAddress").replace(/[^\@\.a-zA-Z0-9]+/g, '_') + " ";
    adminTags = adminTags + "DaytimePhone:" + DWRUtil.getValue("mediaDaytimePhone").replace(/[^\@\.a-zA-Z0-9]+/g, '_') + " ";
    adminTags = adminTags + "CellPhone:" + DWRUtil.getValue("mediaCellPhone").replace(/[^\@\.a-zA-Z0-9]+/g, '_');

    // Set the Admin field
    var adminFld = document.getElementById("mediaAdminTags");
    if (adminFld) {
        adminFld.value = adminTags;
    }

    // … then submit the form
    //   form.submit();
}

setTimeout('noCommentError()', 3000);
function noCommentError() {
    if (Ka.Info.PAGE == "pages/mediaPlayPage.jsp") {
        var oldSendMessage = sendMessage;
        sendMessage = function() {
            tinymce.EditorManager.editors['text'].save();  // Force the tinyMCE object to write to text field
            if ($('text').value == '') {
                $j('#ka_mustError').remove();
                $j('#text').before('<span id="ka_mustError" class="ka_Error">Your comment cannot be blank.</span>');
            } else {
                $j('#ka_mustError').remove();
                oldSendMessage();
            }
        }
    }
}

if (Ka.Info.PAGE == "search/searchPage.jsp" && Ka.Util.getLocationParam('mediaType') == null) {
    $j('#ka_listPage').addClass('searchTags');
}

