$(document).ready(function(){
	ajax_init_sel('select.offer');
});

function ajax_init_sel(domChunk){
	$(domChunk).change(function(){
	var s = SID;
	var m = currentMODEL;
	var v = document.getElementById('VERSION').options[document.getElementById('VERSION').selectedIndex].value;
	var c = null;
	getCategories (s, m, v, c);
	return false;
	});
}

function getCategories (s, m, v, c)
{
	m = (m==undefined) ? null : m;
	v = (v==undefined) ? null : v;
	c = (c==undefined) ? null : c;
	var q='SID=' + s + '&MODEL=' + m + '&VERSION=' + v + '&CATEGORY=' + c;
	
	$.get("./../categorylist.php/", q, function(data){
		$("#categorylist").html(data);
	});
	
	getPartList (s, m, v, c, null);
}

function getPartList (s, m, v, c, page)
{
	m = (m==undefined) ? null : m;
	v = (v==undefined) ? null : v;
	c = (c==undefined) ? null : c;
	var q='SID=' + s + '&MODEL=' + m + '&VERSION=' + v + '&CATEGORY=' + c;
	
	if (page)
	{
		q= q + '&PAGE=' + page;
	}
	
	$.get("./../partlist.php/", q, function(data){
		$("#part").html(data);
	});
}

function getPart (s, c, p, page)
{
	c = (c==undefined) ? null : c;
	p = (p==undefined) ? null : p;
	var q='SID=' + s + '&CATEGORY=' + c + '&PART=' + p;

	if (page)
	{
		q= q + '&PAGE=' + page;
	}
	
	$.get("./../part.php/", q, function(data){
		$("#part").html(data);
	});
}

function addToQuery (s, m, v, c, p, page)
{
	q = 'SID='+s+'&CATEGORY='+c+'&PART='+p+'&PAGE='+page+'&ADD';
	$.get("./../query.php/", q, function(data){
		$("#part").html(data)
	});
}

function addToQueryFromPart (s, m, v, c, p, page)
{
	q = 'SID='+s+'&CATEGORY='+c+'&PART='+p+'&PAGE='+page+'&ADDFROMPART';
	$.get("./../query.php/", q, function(data){
		$("#part").html(data)
	});
}

