// Form Validation Scripts

	function fnInitForm(frmName){
		if(document.forms.length > 0){
			for (var i = 0; i < document.forms.length; i++){
				if(document.forms[i].name == frmName){
					oForm = this.document.forms[frmName];
					fnGetFormFocus();
					break;
				}
			}
		}
	}

// Sets the cursor on the first available form field	
	function fnGetFormFocus(){
		var fld;
		for (var i = 0; i < oForm.elements.length; i++){
			fld = oForm.elements[i];
			if(fld.type != 'hidden'){
				if(!fld.disabled){
					if(fld.type == 'text' || fld.type == 'textarea'){
						fld.focus();
						break;
					}
				}
			}
		}
	}
	
//Validate the form input
	function fnValidateForm(frmName){
		if (typeof oForm=='undefined') {
			oForm = document.forms[frmName];
		}else if(frmName=='login') {
			oForm = document.forms['login'];
		}
		for (var i = 0; i < oForm.elements.length; i++){
			var fld = oForm.elements[i];
			if(!fld.disabled){
				var fldValue = oForm.elements[i].value;
				var fldName = oForm.elements[i].name;
				var fldNameRequired = false;
				var s = (fldName.length - 4);
				if(fldName.substr(s,4) == '_req'){
					fldNameRequired = true;
				}
				
				
				if (fld.type == "text" || fld.type == "textarea"){
					fldValue = trimWhitespace(fldValue);
					if(fldNameRequired && fldValue==''){ 
						alert(fld.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
						fld.style.backgroundColor = '#FFFFCC';
						fld.focus();
						return false;
					}else{
						if( fldName.substr(0,4)=='int_' && ! isInteger(fldValue) ){
							alert(fld.id + ' may only contain whole numbers.  Please try again and then resubmit this form.  Thank you!');
							fld.style.backgroundColor = '#FFFFCC';
							fld.focus();
							return false;
						}else if( fldName.substr(0,4)=='num_' && fldValue != '' &&  ! isNumeric(fldValue) ){
							alert(fld.id + ' may only contain numbers or fractions.  Please try again and then resubmit this form.  Thank you!');
							fld.style.backgroundColor = '#FFFFCC';
							fld.focus();
							return false;
						}else if( fldName.substr(8,5)=='email' && ! isValidEmailStrict(fldValue) ){
							alert('The email address you entered does not appear to be a valid address, please try again.  Thank you!');
							fld.style.backgroundColor = '#FFFFCC';
							fld.focus();
							return false;
						}
					}
					fld.value = fldValue;
				}
				if(fld.type=="password" && fldNameRequired ){
					if(fldValue.length == 0){
						alert(fld.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
						fld.style.backgroundColor = '#FFFFCC';
						fld.focus();
						return false;

					}else if( fldValue.length < 4 || fldValue.length > 32 ){
						alert('Passwords must be between 8 and 32 characters.  Please try again and then resubmit this form.  Thank you!');
						fld.style.backgroundColor = '#FFFFCC';
						fld.focus();
						return false;
					}else if(!isAlphanumeric(fldValue, true)){
						alert('Passwords may only contain numbers or letters and no special characters  Please try again and then resubmit this form.  Thank you!');
						fld.style.backgroundColor = '#FFFFCC';
						fld.focus();
						return false;
					}
				}
				if( fld.type == "select-one" || fld.type == "select-multiple" || fld.type == "select" ) {
					if(fldNameRequired && fldValue==''){ 
						alert(fld.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
						fld.style.backgroundColor = '#FFFFCC';
						fld.focus();
						return false;
					}
				}
				if(fld.type == "file" && fldNameRequired && fldValue.length == 0){
					alert(fld.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
					fld.style.backgroundColor = '#FFFFCC';
					fld.focus();
					return false;
				}
			}
		}
		
		// Page specific validation
		
		switch(frmName){

			//event 107
			case 'add_workshopdemoapplication':
			if(oForm.workshop_or_demo.value == "workshop"){
			if(oForm.workshop_title.value == ""){
			alert("Workshop Title is a required field.");
			oForm.workshop_title.focus();
			return false;
			}
			}else if(oForm.workshop_or_demo.value == "demo"){
			if(oForm.demo_title.value == ""){
			alert("Demonstration Title is a required field.");
			oForm.demo_title.focus();
			return false;
			}
			}else if(oForm.workshop_or_demo.value == "both"){
			if(oForm.workshop_title.value == ""){
			alert("Workshop Title is a required field.");
			oForm.workshop_title.focus();
			return false;
			}
			if(oForm.demo_title.value == ""){
			alert("Demonstration Title is a required field.");
			oForm.demo_title.focus();
			return false;
			}
			}else{
			alert("Please choose between Workshop and Demonstration.");
			oForm.workshop_or_demo.focus();
			return false;
			}

			
			if(oForm.student_level.value == ""){
			alert("Student Level is a required field.");
			oForm.student_level.focus();
			return false;
			}
			if(oForm.description_text.value == ""){
			alert("Description is a required field.");
			oForm.description_text.focus();
			return false;
			}
			if(CountWords(oForm.description_text,80) > 80){
			alert("You can only enter 80 words in the description field");	
			oForm.description_text.focus();
			return false;
			}
			if(oForm.bio_text.value == ""){
			alert("Biography is a required field.");
			oForm.bio_text.focus();
			return false;
			}
			if(CountWords(oForm.bio_text,80) > 80){
			alert("You can only enter 80 words in the biography field");	
			oForm.bio_text.focus();
			return false;
			}
			if(oForm.detailed_text.value == ""){
			alert("Detailed Description is a required field.");
			oForm.detailed_text.focus();
			return false;
			}
			if(oForm.facilities_text.value == ""){
			alert("Facilities is a required field.");
			oForm.facilities_text.focus();
			return false;
			}
			if(oForm.equipment_text.value == ""){
			alert("Equipment is a required field.");
			oForm.equipment_text.focus();
			return false;
			}
			if(oForm.supplies_text.value == ""){
			alert("Supplies is a required field.");
			oForm.supplies_text.focus();
			return false;
			}
	
			
			break;
			
			
			
						case 'add_lecpresapplication':
			
			if(oForm.presentation_title.value == ""){
			alert("Presentation Title is a required field.");
			oForm.presentation_title.focus();
			return false;
			}
			
			if(oForm.presentation_text.value == ""){
			alert("Presentation description is a required field.");
			oForm.presentation_text.focus();
			return false;
			}
			if(CountWords(oForm.presentation_text,80) > 80){
			alert("You can only enter 80 words in the presentation field");	
			oForm.presentation_text.focus();
			return false;
			}
			if(oForm.biography_text.value == ""){
			alert("Biography is a required field.");
			oForm.biography_text.focus();
			return false;
			}
			if(CountWords(oForm.biography_text,80) > 80){
			alert("You can only enter 80 words in the biography field");	
			oForm.biography_text.focus();
			return false;
			}
			if(oForm.detailed_text.value == ""){
			alert("Detailed Description is a required field.");
			oForm.detailed_text.focus();
			return false;
			}
			if(oForm.facilities_text.value == ""){
			alert("Facilities is a required field.");
			oForm.facilities_text.focus();
			return false;
			}

			break;
						case 'add_exhibapplication':
			
			if(oForm.workshop_title.value == ""){
			alert("Workshop Title is a required field.");
			oForm.workshop_title.focus();
			return false;
			}
			if(oForm.description_text.value == ""){
			alert("Description is a required field.");
			oForm.description_text.focus();
			return false;
			}
			if(CountWords(oForm.description_text,80) > 80){
			alert("You can only enter 80 words in the description field");	
			oForm.description_text.focus();
			return false;
			}
			if(oForm.detailed_text.value == ""){
			alert("Detailed Description is a required field.");
			oForm.detailed_text.focus();
			return false;
			}
			if(oForm.space_text.value == ""){
			alert("Space requirements is a required field.");
			oForm.space_text.focus();
			return false;
			}

			
			break;	
			
			case 'add_user':
				if(admin < 1){
					var iStep = parseInt(oForm.x_int_step.value);
					if(iStep==1){
						var user_name=oForm.txt_lcx_user_name_req;
						if(user_name.value.length < 6 || user_name.value.length > 32){
							alert('The user name must be between 6 and 32.');
							user_name.backgroundColor = '#FFFFCC';
							user_name.focus();
							return false;
						}
						var user_pass = oForm.pwd_user_pass_req;
						var pass_confirm = oForm.pwd_passconfirm_req.value;
						if(user_pass.value != pass_confirm){
							alert('The passwords do not match. Please retype the passwords and submit again');
							user_pass.backgroundColor = '#FFFFCC';
							user_pass.focus();
							return false;
						}
					}
					if(iStep==3){
						if(!isValidEmailStrict(oForm.txt_lcx_email_req.value)){
							alert('The email address you entered does not appear to be valid.');
							oForm.txt_lcx_email_req.style.backgroundColor = '#FFFFCC';
							oForm.txt_lcx_email_req.focus();
							return false;
						}
					}
				}
				break;
			case 'edit_user':
				if(!isValidEmailStrict(oForm.txt_lcx_email_req.value)){
					alert('The email address you entered does not appear to be valid.');
					oForm.txt_lcx_email_req.style.backgroundColor = '#FFFFCC';
					oForm.txt_lcx_email_req.focus();
					return false;
				}
				if(admin < 1){
					if(oForm.x_changePass.checked){
						if(oForm.x_old_pass_req.value == '' || oForm.x_new_pass.value == '' || oForm.x_passconfirm.value == ''){
							alert('In order to modify your password information you must complete all 3 fields below');
							oForm.x_old_pass_req.style.borderColor = '#FF0000';
							oForm.x_new_pass.style.borderColor = '#FF0000';
							oForm.x_passconfirm.style.borderColor = '#FF0000';
							oForm.x_old_pass_req.focus();
							return false;
						}
					}
				}
				break;
			case 'add_image':
							
				if(oForm.image_file.value == ''){
					alert('You did not select a file to upload.  Click the browse button in the highlighted field, then select the file you wish to upload.\nIt is important to remember we only accept JPG or JPEG formated images.');
					oForm.image_file.style.backgroundColor = '#FFFFCC';
					oForm.image_file.focus();
					return false;					
					
				} 
				
				if (oForm.closeup_of_id.value != null) {
					return true;
				} else if (oForm.txt_non_ao_name.value == '') {

					alert(oForm.txt_non_ao_name.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
					oForm.txt_non_ao_name.style.backgroundColor = '#FFFFCC';
					oForm.txt_non_ao_name.focus();
					return false;					

				} else if (oForm.txt_non_ao_description.value == '') {

					alert(oForm.txt_non_ao_description.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
					oForm.txt_non_ao_description.style.backgroundColor = '#FFFFCC';
					oForm.txt_non_ao_description.focus();
					return false;

				} else if (oForm.num_ao_height.value == '') {

					alert(oForm.num_ao_height.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
					oForm.num_ao_height.style.backgroundColor = '#FFFFCC';
					oForm.num_ao_height.focus();
					return false;

				} else if (oForm.num_ao_width.value == '') {

					alert(oForm.num_ao_width.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
					oForm.num_ao_width.style.backgroundColor = '#FFFFCC';
					oForm.num_ao_width.focus();
					return false;

				} else if (oForm.num_ao_depth.value == '') {

					alert(oForm.num_ao_depth.id + ' is a required field.  Please complete ALL required fields then resubmit this form.  Thank you!');
					oForm.num_ao_depth.style.backgroundColor = '#FFFFCC';
					oForm.num_ao_depth.focus();
					return false;
											
				} else if(oForm.txt_non_ao_description_req.value.length > 300){
					alert('Your art work description may only contain 300 characters');
					oForm.txt_non_ao_description_req.style.backgroundColor = '#FFFFCC';
					oForm.txt_non_ao_description_req.focus();
					return false;
				}else{
					var pBar = findDOM('div_progress_bar',0)
					var cBtns = findDOM('div_cmd_buttons',0)
					clearInterval(uploadStartTimer);
					if(admin==1){
						oForm.cmd_reset.disabled=true;
						oForm.cmd_upload.disabled=true;
					}else{
						cBtns.style.visibility = 'hidden';
						pBar.style.position = 'relative';
						pBar.style.top = '-30px';
					}
					pBar.style.visibility = 'visible';
					progress_update();
				}
				break;
			case 'edit_image':
				if(oForm.txt_non_ao_description_req.value.length > 300){
					alert('Your art work description may only contain 300 characters');
					oForm.txt_non_ao_description_req.style.backgroundColor = '#FFFFCC';
					oForm.txt_non_ao_description_req.focus();
					return false;
				}else if(oForm.image_file.value.length > 0){
					clearInterval(uploadStartTimer);
					if(document.getElementById){
						if(admin==1){
							oForm.cmd_reset.disabled=true;
							oForm.cmd_update.disabled=true;
							oForm.cmd_delete.disabled=true;
							if(oForm.cmd_return) oForm.cmd_return.disabled=true;
						}else{
							document.getElementById("cmd_buttons").style.visibility = 'hidden';
							document.getElementById("progress_bar").style.position = 'relative';
							document.getElementById("progress_bar").style.top = '-30px';
						}
						document.getElementById("progress_bar").style.visibility = 'visible';
						progress_update();
					}
				}
				break;
			case 'add_portfolio':
			case 'edit_portfolio':
				if(oForm.txt_non_port_description.value.length > 1000){
					alert('Your portfolio description may contain a maximum of 1,000 characters');
					oForm.txt_non_port_description.style.backgroundColor = '#FFFFCC';
					oForm.txt_non_port_description.focus();
					return false;
				}
				break;
			case 'add_application':
				if(admin==0 && oForm.initials.value == ''){
					alert('You must indicate that you have read the terms & conditions by signing your initials in order to apply to this event.');
					return false;
				}
				if(oForm.hdn_int_event_id.value == 248){
					//if erotic show, make sure photo release
					if(oForm.read_terms_add.checked != true){
						alert('For this event you must also agree to the photo release.');
					
						return false;	
					}
				}
				//check to see event id
				//if its 97,98
				//then need to check( booth image or discription)
				//req
				
				if(oForm.hdn_int_event_id.value == 98 || oForm.hdn_int_event_id.value == 97){
					//inc_ai_req_one
					
					//ok booth image or 
					if(oForm.txt_non_additional_info.value =="" && oForm.bothimgselc.value == "" ){
							
							alert('THE BOOTH IMAGE OR BOOTH DESCRIPTION IS MANDATORY.');
							oForm.txt_non_additional_info.style.backgroundColor = '#FFFFCC';
							oForm.txt_non_additional_info.focus();
							return false;
						
					}
					
					
				}
				
				var tot = parseInt(oForm.totalchars.value);
				var maxchar = parseInt(oForm.maxchars.value);
				
				if(tot > maxchar){
					alert('Your application description may only contain '+ oForm.maxchars.value+' characters');
					oForm.txt_non_app_description_req.style.backgroundColor = '#FFFFCC';
					oForm.txt_non_app_description_req.focus();
					return false;
				}
				if(admin==1){
					oForm.cmd_reset.disabled=true;
					oForm.cmd_submit.disabled=true;
				}else{
					if(document.getElementById){
						document.getElementById("cmd_buttons").style.visibility = 'hidden';
						document.getElementById("progress_bar").style.position = 'relative';
						document.getElementById("progress_bar").style.top = '-30px';
						document.getElementById("progress_bar").style.visibility = 'visible';
						progress_update();
					}
				}
				//put the part here to check for previous applications
//alert('here  '+oForm.previousApp.value);
//if(oForm.previousApp.value == "true"){

//prompt here
//var answer = confirm("You have already applied in "+ oForm.catname.value +" to this show. Do you wish to continue? Click 'OK' if you wish to apply again. //Click 'Cancel' to return to Manage Applications to review your existing application to this show.");
//if(answer){

//}else{
//window.location = "http://www.juriedartservices.com/index.php?content=view_applications";
//return false;
//}

//}else 
if(oForm.samecat.value == "true"){

var answer = confirm("You have already applied to this event in category: "+ oForm.catname.value +". Do you wish to continue? Click 'OK' if you wish to apply again. Click 'Cancel' to return to Manage Applications to review your existing application to this show.");
if(answer){

}else{
window.location = "http://www.juriedartservices.com/index.php?content=view_applications";
return false;
}
}

				break;
			case 'edit_application':
				
				
				
				if(oForm.hdn_int_event_id.value == 249 && oForm.camefrom.value == "http://www.juriedartservices.com/amdur_app_2010.php"){
					//check number of images selected
					//check artist statement
					//check booth image
					
					//var artiststatement = document.getElementById('txt_non_app_description_req').value ;
					//alert(artiststatement);
					//var pageValue = oEditor.GetHTML();
					
					//if(pageValue == ""){
					//	alert("Artist Statement is a required field.  Please insert your artist statement.");
					//	return false;
					//}
				
					var minimagesreq = 4;
					var maximagereq = 4;
					var imgsel = 0;
					var add_image_req = false;
	
	
					for(var i=0; i < document.forms[0].elements.length; i++){
						if(document.forms[0].elements[i].name){
							//check if contains cbx_AO
							var curtxtname = document.forms[0].elements[i].name;
							if(curtxtname.match("cbx_AO")){
								if(document.forms[0].elements[i].checked == true){
									imgsel++;
								}
							}
			
							//check booth image to see if req
							if(curtxtname.match("rdo_addl_image")){
								if(document.forms[0].elements[i].checked){
									//alert("Bio image was selected");
										add_image_req = true;
								}
							}
						}	
					}
	
					//alert(imgsel + "-" + minimagesreq);
					var minstr = "";
					var selstr = "";
					if(minimagesreq > 1){
						minstr = " images ";	
					}else{
						minstr = " image ";	
					}
		
					if(imgsel == 0){
							selstr = " not selected any images. ";	
					}else if(imgsel == 1){
							selstr = " only selected 1 image. ";	
					}else{
						selstr = " only selected " + imgsel + " images. ";	
					}
		
					if(imgsel < minimagesreq){
		
						alert('This event requires ' + 	minimagesreq +  minstr + 'but you have'+ selstr + '\n Please select the required minimum of images ');
						return false;
					}
					if(imgsel > maximagereq ){
						selstr = " selected " + imgsel + " images. ";	
						alert('This event requires ' + 	minimagesreq +  minstr + 'but you have'+ selstr + '\n Please select the required number of images ');
						return false;
					}
	
					//return false;
					if(add_image_req != true ){
							
							alert('A BOOTH IMAGE is mandatory.  Please select one.');
							return false;
						
					}
	}
				
				
					
		
	
	
	
	
				
				var tot = parseInt(oForm.totalchars.value);
				var maxchar = parseInt(oForm.maxchars.value);
				
				if(tot > maxchar){
					alert('Your application description may only contain '+ oForm.maxchars.value+' characters');
					oForm.txt_non_app_description_req.style.backgroundColor = '#FFFFCC';
					oForm.txt_non_app_description_req.focus();
					return false;
				}
						
				if(admin==1){
					oForm.cmd_reset.disabled=true;
					oForm.cmd_update.disabled=true;
				}else{
					if(document.getElementById){
						document.getElementById("cmd_buttons").style.visibility = 'hidden';
						document.getElementById("progress_bar").style.position = 'relative';
						document.getElementById("progress_bar").style.top = '-30px';
						document.getElementById("progress_bar").style.visibility = 'visible';
						progress_update();
					}
				}
				break;
			case 'paymentech':
				if(payNowOneClick > 0){
					alert('Please be patient while your credit card information is processed.');
					return false;
				}else{
					var ccNum = JustNumbers(oForm.CARDNUM_req.value);
					var ccCVV2 = JustNumbers(oForm.CVV2_req.value);
					var ccType = ccNum.substr(0,1);
					var pos = (ccNum.length - 4);
					var strPymtInfo = new String('');
					
					if(ccNum == ''){
						alert('Please enter your credit card number');
						oForm.CARDNUM_req.style.backgroundColor = '#FFFFCC';
						oForm.CARDNUM_req.focus();
						return false;
					}
					if(ccCVV2 == ''){
						alert('Please enter your credit card security code number');
						oForm.CVV2_req.style.backgroundColor = '#FFFFCC';
						oForm.CVV2_req.focus();
						return false;
					}
					if(!ValidateCreditCard(ccNum)){
						alert('The credit card number is null or is invalid');
						oForm.CARDNUM_req.style.backgroundColor = '#FFFFCC';
						oForm.CARDNUM_req.focus();
						return false;
					}
					
					strPymtInfo += ccType + '-';
					strPymtInfo += ccNum.substr(pos,4) + '-';
					strPymtInfo += oForm.exp_date_mnth_req.value + ':' + oForm.exp_date_year_req.value;
					oForm.PYMTINFO.value = strPymtInfo;
	
					payNowOneClick++;
					
					if(document.getElementById){
						document.getElementById("cmd_buttons").style.display = 'none';
						document.getElementById("div_paynow").style.display = 'none';
						document.getElementById("p_paynow").innerText = 'Please be patient while we process your card.';
						document.getElementById("p_paynow").style.display = 'inline';
					}
				}
				break;
			case 'pay_flow':
				if(payNowOneClick > 0){
					alert('Please be patient while your credit card information is processed.');
					return false;
				}else{
					var ccNum = JustNumbers(oForm.CARDNUM.value);
					var ccType = ccNum.substr(0,1);
					var pos = (ccNum.length - 4);
					var strPymtInfo = new String('');
					
					if(ccNum == ''){
						alert('Please enter your credit card number');
						oForm.CARDNUM.style.backgroundColor = '#FFFFCC';
						oForm.CARDNUM.focus();
						return false;
					}
					if(ccType < 4 || ccType > 5){
						alert('This event accepts MasterCard or Visa Only');
						oForm.CARDNUM.value = '';
						oForm.CARDNUM.style.backgroundColor = '#FFFFCC';
						oForm.CARDNUM.focus();
						return false;
					}
					if(!ValidateCreditCard(ccNum)){
						alert('The credit card number is null or is invalid');
						oForm.CARDNUM.style.backgroundColor = '#FFFFCC';
						oForm.CARDNUM.focus();
						return false;
					}
					
					strPymtInfo += ccType + '-';
					strPymtInfo += ccNum.substr(pos,4) + '-';
					strPymtInfo += oForm.exp_date_mnth_req.value + ':' + oForm.exp_date_year_req.value;
					oForm.PYMTINFO.value = strPymtInfo;
	
					
					payNowOneClick++;
				}
				break;
			case 'auth_net':
				var ccNum = JustNumbers(oForm.x_card_num.value);
				var ccType = ccNum.substr(0,1);
				var pos = (ccNum.length - 4);
				var amexCheck = ccNum.substr(0,2);
				if(ccNum == ''){
					alert('Please enter your credit card number');
					oForm.x_card_num.style.backgroundColor = '#FFFFCC';
					oForm.x_card_num.focus();
					return false;
				}
				if(ccType < 3 || ccType > 5){
					if(oForm.eventID.value == "164" || oForm.eventID.value == "150" ){
						alert('This event accepts MasterCard or Visa Only');
					}else{
						alert('This event accepts AmEx, MasterCard or Visa Only');
					}
					
					oForm.x_card_num.value = '';
					oForm.x_card_num.style.backgroundColor = '#FFFFCC';
					oForm.x_card_num.focus();
					return false;
				}
				
				if((oForm.eventID.value == "166" || oForm.eventID.value == "150" || oForm.eventID.value == "249") && (amexCheck == "34" || amexCheck == "37")){
					alert('Amdur Productions does not accept American Express.  Please use a different card.');
					oForm.x_card_num.value = '';
					oForm.x_card_num.style.backgroundColor = '#FFFFCC';
					oForm.x_card_num.focus();
					return false;
				}
				if((oForm.eventID.value == "150") && (ccNum.substr(0,2) == "60" )){
					alert('This event does not accept Discover');
					oForm.x_card_num.value = '';
					oForm.x_card_num.style.backgroundColor = '#FFFFCC';
					oForm.x_card_num.focus();
					return false;
				}
				if(!ValidateCreditCard(ccNum)){
					alert('The credit card number is null or is invalid');
					oForm.x_card_num.style.backgroundColor = '#FFFFCC';
					oForm.x_card_num.focus();
					return false;
				}
				if(oForm.EXPMONTH.value=='' || oForm.EXPYEAR.value==''){
					alert('Please select the expiration date for card # ' + ccNum);
					oForm.EXPMONTH.style.backgroundColor = '#FFFFCC';
					oForm.EXPYEAR.style.backgroundColor = '#FFFFCC';
					oForm.EXPMONTH.focus();
					return false;
				}
				oForm.x_exp_date.value = oForm.EXPMONTH.value + '/' + oForm.EXPYEAR.value;
				oForm.x_card_num.value = ccNum;
				
				var strPymtInfo = new String('');
				strPymtInfo += ccType + '|';
				strPymtInfo += ccNum.substr(pos,4) + '|';
				strPymtInfo += oForm.EXPMONTH.value + '/' + oForm.EXPYEAR.value;
				oForm.x_po_num.value = strPymtInfo;
				
				//oForm.cmd_submit.disabled = true;
				//form is good to go hide submit buttons and change to processing... so the button isn't clicked again
				document.getElementById('cmd_buttons').innerHTML="<strong>Pleaes wait processing... </strong><br>(do not hit refresh or your browser's back button)";
				break;
			case 'manage_events':
				var rGrp;
				rGrp = oForm.rdo_txt_late_app;
				if(rGrp[0].checked){
					if(removeSpaces(oForm.num_late_app_fee.value)=='' || removeSpaces(oForm.dte_late_app_date.value)==''){
						alert('If this event is set to accept late applications, both the [late app fee] and [late app date] fields must also be set.');
						oForm.num_late_app_fee.focus();
						return false;
					}
				}
				
				var pymt_gateway = oForm.sel_txt_pymt_gateway_req.value;
				switch(pymt_gateway) {
					case 'auth_net':
					if(oForm.txt_non_an_loginid.value=='' || oForm.txt_non_an_txnkey.value==''){
						alert('Payment Gateway info is required .  Please complete ALL required fields then resubmit this form.  Thank you!');
						oForm.txt_non_an_loginid.focus();
						return false;
					}
					break;
					case 'pay_flow':
					if(oForm.txt_non_pf_user.value=='' || oForm.txt_non_pf_vendor.value=='' || oForm.txt_non_pf_partner.value=='' || oForm.txt_non_pf_pwd.value==''){
						alert('Payment Gateway info is required .  Please complete ALL required fields then resubmit this form.  Thank you!');
						oForm.txt_non_pf_user.focus();
						return false;
					}
					break;
					case 'pay_pal':
					if(oForm.txt_non_pp_business.value==''){
						alert('Payment Gateway info is required .  Please complete ALL required fields then resubmit this form.  Thank you!');
						oForm.txt_non_pp_business.focus();
						return false;
					}
					break;
					case 'paymentech':
					if(oForm.txt_non_pt_username.value=='' || oForm.txt_non_pt_pwd.value=='' || oForm.txt_non_pt_merchant_id.value==''){
						alert('Payment Gateway info is required .  Please complete ALL required fields then resubmit this form.  Thank you!');
						oForm.txt_non_pymt_url.focus();
						return false;
					}
					break;
					case 'custom':
					if(oForm.txt_non_pymt_url.value=='' || oForm.rdo_txt_form_method.value=='' || oForm.sel_txt_form_target.value==''){
						alert('Payment Gateway info is required .  Please complete ALL required fields then resubmit this form.  Thank you!');
						oForm.txt_non_pymt_url.focus();
						return false;
					}
					break;
				}
			break;
		}
		
	}

// Functions for form input:

// Check that an email address is valid based on RFC 821 (?)
	function isValidEmail(address) {
		if (address != '' && address.search) {
		  if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
		  else return false;
		}
	   // allow empty strings to return true - screen these with either a 'required' test or a 'length' test
	   else return true;
	}
	
// Check that an email address has the form something@something.something
// This is a stricter standard than RFC 821 (?) which allows addresses like postmaster@localhost
	function isValidEmailStrict(address) {
		if (isValidEmail(address) == false) return false;
		var domain = address.substring(address.indexOf('@') + 1);
		if (domain.indexOf('.') == -1) return false;
		if (domain.indexOf('.') == 0 || domain.indexOf('.') == domain.length - 1) return false;
		return true;
	}
	
// Check that a string contains only numbers and one decimal
	function isNumeric(str){
		var reFloatF1 = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/; 
		return reFloatF1.test(str);
	}
	
// Check that a string contains only numbers
	function isInteger(str) {
		if (str.search) {
			if ( str.search(/\D/) != -1) return false;
		}
		return true;
	}
	
	function isAlphanumeric(str, ignoreWhiteSpace) {
		if (str.search) {
			if ((ignoreWhiteSpace && str.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && str.search(/\W/) != -1)) return false;
		}
		return true;
	}
	
// Check that a US zip code is valid
	function isValidZipcode(zipcode) {
		zipcode = removeSpaces(zipcode);
		if (!(zipcode.length == 5 || zipcode.length == 9 || zipcode.length == 10)) return false;
		if ((zipcode.length == 5 || zipcode.length == 9) && !isInteger(zipcode)) return false;
		if (zipcode.length == 10 && zipcode.search && zipcode.search(/^\d{5}-\d{4}$/) == -1) return false;
	   return true;
	}
	
// Check that a Canadian postal code is valid
	function isValidPostalcode(postalcode) {
		if (postalcode.search) {
			postalcode = removeSpaces(postalcode);
			if (postalcode.length == 6 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true;
			else if (postalcode.length == 7 && postalcode.search(/^[a-zA-Z]\d[a-zA-Z]-\d[a-zA-Z]\d$/) != -1) return true;
			else return false;
		}
		return true;
	}
	
//Limit the input in a textarea
	function textCounterSpan(field, countfieldName, maxlimit) {
		var fldLen = field.value.length
		var oCountField = findDOM(countfieldName,0);
		if (fldLen > maxlimit) {
			field.value = field.value.substring(0, maxlimit-1);
			alert('You have entered the maximum allowed characters.');
			field.focus();
		} else {
			//oCountField.innerText = maxlimit - fldLen;
			oCountField.innerText = fldLen;
		}
	}

	function textCounter(field, countfield, maxlimit) {
		if (field.value.length > maxlimit) {
			field.value = field.value.substring(0, maxlimit-1);
			alert('You have entered the maximum allowed characters.');
			field.focus();
		} else {
			countfield.value = maxlimit - field.value.length;
		}
	}

	function textCounterHidden(field, maxlimit) {
		if (field.value.length > maxlimit) {
			field.value = field.value.substring(0, maxlimit-1);
			alert('You have entered the maximum of '+maxlimit+' characters.');
			field.focus();
		}
	}
	
// Remove leading and trailing whitespace from a string
	function trimWhitespace(string) {
		var newString  = '';
		var substring  = '';
		beginningFound = false;
		
		// copy characters over to a new string
		// retain whitespace characters if they are between other characters
		for (var i = 0; i < string.length; i++) {
			
			// copy non-whitespace characters
			if (string.charAt(i) != ' ' && string.charCodeAt(i) != 9) {
				
				// if the temporary string contains some whitespace characters, copy them first
				if (substring != '') {
					newString += substring;
					substring = '';
				}
				newString += string.charAt(i);
				if (beginningFound == false) beginningFound = true;
			}
			
			// hold whitespace characters in a temporary string if they follow a non-whitespace character
			else if (beginningFound == true) substring += string.charAt(i);
		}
		return newString;
	}
	
// Remove all spaces from a string
	function removeSpaces(string) {
		var newString = '';
		for (var i = 0; i < string.length; i++) {
			if (string.charAt(i) != ' ') newString += string.charAt(i);
		}
		return newString;
	}
	
//Return strings with numeric 0-9 only
	function JustNumbers ( argstr, numType ){
		var newstr = new String("")
		var nZero = String ("0").charCodeAt(0)
		var nNine = String("9").charCodeAt(0)
		var nDeci = String(".").charCodeAt(0);
		var nCh
	
		for (i = 0; i < argstr.length; i++ ){
			nCh = argstr.charCodeAt(i)
			if ( numType == 1 ) {
				if ( ( (nCh >= nZero) && (nCh <= nNine) ) || (nCh == nDeci)  ){
					newstr = newstr + argstr.charAt(i)
				}
			}else{
				if ( ( (nCh >= nZero) && (nCh <= nNine) ) ){
					newstr = newstr + argstr.charAt(i)
				}
			}
		}
		return newstr	
	}
	
//Credit Card validation functions;

	function SumIntString (argstr){
		var i = argstr.length - 1
		var nSum = new Number(0)
		
		for (i; i >= 0; i--){
			nSum = parseInt(argstr.charAt(i)) + nSum		
		}	
		return parseInt(nSum)
	}
	
	function ValidateCreditCard( strCardNumber ){
		var strOddNumbers = new String("")
		var strEvenNumbers = new String("")
		var strDoubled = new String("")
		var i = strCardNumber.length
		var i2
		var isValid = new Boolean (0)
		var nOddNumbers 
		var nEvenNumbers
		var nSumDigits
		var nDoubled
		
		if(strCardNumber.length < 13) {
			isValid = false;
		}else{
		//seperate odd and even digits into two strings	
			for (i; i >= 0; i--)
			{
				if (((strCardNumber.length-i) % 2) == 1)
				{
					strOddNumbers += strCardNumber.charAt(i)
				}
				 else
				{
					strEvenNumbers += strCardNumber.charAt(i)
				}		
			}
		//simply sum the odds	
			nOddNumbers = SumIntString(strOddNumbers)
		//but sum the double of the evens	
			nEvenNumbers = 0
			for (i = 0; i < strEvenNumbers.length; i++)
			{
				nDoubled = parseInt(strEvenNumbers.charAt(i)) * 2
				strDoubled = nDoubled.toString()
				nEvenNumbers = SumIntString(strDoubled) + nEvenNumbers
			}
		//add the sum of the two strings (odds and evens)
			nSumDigits = parseInt(nOddNumbers) + parseInt(nEvenNumbers)
		//divisible by 10? yes then valid, no then invalid	
			isValid = ((nSumDigits % 10) == 0)
		}
		return isValid
	}
	
// Internet Explorer holds references to objects that are not actually javascript objects. So if we use the objects in javascript it will give error. But the typeof operator identifies them as javascript objects( problem!!!). 
// Here we can use the isIEObject() function to identify those objects.
	function isIEObject(a) {
		return isObject(a) && typeof a.constructor != 'function';
	}

//This function returns true if a is an array, meaning that it was produced by the Array constructor or by the [ ] array literal notation.
	function isArray(a) {
		return isObject(a) && a.constructor == Array;
	}
	 
//This function returns true if a is one of the Boolean values, true or false. 
	 function isBoolean(a) 
	 {
		  return typeof a == 'boolean';
	 }
	
//This function returns true if a is an object or array or function containing no enumerable members.
	 function isEmpty(o) 
	 {
		  if (isObject(o)) 
	  {
			   for (var i in o) 
	   {
					return false;
			   }
		  }
		  return true;
	 }
	
	
//This function returns true if a is a function. Beware that some native functions in IE were made to look like objects instead of functions. This function does not detect that.Netscape is better behaved in this regard.
	 function isFunction(a) 
	 {
		  return typeof a == 'function';
	 }
	
// This function returns true if a is the null value.
	 function isNull(a) 
	 {
		  return typeof a == 'object' && !a;
	 }
	
//This function returns true if a is an object, array, or function. It returns false if a is a string, number, Boolean, null, or undefined.
	 function isObject(a) 
	 {
		 return (typeof a == 'object' && !!a) || isFunction(a);
	 }
	
// This function returns true if a is a string.
	 function isString(a) 
	 {
		 return typeof a == 'string';
	 }
	
// This function returns true if a is the undefined value. You can get the undefined value from an uninitialized variable or from an object's missing member.
	 function isUndefined(a) 
	 {
		 return typeof a == 'undefined';
	 } 

function CountWords(this_field, maxwords) {
var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}
return word_count;
}

function confirmBack(){
return "You will lose all of your progress on this application if you go to another page.  Are you sure you want to leave this page?";
}