﻿function SetTopNav(pid)
{
    $(function()
    {
        //$('#'+pid).attr('class','on');
        $('#'+pid).addClass('selected');
    });
}

function SetMailingList()
{
    $(function()
    {
        $('#searchForm #btnSubmit').colorbox
        ({
            height:'670',
            iframe:'true',
            opacity:'0.50',
            width:'580',
            onOpen:function()
            {
                $(this).attr('href','mailing-list.aspx?email='+$('#searchForm #txtEmail').val());
            }
        });
    });

    return false;
}

function SetTopSocial(pelement)
{
    var id=$(pelement).attr('id');
    
    if (id=='facebook')
    {
        $.colorbox
        ({
            height:'650',
            href:'http://www.facebook.com/plugins/likebox.php?id=281803931473&width=292&connections=10&stream=true&header=true&height=587',
            iframe:'true',
            opacity:'0.50',
            width:'320'
        });
    } else if (id=='twitter') {
        $.colorbox
        ({
            height:'480',
            href:'twitter.html',
            iframe:'true',
            opacity:'0.50',
            width:'300'
        });
    }
}

function SetFAQ()
{
    $(function()
    {
        $('span.answer').css('display','none');

        $('a.question').click(function()
        {
            if ($(this).next().next().css('display')=='block')
                $(this).next().next().css('display','none');
            else
                $(this).next().next().css('display','block');

            return false;
        });
    });
}

function GetQuerystringParam(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 decodeURIComponent(results[1].replace(/\+/g, " "));
}

function getLink(name,id) {

    $(function () {
        var url = window.location.href;
        var host = window.location.hostname;
        var title = $('#title').text();
        title = escape(title); //clean up unusual characters
        if (id=="facebook") 
            $('#' + name).attr('href', 'http://www.facebook.com/sharer.php?u=' + url);
        else 
            $('#' + name).attr('href', 'http://twitter.com/home?status=' + title + '%20' + url);               
        
    });
}

function ToggleArchive(e) {
    e = $('#' + e);

    if (!e) return false;

    /* Hides all month lists */
    $('.archive_month').addClass('hide');
    $('.archive_month').removeClass('show');

    /* Shows the selected month list */
    e.parent().next().addClass('show');
    e.parent().next().removeClass('hide');

    /* Removes the style of all years */
    $('.archive_month').prev().children().removeClass('selected');

    /* Adds style for the selected year */
    $(e).addClass('selected');

    /* Removes all br tags */
    $('.archive_month').each(function () {
        if ($(this).next().is('br'))
            $(this).next().remove();
    });

    /* Adds br tag for the selected year */
    $(e).parent().next().next().before('<br />');

    return false;
}

function SetSiteSearch(pblnOnEnter)
{
    var strKeyword=escape($('#txtSiteSearch').val());

    if (jQuery.trim(strKeyword).length==0) strKeyword='Century Square';

    var strParams='?zoom_sort=0&zoom_xml=0&zoom_query='+strKeyword+'&zoom_per_page=10&zoom_and=0&zoom_cat%5B%5D=1';

    if (pblnOnEnter)
        window.location=$('#topSearchSumbit a').attr('href')+strParams;
    else
        $('#topSearchSumbit a').attr('href','search.aspx?'+strParams);
}

