function checkRadio(objradio, strcomment)
{
var flagcheck = 0;

	if (objradio[0]) // if array of more than 1 radio button
	{
		for (var i = 0; i < objradio.length; i++) 
		{
			if (objradio[i].checked == true)
			{
				flagcheck = 1;
			}
		}	
	}
	else // only 1 radio button
	{
		if (objradio.checked == true)
		{
			flagcheck = 1;
		}
	}
	
	if (flagcheck == 0)
	{
		strmsg = strmsg + "\n" + strcomment;
	}

	return(flagcheck);	
}

function clearRadio(objradio)
{
	for (var i = 0; i < objradio.length; i++) 
	{
		objradio[i].checked = false;
	}
	return(true);	
}

function getRadioValue(objradio)
{
var retValue = null;

	for (var i=0; i<objradio.length; i++)
	{
		if (objradio[i].checked)
		{
			retValue = objradio[i].value;
		}
	}
	return(retValue);
}

function checkSelect(objselect, strcomment)
{
var retValue = true;

	if ((objselect[objselect.selectedIndex].value == "") || (objselect[objselect.selectedIndex].value == " ") || (objselect[objselect.selectedIndex].value == "--"))
	{
		retValue = false;
		strmsg = strmsg + "\n" + strcomment;
	}
	return(retValue);
}

function checkSelectShowError(objselect, strcomment, strClassName, strClassNameError)
{
var retValue = true;

	if ((objselect[objselect.selectedIndex].value == "") || (objselect[objselect.selectedIndex].value == " ") || (objselect[objselect.selectedIndex].value == "--"))
	{
		retValue = false;
		strmsg = strmsg + "\n" + strcomment;
		objselect.className = strClassNameError;
	}
	else
	{
		objselect.className = strClassName;
	}
	return(retValue);
}

function checkYesOnly(yesbtn, radioBtn)
{
	if (!yesbtn.checked && radioBtn.checked)
	{
		radioBtn.checked = false;
		alert("This question is only valid if you answered 'Yes' to the previous question.\n");
	}
}

function checkCheckbox(frmObj, strStartName, intStartNum, intEndNum, intMinAnswers, intMaxAnswers, strcomment)
{
var flagcheck = 0;
var intCountAnswers = 0;

	for (var i = intStartNum; i <= intEndNum; i++) 
	{
	    if (eval("document." + frmObj.name + "." + strStartName + i + ".checked"))
		{
			++intCountAnswers;
		}
	}	

	if ((intCountAnswers >= intMinAnswers) && (intCountAnswers <= intMaxAnswers))
	{
		flagcheck = 1;
	}
	
	if (flagcheck == 0)
	{
		strmsg = strmsg + "\n" + strcomment;
	}

	return(flagcheck);
}

function clearCheckboxes(frmObj, strChkName, intStart, intEnd)
{
	for (i=intStart; i<=intEnd; i++)
	{
	    eval("document." + frmObj.name + "." + strChkName + i + ".checked = false");
	}
}

function digitsOnly(afield, lowerbound, upperbound)
{
var strText, thelength;

	strText = afield.value;
	thelength = strText.length;
	i = 0;
	while (i < thelength)
	{
		reg = /[0-9]/;
		if (reg.test(strText.substr(i,1)) == false)
		{
			strText = strText.substring(0, i) + strText.substring(i+1);
		}
		else
		{
			i = i + 1;
		}
		thelength = strText.length;
	}

	if (strText > "")
	{
		if ((parseFloat(strText) < lowerbound) || (parseFloat(strText) > upperbound))
		{
			strText = "";
		}
	}
	afield.value = strText;
}

function numericOnly(afield, lowerbound, upperbound)
{
var strText, thelength;

	strText = afield.value;
	thelength = strText.length;
	i = 0;
	while (i < thelength)
	{
		reg = /[0-9\.]/;
		if (reg.test(strText.substr(i,1)) == false)
		{
			strText = strText.substring(0, i) + strText.substring(i+1);
		}
		else
		{
			i = i + 1;
		}
		thelength = strText.length;
	}

	if (strText > "")
	{
		if ((parseFloat(strText) < lowerbound) || (parseFloat(strText) > upperbound))
		{
			strText = "";
		}
	}
	afield.value = strText;
}

function removeQuotes(strValue)
{
	i = strValue.indexOf("\"");
	while (i > -1)
	{
		strValue = strValue.substr(0,i) + strValue.substr(i+1);
		i = strValue.indexOf("\"");
	}
	
	return(strValue);
}

function removeCRandLF(strValue)
{
	i = strValue.indexOf(String.fromCharCode(13,10));
	while (i > -1)
	{
		strValue = strValue.substr(0,i) + " " + strValue.substr(i+2);
		i = strValue.indexOf(String.fromCharCode(13,10));
	}

	i = strValue.indexOf(String.fromCharCode(10,13));
	while (i > -1)
	{
		strValue = strValue.substr(0,i) + " " + strValue.substr(i+2);
		i = strValue.indexOf(String.fromCharCode(10,13));
	}

	i = strValue.indexOf(String.fromCharCode(10));
	while (i > -1)
	{
		strValue = strValue.substr(0,i) + " " + strValue.substr(i+1);
		i = strValue.indexOf(String.fromCharCode(10));
	}

	i = strValue.indexOf(String.fromCharCode(13));
	while (i > -1)
	{
		strValue = strValue.substr(0,i) + " " + strValue.substr(i+1);
		i = strValue.indexOf(String.fromCharCode(13));
	}
	
	return(strValue);
}

function checkText(objtext, strcomment)
{
var flagcheck = 0;
var strText = "";
var strChar = "";
var x = 0;

	strText = objtext.value;
	if (strText > "")
	{
/*
		strChar = strText.substr(x, 1);
		while ((strChar == " ") && (x < strText.length))
		{
			x = x + 1;
			if (x < strText.length)
			{
				strChar = strText.substr(x, 1);
			}
		}
		
		if (x > 0)
		{
			if (x == strText.length)
			{
				strText = "";
			}
			else
			{
				strText = strText.substr(x);
			}
		}
*/
		strText = strText.replace(/^\s*|\s*$/g,'');
		objtext.value = strText;
		
		if (strText != "")
		{
			flagcheck = 1;
		}
	}
	
	if (flagcheck == 0)
	{
		strmsg = strmsg + "\n" + strcomment;
	}

	return(flagcheck);	
}

function checkTextShowError(objtext, strcomment, strClassName, strClassNameError)
{
var flagcheck = 0;
var strText = "";
var strChar = "";
var x = 0;

	strText = objtext.value;
	if (strText > "")
	{

/*
		strChar = strText.substr(x, 1);
		while ((strChar == " ") && (x < strText.length))
		{
			x = x + 1;
			if (x < strText.length)
			{
				strChar = strText.substr(x, 1);
			}
		}
		
		if (x > 0)
		{
			if (x == strText.length)
			{
				strText = "";
			}
			else
			{
				strText = strText.substr(x);
			}
		}
*/
		strText = strText.replace(/^\s*|\s*$/g,'');
		objtext.value = strText;
		
		if (strText != "")
		{
			flagcheck = 1;
		}
	}
	
	if (flagcheck == 0)
	{
		strmsg = strmsg + "\n" + strcomment;
		objtext.className = strClassNameError;
	}
	else
	{
		objtext.className = strClassName;
	}

	return(flagcheck);	
} // end checkTextShowError


function clearText(objTest)
{
	objTest.value = "";
	return(true);	
}

function checkEmail(afield)
{
	afield.value = afield.value.replace(/^\s*|\s*$/g,'');		

var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if (re.test(afield.value) == false)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}

function checkEmailShowError(afield, strcomment, strClassName, strClassNameError)
{
	afield.value = afield.value.replace(/^\s*|\s*$/g,'');		

var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if (re.test(afield.value) == false)
	{
		strmsg = strmsg + "\n" + strcomment;
		afield.className = strClassNameError;
	}
	else
	{
		afield.className = strClassName;
	}
}

function validDate(intday, strmonth, intyear) 
{
var checkDate;
var intMonth;

	switch (strmonth)
	{
	case ("Jan"):
	  intMonth = 0;
	break
	case ("Feb"):
	  intMonth = 1;
	break
	case ("Mar"):
	  intMonth = 2;
	break
	case ("Apr"):
	  intMonth = 3;
	break
	case ("May"):
	  intMonth = 4;
	break
	case ("Jun"):
	  intMonth = 5;
	break
	case ("Jul"):
	  intMonth = 6;
	break
	case ("Aug"):
	  intMonth = 7;
	break
	case ("Sep"):
	  intMonth = 8;
	break
	case ("Oct"):
	  intMonth = 9;
	break
	case ("Nov"):
	  intMonth = 10;
	break
	case ("Dec"):
	  intMonth = 11;
	break
	default:
	  intMonth = 99;
	break
	} 
	

	checkDate = new Date(intyear, intMonth, intday);
	if ( checkDate.getDate() != intday )
	{
		// not valid date.
		return(false);
	}
	else
	{
		return(true);
	}	
}