/*  Start /_templates/roottemplate/scripts/roottemplate.js */

swfobject.addLoadEvent(function(){

	if($('right')) {
		iDocHeight = document.viewport.getHeight();
		iMainHeight = $('main_container').getHeight()+1;
		if(iDocHeight > iMainHeight) {
			iHeight = iDocHeight;
		
			if($('right').className=='right') {
				iMinHeight= 273; //ivm met padding is deze 2x14px groter
			}else{
				iMinHeight= 245;
			}
			iHeight = iHeight-iMinHeight;
			
		}else{
			iHeight = iMainHeight;
		}
			
		$('right').style.height = iHeight+'px';
	}
});

function showImg(element) {
	$(element).up(1).show();
}

/*function hidePageCount() {
	if($('pagecount_ov')) {
		iCount = $('counter').innerHTML;
		if(iCount == 0 || iCount == 1 ) {
			var productCountElements = $$('.pagecount_overall#product_count');
			productCountElements.each(function(item) {
			//alert(item+ 'test');
				item.hide();
			});			
			
			//$('product_count').hide();
		}
	}
	
	//
}
*/

function hidePageCount() {
	if($('pagecount_ov')) {
		iCount = $('counter').innerHTML;
				
		var productCountElements = $$('.pagecount_overall'); // div met pagecount en productcount
		productCountElements.each(function(item) {
			if(iCount == 0 || isNaN(iCount) ) {	// isNaN check voor als variabele niet vervangen wordt doordat core repeat niet uitgevoerd wordt ivm met geen resultaten uit query
				removeElementBySelector(item,'id','pagecount_ov');
				removeElementBySelector(item,'id','product_count');
			} else if(iCount == 1) {
				removeElementBySelector(item,'id','pagecount_ov');
			}
		});
	}
	
			
	//
}

function removeElementBySelector (parentitem,selector,value) {
			var Elements = parentitem.getElementsBySelector('['+selector+'="'+value+'"]');
				Elements.each(function(element) {
					element.hide();				
				});
}

function updatePage(sVal){
	$('search_page_count').value = sVal;
	document.main_search.submit();
}


document.observe("dom:loaded", function() {
	$('main_container').style.overflow = 'hidden';
	hidePageCount();  

});

function toLocation(location) {
	window.location=(PGX.Path + location);
}

/*  End /_templates/roottemplate/scripts/roottemplate.js */

/*  Start /_templates/winkelwagen/scripts/winkelwagen_klein.js */

function gotoUrl(myurl) {
	location=(PGX.Path+myurl);
	//location="http://www.google.nl";
}

function updateWinkelwagenklein() {
	aParams = {};
	aParams.source = '/_templates/winkelwagen/winkelwagen_klein.html';	
	pgx('cartContainer', 'core.html', aParams);
}

function orderProduct(product, prefix) {		
	aParams = {};
	aParams.action = 'add';
	aParams.product = product;
	aParams.quantity = 1;
		
	aParams.lichtbron1 = '';
	aParams.lichtbron1_id = '';
	aParams.lichtbron1_artikelnr = '';
	aParams.lichtbron1_aantal = 0;	
	aParams.lichtbron2 = '';
	aParams.lichtbron2_id = '';
	aParams.lichtbron2_artikelnr = '';
	aParams.lichtbron2_aantal = 0;	
	aParams.lichtbron3 = '';
	aParams.lichtbron3_id = '';
	aParams.lichtbron3_artikelnr = '';
	aParams.lichtbron3_aantal = 0;
	
	aParams.onComplete = function() {
	
		aParams = {};
		aParams.source = '/_templates/winkelwagen/winkelwagen_klein.html';
		aParams.onComplete = function() {
			
			location=prefix+'/nl/webshop/bestellen/winkelwagen.html';
			
		}
		pgx('cartContainer', 'core.html', aParams);		
	}
	
	pgx('', 'local.order', aParams);
}

function deleteProduct(uuid) {		
	aParams = {};
	aParams.action = 'delete';
	aParams.uuid = uuid;
	aParams.onComplete = function() {
		
		aParams = {};
		aParams.source = '/_templates/winkelwagen/winkelwagen_groot.html';
		aParams.onComplete = function() {
			aParams = {};
			aParams.source = '/_templates/winkelwagen/winkelwagen_klein.html';
			pgx('cartContainer', 'core.html', aParams);
		}
		pgx('cartContainerFull', 'core.html', aParams);
		
	}
	
	pgx('', 'local.order', aParams);
}

function updateProduct(uuid, element) {		
	focused = $(element).id;
	
	// aantal
	elmAantal = 'a_'+uuid;	
	quantity = $(elmAantal).value;
	
	if (isNaN(quantity)) {
		quantity = 1;
	}
			
	aParams = {};
	aParams.action = 'update';
	aParams.uuid = uuid;
	aParams.quantity = quantity;
	
	//lichtbronnen aantal	
	// lichtbron 1
	myName = 'al1_'+uuid;
	elm1 = $(myName);
	myName = 'al1id_'+uuid;
	elm2 = $(myName);
	myId = '';
	myAantal = 0;
	if ((elm1) && (elm2)) {
		myId = elm2.value;
		myAantal = elm1.value;
		if (isNaN(myAantal)) {
			myAantal = 0;
		}		
	}
	aParams.lichtbron1_id = myId;
	aParams.lichtbron1_aantal = myAantal;
	
	// lichtbron 2
	myName = 'al2_'+uuid;
	elm1 = $(myName);
	myName = 'al2id_'+uuid;
	elm2 = $(myName);
	myId = '';
	myAantal = 0;
	if ((elm1) && (elm2)) {
		myId = elm2.value;
		myAantal = elm1.value;
		if (isNaN(myAantal)) {
			myAantal = 0;
		}		
	}
	aParams.lichtbron2_id = myId;
	aParams.lichtbron2_aantal = myAantal;
	
	// lichtbron 3
	myName = 'al3_'+uuid;
	elm1 = $(myName);
	myName = 'al3id_'+uuid;
	elm2 = $(myName);
	myId = '';
	myAantal = 0;
	if ((elm1) && (elm2)) {
		myId = elm2.value;
		myAantal = elm1.value;
		if (isNaN(myAantal)) {
			myAantal = 0;
		}		
	}
	aParams.lichtbron3_id = myId;
	aParams.lichtbron3_aantal = myAantal;	
						
	aParams.onComplete = function() {				
		
		aParams = {};
		aParams.source = '/_templates/winkelwagen/winkelwagen_groot.html';
		aParams.onComplete = function() {
			$(focused).focus();			
		}
		
		pgx('cartContainerFull', 'core.html', aParams);		
		/**/
	}
		
	pgx('', 'local.order', aParams);
}

/*  End /_templates/winkelwagen/scripts/winkelwagen_klein.js */

