// Detect if browser is Netscape 3 + or IE 4 +
bName=navigator.appName;
bVer=parseInt(navigator.appVersion);
	br="n2";
	if (bName=="Netscape" && bVer >=4){br="n4";}
	if (bName=="Netscape" && bVer >=5){br="n5";}
	if (bName=="Microsoft Internet Explorer" && bVer >=4){br="ie4";}
	if (bName=="Microsoft Internet Explorer" && bVer >=5){br="ie4";}

function isEmpty(inputStr) {
	if(inputStr.value=="" || inputStr.value==null) {return true;}
	return false;
}

function chkEmptyValue(field){
	var myfield=field;
	if(isEmpty(myfield)){
		alert("Field can not be empty.\n\nPlease enter valid data as described in the on screen instructions.");
		myfield.select();
		myfield.focus();
		return false;
	}
	return true;
}

function chkEn(sct){
	var enrq="en";
	if(sct.name.indexOf("_en")==-1){enrq="rq"}
	var fld=sct.name.substring(0,sct.name.indexOf("_"+enrq))
	if(enrq=="rq"){
		if(document.form_0.elements[fld+"_rq"].checked){
			document.form_0.elements[fld+"_en"].checked=true;
		}
	}
	if(enrq=="en"){
		if(document.form_0.elements[fld+"_en"].checked==false){
			document.form_0.elements[fld+"_rq"].checked=false;
		}
	}
	return true;
}

// TRIM spaces from beginning and end of string
function trim(fld){
	trimstr=new String(fld.value);
	while(''+trimstr.charAt(0)==' ')
		trimstr=trimstr.substring(1,trimstr.length);
	while(''+trimstr.charAt(trimstr.length-1)==' ')
		trimstr=trimstr.substring(0,trimstr.length-1);
	fld.value=trimstr;
}

function toPhone(fld){
	var tmpfld=fld.value;
	var tf=true;
	tmpfld=tmpfld.replace(/[^0-9]/g,"");
	if(tmpfld.length==0){
		//empty of numbers
	}else if(tmpfld.length==7){
		alert("Please include the area code for "+tmpfld+".\n\n###-###-####");
		tmpfld=tmpfld.replace(/(\d{3})(\d{4})/, "-$1-$2");
		setTimeout("document.forms['"+fld.form.name+"'].elements['"+fld.name+"'].select()", 5);
		setTimeout("document.forms['"+fld.form.name+"'].elements['"+fld.name+"'].focus()", 5);
		tf=false;
	}else if(tmpfld.length==10){
		tmpfld=tmpfld.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
	}else{
		alert("Please specify the phone number in the following format.\n\n###-###-####");
		setTimeout("document.forms['"+fld.form.name+"'].elements['"+fld.name+"'].select()", 5);
		setTimeout("document.forms['"+fld.form.name+"'].elements['"+fld.name+"'].focus()", 5);
		tf=false;
	}
	fld.value=tmpfld;
	return tf;
}

function toSSN(fld){
	var tmpfld=fld.value;
	tmpfld=tmpfld.replace(/[^0-9]/g,"");
	if(tmpfld.length==0){
		//empty
	}else if(tmpfld.length==9){
		tmpfld=tmpfld.replace(/(\d{3})(\d{2})(\d{4})/, "$1-$2-$3");
	}else{
		alert("Please specify the SSN in the following format.\n\n###-##-####'");
		setTimeout("doSelection(document.forms['"+fld.form.name+"'].elements['"+fld.name+"'])", 0)
	}
	fld.value=tmpfld;
}

function toUpper(fld){
	trim(fld);
	fld.value=fld.value.toUpperCase();
	return;
}

function toLower(fld){
	trim(fld);
	fld.value=fld.value.toLowerCase();
	return;
}

function toDate(fld){
	var tmpfld=fld.value;
	tmpfld=tmpfld.replace(/[^0-9]/g,"");
	if(tmpfld.length==0){
		//empty
	}else if(tmpfld.length==8){
		tmpfld=tmpfld.replace(/(\d{2})(\d{2})(\d{4})/, "$1/$2/$3");
	}else{
		alert("Please enter date in the following format:\n\nmm/dd/yyyy (i.e. 06/04/1964)");
		setTimeout("doSelection(document.forms['"+fld.form.name+"'].elements['"+fld.name+"'])", 0)
	}
	fld.value=tmpfld;
}

function toTime(fld){
	trim(fld);
	if(fld.value==""){return}
	var timePat=/^(\d{1,2}):(\d{2})?$/;
	var matchArray=fld.value.match(timePat);
	if (matchArray==null) {
		fld.select();
		alert('Please enter time in the following military (24 hour) format:\n\nhh:mm (i.e. 3:22pm = 15:22)');
		fld.focus();
		return false;
	}

	hour=matchArray[1];
	minute=matchArray[2];

	if ((hour<0 || hour>23) || (minute<0 || minute>59)) {
		fld.select();
		fld.focus();
		alert('Please enter time in the following military (24 hour) format:\n\nhh:mm (i.e. 3:22pm = 15:22)');
		return false;
	}
	return true;
}

function toFloat(fld,precision){
	var num=Number(fld.value.replace(/[^0-9.]/g,''));
	return num.toFixed(precision);
}

function toCurrency(fld){
	var num=Number(fld.value.replace(/[^0-9.]/g,''));
	if(isNaN(num)){
		num="0";
	}
	sign=(num==(num=Math.abs(num)));
	num=Math.floor(num*100+0.50000000001);
	cents=num%100;
	num=Math.floor(num/100).toString();
	if(cents<10){
		cents="0"+cents;
	}
	for(var i=0;i<Math.floor((num.length-(1+i))/3);i++){
		num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}
	fld.value=(((sign)?'':'-')+'$'+num+'.'+cents);
}

function toDollarCent(fld){
	trim(fld);
	if(fld.value==""){return true;}

	fld.value=fld.value.replace(/[^0-9]\../g,"");
	var NumericRegExp=/^\d+(\.[0]{0,2})?$/;
	var regex=new RegExp(NumericRegExp);
	if(!regex.test(fld.value)){
		alert(fld.value + " is not valid for this field.");
		setTimeout("doSelection(document.forms['"+fld.form.name+"'].elements['"+fld.name+"'])", 0)
		return false;
	}else{
		return true;
	}
}

function toEmail(fld){
	trim(fld);
	if(fld.value==""){return true;}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(fld.value)){ return true; }
	fld.select();
	alert('Please enter a valid e-mail address in the following format.\n\nyourname@domain.com');
	fld.focus();
	return false;
}

function toURL(fld){
	var e;
	toLower(fld);
	//record length so that we can be sure '.' is not last
	e=fld.value;

	// check that we have a value:
	if ((e==null)||(e=="")){return true;}

	var httppos=e.indexOf("http");
	if (httppos!=0){
		fld.select();
		fld.focus();
		alert('Please enter a valid Web Address address including the HTTP:// or HTTPS://.');
		return false;
	}
	return true;
}

function toNumber(fld){
	trim(fld);
	if(fld.value==""){return true;}
	if(parseInt(fld.value)){
		fld.value=parseInt(fld.value)
		return true;
	}else{
		fld.value="";
		fld.focus();
		alert('Please enter only numbers in this field.');
		return false;
	}
}

function minmax(fld,min,max){
	trim(fld);
	if(fld.value==""){return true;}
	if(parseInt(fld.value)){
		fld.value=parseInt(fld.value)
		if(fld.value<min || fld.value>max){
			fld.focus();
			alert('Please enter a number between '+min+' and '+max+'.');
			return false;
		}
	}else{
		alert('Please enter only numbers in this field.');
		return false;
	}
	return true;
}


function toUpperLower(fld){
	var arrStr=fld.value.split(" ");
	var strOut="";
	var i=0;
	while(i<arrStr.length){
		firstChar  = arrStr[i].substring(0,1);
		remainChar = arrStr[i].substring(1);
		firstChar  = firstChar.toUpperCase();
		remainChar = remainChar.toLowerCase();
		strOut += firstChar + remainChar + ' ';
		i++;
	}
	fld.value=strOut.substring(0,strOut.length-1);
}

function doSelection(fld){
    fld.focus()
    fld.select()
}
