$(document).ready(function()
{
    SetPopup();

    SetTreeImages();

    //SetNavigationLinkEvents();

    //watermark for search-textboxes
    SetWatermarks();

    //open login modal popup on click for any items that have the class "triggerLoginPopup"
    SetLoginPopupTriggers();

});

function openShareThis(id, title, type) {

    var newWindow = window.open(root + "ShareThis.aspx?id=" + id + "&title=" + title + "&type=" + type, "ShareThis", "height=230px,width=355px;")

    newWindow.focus();

}

function SetLoginPopupTriggers()
{
    $(".triggerLoginPopup").click(function() { showLoginPopup(); return false; });
}

function ChangeBackground(editor, args)
{
    var style = editor.get_contentArea().style;
    style.backgroundImage = "none";
    style.backgroundColor = "#ffffff";
}

function SetWatermarks()
{
    $(".watermarkName").Watermark("Search by name...", "#5D5D53");
    $(".watermarkCity").Watermark("Search by city...", "#5D5D53");
    $(".watermarkKeyword").Watermark("Search by keyword...", "#5D5D53");
    $(".watermarkKeywordMap").Watermark("keyword, name", "#5D5D53");
    $(".watermarkAddressMap").Watermark("address/city/postal code", "#5D5D53");
    $(".enterName").Watermark("Enter name", "#5D5D53");
    $(".enterEmail").Watermark("Enter e-mail address", "#5D5D53");
    $(".filterTitleDesc").Watermark("Filter by title/description", "#5D5D53");
}

function fbs_click() { u = location.href; t = document.title; window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436'); return false; }

//swap out images on hover
function SetNavigationLinkEvents()
{
    $(".navigationLink img").hover(
      function()
      {
          if ($(this).attr("src").indexOf("_on") == -1)
              $(this).attr("src", $(this).attr("src").replace("_off", "_hover"));
      },
      function()
      {
          if ($(this).attr("src").indexOf("_on") == -1)
              $(this).attr("src", $(this).attr("src").replace("_hover", "_off"));
      }
    );
}

function SetPopup()
{
    //redirect all external links to disclaimer-page
    $('a').filter(
                    function()
                    {
                        return this.target == "_pop";

                    }).each(

                        function(i)
                        {
                            $(this).attr("href", "javascript:openWindow('" + $(this).attr("href") + "', 550, 655);");
                            $(this).attr("target", "");
                        }
                );
}

function toggleMore()
{

    $(".more").parent().children(".heading2:first").html($(".more").parent().children(".heading2:first").html().replace("...", $(".more").parent().children(".heading2:last").html()));
    $(".more").parent().children("a.less").hide();
    $(".more").parent().children("a.more").show();

}

function toggleLess()
{

    $(".more").parent().children(".heading2:first").html($(".more").parent().children(".heading2:first").html().replace($(".more").parent().children(".heading2:last").html(), "") + "...");
    $(".more").parent().children("a.less").show();
    $(".more").parent().children("a.more").hide();

}

//sets the onclick for the images in the topic-tree
function SetTreeImages()
{
    $(".topicTree img").click(function()
    {
        if (this.src.indexOf("Minus") != -1)
        {
            $(this).parent().children("ul").slideUp("fast");
            this.src = this.src.replace("Minus", "Plus");
            $(this).parent().children("a").removeClass("current");
        }
        else
        {
            $(".level2").slideUp("fast");
            $(".topicTree img").attr("src", this.src.replace("Minus", "Plus"));
            $(".topicTree a").removeClass("current");
            $(this).parent().children("ul").slideDown("fast");
            $(this).parent().children("a").addClass("current");
            this.src = this.src.replace("Plus", "Minus");
        }
    })
}

//clears a fileupload control
function reset_html(id)
{
    $('#' + id).html($('#' + id).html());
}

//use this to set a maxlength for multiline textboxes
function maxLength(text, long)
{

    var maxlength = new Number(long); // Change number to your max length.

    if (text.value.length > maxlength)
    {

        text.value = text.value.substring(0, maxlength);

        alert(" This field allows a maximum of " + long + " characters");

    }

}

//little function to cause postback when ok button in modalpopup is clicked
function clickOK(sender, e)
{
    __doPostBack(sender, e);
}

//background color for radeditor
function RadEditorLoad(editor)
{
    var style = editor.GetContentArea().style;
    //style.backgroundColor = document.bgColor;
    style.backgroundColor = "#FFFFFF";
}

//open a new window
function openWindow(url, w, h)
{
    window.open(url, "Resource", "toolbar=no, location=yes, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width=" + w + ", height=" + h + ", top=220, left=200");
}

//prevent enter from triggering
function noenter()
{
    return !(window.event && window.event.keyCode == 13);
}

//make enter submit form
function entsub(myform)
{
    if (window.event && window.event.keyCode == 13)
        myform.submit();
    else
        return true;
}

//the purpose of this function is to allow the enter key to 
//point to the correct button to click.
function doClick(buttonName, e)
{
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox


    if (key == 13)
    {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null)
        { //If we find the button click it

            btn.click();

            if (window.event)
                event.keyCode = 0; //IE

            event.returnValue = false;
            event.cancel = true;
        }
    }
}

//select all checkboxes in a given gridview
function selectGridViewAll(gridView)
{
    var list = document.getElementById(gridView);

    var options = list.getElementsByTagName('input');

    for (i = 0; i < options.length; i++)
        options[i].checked = true;
}

function selectGridViewNone(gridView)
{
    var list = document.getElementById(gridView);

    var options = list.getElementsByTagName('input');

    for (i = 0; i < options.length; i++)
        if (!options[i].disabled)
        options[i].checked = false;
}

function toggleVisibility(elementId)
{
    if ($get(elementId).style.visibility == 'visible')
        $get(elementId).style.visibility = 'hidden';
    else
        $get(elementId).style.visibility = 'visible';
}





/*
* Copyright (c) 2007 Josh Bush (digitalbush.com)
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:

* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. 
*/

/*
* Version: Beta 1
* Release: 2007-06-01
*/
(function($)
{
    var map = new Array();
    $.Watermark = {
        ShowAll: function()
        {
            for (var i = 0; i < map.length; i++)
            {
                if (map[i].obj.val() == "")
                {
                    map[i].obj.val(map[i].text);
                    map[i].obj.css("color", map[i].WatermarkColor);
                } else
                {
                    map[i].obj.css("color", map[i].DefaultColor);
                }
            }
        },
        HideAll: function()
        {
            for (var i = 0; i < map.length; i++)
            {
                if (map[i].obj.val() == map[i].text)
                    map[i].obj.val("");
            }
        }
    }

    $.fn.Watermark = function(text, color)
    {
        if (!color)
            color = "#aaa";
        return this.each(
			function()
			{
			    var input = $(this);
			    var defaultColor = input.css("color");
			    map[map.length] = { text: text, obj: input, DefaultColor: defaultColor, WatermarkColor: color };
			    function clearMessage()
			    {
			        if (input.val() == text)
			            input.val("");
			        input.css("color", defaultColor);
			    }

			    function insertMessage()
			    {
			        if (input.val().length == 0 || input.val() == text)
			        {
			            input.val(text);
			            input.css("color", color);
			        } else
			            input.css("color", defaultColor);
			    }

			    input.focus(clearMessage);
			    input.blur(insertMessage);
			    input.change(insertMessage);

			    insertMessage();
			}
		);
    };
})(jQuery);

1/**
2 * jQuery.ScrollTo - Easy element scrolling using jQuery.
3 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
4 * Dual licensed under MIT and GPL.
5 * Date: 5/25/2009
6 * @author Ariel Flesler
7 * @version 1.4.2
8 *
9 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
10 */
11; (function(d) { var k = d.scrollTo = function(a, i, e) { d(window).scrollTo(a, i, e) }; k.defaults = { axis: 'xy', duration: parseFloat(d.fn.jquery) >= 1.3 ? 0 : 1 }; k.window = function(a) { return d(window)._scrollable() }; d.fn._scrollable = function() { return this.map(function() { var a = this, i = !a.nodeName || d.inArray(a.nodeName.toLowerCase(), ['iframe', '#document', 'html', 'body']) != -1; if (!i) return a; var e = (a.contentWindow || a).document || a.ownerDocument || a; return d.browser.safari || e.compatMode == 'BackCompat' ? e.body : e.documentElement }) }; d.fn.scrollTo = function(n, j, b) { if (typeof j == 'object') { b = j; j = 0 } if (typeof b == 'function') b = { onAfter: b }; if (n == 'max') n = 9e9; b = d.extend({}, k.defaults, b); j = j || b.speed || b.duration; b.queue = b.queue && b.axis.length > 1; if (b.queue) j /= 2; b.offset = p(b.offset); b.over = p(b.over); return this._scrollable().each(function() { var q = this, r = d(q), f = n, s, g = {}, u = r.is('html,body'); switch (typeof f) { case 'number': case 'string': if (/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)) { f = p(f); break } f = d(f, this); case 'object': if (f.is || f.style) s = (f = d(f)).offset() } d.each(b.axis.split(''), function(a, i) { var e = i == 'x' ? 'Left' : 'Top', h = e.toLowerCase(), c = 'scroll' + e, l = q[c], m = k.max(q, i); if (s) { g[c] = s[h] + (u ? 0 : l - r.offset()[h]); if (b.margin) { g[c] -= parseInt(f.css('margin' + e)) || 0; g[c] -= parseInt(f.css('border' + e + 'Width')) || 0 } g[c] += b.offset[h] || 0; if (b.over[h]) g[c] += f[i == 'x' ? 'width' : 'height']() * b.over[h] } else { var o = f[h]; g[c] = o.slice && o.slice(-1) == '%' ? parseFloat(o) / 100 * m : o } if (/^\d+$/.test(g[c])) g[c] = g[c] <= 0 ? 0 : Math.min(g[c], m); if (!a && b.queue) { if (l != g[c]) t(b.onAfterFirst); delete g[c] } }); t(b.onAfter); function t(a) { r.animate(g, j, b.easing, a && function() { a.call(this, n, b) }) } }).end() }; k.max = function(a, i) { var e = i == 'x' ? 'Width' : 'Height', h = 'scroll' + e; if (!d(a).is('html,body')) return a[h] - d(a)[e.toLowerCase()](); var c = 'client' + e, l = a.ownerDocument.documentElement, m = a.ownerDocument.body; return Math.max(l[h], m[h]) - Math.min(l[c], m[c]) }; function p(a) { return typeof a == 'object' ? a : { top: a, left: a} } })(jQuery);