function checkRadio(objradio, strcomment)
{
var flagcheck = 0;

	for (var i = 0; i < objradio.length; i++) 
	{
		if (objradio[i].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 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(formname, strStartName, intStartNum, intEndNum, intMinAnswers, intMaxAnswers, strcomment)
{
var flagcheck = 0;
var intCountAnswers = 0;

	for (var i = intStartNum; i <= intEndNum; i++) 
	{
		if (eval("formname." + strStartName + i + ".checked"))
		{
			++intCountAnswers;
		}
	}	

	if ((intCountAnswers >= intMinAnswers) && (intCountAnswers <= intMaxAnswers))
	{
		flagcheck = 1;
	}
	
	if (flagcheck == 0)
	{
		strmsg = strmsg + "\n" + strcomment;
	}

	return(flagcheck);	
}

function clearCheckboxes(formname, strChkName, intStart, intEnd)
{
	for (i=intStart; i<=intEnd; i++)
	{
		eval("formname" + "." + strChkName + i + ".checked = false");
	}
}

function clearOnChecked(isChecked, formname, strChkName, intStart, intEnd)
{
	if (isChecked)
	{
		clearCheckboxes(formname, strChkName, intStart, intEnd);
	}
	
}

function checkFloat(afield, lowerbound, upperbound, strcomment)
{
var strText;
var flagcheck = 1;

	strText = afield.value;
	
	if ( (strText > "") && !isNaN(parseFloat(strText)) )
	{
		if ((parseFloat(strText) < lowerbound) || (parseFloat(strText) > upperbound))
		{
			flagcheck = 0;
		}
	}
	else
	{
		flagcheck = 0;
	}

	if (flagcheck == 0)
	{
		strmsg = strmsg + "\n" + strcomment;
	}

	return(flagcheck);
}

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 checkPhone(objText, strcomment)
{
var strText, thelength;

	objText.value = trimString(objText.value);
	strText = objText.value;
	thelength = strText.length;

	reg = /^[ 0-9()\+]+$/;
	if (reg.test(strText) == false || thelength < 10)
	{	
		strmsg = strmsg + "\n" + strcomment;
	}

}

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);
			}
		}
		
		objtext.value = strText;
		
		if (strText != "")
		{
			flagcheck = 1;
		}
	}
	
	if (flagcheck == 0)
	{
		strmsg = strmsg + "\n" + strcomment;
	}

	return(flagcheck);	
}

function clearText(objTest)
{
	objTest.value = "";
	return(true);	
}

function checkEmail(afield)
{
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 (afield.value == "")
	{
		return(false);
	}
	else
	{
		if (re.test(afield.value) == false)
		{
			return(false);
		}
		else
		{
			return(true);
		}
	}
}

function checkURL (strURL, strcomment)
{
var rexp = new RegExp();
	
	rexp.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
	//rexp.compile("^(((https?:|ftp:|gopher:)\/\/))[-[:alnum:]\?%,\.\/&##!@:=\+~_]+[A-Za-z0-9\/]$");
	if (!rexp.test(strURL))
	{
		strmsg = strmsg + "\n" + strcomment;
	}

}

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 popWin(strurl, intwidth, intheight)
{
var popWin;
var strFeatures

	strFeatures = "menubar=yes,resizable=yes,width=" + intwidth + ",height=" + intheight;
	popWin = window.open(strurl, "popwin", strFeatures);
	popWin.focus();
}

function trimString(str)
{
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--)
	{
		if (/\S/.test(str.charAt(i)))
		{
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

