
// Declare Global Variables

	var formAlertMessage='There were Errors!';
	var formSubmit=1;

/*
	throwError gets called each time there is an error
*/
function throwError (theField,theMessage) {
	formAlertMessage=formAlertMessage + "\n - " + theMessage;
	formSubmit=0;
	switchStyle(theField);
}
function switchStyle (theField) {
	theSwitch=new Function("this.style.backgroundColor='FFFFFF';this.style.color='000000';if(this.type=='text') this.select();")
	theField.style.backgroundColor='E9967A';
	theField.style.color='White';
	theField.onfocus=theSwitch;
}

/*
	formAlert displays the alert message and clears necessary variables to start
	the validation over.
*/

function formAlert() {
	alert(formAlertMessage);
	formAlertMessage='There were Errors!';
	formSubmit=1;
}


/*
	formRequired makes sure a field has been completed by the user.   In order
	for this function to work with select boxes the empty value must be set to 0
	in the form.
*/

function formRequired(theField,theMessage) {
	theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
	if(theField.value == '' || theField.value == '-1' || theField.value == '0') {
		throwError(theField,theMessage);
	}
}

// form field must be composed only of numbers and letters.
function formIsAlphaNumeric(theField,theMessage) {
	theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
	isAlphaNum = new RegExp ("[^0-9a-zA-Z \(\)\-\.\/]");
	if (isAlphaNum.test(theField.value)) {
		throwError(theField,theMessage);
	}
}


// form field must be composed only of numbers.
function formIsNumeric(theField,theMessage) {
	theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
	isNum = new RegExp ("[^0-9 \-\.\/]");
	if (isNum.test(theField.value)) {
		throwError(theField,theMessage);
	}
}


// form field must be valid email.

function formIsEmail (theField,theMessage) {
      var email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
       if(!email.test(theField.value)) {
            throwError(theField,theMessage);
      }
 }

// generic popup window
function pop_me_up(pURL,name,features){
	new_window = window.open(pURL,name,features);
	new_window.focus();
}


// form field1 and 2 must be same (email verification).
function formIsSame(field1,field2,theMessage) {
	if(field1.value != field2.value) {
		throwError(field2,theMessage);
		switchStyle(field1);
	}
}
 
//Remove the $ sign if you wish the parse number to NOT include it
var prefix="$"
var wd
function parseelement(thisone){
if (thisone.value.charAt(0)=="$")
return
wd="w"
var tempnum=thisone.value
for (i=0;i<tempnum.length;i++){
if (tempnum.charAt(i)=="."){
wd="d"
break
}
}
if (wd=="w")
thisone.value=prefix+tempnum+".00"
else{
if (tempnum.charAt(tempnum.length-2)=="."){
thisone.value=prefix+tempnum+"0"
}
else{
tempnum=Math.round(tempnum*100)/100
thisone.value=prefix+tempnum
}
}
}
