
function candshow() {
	candpop = document.getElementById('candidatepop');
	candpop.style.zIndex=4;
	candpop.style.visibility='visible';
	candpop.style.width='375px';
	candpop.style.height='30px';
	candpop.style.display='block';
}
function candhide() {
	candpop = document.getElementById('candidatepop');
	candpop.style.zIndex=0;
	candpop.style.visibility='hidden';
	candpop.style.width='0px';
	candpop.style.height='30px';
	candpop.style.display='none';
}

function clieshow() {
	cliepop = document.getElementById('clientpop');
	cliepop.style.zIndex=4;
	cliepop.style.visibility='visible';
	cliepop.style.width='375px';
	cliepop.style.height='30px';
	cliepop.style.display='block';
}
function cliehide() {
	cliepop = document.getElementById('clientpop');
	cliepop.style.zIndex=0;
	cliepop.style.visibility='hidden';
	cliepop.style.width='0px';
	cliepop.style.height='30px';
	cliepop.style.display='none';
}


var xmlHttp;

function populate() {
	xmlHttp=GetXmlHttpObject(bearingtol)
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	tolerance_input = bearingtol.split("**");
	var outside_tol = tolerance_input[0];
	var inside_tol = tolerance_input[1];

	var url="option?sminpay="+inside_tol+"&outtol="+outside_tol+"&type="+porf+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("bearingtable").innerHTML=xmlHttp.responseText;
	} 
} 

function GetXmlHttpObject() {
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}


function digitonly(key) {
	if ( ((key > 47) && (key < 58)) || ((key > 36) && (key < 41)) || (key == 8) || (key == 46) || (key == 190) || (key == 116) || (key == 9) ){
		return true;
	} else {
		return false;
	}
}

function form_setup() {
	document.getElementById('bush_nominal_combined_tolerance_id').value = 's7--F7';
	document.getElementById('housing_bore_tolerance_id').value = 'E7';
	document.getElementById('shaft_diameter_tolerance_id').value = 'r6';
}


function threedp(value) { // shows trailing zeros to be clear that this is a maximum or minimum value to 3 decimal places
	process = String(Math.round(value * 1000));
	result = process.substr(0,process.length-3) + '.' + process.substr(process.length-3, 3);
	return result;
}


function digitonly(variable) {
	var dot = 0;
	var reformed = '';
	for (var z=0; z<variable.value.length; z++) {
		if ((variable.value.charAt(z) >= "0") && (variable.value.charAt(z) <= "9") || (variable.value.charAt(z) == ".")) {
			if (variable.value.charAt(z) == ".") {
				dot++;
				if (dot < 2) {
					reformed += variable.value.charAt(z);
				}
			} else {
				reformed += variable.value.charAt(z);
			}
		}
	}
	variable.value = reformed;
}	

function threedpb(value) { // shows trailing zeros to be clear that this is a maximum or minimum value to 3 decimal places
	var process = String(Math.round(value * 1000));
	if (value == '0') {
		var result = '0.000';
	} else if (process.substr(0,1) == '-') {
		while (process.length < 5) {
			process = process.substr(0,1) + '0' + process.substr(1,process.length-1);
		}
		var result = '-' + process.substr(1,process.length-4) + '.' + process.substr(process.length-3, 3);
	} else {
		while (process.length < 4) {
			process = '0' + process.substr(0,process.length);
		}
		var result = process.substr(0,process.length-3) + '.' + process.substr(process.length-3, 3);
	}
	return result;
}