function showDiv(strDivName) {
    
    eval('document.getElementById("'+strDivName+'").style.visibility="visible"');
    eval('document.getElementById("'+strDivName+'").style.display="inline"');
}

function hideDiv(strDivName) {
    eval('document.getElementById("'+strDivName+'").style.visibility="hidden"');
    eval('document.getElementById("'+strDivName+'").style.display="none"');
}
	
function checkField(FormName, FieldName, DispName){
	if (eval(FormName + "." + FieldName + ".value.length") <= 0 ){
		alert("Please fill in the "+ DispName +" field.");
		eval(FormName + "." + FieldName + ".focus();"); 
		return false;
	}
	else
		return true;
}
	
function CheckWholeForm(theForm){
		var bRadioChecked;
		var bCheckChecked;
		var sElementGroupName;
		var theElement;
		var focusElement;

		// loop through all elements on form
		for (var iElement = 0; iElement < theForm.length;iElement++){  
			theElement = theForm[iElement];
	  		
			if (theElement.type == "text"){				
				if (theElement.value == ""){
					alert("One of your Text Questions is not answered");
					theElement.focus();
					theElement.select();
					return false;
			 	}
			}
		  
			else if (theElement.type == "radio"){
				bRadioChecked = false;
				sElementGroupName = theElement.name;
				focusElement = theElement;
				while (theElement.name == sElementGroupName){
					if (theElement.checked == true){
						bRadioChecked = true;
					}
					iElement++;
					theElement = theForm[iElement];
				}

				if (bRadioChecked == false){
					alert("One of your True/False, Yes/No, or On/Off Questions is not answered");
					focusElement.focus();
					focusElement.select();
					return false;
			 	}
				iElement--;
			}
			else if (theElement.type == "checkbox") {
				bCheckChecked = false;
				sElementGroupName = theElement.name;
				focusElement = theElement;
				while (theElement.name == sElementGroupName){
					if (theElement.checked == true){
						bCheckChecked = true;
					}
					iElement++;
					theElement = theForm[iElement];
				}

				if (bCheckChecked == false){
					alert("One of your Multiple Choice Questions is not answered");
					focusElement.focus();
					focusElement.select();
					return false;
				}
				iElement--;
			
			}
			else if (theElement.type == "select-one"){
				if (theElement.selectedIndex == ""){
					alert("One of your Drop Down Questions is not answered");
					theElement.focus();
					theElement.selectedIndex = 0;
					return false;
			 	}
		}
	}
	return true;
}  

function formatCurrency(nCurrencyIn) {
	var sign;	
	var cents;
	
	//take out any current dollar signs and what not
	nCurrencyIn = nCurrencyIn.toString().replace(/\$|\,/g,'');
	
	//check if it still a number
	if(isNaN(nCurrencyIn)){
		nCurrencyIn = "0";
		return nCurrencyIn;
	}
		
	sign			= (nCurrencyIn == (nCurrencyIn = Math.abs(nCurrencyIn)));
	nCurrencyIn		= Math.floor(nCurrencyIn * 100 + 0.50000000001);
	cents			= nCurrencyIn % 100;
	nCurrencyIn		= Math.floor(nCurrencyIn / 100).toString();
	
	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((nCurrencyIn.length - (1 + i)) / 3); i++)
		nCurrencyIn = nCurrencyIn.substring(0,nCurrencyIn.length - (4 * i + 3)) + ',' + nCurrencyIn.substring(nCurrencyIn.length - (4 * i + 3));
	
	return (((sign) ? '':'-') + nCurrencyIn + '.' + cents);
}

function validateNumeric(obj){
	if (isNaN(obj.value)){
		alert('Sorry this is not a correct value. Please enter a valid number');
		obj.value = '';
		obj.focus();
		return false;
	}
}

function validateMaxLen(obj, maxLen) {
	if (obj.value.length > maxLen) {
		alert('Sorry this is not a correct value.  Please enter a maximum of ' + maxLen + ' characters.');
		obj.focus();
		return false;
	}
}

function Convert_lbs_to_kg(obj){
	obj.value = formatCurrency((obj.value / 2.204623));
}

function Convert_kg_to_lbs(obj){
	obj.value = formatCurrency((obj.value * 2.204623));
}

function Convert_in_to_cm(obj){
	obj.value = formatCurrency((obj.value * 2.54));
}

function Convert_cm_to_in(obj){
	obj.value = formatCurrency((obj.value / 2.54));
}

function checkMemoInput(obj){
	if (obj.value.length > 2000) {
		alert('You must keep your Description under 2000 characters');
		obj.focus();
	}

}

var isFocused = 0;

function checkTwoDigit(obj){
	if (obj.value.length < 2){
		alert('Please enter in atleast 2 numeric digits');
		
		if (isFocused == 1){
			isFocused = 0;
		}
		else {
			isFocused = 1;
			obj.focus();
		}
	}
}

function validateRange(obj, minVal, maxVal) {
	return validateRangeWithMessage(obj, minVal, maxVal, 'Sorry this is not a correct value.  Please enter a number between ' + minVal + ' and ' + maxVal + '.');
}

function validateRangeWithMessage(obj, minVal, maxVal, errMsg) {
	if ((obj.value.length > 0) && (isNaN(obj.value) || (obj.value < minVal) || (obj.value > maxVal))) {
		alert(errMsg);
		obj.focus();
		return false;
	}
	return true;
}
