var urlParams = {};

// jQuery function wrapper to avoid library conflicts
(function($) {

    /*
    * Set non-js / js specific classes for CSS
    */
    $(function() {
        $("html").removeClass("nojs").addClass("js");
    });

    /**
     *  Table Stripes
     *  Simple table striping function; looks for tables with the class
     *  "stripes" and then applies striping to all tbody rows.
     *  Last modified: 2010-02-16 {pf}
    */ 
    function tableStripes() {
        $('table.stripes tbody tr:even').addClass('odd');
        $('table.stripes tbody tr:odd').addClass('even');
        $('table.stripes tbody tr:odd').removeClass('odd');
        $('table.stripes tbody tr:even').removeClass('even');
    }

    //  Bind table stripes on load
    $(document).ready(function() {
        tableStripes();
        
        $('.fdpoweredby').hide();
        $('.submit').click(function() {
            jQuery('form').unbind('submit');
        });
    });

    /*
    * Set Channel Columns height
    * Sets the minimum height of whitespace across all channel columns.
    */
    $(function() {
        var heighest = 0;    
        $('.channelCols h2').each(function() { if ($(this).height() > heighest) { heighest = $(this).height() } });
        $('.channelCols h2').css("min-height", heighest + "px");
    });

    /**
        *  (Bind Externals)
        *  On page load, automatically finds and sets all rel="external"
        *  hyperlinks to open in a new window when clicked.
        *  Last modified: 2010-02-16 {pf}
        */
    $(function() {
        $('a[rel=external]').each( function() {
            $(this).attr('title') ? $(this).attr('title', $(this).attr('title') + ' [opens in a new window]') : $(this).attr('title', 'Opens in a new window');
            $(this).click( function() {
                window.open($(this).attr('href'));
                return false;
            });
        });
    });

    $.fn.clearForm = function() {
        return this.each(function() {
            var type = this.type, tag = this.tagName.toLowerCase();
            if (tag == 'form')
                return $(':input', this).clearForm();
            if (type == 'text' || type == 'password' || tag == 'textarea')
                this.value = '';
            else if (type == 'checkbox' || type == 'radio')
                this.checked = false;
            else if (tag == 'select')
                this.selectedIndex = -1;
        });
    };

    /* Parse URL Querystring */

    (function() {
        var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function(s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

        while (e = r.exec(q))
            urlParams[d(e[1])] = d(e[2]);
    })();

})(jQuery)

function querySt(ji) {
    var queryString = window.location.search.substring(1);
    gy = queryString.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return urlDecode(unescape(ft[1])).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
        }
    }
}

function urlEncode(string) {
    string = string.replace(/\r\n/g, "\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if ((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

    }
    return utftext;
}

function urlDecode(utftext) {
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;

    while (i < utftext.length) {
        c = utftext.charCodeAt(i);
        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        }
        else if ((c > 191) && (c < 224)) {
            c2 = utftext.charCodeAt(i + 1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        }
        else {
            c2 = utftext.charCodeAt(i + 1);
            c3 = utftext.charCodeAt(i + 2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }

    }
    return string.replace("+", " ");
}

function checkValue(val) {
    if (val == "") {
        return "";
    } else if (val == null) {
        return "";
    } else if (val == "null") {
        return "";
    } else {
        return val;
    }
}


