﻿
redirect = function(str) {
    window.location = str
};

addFavorite = function(url, title) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    } else if (document.all) {
        window.external.AddFavorite(url, title);
    } else {
        alert("Sorry, your browser doesn't support this");
    } 
};

switchClass = function(el, class1, class2) {
    if ($(el).hasClass(class1)) {
        $(el).removeClass(class1).addClass(class2);
    } else {
    $(el).removeClass(class2).addClass(class1);
    }
};

$(document).ready(function() {
    $('#tree2').quickTreeBaseOne();
    $('#tree1').quickTreeBase();
    $('span.expand').toggle(function() { $(this).toggleClass('contract').nextAll('ul').slideDown(); },
                            function() { $(this).toggleClass('contract').nextAll('ul').slideUp(); });
    $("#wrapper #browsBg").css({ opacity: 0.5 });
    $("#dDown").click(function() { $("#browseBtn").toggleClass("active"); $("#browseCats").toggleClass("hidden"); });
    $("#browseCatscloseBottom").click(function() { $("#browseBtn").toggleClass("active"); $("#browseCats").toggleClass("hidden"); });
    $("#browseCatscloseTop").click(function() { $("#browseBtn").toggleClass("active");$("#browseCats").toggleClass("hidden"); });
    $("#DdQuickLinksOverview").click(function() { $("#quickLinksOverview").toggleClass("hidden"); $("#DdQuickLinksOverview").toggleClass("off"); });
    $("#quickLinksOverview").click(function() { $("#quickLinksOverview").toggleClass("hidden"); $("#DdQuickLinksOverview").toggleClass("off"); });

    DdSelect = function(str, txt) {
        $(".MembersAriaDropdown").val(txt);
        document.cookie = 'DdButton=' + str + '|' + txt + ';;path=/'
    };

    if ($("#ctl00_contentMiddleCenter_TestimonialsAdd1_CheckBoxMedia").attr("checked") == true) {
        $("#additionalInfo").show();
    }; 
    
    $("#ctl00_contentMiddleCenter_TestimonialsAdd1_CheckBoxMedia").click(function() { if (this.checked) { $("#additionalInfo").show(); } else { $("#additionalInfo").hide(); } });
});

jQuery.fn.quickTreeBaseOne = function(MyTree) {
    return this.each(function() {
        var $treeone = $(this);
        var $rootsone = $treeone.find('li');
        $treeone.find('li:last-child').addClass('last');
        $treeone.addClass('tree');
        $treeone.find('ul').hide();
        $rootsone.each(function() {
            if ($(this).children('ul').length > 0) {
                $(this).addClass('root').prepend('<span class="expand" />');
            }
        });
    });
};

jQuery.fn.quickTreeBase = function(MyTree) {
    return this.each(function() {
        var $tree = $(this);
        var $roots = $tree.find('li');
        $tree.find('li:last-child').addClass('last');
        $tree.addClass('tree');
        $tree.find('ul').hide();
        $roots.each(function() {
            if ($(this).children('ul').length > 0) {
                $(this).addClass('root').prepend('<span class="expand" />');
            }
        });
        var buildSelector = $(this)[0].id + ',span.expand';
    });
};

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options);
            options.expires = -1;
        };
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            };
            expires = '; expires=' + date.toUTCString();
        };
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        };
        return cookieValue;
    } 
};
        
$(document).ready(function() {
    $(".productsbox .hide ").click(function() {
        $(".productsOverView").animate({height: "toggle"});
        $(".productsbox .hide i span").text(
        $(".productsbox .hide i span").text() == '« hide it' ? '« show it' : '« hide it');
    });
});


function OnExecuteServiceJSON(location, data, success) {

    $.ajax({
        type: "POST",
        url: location, //"Service.asmx/Method"; "Page.aspx/Method"
        data: data, //"{'id':'1234','name':'myname'}"
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: success,
        error: OnExecuteServiceError
    });
}

function OnExecuteServiceError(xhr, status, results) {

    try {
        var err = eval("(" + xhr.responseText + ")");
        alert('There was an error calling the service: ' + '\r\n\r\n' + 'Message: ' + err.Message + '\r\n\r\n' + 'StackTrace: ' + err.StackTrace);
    }
    catch (err) {
    }
}

var reportAbuseElement;

function OnReportAbuse(commentID, method, el) {

    if (commentID > 0) {
        reportAbuseElement = el;
        var data = "{'id':'" + commentID + "'}";
        OnExecuteServiceJSON("Ajax.asmx/" + method, data, OnReportAbuseComplete);
    }
}

function OnReportAbuseComplete(result) {

    if (result.d.toLowerCase() == "false") {
        alert("Sorry, failed to report abuse. You may have exceeded the maximum limit of reports allowed.");
    }
    else {
        alert("Thank you, abuse has been report against this item and brought to our attention.");
        $(reportAbuseElement).hide();
    }
}


/*
 * Capslock 0.1 - jQuery plugin to detect if a user's caps lock is on or not.
 * 
 * Provides global events, "caps_lock_on" and "caps_lock_off", that custom functions can be bound to.
 * This saves you having to bind to each text box or area that needs watching.
 *
 * Copyright (c) 2009 Arthur McLean
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */

; // Just in case the previously included plug-in failed to close with a semi-colon.
(function($) {
	
	$.fn.capslock = function(options) {
		
		if (options) $.extend($.fn.capslock.defaults, options);
		
		//init();
		
		$().bind("caps_lock_on", $.fn.capslock.defaults.caps_lock_on);
		$().bind("caps_lock_off", $.fn.capslock.defaults.caps_lock_off);
		
		$(document).keypress(function(e){
			check_caps_lock(e);
		});
		
		return this;
	};
	

	
	// The actual check:
	function check_caps_lock(e)
	{
		var ascii_code	= e.which;
		var shift_key	= e.shiftKey;
		if( (65 <= ascii_code) && (ascii_code <= 90) && !shift_key)
		{
			$().trigger("caps_lock_on");
		}
		else
		{
			$().trigger("caps_lock_off");
		}
		
	}
	
	// Public definition of defaults for easy overriding:
	$.fn.capslock.defaults = {
		caps_lock_on:			function() {},
		caps_lock_off:			function() {}
	};
	
})(jQuery);

$(document).ready(function() {

    var options = {
    caps_lock_on: function()  { $("#caps_lock_status_ico").show(); $("#caps_lock_status_txt").show(); },
    caps_lock_off: function() { $("#caps_lock_status_ico").hide(); $("#caps_lock_status_txt").hide(); }
    };

    $().capslock(options);

    //$("#login :password").focus();
   
});