//load external scripts

/* //fancy box
$.getScript("/Script/jquery.fancybox-1.2.6.js");
$.getScript("/Script/jquery.fancybox-1.2.6.pack.js");

//please wait
$.getScript("/Script/jquery.blockUI.js");

//tooltip
$.getScript("/Script/jquery.cluetip.js");
$.getScript("/Script/jquery.TooltipSettings.js");

$.getScript("/Script/wz_tooltip.min.js");
*/

//on start
$(document).ready(function() {
    $('head').append('<!--[if IE 6]><link href="/Communities/Common/Styles/DefaultIE.css" type="text/css" rel="stylesheet" media="screen"><![endif]-->');
    $('.ToggleDiv').click(function() {
        //$('.contractingDiv').slideToggle("slow");
        $(this).next("div").slideToggle("slow");
    });

    $(".formSectionHeader").next("div").addClass("PreviewTable");

    $(".formSectionHeader").click(function() {
        $(this).next("div").slideToggle("slow");
        return false;
    });
    $("div.formSectionHeader").toggle(function() {
        $(this).addClass("contracted");
    }, function() {
        $(this).removeClass("contracted");
    });

    $(".formSectionHeaderCollapsed").next("div").addClass("PreviewTable").hide();

    $(".formSectionHeaderCollapsed").click(function() {
        $(this).next("div").slideToggle("slow");
        return false;
    });
    $("div.formSectionHeaderCollapsed").toggle(function() {
        $(this).addClass("contractedCollapsed");
    }, function() {
        $(this).removeClass("contractedCollapsed");
    });

    var factor = .9;

    var w = $(window).width() == 0 ? 700 : $(window).width() * factor;
    var h = $(window).height() == 0 ? 500 : $(window).height() * factor;

    //alert(h);
    if ($(".fancyBox").length)
        $(".fancyBox").fancybox({ 'hideOnContentClick': false, 'frameWidth': w, 'frameHeight': h }); //, 'frameWidth': 750, 'frameHeight': 550 

    $(window).resize(function() {
        SizeBox();
    });
    function SizeBox() {
        var w = $(window).width() * factor;
        var h = $(window).height() * factor;
        $("#fancy_outer").css({ 'width': w + 'px', 'height': h + 'px' });
    }

    $("#updateparent").click(function() {
        // window.opener.$("#accept-terms").attr("checked","checked"); //updates parent checkbox
        parent.location.href = parent.location;
        return false;
    });
    $("#returnparent").click(function() {
        parent.$.fn.fancybox.close();
        return false;
    });

    if ($(".editHTMLlink").length)
        $(".editHTMLlink").hide();

    $(".editHTMLPanel").mouseover(function() {
        $(".editHTMLlink", this).show(); //
    }).mouseout(function() {
        $(".editHTMLlink", this).hide();
    });

    if ($(".editHTMLPanel>span").length) {
        if ($(".editHTMLPanel>span").html().length <= 1) {
            $(".editHTMLPanel>span").append("add your text here").addClass("emptyHtml");
        }
    }
});

function toggleBlockUI(chk, pnl) {
        if ($(chk).is(":not(':checked')")) {
            $(pnl).block({ message: null });
        }
        else {
            $(pnl).unblock();
        }
    }
jQuery.fn.fadeToggle = function(speed, easing, callback) {
    return this.animate({ opacity: 'toggle' }, speed, easing, callback);

};

function htmlEncode(value) {
    return $('<div/>').text(value).html();
}

function htmlDecode(value) {
    return $('<div/>').html(value).text();
}

function MM_openBrWindow(_1, w, h, r) {
    //hideSpinner();
    var _5, scrWidth, winHeight, winWidth, resize;
    winWidth = window.screen.width;
    winHeight = window.screen.height;
    resize = "yes";
    if (r != null) {
        resize = r;
    }
    if (w != null) {
        winWidth = w;
    }
    if (h != null) {
        winHeight = h;
    }
    scrWidth = ((window.screen.width - winWidth) / 2);
    _5 = ((window.screen.height - winHeight) / 2);
    popup = window.open(_1, "newwindow", "scrollbars=yes,resizable=" + resize + ",width=" + winWidth + ",height=" + winHeight + ",left=" + scrWidth + ",top=" + _5 + "");
    //popup.focus();
}

function MM_swapImage() {
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3) {
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) {
                x.oSrc = x.src;
            }
            x.src = a[i + 2];
        }
    }
}
function MM_swapImgRestore() {
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) {
        x.src = x.oSrc;
    }
}
function MM_preloadImages() {
    var d = document;
    if (d.images) {
        if (!d.MM_p) {
            d.MM_p = new Array();
        }
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++) {
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
        }
    }
}

function MM_findObj(n, d) {
    var p, i, x;
    if (!d) {
        d = document;
    }
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) {
        x = d.all[n];
    }
    for (i = 0; !x && i < d.forms.length; i++) {
        x = d.forms[i][n];
    }
    for (i = 0; !x && d.layers && i < d.layers.length; i++) {
        x = MM_findObj(n, d.layers[i].document);
    }
    if (!x && document.getElementById) {
        x = document.getElementById(n);
    }
    return x;
}
function printFriendly(_d) {
    var _e = _d;
    if (document.getElementById != null) {
        var _f = "<HTML>\n<HEAD>\n";
        _f += "<style type=\"text/css\">";
        _f += "<!--";
        _f += "html,body,td,p {";
        _f += "font-family: Arial, Helvetica, sans-serif;";
        _f += "font-size: x-small;";
        _f += "}";
        _f += "html,body{";
        _f += "background-color: #FFFFFF;margin:0px;";
        _f += "}";
        _f += "-->";
        _f += "</style>";
        _f += "\n</HEAD>\n<BODY>\n";
        var _10 = document.getElementById("printFriendly");
        if (_10 != null) {
            _f += _10.innerHTML;
        } else {
            alert("Could not find the printFriendly section in the HTML");
            return;
        }
        _f += "\n</BODY>\n</HTML>";
        var _11 = window.open("", "printFriendly", "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,height=500,width=700");
        _11.document.open();
        _11.document.write(_f);
        _11.document.close();
        if (_e) {
            _11.print();
        }
    } else {
        alert("Sorry, the printer friendly feature works\nonly in javascript enabled browsers.");
    }
}
function Email() {
    var _12 = GetContentWnd();
    var _13 = _12.document;
    _12.location.href = "mailto:?subject=" + escape(_13.title) + "&body=" + BuildEmailDescription(_12.location.href);
}
function GetContentWnd() {
    return parent;
}
function BuildEmailDescription(_14) {
    return escape("Here's a great website you might be interested in:" + String.fromCharCode(13) + String.fromCharCode(13) + "URL: " + _14);
}
function OnSave() {
    var _15 = GetContentWnd();
    if (window.sidebar) {
        window.sidebar.addPanel(_15.document.title, _15.location.href, "");
        return true;
    }
    else {
        if (document.all) {
            window.external.addFavorite(_15.location.href, _15.document.title);
            return true;
        }
        else {
            if (window.opera && window.print) {
                return true;
            }
            else { return false; }
        }
    }
}
function breakout_of_frame() {
    //if (top.location != location) {
      //  top.location.href = document.location.href;
    //}
}

function writetimer(swf, w, h, _1d, clr) {
    document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + w + "\" height=\"" + h + "\" id=\"myFlv\" align=\"middle\">");
    document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
    document.write("<param name=\"movie\" value=\"" + swf + "\" />");
    document.write("<param name=\"quality\" value=\"high\" />");
    document.write("<param name=\"bgcolor\" value=\"#" + clr + "\" />");
    document.write("<param name=\"FlashVars\" value=\"" + _1d + "\">");
    document.write("<embed src=\"" + swf + "\" quality=\"high\" bgcolor=\"#" + clr + "\" width=\"" + w + "\" height=\"" + h + "\" flashvars=\"" + _1d + "\" name=\"myFlv\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />");
    document.write("</object>");
}
function TJK_doToggleDL(x) {
    var zDD = document.getElementById("TJK_DL").getElementsByTagName("dd");
    var zDT = document.getElementById("TJK_DL").getElementsByTagName("dt");
    zDD[x].className = (zDD[x].className == "hideDD") ? "showDD" : "hideDD";
    zDT[x].className = (zDT[x].className == "DTplus") ? "DTminus" : "DTplus";
}
function TJK_ToggleDLopen() {
    var zDD = document.getElementById("TJK_DL").getElementsByTagName("dd");
    var zDT = document.getElementById("TJK_DL").getElementsByTagName("dt");
    for (var i = 0; i < zDT.length; i++) {
        zDD[i].className = "showDD";
        zDT[i].className = "DTminus";
    }
    return false;
}
function TJK_ToggleDLclose() {
    var zDD = document.getElementById("TJK_DL").getElementsByTagName("dd");
    var zDT = document.getElementById("TJK_DL").getElementsByTagName("dt");
    for (var i = 0; i < zDT.length; i++) {
        zDD[i].className = "hideDD";
        zDT[i].className = "DTplus";
    }
    return false;
}

function TJK_ToggleDL() {
    if (document.getElementById && document.getElementsByTagName && document.getElementById("TJK_DL") != null) {
        var zDT = document.getElementById("TJK_DL").getElementsByTagName("dt");
        var zDD = document.getElementById("TJK_DL").getElementsByTagName("dd");
        var _2e = document.getElementById("TJK_ToggleON");
        var _2f = document.getElementById("TJK_ToggleOFF");
        if (_2e && _2f) {
            _2e.onclick = TJK_ToggleDLopen;
            _2e.title = "Show all answers";
            _2e.href = "#";
            _2f.onclick = TJK_ToggleDLclose;
            _2f.title = "Hide all answers";
            _2f.href = "#";
        }
        for (var i = 0; i < zDT.length; i++) {
            var _31 = zDT[i].innerHTML;
            var _32 = "<a href='javascript:void(0)' onclick=\"TJK_doToggleDL(" + i + ");return false\" title='Show/hide the answer'>";
            zDT[i].innerHTML = _32 + _31 + "</a>";
            zDD[i].className = "hideDD";
            zDT[i].className = "DTplus";
        }
    }
}
function disableSelection(target) {
    if (typeof target.onselectstart != "undefined") //IE route
        target.onselectstart = function() { return false }
    else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
        target.style.MozUserSelect = "none"
    else //All other route (ie: Opera)
        target.onmousedown = function() { return false }
    target.style.cursor = "default"
}
var strGif;
var strFilter;
function findImgInputs(_d) {
    var _e = _d.children;
    if (_e) {
        for (var i = 0; i < _e.length; i++) {
            var _10 = _e(i);
            if ((_10.type == "image") && (_10.src)) {
                var _11 = _10.src;
                _10.src = strGif;
                _10.style.filter = strFilter + "(src='" + _11 + "' sizingMethod='image')";
            }
            findImgInputs(_10);
        }
    }
}

function hideAnimation(element) {
    document.getElementById(element).style.display = "none";
};

function SelectAll(CheckBoxControl, List) {
    var i;
    if (CheckBoxControl.checked == true) {
        for (i = 0; i < document.forms[0].elements.length; i++) {
            if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf(List) > -1)) {
                document.forms[0].elements[i].checked = true;
            }
        }
    }
    else {
        for (i = 0; i < document.forms[0].elements.length; i++) {
            if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf(List) > -1)) {
                document.forms[0].elements[i].checked = false;
            }
        }
    }
}
String.prototype.startsWith = function(str) {
    return (this.indexOf(str) === 0);
}
relativeToAbsoluteContent = function(id, link) {
    var elemId = '#' + id + ' img'

    $(elemId).each(function() {
        var src = $(this).attr('src');
        if (!src.startsWith("http")) {
            $(this).attr('src', link + $(this).attr('src'));
        }
    });

    elemId = '#' + id + ' a'
    $(elemId).each(function() {
        src = $(this).attr('href');
        if (!src.startsWith("http")) {
            $(this).attr('href', link + $(this).attr('href')).attr('target', '_blank');
        }
    });
}
function expandContractDiv(Img, Tbl) {
    //hideSpinner();
    var _tbl = document.getElementById(Tbl);
    var _img = null;
    if (Img != null)
        _img = document.getElementById(Img);

    if (_tbl.className == "hidden") {
        _tbl.className = "visible";
        if (_img != null) { _img.src = "/Communities/Common/Images/minus.gif"; }
    } else {
        _tbl.className = "hidden";
        if (_img != null) { _img.src = "/Communities/Common/Images/plus.gif"; }
    }
}

function communityLoadOnEnd() {
    disableSelection(document.body);
}
function communityLoadOnstart() {
    TJK_ToggleDL(); //This is about using a Definition List and the DOM to create a nice FAQ page
    breakout_of_frame();
}
/*
function cskInsertHtml(id, content) {
    var myId = "'" + id + "'";
    alert(myId); alert(content);
    FTB_API[myId].InsertHtml(content);
}*/
