function FillTypeList(){ 
//This function is used to fill the type list on load
addOption(document.drop_list.Type, "Hobby", "Hobby", "");
addOption(document.drop_list.Type, "Carbon Steel", "Carbon Steel", "");
addOption(document.drop_list.Type, "Bi-Metal", "Bi-Metal", "");
addOption(document.drop_list.Type, "Meat & Fish", "Meat & Fish", "");
addOption(document.drop_list.Type, "Band Knife", "Band Knife", "");
}

function GetLength(){
//On selection of TPI, check length text field and get dets if not empty
if (parseFloat(document.drop_list.length.value)>0){
	ShowDets();
}
// Move focus to length text box
document.drop_list.length.focus();
}

function SelectWidth(){
//On entry of length, this function will work
if(document.drop_list.Teeth.selectedIndex!=0){ //Clear previous details
	document.drop_list.Teeth.selectedIndex=0;
	ShowDets();
}
removeAllOptions(document.drop_list.Teeth);
addOption(document.drop_list.Teeth,"","","");
removeAllOptions(document.drop_list.Width);
addOption(document.drop_list.Width,"","Select Width","");

if(document.drop_list.Type.value == 'Hobby'){
addOption(document.drop_list.Width,"3/16", "3/16");
addOption(document.drop_list.Width,"1/4", "1/4");
addOption(document.drop_list.Width,"3/8", "3/8");
addOption(document.drop_list.Width,"1/2", "1/2");
addOption(document.drop_list.Width,"5/8", "5/8");
}
if(document.drop_list.Type.value == 'Carbon Steel'){
addOption(document.drop_list.Width,"1/8", "1/8");
addOption(document.drop_list.Width,"3/16", "3/16");
addOption(document.drop_list.Width,"1/4", "1/4");
addOption(document.drop_list.Width,"3/8", "3/8");
addOption(document.drop_list.Width,"1/2", "1/2");
addOption(document.drop_list.Width,"5/8", "5/8");
addOption(document.drop_list.Width,"3/4", "3/4");
addOption(document.drop_list.Width,"1", "1");
addOption(document.drop_list.Width,"1.1/4", "1.1/4", "");
}
if(document.drop_list.Type.value == 'Bi-Metal'){
addOption(document.drop_list.Width,"1/4", "1/4");
addOption(document.drop_list.Width,"3/8", "3/8");
addOption(document.drop_list.Width,"1/2", "1/2");
addOption(document.drop_list.Width,"3/4", "3/4");
addOption(document.drop_list.Width,"1", "1");
addOption(document.drop_list.Width,"1.1/4", "1.1/4", "");
addOption(document.drop_list.Width,"1.1/2", "1.1/2", "");
addOption(document.drop_list.Width,"2", "2");
}
if(document.drop_list.Type.value == 'Meat & Fish'){
addOption(document.drop_list.Width,"1/2", "1/2");
addOption(document.drop_list.Width,"5/8", "5/8");
addOption(document.drop_list.Width,"3/4", "3/4");
}
if(document.drop_list.Type.value == 'Band Knife'){
addOption(document.drop_list.Width,"3/8", "3/8");
addOption(document.drop_list.Width,"1/2", "1/2");
addOption(document.drop_list.Width,"5/8", "5/8");
addOption(document.drop_list.Width,"3/4", "3/4");
addOption(document.drop_list.Width,"1", "1");
}

}
////////////////// 

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}

function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}
//Function to return the XML Http object
function getXMLHTTP() 
{ 
  var xmlhttp=false;	
  try {
  	xmlhttp=new XMLHttpRequest();
  }
  catch(e) {		
  	try {			
  		xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
  	}
  	catch(e){
  		try {
  			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  		}
  		catch(e1){
  			xmlhttp=false;
  		}
  	}
  }
  return xmlhttp;
}

function SelectTPI()//TypeId, WidthId
{		
  if(document.drop_list.Teeth.selectedIndex!=0){ //Clear previous details
  	document.drop_list.Teeth.selectedIndex=0;
  	ShowDets(document.drop_list.Teeth);
  }
  var strURL="BsawsTpi.php?Type="+document.drop_list.Type.selectedIndex+"&Width="+document.drop_list.Width.value+"&sid="+Math.random();
  var req = getXMLHTTP();

  if (req) {
  	req.onreadystatechange = function() {
    	if (req.readyState == 4) {
    		// only if "OK"
    		if (req.status == 200) {						
    			document.getElementById('tpidiv').innerHTML=req.responseText;						
    		} else {
    			alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    		}
    	}
    }			
  	req.open("GET", strURL, true);
  	req.send(null);
  }
}

function ShowDets()
{		
  var tpidrop=document.drop_list.Teeth;
  var si=tpidrop.selectedIndex;
  var mm="in";
  if (document.drop_list.units[1].checked){
  	mm="mm";
  }
  var strURL="BsawsDets.php?Type="+document.drop_list.Type.selectedIndex+"&Width="+document.drop_list.Width.value+"&TPI="+tpidrop.options[si].text+"&Length="+document.drop_list.length.value+"&Units="+mm+"&sid="+Math.random();
  var req = getXMLHTTP();

  if (req) {
  	req.onreadystatechange = function() {
    	if (req.readyState == 4) {
    		// only if "OK"
    		if (req.status == 200) {						
    			document.getElementById('detsdiv').innerHTML=req.responseText;						
    		} else {
    			alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    		}
    	}
    }			
  	req.open("GET", strURL, true);
  	req.send(null);
  }
}

function GetResults(){
	ShowDets();
	return false;
}
