
function changeVariant ()
{
	// get the selected variants
	var elements = document.variant_selector.elements;
	var variants = new Object ();
	var num_variants = 0;
	for (var i=0;elements[i];i++) {
		var element 	= elements[i];
		var key			= element.name;
		// ignore everything but selects
		if (element.nodeName != 'SELECT') { continue; }
		var value		= element.options[element.selectedIndex].value;
		/*
		console.log ('checking');
		console.log (key);
		console.log (value);
		*/
		num_variants++;
		variants[key]	= value;
	}
	console.debug ('variants');
	console.debug (variants);

	var match = {article_id:0,matches:0};
	for (var artI=0;articles[artI];artI++) {
		var matches = 0;
		var article = articles[artI];
		console.log('checking');
		console.log(article);
		for (key in variants) {
			var prop_value = variants[key];
			var prop_key = key;
			if (article._properties) {
				for (var pI=0;article._properties[pI];pI++) {
					var property = article._properties[pI];
					/*
					console.log (prop_key);
					console.log (prop_value);
					console.log (property);
					console.log (property);
					*/
					if (property._propertytype._propertytype_name.text_value == prop_key &&
							property._property_value.text_value == prop_value) {
						matches++;
					}
				}
			}
		}
		// prevent current article from counting....
		if (matches > match.matches && article.article_id != current_article_id) {
			match = {article_id: article.article_id, matches: matches};
		}
	}
	// console.log (match);
	// TODO: what happends if there is 0 matches?
	if (match.matches > 0) {
		/*
		console.log ("got matches");
		console.log (match);
		*/
		
		var hidden = document.variant_selector.elements['params[article_id]'];
		hidden.value = match.article_id;
		// console.log (hidden);
		document.variant_selector.submit();
	} else {
		// console.log ("No matches");
	}
}

