﻿$(function() {

    /*
    1.) Form Field Value Swap
    */

    swapValues = [];
    $(".searchtextbox").each(function(i) {
        swapValues[i] = $(this).val();
        $(this).focus(function() {
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function() {
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });

    /*
    2.) Characters Remaining Countdown
    */

    var countdown = {
        init: function() {
            countdown.remaining = countdown.max - $(countdown.obj).val().length;
            if (countdown.remaining > countdown.max) {
                $(countdown.obj).val($(countdown.obj).val().substring(0, countdown.max));
            }
            $(countdown.obj).siblings(".remaining").html(countdown.remaining + " characters remaining.");
        },
        max: null,
        remaining: null,
        obj: null
    };
    $(".countdown").each(function() {
        $(this).focus(function() {
            var c = $(this).attr("class");
            countdown.max = parseInt(c.match(/limit_[0-9]{1,}_/)[0].match(/[0-9]{1,}/)[0]);
            countdown.obj = this;
            iCount = setInterval(countdown.init, 1000);
        }).blur(function() {
            countdown.init();
            clearInterval(iCount);
        });
    });

    /*
    3.) Simply Centered Informational DIV Popup
    */

    /*
    The viewport object is mainly for the cross-browser mess
    that is unfortunately necessary to get a DIV to center.

        There is also an officially supported plugin called "Dimensions"
    that can manage some of this on your own projects. Check it out at:

        http://jquery.com/plugins/project/dimensions
    */

    var viewport = {
        o: function() {
            if (self.innerHeight) {
                this.pageYOffset = self.pageYOffset;
                this.pageXOffset = self.pageXOffset;
                this.innerHeight = self.innerHeight;
                this.innerWidth = self.innerWidth;
            } else if (document.documentElement && document.documentElement.clientHeight) {
                this.pageYOffset = document.documentElement.scrollTop;
                this.pageXOffset = document.documentElement.scrollLeft;
                this.innerHeight = document.documentElement.clientHeight;
                this.innerWidth = document.documentElement.clientWidth;
            } else if (document.body) {
                this.pageYOffset = document.body.scrollTop;
                this.pageXOffset = document.body.scrollLeft;
                this.innerHeight = document.body.clientHeight;
                this.innerWidth = document.body.clientWidth;
            }
            return this;
        },
        init: function(el) {
            $(el).css("left", Math.round(viewport.o().innerWidth / 2) + viewport.o().pageXOffset - Math.round($(el).width() / 2));
            $(el).css("top", Math.round(viewport.o().innerHeight / 2) + viewport.o().pageYOffset - Math.round($(el).height() / 2));
        }
    };
    $(".simple_popup_info").each(function() {
        $(this).css("display", "none").siblings(".simple_popup").click(function() {
            $(".simple_popup_div").remove();
            var strSimple = "<div class='simple_popup_div'><div class='simple_popup_inner'>";
            strSimple += "<p class='simple_close'>[ x ] <a href='#'>Close</a></p>";
            strSimple += $(this).siblings(".simple_popup_info").html();
            strSimple += "</div></div>";
            $("body").append(strSimple);
            viewport.init(".simple_popup_div");
            $(".simple_close").click(function() {
                $(".simple_popup_div").remove();
                return false;
            });
            return false;
        });
    });

    /*
    4.) Collapsing Table Columns
    */

    $(".collapse").click(function() {
        var o = this;
        var p = $(this);
        while (!$(p).is("table")) {
            p = $(p).parent();
        }
        $(".collapse", p).each(function(i) {
            if (this == o) {
                $("tr", p).find("td:eq(" + i + ")").css("display", "none");
            }
        });
        $(this).parent().css("display", "none");
        $(p).siblings(".reset_collapse").html("<p><a href='#' class='show_all_collapsed'>Show All</a></p>").find(".show_all_collapsed").click(function() {
            $("th,td", p).css("display", "");
            $(this).parent().remove();
            return false;
        });
        return false;
    });

    /*
    5.) The RSS Feed Reader
    */

    $.ajax({
        type: "GET",
        url: "feed.xml",
        dataType: "xml",
        success: function(rss) {
            strRSS = "<h4>" + $("/rss/channel/title", rss).text() + "</h4>";
            $("/rss/channel/item/title:lt(5)", rss).each(function(i) {
                strRSS += "<p><strong><a href='";
                strRSS += $("/rss/channel/item/link:eq(" + i + ")", rss).text();
                strRSS += "'>";
                strRSS += $(this).text();
                strRSS += "</a></strong><br />";
                strRSS += ($("/rss/channel/item/description:eq(" + i + ")", rss).text()).substring(0, 200) + "...</p>";
            });
            $("#feed_me").html(strRSS);
        }
    });

});












function toggleLayer(whichLayer, whichLayer1) {
    var elem, vis;
    if (document.getElementById) // this is the way the standards work
    {
        elem = document.getElementById(whichLayer);
    }
    else if (document.all) // this is the way old msie versions work
        elem = document.all[whichLayer];
    else if (document.layers) // this is the way nn4 works
        elem = document.layers[whichLayer];
    vis = elem.style;
    // if the style.display value is blank we try to figure it out here
    if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
        vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
    vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';


    var elem1, vis1;
    if (document.getElementById) // this is the way the standards work
    {
        elem1 = document.getElementById(whichLayer1);
    }
    else if (document.all) // this is the way old msie versions work
        elem1 = document.all[whichLayer1];
    else if (document.layers) // this is the way nn4 works
        elem1 = document.layers[whichLayer1];
    vis1 = elem1.style;
    // if the style.display value is blank we try to figure it out here
    if (vis1.display == '' && elem1.offsetWidth != undefined && elem1.offsetHeight != undefined)
        vis1.display = (elem1.offsetWidth != 0 && elem1.offsetHeight != 0) ? 'block' : 'none';
    vis1.display = (vis1.display == '' || vis1.display == 'block') ? 'none' : 'block';

}


function toggleLayerWhois(whichLayer, whichLayer1, domName) {
    var elem, vis;
    if (document.getElementById) // this is the way the standards work
    {
        elem = document.getElementById(whichLayer);
    }
    else if (document.all) // this is the way old msie versions work
        elem = document.all[whichLayer];
    else if (document.layers) // this is the way nn4 works
        elem = document.layers[whichLayer];
    vis = elem.style;
    // if the style.display value is blank we try to figure it out here
    if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
        vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
    vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';


    var elem1, vis1;
    if (document.getElementById) // this is the way the standards work
    {
        elem1 = document.getElementById(whichLayer1);
    }
    else if (document.all) // this is the way old msie versions work
        elem1 = document.all[whichLayer1];
    else if (document.layers) // this is the way nn4 works
        elem1 = document.layers[whichLayer1];
    vis1 = elem1.style;
    // if the style.display value is blank we try to figure it out here
    if (vis1.display == '' && elem1.offsetWidth != undefined && elem1.offsetHeight != undefined)
        vis1.display = (elem1.offsetWidth != 0 && elem1.offsetHeight != 0) ? 'block' : 'none';
    vis1.display = (vis1.display == '' || vis1.display == 'block') ? 'none' : 'block';
    if (vis1.display == '' || vis1.display == 'block') {
        BeginWhoisProcessWithDom(domName);
    }
}


function toggleLayer1(whichLayer) {
    var elem, vis;
    if (document.getElementById) // this is the way the standards work
    {
        elem = document.getElementById(whichLayer);
    }
    else if (document.all) // this is the way old msie versions work
        elem = document.all[whichLayer];
    else if (document.layers) // this is the way nn4 works
        elem = document.layers[whichLayer];
    vis = elem.style;
    // if the style.display value is blank we try to figure it out here
    if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
        vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
    vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
}





ddaccordion.init({
    headerclass: "headerbar", //Shared CSS class name of headers group
    contentclass: "submenu", //Shared CSS class name of contents group
    revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
    mouseoverdelay: 0, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
    collapseprev: false, //Collapse previous content (so only one open at any time)? true/false
    defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
    animatedefault: false, //Should contents open by default be animated into view?
    persiststate: true, //persist state of opened contents within browser session?
    toggleclass: ["", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
    animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
    oninit: function(headers, expandedindices) { //custom code to run when headers have initalized
        //do nothing
    },
    onopenclose: function(header, index, state, isuseractivated) { //custom code to run whenever a header is opened or closed
        //do nothing
    }
})

