//--- this covers footer positioning (footer positioning script is in sitescripts.js);
//--- plus other init functions
window.onload = init;
function init() {
			setFooter();
			document.getElementById('form_submitted').onfocus=flagIt;
		}
function formValidator(){
	// Make quick references to our fields
	var item = document.form1.Selected_item;
	var realname = document.getElementById('name');
	var email = document.getElementById('emailaddress');
	var address = document.getElementById('address');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zipcode = document.getElementById('zip_code');
	var phone = document.getElementById('phone');
	var mesg = document.getElementById('mesg');
	var recaptcha = document.getElementById('recaptcha_response_field');
	var note = document.getElementById('note');
	
	// Check each input in the order that it appears in the form!
	if(notChecked("Please select one or more cards")){
		if(notEmpty(realname, "Please enter your name")){
    		if(isAlphabet(realname, "Please enter only letters for your name")){
				if(notEmpty(address, "Please enter your address")){
					if(notEmpty(city, "Please enter your city")){
						if(notEmpty(state, "Please enter your state")){
							if(notEmpty(zipcode, "Please enter your zip code")){
								if(notEmpty(email, "Please enter your email")){
    								if(emailValidator(email, "Please enter a valid email address")){
    									if(notEmpty(mesg, "Please enter a message")){
    										if(notEmpty(recaptcha, "Please enter the characters in the image")){
    											if(extraCheck(note)){
    												if(lastPart()){
    													return true;
    												}
    											}
    										}
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    	}
   }
	
	
	return false;
	
}

function notChecked(helperMsg){
  //	if(!(elem.checked)){
  	if(!(document.getElementById('aa').checked || document.getElementById('bb').checked || document.getElementById('cc').checked || document.getElementById('dd').checked || document.getElementById('ee').checked || document.getElementById('ff').checked || document.getElementById('gg').checked || document.getElementById('hh').checked || document.getElementById('ii').checked || document.getElementById('jj').checked )){
		alert(helperMsg);
		//elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z ]+$/; //-- Paul added space character (after Z)
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

var flag = '';
var check = '';
function extraCheck(elem){
	if(!(elem.value.length == 0)){
		window.location = "http://www.lisathiesing.com/sorry-spam.htm";
		return false;
		}
	check = '1';
	return true;
	}

function flagIt(){
	flag = '1';
	}

function lastPart(){
	if ((flag==1)&&(check==1)){
	document.form1.action='http://www.lisathiesing.com/cf/ltfm.php';
	return true;
	}
		window.location = "http://www.lisathiesing.com/sorry-spam.htm";
		return false;
}
