function checkSSN(whichSSN) {
	var tracking=0
	var re_ssn = /\d\d\d-\d\d-\d\d\d\d/
	if (!re_ssn.test(whichSSN)) {
		tracking=1
	}
	return tracking
}


function checkNumbersOnly(thisNumber,includeDecimal) {
	//	thisNumber			value to check
	//	includeDecimal		"yes"(decimals are okay) or "no"(decimals will kill it)
	//
	//	This function returns a 1 if valid or 0 if invalid
	//
	// call this function from another script by the following:
	//		var checkQty = numbersOnly(document.theForm.qty.value,"yes")
	//		if (checkQty > 1) {	alert('not a number')	}
	
	var tracking=0
	var re_areaCode
	if (includeDecimal == "yes") {
		re_areaCode = /[\d.]+/
	}	else	{
		re_areaCode = /\d+/
	}
	
	if (!re_areaCode.test(thisNumber)) {
		tracking=1
	}
	
	return tracking
}


function checkPhones(thisAC,thisPhone) {
	
	var tracking=0
	
	// area code
	var re_areaCode = /\d\d\d/
	if (!re_areaCode.test(thisAC)) {
		tracking=1
	}
	
	// phone number
	var re_phone = /\d\d\d\-\d\d\d\d/
	if (!re_phone.test(thisPhone)) {
		tracking += 2
	}
	
	return tracking
}


function checkEmail(whichEmail) {
	var tracking=0
	
	//valid characters, @, 2 or more valid characters, ., 2 or letters
	// var regExp = /^[-\w_\.]+\@\w{2,}(\.[-\w_\.]{2,})+$/
	var regExp = /^[-\w_\.]+\@[-\w_\.]{2,}\.\w{2,}$/
	if (!regExp.test(whichEmail)) {
		//alert("WARNING:\n\nthis email is invalid")
		tracking++
	}
	
	return tracking

}

function checkDate(whichDate) {
	var tracking=0
	var re_date = /\d\d\d\d\D(\d{1,2})\D(\d{1,2})/
	if (!re_date.test(whichDate)) {
		tracking++
	}	else	{
		var dateArray = re_date.exec(whichDate)
		if (dateArray[1] < 1 || dateArray[1] > 12) {
			tracking++
		}
		if (dateArray[2] < 1 || dateArray[2] > 31) {
			tracking++
		}
	}
	return tracking
}



//////////////////////////////////////////////////////////////////////
/////////////			OLD-STYLE FUNCTIONS:		begin				//////////

function numbersOnly (x,y,z)	{
//		x = element name		y = value of textfield		z = form name
//		Each form must have a name.
//		Each element must have a name.
//		NOTE:  if this is the price and the value is "call", it will not 
//		convert to numbers only. Other pages convert the price "call" to
//		"call for pricing".
//		Each textfield needs to have the following:
//			 onBlur="numbersOnly(this.name,this.value,form.name)"

//	NOTE: the number must be in quotes - otherwise, Netscape erases everything

			var theForm = z
			var theString = y
			var newString = new String()
			for (var i=0; i<theString.length; i++)	{
				theCharacter = theString.charAt(i)
				if (theCharacter == "0" ||
						theCharacter == "1" ||
						theCharacter == "2" ||
						theCharacter == "3" ||
						theCharacter == "4" ||
						theCharacter == "5" ||
						theCharacter == "6" ||
						theCharacter == "7" ||
						theCharacter == "8" ||
						theCharacter == "9" ||
						theCharacter == ".")	{
					newString = newString + theCharacter
				}
			}
			if (newString == "0" ||
					newString == "00" ||
					newString == "000" ||
					newString == "0." ||
					newString == "0.0" ||
					newString == "0.00")	{
				document.forms[z].elements[x].value = "0"
			}	else	{
			document.forms[z].elements[x].value = newString
			}
}

function numbersOnly_no_decimal (x,y,z)	{
//		x = element name		y = value of textfield		z = form name
//		Each form must have a name.
//		Each element must have a name.
//		NOTE:  if this is the price and the value is "call", it will not 
//		convert to numbers only. Other pages convert the price "call" to
//		"call for pricing".
//		Each textfield needs to have the following:
//			 onBlur="numbersOnly_no_decimal(this.name,this.value,form.name)"


			var theForm = z
			var theString = y
			var newString = new String()
			for (var i=0; i<theString.length; i++)	{
				theCharacter = theString.charAt(i)
				if (theCharacter == "0" ||
						theCharacter == "1" ||
						theCharacter == "2" ||
						theCharacter == "3" ||
						theCharacter == "4" ||
						theCharacter == "5" ||
						theCharacter == "6" ||
						theCharacter == "7" ||
						theCharacter == "8" ||
						theCharacter == "9")	{
					newString = newString + theCharacter
				}
			}
			if (newString == "0" ||
					newString == "00" ||
					newString == "000" ||
					newString == "0." ||
					newString == "0.0" ||
					newString == "0.00")	{
				document.forms[z].elements[x].value = ""
			}	else	{
			document.forms[z].elements[x].value = newString
			}
}


function checkQuotes()	{
	for (var w=0; w<document.theForm.length; w++)	{
		if (document.theForm.elements[w].type == "text")	{
			var elementName = document.theForm.elements[w].name
			var elementValue = document.theForm.elements[w].value
			var elementForm = document.theForm.name
			noQuotes(elementName,elementValue,elementForm)
		}
	}
}

function noQuotes(x,y,z)	{
//alert("x = " + x + "\ny = " + y + "\nz = " + z)
//		x = element name		y = value of textfield		z = form name
//		Each form must have a name.
//		Each element must have a name.
//		NOTE:  if this is the price and the value is "call", it will not 
//		convert to numbers only. Other pages convert the price "call" to
//		"call for pricing".
//		If this is to be done onBlur, each textfield needs to have the following:
//			 onBlur="noQuotes(this.name,this.value,form.name)"
//
//		This is currently setup so that the function checkQuotes() loops through the
//		form elements of the form called "theForm". checkQuotes() calls this function, 
//		instead of using onBlur. THIS MEANS THAT IT NEEDS TO BE RUN IN A submitMe() FUNCTION.

			var theForm = z
			var theString = y
			var newString = new String()
			for (var i=0; i<theString.length; i++)	{
				theCharacter = theString.charAt(i)
				if (theCharacter != "\'" &&
						theCharacter != "\"")	{
					newString = newString + theCharacter
				}
				if (theCharacter == "\'")	{
					newString = newString + "\'"	// there is no cross-browser version of single quote
				}
				//if (theCharacter == "\"")	{
				//	if (document.theForm.elements[x].type == "textarea")	{
				//		newString = newString + "&quot;"
				//	}
				//}
			}
			document.forms[z].elements[x].value = newString
}

function lookForBlankFields(elementNames,displayText,elementTypes,formName) {
	//	This function verifies that the fields are not blank.
	//	If you get an error message when implementing this function, make sure the elementTypes are correct.
	// Incoming variables are ARRAYS (except formName, which is just the name of the form)
	//		elementNames = array of form elements to check
	//		displayText = text to display in the alert message, if it's displayed
	//		elementTypes = type of form element to check (to distinguish between select lists & others)
	
	var theWarningList = ""
	var selectFormName, radioName
	for (var i=0; i<elementNames.length; i++) {
		
		
		// check for text, textareas, and password fields
		if (elementTypes[i] == "text" || elementTypes[i] == "textarea" || elementTypes[i] == "password") {
			if (document.forms[formName].elements[elementNames[i]].value == "") {
				theWarningList += displayText[i] + "\n"
			}
		}
		
		// check for select lists
		if (elementTypes[i] == "select") {
			
			selectFormName = document.forms[formName].elements[elementNames[i]]
			if (selectFormName[selectFormName.selectedIndex].value == "") {
				theWarningList += displayText[i] + "\n"
			}
		}
		
		// check for radio lists
		if (elementTypes[i] == "radio") {
			radioName = document.forms[formName].elements[elementNames[i]]
			var verifyRadio=0
			for (var x=0; x<radioName.length; x++) {
				if (radioName[x].checked == true) {
					verifyRadio++
				}
			}
			if (verifyRadio == 0) {
				theWarningList += displayText[i] + "\n"
			}
		}
	}

	return theWarningList
	
}

/////////////			OLD-STYLE FUNCTIONS:		begin				//////////
//////////////////////////////////////////////////////////////////////


