﻿var userAccessLevel = 0;
var displayComedy = false;
var cookie = document.cookie;

userAccessLevel = cookie.substr(cookie.search("AccessLevel=") + 12, 1);

if (userAccessLevel > 1) {
    displayComedy = true;
}

function changePageTitle(suffix) {
    document.title = 'Go Prep Yourself - ' + suffix;
}

function showEmbed(videoId) {
    window.open('EmbedCode.aspx?VideoId=' + videoId + '', 'terms', 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=400, height=400, left=100, top=25', false);
}
            
function showTerms() {
    window.open('Terms.htm', 'terms', 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=400, height=600, left=100, top=25', false);
}

function showPrivacy() {
    window.open('Privacy.htm', 'terms', 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=400, height=600, left=100, top=25', false);
}

function showAbout() {
    window.open('About.htm', 'terms', 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=400, height=600, left=100, top=25', false);
}

function loadTagPage(tag) {
    document.location = 'Search.aspx?k=' + tag + '&o=1';
}

function outputExtraStylesheet() {
    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    var is_safari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
    if (is_chrome == true || is_safari == true) {
        document.write('<link rel="Stylesheet" type="text/css" href="chrome.css" />');
    }
}

function doSearch() {
    var searchBox = document.getElementById("searchTextBox");
    if (searchBox != null) {
        var keyword = searchBox.value;

        if (keyword.length > 0) {
            document.location = "Search.aspx?k=" + keyword;
        }
    }
}
    
function kH(e) {
    var pK = e ? e.which : window.event.keyCode;
    if (pK == 13)
    {
        if (document.activeElement.id == 'searchTextBox') {
            doSearch();
        }
        else if (document.activeElement.id == 'refineSearchTextBox') {
            doAdvancedSearch();
        }
        else if (document.activeElement.id == 'passwordTextBox') { //sign the poor sod in
            return true;
        }
    }
    return pK != 13;
}

document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
      
     
function outputNav(displayComedy)                                   
{
    var navString = '<div id="nav">' +
            '<a href="Home.aspx"><img border="0" src="images/nav/gpynavbar_01.gif" title="Home" alt="Home" /></a>' +
            '<a href="StoryIndex.aspx"><img border="0" src="images/nav/gpynavbar_02.gif" alt="News" title="News" /></a>' +
            '<a href="Lifestyle.aspx"><img border="0" src="images/nav/gpynavbar_03.gif" alt="Lifestyle" title="Lifestyle" /></a>' + 
            '<a href="BitsIndex.aspx"><img border="0" src="images/nav/gpynavbar_04.gif" alt="Bits &amp; Games" title="Bits &amp; Games"/></a>';
            
            if (displayComedy == true)
            {
                navString = navString + '<a href="PrepMeHarder.aspx" target="_blank"><img border="0" src="images/nav/gpynavbar_05.gif" alt="Prep Me Harder!" title="Prep Me Harder!"/></a>';
            }

            navString = navString + '<a href="Links.aspx"><img border="0" src="images/nav/gpynavbar_06.gif" alt="Links" title="Links" /></a>' +
            '<a href="Audio.aspx"><img border="0" src="images/nav/gpynavbar_07.gif" alt="Audio" title="Audio" /></a>' +
            '<a href="VideoPage.aspx"><img border="0" src="images/nav/gpynavbar_08.gif" alt="Video" title="Video" /></a>' +
            '<a href="Phoneburners.aspx"><img border="0" src="images/nav/gpynavbar_09b.gif" alt="Phoneburners" title="Phoneburners" /></a>' +
            '<a href="PrintItYourWay.aspx"><img border="0" src="images/nav/gpynavbar_10.gif" alt="Go Print Yourself!" title="Go Print Yourself!"/></a>';

            if (displayComedy == false) {
                navString = navString + '<a href="ContactUs.aspx" target="_blank"><img border="0" src="images/nav/gpynavbar_10b.gif" alt="Contact Us" title="Contact Us"/></a>';
            }

            navString = navString + '<a href="Favorites.aspx"><img border="0" src="images/nav/gpynavbar_faves.gif" alt="Your Favorites" title="Your Favorites" /></a></div>';

            //navString = navString + '<div id="favoritesLink"><a href="Favorites.aspx">Your Favorites</a></div>';
            
            document.write(navString);

            //based on whether we displayed the Prep Me Harder icon in the nav,
            //we have to resize the nav div so that it centers properly
            var currentStyle = document.styleSheets[0];
            var currentRules = currentStyle.cssRules ? currentStyle.cssRules.length : currentStyle.rules.length;
            if (currentStyle.deleteRule) //if Firefox
            {
                if (displayComedy == true) {
                    currentStyle.insertRule("#nav{width: 795px; }", currentRules - 1);
                }
                else {
                    currentStyle.insertRule("#nav{width: 795px; }", currentRules - 1);
                }
            }
            else if (currentStyle.removeRule) //else if IE
            {
                if (displayComedy == true) {
                    currentStyle.addRule("#nav", "width: 795px");
                }
                else {
                    currentStyle.addRule("#nav", "width: 795px");
                }
            }
        }

        function outputHeader(splash) {
            var headerString = "";

            if (splash == true) {
                headerString = '<div id="header">' +
                '<img border="0" src="images/splash/headline.jpg" alt="Go Prep Yourself!" Title="Go Prep Yourself!" />' +
                '</div>';
            }
            else {

                headerString = '<div id="header">' +
                '<p class="centeredImage">' +
                '<a href="Home.aspx">' +
                '<img border="0" src="images/GPYHeader.png" alt="Go Prep Yourself!" Title="Go Prep Yourself!" />' +
                '</a></p></div>';
            }
        document.write(headerString);
    }

    function outputSearch(compact) {
        var searchAreaString = '<div id="search"><span id="searchField">';

        if (compact == false) {
            searchAreaString += 'ENTER TEXT ';
            }
            
            searchAreaString += '<input type="text" id="searchTextBox" /></span>' +
            '<span id="searchBut">' +
            '<img onclick="doSearch();" border="0" src="images/GPYsearchbut.jpg" title="Search" alt="Search" />' +
            '</span>' +
            '</div>';
        
        document.write(searchAreaString);
    }
    
    function outputTopBar(amount, displayPopular) {
        var topBar = '<div id="topBar">';

        if (displayPopular == true) {
            topBar = topBar + '<span id="recentpop"><img id="recentButton" src="images/GPYrecent_off.gif" title="Recent Stories" border="0" />' +
                    '<img id="popularButton" onclick="getPopular()" src="images/GPYpopular_on.gif" title="Popular Stories" border="0" />';
        }
        else {
            //topBar = topBar + '<img border="0" id="spacer" src="images/spacer.gif" width="114px" height="26px">';
            if (amount == 5) {
                topBar = topBar + '<span id="prev5"><a><img onclick="prev5();" class="prev5" border="0" id="prev5stories" src="images/prev5stories.png" height="12px" width="100px"></a>';
            }
            else if (amount == 10) {
            topBar = topBar + '<span id="prev10"><a><img onclick="prev10();" class="prev10" border="0" id="prev10stories" src="images/prev10stories.png" height="12px" width="100px"></a>';
            }
        }
        
        topBar = topBar + '</span>';
                
        if (amount == 5)
        {
            topBar = topBar + '<span id="next5">' +
                '<a><img id="next5button" onclick="next5();" title="Next 5 Stories" src="images/next5stories.png" width="100" height="9" border="0"/></a></span>';
        }
        else if (amount == 10)
        {
            topBar = topBar + '<span id="next10">' +
                '<a><img id="next10button" onclick="next10();" title="Next 10 Stories" src="images/next10stories.png" width="100" height="9" border="0"/></a></span>';
        }

        topBar = topBar + '</div>';

        document.write(topBar)

        //based on whether we are displaying 5 or 10 stories,
        //we have to resize the topBar and topStories divs so that they center properly
        var currentStyle = document.styleSheets[0];
        var currentRules = currentStyle.cssRules ? currentStyle.cssRules.length : currentStyle.rules.length;
        if (currentStyle.deleteRule) //if Firefox
        {
            if (amount == 5) {
                currentStyle.insertRule("#topBar{width: 764px; }", currentRules - 1);
                currentStyle.insertRule("#topStories{width: 780px; }", currentRules - 1);
            }
            else {
                currentStyle.insertRule("#topBar{width: 786px; }", currentRules - 1);
                currentStyle.insertRule("#topStories{width: 790px; }", currentRules - 1);
            }
        }
        else if (currentStyle.removeRule) //else if IE
        {
            if (amount == 5) {
                currentStyle.addRule("#topBar", "width: 764px");
                currentStyle.addRule("#topStories", "width: 780px");
            }
            else {
                currentStyle.addRule("#topBar", "width: 786px");
                currentStyle.addRule("#topStories", "width: 790px");
            }
        }
    }

    function outputFooter() {

        var curYear = new Date();
        curYear = curYear.getFullYear();

        var footer = '<div id="footer">©' + curYear + ' United Stations Radio Networks &#8226 <span id="footerLinkSpan" class="footerLinks"><a onclick="showTerms();">Terms & Conditions</a> &#8226 <a href="ContactUs.aspx">Contact Us</a> &#8226 <a onclick="showAbout();">About Us</a></span></div>';

        document.write(footer);
        
    }
    
    
    function outputTopStories(amount) { //DO NOT USE
        var topStories = '<div id="topStories">';
        
        if (amount == 5)
        {
            topStories = topStories + '<div id="headline1" class="headlines" runat="server"></div>' + 
                '<div id="topStory1" class="topStoryContainers" runat="server"></div>' + 
                '<div id="headline2" class="headlines" runat="server"></div>' + 
                '<div id="topStory2" class="topStoryContainers" runat="server"></div>' + 
                '<div id="headline3" class="headlines" runat="server"></div>' + 
                '<div id="topStory3" class="topStoryContainers" runat="server"></div>' + 
                '<div id="headline4" class="headlines" runat="server"></div>' + 
                '<div id="topStory4" class="topStoryContainers" runat="server"></div>' + 
                '<div id="headline5" class="headlines" runat="server"></div>' + 
                '<div id="topStory5" class="topStoryContainers" runat="server"></div>';   
        }
        else if (amount == 10)
        {
            topStories = topStories + '<span id="topStory1" runat="server"></span>' + 
                '<span id="topStory2" runat="server"></span>' +
                '<span id="topStory3" runat="server"></span>' + 
                '<span id="topStory4" runat="server"></span>' + 
                '<span id="topStory5" runat="server"></span>' + 
                '<span id="topStory6" runat="server"></span>' + 
                '<span id="topStory7" runat="server"></span>' + 
                '<span id="topStory8" runat="server"></span>' + 
                '<span id="topStory9" runat="server"></span>' + 
                '<span id="topStory10" runat="server"></span>';

        }

        topStories = topStories + '</div>';

        document.write(topStories);
    }

    function fixStyleSheetForComedy() {
        //based on whether we are displaying comedy in the scoller, we have to fix the styles
        var currentStyle = document.styleSheets[0];
        var currentRules = currentStyle.cssRules ? currentStyle.cssRules.length : currentStyle.rules.length;
        
        if (displayComedy == true) {
            if (currentStyle.deleteRule) //if Firefox
            {
                currentStyle.insertRule("div#firstLookDiv{font-family: Arial; }", currentRules - 1);
                currentStyle.insertRule("div#firstLookDiv{text-align: left; }", currentRules - 1);
                currentStyle.insertRule("div#firstLookDiv{font-size: small; }", currentRules - 1);
                currentStyle.insertRule("div#firstLookDiv{padding: 5px; }", currentRules - 1);
                currentStyle.insertRule("div#firstLookDiv{width: 544px; }", currentRules - 1);
                currentStyle.insertRule("div#firstLookDiv{overflow: auto; }", currentRules - 1);
                currentStyle.insertRule("div#firstLookDiv{height: 120px; }", currentRules - 1);
                currentStyle.insertRule("div#firstLookDiv{max-height: 150px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{position:relative; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{text-align: center; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{padding: 2px;}", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{border: Defaultpx dotted ; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{width: 240px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{min-height: 90px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{max-height: 390px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{overflow: auto; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{max-width: 240px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{text-align: center; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{position:relative;}", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{width:230px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{max-width: 230px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{min-height: 90px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{max-height: 390px;}", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{overflow: auto;}", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{padding: 0px; }", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{font-family: arial; }", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{color: white;}", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{margin: 1px; }", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{cursor: pointer; }", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{font-size: medium; }", currentRules - 1);
            }
            else if (currentStyle.removeRule) //else if IE
            {
                currentStyle.addRule("div#firstLookDiv", "font-family: Arial");
                currentStyle.addRule("div#firstLookDiv", "text-align: left");
                currentStyle.addRule("div#firstLookDiv", "font-size: small");
                currentStyle.addRule("div#firstLookDiv", "padding: 5px; }");
                currentStyle.addRule("div#firstLookDiv", "width: 544px");
                currentStyle.addRule("div#firstLookDiv", "overflow: auto");
                currentStyle.addRule("div#firstLookDiv", "height: 120px");
                currentStyle.addRule("div#firstLookDiv", "max-height: 150px");
                currentStyle.addRule("div#tagcloud-container", "position:relative");
                currentStyle.addRule("div#tagcloud-container", "text-align: center");
                currentStyle.addRule("div#tagcloud-container", "padding: 2px");
                currentStyle.addRule("div#tagcloud-container", "border: Defaultpx dotted ");
                currentStyle.addRule("div#tagcloud-container", "width: 240px");
                currentStyle.addRule("div#tagcloud-container", "min-height: 90px");
                currentStyle.addRule("div#tagcloud-container", "max-height: 390px");
                currentStyle.addRule("div#tagcloud-container", "overflow: auto");
                currentStyle.addRule("div#tagcloud-container", "max-width: 240px");
                currentStyle.addRule("div#tagcloud", "text-align: center");
                currentStyle.addRule("div#tagcloud", "position:relative");
                currentStyle.addRule("div#tagcloud", "width:230px");
                currentStyle.addRule("div#tagcloud", "max-width: 230px");
                currentStyle.addRule("div#tagcloud", "min-height: 90px");
                currentStyle.addRule("div#tagcloud", "max-height: 390px");
                currentStyle.addRule("div#tagcloud", "overflow: auto");
                currentStyle.addRule("div#tagcloud", "padding: 0px");
                currentStyle.addRule("div#tagCloud a", "font-family: arial");
                currentStyle.addRule("div#tagCloud a", "color: white");
                currentStyle.addRule("div#tagCloud a", "margin: 1px");
                currentStyle.addRule("div#tagCloud a", "cursor: pointer");
                currentStyle.addRule("div#tagCloud a", "font-size: medium");
            }
        }
        else {
            if (currentStyle.deleteRule) //if Firefox
            {
//                currentStyle.insertRule("div#firstLookDiv{font-family: Arial; }", currentRules - 1);
//                currentStyle.insertRule("div#firstLookDiv{text-align: left; }", currentRules - 1);
//                currentStyle.insertRule("div#firstLookDiv{font-size: small; }", currentRules - 1);
//                currentStyle.insertRule("div#firstLookDiv{padding: 5px; }", currentRules - 1);
//                currentStyle.insertRule("div#firstLookDiv{width: 544px; }", currentRules - 1);
//                currentStyle.insertRule("div#firstLookDiv{overflow: auto; }", currentRules - 1);
//                currentStyle.insertRule("div#firstLookDiv{height: 120px; }", currentRules - 1);
//                currentStyle.insertRule("div#firstLookDiv{max-height: 150px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{position:relative; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{text-align: center; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{padding: 2px;}", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{border: Defaultpx dotted ; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{width: 544px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{min-height: 120px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{max-height: 150px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{overflow: auto; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud-container{max-width: 544px; }", currentRules - 1);
                
                currentStyle.insertRule("div#tagcloud{text-align: center; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{position:relative;}", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{width:534px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{max-width: 534px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{min-height: 120px; }", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{max-height: 150px;}", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{overflow: auto;}", currentRules - 1);
                currentStyle.insertRule("div#tagcloud{padding: 0px; }", currentRules - 1);
                
                currentStyle.insertRule("div#tagCloud a{font-family: arial; }", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{color: white;}", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{margin: 1px; }", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{cursor: pointer; }", currentRules - 1);
                currentStyle.insertRule("div#tagCloud a{font-size: medium; }", currentRules - 1);
            }
            else if (currentStyle.removeRule) //else if IE
            {
//                currentStyle.addRule("div#firstLookDiv", "font-family: Arial");
//                currentStyle.addRule("div#firstLookDiv", "text-align: left");
//                currentStyle.addRule("div#firstLookDiv", "font-size: small");
//                currentStyle.addRule("div#firstLookDiv", "padding: 5px; }");
//                currentStyle.addRule("div#firstLookDiv", "width: 544px");
//                currentStyle.addRule("div#firstLookDiv", "overflow: auto");
//                currentStyle.addRule("div#firstLookDiv", "height: 120px");
//                currentStyle.addRule("div#firstLookDiv", "max-height: 150px");
                currentStyle.addRule("div#tagcloud-container", "position:relative");
                currentStyle.addRule("div#tagcloud-container", "text-align: center");
                currentStyle.addRule("div#tagcloud-container", "padding: 2px");
                currentStyle.addRule("div#tagcloud-container", "border: Defaultpx dotted ");
                currentStyle.addRule("div#tagcloud-container", "width: 544px");
                currentStyle.addRule("div#tagcloud-container", "min-height: 120px");
                currentStyle.addRule("div#tagcloud-container", "max-height: 150px");
                currentStyle.addRule("div#tagcloud-container", "overflow: auto");
                currentStyle.addRule("div#tagcloud-container", "max-width: 544px");

                currentStyle.addRule("div#tagcloud", "text-align: center");
                currentStyle.addRule("div#tagcloud", "position:relative");
                currentStyle.addRule("div#tagcloud", "width:534px");
                currentStyle.addRule("div#tagcloud", "max-width: 534px");
                currentStyle.addRule("div#tagcloud", "min-height: 120px");
                currentStyle.addRule("div#tagcloud", "max-height: 150px");
                currentStyle.addRule("div#tagcloud", "overflow: auto");
                currentStyle.addRule("div#tagcloud", "padding: 0px");

                currentStyle.addRule("div#tagCloud a", "font-family: arial");
                currentStyle.addRule("div#tagCloud a", "color: white");
                currentStyle.addRule("div#tagCloud a", "margin: 1px");
                currentStyle.addRule("div#tagCloud a", "cursor: pointer");
                currentStyle.addRule("div#tagCloud a", "font-size: medium");
            }
        }
    }
