

// Search Paramater States

var AD_CLASS = 'BIKE';
var TYPE = 'USED';
var CAT_ID = 0;
var STY_ID = 0;



function initSearch(categoryID) {
	
	// Get Category List
	getCategory(categoryID);
	
	/*
	if (categoryID > 0) {
		selectValue('G', categoryID);
	}
	*/
};



//***************************************************
// Get Category List
//***************************************************
function getCategory(selectMe) {
	var obj = document.getElementById('G');
	// disable selection box
	obj.disabled = true;
	// Empty select box
	obj.options.length = 0;
	obj.options[obj.options.length] = new Option('>>LOADING<<','0');

	var index = ajax.length;
	ajax[index] = new sack();	
	ajax[index].requestFile = '/modules/ajax/getCategoryList.php';
	ajax[index].onCompletion = function(){ createCategoryList(index,selectMe) };
	ajax[index].runAJAX();

};

function createCategoryList(index,selectMe) {
	var obj = document.getElementById('G');
	eval(ajax[index].response);
	// Enable select box
	obj.disabled = false;
	obj.options[0] = null;
	
	// Select the Category on page-load
	if (selectMe > 0 || selectMe == 'PART') {
		selectValue('G', selectMe);
	}
	

	// set type
	//TYPE = obj.options[obj.selectedIndex].value;
	//alert(obj.options[obj.selectedIndex].value);
	
	getType();

};


function resetSearch() {

	var obj = object('TY');
	obj.options.length = 0;
	obj.options[obj.options.length] = new Option('New + Used','');

	obj = object('S');
	obj.options.length = 0;
	obj.options[obj.options.length] = new Option('Any Style','0');
	
	obj = object('P').value = '';

}




//***************************************************
// Get Type List
//***************************************************
function getType() {

	// What Category have they chosen?
	sel = object('G');
	var selection = sel.options[sel.selectedIndex].value;
	
	

	if (selection == "ALL") {
		AD_CLASS = 'ALL';
		CAT_ID = 'ALL';
	} else if (selection == "PART") {
		AD_CLASS = 'PART';
		CAT_ID = 'ALL';
	} else {
		AD_CLASS = 'BIKE';
		CAT_ID = selection;
	}
	
	object('C').value = CAT_ID;
	object('CL').value = AD_CLASS;
	
	// reset search form
	//if (CAT_ID == 'ALL') { resetSearch(); return; }
	
	var obj = object('TY');
	// disable selection box
	obj.disabled = true;
	// Empty select box
	obj.options.length = 0;
	obj.options[obj.options.length] = new Option('>>LOADING<<','0');

	//alert('/modules/ajax/getTypes.php?CL='+AD_CLASS+'&C='+CAT_ID);

	var index = ajax.length;
	ajax[index] = new sack();	
	ajax[index].requestFile = '/modules/ajax/getTypes.php?CL='+AD_CLASS+'&C='+CAT_ID;
	
	//alert('/modules/ajax/getTypes.php?AD_CLASS='+AD_CLASS+'&C='+CAT_ID);
	
	ajax[index].onCompletion = function(){ createTypeList(index) };
	ajax[index].runAJAX();

};

function createTypeList(index) {
	var obj = document.getElementById('TY');
	eval(ajax[index].response);
	// Enable select box
	obj.disabled = false;
	obj.options[0] = null;
	

	// set type
	TYPE = obj.options[obj.selectedIndex].value;
	//alert(obj.options[obj.selectedIndex].value);
	
	getStyle();

};




//***************************************************
//                  GET STYLE
//***************************************************

function getStyle() {
	
	// Update Type var
	sel = object('TY');
	TYPE = sel.options[sel.selectedIndex].value;
	

	var obj = document.getElementById('S');

	// disable selection box
	obj.disabled = true;
	
	// Empty select box
	obj.options.length = 0;
	obj.options[obj.options.length] = new Option('>>LOADING<<','1');
	
	//alert('/modules/ajax/getStyleList.php?C='+CAT_ID+'&T='+TYPE+'&CL='+AD_CLASS);
	
	var index = ajax.length;
	ajax[index] = new sack();	
	ajax[index].requestFile = '/modules/ajax/getStyleList.php?C='+CAT_ID+'&T='+TYPE+'&CL='+AD_CLASS;
	ajax[index].onCompletion = function(){ createStyleList(index) };
	ajax[index].runAJAX();
	
};

function createStyleList(index) {
	
	var obj = document.getElementById('S');

	// Executing the response from Ajax as Javascript code
	eval(ajax[index].response);
		
	// Enable select box
	obj.disabled = false;
	obj.options[0] = null;

	// set style
	//STY_ID = obj.options[obj.selectedIndex].value;

	

};



