(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));


!function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (!d.getElementById(id)) {
        js = d.createElement(s);
        js.id = id;
        js.src = "//platform.twitter.com/widgets.js"; 
        fjs.parentNode.insertBefore(js, fjs);
    }
} (document, "script", "twitter-wjs");

var g_sPopupElementID = null;
var g_bModal = null;
var g_bDropShadow = null;
var g_arrSavedTabIndices = null;
var g_arrDisabledSelects = null;
var g_arrTagsWithTabIndex = new Array('A','AREA','BUTTON','INPUT','OBJECT','SELECT','TEXTAREA','IFRAME');
function PopupShow(sPopupElementID, bModal, bDropShadow, sFocusID)
{
    g_sPopupElementID = sPopupElementID;
    g_bModal = bModal;
    g_bDropShadow = bDropShadow;
    document.getElementById(g_sPopupElementID).style.zIndex = 10002;
    document.getElementById(g_sPopupElementID).style.position='absolute';
    document.getElementById(g_sPopupElementID).style.display='block';
    if (g_bModal)
    {
        if (document.getElementById(g_sPopupElementID + '_backgroundElement') == null)
        {
            var _backgroundElement = document.createElement('div');
            _backgroundElement.id = g_sPopupElementID + '_backgroundElement';
            _backgroundElement.style.position = 'absolute';
            _backgroundElement.style.left = '0px';
            _backgroundElement.style.top = '0px';
            _backgroundElement.className = 'modalBackground';
            document.body.appendChild(_backgroundElement)
        }
        document.getElementById(g_sPopupElementID + '_backgroundElement').style.zIndex = 10000;
        document.getElementById(g_sPopupElementID + '_backgroundElement').style.display = 'block';
    }
    if (g_bDropShadow)
    {
        if (document.getElementById(g_sPopupElementID + '_shadowElement') == null)
        {
            var _shadowElement = document.createElement('div');
            _shadowElement.id = g_sPopupElementID + '_shadowElement';
            _shadowElement.style.position = 'absolute';
            _shadowElement.style.left = '0px';
            _shadowElement.style.top = '0px';
            _shadowElement.style.width = document.getElementById(g_sPopupElementID).clientWidth;
            _shadowElement.style.height = document.getElementById(g_sPopupElementID).clientHeight;
            _shadowElement.style.backgroundColor = '#222222';
            document.body.appendChild(_shadowElement)
        }
        document.getElementById(g_sPopupElementID + '_shadowElement').style.zIndex = 10001;
        document.getElementById(g_sPopupElementID + '_shadowElement').style.display = 'block';
    }
    if (typeof(sFocusID) != 'undefined')
    {
        document.getElementById(sFocusID).focus();
    }
    if (g_bModal)
    {
        PopupDisableTabs();
    }
    PopupResize();
    window.onresize=PopupResize;
    window.onscroll=PopupResize;
}
function PopupHide()
{
    document.getElementById(g_sPopupElementID).style.display = 'none';
    window.onresize=null;
    window.onscroll=null;
    if (g_bModal)
    {
        if (document.getElementById(g_sPopupElementID + '_backgroundElement') != null)
        {
            document.getElementById(g_sPopupElementID + '_backgroundElement').style.display = 'none';
            PopupRestoreTabs();
        }
    }
    if (g_bDropShadow)
    {
        if (document.getElementById(g_sPopupElementID + '_shadowElement') != null)
        {
            document.getElementById(g_sPopupElementID + '_shadowElement').style.display = 'none';
        }
    }
}
function PopupResize()
{
    if (g_sPopupElementID != null)
    {
        var h = document.documentElement.clientHeight;
        var w = document.documentElement.clientWidth;
        if (h == 0)
        {
            h = document.documentElement.offsetHeight;
            w = document.documentElement.offsetWidth;
        }
        if (g_bModal)
        {
            document.getElementById(g_sPopupElementID + '_backgroundElement').style.top = document.body.scrollTop;
            document.getElementById(g_sPopupElementID + '_backgroundElement').style.left = document.body.scrollLeft;
            document.getElementById(g_sPopupElementID + '_backgroundElement').style.height = h - 1;
            document.getElementById(g_sPopupElementID + '_backgroundElement').style.width = w - 1;
        }
        document.getElementById(g_sPopupElementID).style.top = (h - document.getElementById(g_sPopupElementID).clientHeight) / 2 + document.body.scrollTop;;
        document.getElementById(g_sPopupElementID).style.left = (w - document.getElementById(g_sPopupElementID).clientWidth) / 2 + document.body.scrollLeft;;
        if (g_bDropShadow)
        {
            document.getElementById(g_sPopupElementID + '_shadowElement').style.top = document.getElementById(g_sPopupElementID).style.pixelTop + 5 + "px";
            document.getElementById(g_sPopupElementID + '_shadowElement').style.left = document.getElementById(g_sPopupElementID).style.pixelLeft + 5 + "px";
            document.getElementById(g_sPopupElementID + '_shadowElement').style.width = document.getElementById(g_sPopupElementID).clientWidth;
            document.getElementById(g_sPopupElementID + '_shadowElement').style.height = document.getElementById(g_sPopupElementID).clientHeight;
        }
    }
}
function PopupDisableTabs()
{
    var i = 0;
    var tagElements;
    var tagElementsInPopUp = new Array();
    var popup = document.getElementById(g_sPopupElementID);
    g_arrSavedTabIndices = new Array();
    for (var j = 0; j < g_arrTagsWithTabIndex.length; j++) 
    {
        tagElements = popup.getElementsByTagName(g_arrTagsWithTabIndex[j]);
        for (var k = 0 ; k < tagElements.length; k++) 
        {
            tagElementsInPopUp[i] = tagElements[k];
            i++;
        }
    }
    i = 0;
    for (var j = 0; j < g_arrTagsWithTabIndex.length; j++) 
    {
        tagElements = document.getElementsByTagName(g_arrTagsWithTabIndex[j]);
        for (var k = 0 ; k < tagElements.length; k++) 
        {
            if (tagElementsInPopUp.indexOf(tagElements[k]) == -1)  
            {
                g_arrSavedTabIndices[i] = {tag: tagElements[k], index: tagElements[k].tabIndex};
                tagElements[k].tabIndex="-1";
                i++;
            }
        }
    }
    i = 0;
    if (navigator.userAgent.indexOf('MSIE 6') != -1) 
    {
        var tagSelectInPopUp = new Array();
        for (var j = 0; j < g_arrTagsWithTabIndex.length; j++) 
        {
            tagElements = document.getElementById(g_sPopupElementID).getElementsByTagName('SELECT');
            for (var k = 0 ; k < tagElements.length; k++) 
            {
                tagSelectInPopUp[i] = tagElements[k];
                i++;
            }
        }
        i = 0;
        g_arrDisabledSelects = new Array();
        tagElements = document.getElementsByTagName('SELECT');
        for (var k = 0 ; k < tagElements.length; k++) 
        {
            if (Array.indexOf(tagSelectInPopUp, tagElements[k]) == -1)  
            {
                g_arrDisabledSelects[i] = {tag: tagElements[k], visib: tagElements[k].style.visibility } ;
                tagElements[k].style.visibility = 'hidden';
                i++;
            }
        }
    }
}
function PopupRestoreTabs() 
{
    for (var i = 0; i < g_arrSavedTabIndices.length; i++) 
    {
        g_arrSavedTabIndices[i].tag.tabIndex = g_arrSavedTabIndices[i].index;
    }
    g_arrSavedTabIndices = new Array();
    if (navigator.userAgent.indexOf('MSIE 6') != -1) 
    {
        for (var k = 0 ; k < g_arrDisabledSelects.length; k++) 
        {
            g_arrDisabledSelects[k].tag.style.visibility = g_arrDisabledSelects[k].visib;
        }
        g_arrDisabledSelects = null;
    }
}
if(!Array.indexOf)
{
    Array.prototype.indexOf = function(obj)
    {
        for(var i = 0; i < this.length; i++)
        {
            if(this[i] == obj)
            {
                 return i;
            }
        }
        return -1;
    }
}

