$(document).ready(function(){
    categoryLinksPopUp();

    // change 'no-js' class to 'js' when Javascript is available
    $("#inner-wrapper").removeClass("no-js").addClass("js");

    // show/hide function for Sign Up Form

    $("#submitForm").hide();
    $("#submitForm").css("visibility", "visible"); 
    
    $("#sign-up .button").click(function() {
        $("#sign-up").hide();
        $("#submitForm").slideDown("normal");
        $("#submitForm").css("display", "block");
        $("#submitForm").css("visibility", "visible"); 
        return false; // prevents shifting of page when anchor is clicked on
    });

    // accordion function for Redeem for Rewards Page
    $("#first h3").addClass("open");
    $("#accordion li .rewards-details:not(#first .rewards-details)").addClass("hide");
    $("#accordion h3 a").click(function(){
        $(".open").removeClass("open");
        $("#accordion .rewards-details:visible").slideUp("fast");
        $(this).parent().addClass("open").next().slideDown("fast").removeClass("hide");
        return false; // prevents shifting of page when anchor is clicked on
    });

    // toggle function for Save Money With Blueprint Page
    $("#fullpay").addClass("selected");
    $("#icon-fullpay a").addClass("on");
    $(".blueprint-feature:not(.selected)").addClass("hide");
    $("#blueprint-icons a").click(function() {
        $("#blueprint-icons a").removeClass("on")
        $(this).addClass("on");
        var newFeature = $(this).attr("href").split("#")[1];
        $(".selected").removeClass("selected").addClass("hide");
        $("div#" + newFeature).removeClass("hide").addClass("selected");
        return false; // prevents shifting of page when anchor is clicked on
    });


    // show/hide function for logon module
    $("#account-login h3 a").click(function(){
        if ($("#logonModule").is(":hidden")) {
            $("#account-login h3").addClass("open");
            $("#logonModule").slideDown("normal");
        }
        else {
            $("#account-login h3").removeClass("open");
            $("#logonModule").slideUp("normal");
        }
        return false; // prevents shifting of page when anchor is clicked on
    })
});


/* Calendar Popup Function - For the Homepage Flash */
function categoryCalendarClick() {
    popIt('calendar.htm','MainPop',0,1,0,0,0,1,720,535);
}


function categoryLinksPopUp() {
    if (!document.getElementById) return false;
    
    if (document.getElementById("calendar-link") != null){
        var calendar = document.getElementById("calendar-link");
        var calendarLink = calendar.getAttribute("href");
        calendar.onclick = function(){
        popIt(calendarLink, 'MainPop', 0, 1, 0, 0, 0, 1, 720, 535);
        return false;
        }
    } 
    if (document.getElementById("calculator-link") != null){
        //now popping up calculator in a window for consistency
        var calculator = document.getElementById("calculator-link");
        var calculatorLink = calculator.getAttribute("href");
        //now popping up calculator in a window for consistence
        calculator.onclick = function() {
        popIt(calculatorLink,'Calculator',0,1,0,0,0,1,830,840);
        return false;
        }
    }
    if (document.getElementById("category-faqs-link") != null){
        var category = document.getElementById("category-faqs-link");
        var categoryLink = category.getAttribute("href");
        category.onclick = function() {
        popIt(categoryLink,'MainPop',0,1,0,0,0,1,720,535);
        return false;
        }
    }
    if (document.getElementById("terms-link") != null){
        var terms = document.getElementById("terms-link");
        var termsLink = terms.getAttribute("href");
        terms.onclick = function() {
        popIt(termsLink,'MainPop',0,1,0,0,0,1,720,535);
        return false;
        }
    }     
 
}


function popIt(url, name, tb, sb, lo, st, mu, rs, w, h){
    popupWin = window.open(url, name, +',toolbar=' + tb + ',scrollbars=' + sb + ',location=' + lo + ',statusbar=' + st + ',menubar=' + mu + ',resizable=' + rs + ',width=' + w + ',height=' + h);
    if (window.focus) {
        if (popupWin != null){
            popupWin.focus();
        }    
    }
}

//support function for checkEnrolled()
function getURLParam(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  
  if( results == null )
    return "";
  else
    return results[1];
}

//Check if the status url param is set.  If so the user is enrolled and we need to display the 
//enrolled version of the calendar and footer links on each popup
function checkEnrolled()
{
    var status = "";
     status = getURLParam("status");
    
    
    
    if (status){
        //we need to update the footer links to be enrolled
        var calendar = document.getElementById("calendar-link2");
        var calendarLink = calendar.getAttribute("href");
        calendar.setAttribute("href", calendarLink + "?status=1");
        var terms = document.getElementById("terms-link2");
        var termsLink = terms.getAttribute("href");
        terms.setAttribute("href", termsLink + "?status=1");
        var category = document.getElementById("category-faqs-link2");
        var categoryLink = category.getAttribute("href");
        category.setAttribute("href", categoryLink + "?status=1");
       
        //we need to replace the overlay image to enrolled
        //on calendar page
        if (document.getElementById("activateImage") != null){
            var activateImage = document.getElementById("activateImage");
            //no setAttribute for ie6
            activateImage.className = "activateImageEnrolled"; 
        }  
        //there's 2 more links now in the faqs to consider
        if (document.getElementById("termsLink2") != null){
            var terms2 = document.getElementById("termsLink2");
            var termsLink2 = terms2.getAttribute("href");
            terms2.setAttribute("href", termsLink2 + "?status=1");
        }  
        if (document.getElementById("calendarLink2") != null){
            var calendar2 = document.getElementById("calendarLink2");
            var calendarLink2 = calendar2.getAttribute("href");
            calendar2.setAttribute("href", calendarLink2 + "?status=1");
        }  
    }
    return;

}

function ShowDetails(obj) {
    alert(obj);
}


