function isNumber(strData)
{
    if( strData && strData.search(/[^0-9]/) != -1) {
         return false;
    } else {
         return true;
    }
}

function validateForm (formName) {

	//set variables
	//to field
	var tempIndex = document.forms[formName].toopts.selectedIndex;
	if (tempIndex==-1) {
		var to = "error";
	} else {
		var to = document.forms[formName].toopts.options[tempIndex].value;
	}
	//from field
	tempIndex = document.forms[formName].fromopts.selectedIndex;
	if (tempIndex==-1) {
		var from = "error";
	} else {
		var from = document.forms[formName].fromopts.options[tempIndex].value;
	}
	//unittype
	var unittype = document.forms[formName].unittype.value;
	//qty
	var qty = document.forms[formName].qty.value;
	//error msg
	var badNumberFormat = qty + " is not valid. Your quantity must be in the form of a positive integer, decimal, or fraction.";
	
	//WHEN TEMPERATURE IS BEING USED, MAKE SURE THIS WORKS
	//check rankine and kelvin first since they have special cases
	if (from=="tempR" || from=="tempK") {
		//if nothing entered, assume 0 if possible, otherwise assume 1
		if (qty==null) {
			document.forms[formName].qty.value=0;
		} else if (qty < 0) {
			//if a negative number is entered for these 2 units, use special error
			if (from=="tempR") {
				alert("Sorry, degrees Rankine cannot be negative.");
			} else {
				alert("Sorry, degrees Kelvin cannot be negative.");
			}
		} else if (isNaN(qty)) {
			//else if what was entered is not a number, use special alert msg
			alert(qty + " is not valid. Your quantity must be in the form of a positive integer.");
			return false;
		}
	//now, if it's other temps that can be negative
	} else if (unittype=="temperature") {
		//if nothing entered, assume 0 if possible, otherwise assume 1
		if (qty==null) {
			document.forms[formName].qty.value=0;
		} else if (isNaN(qty)) {
			//else if what was entered is not a number, use special alert msg
			alert(qty + " is not valid. Your quantity must be in the form of a positive or negative integer or decimal.");
			return false;
		}
	
	//WITH TEMPERATURE COMMENTED OUT, VALIDATION IS STARTING HERE
	//now, check units other than temperature
	//if user does not enter something	
	} else if (qty==null || qty==0) {
		return true;
	} else if (qty.indexOf('-')!=-1) {
		//if they have entered a negative number
		alert(badNumberFormat);
		return false;
	} else if (isNaN(qty)) {
		//if qty is not a number, make sure it's not a fraction before doing error msg
		//check for fraction by looking for a '/'
		if (qty.indexOf('/')!=-1) {
			var tempQty = qty.split('/');
			//if 1 slash was found, continue; otherwise give error msg
			if (tempQty.length == 2) {
				//if both sides of the '/' are numbers and not 0
				if ((isNumber(tempQty[0]) && tempQty[0]!=0 && tempQty[0].indexOf('.')==-1 && tempQty[0].indexOf('-')==-1) && (isNumber(tempQty[1]) && tempQty[1]!=0 && tempQty[1].indexOf('.')==-1 && tempQty[1].indexOf('-')==-1)) {
				//this number is an acceptable fraction
				} else {
					alert(badNumberFormat);
					return false;
				}
			} else {
				alert(badNumberFormat);
				return false;
			}	
		} else {
			alert(badNumberFormat);
			return false;
		}
	} //if it's a number just let is pass
	
		
	//check if values are set for the to, from, and if so, whether they equal each other
	if (from=="error") {
		alert("You forgot to choose a unit to convert from.");
		return false;
	} else if (to=="error") {
		alert("You forgot to choose a unit to convert to.");
		return false;
	} else if (to==from) {
		alert("You have chosen the same unit in both columns.");
		return false;
	} else {
		return true;
	}

}
