$(function(){
	$("a[rel=jqzoom]").lightBox();
	//$("a[rel=jqzoom]").jqzoom();
	$("#modelTxt").autocomplete(PATH.root+"ajax.php?op=autocompleteModel",{
		selectFirst : false,
		formatItem : ACformatItem,
		formatResult : ACformatResult,
		max:50,
		width:156,
		scrollHeight:350,
		extraParams: {
	       	id_brand: function() { return $("#id_brand").val(); }
	   	}
	}).result(function(event, row) {
		$("#rightForm input[type=hidden][name=id_model]").remove();
	  	$("#rightForm").prepend("<input type='hidden' name='id_model' value='"+row[1]+"'>");
	  	getYears(row[1]);
	  	submitRightForm();
	});
	
	$("#brand_model").autocomplete(PATH.root+"ajax.php?op=autocompleteBrandModel",{
		selectFirst : false,
		formatItem : ACformatItem,
		formatResult : ACformatResult,
		max:50,
		width:156,
		scrollHeight:350,
		extraParams: {
	       	id_brand: function() { return $("#id_brand").val(); }
	   	}
	}).result(function(event, row) {
		
		$("#rightForm input[type=hidden][name=id_model]").remove();
		$("#rightForm input[type=hidden][name=id_brand]").remove();
	  	$("#rightForm").prepend("<input type='hidden' name='id_model' value='"+row[2]+"'>");
	  	$("#rightForm").prepend("<input type='hidden' name='id_brand' value='"+row[1]+"'>");
	  	getYears(row[2]);
	  	submitRightForm();
	});
})

function ACformatItem(row) {
	return row[0];
}
function ACformatResult(row) {
	
	return row[0];
}

function clearModel(){
	$("#modelTxt").val("");
	$("#rightForm input[type=hidden][name=id_model]").remove();
}
function clearYears(){
	$("#years").html("<option value=''>Vælg Model</option>");
}
function getModels(o){
	$.ajax({
		type : "POST",
		url : PATH.root+"ajax.php",
		data : "op=getModels&id_brand="+$(o).val(),
		success : function(rasp){
			$("#id_model").html(rasp);
		}
	});
}
function getYears(id_model){
	$.ajax({
		type : "POST",
		url : PATH.root+"ajax.php",
		data : "op=getYears&id_model="+id_model,
		success : function(rasp){
			$("#years").html(rasp);
		}
	});
}
function shortOrder(){
	$("#act").val("short_order");
	$("#rightForm").attr("action",PATH.root);
	$("#rightForm").submit();
}
function submitRightForm(){
	 $("#rightForm").submit();
}
