/*********************************************************Genral purpose JavaScript functions for validation. Each function returns either 'True' or 'False'\u00A9 Copyright 2002Curt Cotycoty@gte.net**********************************************************//*********************************************************validateText()This function checks to make sure the user has entereddata into a text-only field.Arguments:fld = fielderrMsg = english name of field for display on error**********************************************************/function validateText(fld, errMsg){	if(fld.value=="")	{		alert("Please enter a value for " + errMsg + ".");		fld.focus();		return false;		}//endif	return true;}//endfunction validatetext/*********************************************************validateNumber()This function checks that the value of a field is a numberand, optionally within a certain range.Arguments:fld = fielderrMsg = english name of field for display on errormin = Optional minimum allowed valuemax = Optional maximum allowed value**********************************************************/function validateNumber(fld, errMsg, min, max){	if(fld.value=="")	{		alert("Please enter a value for " + errMsg + ".");		fld.focus();		return false;		}//endif		//check to see if it is a number		var n=parseFloat(fld.value);		if(isNaN(n))	{		alert("Please enter a valid number for " + errMsg + ".");		fld.focus();		return false;		}//endif	// check to see if the number is less than the minimum	if ( min && n < min ) 		{		alert("Please enter a number greater than " + min + " for " + errMsg + ".");		fld.focus();		return false;		}//endif	// check to see if the number is more than the maximum	if ( max && n > max )	{		alert("Please enter a number less than " + max + " for " + errMsg + ".");		fld.focus();		return false;		}//endif	return true;}//endfunction validateNumber/*********************************************************validateDate()This function checks to make sure the user has entereda date.Arguments:fld = fielderrMsg = english name of field for display on error**********************************************************/function validateDate(fld, errMsg){	var stDate = new Date(fld.value);	if (stDate == "NaN")	{		alert("Please enter a valid date for " + errMsg + ".");		fld.focus();		return false;		}	return true;}//endfunction validateDate/*********************************************************validateSelect()This function checks to make sure the user has selectedan option from a combobox or multi-select list box.Arguments:fld = fielderrMsg = english name of field for display on error**********************************************************/function validateSelect(fld, errMsg){		var idx=fld.selectedIndex;		if(idx== -1)	{		alert("Please choose a value for " + errMsg + ".");		fld.focus();		return false;		}//endif	return true;}//endfunction validateSelect/*********************************************************validateCombobox()This function checks to make sure the user has selectedan option from a combobox.  (The first option should always be "(please select)"Arguments:fld = fielderrMsg = english name of field for display on error**********************************************************/function validateCombobox(fld, errMsg){		var idx=fld.selectedIndex;		if(idx== -1 || idx==0 )	{		alert("Please choose a value for " + errMsg + ".");		fld.focus();		return false;		}//endif	return true;}//endfunction validateCombobox/*********************************************************validateRadio()This function checks to make sure the user has enteredan option for a radio buttonArguments:fld = fielderrMsg = english name of field for display on error**********************************************************/function validateRadio(fld, errMsg){	for(i=0;i<fld.length;i++)	{		if(fld[i].checked==true)		{			return true;		}//endif	}//endfor	alert("Please select a choice for " + errMsg + ".");	fld[0].focus();	return false;}//endfunction validateRadio/*********************************************************validateCheckbox()This function checks to make sure the user has selectedat least one optionArguments:fld = fielderrMsg = english name of field for display on error**********************************************************/function validateCheckbox(fld, errMsg){	for (index = 0; index < fld.length; index++)	{		if (fld[index].checked)			return true;	}	alert("Please select at least one choice for " + errMsg + ".");	fld[0].focus();	return false;}//endfunction validateCheckbox/*********************************************************validatePhone()This function checks to make sure the user has entereda correctly formatted phone numberArguments:fld = fielderrMsg = english name of field for display on error**********************************************************/function validatePhone(fld, errMsg){	var phone = fld.value;		// retrieve the value	if(phone == "")	{		alert("Please enter a phone number for " + errMsg + ".");		fld.focus();		return false;		}//endif	// Phone number entered with dashes or dots	if (phone.length == 12)	{		while (phone.indexOf(".") > -1)		{			phone = phone.replace(".", "-");		}		fld.value = phone;		return true;	} // end if	// Phone entered with no punctuation	if (phone.length == 10)	{		phone = phone.substr(0, 3) + "-" + 			phone.substr(3, 3) + "-" + phone.substr(6, 4);		fld.value = phone;		return true;	} // end if	// we can't deal with this format	alert("Please enter your phone number in one of the following formats:" +            "\n\n    999.999.9999 or " +             "\n    999-999-9999 or " +             "\n    9999999999.");	fld.focus();	return false;} // end function validatePhone/*********************************************************checkAmount()This function checks to make sure the user has entered avalid currency value.Arguments:fld = field**********************************************************/function checkAmount (fld){	var input = fld.value;	num = input.toString().replace(/,|\$/, '')		var n = parseFloat(num);		if (fld.value !="")	{		if(isNaN(n))		{			alert ("Amount must be a numeric value.");			fld.focus();			return input;		} // end if		return formatCurrency(n);	}	return input;}/*********************************************************formatCurrency()This is a helper function for checkAmount()**********************************************************/function formatCurrency(input) {	num = input.toString().replace(/,|\$/, '')		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));	return (((sign)?'':'-') + num + '.' + cents);}/*****************************************************************dialogAddressLookup (fieldName)fieldName = return field on formThis function displays the address lookup "dialog box"*****************************************************************/function dialogAddressLookup(fieldName){	var pathname;	var url;	pathname = (window.location.pathname);	url=pathname.substring(0,(pathname.lastIndexOf('.nsf')+5))+'F_DLG_ADDRESS?OpenForm&rf=' + fieldName;	window.open(url ,'Address', 'status=yes, menubar=yes,resizable=no,scrollbars=no,top=120,left=100,width=376,height=460');}