

//generate Selects for TypesAttributes

var lastSelect="";

function getAttributesSelects(field){
	
	if(field.selectedIndex>0 && lastSelect!=field.selectedIndex){
		lastSelect=field.selectedIndex;
		var typeAlias=field.options[field.selectedIndex].value;
		var typeName=field.options[field.selectedIndex].text;
		$.post('/modules/mod_products/lib/response.php',{ type : "attributes" , typeAlias : typeAlias },function(data){getAttributes_callback(data);},"json");
	}
}

var lastAttrSelect=null;

function getAttributes_callback(data){
	document.getElementById('articles').innerHTML="";
	document.getElementById("articleAttributes").innerHTML="";
	if(data){
		var html="";
		lastAttrSelect=new Array;
		lastAttrSelect.length=data.msg.length;
		for(var i=0;i<lastAttrSelect.length;i++){
			lastAttrSelect[i]=0;
		}
		for(var i=0;i<data.msg.length;i++){
			html+="<p>"+data.msg[i].name+"</p>";
			if(data.msg[i].values.length>0){
				html+='<select id="attr_'+i+'">';
				html+='<option value="'+data.msg[i].id+'" onclick="getArticles();">keine Angabe</option>';
				for(var h=0;h<data.msg[i].values.length;h++){
					html+='<option value="'+data.msg[i].id+'" onclick="getArticles();">'+data.msg[i].values[h].attributes_value+'</option>';
				}
				html+='</select>';
			}
		}
		document.getElementById("articleAttributes").innerHTML=html;
		getArticles();
	}
	
}


function getArticles(){
	
	document.getElementById('articles').innerHTML="";
	var query="";
	var typeId=document.getElementById('types').options[document.getElementById('types').selectedIndex].value;
	for(var i=0;i<lastAttrSelect.length;i++){
		if(document.getElementById('attr_'+i)){
			attribute=document.getElementById('attr_'+i);
			query+=attribute.options[attribute.selectedIndex].value+"##sep1##"+attribute.options[attribute.selectedIndex].text+"##sep2##";
		}
	}
	query=query.substring(0,query.length-8);
	$.post('/modules/mod_products/lib/response.php',{ type : "articles" , query : query , typeId : typeId },function(data){getArticles_callback(data);},"json");
	
}

function getArticles_callback(data){
	var html="";
	var cat=document.getElementById('param1').value;
	var mod=document.getElementById('module').value;
	var typ=document.getElementById('types').options[document.getElementById('types').selectedIndex].value;
	
	for(var i=0;i<data.msg.length;i++){
		var art=data.msg[i].alias;
		html+='<p>';
		html+='<a href="/'+art+'/'+cat+'/'+typ+'/'+mod+'" class="articleLink">';
		html+='<image src="/'+data.msg[i].pics[0].path+'thn_'+data.msg[i].pics[0].filename+'" alt=""/>&nbsp;&nbsp;';
		html+='<span style="font-weight: bold;">'+data.msg[i].name+'</span>&nbsp;&nbsp;';
		html+=data.msg[i].description.substring(0,20)+'&nbsp;&nbsp;';
		html+=data.msg[i].price+'&nbsp;&nbsp;';
		html+='</a>';
		html+='</p>';
	}
	document.getElementById('articles').innerHTML=html;
}

