function setSearchFocusCssClass(element) {
	if (element.value=='Search...') {
		element.value='';
	}
	element.className = 'searchInputActive';
}
function unsetSearchFocusCssClass(element) {
	if (element.value=='') {
		element.value='Search...';
		element.className = 'searchInput';
	}
}

function setCategorySearchFocusCssClass(element, textValue) {
	if (element.value==textValue) {
		element.value='';
	}
	element.className = 'searchInputActive';
}
function unsetCategorySearchFocusCssClass(element, textValue) {
	if (element.value=='') {
		element.value=textValue;
		element.className = 'searchInput';
	}
}

function bookmarkPage(title, url){
	if(document.all) {
		window.external.AddFavorite(url, title);
	}
}

function getOpenWindowsSettings(width,height,scroll,menubar,toolbar,status) {
	var startLeft = (screen.width-width)/2;
	var startTop = (screen.height-height)/2;
	var settings  ='height='+height+',';
	settings +='width='+width+',';
	settings +='top='+startTop+',';
	settings +='left='+startLeft+',';
	settings +='scrollbars='+scroll+',';
	settings +='menubar='+menubar+',';
	settings +='toolbar='+toolbar+',';
	settings +='status='+status+',';
	settings +='resizable=yes';
	return settings;
}

function popupWindow(url,name,width,height) {
	settings = getOpenWindowsSettings(width, height, 'yes', 'yes', 'yes', 'yes');
	window.open(url,name,settings);
}

function popupWindowSettings(url,name,width,height,scroll,menubar,toolbar,status) {
	settings = getOpenWindowsSettings(width,height,scroll,menubar,toolbar,status);
	window.open(url,name,settings);
}

function shareMySpace(title, content, url, l)
{
	var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(title)
	+ '&c=' + encodeURIComponent(content) + '&u=' + encodeURIComponent(url) + '&l=' + l;
	window.open(targetUrl);
	return false;
}


function shareDelicious() { window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=700,height=400'); return false; }
function shareFacebook() { 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; }
function shareWishlistFacebook() { u=location.href;window.open('http://www.facebook.com/share.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');return false; }

// cookies
function createCookie(name, value, days)
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires="+date.toGMTString();
	}
	else {
		var expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

function eraseCookie(name)
{
	createCookie(name, "" , -1);
}

function setRefString(string)
{
	document.cookie = "linkRef=" + string + "; path=/";
	return true;
}

// "Welcome to Mighty Ape" notification bar hider
function hideWelcome()
{
	createCookie('HideWelcomeBar', 'true', 1000);
	var welcome = document.getElementById('welcomeBar');
	welcome.style.display = 'none';
	return false;
}

function loadProducts(listId, direction, tracking, params)
{
	var page = $('#listPage_' + listId).val();
	var totalPages = $('#listMaxPages_' + listId).val();

	// generate base url
	var requestUrl = '/ajax/products/get-list-products/direction/' + direction + '/page/' + page + '/tracking/' + tracking + '/';

	var listContainer = $('#listContainer_'+listId);
	listContainer.addClass('loading');

	// do request passing in an extra params that are required
	jQuery.getJSON(requestUrl, params, function (data) {
		// manually make the button go back to inactive state in MSIE
		window.focus();

		// store the new page number
		$('#listPage_' + listId).val(data.page);

		// update the pages count
		$('#listPageLabel_' + listId).html(data.pagesLabel);

		// replace items
		for (i = 0; i < data.items.length; i++) {
			containerId = 'listItems_' + listId + '_item' + (i + 1);
			$('#' +containerId).html(data.items[i]);
		}

		// toggle prev/next arrows
		if (data.page == '1') {
			$('#listPrev_' + listId).hide();
		}
		else {
			$('#listPrev_' + listId).show();
		}

		if (data.page == totalPages) {
			$('#listNext_' + listId).hide();
		}
		else {
			$('#listNext_' + listId).show();
		}

		listContainer.removeClass('loading');
	});
}

function loadDailyDeal(direction)
{
	var page = $('#dailyDealPage').val();

	var requestUrl = '/ajax/products/get-daily-deal/direction/' + direction + '/page/' + page + '/';

	jQuery.getJSON(requestUrl, function (data) {
		// store the new page number
		$('#dailyDealPage').val(data.page);

		// update the deal
		$('#dailyDealProduct').html(data.item);
	});
}

function closeNotice(container)
{
	$('#' + container).slideUp();
}
