function blockSelect(el){
	//alert (el.style.color);
	 if (el.style.color == 'rgb(255, 255, 255)' || el.style.color == '#fff'){ 
	 	el.style.color = '#000'; 
		el.style.backgroundColor = '#FFF'; 
		return false; 
	} 
	el.style.color = '#FFF'; 
	el.style.backgroundColor = '#666'; 
}

function MoveBlocks(productId,url){
	
	var parrent  = document.getElementById('cati');
	var acti = document.getElementById('actC');
	var del = [];
	var childs = parrent.childNodes;
	var g = 0
	for (s=0; s< childs.length; s++){
	
		if (childs[s].style.color == 'rgb(255, 255, 255)' || childs[s].style.color == '#fff'){
			
			childs[s].style.color = '#000'; 
			childs[s].style.backgroundColor = '#FFF'; 	
			$('node').request(url + 'Framework/Modules/ShopModule/Admin/ajax.ShopControle.php?id=' + productId + '&catId=' + childs[s].id + '&add');
			del[g]= childs[s].id;
			g ++;
			
			
		}
			
		
		
	}
	for (s=0; s< del.length; s++){
	
		acti.appendChild(document.getElementById(del[s]));
		
	}
	
	
}

function WareHouseMoveBlocks(productId,url){
	
	var parrent  = document.getElementById('cati');
	var acti = document.getElementById('actC');
	var del = [];
	var childs = parrent.childNodes;
	var g = 0
	for (s=0; s< childs.length; s++){
	
		if (childs[s].style.color == 'rgb(255, 255, 255)' || childs[s].style.color == '#fff'){
			
			childs[s].style.color = '#000'; 
			childs[s].style.backgroundColor = '#FFF'; 	
			$('node').request(url + 'Framework/Modules/ShopModule/Admin/ajax.ShopWarehouseControle.php?id=' + productId + '&catId=' + childs[s].id + '&add');
			del[g]= childs[s].id;
			g ++;
			
			
		}
			
		
		
	}
	for (s=0; s< del.length; s++){
	
		acti.appendChild(document.getElementById(del[s]));
		
	}
	
	
}


function MoveBlocksBack(productId,url){
	
	var parrent  = document.getElementById('actC');
	var acti = document.getElementById('cati');
	var del = [];
	var childs = parrent.childNodes;
	var g = 0
	for (s=0; s< childs.length; s++){
		//alert(childs[s].style.color);
		if (childs[s].style.color == 'rgb(255, 255, 255)' || childs[s].style.color == '#fff'){
			
			childs[s].style.color = '#000'; 
			childs[s].style.backgroundColor = '#FFF'; 	
			
			del[g]= childs[s].id;
			g ++;
			
			$('node').request(url + 'Framework/Modules/ShopModule/Admin/ajax.ShopControle.php?id=' + productId + '&catId=' + childs[s].id + '');
			
		}

		
	}
	
	for (s=0; s< del.length; s++){
	
		acti.appendChild(document.getElementById(del[s]));
		
	}
	
	
}


function WareHouseMoveBlocksBack(productId,url){
	
	var parrent  = document.getElementById('actC');
	var acti = document.getElementById('cati');
	var del = [];
	var childs = parrent.childNodes;
	var g = 0
	for (s=0; s< childs.length; s++){
		//alert(childs[s].style.color);
		if (childs[s].style.color == 'rgb(255, 255, 255)' || childs[s].style.color == '#fff'){
			
			childs[s].style.color = '#000'; 
			childs[s].style.backgroundColor = '#FFF'; 	
			
			del[g]= childs[s].id;
			g ++;
			
			$('node').request(url + 'Framework/Modules/ShopModule/Admin/ajax.ShopWarehouseControle.php?id=' + productId + '&catId=' + childs[s].id + '');
			
		}

		
	}
	
	for (s=0; s< del.length; s++){
	
		acti.appendChild(document.getElementById(del[s]));
		
	}
	
	
}

function calucateprice(){
	
	var p =  document.getElementById('percentage').value;
	var f =  document.getElementById('fixed').value;
	var pr =  document.getElementById('prices').value;

	if (f >0){
		
		$('price').update('Aanbiedings prijs <br>&euro;'+ f);
		
		return false;
	}
	if (p >0){
		
		var newPrice = (Math.round((pr*((100-p)/100))*100)/100) ;
		$('price').update('Aanbiedings prijs <br>&euro;'+ newPrice);
		
		return false;	
	}
	
	else {
		$('price').update('prijs <br>&euro;'+ pr)
	}
}

function SaveOffer(productId,url){
	var p =  document.getElementById('percentage').value;
	var f =  document.getElementById('fixed').value;
	
	var startDate = document.getElementById('yearstart').value + '-' + document.getElementById('maandstart').value + '-' + document.getElementById('dagstart').value; 
	var endDate = document.getElementById('yearend').value + '-' + document.getElementById('maandend').value + '-' + document.getElementById('dagend').value; 
	
	
	if (f > 0 || p > 0){
		$('node').request(url+'./Framework/Modules/ShopModule/Admin/ajax.ShopControle.php?id=' + productId + '&fixed=' + f + '&percentage=' + p + '&saveOffer=true&start=' + startDate + '&end=' + endDate);
	}
	else {
		$('node').request(url+'./Framework/Modules/ShopModule/Admin/ajax.ShopControle.php?id=' + productId + '&DeleteOffer=true');
	}
}

function CalculateBatchPrice(id){
	
	var pr = document.getElementById(id + 'normalPrice').value;
	var f = document.getElementById(id + 'fixed').value;
	var p = document.getElementById(id + 'percentage').value;
	
	if (f >0){
		
			$(id + 'batchprice').update(' = &euro;'+ f);
		
		return false;
	}
	if (p >0){
		
		var newPrice = (Math.round((pr*((100-p)/100))*100)/100) ;
		$(id + 'batchprice').update(' = &euro;'+ newPrice);
		
		return false;	
	}
	
}
function calculateQuantum(){
	
	var f = document.getElementById('prijs').value;
	f = ((f)? f : 0);
	var p = document.getElementById('percentage').value;
	p = ((p)? p : 0);
	var n = document.getElementById('normalPrice').value;
	var a = document.getElementById('Aantal').value;
	
	if (f>0){
		$('quantumPrice').update("prijs voor " + a + " = &euro; " + (f));
	}
	if(p > 0  && f == 0){
		$('quantumPrice').update("prijs voor " + a + " = &euro; " + ((a*n)*((100-p)/100)));
	}
	
	
}

function safeQuantum(product_id,url){
	
	var f = document.getElementById('prijs').value;
	f = ((f)? f : 0);
	var p = document.getElementById('percentage').value;
	p = ((p)? p : 0);
	var a = document.getElementById('Aantal').value;
	
	$('node').request(url+'Framework/Modules/ShopModule/Admin/ajax.ShopControle.php?id=' + product_id + '&AddDiscount=true&fixed=' + f +'&percentage=' + p + '&amount=' + a,null,function (e) { calculateQuantum(); } );
}


function CheckIfVariant(url,product_id,client){
	client = ((client)? client : null);
	var v =document.getElementById('Vert');
	
	var h = document.getElementById('Horz');
		
	var vertValue = v.options[v.selectedIndex].value
	var horzValue = h.options[h.selectedIndex].value
	
	if (vertValue != '.....' && horzValue != '.....'){
		
		$('variantId').request(url + 'Framework/Modules/ShopModule/ajax/ajax.Variant.php?vert=' + vertValue + '&horz=' + horzValue + '&product_id=' + product_id,null,function (e){ $('price').request(url + 'Framework/Modules/ShopModule/ajax/ajax.PriceVariant.php?vert=' + vertValue + '&horz=' + horzValue + '&product_id=' + product_id); } );
		
	}
	
	
}


function ShowMain(element){
	
	var image = element.src;
	
	document.getElementById('MainPicture').src = image;
	
	var Active = document.getElementsByClassName('act');
	
	for (s = 0;s < Active.length; s++){
	
	
		Active[s].className = '';
		Active[s].style.border = '';
		Active[s].style.height = '55px';
		
	}
	element.style.border ='1px solid #333';	
	element.className ='act';
	element.style.height = '53px';
	
	if (parseInt(element.id) <= 4){
		document.getElementById('Wrapper').style.marginLeft = '0px';	
	}
	
}

function BackPicture(){
	var ActId = 0;
	var Active = document.getElementsByClassName('act');
	for (s = 0;s < Active.length; s++){
	
		if (Active[s].className == 'act'){
			
			ActId = Active[s].id;
			if (ActId>0){
				Active[s].className = '';
				Active[s].style.border = '';
				Active[s].style.height = '55px';
			}
		}		
		
	}
	
	ActId--;
	
	if (ActId >=4){
		var cmargin = document.getElementById('Wrapper').style.marginLeft;	
		cmargin = cmargin.replace('px','');
		cmargin = parseInt(cmargin);		
		var margin = cmargin + 80;
		document.getElementById('Wrapper').style.marginLeft = margin+'px';		
	}
	
	
	
	if(ActId >= 0){
	
		var element = document.getElementById(ActId);
		element.style.border ='1px solid #333';	
		element.className ='act';
		element.style.height = '53px';
		var image = element.src;
		document.getElementById('MainPicture').src = image;
	
	}
}

function NextPicture(amount){
	var ActId = 0;
	var Active = document.getElementsByClassName('act');
	
	for (s = 0;s < Active.length; s++){
	
		if (Active[s].className == 'act'){
			
			ActId = Active[s].id;
			if (ActId < (amount-1)){	
				Active[s].className = '';
				Active[s].style.border = '';
				Active[s].style.height = '55px';
			}
			
		}		
		
	}
	
	ActId++;
	
	
	
	
		var element = document.getElementById(ActId);
		if (element != null){
			
			if (ActId >4){
	
				var margin = (ActId-(amount-2))*80;
				var cmargin = document.getElementById('Wrapper').style.marginLeft;	
				cmargin = cmargin.replace('px','');
				document.getElementById('Wrapper').style.marginLeft = -margin+'px';		
			}
			
			element.style.border ='1px solid #333';	
			element.className ='act';
			element.style.height = '53px';
			var image = element.src;
			document.getElementById('MainPicture').src = image;
		}

}

function rate(el){
	
	rating = el.title;
	
	document.getElementById('rateStars').value = rating;
	
	
	
}
function rateHighlight(el,url){
	rating = el.title;
	//alert(rating);
	for(var s =1;s<=rating;s++){
		
		document.getElementById('star'+s).src = url+'Graphics/Default/webshop/star.png';
		
	}
	
}
function rateUnhighlight(el,url){
	
	for(var s =1;s<=5;s++){
		
		document.getElementById('star'+s).src = url+'Graphics/Default/webshop/staroff.png';
		
	}
	
	
}

function rateRestore(url){
	//alert("lol");
	var value = document.getElementById('rateStars').value;
	for(var s =1;s<=value;s++){
		
		
		document.getElementById('star'+s).src = url+'Graphics/Default/webshop/star.png';
		
	}
	
}

