// validate.js - Validate Fields in Member Registration form
/*This validation accepts the following parameters:
			Text: field ID, field name, required.
			Email is always required.
			Phone:  area code, first 3 digits, last 4 digits, the field label (primary, secondary), and required.
			
			All errors are stored into an array and displayed in a DIV element after validation.
*/

//establish DIV
var validate_div = document.getElementById("validateBox");

var n=0;


function checkWholeRequestForm(theForm) {
		/**/
		//establish error array
		errorArray =[];
		ecounter = 0;
		
		//capture phone fields to use as params for checkPhone()
		if (priareacode) {
			var priareacode = theForm.intPriAreaCode.value;
			var priphone1 = theForm.intPriPhone1.value;
	 		var priphone2 = theForm.intPriPhone2.value;
			var priphone = priareacode+priphone1+priphone2;
		}
		
		if (secareacode) {
			var secareacode = theForm.intSecAreaCode.value;
			var secphone1 = theForm.intSecPhone1.value;
	 		var secphone2 = theForm.intSecPhone2.value;	
			var secphone = secareacode+secphone1+secphone2;
		}
		
		var why = checkFields();
		
		//If there are errors
		if (why !== "") {
       		//alert('The form could not be completed:\n\n'+why);
			var validate_div = document.getElementById("validateBox");
			
			
			//alert('The form cannot be sent!\n Please go back and complete the fields in red.');
			//alert('validate children: '+validate_div.childNodes.length);
			//alert(document.getElementById("firstname").value);
			
			//Clear errors from previous submit
			if (validate_div.childNodes.length > 0) {
				for (link_counter = validate_div.childNodes.length - 1;link_counter >=0;link_counter--) {
					// Get the row element to be deleted
					var remove_node = validate_div.childNodes[link_counter];
					validate_div.removeChild(remove_node);
				}
			}
			
			validate_div.style.display = "block";
			
			//create heading
	  		var div_node = document.createElement("div");
			div_node.style.marginBottom = "3px";
			validate_div.appendChild(div_node);
			
			var h4_node = document.createElement("h4");
			h4_node.id = "validateHdr";
			validate_div.appendChild(h4_node);
			
			var h4text_node = document.createTextNode("The form could not be completed:");
			h4_node.appendChild(h4text_node);
			
			var ul_node = document.createElement("ul");
			validate_div.appendChild(ul_node);
			
			//populate error msg with errorArray
			for (var i in errorArray) {
				// Get the row element to be deleted
				var li_node = document.createElement("li");
				li_node.style.marginBottom = "3px";
				ul_node.appendChild(li_node);

				var desc_node = document.createTextNode(errorArray[i]);
				li_node.appendChild(desc_node);
			}
			
			//Empty array after displaying - error msg will show until resubmitted
			errorArray =[];
			//alert('error array:'+errorArray+', '+errorArray.length);
			ecounter++;
			window.scrollTo(0,0);

			return false;
		} 
		return true;
}

	
	function IsRequestFormReady(theForm) {
		if (!checkWholeRequestForm(theForm)) {
			//document.write(checkWholeForm(theForm))
			return false;
		}
		return true;
	}
	
	//all text fields
	function checkTextField(inputclassname,label,required) {
		var textfield = document.getElementById(inputclassname);
		//var firstNameValid = document.getElementById(isvalidclassname);
		//alert('textfield: '+textfield.name+', '+textfield.value);
		var error="";
		var illegalChars= /[\@\(\)\<\>\;\:\\\[\]\~\!\$\%\^\&\*\+\=\{\}\|]/
		
		if (textfield.value == '' && required == 'yes'){
			//alert(firstName.name + ' is empty');
			error = label+" is Required.\n";
			errorArray[n++] = error;
			textfield.className = 'invalidfield';
			//alert(firstName.name + ' is empty' + " "+ firstName.className);
			return error;
		}
		else if (textfield.value.match(illegalChars)) {
        	error = "Illegal characters in "+label+".\n";
			errorArray[n++] = error;
			textfield.className = 'invalidfield';
			return error;
      	}
		
		else {
			//alert(firstName.name + ' is not empty');
			textfield.className = 'inputstart';
			}
		return error;
	}
	
	//zip code
	function checkZip (inputclassname,type,required) {
 		var zip = document.getElementById(inputclassname);
		var error = "";
		var digit;
		///alert(strng.length);
		//alert("phoneln: "+parseInt(strng).toString().length)
		//alert('Zip Code: '+zip.value.length);
		//alert('Is strng null: '+(strng.length == ""));
		if (required == 'yes') { 
			if (zip.value == "" || zip.value == null || zip.value.length !== 5 ) {
    			error = type+" Zip Code is required, 5-digits.";
				errorArray[n++] = error;
				zip.className = 'invalidfield';
				return error;
			}
			else {
				for (var count=0; count < 5; count++) {
				//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
					if (isNaN(parseInt(zip.value.charAt(count)))) {
						error = type+" Zip Code must be a number, 5-digits.";
						errorArray[n++] = error;
						zip.className = 'invalidfield';
						return error;
					}
				}
			}
		}
		else if (zip.value !== '' && required == 'no')  {
			if (zip.value.length !== 5 ) {
    			error = type+" Zip Code must be 5-digits.";
				errorArray[n++] = error;
				zip.className = 'invalidfield';
				return error;
			}
			else {
				for (var count=0; count < 5; count++) {
					//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
					if (isNaN(parseInt(zip.value.charAt(count)))) {
						error = type+" Zip Code must be a number, 5-digits.";
						errorArray[n++] = error;
						zip.className = 'invalidfield';
						return error;
					}
				}
			}
		}
		zip.className = 'inputstart';
		return error;
		/*else if (parseInt(strng).toString().length !== 5) {
			error = "Please enter numeric values for the zip code.\n";
		}*/
		//return error;
	}
	
	//email
	function checkEmail(inputclassname) {
		//alert('checking email');
		var error = "";
		var email = document.getElementById(inputclassname);
		var emailFilter=/^.+@.+\..{2,3}$/;
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]\~\!\#\$\%\^\&\*\+\=\{\}\|\s]/
		
		if (email.value == "" || email.value == null) {
   			error = "Email Address is Required.\n";
			errorArray[n++] = error;
			email.className = 'invalidfield';
			return error;
		}
		else if (!(emailFilter.test(email.value))) { 
      		error = "Invalid format in Email Address.\n";
			errorArray[n++] = error;
			email.className = 'invalidfield';
			return error;
   		}
		else if (email.value.indexOf("chelseapiers.com") > -1) {
			//alert('If you are using a chelseapiers.com email address, you will not receive the confirmation. Please use a different email address.');
			error = "If you are using a chelseapiers.com Email Address, you will not receive the confirmation. Please use a different email address.";
			errorArray[n++] = error;
			email.className = 'invalidfield';
			return error;
		}
   		//test email for illegal characters
		
		//alert(email.value);
		else if (email.value.match(illegalChars)) {
        	error = "Invalid characters in Email Address.\n";
			errorArray[n++] = error;
			email.className = 'invalidfield';
			return error;
      	}
		else {
			email.className = 'inputstart';
			//alert('email good class: '+email.className);
		}
		return error;
    		 
	}
	
	function checkOtherEmail(inputclassname,label, required) {
		//alert('checking email');
		
		var error = "";
		var email = document.getElementById(inputclassname);
		//alert(document.getElementById('email').value);
		var emailFilter=/^.+@.+\..{2,3}$/;
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]\~\!\#\$\%\^\&\*\+\=\{\}\|\s]/
		
		if (required == 'yes') {
			if (email.value == "" || email.value == null) {
   				error = label+" Email Address is Required.\n";
				errorArray[n++] = error;
				email.className = 'invalidfield';
				return error;
			}
			else if (!(emailFilter.test(email.value))) { 
      			error = "Invalid format in "+label+" Email Address.\n";
				errorArray[n++] = error;
				email.className = 'invalidfield';
				return error;
   			}
			else if (email.value.indexOf("chelseapiers.com") > -1) {
				//alert('If you are using a chelseapiers.com email address, you will not receive the confirmation. Please use a different email address.');
				error = "If you are using a chelseapiers.com Email Address, you will not receive the confirmation. Please use a different email address, or email webmaster@chelseapiers.com for further assistance.";
				errorArray[n++] = error;
				email.className = 'invalidfield';
				return error;
			}
			else if (email.value.match(illegalChars)) {
        		error = "Invalid characters in "+label+" Email Address.\n";
				errorArray[n++] = error;
				email.className = 'invalidfield';
				return error;
      		}
		}
		else if (required == 'no' && email.value !== "" && email.value !== null) {
			
			if (!(emailFilter.test(email.value))) { 
      			error = "Invalid format in "+label+" Email Address.\n";
				errorArray[n++] = error;
				email.className = 'invalidfield';
				return error;
   			}
			else if (email.value.indexOf("chelseapiers.com") > -1) {
				//alert('If you are using a chelseapiers.com email address, you will not receive the confirmation. Please use a different email address.');
				error =  label+": If you are using a chelseapiers.com Email Address, you will not receive the confirmation. Please use a different email address, or email webmaster@chelseapiers.com for further assistance.";
				errorArray[n++] = error;
				email.className = 'invalidfield';
				return error;
			}
			else if (email.value.match(illegalChars)) {
        		error = "Invalid characters in  "+label+" Email Address.\n";
				errorArray[n++] = error;
				email.className = 'invalidfield';
				return error;
      		}
		}
		
		//test email for illegal characters
		
		//alert(email.value);
		
		
		//alert('email good class: '+email.className);
		email.className = 'inputstart';
		return error;
    		 
	}
	
	//phone field - first get phone
	function getPhone(areacode,phone1,phone2) {
		thePhone = areacode+phone1+phone2;
		return thePhone;
	}
	
	//then check phone
	function checkPhone(area,phone1,phone2,type,required) {
 		var error = "";
		var digit;
		var thisAreaCode = document.getElementById(area);
		var thisPhone1 = document.getElementById(phone1);
		var thisPhone2 = document.getElementById(phone2);
		var thePhoneNum = getPhone(thisAreaCode.value,thisPhone1.value,thisPhone2.value);
		
		//alert('id: '+isvalidclassname);
		
		///(strng.length);
		//("phoneln: "+parseInt(strng).toString().length)
		if (required == 'yes') { 
			if (thePhoneNum == '' || thePhoneNum.length !== 10) {
				//alert('phone: '+thePhoneNum);
    			error = type+" Phone is Required, 10-digit.\n";
				errorArray[n++] = error;
				thisAreaCode.className = 'invalidfield';
				thisPhone1.className = 'invalidfield';
				thisPhone2.className = 'invalidfield';
				return error;
 			}
			else  {
				for (var count=0; count < 10; count++) {
					//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
					//alert('num: '+thePhoneNum.charAt(count)+ ', not numeric: '+isNaN(parseInt(thePhoneNum.charAt(count))));
					/**/
					if (isNaN(parseInt(thePhoneNum.charAt(count)))) {
						error = "Please enter "+type+" Phone as a number.\n";
						errorArray[n++] = error;
						thisAreaCode.className = 'invalidfield';
						thisPhone1.className = 'invalidfield';
						thisPhone2.className = 'invalidfield';
						return error;
					}
				}
			}
		}
		else if (thePhoneNum !== '' && required == 'no')  {
			if (thePhoneNum.length !== 10) {
				//alert('phone: '+thePhoneNum);
    			error = type+" Phone must be 10 digits.\n";
				errorArray[n++] = error;
				thisAreaCode.className = 'invalidfield';
				thisPhone1.className = 'invalidfield';
				thisPhone2.className = 'invalidfield';
				return error;
 			}
			else  {
				for (var count=0; count < 10; count++) {
					//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
					//alert('num: '+thePhoneNum.charAt(count)+ ', not numeric: '+isNaN(parseInt(thePhoneNum.charAt(count))));
					/**/
					if (isNaN(parseInt(thePhoneNum.charAt(count)))) {
						error = "Please enter "+type+" Phone as a number.\n";
						errorArray[n++] = error;
						thisAreaCode.className = 'invalidfield';
						thisPhone1.className = 'invalidfield';
						thisPhone2.className = 'invalidfield';
						return error;
					}
				}
			}
		//alert('phone good class: '+thisAreaCode.className);
		
		//alert('phone - '+error);
		//return error;
		}
		thisAreaCode.className = 'inputstart';
		thisPhone1.className = 'inputstart';
		thisPhone2.className = 'inputstart';
		return error;
	}
	
	function checkPhoneSE(phonenum,type,required) {
 		var error = "";
		var digit;
		var thePhoneNum = document.getElementById(phonenum);
		
		//alert('id: '+isvalidclassname);
		
		///(strng.length);
		//("phoneln: "+parseInt(strng).toString().length)
		if (required == 'yes') { 
			if (thePhoneNum.value == '') {
				error = type+" Phone is required, with the format xxx-xxx-xxxx.";
				errorArray[n++] = error;
				thePhoneNum.className = 'invalidfield';
				return error;
			}
			else if(thePhoneNum.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1){
   				error = "Please enter the "+type+" Phone with the format xxx-xxx-xxxx.";
				errorArray[n++] = error;
				thePhoneNum.className = 'invalidfield';
				return error;
   			}
		}
		else if (thePhoneNum.value !== '' && required == 'no')  {
			if (thePhoneNum.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1){
   				error = "Please enter the "+type+" Phone with the format xxx-xxx-xxxx.";
				errorArray[n++] = error;
				thePhoneNum.className = 'invalidfield';
				return error;
   			}
		//alert('phone good class: '+thisAreaCode.className);
		
		//alert('phone - '+error);
		//return error;
		}
		thePhoneNum.className = 'inputstart';
		return error;
	}
	
	function checkChildName(inputclassname,isvalidclassname) {
		var childName = document.getElementById(inputclassname);
		var childNameValid = document.getElementById(isvalidclassname);
		var error="";
		
		if (firstName.value == ''){
			//alert(firstName.name + ' is empty');
			error = "Required field.";
			childName.className = 'invalidfield';
			removeValid(isvalidclassname);
			childNameValid.className = 'invalid';
			showValid(isvalidclassname,'no',error);
			return error;
		}
		
		else {
			//alert(firstName.name + ' is not empty');
			childName.className = 'inputstart';
			removeValid(isvalidclassname);
			childNameValid.className = 'valid';
			showValid(isvalidclassname,'yes');
		}
		return error;
	}
	
	function checkNum(inputclassname,label,required) {
		var num = document.getElementById(inputclassname);
		var stripnum;
		var error = "";
		var digit;
		//alert ('checking');
		//alert(childAge.value);
		//alert (num.value.length);
		
		
		stripnum = num.value.replace(/\./, ''); //strip out acceptable non-numeric characters
		
		if (required == 'yes') { 
			if (stripnum == "" || num.value == null) {
    			error = label+" is required.";
				errorArray[n++] = error;
				num.className = 'invalidfield';
				return error;
			}
			else {
				for (var count=0; count < stripnum.length; count++) {
					
				//alert (num.length);
				//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
					if (isNaN(parseInt(stripnum.charAt(count)))) {
						error = label+" must be a number.";
						errorArray[n++] = error;
						num.className = 'invalidfield';
						return error;
					}
				}
			}
		}
		else if (num.value !== '' && required == 'no')  {
			//alert (num.length);
			for (var count=0; count <  num.value.length; count++) {
					//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
				if (isNaN(parseInt(stripnum.charAt(count)))) {
						error = label+" must be a number.";
						errorArray[n++] = error;
						num.className = 'invalidfield';
						return error;
				}
			}
		}
		num.className = 'inputstart';
		return error;
	}
	
	function checkDate(thismonth,thisday,thisyear,fieldname) {
		var error = "";
		var digit;
		
		//entered
		var thisMonth = document.getElementById(thismonth);
		var thisDay = document.getElementById(thisday);
		var thisYear = document.getElementById(thisyear);
		var thisDate = new Date(thisMonth.value+'/'+thisDay.value+'/'+thisYear.value);
		
		//alert(thisDate);
		
		//today
		var now = new Date();
		nowMonth = now.getMonth();
		nowDay = now.getDate();
		nowYear = now.getFullYear();
		nowformatted = nowMonth+1+'/'+nowDay+'/'+nowYear;
		now = new Date(nowMonth+1+'/'+nowDay+'/'+nowYear);
		//alert (thisDate < now);
		
		if (!thisDate) {
    		error = fieldname+"is a Required field.";
			errorArray[n++] = error;
			thisMonth.className = 'invalidfield';
			thisDay.className = 'invalidfield';
			thisYear.className = 'invalidfield';
			return error;
 		}
		else if (thisDate < now) {
			error = "Please select a future "+fieldname+".\n";
			errorArray[n++] = error;
			thisMonth.className = 'invalidfield';
			thisDay.className = 'invalidfield';
			thisYear.className = 'invalidfield';
			return error;		
		}
		else {
			thisMonth.className = 'inputstart';
			thisDay.className = 'inputstart';
			thisYear.className = 'inputstart';
		}
		return error;	
	}
	
	function checkTextArea(inputclassname,label,required) {
		var textareafld = document.getElementById(inputclassname);
		//var firstNameValid = document.getElementById(isvalidclassname);
		var error="";
		var illegalChars= /[\@\+\\\|\{\}\<\>\[\]\~\^\*]/;
		var illegalPhrases = new Array("ftp","href","img","src");
		
		if (textareafld.value == '' && required == 'yes'){
			//alert(firstName.name + ' is empty');
			error = label+" is Required.\n";
			errorArray[n++] = error;
			textareafld.className = 'invalidfield';
			//alert(firstName.name + ' is empty' + " "+ firstName.className);
			//removeValid(isvalidclassname);
			//firstNameValid.className = 'invalid';
			//showValid(isvalidclassname,'no',error);
			return error;
		}
		else if (textareafld.value.match(illegalChars)) {
        	error = "Illegal characters in "+label+".\n";
			errorArray[n++] = error;
			textareafld.className = 'invalidfield';
			return error;
      	}
		
		else  {
			for (var count=0; count < illegalPhrases.length; count++) {
				//alert(illegalPhrases[count]);
			//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
			//alert('num: '+thePhoneNum.charAt(count)+ ', not numeric: '+isNaN(parseInt(thePhoneNum.charAt(count))));
			/**/
				if (textareafld.value.indexOf(illegalPhrases[count]) > -1) {
					error = "Invalid text in "+label+".\n";
					errorArray[n++] = error;
					textareafld.className = 'invalidfield';
					return error;
				}
			}
			//alert(firstName.name + ' is not empty');
			textareafld.className = 'inputstart';
			//removeValid(isvalidclassname);
			//firstNameValid.className = 'valid';
			//showValid(isvalidclassname,'yes');
		}
		return error;
	}
	
function checkCCNum(inputclassname) {
	
 	var illegalChars= /\D/
		var error = "";
		var stripnum;
		var cardtype = document.getElementById("creditcardtype").selectedIndex;
		var num = document.getElementById(inputclassname);
		//alert(num.value);
		//alert(document.getElementById("creditcardtype").selectedIndex);
		
		//var stripnum = num.value.replace(/\D/g, ''); //strip out acceptable non-numeric characters
		
		if (num.value == "" || num.value == null) {
			error = "Please enter your credit card number.\n";
			errorArray[n++] = error;
			num.className = 'invalidfield';
			return error;
		}
		if (num.value.length) {
			for (digit=0; digit < num.value.length; digit++) {
			//alert(parseInt(stripnum.charAt(digit)));
				//if (isNaN(parseInt(stripnum.charAt(digit)))) {
				if (num.value.match(illegalChars)){
					error = "Credit card number: please use numeric values, no spaces or dashes.\n";
					errorArray[n++] = error;
					num.className = 'invalidfield';
					return error;
				}
			}
			//alert('type: '+document.paymentform.creditcardtype.selectedIndex+'\nfirst digit: '+stripnum.charAt(0)+'\nvalid? '+(!(stripnum.length == 16 && stripnum.charAt(0) == 5)));
			//alert(cardtype);
			if (cardtype == 0) { //MC
				if (!(num.value.length == 16 && num.value.charAt(0) == 5)) {
					error = "Please enter correct credit card number, no spaces or dashes.\n";
					errorArray[n++] = error;
					num.className = 'invalidfield';
					return error;
				}
			}
			else if (cardtype == 1) { //AMEX
				if (!(num.value.length == 15 && num.value.charAt(0) == 3)) {
					error = "Please enter correct credit card number, no spaces or dashes.\n";
					errorArray[n++] = error;
					num.className = 'invalidfield';
					return error;
				}
			}
			else if (cardtype == 2) { //Disc
				if (!(num.value.length == 16 && num.value.charAt(0) == 6)) {
					error = "Please enter correct credit card number, no spaces or dashes.\n";
					errorArray[n++] = error;
					num.className = 'invalidfield';
					return error;
				}
			}
			else if (cardtype == 3) { //Visa
				if (!(num.value.length == 16 && num.value.charAt(0) == 4)) {
					error = "Please enter correct credit card number, no spaces or dashes.\n";
					errorArray[n++] = error;
					num.className = 'invalidfield';
					return error;
				}
			}
			else {
				if (!(num.value.length == 16)) { //default
					error = "Please enter correct credit card number, no spaces or dashes.\n";
					errorArray[n++] = error;
					num.className = 'invalidfield';
					return error;
				}
			}
		}
		num.className = 'inputstart';
		return error;
}
function checkExpDate(thismonth,thisyear,fieldname) {
		var error = "";
		var digit;
		
		//entered
		var thisMonth = document.getElementById(thismonth);
		var thisDay = 30;
		var thisYear = document.getElementById(thisyear);
		var thisDate = new Date(thisMonth.value+'/'+thisDay+'/'+thisYear.value);
		
		//alert(thisDate);
		
		//today
		var now = new Date();
		nowMonth = now.getMonth();
		nowDay = now.getDate();
		nowYear = now.getFullYear();
		nowformatted = nowMonth+1+'/'+nowDay+'/'+nowYear;
		now = new Date(nowMonth+1+'/'+nowDay+'/'+nowYear);
		//alert (thisDate < now);
		
		if (!thisDate) {
    		error = "Required field.";
			errorArray[n++] = error;
			thisMonth.className = 'invalidfield';
			thisYear.className = 'invalidfield';
			return error;
 		}
		else if (thisDate < now) {
			error = "Please select a future "+fieldname+".\n";
			errorArray[n++] = error;
			thisMonth.className = 'invalidfield';
			thisYear.className = 'invalidfield';
			return error;		
		}
		else {
			thisMonth.className = 'validinput';
			thisYear.className = 'validinput';
		}
		return error;
	}
function checkCVV (inputclassname) {
 		var cvv = document.getElementById(inputclassname);
		var error = "";
		var digit;
		///alert(strng.length);
		//alert("phoneln: "+parseInt(strng).toString().length)
		//alert('Zip Code: '+zip.value.length);
		//alert('Is strng null: '+(strng.length == ""));
		if (cvv.value == "" || cvv.value == null || (cvv.value.length !== 3 && cvv.value.length !== 4)) {
    		error = "Please enter the Card Security Code, or CVV2 - 3 or 4 digits.";
			errorArray[n++] = error;
			cvv.className = 'invalidfield';
			return error;
		}
		else {
			for (var count=0; count < cvv.value.length; count++) {
			//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
				if (isNaN(parseInt(cvv.value.charAt(count)))) {
					error = "Please enter the Card Security Code, or CVV2 as a number - 3 or 4 digits.";
					errorArray[n++] = error;
					cvv.className = 'invalidfield';
					return error;
				}
			}
		}
		cvv.className = 'inputstart';
		return error;
		/*else if (parseInt(strng).toString().length !== 5) {
			error = "Please enter numeric values for the zip code.\n";
		}*/
		//return error;
	}
	
	function checkSurveyTextArea(inputclassname,label,required) {
		//alert(inputclassname);
		var textareafld = document.getElementById(inputclassname);
		//alert(inputclassname+", "+textareafld.name);
		//var firstNameValid = document.getElementById(isvalidclassname);
		var error="";
		var illegalChars= /[\@\+\\\|\{\}\<\>\[\]\~\^\*]/;
		//var illegalPhrases = new Array("http","ftp","www",".com",".net",".us",".tv",".cc",".biz",".de","href","img","src");
		
		if (textareafld.value == '' && required == 'yes'){
			//alert(firstName.name + ' is empty');
			error = label+" is Required.\n";
			errorArray[n++] = error;
			textareafld.className = 'invalidfield';
			//alert(firstName.name + ' is empty' + " "+ firstName.className);
			//removeValid(isvalidclassname);
			//firstNameValid.className = 'invalid';
			//showValid(isvalidclassname,'no',error);
			return error;
		}
		else if (textareafld.value.match(illegalChars)) {
        	error = "Illegal characters in "+label+".\n";
			errorArray[n++] = error;
			textareafld.className = 'invalidfield';
			return error;
      	}
		
		else  {
			/*for (var count=0; count < illegalPhrases.length; count++) {
				//alert(illegalPhrases[count]);
			//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
			//alert('num: '+thePhoneNum.charAt(count)+ ', not numeric: '+isNaN(parseInt(thePhoneNum.charAt(count))));
			
				if (textareafld.value.indexOf(illegalPhrases[count]) > -1) {
					error = "Invalid text in "+label+".\n";
					errorArray[n++] = error;
					textareafld.className = 'invalidfield';
					return error;
				}
			}*/
			//alert(firstName.name + ' is not empty');
			textareafld.className = 'inputstart';
			//removeValid(isvalidclassname);
			//firstNameValid.className = 'valid';
			//showValid(isvalidclassname,'yes');
		}
		return error;
	}
function checkMemberNum (inputclassname) {
 		var membernum = document.getElementById(inputclassname);
		var numstripped = parseInt(membernum.value.substr(2));
		var error = "";
		var digit;
		///alert(strng.length);
		//alert("phoneln: "+parseInt(strng).toString().length)
		//alert('Zip Code: '+zip.value.length);
		//alert('Is strng null: '+(strng.length == ""));
		if (membernum.value == "" || membernum.value == null) {
    		error = "Membership Number is required.";
			errorArray[n++] = error;
			membernum.className = 'invalidfield';
			return error;
		}
		else if (membernum.value.length !== 8 || (membernum.value.substr(0,2).toUpperCase() !== "SC") || numstripped.toString().length !== 6) {
			//alert(parseInt(strng.charAt(count))+', '+isNaN(parseInt(strng.charAt(count))));
			error = "Member Number is invalid.";
			errorArray[n++] = error;
			membernum.className = 'invalidfield';
			return error;
		}
		membernum.className = 'validinput';
		return error;
	}
	function checkRadio(checkvalue,inputclassname,label) {
		var error = "";
		var theradio = document.getElementById(inputclassname);
   		if (!(checkvalue)) {
       		error = "Please check a value for "+label+".\n";
       		errorArray[n++] = error;
       		theradio.parentNode.className = 'invalidfield';
       		return error;
    	}
		else  {
			theradio.parentNode.className = '';	
		}
		return error;    
	}
	function checkCheckBoxGroup(inputclassnamelist,label) {
		var emptyItems=0;
		var error="";
		for (var counter in inputclassnamelist) {
			//alert(counter);
			//alert(inputclassnamelist);
			//alert(inputclassnamelist[counter]);
			var checkboxinput = document.getElementById(inputclassnamelist[counter]);
			
			var isChecked = checkboxinput.checked;
			if (isChecked) {
				for (var counter in inputclassnamelist) {
					var checkboxinput = document.getElementById(inputclassnamelist[counter]);
					checkboxinput.className = 'inputstart';
				}
				return error;
			}
			else {
				var emptyItems = emptyItems+ 1;
			}
		}
		if (emptyItems == inputclassnamelist.length) {
			error="No "+label+ " was entered. Please enter an "+label+ ".\n";
			errorArray[n++] = error;
			for (var counter in inputclassnamelist) {
				var checkboxinput = document.getElementById(inputclassnamelist[counter]);
				checkboxinput.className = 'invalidfield';
			}
			return error;
		}
		return error;
	}
	
	function checkCheckBoxGroupWithId(inputclassnamelist,label,inputclassparent) {
		var emptyItems=0;
		var error="";
		var checkboxparent = document.getElementById(inputclassparent);
		
		for (var counter in inputclassnamelist) {
			//alert(counter);
			//alert(inputclassnamelist);
			//alert(inputclassnamelist[counter]);
			var checkboxinput = document.getElementById(inputclassnamelist[counter]);
			
			
			var isChecked = checkboxinput.checked;
			if (isChecked) {
				for (var counter in inputclassnamelist) {
					var checkboxinput = document.getElementById(inputclassnamelist[counter]);
					if(checkboxparent.className == 'nobullet float') {checkboxparent.className = 'nobullet float';}
					else if(checkboxparent.className == 'nobullet floatlast'){checkboxparent.className == 'nobullet floatlast'}
				}
				return error;
			}
			else {
				var emptyItems = emptyItems+ 1;
			}
		}
		if (emptyItems == inputclassnamelist.length) {
			error="No "+label+ " was entered. Please enter an "+label+ ".\n";
			errorArray[n++] = error;
			for (var counter in inputclassnamelist) {
				var checkboxinput = document.getElementById(inputclassnamelist[counter]);
			}
			if (checkboxparent.className == 'nobullet float') {
				checkboxparent.className = 'invalidfield nobullet float';}
			else if (checkboxparent.className == 'nobullet floatlast') {
				checkboxparent.className = 'invalidfield nobullet floatlast';
			}
			return error;
		}
		return error;
	}
	
	function checkApptDateTime(thismonth,thisday,thisyear,thishour,thisminute,thistimeofday,fieldname) {
		var error = "";
		var digit;
		
		//entered
		var thisMonth = document.getElementById(thismonth);
		var thisDay = document.getElementById(thisday);
		var thisYear = document.getElementById(thisyear);
		var thisHour = document.getElementById(thishour);
		var thisMin = document.getElementById(thisminute);
		var thisTimeOfDay = document.getElementById(thistimeofday);
		//var thisDate = new Date(thisMonth.value+'/'+thisDay.value+'/'+thisYear.value+' '+thisHour.value+':'+thisMin.value+' '+thistimeofday.value);
		if (thisTimeOfDay.value == "PM") {
			//alert (12+parseInt(thisHour.value));
			thisHourConverted = 12+parseInt(thisHour.value);	
		}
		else {
			thisHourConverted = thisHour.value;
		}
		var thisDate = new Date(thisMonth.value+'/'+thisDay.value+'/'+thisYear.value+' '+thisHourConverted+':'+thisMin.value);
		
		//alert(thisDate);
		
		//today
		var now = new Date();
		nowMonth = now.getMonth();
		nowDay = now.getDate();
		nowYear = now.getFullYear();
		nowHour = now.getHours();
		nowMin = now.getMinutes();
		nowformatted = nowMonth+1+'/'+nowDay+'/'+nowYear+' '+nowHour+':'+nowMin;
		now = new Date(nowMonth+1+'/'+nowDay+'/'+nowYear+' '+nowHour+':'+nowMin);
		//alert (now);
		//alert (thisDate);
		//alert (thisDate < now);
		
		if (!thisDate) {
    		error = "Required field.";
			errorArray[n++] = error;
			thisMonth.className = 'invalidfield';
			thisDay.className = 'invalidfield';
			thisYear.className = 'invalidfield';
			thisHour.className = 'invalidfield';
			thisMin.className = 'invalidfield';
			return error;
 		}
		else if (thisDate < now) {
			error = "Please select a future "+fieldname+".\n";
			errorArray[n++] = error;
			thisMonth.className = 'invalidfield';
			thisDay.className = 'invalidfield';
			thisYear.className = 'invalidfield';
			thisHour.className = 'invalidfield';
			thisMin.className = 'invalidfield';
			return error;		
		}
		else {
			thisMonth.className = 'inputstart';
			thisDay.className = 'inputstart';
			thisYear.className = 'inputstart';
			thisHour.className = 'inputstart';
			thisMin.className = 'inputstart';
		}
		return error;
	}
	
function checkCheckBox(inputclassname) {
	var checkboxinput = document.getElementById(inputclassname)
	var isChecked = checkboxinput.checked;
	
	var error="";
	
	if (!isChecked) {
		if (checkboxinput.id == "agreetoterms") {
			error = "You must must agree to the Terms and Conditions.\n";
		}
		errorArray[n++] = error;
		checkboxinput.className = 'invalidfield';
		return error;
	}
	else {
		return error;
	}
	return error;
}

function checkWaiver(inputclassname) {
	//alert(inputclassname);
	var checkboxinput = document.getElementById(inputclassname)
	var isChecked = checkboxinput.checked;
	
	var error="";
	
	if (!isChecked) {
		if (checkboxinput.id == "agreetoterms") {
			error = "You must agree to the terms of the Waiver in order to register online.\n";
		}
		errorArray[n++] = error;
		checkboxinput.parentNode.className = 'invalidfield';
		checkboxinput.parentNode.style.padding = '5px';
		return error;
	}
	else {
		checkboxinput.parentNode.className = '';
		checkboxinput.parentNode.style.padding = '0px';
		return error;
	}
	return error;
}




