var cookieName = "pollPops";

function CheckPollCookie() {
//
    if ($(".PollPopup").length) {

        $("#popContainer").css("display", "block");

    if (!$.cookie(cookieName)) {
        $(".PollPopup").css("display","block");
    }
    else {
        $(".PollPopup").hide("slow");
    }
}

}
function popUp(choice) {
    //expires: 30,
    if (choice) {
        $.cookie(cookieName, "true", { path: '/', expires: 30 });
        $(".PollPopup").hide("slow");
    }
    else {
        $.cookie(cookieName, "false", { path: '/', expires: 30 });
    }
    
    $(".PollPopup").hide("slow");

}




//This loads main style sheet
//seperated by name attribute as to not interfere with other/print style sheets

function GoSearch()
{
document.location = "/en/The_Board/Board_Members_Area/Search/?Query="+$("#q").val();
}

function GetSearchText()
{

if(document.location.toString().match("/ga/") == "/ga/")
{
    var text = "Cuardaigh an l%E1ithre%E1n seo";
    text = unescape(text);
     $("#q").val(text);
     $("#searchimg").attr('src','/images/search-button-text-gaeilge.gif');
}
else
{
     $("#q").val('Search this site');
     $("#searchimg").attr('src','/images/search-button-text.gif');     

}

}

function RemoveH1()
{

$("#formdata h1").css('display','none');
if(document.location.toString().match("/ga/") == "/ga/")
{
$("span#privacyLink").css('display','none');
$("input#ctl00_ctl00_ContentPlaceHolder_Main_ContentPlaceHolder_Sub_btnSubmit").attr('src','/images/submit-button-ga.gif');
$("input#ctl00_ctl00_ContentPlaceHolder_Main_ContentPlaceHolder_Sub_btnSubmit").css('width','91px');


}
}


function SetCurrentStyle()
{
        if($.cookie("css")) {
         $("link[id=mainStyle]").attr("href","/includes/css/"+$.cookie("css"));
        }
 
}

function CheckMenuClasses()
{
    
    
    if($("#left-nav-list ul li.first").hasClass('active-trail')) 
    {
       $("#left-nav-top").attr("id","left-nav-top-active");
    }
       
    
    if($("#left-nav-list ul li.last").hasClass('active-trail')) 
    {
            $("#left-nav-bottom").attr("id","left-nav-bottom-active");
    }
    
    
 
}


function CheckMissingIrishLink()
{

    if($("a#engLink").size())
    {
         $("a#engLink").attr('href', $("a.SwitchLink").attr('href'));
         $("h1").css('display','none');
    }

}

 
 //sets style sheet, remember to add /includes/css/ etc
$(document).ready(function() {

    $("#header-links-right a").click(function() {
        $("link[id=mainStyle]").attr("href", "/includes/css/" + $(this).attr('rel'));
        $.cookie("css", $(this).attr('rel'), { expires: 365, path: '/' });
        return false;
    });


    $("#EnableAgree").click(function() {

        if ($('#EnableAgree').is(':checked')) {
            $("#ctl00_ctl00_ContentPlaceHolder_Main_ContentPlaceHolder_Sub_btnSend").removeClass('disabled');
            $("#ctl00_ctl00_ContentPlaceHolder_Main_ContentPlaceHolder_Sub_btnSend").removeAttr('disabled');
        }
        else {
            $("#ctl00_ctl00_ContentPlaceHolder_Main_ContentPlaceHolder_Sub_btnSend").addClass('disabled');

            $("#ctl00_ctl00_ContentPlaceHolder_Main_ContentPlaceHolder_Sub_btnSend").attr('disabled', 'true');

        }
    });

    SetCurrentStyle();
    CheckMenuClasses();
    GetSearchText();
    CheckMissingIrishLink();
    CheckPollCookie();

    if (document.getElementById("MainHeader")) {

        $("h1#MainHeader").text($("h1#hiddenTitle").text());
        $("span#hiddenTitle").hide();
        $("h1#MainHeader").css({ 'display': 'block' });


    }
});

 function PrintCalculatorFrame() {
     var frameCode = "";
     var formSrc = "http://forms.pensionsboard.ie/pbcalc/pensioncalculator_nobanners1.asp";


     if ((window.name != null) && (window.name != "")) {
         frameCode = "<iframe id='myFrame' src='" + formSrc + "' width='700' height='1500' target='" + window.name + "' frameborder='0' scrolling='auto'>Your Browser does not support iframes</iframe>";
     }

     else {
         frameCode = "<iframe id='myFrame' src='" + formSrc + "' width='700' height='1500' target='CalculatorFrame' frameborder='0' scrolling='auto'>Your Browser does not support iframes</iframe>";
     }

     if ((frameCode != null) && (frameCode != "")) {
         document.write(frameCode);
     }
 }
