﻿/************************************Load Poll jQuery **********************************/
//  This jQuery ready function will check if the page is currently in
//  design mode or display mode.
//  If in design mode then it will display the poll selection control
//  If in display mode then it will load ShowPoll page.
//  Need to pass in the name of the current page so that it can pick up
//  which poll to render.
//  by TT0207 (May 2010)
/*********************************On Load Function Call Start **************************/

$(document).ready(function() {
    function isDesignMode() {
        if ($("input[name=MSOLayout_InDesignMode]").val() == '1') return true;
        if ($("input[name=MSOTlPn_SelectedWpId]").val() != '') return true;
        if ($("input[name=MSOSPWebPartManager_DisplayModeName]").val() == 'Design' || $("input[name=MSOSPWebPartManager_DisplayModeName]").val() == 'Edit') return true;
        return false;
    }
    if (!isDesignMode()) {

        var sPath = window.location.pathname;
        var pagesLib = "/pages/";
        var url = new String(window.location);
        url = url.toLowerCase();

        var domainUrl = url.substr(0, url.indexOf(pagesLib));
        var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
        var loadURL = domainUrl + "/_layouts/SP.WebControls.SimplePoll/ShowPoll.aspx?URL=" + sPage;

        var temp = $(".SimplePollHTML").load(loadURL); $(".SimplePoll").replaceWith(temp);

    }
});
