<!--
	
	function updateWarning(){
		var warningMessage;
	
		//Warn people entering large numbers of requests that it could be lost...
		warningMessage = "--------------\n";
		warningMessage += "WARNING:\n";
		warningMessage += "--------------\n";
		warningMessage += "When entering multiple requests,\n";
		warningMessage += "do not refresh/reload page before\n";
		warningMessage += "all of the information is entered,\n";
		warningMessage += "your data could be lost and need\n";
		warningMessage += "to be re-entered.\n";
	
		
		alert(warningMessage);
		UpdateSubscribePage();
	}
	
	function UpdateSubscribePage(){
		var thisForm = document.forms[0];
		var ThisFormField = thisForm.TotalNumber;
		var TotalItems = ThisFormField.value;
		
		
		if (!isNaN(TotalItems)){
			if (TotalItems < 100){
				//is numeric and under 100, reload with QueryString
				thisForm.submitType.value = 'update';
				thisForm.submit();
			}else{
				//is over 100, warn.
				alert("Please, no more than 99 accounts at a time.");
			
				ThisFormField.value = 99;
				ThisFormField.focus();
				ThisFormField.select();
			}
			
		}else{
			alert("Number of subscriptions must be numeric.");
			
			ThisFormField.value = 1;
			ThisFormField.focus();
			ThisFormField.select();
		}
	}
	
	function ValidatePage(){
		var Validated = true;
		var ErrorCounter = 0;
		var stringOfBlankErrors = '';
		var stringOfOtherErrors = '';
		var finalErrorString = '';
		var thisForm = document.forms[0];
		var thisFormItem;
		var doneThisField;
		var checkedThisRadio;
		var ThisRadioChecked;
		
		//require that all fields be filled out, except PONum, Prefixes, Suffixes, and Address2
		for (i = 0; i < thisForm.elements.length; i++) {			
		
			thisFormItem = thisForm.elements[i];
			doneThisField = false;
			ThisRadioChecked = false;

			var fieldName = thisFormItem.name;
			var fieldNameAlt;
			
			
			if (fieldName != 'Submit' && fieldName != 'TotalNumber' && fieldName != 'submitType') {
				//create user-friendly field names
				
				switch(fieldName) {
					case 'HaveRead':
						fieldNameAlt = 'Program Subscription Rules';
						doneThisField = true;
						break;
					case 'BuyerName':
						fieldNameAlt = 'Your Name';
						doneThisField = true;
						break;
					case 'BuyerEmail':
						fieldNameAlt = 'E-mail Address';
						doneThisField = true;
						break;
					case 'AgencyName':
						fieldNameAlt = 'Agency Name';
						doneThisField = true;
						break;
					case 'AgencyNumber':
						fieldNameAlt = 'Agency Code No.';
						doneThisField = true;
						break;
					case 'PONumber':
						fieldNameAlt = 'Purchase Order No.';
						doneThisField = true;
						break;
				}	
				
				if (!doneThisField){
					for (x=1; x <= thisForm.TotalNumber.value; x++){
						if (!doneThisField){
							switch(fieldName) {
								case ('CustomerType' + x):
									fieldNameAlt = '#' + x + ' Existing or Prospect';
									doneThisField = true;
									break;
								case ('CustomerSegment' + x):
									fieldNameAlt = '#' + x + ' RSG or STG';
									doneThisField = true;
									break;
								case ('CustomerPrefix' + x):
									fieldNameAlt = '#' + x + ' Prefix';
									doneThisField = true;
									break;
								case ('CustomerFName' + x):
									fieldNameAlt = '#' + x + ' First Name';
									doneThisField = true;
									break;
								case ('CustomerLName' + x):
									fieldNameAlt = '#' + x + ' Last Name';
									doneThisField = true;
									break;
								case ('CustomerCompany' + x):
									fieldNameAlt = '#' + x + ' Company';
									doneThisField = true;
									break;
								case ('CustomerAddy1' + x):
									fieldNameAlt = '#' + x + ' Address 1';
									doneThisField = true;
									break;
								case ('CustomerCity' + x):
									fieldNameAlt = '#' + x + ' City';
									doneThisField = true;
									break;
								case ('CustomerState' + x):
									fieldNameAlt = '#' + x + ' State';
									doneThisField = true;
									break;
								case ('CustomerZIP' + x):
									fieldNameAlt = '#' + x + ' ZIP Code';
									doneThisField = true;
									break;
							}
						}
					}
				}
				
				if(!doneThisField){
					fieldNameAlt = 'UNKNOWN';
				}
				
				
					
				//must accept Program Subscription Rules
				if (fieldNameAlt == 'Program Subscription Rules') {
					if (!thisFormItem.checked){
    					ErrorCounter += 1;
						LastErrorID = fieldNameAlt
    					stringOfBlankErrors += '     \xB7 ' + fieldNameAlt + '\n';
    					Validated = false;
					}
				}
				
				if (fieldNameAlt != 'UNKNOWN' && fieldNameAlt != 'Program Subscription Rules'){
					//watch for radio buttons and dropdowns, as values are read differently
					if (fieldNameAlt.indexOf(" Existing or Prospect") >= 0){
						//radio button
						
						//don't check the same radio list repeatedly...
						if (fieldNameAlt != checkedThisRadio){
							checkedThisRadio = fieldNameAlt
							
							hasSelected = false;
							
							for (counter = 0; counter < thisForm.elements[fieldName].length; counter++){
								// loop through elements and find this radio list
								if (thisForm.elements[fieldName][counter].checked){
									hasSelected = true; 
								}
							}
							
							if (!hasSelected){
								//not selected
								ErrorCounter += 1;
								
								LastErrorID = fieldNameAlt
								stringOfBlankErrors += '     \xB7 ' + fieldNameAlt + '\n';
								Validated = false;
							}
						}
					}else if (fieldNameAlt.indexOf(" RSG or STG") >= 0){
						//radio button
						
						//don't check the same radio list repeatedly...
						if (fieldNameAlt != checkedThisRadio){
							checkedThisRadio = fieldNameAlt
							
							hasSelected = false;
							
							for (counter = 0; counter < thisForm.elements[fieldName].length; counter++){
								// loop through elements and find this radio list
								if (thisForm.elements[fieldName][counter].checked){
									hasSelected = true; 
								}
							}
							
							if (!hasSelected){
								//not selected
								ErrorCounter += 1;
								
								LastErrorID = fieldNameAlt
								stringOfBlankErrors += '     \xB7 ' + fieldNameAlt + '\n';
								Validated = false;
							}
						}
					}else if (fieldNameAlt.indexOf(" Prefix") >= 0 || fieldNameAlt.indexOf(" State") >= 0){
						//dropdowns
						if(thisFormItem.selectedIndex==0){
							//not selected
							ErrorCounter += 1;
							
							LastErrorID = fieldNameAlt
							stringOfBlankErrors += '     \xB7 ' + fieldNameAlt + '\n';
							Validated = false;
						}
					}else{
						//typical textfield with a "value" property
						fieldValue = thisFormItem.value;

						if ((fieldValue != null && fieldValue != '') && (fieldNameAlt == 'Agency Code No.' && fieldValue.length < 4 && fieldValue.length > 0)){
							//pad the Agent# with zeros
							var NumberLength = 4 - fieldValue.length;
							
							do{
								fieldValue = '0' + fieldValue; 
								NumberLength -= 1; 
							}while (NumberLength > 0)
						}
						
						if (fieldValue == 'First Name' || fieldValue == 'Last Name') {
							//don't allow default values
							
							//set value, so that validation below doesn't catch it again
							fieldValue = '';
							
							thisFormItem.focus();
							thisFormItem.select();
							
							ErrorCounter += 1;
							LastErrorID = fieldNameAlt
							stringOfBlankErrors += '     \xB7 ' + fieldNameAlt + '\n';
							Validated = false;
						}else if ((fieldValue == null || fieldValue == '') && (fieldNameAlt != 'Purchase Order No.')) {
							//general catch-all required fields
							thisFormItem.focus();
							thisFormItem.select();
							
							ErrorCounter += 1;
							LastErrorID = fieldNameAlt
							stringOfBlankErrors += '     \xB7 ' + fieldNameAlt + '\n';
							Validated = false;
						}
						
						if (fieldValue != null && fieldValue != '') {
							switch(fieldNameAlt) {
								case 'Your Name':
									nameRegEx=/([0-9]|!|@|#|\$|%|\^|&|\*|=|\+|\{|\}|\[|\]|\?)+/g;
									if ((nameRegEx.exec(fieldValue) != null) && (fieldValue.length >= 5)){
										thisFormItem.focus();
										thisFormItem.select();
										ErrorCounter += 1;
										LastErrorID = fieldNameAlt
										stringOfOtherErrors += '     \xB7 ' + fieldNameAlt + ' (must be alphabetic)\n';
										Validated = false;
									}
									break;
								case 'E-mail Address':
									//simple email validation -more advanced used on server-side
									nameRegEx=/^([a-zA-Z0-9_\-\.])+@((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|((([a-zA-Z0-9\-])+\.)+([a-zA-Z\-])+))$/
									if (nameRegEx.exec(fieldValue) == null){
										thisFormItem.focus();
										thisFormItem.select();
										ErrorCounter += 1;
										LastErrorID = fieldNameAlt
										stringOfOtherErrors += '     \xB7 ' + fieldNameAlt + ' (must be a valid address)\n';
										Validated = false;
									}
									break;
								case 'Agency Name':
									nameRegEx=/(!|@|\$|%|\^|\*|=|\+|\{|\}|\[|\]|\?)+/g;
									if (nameRegEx.exec(fieldValue) != null){
										thisFormItem.focus();
										thisFormItem.select();
										ErrorCounter += 1;
										LastErrorID = fieldNameAlt
										stringOfOtherErrors += '     \xB7 ' + fieldNameAlt + ' (must be alphanumeric)\n';
										Validated = false;
									}
									break;
								case 'Agency Code No.':
									nameRegEx=/^\d{1,4}$/
									if (nameRegEx.exec(fieldValue) == null){
										thisFormItem.focus();
										thisFormItem.select();
										ErrorCounter += 1;
										LastErrorID = fieldNameAlt
										stringOfOtherErrors += '     \xB7 ' + fieldNameAlt + ' (1-4 digits)\n';
										Validated = false;
									}
									break;
								case 'Purchase Order No.':
									//no validation at this time...
									break;

							}
						}
					}
					
					
				}
			}
		}
		
		if (Validated){
			//disable the submit button, then send the form
			document.forms[0].onSubmit = "return false;";

			return true;
		}else{
			if (ErrorCounter >= 22){
				//don't display too many errors
				finalErrorString += 'Please, make sure you fill in all required fields.\n(required fields are marked with an asterisk)\n\n';
			}else if (ErrorCounter > 1){
				if (stringOfBlankErrors != ''){
					finalErrorString += 'The following fields must be entered:\n';
					finalErrorString += stringOfBlankErrors + '\n';
				}
				if (stringOfOtherErrors != ''){
					finalErrorString += 'The following fields do not contain valid data:\n';
					finalErrorString += stringOfOtherErrors + '\n';
				}
				finalErrorString += 'Please correct these fields and try again.\n';
			}else{
				if (LastErrorID == 'Program Subscription Rules'){
					finalErrorString = 'You must read and understand the \"' + LastErrorID + '\" before submitting.\n\n';
				}else if (stringOfBlankErrors != ''){
					finalErrorString = 'You must enter a value for the \"' + LastErrorID + '\" field.\n\n';
				}else{
					switch(LastErrorID) {
						case 'Your Name':
							finalErrorString = 'Your Name must be alphabetic. No numbers or special characters\n\n';
							break;
						case 'E-mail Address':
							finalErrorString = 'You must enter a valid e-mail address.\n\n';
							break;
						case 'Agency Name':
							finalErrorString = 'The Agency Name must be alphanumeric. No special characters\n\n';
							break;
						case 'Driver Code No.':
							finalErrorString = 'The Driver Code No. must be 1-4 digits\n(or left blank if not applicable).\n\n';
							break;
						case 'Purchase Order No.':
							finalErrorString = 'The Purchase Order No. is not valid.\n(may be left blank if not applicable).\n\n';
							break;
						default:
							finalErrorString = 'There is an error with your form input, please verify it.\n\n';
							break;
					}		
				}	
			}
			alert(finalErrorString);
			
			return false;
		}
	}
//-->