////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SYSTEM /////////////////////////////////////////////////////////filterArticleList//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function changeDefaultAdress(_ala_nr, _kdnr){
		var url = "/modules/change_default_address.php";
	var _param = "ala_nr="+_ala_nr+"&kdnr="+_kdnr
	var popupReq = new Ajax.Request(url, {method:'post', parameters:_param, 
			onComplete:function(elem){
						_resp = elem.responseText;
						if(_resp){
							alert("Ihre Anfrage wurde erfolgreich an Wolf Möbel verschickt")
						}else{
							alert("Bei der Anfrage trat ein unbekannter Fehler auf")
						}
					}
			});
}

function updateArtCalc1(){
	var d = document.getElementById("art_calc");
	if(!d || document.print_tmp=="") return false;
	var list = document.print_tmp
	tmp = list.split("_");
	art_count = tmp.length-1;
	page_mod = art_count%8;
	page_count = page_count_ret = Math.ceil(art_count/8);
	if(page_mod && page_count!=1){
		//page_count_ret -=1;
	}
	ret_str = "Markierte Artikel: "+art_count;
	if(page_mod && page_count!=1){
		ret_str += " (davon "+page_mod+" auf der letzten Seite)"; 
	}
	var add_cover = document.getElementById("add_cover").checked
	if(add_cover){
		page_count_ret +=1;
	}
	ret_str += "<br />Katalog-Seiten: "+page_count_ret;
	if(add_cover) ret_str += " (inkl. Deckblatt)";
	d.innerHTML = ret_str;
}

function submitPdf(collection, catalog){
	pl = document.print_tmp;	
	if(pl){		
		if(catalog){
			var vk_fac = document.getElementById("vk_factor").value;			
			var add_fk = document.getElementById("show_prices").checked;	
			var show_vk_fac_val = document.getElementById("show_prices").checked;
			var add_cover_val = document.getElementById("add_cover").checked;
			add_pricelist_val = false;
			only_pricelist_val = false;
			if(arguments[2]==1){
				only_pricelist_val = true;
			}
			if(arguments[2]==2){
				add_pricelist_val = true;
			}
			window.open("/modules/g_pdf_cat.php?collection="+collection+"&list="+pl+"&show_vk_factor="+show_vk_fac_val+"&add_cover="+add_cover_val+"&add_pricelist="+add_pricelist_val+"&only_pricelist="+only_pricelist_val+"&vk_factor="+vk_fac+"&add_fk="+add_fk);
		}else{
			window.open("/modules/g_pdf.php?collection="+collection+"&list="+pl);
		}
	}else{
		alert("Bitte w"+unescape("%E4")+"hlen Sie einen oder mehrere Artikel aus");
	}
}


function showPriceBox(){
	var d = document.getElementById("vk_factor_check");
	var vkf = document.getElementById("vk_factor");
	if(d.style.display=="none"){
		d.style.display="block";
		vkf.value=1;
	}else{
		d.style.display="none";
		d.value="";
		vkf.value=0;
	}
}

function ieLink(url){
	window.location.href=url;
}
/*
	FUNCTION openBrWindow(theURL,winName,features)
*/
function openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}
function checkNumber(id){
	var elem = document.getElementById(id).value;
	if(isNaN(elem)){
		alert("Bitte geben Sie eine g"+unescape("%FC")+"ltige Menge ein!");
		return false; 
	}else{
		return true; 
	}

	
}
/*
	FUNCTION getCookieVal (offset)
*/
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
}
/*
	FUNCTION GetCookie (name)
*/
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
/*
	FUNCTION SetCookie (name, value)
*/
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CONTENT /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
	FUNCTION filterArticleList(collection)
*/
function filterArticleList(collection, target, by_hst){	 
	var filter = document.getElementById('kategorie').value;
	c = collection.replace(" ", "_");
	if(by_hst==1){
		window.location.href="/Container/"+c+"="+target+"@filter="+filter;
	}else if(by_hst==2){
		window.location.href="/Katalog/"+c+"=Artikel@filter="+filter;
	}else{
		window.location.href="/Kollektionen/"+c+"="+target+"@filter="+filter;
	}
	
}

/*
	FUNCTION filterArticleListNew(collection)
*/
function filterArticleListNew(collection, target, by_hst){	 
	var filter = document.getElementById('kategorie').value;
	var afilter = document.getElementById('art_dd') ? document.getElementById('art_dd').value : "0";//document.getElementById('art_dd').value;
	var cfilter = document.getElementById('coll_dd') ? document.getElementById('coll_dd').value : "0";
	if(arguments[3]==true){
		if(by_hst) filter = 0;
		afilter = 0;
	
	}
	
	if(arguments[4]==true) afilter = 0

	c = collection.replace(" ", "_");
	
	if(target=="Artikel"){
		window.location.href="/Katalog/"+c+"=Artikel@filter="+cfilter+";"+filter+";"+afilter;
	}else{
	if(by_hst==1){
		window.location.href="/Container/"+c+"="+target+"@filter="+cfilter+";"+filter+";"+afilter;
	}else if(by_hst==2){
		window.location.href="/Katalog/"+c+"=Artikel@filter="+cfilter+";"+filter+";"+afilter;
			}else{
		window.location.href="/Kollektionen/"+c+"="+target+"@filter="+cfilter+";"+filter+";"+afilter;
	}
	}
	
}
/*
	FUNCTION getMusterconti(collection, page)
*/
function getMusterconti(collection, page){	
	var mc = document.getElementById('mc_id').value;
	c = collection.replace(" ", "_");
	window.location.href="/Kollektionen/"+c+"="+page+"@mc="+mc;
}
/*
	FUNCTION filterPictureList(collection)
*/
function filterPictureList(collection){	
	var filter = document.getElementById('kategorie').value;
	c = collection.replace(" ", "_");
	window.location.href="/Kollektionen/"+c+"=Bilder@filter="+filter;
}
/*
	FUNCTION showDlThumb(id)
*/
function showDlThumb(id){
	var d=document.getElementById("dlThumb_"+id);
	if(d.style.display=="none"){
		d.style.display="block";
	}else{
		d.style.display="none";
	}
}

/*
	FUNCTION showThumb(id)
*/


/*
	FUNCTION getDownload(id)
*/
function getDownload(id){
	window.open("/Downloads=Download!"+id, "download", "width=100, height=100");
	window.download.close();
}  




/*
	FUNCTION setCount(id)
*/
function setCount(id){
	var d=document.getElementById("changeCountLink_"+id);
	var s=document.getElementById("changeCount_"+id);
	d.style.display="none";
	s.style.display="block";
	s.count.focus();
	s.count.select();
}
/*
	FUNCTION setCountForm(id)
*/
function setCountForm(id){
	var val = document.getElementById("changeCount_"+id).count.value
	return (!isNaN(val) || val>0);	
}
/*
	FUNCTION changeCount(id, count, collection)
*/
function changeCount(id, count, collection){
	/*var d=prompt("Bitte neue Menge eingeben:", count);
	if(d){
		if(isNaN(d) ||? d<=0){
			var c=alert("Bitte geben Sie eine g�ltige Zahl ein!");		
		}else{
			window.location.href="/modules/changeCount.php?id="+id+"&count="+d+'&collection='+collection;
		}
	}*/
}
/*
	FUNCTION addToBasket(id, coll, land, hst_nr)
*/
function addToBasket(id, coll, land, hst_nr){
	var d=prompt("Bitte Menge eingeben:", "1");
	if(isNaN(d)){
		var c=alert("Bitte geben Sie eine g"+unescape("%FC")+"ltige Zahl ein!");		
	}else{
		if(d){
			window.location.href="/modules/addToBasket.php?id="+id+"&collection="+coll+"&count="+d+"&land="+land+"&hst_nr="+hst_nr;
		}
	}
}
/*
	FUNCTION mcToBasket(id, coll, mcName, has, land)
*/
function mcToBasket(id, coll, mcName, has, land){
	var check = true;
	if(has==1){
		check = false;
		check = confirm("Sie haben Bereits einen Warenkorb der Kollektion '"+coll+"'. Wollen Sie diesen durch den Mustercontainer '"+mcName+"' ersetzten?");		
	}
	if(check){
		window.location.href="/modules/addMcToBasket.php?id="+id+"&collection="+coll+"&land="+land;
	}
}
/*
	FUNCTION  deleteItem(id, art_nr, def, collection, bid)
*/
function deleteItem(id, artnr){
	var check = confirm("Wollen Sie den Artikel '"+artnr+"' wirklich aus dem Warenkorb l"+unescape("%F6")+"schen?");
	if(check){
		window.location.href="/modules/delete_item.php?id="+id+'&artnr='+artnr;
	}
}
/*
	FUNCTION  deleteBasket(id, collection, openBasket)
*/
function deleteBasket(id, collection){
	var check = confirm("Wollen Sie den Warenkorb der Kollektion '"+collection+"' wirklich l"+unescape("%F6")+"schen?");
	if(check){
		window.location.href="/modules/delete_card.php?id="+id;
	}
}
/*
	FUNCTION  deleteOldOrder(id, sid, collection)
*/
function deleteOldOrder(id, sid, collection){
	var check = confirm("Wollen Sie die offene Bestellung wirklich l"+unescape("%F6")+"schen?");
	if(check){
		window.location.href="/modules/deleteOldBasket.php?id="+id+"&sess="+sid+'&collection='+collection;
	}
}
/*
	FUNCTION  activateOldBasket(id, collection)
*/
function activateOldBasket(id, collection, related){
	var check = 1; //confirm("Wollen Sie diese Bestellung wieder aktivieren?");
	if(check){
		window.location.href="/modules/activateOldBasket.php?id="+id+"&collection="+collection+'&related='+related;
	}
}
/*
	FUNCTION  fusionOldBasket(id, collection)
*/
function fusionOldBasket(id, collection){
	alert("Es besteht ein aktueller Container der Linie '"+collection+"'! Funktion zur Zusammenf�hrung kommt noch ;)");
}
/*
	FUNCTION  showOpenBastket(show)
*/
function showOpenBastket(show){
	var d=document.getElementById("openItems");
	var s=document.getElementById("showOpenBaskets");
	var h=document.getElementById("hideOpenBaskets");	
	if(show){
		d.style.display="block";
		h.style.display="inline";
		s.style.display="none";
	}else{
		d.style.display="none";
		h.style.display="none";
		s.style.display="inline";
	}
}
/*
	FUNCTION  changeShippingAdress(id, sid, collection)
*/
function changeShippingAdress(id, sid, collection){
	var selId = document.orderForm.shippingAdress.value;
	var urlStr = "/Kollektionen/"+collection+"=Bestelluebersicht@id="+id+";sid="+sid+";selId="+selId;
	window.location.href=urlStr;
}
function showSubfolders(num, allnums){	
	for(t=1; t<=allnums; t++){
		d = document.getElementById("subFolder_"+t);
		l = document.getElementById("subList_"+t);
		if(t==num){
			d.style.display="block";
			l.style.color="#900";
		}else{
			d.style.display="none";
			l.style.color="black";
		}
			
	}
}


function swapArticleDD(elem, id){
	var dd = document.getElementsByClassName('class_categorie_'+id)
	for(var t=0; t<dd.length; t++){
		dd[t].style.display = "none";	
	}
	
	var dd = document.getElementsByClassName('class_articles_'+id)
	for(var t=0; t<dd.length; t++){
		dd[t].style.display = "none";	
	}
	if($('linker_li_'+id)) $('linker_li_'+id).className = elem.value=="0" ? "open" : "succ";
	//dd_articles_139_1
	$("dd_categorie_"+id+"_"+elem.value).style.display = "inline";
	$("dd_articles_"+id+"_"+elem.value).style.display = "inline";
	
}

function swapArticleDDFirst(elem, id){
	if($('linker_li_'+id)) $('linker_li_'+id).className = elem.value=="0" ? "open" : "succ";
	
}
function swapArticleDDFirst(elem){	
	resetSavedStatus(elem);
}
function resetSavedStatus(elem){	
	var _id = elem.getAttribute("id");
	var _coll = elem.getAttribute("title");
	if(_id.match(/categorie/)){
		var dd = document.getElementsByClassName('class_articles_0')
		for(var t=0; t<dd.length; t++){
			dd[t].value = 0;
		}
	}
	if(_id.match(/article/)){
		var dd = document.getElementsByClassName('class_categorie_0')
		for(var t=0; t<dd.length; t++){
			dd[t].value = 0;
		}
		var _index = elem.selectedIndex;
		
		// SET CAT
		var _cat = elem.options[_index].getAttribute("title");
		// GET CURRENT KAT DD
		var dd = document.getElementsByClassName('class_categorie_0')
		for(var t=0; t<dd.length; t++){
			if(dd[t].style.display =="inline"){
				dd[t].value = _cat
			}
		}
	}
}
