////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PRODUCTS ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function showThumb(id){
	var d=$("thumb_"+id);
	var s=$("prev_a_"+id);
	var h=$("prev_d_"+id);
	if(d.style.display=="none"){
		new Effect.Appear(d);
		h.style.display="block";
		s.style.display="none";
	}else{
		new Effect.Fade(d,{duration:.2})
		h.style.display="none";
		s.style.display="block";
	}
}
function markAllPdfs(){
	var extension = "";
	var str = "";
	if(arguments[1]==1){
		extension = " with_image";
		//markAllPdfs(1);
	}
	 var cb = document.getElementsByClassName("add_pdf_checkbox"+extension);
	 for(var t=0; t<cb.length; t++){
	 	cb[t].checked = !arguments[0];
	 }	 
	 var im = document.getElementsByClassName("article pdf"+extension);
	
	 for(var t=0; t<im.length; t++){
	 	if(arguments[0]!=1){
	 		if(!im[t].className.match(/mark/)){
	 			im[t].className += " mark";
	 			// CHECK BOX
	 			var id = im[t].getAttribute("id").replace(/art_/, '');
	 			if($("cb_"+id)) $("cb_"+id).checked = true;
	 		}
	 		
	 	}else{
	 		im[t].className = im[t].className.replace(" mark", "");
	 		// CHECK BOX
	 		var id = im[t].getAttribute("id").replace(/art_/, '');
	 		if($("cb_"+id)) $("cb_"+id).checked = false;
	 	}
	 }
		updateArtCalc();
}
function markAllPdf(){
	document.print_tmp ="";
	for(var t=0; t<arguments.length; t++){
		document.getElementById("cb_"+arguments[t]).checked=true;
		addToPdf(arguments[t]);
	}
}
function deMarkAllPdf(){
	document.print_tmp ="";
	for(var t=0; t<arguments.length; t++){
		document.getElementById("cb_"+arguments[t]).checked=false;
		addToPdf(arguments[t]);
	}
}
function addToPdf(art_nr){
	var act = document.getElementById("art_"+art_nr);
	var cb = document.getElementById("cb_"+art_nr);	
	if(arguments[1]){
		cb.checked = !cb.checked;
	}

	// SetCookie ('wannasomecookie', 1, exp);
	// get cookie
	printList = document.print_tmp;
	if(printList==null){
		printList ="";
	}
	
	

	
	if(cb.checked){
		if(arguments[2]){	
			act.className = "article pdf with_image mark "+arguments[2];
		}else{
			act.className = "article pdf with_image mark"
		}
	   printList = printList + art_nr+"_";
	}else{
		if(arguments[2]){	
			act.className = "article pdf with_image "+arguments[2];
		}else{
			act.className = "article pdf with_image"
		}
		// remove from cookie
		 printList =  printList.replace(art_nr+"_", "");
	}
	document.print_tmp=printList;
	//alert(document.print_tmp);	
	
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BASKET ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function addItemToCart(_rand){
	var url = "/modules/add_to_cart.php?ajax=true";
	var _param = Form.serialize("changeCount_"+_rand);
	var popupReq = new Ajax.Request(url, {method:'post', parameters:_param, 
		onComplete:function(elem){
			_resp = elem.responseText;
				var can_parse = _resp.match(/^\[.*\]$/);
					if(can_parse){
						var resp_array = eval(_resp);
							openCountFormV2(_rand, true)
							if(resp_array[0]!=0 || resp_array[0]==undefined){
								$('addToBasketLink_'+_rand).innerHTML = "Menge: "+resp_array[0];
								if($('item_'+_rand)) $('item_'+_rand).className = "item in_cart";
								$('changeCount_'+_rand).count.value = resp_array[0]
							}else{
								$('addToBasketLink_'+_rand).innerHTML = "Warenkorb";
								if($('item_'+_rand)) $('item_'+_rand).className = "item";
								$('changeCount_'+_rand).count.value = 1
							}							
							$('items_count_in_cart').innerHTML = resp_array[1]
						}else{
							alert("UNBEKANNTER FEHLER");
						}
					}
			}
		);	
}
function openCountFormV2(id){
	_close = arguments[1];
	var f=$("row_"+id);
	var fs=$("sub_row_"+id);
	var b=$("addToBasketLink_"+id);
	f.style.display = _close ? "none" : (isIE() ? "block" : "table-row")
	fs.style.display = _close ? "none" : (isIE() ? "block" : "table-row")
	b.style.display = _close ? "block" : "none";	
	if(!_close){
		$('changeCount_'+id).count.focus();
	}
}

