function runVoteCheck(idNum){
    var voteBox = document.getElementById("voteBox");
    var voteText = 'Vote For Your Favorite Or Submit Your Own';
    var voteUrl = '';
    var voteHTML = ''
    switch(idNum) {
        case "1412":
        voteBox.style.display="block";
        voteUrl = '/ideas/beachisland/tours/favoritebeaches/vote';
        voteHTML = buildButton(voteText, voteUrl);
        voteBox.innerHTML = voteHTML;
        break;    
        case "1435":
        voteBox.style.display="block";
        voteUrl = '/ideas/activeadventure/tours/favoriteroadtrips/vote';
        voteHTML = buildButton(voteText, voteUrl);
        voteBox.innerHTML = voteHTML;
        break;    
        case "1583":
        voteBox.style.display="block";
        voteUrl = '/ideas/holidays/tours/holidaygiftguide/vote';
        voteHTML = buildButton(voteText, voteUrl);
        voteBox.innerHTML = voteHTML;
        break;                
    }    
}

function buildButton(text,url) {    
    var buttonCode = '<span class="yellowOnBlackCssButton">';
    buttonCode = buttonCode + '<a href="' + url + '">';
    buttonCode += text;    
    buttonCode += '</a></span>';
    return buttonCode;
}

var mostRecentState = false;
var topRatedState = false;
var redditSort = "&s=new";

function setStyle(thisId,otherId) {
    
    if (thisId == 'mostRecent') {
        if (mostRecentState == false) {
            sortRedditFrame("new");
            document.getElementById(thisId).parentNode.className="asc";
            document.getElementById(otherId).parentNode.className="off";            
            topRatedState = false;
            mostRecentState = true;
            return;
        }
        if (mostRecentState == true) {
            sortRedditFrame("old");
            document.getElementById(thisId).parentNode.className="desc";
            document.getElementById(otherId).parentNode.className="off";  
            mostRecentState = false;
            topRatedState = false;
            return;
        } 
        
    }
    if (thisId == 'topRated') {
        if (topRatedState == false) {
            sortRedditFrame("top");
            document.getElementById(thisId).parentNode.className="desc";
            document.getElementById(otherId).parentNode.className="off";  
            mostRecentState = false;
            topRatedState = true;
            return;
        }
        if (topRatedState == true) {
            sortRedditFrame("bottom");
            document.getElementById(thisId).parentNode.className="asc";
            document.getElementById(otherId).parentNode.className="off";  
            mostRecentState = false;
            topRatedState = false;
            return;
        }             
    }    
    
   
}    

function sortRedditFrame (value) {
    var iframeSrc = document.getElementById('reddit_yay_nay').src;
    var iframeRoot = iframeSrc.substring(0,iframeSrc.indexOf('?'));
    var iframeQuery = iframeSrc.substring(iframeSrc.indexOf('?')+1);
    var redditParm = new Array();
    var parms = iframeQuery.split('&');
    var newParams = '?';

    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);
            redditParm[key] = val;
        }
    }
    
    redditParm['s']=value;
    
    for (key in redditParm) {
        newParams = newParams + key + "=" + redditParm[key] + "&"; 
    }
    newParams = newParams.substring(0,newParams.length-1);
    window.frames['redditVote'].location = iframeRoot + newParams;
}

 