function AttributeDropDown(input,element,id) {

	var attribute_titles = new Array();	
		var final = new Array();
				
			if(input.contains('|'))
			{
				try {
				groups = input.split('|');
				groups.each(function(group,i){
					
					if(group.contains(':'))
					{
						var pairs = group.split(';');					
						var pairArray  = new Array();				
						var numberOfPairs = 0;
						pairs.each(function(pair,j){
							if(pair.clean() != '')
							{
								if(numberOfPairs == 2)
									return;

								var parts = pair.split(':');
								attribute_titles.include(parts[0].clean());							
	
								values = new Array();																									
								if(parts[1].contains(','))																							
									parts[1].split(',').each(function(value,l){
										values.include(value.clean());										
									});																							
								else
									values.include(parts[1].clean());
	
								pairArray[attribute_titles.indexOf(parts[0].clean())] = values;							
								
								numberOfPairs++;
							}
						});		
						final[final.length] = pairArray;			
					}				
				});	
				} catch(e) {
					alert("Error 1st IF");
					return;
				}
			}
			else
			{
				try {
				if(input.contains(':'))
					{

						var pairs = input.split(';');					
						var pairArray  = new Array();	
							pairs.each(function(pair,j){
							if(pair.clean() != '')
							{
								var parts = pair.split(':');
								attribute_titles.include(parts[0].clean());							
	
								values = new Array();																									
								if(parts[1].contains(','))																							
									parts[1].split(',').each(function(value,l){
											values.include(value.clean());																					
									});																							
								else {
										values.include(parts[1].clean());
								}
	
								pairArray[attribute_titles.indexOf(parts[0].clean())] = values;							
							}
						});		
						final[final.length] = pairArray;			
					}
					
			} catch(e) {
			alert("Error 1st else");
			return;

			}
		}
		var attributes = new Array();
		var values = new Array();		
		try {
		final.each(function(pair,i){
			pair[0].each(function(attribute,j){
				if(attributes.contains(attribute))
					values[attributes.indexOf(attribute)] = values[attributes.indexOf(attribute)].copy().extend(pair[1]);
				else {
					attributes.include(attribute);
					if(pair[1]!=undefined)
						values.push(pair[1]);				
					else
						values.remove(pair[1]);
				}
			});		
		});
		} catch(e) {
			alert("ERROR 3rd");
			return;
		}
		
		try {
				var l1,l2,ddp1,ddp2,lqnt,qnt;
				
				function fillDDP(ddp,elementsArray)
				{
					$$(ddp).empty();
					elementsArray.each(function(element){
						ddp.adopt(new Element('option',{'value':element}).setText(unescape(element)));
					});
				}	


				//Om det finnes attributer
				if(attributes.length>0)
				{
					try {
					//ADDING DROPDOWNS
					l1 = new Element('label', {'for':'ddp1_'+id}).setHTML(attribute_titles[0]+": ").injectInside(element);
					ddp1 = new Element('select', {'name':'ddp1_'+id}).injectInside(element);
					fillDDP(ddp1,attributes);
					} catch(e) {alert("error creating l1 and filling it");}
					if(values.length>0)
					{
						try {
						l2 = new Element('label', {'for':'ddp2_'+id}).setHTML(attribute_titles[1]+": ").injectInside(element);				
						ddp2 = new Element('select', {'name':'ddp2_'+id}).injectInside(element);							
						fillDDP(ddp2,values[0]);														
						ddp1.addEvent('change',function(){fillDDP(ddp2,values[ddp1.selectedIndex])});						
						} catch(e) {alert("error creating l2 and filling it");}							
					}												
				}
				try {
					//ADDING QUANTITY
					lqnt = new Element('label', {'for':'qnt_'+id}).setHTML('Antall: ').injectInside(element);
					qnt = new Element('input', {'type':'text','value':'1','size':'5','name':'AddQnt_'+id}).injectInside(element);
				} catch(e) {alert("error adding quantity");}
		} catch(exception) {
			alert("ERROR 4th");
			return;
		}
}

window.addEvent('domready', function(){
	$ES('form').each(function(ProductForm) {
		ProductForm.setAttribute('action',ProductForm.getAttribute('action').replace(/SHOPID/,ShopID));
	});
});

function AddToBasket(form,id) {	

	if(form.elements['ProdNo_'+id].value.contains(':'))
		form.elements['ProdNo_'+id].value = form.elements['ProdNo_'+id].value.split(':')[0];	
	
	if($chk(form.elements['ddp1_'+id])) {
		form.elements['ProdNo_'+id].value += ':' + form.elements['ddp1_'+id].value; 
		if($chk(form.elements['ddp2_'+id]))
			form.elements['ProdNo_'+id].value += ':' + form.elements['ddp2_'+id].value;			
	}
	return true;
}
