/*
 * $ Default javascript file
 *
 * Copyright (c) 2007 That's-id Multimedia
 */

/*------------------------------------------------------------------------------
	Methode om CSS background-image cache te forceren voor IE6
------------------------------------------------------------------------------*/

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


/*------------------------------------------------------------------------------
	onLoad handler
------------------------------------------------------------------------------*/
function bootstrap(cont)
{
	if(typeof sIFR == "function") sIFR.replaceElement(cont+" h1", named({sFlashSrc: "/flash/sifr/parrot_h1.swf", sColor: (cont=='body' ? "#ed1c24" : '#ec008c'), sWmode: "transparent", sCase:"upper"}));
	if(typeof $.validator == 'object') $(cont+' form').validatorEnable();
	if(typeof $.overlay == 'object') $(cont+' .contImgLeft, '+cont+' .contImgRight').setZoomHandler({animation: 'fade'});
}

function setProductContent($popup, options)
{
	//setTimeout("bootstrap('#popup_"+options.name+"');", 1);
	bootstrap('#popup_'+options.name);
}

function showProduct(pro_Id)
{
	$.overlay.showPopup('product', {
		showAnimation: 'slide',
		hideAnimation: 'slide',
		content: {url: '/product/'+pro_Id},
		preShowHandler: setProductContent
	});
	return false;
}

function updateShopList(page)
{

	if($('#winkel_plaats').val()=="" && $('#winkel_cat').val()=="")
	{ 
		$('.sfrm_errors').show();
	}
	else
	{	
		location.href='/'+page+'/'+$('#winkel_plaats').val()+'='+$('#winkel_cat').val();
	}
	
	return false;
}

function updateWebShopList()
{
	document.getElementById('index_online').innerHTML= "...de online verkooppunten worden ingeladen...";
	$.get('/dynamics/getshops.php',{
		online: true
	},
	function(msg) {
		document.getElementById('index_online').innerHTML=msg;
	});

	return false;
}

function findOnline(onl) 
{
	
	$('#zoekopties').hide();
	$('#switch_opties').show();
	$('#txtDealerType').hide();
	
	if(onl) {
		
		$('#txtDealerOnline').show();
		$('#txtDealerRegulier').hide();
		
		$('#dealer_online').show();	
		
		if($('#idx_populated').val()==1) $('#switch_online').hide();
		$('#index_online').show();
		
		$('#dealer_regulier').hide();
		$('#switch_regulier').show();
		$('#index_regulier').hide();
		
		updateWebShopList();		
	}
	else {
		
		$('#txtDealerOnline').hide();
		$('#txtDealerRegulier').show();
		
		$('#dealer_online').hide();
		if($('#idx_populated').val()==1) $('#switch_online').show();
		$('#index_online').hide();
		
		$('#dealer_regulier').show();	
		$('#switch_regulier').hide();
		$('#index_regulier').show();
	}
}

/*------------------------------------------------------------------------------
	AJAX handlers
------------------------------------------------------------------------------*/

function setIndex(pub_Id, page, archive)
{
	container = 'index_content';
	$.get('/dynamics/getindex.php',{ pub_Id: pub_Id, page: page, archive: archive },
		function(msg) {
			document.getElementById('index_container').innerHTML=msg;
		});
}

function showPub(pub_Id, action)
{
	$.overlay.status.overlayPub = pub_Id;
	$.overlay.status.overlayAction = action;

	$.ajax({
		url:	'/dynamics/getoverlay.php',
		data:	{pub_Id: pub_Id, action: action},
		success: function(content)
		{
			$.overlay.showOverlay();
			$('#popup').html(content);
			$.overlay.showPopup($.overlay.popupWidth, $.overlay.popupHeight);
			$('#overlay form').validatorEnable({ajaxHandler: setForm});
		},
		error: ajaxError

	});
}

function setForm(form_Id)
{
	$.ajax({
		type: 'POST',
		url: '/dynamics/getoverlay.php?pub_Id='+overlayPub+'&action='+overlayAction,
		data: $('form#'+form_Id+' :input').serialize(),
		success: function(content){
			$('#popup').html(content);
			$.overlay.showPopup($.overlay.popupWidth, $.overlay.popupHeight);
			$('#overlay form').validatorEnable({ajaxHandler: setForm});
		},
		error: ajaxError
	});
	return false;
}

/*------------------------------------------------------------------------------
	Various
------------------------------------------------------------------------------*/

function checkCookies(redirect)
{
	var cookieName = 'testCookie';
	document.cookie = cookieName + '=cookieValue';
	var cookiesEnabled = document.cookie.indexOf(cookieName) != -1;
	if (!cookiesEnabled)
	{
		location.href=redirect;
	}
}
