
function findObject(objectId)
{
	if(window.document.getElementById && window.document.getElementById(objectId))
		return window.document.getElementById(objectId);
	else if (window.document.all && window.document.all(objectId))
		return window.document.all(objectId);
	else if (window.document.layers && window.document.layers[objectId]) 
		return window.document.layers[objectId];
	else
		return null;
}

function loadPopup(sHref, sWidth, sHeight)
{
	var LeftPosition=(screen.width)?(screen.width-sWidth)/2:100;
	var TopPosition=(screen.height)?(screen.height-sHeight)/2:100;
	var settings='width='+sWidth+',height='+sHeight+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	var theWindow = window.open(sHref, '_blank', settings);
	if (theWindow != null)
		theWindow.focus();
	return theWindow;
}


window.onload = function()
{	
	InitializeLightBox();
}

function InitializeLightBox()
{
	if (typeof(initLightbox) == 'function')
	{
		initLightbox();
	}
}
	
function ToggleContainer(id, bExpand)
{
	try
	{
		var _objContainer = findObject(id);
		if (_objContainer != null)
		{
			PageMethods.ToggleProductContainer(id, bExpand, function(response)
			{
				_objContainer.innerHTML = response;				
			});
		}
	}
	catch(e)
	{
	}	
	return false;
}


/*function SetFilter(sID, sFilter, sValue)
{
	try
	{
		var _objProductList = findObject('productlist');
		
		if (_objProductList != null)
		{
			PageMethods.SetFilter(sID, sFilter, sValue, function(response)
			{
				if(response)
				{				
					window.document.location.reload();
				}
			});	
		}	
	}
	catch(e)
	{
		alert(e);
	}
	
	return false;
}*/

/*function RemoveFilter(FilterName, CategoryId)
{
	PageMethods.RemoveFilter(FilterName, CategoryId, function(response)
	{
		if(response)
		{				
			window.document.location.reload();
		}
	});
	
	return false;
}*/

function ExpandFilters(obj)
{
	var filterList = findObject('filters');
	var expandButton = findObject('filterExpander');
	
	if (filterList != null)
	{
		filterList.id = 'filters_expanded';
		expandButton.className = 'filter_collapse';
		expandButton.innerText = 'Verberg filter opties';
	}
	else
	{
		filterList = findObject('filters_expanded');
		
		if (filterList != null)
		{
			filterList.id = 'filters';
			expandButton.className = 'filter_expand';
			expandButton.innerText = 'Toon alle filter opties';
		}
	}
}


var showingMore = false;
var moreText = 'More...';
var lessText = 'Less...';


function pageLoaded() {
	jQuery('li.hiddenFilter').css('display', 'none');
}

$(document).ready(function() {
	jQuery('li.hiddenFilter').css('display', 'none');

	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(pageLoaded);
});

function ExpandFilterColumn(obj_id) {
	var obj = jQuery('#' + obj_id);
	
	if (obj) {
		if (obj.children('li.moreFiltersLink').children('a').text() == moreText) {
			if (obj.children('li.hiddenFilter').length > 0) {
				obj.children('li.hiddenFilter').css('display', 'block');
				obj.children('li.moreFiltersLink').children('a').text(lessText);
			}
		}
		else {
			if (obj.children('li.hiddenFilter').length > 0) {
				obj.children('li.hiddenFilter').css('display', 'none');
				obj.children('li.moreFiltersLink').children('a').text(moreText);
			}
		}
	}
}

function PrintProduct(obj_id) {

	jQuery(obj_id).openOverlay({ sColor: '#ffffff', iOpacity: 60 });

	var detailBlocks = jQuery('#productlist').children('div');

	for (var i = 0; i <= detailBlocks.length - 1; i++) {
		if (detailBlocks[i].id != obj_id) {
			jQuery(detailBlocks[i]).css('display', 'none');
		}
	}

	window.print();

	setTimeout(function() {
		for (var i = 0; i <= detailBlocks.length - 1; i++) {
			jQuery(detailBlocks[i]).css('display', 'block');
			jQuery(obj_id).openOverlay('close');
		} 
	}, 1500);
}


function ShowSearchDetails(obj_id) {
	var obj = jQuery('#' + obj_id);
	if (obj) {
		PageMethods.ToggleProductSearchContainer(obj_id, true, function(response) {
			obj.slideUp('fast', function() {
				obj.html(response);
				obj.slideDown('slow', function() {
					jQuery('div.producten_uitgeklapt_search').css('border', '1px solid #B62517');
				});
			});
		});
	}

	return false;
}

function HideSearchDetails(obj_id) {
	var obj = jQuery('#' + obj_id);
	if (obj) {
		PageMethods.CreateSearchControlASync(obj_id, function(response) {
			obj.slideUp('fast', function() {
				obj.html(response);
				obj.slideDown('slow', function() {
					jQuery('div.producten_uitgeklapt_search').css('border', '1px solid #B62517');
				});
			});
		});
	}

	return false;
}

$(document).ready(function() {
	jQuery('#shopbanners').children('a').mouseover(function() {
		if (jQuery(this).children('img').attr('src').indexOf('_over.jpg') == -1) {
			jQuery(this).children('img').attr('src', jQuery(this).children('img').attr('src').replace('.jpg', '_over.jpg'));
		}
	});


	jQuery('#shopbanners').children('a').mouseout(function() {
		if (jQuery(this).children('img').attr('src').indexOf('_over.jpg') > -1) {
			//jQuery(this).children('img').attr('src', jQuery(this).children('img').attr('src').replace('_over.jpg', '.jpg'));
			jQuery(this).children('img').attr('src', jQuery(this).children('img').attr('originalsrc'));
		}
	});
	
	jQuery('#txtUsername').keypress(function (e) {
		CatchLogin(e);
	});

	jQuery('#txtPassword').keypress(function (e) {
		CatchLogin(e);
	});

	jQuery('#chkPersist').keypress(function (e) {
		CatchLogin(e);
	});
});

function CatchLogin(e)
{
	
	if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) 
	{  
		e.preventDefault();
		Login();
		return false;  
	} 
	else 
	{  
		return true;  
	}  
}

function Login()
{
	var username = jQuery('#txtUsername');
	var password = jQuery('#txtPassword');
	var persist = jQuery('#chkPersist');
	
	if (username.val() == '')
	{
		username.addClass('inloggenstyle_error');
	}
	else
	{
		username.removeClass('inloggenstyle_error');
	}

	if (password.val() == '')
	{
		password.addClass('inloggenstyle_error');
	}
	else
	{
		password.removeClass('inloggenstyle_error');
	}

	if (username.val() != '' && password.val() != '')
	{
		PageMethods.Login(username.val(), password.val(), persist.attr('checked'), function(response){
			if (response == 'OK')
			{
				window.location.replace(window.location);
			}
			else
			{
				jQuery('#inloggen_feedback').text(response);
			}
		});
	}
}

function Logout()
{
	PageMethods.Logout(function(){
		window.location.replace('/');
	});
}
