// JavaScript Document

var state = 'none';

/* Test for Javascript by running this */
function test_js() {
	ShowContent('q_model', 'table-row');
/* If Javascript isn't working then the first question won't show so nothing will */
}

function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d, type) { 
	if(d.length < 1) { return; }
	if(!type) {	type = "table-cell"	}
	if(document.all){ document.getElementById(d).style.display = "block"; } 
	else { document.getElementById(d).style.display = type;	}
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
	else { document.getElementById(d).style.display = "none"; }
}


/* get the selected option value */
function getOption(myselect) {
	for (var i=0; i<myselect.options.length; i++){
		if (myselect.options[i].selected==true){
			break;
		}
	}
	return myselect.options[i].value;
}

/* Determine which waste ink kit(s) are best for this model */
function wibs2go() {
	/* Setup vars to use for determining display */
	wbags = wboxes = solo = solol = duo = "";

	model = getOption(document.forms[1].pmodel);	// 0, 1=>solo, 2=>sololong, 3=>duo
	workload = getOption(document.forms[1].pworkload);
	place = getOption(document.forms[1].pplace);
	vital = getOption(document.forms[1].pvital);
	if(document.forms[1].palloptions.checked==true) {
		alloptions = document.forms[1].palloptions.value;
	} else {
		alloptions = 0;
	}
	
	if(workload >= 3) {
		wboxes = 1
		wbags = 0
	}
	else {
		wbags = 1
		wboxes = 0
	}
	if(place == 2 && model != 3) {
		solo = 0
		solol = 1
	}
	if(vital == 2) {
		wbags = 0
		wboxes = 1
	}
	else if(vital == 1 && workload < 3) {
		wbags = 1
		wboxes = 0
	}
	if(alloptions == 1) {
		wbags = 1
		wboxes = 1
	}
	
	if(model == 0) {
		wbags = wboxes = solo = solol = duo = 0;
		// Hide the other questions and set to null
		HideContent('q_workload')
		HideContent('q_place')
		HideContent('q_vital')
		HideContent('q_alloptions')
		
	}
	else if(model >= 1) {
		// Show the next questions
		ShowContent('q_workload','table-row')
		ShowContent('q_place','table-row')
		ShowContent('q_vital','table-row')
		ShowContent('q_alloptions','table-row')
	
		// 0, 1=>solo, 2=>sololong, 3=>duo
		switch(model) {
			case "1":
				if(solo == "0") {
					solol = 1;
					solo = 0;
				} else if(alloptions == "1") {
					solol = solo = 1;
				} else {
					solo = 1;
					solol = 0;
				}
				duo = 0;
				break;
				
			case "2":
				duo = 0;
				solo = 0;
				solol = 1;
				break;
			
			case "3":
				solo = solol = 0;
				duo = 1;
				break;
		}
	}
	
	/* figure out what to display now */
	if(wbags === 0){
		HideContent('wibkits');
	} else {
		ShowContent('wibkits', 'table-row')
		if(solo === 1) {
			ShowContent('wibsolo')
		} else {
			HideContent('wibsolo')
		}
		if(solol === 1) {
			ShowContent('wibsolol')
		} else {
			HideContent('wibsolol')
		}
		if(duo === 1) {
			ShowContent('wibduo')
		} else {
			HideContent('wibduo')
		}
	}
	if(wboxes === 0){
		HideContent('wiboxkits');
	} else {
		ShowContent('wiboxkits', 'table-row')
		if(solo === 1) {
			ShowContent('wiboxsolo')
		} else {
			HideContent('wiboxsolo')
		}
		if(solol === 1) {
			ShowContent('wiboxsoll')
		} else {
			HideContent('wiboxsoll')
		}
		if(duo === 1) {
			ShowContent('wiboxduo')
		} else {
			HideContent('wiboxduo')
		}
	}
}
