sql1 = "SELECT * FROM ";
sql2 = " WHERE ";
current = 0;
func_val = "";
flowrate_val = "";
accuracy_val = "";
output_val = "";
fluid = "";
table_val = "biweb_vm_product_type_3";
czx = 0;
function lite(e) {

e.style.backgroundColor = "#B5B4B4";
}
function dim(e) {
e.style.backgroundColor = "#EBEBEB";
}
function step(n) {
var elm = document.forms[1].elements;
document.getElementById("functionTR").style.display = "none";
}
function viewresults(n) {
//alert(sql1 + table_val + sql2 + func_val + flowrate_val + accuracy_val + output_val, "output_resultcount");
n=n+1;
//alert(n);
	 if (n==1) {
  document.getElementById('sql').value = sql1 + table_val + sql2 + func_val;
 } else if (n==2) {
  document.getElementById('sql').value = sql1 + table_val + sql2 + func_val;
 } else if (n==3) {
  document.getElementById('sql').value = sql1 + table_val + sql2 + func_val + flowrate_val;
 } else if (n==4) {
  document.getElementById('sql').value = sql1 + table_val + sql2 + func_val + flowrate_val + accuracy_val;
 // alert(sql1 + table_val + sql2 + func_val + flowrate_val + accuracy_val);
 } else if (n==5) {
  document.getElementById('sql').value = sql1 + table_val + sql2 + func_val + flowrate_val + accuracy_val + output_val;
  // alert(sql1 + table_val + sql2 + func_val + flowrate_val + accuracy_val + output_val);
 }

 document.vr.submit();
}
function func(bool) {
//alert("x");
	current = 1;
	functionselect = document.getElementById("function");
	document.getElementById('funcvr').style.display="block";
	if (functionselect.selectedIndex == 0) {
		
	} else {
	func_val = "`Function` LIKE '%" + functionselect.options[functionselect.selectedIndex].value + "%' ";
	//document.getElementById("function_resultcount").innerHTML = 
	if (!bool) {
	ResCount(sql1 + table_val + sql2 + func_val,"function_resultcount");
	}
	document.getElementById("fluidtypeTR").style.display = "block";
	setstep(1);
	}
}
function fluidtype() {
	func("yo");
	document.getElementById("function").disabled = true;
	
	current = 2;
	fluidselect = document.getElementById("ftype");
	fluid = fluidselect.options[fluidselect.selectedIndex].value;
	table_val = "biweb_vm_product_type_" + fluid
	ResCount(sql1 + table_val + sql2 + func_val,"fluidtype_resultcount");
	if (fluid==1) {
	 document.getElementById("flowrateTR_gas").style.display = "block";
	 document.getElementById("flowrateTR_liquid").style.display = "none";
	} else if (fluid==2) {
	document.getElementById("flowrateTR_gas").style.display = "none";
	 document.getElementById("flowrateTR_liquid").style.display = "block";
	}
	setstep(2);
}
function setstep(n) {
//steps = document.getElementById("steps");

stepsa = document.getElementById("steps").getElementsByTagName("a");
for (var i = 0; i < stepsa.length; i++) {
	stepsa[i].className = "";
	
	if (i==n) {
	stepsa[i].className = "selected";
	}
}
}
function flowrate() {
document.getElementById("ftype").disabled = true;
	current = 3;
	if (fluid==1) {
		//gas
		v = getCheckedValue(document.forms[1].elements['maxGasFlow'])
		flowrate_val = " AND `fullscalecapacity` LIKE 'xenophobe" + v + "\%' ";
		ResCount(sql1 + table_val + sql2 + func_val + flowrate_val,"flowrate_gas_resultcount");
	
	} else if (fluid==2) {
		//liquid
		v = getCheckedValue(document.forms[1].elements['maxLiquidFlow'])
		flowrate_val = " AND `fullscalecapacity` LIKE 'xenophobe" + v + "\%' ";
		ResCount(sql1 + table_val + sql2 + func_val + flowrate_val,"flowrate_liquid_resultcount");
		
	}
	document.getElementById("accuracyTR").style.display = "block";
	setstep(3);
}
function accuracy() {
		if (fluid==1) {
		var e, i = 0;
  while (e = document.getElementsByName ('maxGasFlow')[i++]) {e.disabled = true}
		} else if (fluid==2) {
		var e, i = 0;
  while (e = document.getElementsByName ('maxLiquidFlow')[i++]) {e.disabled = true}
		}
		current = 4;
		accuracysql = " AND (";
		accratesql = " AND (";
		if (document.forms[1].elements["accuracy_1"].checked) {
			accuracysql += " accFullScale LIKE '%1%' OR";
		}
		if (document.forms[1].elements["accuracy_2"].checked) {
			accuracysql += " accFullScale LIKE '%2%' OR";
		}
		if (document.forms[1].elements["accuracy_3"].checked) {
			accuracysql += " accFullScale LIKE '%3%' OR";
		}
		if (document.forms[1].elements["accuracy_4"].checked) {
			accuracysql += " accFullScale LIKE '%4%' OR";
		}
		if (document.forms[1].elements["accuracy_5"].checked) {
			accuracysql += " accFullScale LIKE '%5%' OR";
		}
		if (document.forms[1].elements["accuracy_6"].checked) {
			accuracysql += " accFullScale LIKE '%6%' OR";
		}
		if (document.forms[1].elements["accRate_1"].checked) {
			accratesql += " accRate LIKE '%1%' OR";
		}
		if (document.forms[1].elements["accRate_2"].checked) {
			accratesql += " accRate LIKE '%2%'";
		}
		accuracysql += ") ";
		accratesql += ") ";
		
		if (accuracysql.indexOf("AND ()") >= 0) {
		accuracysql = "";
		}
		if (accratesql.indexOf(" AND ()") >= 0) {
		accratesql = "";
		}
		accuracysql = accuracysql.replace("OR)", ")");
		accratesql = accratesql.replace("OR)",")");
		accuracy_val = accuracysql + accratesql;
		ResCount(sql1 + table_val + sql2 + func_val + flowrate_val + accuracy_val, "accuracy_resultcount");


		document.getElementById("outputTR").style.display = "block";
		document.getElementById("sbm").disabled = true;
		setstep(4);
}
function output() {
		document.forms[1].elements["accuracy_1"].disabled = true;
		document.forms[1].elements["accuracy_2"].disabled = true;
		document.forms[1].elements["accuracy_3"].disabled = true;
		document.forms[1].elements["accuracy_4"].disabled = true;
		document.forms[1].elements["accuracy_5"].disabled = true;
		document.forms[1].elements["accuracy_6"].disabled = true;
		document.forms[1].elements["accRate_1"].disabled = true;
		document.forms[1].elements["accRate_2"].disabled = true;

	current = 5;
	output_select = document.getElementById("op");
	output_val =  " AND Output LIKE '%" + output_select.options[output_select.selectedIndex].value + "%' ";
	ResCount(sql1 + table_val + sql2 + func_val + flowrate_val + accuracy_val + output_val, "output_resultcount");
}
function next() {
 if (current==0) {
  func();
 } else if (current==1) {
  fluidtype();
 } else if (current==2) {
  flowrate();
 } else if (current==3) {
  accuracy();
 } else if (current==4) {
  output();
 }
}
function resetform(ark) {

document.getElementById("function").disabled = false;
document.getElementById("ftype").disabled = false;
if (fluid==1) {
var e, i = 0;
  while (e = document.getElementsByName ('maxGasFlow')[i++]) {e.disabled = false}
} else if (fluid==2) {
var e, i = 0;
  while (e = document.getElementsByName ('maxLiquidFlow')[i++]) {e.disabled = false}
}
	document.forms[1].elements["accuracy_1"].disabled = true;
		document.forms[1].elements["accuracy_2"].disabled = false;
		document.forms[1].elements["accuracy_3"].disabled = false;
		document.forms[1].elements["accuracy_4"].disabled = false;
		document.forms[1].elements["accuracy_5"].disabled = false;
		document.forms[1].elements["accuracy_6"].disabled = false;
		document.forms[1].elements["accRate_1"].disabled = false;
		document.forms[1].elements["accRate_2"].disabled = false;
		document.getElementById("sbm").disabled = false;
if (ark=="uo") {
document.getElementById("function_resultcount").innerHTML = "";
} else {
window.location.reload();
}


}
function ResCount(querystring, control){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		
		ajaxRequest = new XMLHttpRequest();
		 
	} catch (e){
		// Internet Explorer Browsers
		try{
		
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		   
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
	
		if(ajaxRequest.readyState == 4){
		
		//document.getElementById("jawn").innerHTML = querystring;
		
		document.getElementById(control).innerHTML = ajaxRequest.responseText + " results";
		
		}
	}
	//alert(querystring);
	//document.getElementById("jawn").innerHTML = querystring;
	ajaxRequest.open("GET", "qry.php?sql=" + querystring, true);
	//alert(querystring);
	ajaxRequest.send(null); 


}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}