
/*********************************************************************
*	The function openWin will open a new window given various	 	 *
*	parameters.														 *
**********************************************************************/	
function openWin(mylink, w, h, otherparams){
	mywin = window.open(mylink, '', 'width='+w+',height='+h + otherparams);
	mywin.focus()
}	





/********************************************
*	function isDate()						*
* 	- determines if a date is a valid date	*
* 	- 2/29/2004 returns true				*
* 	- 2/29/2005 returns false				*
********************************************/

function isDate(m, d, y, fldDsp){
	if (!fldDsp) fldDsp = "";
	fldDsp += " ";
	var msg = "";
	msg += "The " + fldDsp + "date is not a valid date.  Please select a valid date."
	m--; // subtract 1 from month to get to the javascript month array index values
	var oTestDate = new Date(y, m, d);
	var bIsDate = (oTestDate.getFullYear() == y) && (oTestDate.getMonth() == m) && (oTestDate.getDate() == d);
	if (!bIsDate) alert(msg);
	return bIsDate;
}

/****************************************************************
*	function isValidDate()										*
*	takes a date string in the mm/dd/yyyy format and returns	*
*	a Boolean based on whether it is an actual date				*
*	AGS(RH) - 10/13/06											*
****************************************************************/
function isValidDate(s){

	// if not in mm/dd/yyyy format, then return false
	if (!(/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/.test(s))) return false;

	// split date string into array so we can get to month, date, and year individually
	var a = s.split("/");

	// Use parseInt to convert strings into numbers.  If string starts with '0', parseInt will assume it's octet unless we 
	// specify the radix for base 10. - AGS(RH) - 10/13/06
	var m = parseInt(a[0], 10) - 1;		// subtract 1 to work with javascript nonths zero-based array
	var d = parseInt(a[1], 10);
	var y = parseInt(a[2], 10);
	
	// create date object using month, date, and year of date string passed into function
	var D = new Date(y, m, d)

	// We have attempted to create a date object from the date string.  If the string cannot be converted into a number, then we'll get a NaN response when
	// attempting to create the date.  However, it may create a number, but not refer to the correct date.  For example, a date string of '6/31/2006' will
	// create a date of 7/1/06.  Therefore, to ensure that we have a valid date, we also need to compare the m, d, and y of the date string with the
	// m, d, and y of the date created.  If they're not the same, then the date string must not be an actual date. - AGS(RH) - 10/13/06
	return !(isNaN(D) || (D.getMonth() != m) || (D.getDate() != d) || (D.getYear() != y))
}

/********************************************************
*	Function: areYouSure						  		*
*		Determines if the user is sure if he/she 		*
*		wants to do what he/she is about to do.			*
*********************************************************/	

function areYouSure(sQuestion){
	if(!sQuestion || trim(sQuestion).length == 0) sQuestion = "Are you sure you want to do this?"	//default question if none provided
	bAreYouSure = confirm(sQuestion);
	if(!bAreYouSure) return false;
	return true;
}

/********************************************************
*	Function: passwordsMatch					  		*
*		Checks a two password fields to see if the		*
*		user enters the same password twice.			*
*********************************************************/	

function passwordsMatch(pw1, pw2){
	if(pw1.value != pw2.value){
		alert("The passwords you have entered are not the same.  Please re-enter the passwords.");
		pw1.focus();
		error_occurred = true;
	}
}

/********************************************************
*	Function: requiredFound						  		*
*		Checks a text field to see if it is empty		*
*		If so, it alerts and sets an error variable		*
*********************************************************/	

function requiredFound(fld, fldDsp){
	if(fld.value.length == 0){
		alert("Please complete the " + fldDsp + " field.");
		fld.focus();
		return true;
	}
}

/********************************************************
*	Function: areTextFieldsValidTogether		  		*
*		Checks two text fields to ensure that they		*
*		either both have a value or neither one has		*
*		a value.										*
*********************************************************/	
function areTextFieldsValidTogether(fld1, fld2, fld1Dsp, fld2Dsp){
	msg = "";
	result = isEitherStringEmpty(fld1.value, fld2.value);
	if(result > 0){
		msg = "The '" + fld2Dsp + "' field is required since the '" + fld1Dsp + "' field has a value.";
		fld2.select();
	} else if(result < 0){
		msg = "The '" + fld1Dsp + "' field must have a value to be able to enter a value for the '" + fld2Dsp + "' field.";
		fld1.select();
	}
	if(msg.length){
		alert(msg);
		return false;
	}
	return true;
}


/********************************************************
*	Function: isUploadPDFFieldPairValid			  		*
*		Determine if the pdf upload file field and its	*
*		title field either both have a value or neither	*
*		one has a value.								*
*********************************************************/	
function isUploadPDFFieldPairValid(f, i){
	fldFile = eval("f.UPLOAD_PDF_" + i);
	fldDisplay = eval("f.S_UPLOAD_PDF_DISPLAY_TEXT_" + i);

	value1 = fldFile.options[fldFile.selectedIndex].value;
	value2 = fldDisplay.value;

	msg = "";
	result = isEitherStringEmpty(value1, value2);
	if(result > 0){
		msg = "The display text field is required for 'Related File #" + i + "'.";
		fldDisplay.select();
	} else if(result < 0){
		msg = "A file must be selected for 'Related File " + i + "' to be able to enter a value for its display text field.";
		fldFile.focus();
	}
	if(msg.length){
		alert(msg);
		return false;
	}
	return true;
}


function arePDFFieldsAndPDFHeadingValid(f, num_pdfs){
	bAllPDFFieldsEmpty = true;
	for(i=1; i<=num_pdfs; i++){
		fldDisplay = eval("f.S_UPLOAD_PDF_DISPLAY_TEXT_" + i);
		if(trim(fldDisplay.value).length){
			bAllPDFFieldsEmpty = false;
			break;
		}
	}
	
	value2 = "";
	if(!bAllPDFFieldsEmpty) value2 = "STRINGWITHLENGTH";
	msg="";
	result = isEitherStringEmpty(f.S_PROD_PDF_HDNG.value, value2);
	if(result > 0){
		msg = "A 'Related File' is required to be selectted since the 'Related File Heading' field has a value.";
	} else if(result < 0){
		msg = "The 'Related File Heading' field must have a value to be able to select files.";
		f.S_PROD_PDF_HDNG.select();
	}
	if(msg.length){
		alert(msg);
		return false;
	}
	return true;
}

/********************************************************
*	Function: isEitherStringEmpty				  		*
*		Checks two string values to ensure that they	*
*		either both have a value or neither one has		*
*		a value.										*
*********************************************************/	
function isEitherStringEmpty(str1, str2){
	if(trim(str1).length > 0 && trim(str2).length == 0){
		return 1;
	} else if(trim(str1).length == 0 && trim(str2).length > 0){
		return -1;
	}
	return 0;
}

/********************************************************
*	Function: isFieldNotEmpty					  		*
*		Checks a text field to see if it is not empty	*
*		If so, it alerts and sets an error variable		*
*********************************************************/	

function isFieldNotEmpty(fld, msg){
	if(fld.value.length != 0){
		alert(msg);
		fld.select();
		return true;
	}
}

/****************************************************************
*	Function: isIntegerGTEx						  				*
*		Checks to see if a text field is holding a positive 	*
*		number.  It only uses the javascript isNaN()			*
*		function to test.  Error message displayed and 			*
*		boolean value returned.						 			*
****************************************************************/	

function isIntegerGTEx(theValue, fldDsp, x){
	if(isNaN(theValue)){
		msg = "Please enter a numeric value for the " + fldDsp + " field.";
	} else if(theValue == ""){
		msg = "Please enter a value for the " + fldDsp + " field.";
	} else if(theValue < x){
		msg = "Please enter a positive value for the " + fldDsp + " field.";
	} else {
		msg = "";
	}
	//return msg;	
	if(msg.length){
		alert(msg);
		return false;
	}
	return true;
}

/********************************************************
*	Function: isGreaterThanZero					  		*
*		Checks a text field to see if its value is		*
*		equals zero. If so, it alerts and sets an		*
*		error variable									*
*********************************************************/	

function isGreaterThanZero(fld, fldDsp, fldToMoveTo){
	if(isNaN(fld.value)){
		alert("Please enter a numeric value for the " + fldDsp + " field.");
		if(!fldToMoveTo) fldToMoveTo = fld;
		fldToMoveTo.select();
		return false;
	} else if(fld.value <= 0){
		alert("Please provide a positive value for the " + fldDsp + " field.");
		if(!fldToMoveTo) fldToMoveTo = fld;
		fldToMoveTo.select();
		return false;
	} else if(fld.value != Math.floor(fld.value)){
		alert("Please provide a whole number for the " + fldDsp + " field.");
		if(!fldToMoveTo) fldToMoveTo = fld;
		fldToMoveTo.select();
		return false;
	}
	return true;
}

/********************************************************
*	Function: isEntryAllowed					  		*
*		Checks to see if a text field is allowed to		*
*		have a value entered in it.  This decision is	*
*		based upon whether or not a radio button (or	*
*		checkbox) is checked.  The first argument is	*
*		the radio button field to test, and the second	*
*		argument is the message to display to the user.	*
*		The third argument is used to determine if the	*
*		radio button should be tested to see if it is	*
*		checked or not checked.  To test for checked	*
*		do not provide a third argument.  To test for	*
*		unchecked, provide a value of true for the		*
*		third argument.
*********************************************************/	

function isEntryAllowed(fldDecisionBasedUpon, message, fldNotChecked){
	// In NN 4.x, there is some weird behavior with the focus getting reset that
	// causes this function and, therefore, the alert() to be called twice.  The
	// code in this function only shows the alert() if x == 1.  Each time the
	// function gets called, x is incremented.  When the alert is called, a
	// setTimeout is used to reset x to 0 after .5 seconds.  Therefore, once .5
	// seconds has gone by, it will reset itself and be able to issue another alert(). 

	if(typeof(x)=="undefined") x=0;

	if(!fldNotChecked){// if no third argument is given, assume you're testing if the fld is CHECKED
		if(isThisRadioButtonChecked(fldDecisionBasedUpon)){
			if(message && x==0){
				alert(message); 
				setTimeout("x=0",.5*1000)
				x++;
			}
			return false;
		}
	} else {// if third argument holds value of true, assume you're testing if the fld in NOT CHECKED
		if(!isThisRadioButtonChecked(fldDecisionBasedUpon)){
			if(message && x==0){
				alert(message); 
				setTimeout("x=0",.5*1000)
				x++;
			}
			return false;
		}	
	}
	return true;
}

/********************************************************
*	Function: isThisRadioButtonChecked			  		*
*		Checks a radio button (or checkbox) to see		*
*		if it is checked.  If so, it returns true,		*
*		otherwise it returns false.						*
*********************************************************/	

function isThisRadioButtonChecked(radioToTest){
	if(radioToTest.checked) return true;
	return false;
}

/********************************************************
*	Function: setFieldBlank						  		*
*		Sets a text field to blank.  The field to be 	*
*		set is provided as an argument.  Multiple		*
*		fields can be set at once by providing			*
*		additional arguments.							*
*********************************************************/	

function setFieldBlank(fld){
	for(i=0;i<arguments.length;i++){
		setFieldBlank.arguments[i].value = "";
	}
}

/********************************************************
*	Function: blurFocus							  		*
*		Blurs the focus to the field provided as	 	*
*		the argument.									*
*********************************************************/

function blurFocus(fld){
	fld.blur();
}

/********************************************************
*	Function: isCCNumber						  		*
*		Checks to see if a text field is holding a	 	*
*		credit card number.  It makes two types of		*
*		checks, allowing for 16 digits without any		*
*		dashes.  It also allows for the following 		*
*		format (xxxx-xxxx-xxxx-xxxx).  However, it 		*
*		does not currently allow for other formats 		*
*		of CC numbers (such as Amer. Express).	A 		*
*		message is returned and an error variable set	*
*		if the CC Number is not validated.		 		*
*********************************************************/	

function isCCNumber(fld, fldDsp){
	if(fld.value.length == 15 || fld.value.length == 16){
		if(isNaN(fld.value)){
			alert("Please provide a valid value for the " + fldDsp + " field.");
			fld.select();
			error_occurred = true;
		}
	} else if (fld.value.length == 19) {
		for(i=0;i<fld.value.length;i++){
			if(i==4 || i==9 || i== 14){
				if(fld.value.charAt(i) != "-"){
					alert("Please provide a valid value for the " + fldDsp + " field.");
					fld.select();
					error_occurred = true;	
				}
			} else {
				if(isNaN(fld.value.charAt(i))){
					alert("Please provide a valid value for the " + fldDsp + " field.");
					fld.select();
					error_occurred = true;			
				}
			}
		}
	} else {
		alert("Please provide a valid value for the " + fldDsp + " field.");
		fld.select();
		error_occurred = true;	
	}
}

/********************************************************
*	Function: isNumeric							  		*
*		Checks to see if a text field is holding a	 	*
*		number.  It only uses the javascript isNaN()	*
*		function to test.  A messsage is provided and	*
*		an error variable set if it's not a number.		*
*********************************************************/	

function isNumeric(fld, fldDsp){
	if(isNaN(fld.value)){
		alert("Please provide a numeric value for the " + fldDsp + " field.");
		fld.select();
		error_occurred = true;
	}
}	

/********************************************************
*	Function: radioSelected						  		*
*		Checks to see if one of a set of radio buttons 	*
*		has been selected.  This is a validation to 	*
*		ensure that the person has not left the entire	*
*		set blank.  The first argument is the radio		*
*		button set to be tested.  The second argument	*
*		is optional - is you want a message to be 		*
*		displayed provide it as the second argument.	*
*		If there is no second argument, a value of 		*
*		true or false will simply be returned.			*
*********************************************************/	

function radioSelected(fld, fldDsp){
	radio_selected = false;
	for(i=0;i<fld.length;i++){
		if(fld[i].checked){
			radio_selected = true;			
		}
	}
	if(fldDsp){
		if(!radio_selected){
			alert("Please select a value for the " + fldDsp + " field.");
			fld[0].focus();
			error_occurred = true;
		}
	} else {
		return radio_selected;
	}
}


/********************************************************
*	Function: areAllCheckboxesInFormUnchecked	  		*
********************************************************/

function areAllCheckboxesInFormUnchecked(f, sItemDescription){
	if(!sItemDescription) sItemDescription = "an item";
	bNoItemsChecked = true;
	for (i=0; i<f.length; i++) {
		var e = f.elements[i];
		if (e.type=="checkbox" && e.checked){
	  		bNoItemsChecked = false;
			break;
		}
	}
	if(bNoItemsChecked){
		alert("Please select " + sItemDescription + " to be deleted.");
		return true;
	}
	return false;
}

/********************************************************
*	Function: menuSelected						  		*
*		Checks to see if one of a set of drop down	 	*
*		menu has been selected.  If the item selected 	*
*		is the first item, this assumes that nothing	*
*		has been selected.  Therefore, make sure that	*
*		the first item is blank, or some type of		*
*		direction to the user.  This does not work 		*
*		for a select list - only a drop down.			*
*		If no item is selected a message is displayed 	*
*		and an error variable is set.					*
*********************************************************/	

function menuSelected(fld, fldDsp){
	if(fld.selectedIndex == 0){
		alert("Please select a value for the " + fldDsp + " field.");
		fld.focus();
		return true;
	}
}

/********************************************************
*	Function: listSelected						  		*
*		Checks to see if one of a set of select list 	*
*		menu has been selected.  If no item is selected	*
*		a message is displayed and an error variable	*
*		is set.											*
*********************************************************/	

function listSelected(fld, fldDsp){
	if(fld.selectedIndex == -1){
		alert("Please select a value for the " + fldDsp + " field.");
		fld.focus();
		error_occurred = true;
	}
}

/************************************************************
*	Function: trim								  			*
*		Trims a string of any leading or trailing spaces.	*
*************************************************************/	

function trim(strText) { 
	//alert("trim");
     // this will get rid of leading spaces 
     while (strText.substring(0,1) == ' ') 
         strText = strText.substring(1, strText.length);

     // this will get rid of trailing spaces 
     while (strText.substring(strText.length-1,strText.length) == ' ')
         strText = strText.substring(0, strText.length-1);

    return strText;
} 

/************************************************************
*	Function: isEmail and checkEmail			  			*
*		These two functions validate email addresses.		*
*************************************************************/	

// function isEmail2 splits the Email based on @ symbol
// isEmail2 accepts 2 parameters - email and flag 
// flag should be set to 0.
function isEmail(email){
	//alert("isEmail");
	var temp = email.indexOf('@');
	var tempstring = email.substring(temp+1);
	var period = tempstring.indexOf('.');
	
	var iChars = "*|,\":<>[]{}`\'()&$#% !^+=\\/;?";
	for(var i=0; i < temp; i++){
		if(iChars.indexOf(email.charAt(i))!= -1)
			return false;
	}
	
	if(period == -1)
		return false;
	if(temp == -1 )
		return false;
		
	iChars = "*|,\":<>[]{}`\'()&$#% @!^+=\\/;?";
	for(var i=temp+1; i < email.length; i++){
		if(iChars.indexOf(email.charAt(i))!= -1)
			return false;
	}

	if(iChars.indexOf(tempstring.charAt(period+1))!= -1)
		return false;

	return true
}

function checkEmail(field, sDisplayText){
	if(sDisplayText == null){
		sDisplayText = "Email Address";
	}
	if(trim(field.value) != "")
	if(!isEmail(field.value)){
		alert("Please enter a correctly formatted " + sDisplayText + ".");
		field.select();
		error_occurred = true;
		return false;
	}
	return true;
}

/************************************************************
*	Function: checkZip							  			*
*		Tests a zip code field to see if it's holding a		*
*		valid format for a zip code.  (xxxxx or xxxxx-xxxx)	*
*		If not, message displayed and error variable set.	*
*************************************************************/	

function checkZip(fld){
	rExp = /^\d{5}(-\d{4})?$/;
	results = fld.value.match(rExp);
	if(results == null){
		alert("Please provide a valid Zip/Postal Code.");
		fld.select();
		error_occurred = true;
		return error_occurred;
	}
}

/************************************************************
*	Function: checkPhone						  			*
*		Tests a phone number field to see if it's holding a	*
*		valid format for a phone number.					*
*		(xxx) xxx-xxxx										*
*		xxx-xxx-xxxx										*
*		xxx.xxx.xxxx										*
*		xxxxxxxxxx											*
*		If not, message displayed and error variable set.	*
*															*
*		Note: This function has been modified to only 		*
*			accept the following format: xxx-xxx-xxxx		*
*************************************************************/	

function checkPhone(fld, fldDsp){
	rExp = /^\(?\d{3}\)?[\-\.\s]?\d{3}[\-\.\s]?\d{4}$/;
	//rExp = /^\(\d{3}\)\s\d{3}\-\d{4}$/
	results = fld.value.match(rExp);
	if(fld.value.length > 0 && results == null){
		alert("Please provide a valid phone number for the " + fldDsp + " field.  (xxx) xxx-xxxx");
		fld.select();
		error_occurred = true;
		return error_occurred;
	}
}

/************************************************************
*	Function: checkSSN							  			*
*		Tests a Social Security Number field to see if		*
*		it's holding a valid format for a phone number.		*
*		xxxxxxxxx	(no dashes)								*
*		If not, message displayed and error variable set.	*
*************************************************************/	

function checkSSN(fld){
	if(fld.value.length != 9 || isNaN(fld.value)){
		validSSN = false;
	} else {
		validSSN = true;
	}
	
	if(!validSSN){
		alert("Please provide a valid Social Security Number.\nBe sure not to include any dashes.");
		fld.select();
		error_occurred = true;
	}
}

/************************************************************
*	Function: checkCouponNumber					  			*
*		Tests a Coupon Number field to see if it's holding	*
*		an 8-digit number									*
*		If not, message displayed and error variable set.	*
*************************************************************/	

function checkCodeNumber(fld, type){
	switch (type){
		case "coupon":
			sCodeDisplay = "Coupon Number";
			iCodeNumberLength = 8;
			break;
		case "giftcert":
			sCodeDisplay = "Gift Certificate Number";
			iCodeNumberLength = 6;
			break;
		default:
			sCodeDisplay = "Code Number";
			iCodeNumberLength = 8;
	}
	if(fld.value.length != iCodeNumberLength || isNaN(fld.value)){
		validCodeNumber = false;
	} else {
		validCodeNumber = true;
	}
	
	if(!validCodeNumber){
		alert("Please provide a valid " + sCodeDisplay + ".\nBe sure it is a(n) " + iCodeNumberLength + "-digit number.");
		fld.select();
		error_occurred = true;
	}
}

/************************************************************
*	Function: checkForDecimal					  			*
*		Tests a text field to see if it's holding a decimal	*
*		value.												*
*		If not, message displayed and error variable set.	*
*************************************************************/	

function checkForDecimal(fld, fldDsp){
	if(isNaN(trim(fld.value))){
		validDecimalNumber = false;
	} else {
		validDecimalNumber = true;
	}
	
	if(!validDecimalNumber){
		alert("Please provide a valid value for the " + fldDsp + " field.\nBe sure it is a number.");
		fld.select();
		error_occurred = true;
	}
}

/************************************************************
*	Function: checkStateZipBasedOnCountry		  			*
*		Determines whether the state/zip fields need to be	*
*		validated based on the selected country.			*
*************************************************************/	
	
function checkStateZipBasedOnCountry(theStateField, theZipField, theCountryField, sFieldType){
	
	determineSelectedCountry(theCountryField);
	
	if(bUSAIsSelected || bCanadaIsSelected){
		if(theStateField.options[theStateField.selectedIndex].value == ""){
			alert("Please select a state/province for the " + sFieldType + " State/Province field.");
			theStateField.focus();
			error_occurred = true;
		}
		if(!error_occurred){
			sSelectedState = theStateField.options[theStateField.selectedIndex].text;
			sUSStatesList = "Alabama|American Samoa|Alaska|Arizona|Arkansas|Armed Forces Africa|Armed Forces Americas|Armed Forces Canada|Armed Forces Europe|Armed Forces Middle East|Armed Forces Pacific|California|Colorado|Connecticut|Delaware|District of Columbia|Federated States of Micronesia|Florida|Georgia|Guam|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Marshall Islands|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Northern Mariana Islands|Ohio|Oklahoma|Oregon|Palau|Pennsylvania|Puerto Rico|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virgin Islands|Virginia|Washington|West Virginia|Wisconsin|Wyoming";
			USStatesArray = sUSStatesList.split("|");
			bUSStateFound = false;
			for(i=0;i<USStatesArray.length;i++){
				if(USStatesArray[i] == sSelectedState){
					bUSStateFound = true;
					break;
				}
			}
			if(bUSStateFound && bCanadaIsSelected){
				alert(sSelectedState + " is not a Canadian province.  Please select a Canadian province for the " + sFieldType + " State/Province field.");
				theStateField.focus();
				error_occurred = true;
			} else if(!bUSStateFound && bUSAIsSelected){
				alert(sSelectedState + " is not a US state.  Please select a US state for the " + sFieldType + " State/Province field.");
				theStateField.focus();
				error_occurred = true;
			}
			if(!error_occurred) requiredFound(theZipField, sFieldType + " Zip/Postal Code");
			if(bUSAIsSelected){
				if(!error_occurred) checkZip(theZipField);
			}
		}
	} else {
		if(theStateField.selectIndex > 0){
			alert("You have not selected the United States or Canada, so please do not select a state/province for the " + sFieldType + " State/Province field.");
			theStateField.focus();
			error_occurred = true;
		}
	}
}


function determineSelectedCountry(theCountryField){
	if(theCountryField.options[theCountryField.selectedIndex].value == "USA"){
		bUSAIsSelected = true;
	} else if(theCountryField.options[theCountryField.selectedIndex].value == "Canada"){
		bCanadaIsSelected = true;
	}
}

/************************************************************
*	Function: y2k and DateCheck					  			*
*		These two functions check to see if a text field	*
*		is holding a date in a correct format.				*
*		If not, message displayed and error variable set.	*
*************************************************************/	

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function DateCheck (myDate,sep, fldDsp) {
// checks if date passed is in valid mm/dd/yyyy, mm/d/yyyy, m/dd/yyyy, or m/d/yyyy format

	// checks if date passed is in valid mm/dd/yyyy format
    if (myDate.length == 10) {
        if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {
            var month  = myDate.substring(0,2);
            var date = myDate.substring(3,5);
            var year  = myDate.substring(6,10);

            var test = new Date(year,month-1,date);

            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
                return true;
            }
            else {
            	alert("Please enter the correct format for the " + fldDsp + " field.");
				error_occurred = true;
                return false;
            }
        }
        else {
        	alert("Please enter the correct format for the " + fldDsp + " field.");
			error_occurred = true;		
            return false;
        }
    }
    else {
		// checks if date passed is in valid mm/d/yyyy, or m/dd/yyyy format
		// checks if date passed is in valid mm/d/yyyy format
	    if (myDate.length == 9) {
	        if (myDate.substring(2,3) == sep && myDate.substring(4,5) == sep) {
	            var month  = myDate.substring(0,2);
	            var date  = myDate.substring(3,4);
	            var year  = myDate.substring(5,9);
	
	            var test = new Date(year,month-1,date);
	
	            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
	                return true;
	            }
	            else {
					alert("Please enter the correct format for the " + fldDsp + " field.");
					myDate.focus;
					error_occurred = true;
	                return false;
	            }
	        }
	        else {
				// checks if date passed is in valid m/dd/yyyy format
		        if (myDate.substring(1,2) == sep && myDate.substring(4,5) == sep) {
		            var month  = myDate.substring(0,1);
		            var date = myDate.substring(2,4);
		            var year  = myDate.substring(5,9);
		
		            var test = new Date(year,month-1,date);
		
		            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
		                return true;
		            }
		            else {
		            	alert("Please enter the correct format for the " + fldDsp + " field.");
						error_occurred = true;
		                return false;
		            }
		        }
		        else {
		        	alert("Please enter the correct format for the " + fldDsp + " field.");
					error_occurred = true;
					return false;
		        }
	        }
	    }
	    else {
		// checks if date passed is in valid m/d/yyyy format
	    	if (myDate.length == 8) {
		        if (myDate.substring(1,2) == sep && myDate.substring(3,4) == sep) {
		            var month  = myDate.substring(0,1);
		            var date = myDate.substring(2,3);
		            var year  = myDate.substring(4,8);
		
		            var test = new Date(year,month-1,date);
		
		            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
		                return true;
		            }
		            else {
			            alert("Please enter the correct format for the " + fldDsp + " field.");
						error_occurred = true;
		                return false;
		            }
		        }
		        else {
		        	alert("Please enter the correct format for the " + fldDsp + " field.");
					error_occurred = true;
		            return false;
		        }
		    }
		    else {
		    	if (myDate.length == 0) {
		           	return true;
			    }
			    else {
			    	alert("Please enter the correct format for the " + fldDsp + " field.");
					error_occurred = true;
			        return false;
			    }
		    }
	    }
    }
}
