

function linkWindow(theURL) {
	var theWindow = window.open(theURL,"otherSite","width=400,height=300,resizable=yes,scrollbars=yes,toolbar=yes,status=yes,menubar=yes,location=yes")
	theWindow.focus() // this line just brings the window to the front if it's already been opened
}

function validateEmail(whichEmail) {
	//valid characters, @, 2 or more valid characters, ., 2 or letters
	var emailVerified = ""
	var regExp = /^[-\w_\.]+\@\w{2,}\.[a-zA-Z]{2,}$/
	if (regExp.test(whichEmail)) {
		emailVerified = "verified"
	}	else	{
		emailVerified = "bad address"
	}
	
	return emailVerified
}

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)"


			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 = ""
			}	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
	
}


function submitDonationForm() {
	numbersOnly(document.theCart.amount.name,document.theCart.amount.value,document.theCart.name)
	document.theCart.submit()
}


