﻿$(function() {

    if ($('.dvReadSpeaker').length == 1) {
        readpage($('#hdReadSpeaker').val(), "readspeakerContainer");
    }


    preparePresentationTypeControl("input[name='radioGroup01']", "input[name='radioGroup001']");
    prepareMediaDocumentControl("input[name='fRadionGroup04']", "input[name='fRadionGroup05']");

    $(".historyBar li:first").addClass("timeNavFirst");
    $(".historyBar li:last").addClass("timeNavLast");

    $(".yearNav li:first").addClass("ynFirst");
    $(".yearNav li:last").addClass("ynLast");

    $(".featureBoxList  li:first").addClass("fbListFirst");
    $(".featureBoxList  li:last").addClass("fbListLast");

    if ($(".selected").prev().hasClass('eventYear')) {
        $(".selected").prev().addClass('prevToSelected');
    }


    $('.tandcError').hide(); 
 
    $(".fCheckBox").click(function() {
      var statusOfCheckBox = $('.fCheckBox')[0].firstChild.checked;
      if(statusOfCheckBox)
         $('.tandcError').hide();
      else
        $('.tandcError').show();
    });


    $(".submitClass").click(function() {
        var statusOfCheckBox = $('.fCheckBox')[0].firstChild.checked;
        if(statusOfCheckBox)
            $('.tandcError').hide();
        else {
            $('.tandcError').show();
            return false;
        }
    });
   
   
    $(".backtoeventlist").click(function() {
        window.history.back();
    });

    $(".PRSignUp").click(function() {
        if ($('input[type=checkbox]:checked').length > 0) {
            $('#chkError').text("");
        }
        else {
            $('#chkError').text("Please check alleast one language");
            return false;
        }
    });



    $(".languageChk").click(function() {

        if ($('input[type=checkbox]:checked').length > 0) {
            $('#chkError').text("");
        }
        else {
            $('#chkError').text("Please check alleast one language");
        }
    });




    if ($(".chkEvent").find('input[type=checkbox]:checked').length > 0) {
        $('.chkEventError').text("");
    }
    else {
        $('.chkEventError').text("Please select at least one in Media and Investor");
    }


    function checkEvents() {
        if ($(".chkEvent").find('input[type=checkbox]:checked').length > 0) {
            $('.chkEventError').text("");
        }
        else {
            $('.chkEventError').text("Please select at least one in Media and Investor");
        }
    }

    $(".chkEvent").find('input[type=checkbox]').change(checkEvents);

    $(".chkEvent").find('input[type=checkbox]').click(checkEvents);




    $('.showWhatAreThesePopUp').click(function() {
        var href = $(this).attr('href');
        $('.pubContent').load(href + ' #whataretheseContainer');
    });

    $('.videoPopup').colorbox({
        href: function() {
            var href = $(this).attr('href');
            var guid = href.split('guid=');
            return "~/VideoPopup.ashx?guid=" + guid[1];
        },
        title: function() {
            var title = $(this).attr('title');
            if (title.length > 50)
                title = title.substring(0, 47) + '...';
            return title;
        }
    });

    $('.ajaxPopup').click(function() {
        $('.showKPIData').show();
        var href = $(this).attr('href');
        $('.pubContainerKPI h3 span').text("");
        $('.pubContentKPIPopup').text("");
        $('.pubContainerKPI h3 span').load(href + ' #mainCol .content h1', function() {
            var titleText = $('.pubContainerKPI h3 span').text();
            $('.pubContainerKPI h3 span').html(titleText);
        });

        $('.pubContentKPIPopup').load(href + ' .pubContentKPI');

        loadKPIContent(href);

        return false;
    });

    $('.relatedImagesAjaxPopup').click(function() {
        $('.relatedImagesPopupBox').show();
        relatedImagesAjaxPopup = $(this)[0];
        title =$(this).parent()[0].document.title;
        if(title == "Management")
        {
            ImageTotalCount = $(this).parent()[0].childNodes.length - 1;
        }
        else
        {
            ImageTotalCount = $(this).parent()[0].childNodes.length;
        }
        ImagePresentCount = $(this).attr('id');
        var href = $(this).attr('href');

        $('#relatedImages .pubContent .pubImageShow').load(href + ' #pageContentBlock .container .pubContent .pubImageShow',
        function() {

            $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
            if (relatedImagesAjaxPopup.previousSibling == null) {

                AddClassForFirstPrev();
            }
            else { $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEvent); }
            if(title == "Management")
            {
                if (relatedImagesAjaxPopup.nextSibling.nextSibling == null) {

                    AddClassForNextNav();
                }
                else { $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEvent); }
            }
            else
            {
                if (relatedImagesAjaxPopup.nextSibling == null) {

                    AddClassForNextNav();
                }
                else { $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEvent); }
            }
            
        });
        return false;
    });

    $('.pictureBoxPopup').click(function() {

        $('.relatedImagesPopupBox').show();

        relatedImagesAjaxPopup = $(this)[0];


        ImageTotalCount = $('.pictureBoxPopup').length;

        ImagePresentCount = $(this).attr('id');

        var href = $(this).attr('href');

        $('#relatedImages .pubContent .pubImageShow').load(href + ' #pageContentBlock .container .pubContent .pubImageShow',
        function() {

            $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;


            if (relatedImagesAjaxPopup.parentNode.previousSibling == null) {

                AddClassForFirstPrev();
            }
            else { $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEventForNavImages); }

            if (relatedImagesAjaxPopup.parentNode.nextSibling == null) {

                AddClassForNextNav();
            }
            else { $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEventNavImages); }


        });
        return false;
    });



    var relatedImagesAjaxPopup = null;
    var ImageTotalCount = null;
    var ImagePresentCount = null;
    var title =null;
    function PrevHrefEvent() {
        var PrevHref = null;

        if (relatedImagesAjaxPopup.previousSibling != null) {
            PrevHref = relatedImagesAjaxPopup.previousSibling.href;
            relatedImagesAjaxPopup = relatedImagesAjaxPopup.previousSibling;
        }
        if (PrevHref != null) {
            if (relatedImagesAjaxPopup.previousSibling != null) {
                ImagePresentCount = ImagePresentCount - 1;
                $('#relatedImages .pubContent .pubImageShow').load(PrevHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                    $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEvent); $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEvent);
                    $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                });
            }
            else {
                ImagePresentCount = ImagePresentCount - 1;
                $('#relatedImages .pubContent .pubImageShow').load(PrevHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                    $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEvent); $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEvent); AddClassForFirstPrev();
                    $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                });
            }
        }
        return false;
    }
    function NextHrefEvent() {
        var NextHref = null;
        if (relatedImagesAjaxPopup.nextSibling != null) {
            //NextHref=relatedImagesAjaxPopup.nextSibling.firstChild.href;
            NextHref = relatedImagesAjaxPopup.nextSibling.href;
            relatedImagesAjaxPopup = relatedImagesAjaxPopup.nextSibling;
        }
        if (NextHref != null) {

            ImagePresentCount = parseInt(ImagePresentCount) + 1;
            if(title == "Management")
            {
                if (relatedImagesAjaxPopup.nextSibling.nextSibling != null) {
                    $('#relatedImages .pubContent .pubImageShow').load(NextHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                        $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEvent);
                        $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEvent);

                        $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                    });
                }
                else {
                    $('#relatedImages .pubContent .pubImageShow').load(NextHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                        $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEvent);
                        AddClassForNextNav();
                        $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEvent);
                        $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                    });
                }
            }
            else
            {
                if (relatedImagesAjaxPopup.nextSibling != null) {
                    $('#relatedImages .pubContent .pubImageShow').load(NextHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                        $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEvent);
                        $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEvent);

                        $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                    });
                }
                else {
                    $('#relatedImages .pubContent .pubImageShow').load(NextHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                        $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEvent);
                        AddClassForNextNav();
                        $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEvent);
                        $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                    });
                }
            }
        }
        return false;
    }


    function PrevHrefEventForNavImages() {
        var PrevHref = null;

        if (relatedImagesAjaxPopup.parentNode.previousSibling != null) {
            PrevHref = relatedImagesAjaxPopup.parentNode.previousSibling.childNodes[0].href;
            relatedImagesAjaxPopup = relatedImagesAjaxPopup.parentNode.previousSibling.childNodes[0];
        }
        if (PrevHref != null) {
            if (relatedImagesAjaxPopup.parentNode.previousSibling != null) {
                ImagePresentCount = ImagePresentCount - 1;
                $('#relatedImages .pubContent .pubImageShow').load(PrevHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                    $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEventNavImages); $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEventForNavImages);
                    $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                });
            }
            else {
                ImagePresentCount = ImagePresentCount - 1;
                $('#relatedImages .pubContent .pubImageShow').load(PrevHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                    $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEventNavImages); $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEventForNavImages); AddClassForFirstPrev();
                    $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                });
            }
        }
        return false;
    }
    function NextHrefEventNavImages() {

        var NextHref = null;
        if (relatedImagesAjaxPopup.parentNode.nextSibling != null) {
            //NextHref=relatedImagesAjaxPopup.nextSibling.firstChild.href;
            NextHref = relatedImagesAjaxPopup.parentNode.nextSibling.childNodes[0].href;
            relatedImagesAjaxPopup = relatedImagesAjaxPopup.parentNode.nextSibling.childNodes[0];
        }
        if (NextHref != null) {

            ImagePresentCount = parseInt(ImagePresentCount) + 1;
            if (relatedImagesAjaxPopup.parentNode.nextSibling != null) {
                $('#relatedImages .pubContent .pubImageShow').load(NextHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                    $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEventNavImages);
                    $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEventForNavImages);

                    $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                });
            }
            else {
                $('#relatedImages .pubContent .pubImageShow').load(NextHref + ' #pageContentBlock .container .pubContent .pubImageShow', function() {
                    $('#relatedImages .pubContent .pubImageShow .nextNav a').click(NextHrefEventNavImages);
                    AddClassForNextNav();
                    $('#relatedImages .pubContent .pubImageShow .prevNav a').click(PrevHrefEventForNavImages);
                    $('.number')[0].innerText = ImagePresentCount + " of " + ImageTotalCount;
                });
            }
        }
        return false;
    }

    function AddClassForFirstPrev() {
        $('#relatedImages .pubContent .pubImageShow .prevNav')[0].outerHTML = "<li title='You are already on the first page' class='pubIsFirst prevNav'><span>Previous</span></li>";
    }
    function AddClassForNextNav() {
        $('#relatedImages .pubContent .pubImageShow .nextNav')[0].outerHTML = "<LI class=nextNav title='You are on the last Page'><SPAN>Next</SPAN></LI>";
    }

    function kpiPreviousClickHandler() {
        var currentURL = $(this).attr('href');
        loadKPIContent(currentURL);
        return false;
    }

    function kpiNextClickHandler() {
        var currentURL = $(this).attr('href');
        loadKPIContent(currentURL);
        return false;
    }

    function resetKPIUrls(urlInContext) {
        var currentAnchorInstance = $('.view[href$=' + contextURLKPI + ']');
        var prevHREF = $(currentAnchorInstance.parent().parent().parent().parent().parent().prev().children('.elDetail').children('.detailsList').children('.csvActions').children('span')[2]).children('a').attr('href');
        var nextHREF = $(currentAnchorInstance.parent().parent().parent().parent().parent().next().children('.elDetail').children('.detailsList').children('.csvActions').children('span')[2]).children('a').attr('href');


        if (prevHREF == null) {
            $('.showKPIData .prevNav').html("<span class='navDirectionName'>Previous</span>");
        }
        else {
            $('.showKPIData .prevNav').html("<a href='#' title='Prev card'><span class='navDirectionName'>Previous</span></a>");
            $('.showKPIData .prevNav a').attr("href", prevHREF);
        }

        if (nextHREF == null) {
            $('.showKPIData .nextNav').html("<span class='navDirectionName'>Next</span>");
        }
        else {
            $('.showKPIData .nextNav').html("<a href='#' title='Next card'><span class='navDirectionName'>Next</span></a>");
            $('.showKPIData .nextNav a').attr("href", nextHREF);
        }

        $('.showKPIData .prevNav a').live('click', kpiPreviousClickHandler);
        $('.showKPIData .nextNav a').live('click', kpiNextClickHandler);
    }

    function loadKPIContent(hrefValue) {
        contextURLKPI = hrefValue;

        $('.pubContainerKPI h3 span').load(hrefValue + ' #mainCol .content h1', function() {
            var titleText = $('.pubContainerKPI h3 span').text();
            $('.pubContainerKPI h3 span').html(titleText);
        });
        $('.pubContentKPIPopup').load(hrefValue + ' .pubContentKPI', resetKPIUrls);
    }

    $('.showContactCard').click(function() {
        var href = $(this).attr('href');
        getCurrentContact($(this));
        loadContent(href);
        resetLinks(href);
        return false;
    });


    $('.showContactCard .prevNav a').click(contactsPreviouClickHandler);

    function contactsPreviouClickHandler() {
        var currentURL = $(this).attr('href');
        getCurrentContact($(this));
        resetLinks(currentURL);
        loadContent(currentURL);
        return false;
    }

    $('.showContactCard .nextNav a').click(contactsNextClickHandler);

    function contactsNextClickHandler() {
        var currentURL = $(this).attr('href');
        getCurrentContact($(this));
        resetLinks(currentURL);
        loadContent(currentURL);
        return false;
    }

    function resetLinks(urlInContext) {

        var currentAnchorInstance = $('.showContactCard[href$=' + urlInContext + ']');
        var prevHREF = currentAnchorInstance.parent().prev().children("a").attr("href");
        var nextHREF = currentAnchorInstance.parent().next().children("a").attr("href");

        if (prevHREF == null) {
            $('.prevNav').html("<span class='navDirectionName'></span>");
        }
        else {
            $('.prevNav').html("<a href='#' title='Prev card'><span class='navDirectionName'>Previous</span></a>");
            $('.prevNav a').attr("href", prevHREF);
            $('.prevNav a').bind("click", contactsPreviouClickHandler);
        }

        if (nextHREF == null) {
            $('.nextNav').html("<span class='navDirectionName'></span>");
        }
        else {
            $('.nextNav').html("<a href='#' title='Next card'><span class='navDirectionName'>Next</span></a>");
            $('.nextNav a').attr("href", nextHREF);
            $('.nextNav a').bind("click", contactsNextClickHandler);
        }
    }

    function getCurrentContact(refValue) {
        var ctr = 1;
        var currentContact = 1;
        var totalContacts = 1;
        $('.showContactCard').each(function() {

            if ($(this).attr('href') == refValue.attr('href')) {
                currentContact = ctr;
            }
            totalContacts = ctr;
            ctr++;
        });

        $('.pubContainer h3 span').text("Contact " + currentContact + " of " + totalContacts);
    }

    function loadContent(hrefValue) {
        $('.pubInnerContent').load(hrefValue + ' .pubInnerContent');
    }

    function Cpy2ClB(someText) {
        if (window.clipboardData) {
            window.clipboardData.setData('Text', someText);
        }
        else if (window.netscape) {
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
            var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
            if (!clip) { return false };
            var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
            if (!trans) { return false };
            trans.addDataFlavor('text/unicode');
            var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
            str.data = someText;
            trans.setTransferData('text/unicode', str, someText.length * 2);
            var clipid = Components.interfaces.nsIClipboard;
            if (!clip) { return false };
            clip.setData(trans, null, clipid.kGlobalClipboard);
        }
        alert('Following info was copied to your clipboard:\n\n' + someText);
    }


    /*
    Footer Related functions BEGIN
    */

    $("#footer .container ul:first li:first").addClass("footerFirst");
    $("#footer .container ul:first li:last").addClass("footerLast");

    /*
    Footer Related functions END
    */



    /*
    Initializing the First and Last Menu Items as per the HTML Mockup for Left Hand Navigation BEGIN
    */

    $("#sNavigation ul li:first").addClass("sNavFirst");
    $("#sNavigation ul li:last").addClass("sNavLast");

    /*
    Initializing the First and Last Menu Items as per the HTML Mockup for Left Hand Navigation END
    */

    $(".containerBlock:last").addClass("last");

    /*
    Initializing the First and Last Menu Items as per the HTML Mockup for Brands
    */
    $("#brandsSelector ul li:first").addClass("bsNavFirst");
    $("#brandsSelector ul li:last").addClass("bsNavLast");
    /*
    End
    */

    /*
    Initializing the First and Last Menu Items as per the HTML Mockup for Left Hand Navigation END
    */

    /*
    Global Principals 
    Initializing the last item as per HTML Mock up for the list view control 
    */
    $(".containerBlock:last").addClass("last");

    /*
    Advisory Board
    Initializing the last item as per HTML Mock up for the list view control 
    */

    $("#bodListing ul li:first").addClass("bodListFirst");
    $("#bodListing ul li:last").addClass("bodListLast");


    /*
    Initializing the First and Last Menu Items as per the HTML Mockup BEGIN
    */

    $("#navContainer ul li:first").addClass("pNavFirst");
    $("#navContainer ul li:last").addClass("pNavLast");

    var $nextElement = $("#pnCurrent").next();
    var $prevElement = $("#pnCurrent").prev();

    if ($prevElement != null) {
        $prevElement.addClass("prevToCurrent");
    }

    if ($nextElement != null) {
        $nextElement.addClass("nextToCurrent");
    }

    /*
    chechking Images length in Events and CV management
    */

    if ($('.libraryImages').length > 0) {
        if (jQuery.trim($('.libraryImages')[0].innerHTML) == "") {

            $('.imagestab').hide();
        }
    }

    /*
    Initializing the First and Last Menu Items as per the HTML Mockup END
    */
});

function Cpy2ClB(someText) {
    if (window.clipboardData) {
        window.clipboardData.setData('Text', someText);
    }
    else if (window.netscape) {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) { return false };
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) { return false };
        trans.addDataFlavor('text/unicode');
        var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
        str.data = someText;
        trans.setTransferData('text/unicode', str, someText.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip) { return false };
        clip.setData(trans, null, clipid.kGlobalClipboard);
    }
    alert('Following info was copied to your clipboard:\n\n' + someText);
}

function preparePresentationTypeControl(rbPresentationTopic, rbPresentationType) {
    var selectedTopic = null;
    var selectedType = null;
    var currentURL = window.location.href;
    var Uri = new URI(currentURL);
    function GetSelectedValue() {
        selectedTopic = GetPresentationSelectedValue(rbPresentationTopic);
        selectedType = GetPresentationSelectedValue(rbPresentationType);

        if (selectedTopic != null)
            Uri.variables["Topic"] = selectedTopic;

        if (selectedType != null)
            Uri.variables["Type"] = selectedType;

        window.document.location.href = Uri.toString();
        return false;
    }
    $(rbPresentationTopic).click(GetSelectedValue);

    $(rbPresentationType).click(GetSelectedValue);
}

function GetPresentationSelectedValue(controlReference) {
    var selectedTopic = null;
    $(controlReference).each(function() {
        if ($(this).is(':checked')) {
            selectedTopic = $(this).val();
        }
    });

    return selectedTopic;
}

$(function() {
    $(".SignMeUp").click(function() {

        var $Journdiv = $('div#Journdiv');
        var $signUpUpdates = $('div#signUpUpdates');
        var $signUpUpdatesJourn = $('div#signUpUpdatesJourn');
        var $newsletter = $('div#newsletter');

        if (this.checked) {
            $(".divJournalist").css('display', 'block');
            $(".signmeUpUpdates").css('display', 'none');
            $(".signUpUpdatesJourn").css('display', 'block');
            $(".chknewsletter").css('display', 'none');
        }
        else {
            $(".divJournalist").css('display', 'none');
            $(".signmeUpUpdates").css('display', 'block');
            $(".signUpUpdatesJourn").css('display', 'none');
            $(".chknewsletter").css('display', 'block');
        }
    });



    $(".btnSignMeUp").click(function() {
        var status = true;


        if ($(".SignMeUp").is(':checked')) {

            if ($("#signUpPR :input:checked").length > 0 || $("#signUpUpdatesJourn :input:checked").length > 0) {

                $(".errsignup").css('display', 'none');
                status = true;
            }
            else {

                $(".errsignup").css('display', 'block');
                status = false;
            }

            if ($(".fCountry").val() == "") {
                //alert('error');
                $(".errCountry").css('visibility', 'visible');
                status = false;
            }

            if ($(".fPublication").val() == "") {
                //alert('error');
                $(".errPublication").css('visibility', 'visible');
                status = false;
            }


        }
        else {
            if ($("#signUpPR :input:checked").length > 0 || $(".signmeUpUpdates :input:checked").length > 0 || $(".signupnewsletter").is(':checked')) {

                $(".errsignup").css('display', 'none');
                status = true;
            }
            else {

                $(".errsignup").css('display', 'block');
                status = false;
            }
        }
        if (status == false) {
            return false;
        }

    });


});

var fcountryFilled = false;
var fPublicationFilled = false;

    $(".fCountry").live('focusout',function() { 
    
    if ($(".fCountry").val() == "" && fcountryFilled) {
      $(".errCountry").css('visibility', 'visible');
      }else
      {
       $(".errCountry").css('visibility', 'hidden');
       if($(".fCountry").val() != "")
       {
            fcountryFilled = true;
       }
      }
});

 $(".fPublication").live('focusout',function() { 
    
    if ($(".fPublication").val() == "" && fPublicationFilled) {
      $(".errPublication").css('visibility', 'visible');
      }else
      {
       $(".errPublication").css('visibility', 'hidden');
       if ($(".fPublication").val() != "")
       {
       fPublicationFilled = true;
       }
      }
});


function prepareMediaDocumentControl(rbTopic, rbLanguage) {
    var selectedTopic = null;
    var selectedLanguage = null;
    var currentURL = window.location.href;
    var Uri = new URI(currentURL);
    function GetSelectedValue() {

        selectedTopic = GetMediaDocumentSelectedValue(rbTopic);
        selectedLanguage = GetMediaDocumentSelectedValue(rbLanguage);

        if (selectedTopic != null)
            Uri.variables["Topic"] = selectedTopic;

        if (selectedLanguage != null)
            Uri.variables["Language"] = selectedLanguage;

        window.document.location.href = Uri.toString();
        return false;
    }
    $(rbTopic).click(GetSelectedValue);
    $(rbLanguage).click(GetSelectedValue);
}

function GetMediaDocumentSelectedValue(controlReference) {
    var selectedTopic = null;

    $(controlReference).each(function() {
        if ($(this).is(':checked')) {
            selectedTopic = $(this).val();
        }
    });

    return selectedTopic;
}

//function to export data from journalist admin page
function MenuExportForJournUser(exportobj) {

    if (confirm('Export cannot be canceled once it has been started. Proceed ?')) {
        exportobj.location = "SignmeupAdmin.axd";
    }
}

function PerformCheckInAndRefresh()
{
    if (confirm('Do you want to continue ?'))
    {
        var getURL = '/CheckInHandler.ashx?' + arguments[0] + '&' + arguments[1] + '&' + arguments[2] ;
        $.ajax({ 
                url : getURL , 
                cache:false, 
                async:false,
                
                success:function(msg) { 
                    window.location.href = window.location.href ;
                } 
                });
   }   
   return true;
}

function PerformPendingAndRefresh()
{
    if (confirm('Do you want to continue ?'))
    {
        var getURL = '/PendingHandler.ashx?' + arguments[0] + '&' + arguments[1] + '&' + arguments[2] ;
        $.ajax({ 
                url : getURL , 
                cache:false, 
                async:false,
                
                success:function(msg) { 
                    window.location.href = window.location.href ;
                } 
                });
   }   
   return true;
}

function PerformApproveAndRefresh()
{
    if (confirm('Do you want to continue ?'))
    {
        var getURL = '/ApproveHandler.ashx?' + arguments[0] + '&' + arguments[1] + '&' + arguments[2] ;
        $.ajax({ 
                url : getURL , 
                cache:false, 
                async:false,
                
                success:function(msg) { 
                    window.location.href = window.location.href ;
                } 
                });
   }   
   return true;

}

// This function is used on the press release control of the Nestle home page
// Here we change the tooltip of the selected press release
function SetTooltip(toolTip, link) {
    for (i = 0; i < document.getElementById('paginatorOne').getElementsByTagName('li').length; i++) {
        if (document.getElementById('paginatorOne').getElementsByTagName('li')[i].getElementsByTagName('a')[0].className == 'num') {
            if (document.getElementById('paginatorOne').getElementsByTagName('li')[i].getElementsByTagName('a')[0].title.indexOf('to') < 0) {
                document.getElementById('paginatorOne').getElementsByTagName('li')[i].getElementsByTagName('a')[0].title = 'go to ' + document.getElementById('paginatorOne').getElementsByTagName('li')[i].getElementsByTagName('a')[0].title;
            }
        }
    }
    link.title = toolTip;
    return false;
}

// This function is used to close the video streaming on the click on close link
$(function() {
    $('#cboxClose').click(function() {
        $('#flashControlContainer').replaceWith('');
    });
});
