﻿//--------------------------------------------------------
//      +++ on pageload +++
//--------------------------------------------------------

$(function() {

    // +++ tabs +++
    $(".tab_content").hide();
    $("ul.tabs li:first").addClass("active").show();
    $(".tab_content:first").show();

    // +++  Select field contents +++
    $("input[type=text]").focus(function() {
        this.select();
    });

    // +++  filebrowser styles +++
    $("input[type=file]").filestyle({
        image: "/images/buttons/btn_upload.gif",
        imageheight: 18,
        imagewidth: 72,
        width: 120
    });

    // +++ add listeners +++
    addAllMouseEventListeners();

    // Preload images
    $.preloadImages("/images/10step/step_1_hover.gif",
					"/images/10step/step_2_hover.gif",
					"/images/10step/step_3_hover.gif",
					"/images/10step/step_4_hover.gif",
					"/images/10step/step_5_hover.gif",
					"/images/10step/step_6_hover.gif",
					"/images/10step/step_7_hover.gif",
					"/images/10step/step_8_hover.gif",
					"/images/10step/step_9_hover.gif",
					"/images/10step/step_10_hover.gif",
					"/images/icons/fold_in_black.gif");

});

    
//--------------------------------------------------------
//      +++ mouse events +++
//--------------------------------------------------------

function addAllMouseEventListeners()
{

	// +++ step menu +++
    $('#stepMenu ul#steps li a:not(.sel)').mouseover(
	function()
	{
	    overImage = $(this).find("img").attr("src").replace(".gif", "_hover.gif");
	    $(this).find('img').attr('src', overImage);
	});

	$('#stepMenu ul#steps a:not(.sel)').mouseout(
	function()
	{
	    image = $(this).find("img").attr("src").replace("_hover.gif", ".gif");
	    $(this).find('img').attr('src', image);
	});


    // +++ faq +++
	$('.faqItem .question').click(
	function()
	{
	    $(this).parent('.faqItem').find('.answer').slideToggle('fast');
	});


	// +++  black bar - expand/collapse  +++
	$('.expandArea, .expandArea688').toggle(function()
	{
		$(this).find('.slideContent').slideToggle('fast');
		$(this).find('.barBlack img').attr('src', '/images/icons/fold_in_black.gif');
	}, function()
	{
		$(this).find('.barBlack img').attr('src', '/images/icons/fold_out_black.gif');
		$(this).find('.slideContent').slideToggle('fast');
	});


	// +++ tabs@inbox +++
	$("ul.tabs li").click(function()
	{
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();

		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
	});


	// +++  Login +++
	$('#header a#loginLink').click(function()
	{
		$('#loginBox').fadeIn('slow');
		$('#loginBox input.txt:eq(0)').focus();
		return false;
	});

	$('#loginBox a.close').click(function(event)
	{
		$('#loginBox').fadeOut('fast');
		return false;
	});


	// +++  Footer - expand/collapse  +++
	$('#footer').toggle(
	function()
	{
		$('#footer .slideContent').slideToggle('fast');
		$('#footer .chatActive img').attr('src', '/images/icons/fold_in.gif');

	}, function()
	{
		$('#footer .slideContent').css('display', 'none');
		$('#footer .chatActive img').attr('src', '/images/icons/fold_out.gif');
    });
    $('#footer .slideContent').click(function() { return false; });
    $('#footer .slideContent a').click(function() { if ($(this).attr("href").indexOf("liveperson") < 0) { window.open($(this).attr("href")) }; return false; });

	$('#footer').mouseover(
	function()
	{
		$('#footer .chatActive').css('background-color', '#e9e9e9');
	});

	$('#footer').mouseout(
	function()
	{
		$('#footer .chatActive').css('background-color', '#FFF');
	});


	// +++  Share box  +++
	$('a.share').click(function()
	{
		$('#shareBox').slideToggle('fast');
		$('#shareBox #reciever').focus();
	});

	$('#shareBox a.close').click(function(event)
	{
		$('#shareBox').slideToggle('fast');
	});

	$('a.share').mouseover(
	function()
	{
		$('.boxShare a.share img').attr('src', '/images/icons/ikon_share_over.gif');
	});

	$('a.share').mouseout(
	function()
	{
		$('.boxShare a.share img').attr('src', '/images/icons/ikon_share.gif');
	});


	// +++ print +++
	$('a.print').mouseover(
	function()
	{
		$('a.print img').attr('src', '/images/icons/ikon_print_over.gif');
	});

	$('a.print').mouseout(
	function()
	{
		$('a.print img').attr('src', '/images/icons/ikon_print.gif');
	});
};


//--------------------------------------------------------
//      +++ Blog Rating +++
//--------------------------------------------------------


function toggleBlogRating(blogNodeId, ratingIndex)
{
	var strUpdatedHitCount = '';

	$.get(
	"/toggleBlogRating.ashx",
	{
		blogNodeId: blogNodeId,
		index: ratingIndex,
		rnd: Math.floor(Math.random() * 100000)
	},
	function(data)
	{
		if (data.toLowerCase().indexOf('error') < 0)
		{
			strUpdatedHitCount = data;

			if (strUpdatedHitCount != '')
			{
				var arrUpdatedHitCount = strUpdatedHitCount.split(',');

				var index = 0;
				$('.blogHitCount' + blogNodeId).each(function()
				{
					if (arrUpdatedHitCount.length > index)
						$(this).text('(' + arrUpdatedHitCount[index] + ')');

					index++;
				});
			}
		}
	});
}


//--------------------------------------------------------
//      +++ Quick Poll Vote +++
//--------------------------------------------------------

function incrementQuickPollVote(quickPollNodeId, voteIndex)
{
	var strUpdatedHitCount = '';

	$.get(
	"/addQuickPollVote.ashx",
	{
		quickPollNodeId: quickPollNodeId,
		index: voteIndex,
		rnd: Math.floor(Math.random() * 100000)
	},
	function(data)
	{
		if (data.toLowerCase().indexOf('error') < 0)
		{
			strUpdatedHitCount = data;

			if (strUpdatedHitCount != '')
			{
				$('.quickPollVoteHitCount' + quickPollNodeId + '-' + voteIndex).text('(' + strUpdatedHitCount + ')');

				$('.quickPollOption' + quickPollNodeId).each(function()
				{
					$(this).replaceWith($(this).text());
				});
			}
		}
	});
}



//--------------------------------------------------------
//      +++ LivePerson +++
//--------------------------------------------------------

var lpNumber = ""; // Add Site ID (LP-NUMBER)
var lpImagePath = ""; // Add Image Path
var lpServerName = "server.iad.liveperson.net";

var LPREPSTATEONLINE = "online";  // Reps available online
var LPREPSTATEOFFLINE = "offline";  // No available reps online - offline or away
var LPREPSTATEOCCUPIED = "occupied";  // Rep in "back in 5" state
var LPREPSTATEUNKNOWN = "unknown";  // Unable to contact server

function repStateNotifyFunction(state)
{
	var onclick = "lpButtonCTTUrl = 'https:\/\/server.iad.liveperson.net\/hc\/" + lpNumber + "\/?cmd=file&file=visitorWantsToChat&site=" + lpNumber + "&imageUrl=" + lpImagePath + "&status=online&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat" + lpNumber + "','width=475,height=400,resizable=yes');return false;";

	if (state == LPREPSTATEONLINE)
	{
		$('#footer').addClass('online');
		$('#chatOperatorOnlineText').show();
		$('#A1').attr('href', $('#A1').attr('href').replace('status=offline', 'status=online'));
//		$('#A1').attr('onclick', $('#A1').attr('onclick').replace('status=offline', 'status=online'));
//		//$('#A1').attr('onclick', onclick.replace('status=offline', 'status=online'));
	}
	else
	{
		$('#footer').removeClass('online');
		$('#chatOperatorOfflineText').show();
		$('#A1').attr('href', $('#A1').attr('href').replace('status=online', 'status=offline'));
//		$('#A1').attr('onclick', $('#A1').attr('onclick').replace('status=online', 'status=offline'));
//		//$('#A1').attr('onclick', onclick.replace('status=online', 'status=offline'));
	}
}
