function showTextBox(myIndex){
	if (myIndex==3){
		document.getElementById("pctTxt").style.visibility="visible";
	}
	else{
		document.getElementById("pctTxt").style.visibility="hidden";
	}
}//showTextBox

function clearBoxes(myForm){
	myForm.costTxt.value='';
	myForm.pctSel.selectedIndex=0;
	document.getElementById("pctTxt").style.visibility="hidden";
	document.getElementById("result").style.display="none";
}

function doCalc(myForm){
	var cost=document.getElementById("costTxt").value;
	if (cost==null || isNaN(cost) || cost=="" || cost<=0){
		alert("Please enter a valid meal cost.");
		document.getElementById("costTxt").value='';
		return;
	}//if
	else{
		var cost=parseFloat(document.getElementById("costTxt").value);
	}//else

	var index=myForm.pctSel.selectedIndex;

	if (index==0){
		alert("Please choose a percentage.");
		return;
	}

	if (index==1){
		var perc=0.1;
	}
	if (index==2){
		var perc=0.2;
	}
	if (index==3){
		var pctval=document.getElementById("pctTxt").value;
		if (pctval>100 || pctval<1){
			alert("Please enter a value between 1 and 100");
			document.getElementById("pctTxt").value='';
			return;
		}//if
		if (pctval==null || isNaN(pctval) || pctval==""){
			alert("Please enter a valid percentage (1-100).");
			document.getElementById("pctTxt").value='';
			return;
		}
		else{
			var perc=parseFloat((pctval)/100);
		}
	}//if

	var prod=cost*perc;
	var tip=prod.toFixed(2);
	var total=(parseFloat(cost) + parseFloat(tip)).toFixed(2);

	document.getElementById("result").style.display="block";
	document.getElementById("cost_result").innerHTML="Your meal cost is: $" + cost;
	document.getElementById("tippct_result").innerHTML="Your gratuity percentage is: " + perc*100 + "%";
	document.getElementById("tipamt_result").innerHTML="Your gratuity dollar amount is: $" + tip;
	document.getElementById("total_result").innerHTML="Your TOTAL is: $" + total;


}//calculate
