<!--
function getName(formname){
	
	var thisForm = eval("document." + formname);
	thisForm.name.value = thisForm.realname.value;
}

function getEmail(formname){
	
	var thisForm = eval("document." + formname);
	thisForm.email.value = thisForm.emailreq.value;
}

function getRecipient(formname){
	var thisForm = eval("document." + formname);
	
	if(thisForm.subject[0].checked){
		thisForm.recipient.value = "stories" + "@" + "survivingparentscoalition.org";
	}else if(thisForm.subject[1].checked){
		thisForm.recipient.value = "inquiry" + "@" + "survivingparentscoalition.org";
	} else if (thisForm.subject[2].checked){
		thisForm.recipient.value = "press" + "@" + "survivingparentscoalition.org";
	} else if (thisForm.subject[3].checked){
		thisForm.recipient.value = "webtech" + "@" + "survivingparentscoalition.org";
	}
}

function getRedirect(thisURL){
	if(thisURL == 1){
		document.form1.redirect.value = "http://www.survivingparentscoalition.org/thanks-general.php";
	}else if(thisURL == 2){
		document.form1.redirect.value = "http://www.survivingparentscoalition.org/thanks-general.php";
	} else if (thisURL == 3){
		document.form1.redirect.value = "http://www.survivingparentscoalition.org/thanks-press.php";
	} else if (thisURL == 4){
		document.form1.redirect.value = "http://www.survivingparentscoalition.org/thanks-site.php";
	}
}

function elimSpace(text){
	// removes leading spaces
	while (text.charAt(0) == " "){
		text = text.substring(1,text.length);
	}
	while (text.charAt(text.length - 1) == " "){
		text = text.substring(0,text.length-1);
	}
	return text;
}



function replaceWith(string,text,by) {    //replaceWith(this.form.myField.value,' ','')
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replaceWith(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}



/* Propery of Site Systems, Copyright 2001. All rights Reserved.
   Developers: Matthew Edwards, 

*/

// set global params
var focusfield = '';

function checkForm(formname) {

	// create some default parameters for the error message if one is needed
	var final_msg = ""; 
	var intro = "There was a problem with your message.          \n\n"; // create intro 
	var ending = "\n\nPlease make the appropriate changes and try resending.     \n\n" // create ending
	
	// define default messages 
	var err_text = "     - Incomplete Form"
	var err_ptext = "     - Incomplete Form"
	var err_month = "     - Invalid Month"
	var err_zip = "     - Invalid Zip Code"
	var err_credit = "     - Invalid Credit Card Number" 
	var err_phone = "     - Invalid Phone Number"
	var err_day = "     - Invalid Day"
	var err_year = "     - Invalid Year"
	var err_dropdown = "     - Incomplete Form"
	var err_checkbox = "     - No checkbox selected"
	var err_email = "     - Invalid Email"
	
	
	var f = eval("document." + formname + ".elements"); // define the scope to save time
	var vArray = new Array(); // Create an Array to hold fields to be validated
		
	//Check for fields that need to be validated
	for (i=0; i<f.length; i++) {
		if(f[i].name.indexOf('_validate') != -1) {
			if (vArray.length == 0) {
				vCurrent = 0;
			} else {
				vCurrent = vCurrent + 1;
			}
			vArray[vCurrent]  = f[i].name;
		}
		// check for a hidden test to stop form from submitting
		if(f[i].name == 'sitesys_test') {
			var testing = true;
		}
	}

	// Now that we have the validated fields, start checking values
	for (i=0; i<vArray.length; i++) {
		var fposition = vArray[i].indexOf('_validate'); // find the position of "_validate"
		var fname = vArray[i].substring(0, fposition); // extract field name
		var validate = eval("document." + formname + "." + vArray[i] + ".value"); // define scope
		var dash = validate.indexOf('-'); // find the position of the "-"

		if(dash == -1) {
			var type = validate; // if there is no dash set error_msg to blank/default
			var err_msg = '';
		} else {	
			var type = validate.substring(0,dash); // get field type
			var err_msg = validate.substring(dash + 1, validate.length); // get custom error message if any
		}	

		
		var field = eval("document." + formname + "." + fname); // define field scope

		// validate text fields
		if(type == 'text') {

			// removes leading spaces
			if (field.value){
				field.value = elimSpace(field.value);
			}
				
			if(!field.value) {
				if (err_msg == "") {
					final_msg = final_msg + err_text + "\n";
				} else {
					final_msg = final_msg + err_msg + "\n";
				}	
			setFocus(field); // run focus function
			}	
		}
		// end text validation
		
	// validate dropdown
		if(type == 'dropdown') {
			if(field[0].selected) {
				if (err_msg == "") {
						final_msg = final_msg + err_dropdown + "\n";
					} else {
						final_msg = final_msg + err_msg + "\n";
				}
			setFocus('nofocus'); // run focus function								
			}
		}
		// end dropdown validation
		
		
		// validate radio
		if(type == 'radio'){
			var rempty = true;
			for (r=0;r<field.length;r++) {
				if(field[r].checked) {
					rempty = false;
				}
			}
			if(rempty) {
				if (err_msg == "") {
					final_msg = final_msg + err_radio + "\n";
				} else {
					final_msg = final_msg + err_msg + "\n";
				}
			setFocus('nofocus'); // run focus function											
			}
		}
		// end radio validation
		
		// validate phone number
		if(type == 'phone'){
		
			field.value = replaceWith(field.value,' ','');
		
			re = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/
			validPhone = re.exec(field.value)
			
			if (validPhone) {
				field.value = "(" + validPhone[1] + ") " + validPhone[2] + "-" + validPhone[3]
			} else {
				if (err_msg == "") {
					final_msg = final_msg + err_phone + "\n";
				} else {
					final_msg = final_msg + err_msg + "\n";
				}				
				setFocus(field); // run focus function
			}
		}
		// end phone number validation\
		
		// validate zip code
		if(type == 'zip'){
		
			field.value = replaceWith(field.value,' ','');
			
			var valid = "0123456789-";
			var hyphencount = 0;
			var invalidzip = false;
		
			if (field.value.length!=5 && field.value.length!=10) {
				invalidzip = true;
			}
			for (w=0; w < field.value.length; w++) {
				
				temp = "" + field.value.substring(w, w+1);
				
				if (temp == "-") hyphencount++;
				
				if (valid.indexOf(temp) == "-1") {
					invalidzip = true;
				}
				if ((hyphencount > 1) || ((field.value.length==10) && ""+field.value.charAt(5)!="-")) {
					invalidzip = true;
				}
			}

			if (invalidzip){
				if (err_msg == "") {
					final_msg = final_msg + err_zip + "\n";
				} else {
						final_msg = final_msg + err_msg + "\n";
				}				
				setFocus(field); // run focus function
			}	
			
		}
		
		// validate email (REQUIRED)
		if (type == 'emailreq') {
		
			field.value = replaceWith(field.value,' ','');
			
			var bademail = false
			
			var emailStr = field.value;
			var emailPat=/^(.+)@(.+)$/;
			var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
			var validChars="\[^\\s" + specialChars + "\]";
			var quotedUser="(\"[^\"]*\")";
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
			var atom=validChars + '+';
			var word="(" + atom + "|" + quotedUser + ")";
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
			var matchArray=emailStr.match(emailPat);
			
			if (matchArray==null) { 
				bademail = true; 
			} else {
			
					var user=matchArray[1];
					var domain=matchArray[2];
					
					if (user.match(userPat)==null)  { bademail = true; }
					
					var IPArray=domain.match(ipDomainPat);
					if (IPArray!=null) {
						// this is an IP address
						  for (var i=1;i<=4;i++) {
							if (IPArray[i]>255) {
								 bademail = true;
							}
						}
					}
			
			
					var domainArray=domain.match(domainPat);
					if (domainArray==null)  { bademail = true; }
					
					var atomPat=new RegExp(atom,"g");
					var domArr=domain.match(atomPat);
					var len=domArr.length;
					if (domArr[domArr.length-1].length<2 || 
						domArr[domArr.length-1].length>3) {
						bademail = true;
					}
					
					if (len<2) {
						bademail = true;
					}
			}	
				
			if(bademail) {
				if (err_msg == "") {
					final_msg = final_msg + err_email + "\n";
					} else {
						final_msg = final_msg + err_msg + "\n";
				}
			setFocus(field); // run focus function											
			}
		}
		//end email validation

		// validate email (OPTIONAL)
		if (type == 'email') {
		
			field.value = replaceWith(field.value,' ','');
			
			var bademail = false
	
			if (field.value) { 
			
				var emailStr = field.value;
				var emailPat=/^(.+)@(.+)$/;
				var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
				var validChars="\[^\\s" + specialChars + "\]";
				var quotedUser="(\"[^\"]*\")";
				var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
				var atom=validChars + '+';
				var word="(" + atom + "|" + quotedUser + ")";
				var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
				var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
				var matchArray=emailStr.match(emailPat);
				
				if (matchArray==null) { 
					bademail = true; 
				} else {
				
						var user=matchArray[1];
						var domain=matchArray[2];
						
						if (user.match(userPat)==null)  { bademail = true; }
						
						var IPArray=domain.match(ipDomainPat);
						if (IPArray!=null) {
						    // this is an IP address
							  for (var i=1;i<=4;i++) {
							    if (IPArray[i]>255) {
									 bademail = true;
							    }
						    }
						}
				
				
						var domainArray=domain.match(domainPat);
						if (domainArray==null)  { bademail = true; }
						
						var atomPat=new RegExp(atom,"g");
						var domArr=domain.match(atomPat);
						var len=domArr.length;
						if (domArr[domArr.length-1].length<2 || 
						    domArr[domArr.length-1].length>3) {
							bademail = true;
						}
						
						if (len<2) {
							bademail = true;
						}
				}	
			}
				
			if(bademail) {
				if (err_msg == "") {
					final_msg = final_msg + err_email + "\n";
					} else {
						final_msg = final_msg + err_msg + "\n";
				}
			setFocus(field); // run focus function											
			}
		}
		//end email validation

	}


	// stop the submission if there are errors and notify the user
	if (final_msg != "") {
		alert(intro + final_msg + ending); // give the user the error
		if(focusfield != "false") {
			var focus_on = eval("document." + formname + "." + focusfield); // define scope
			focus_on.focus(); // focus on first field that needs to be fixed
		 }

		focusfield = ''; // clear out the focus field for next run
		return false; 

	}
	

	
	// check and see if we are testing, if so, then stop the form from submitting
	if(testing) { return false; }	
	
}

		//confirm before submitting	
		

function setFocus(field) {
	if(focusfield == '') {
		if (field == 'nofocus') {
			focusfield = "false";
		} else {
			focusfield = field.name;
		} 
	}	
}
-->