/* Cartridge Finder - START */

var ajax = new sack();

function showLoadingMsg() {
	document.forms['cartridgeSelect'].dyn_select2.options[0] = new Option('Loading...','');
}

function clearSubSelects() {
	document.getElementById('dyn_select2').options.length = 0;
	/*document.getElementById('dyn_select3').options.length = 0;*/
}

function initMenus() {
	document.getElementById('dyn_select2').disabled = true;
	document.getElementById('submit_cf').disabled = true;
	/*document.getElementById('dyn_select3').disabled = true;*/
}

function getSelect2(sel, URLpath) {
	var sel2Code = sel.options[sel.selectedIndex].value;
	document.getElementById('cat').value = sel2Code;
	document.getElementById('dyn_select2').disabled = false;
	document.getElementById('dyn_select2').options.length = 0;	// Empty second select box
	if(sel2Code.length > 0){
		ajax.onLoading = showLoadingMsg;
		ajax.onLoaded = clearSubSelects;
		ajax.requestFile = URLpath+'/ajax_categories.class.php?type=cats&sel2Code='+sel2Code+'&code='+sel2Code+'&displaytxt=Choose%20Printer%20Model';	// Specifying which file to get
		ajax.onCompletion = createSelect2;	// Specify function that will be executed after file has been found
		ajax.runAJAX();						// Execute AJAX function
	}
}

function createSelect2() {
	var obj = document.getElementById('dyn_select2');
	eval(ajax.response);	// Executing the response from Ajax as Javascript code	
}

function getSelect3(sel, URLpath) {
	var sel3Code = sel.options[sel.selectedIndex].value;
	document.getElementById('cat').value = sel3Code;
	document.getElementById('dyn_select3').disabled = false;
	document.getElementById('dyn_select3').options.length = 0;	// Empty third select box
	if(sel3Code.length > 0){
		ajax.requestFile = URLpath+'/ajax_categories.class.php?type=cats&sel3Code='+sel3Code+'&code='+sel3Code+'&displaytxt=Choose%20Printer%20Model';	// Specifying which file to get
		ajax.onCompletion = createLocal;	// Specify function that will be executed after file has been found
		ajax.runAJAX();						// Execute AJAX function
	}
}

function submitFinalCatID(sel) {
	var sel4Code = sel.options[sel.selectedIndex].value;
	document.getElementById('cat').value = sel4Code;
}
//
function createStepImage(stepNum, URLpath) {
	if (stepNum == 1) {
		document.getElementById('step1img').innerHTML = '<img src="'+URLpath+'/images/cf-step_one-sel.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		document.getElementById('step2img').innerHTML = '<img src="'+URLpath+'/images/cf-step_two.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		document.getElementById('step3img').innerHTML = '<img src="'+URLpath+'/images/cf-step_three.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		/*document.getElementById('step4img').innerHTML = '<img src="'+URLpath+'/images/cf-step_four.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';*/
	}
	if (stepNum == 2) {
		document.getElementById('step1img').innerHTML = '<img src="'+URLpath+'/images/cf-step_one.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		document.getElementById('step2img').innerHTML = '<img src="'+URLpath+'/images/cf-step_two-sel.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		document.getElementById('step3img').innerHTML = '<img src="'+URLpath+'/images/cf-step_three.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		/*document.getElementById('step4img').innerHTML = '<img src="'+URLpath+'/images/cf-step_four.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';*/
	}
	if (stepNum == 3) {
		document.getElementById('step1img').innerHTML = '<img src="'+URLpath+'/images/cf-step_one.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		document.getElementById('step2img').innerHTML = '<img src="'+URLpath+'/images/cf-step_two.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		document.getElementById('step3img').innerHTML = '<img src="'+URLpath+'/images/cf-step_three-sel.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		/*document.getElementById('step4img').innerHTML = '<img src="'+URLpath+'/images/cf-step_four.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';*/
		document.getElementById('submit_cf').disabled = false;
	}
	if (stepNum == 4) {
		document.getElementById('step1img').innerHTML = '<img src="'+URLpath+'/images/cf-step_one.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		document.getElementById('step2img').innerHTML = '<img src="'+URLpath+'/images/cf-step_two.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		document.getElementById('step3img').innerHTML = '<img src="'+URLpath+'/images/cf-step_three.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';
		/*document.getElementById('step4img').innerHTML = '<img src="'+URLpath+'/images/cf-step_four-sel.png" height="30" width="34" border="0" style="margin: 0px 5px;" />';*/
	}
}

function createSelectorToolTitle(elem) {
	document.getElementById('selectorToolTitle').innerHTML = elem;
}

function selectorToolMenu(elemType, URLpath) {
	if (elemType == "ink") {
		document.getElementById('selectorToolMenu').innerHTML = '<a href="'+URLcurrent+'?prodtype=toner&code=1" class="cf_shopfor_text">Toner</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=copier&code=2813" class="cf_shopfor_text">Copier</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=drum&code=1017" class="cf_shopfor_text">Drum</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=solidink&code=1291" class="cf_shopfor_text">Solid Ink</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=paper&code=3648" class="cf_shopfor_text">Paper</a>';
		createSelectorToolTitle('Ink Cartridge');
	} else if (elemType == "toner") {
		document.getElementById('selectorToolMenu').innerHTML = '<a href="'+URLcurrent+'?prodtype=ink&code=1310" class="cf_shopfor_text">Ink</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=copier&code=2813" class="cf_shopfor_text">Copier</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=drum&code=1017" class="cf_shopfor_text">Drum</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=solidink&code=1291" class="cf_shopfor_text">Solid Ink</a> | ' +		
		'<a href="'+URLcurrent+'?prodtype=paper&code=3648" class="cf_shopfor_text">Paper</a>';
		createSelectorToolTitle('Toner Cartridge');
	} else if (elemType == "paper") {
		document.getElementById('selectorToolMenu').innerHTML = '<a href="'+URLcurrent+'?prodtype=ink&code=1310" class="cf_shopfor_text">Ink</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=toner&code=1" class="cf_shopfor_text">Toner</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=copier&code=2813" class="cf_shopfor_text">Copier</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=drum&code=1017" class="cf_shopfor_text">Drum</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=solidink&code=1291" class="cf_shopfor_text">Solid Ink</a>';
		createSelectorToolTitle('Paper Supplies');
	} else if (elemType == "copier") {
		document.getElementById('selectorToolMenu').innerHTML = '<a href="'+URLcurrent+'?prodtype=ink&code=1310" class="cf_shopfor_text">Ink</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=toner&code=1" class="cf_shopfor_text">Toner</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=drum&code=1017" class="cf_shopfor_text">Drum</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=solidink&code=1291" class="cf_shopfor_text">Solid Ink</a>';
		createSelectorToolTitle('Copier Toner');
	} else if (elemType == "drum") {
		document.getElementById('selectorToolMenu').innerHTML = '<a href="'+URLcurrent+'?prodtype=ink&code=1310" class="cf_shopfor_text">Ink</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=toner&code=1" class="cf_shopfor_text">Toner</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=copier&code=2813" class="cf_shopfor_text">Copier</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=solidink&code=1291" class="cf_shopfor_text">Solid Ink</a>';
		createSelectorToolTitle('Printer Drum');
	} else if (elemType == "solidink") {
		document.getElementById('selectorToolMenu').innerHTML = '<a href="'+URLcurrent+'?prodtype=ink&code=1310" class="cf_shopfor_text">Ink</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=toner&code=1" class="cf_shopfor_text">Toner</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=copier&code=2813" class="cf_shopfor_text">Copier</a> | ' +
		'<a href="'+URLcurrent+'?prodtype=drum&code=1017" class="cf_shopfor_text">Drum</a>';
		createSelectorToolTitle('Solid Ink');
	}
}

function createLocal() {
	var obj = document.getElementById('dyn_select3');
	eval(ajax.response);	// Executing the response from Ajax as Javascript code	
}

/* Cartridge Finder - END */
