// Duplication Form Validation Routines
// M. Paric
// 08-28-2003
//
// These routines are called from specific pages when a form is submitted.
// The routines check the variables in these ways:
//	validateTextFields = List of Fields that are required for form submission.
//						Also checks for proper field format.
//	textFieldLables = Text for Alert Box indicating which field needs to be corrected.
//						Used in conjuction with validateTextFields array, must match length and order.
//	checkTextFields = List of Fields to check for proper format only. Not requried fields.
//	validateRadioFields = List of radio-type form fields that are required for form submission.
//							Field-specific rules are covered in this loop.
//	radioFieldLabels = Text for Alert Box indicating which radio fields need to be corrected.
//						Used in conjuction with validateRadioFields, must match length and order.


// Alert message variables.
var missingPrefix = "You did not enter a value into the "
var missingSuffix = " field. This is a required field. Please enter it now."

// Validate Registration Form
function validate_request(form_type) {

	validate_userinfo(form_type);
	validate_spots();
	
}




// Validate Profile Page
function validate_userinfo(form_type) {

validateTextFields = new Array ('dupe_date_requested','dupe_date_due','dupe_ordered_by',
							'dupe_contact_phone','dupe_client_name','dupe_advertiser_name');
								
textFieldLabels = new Array ('Date Requested','Due Date','Ordered By',
							'Contact #','Client Name','Advertiser Name');

if (form_type > 0) {
	validateTextFields.push('dupe_po_number','dupe_job_number');
	textFieldLabels.push('PO Number','Job Number');
	}
							
for (i=0;i<validateTextFields.length;i++) {
	thisValue = validateTextFields[i];
	if (document.infoform[thisValue] != null) {
		if (document.infoform[thisValue].value == "") {
			alert(missingPrefix + textFieldLabels[i] + missingSuffix);
			document.infoform[thisValue].focus();
			return false;
			}
		if(!checkField(thisValue,'infoform'))
			return false;
		}
	}
}

// Validate Spots
function validate_spots() {



}


function validate_sample() {
validateTextFields = new Array ('USER_EMAIL',
								'USER_LOGIN','USER_PASSWORD','USER_PASSWORD_2');
								
textFieldLabels = new Array ('Email Address',
							'Login Name','Password','Password Verification');
							
checkTextFields = new Array ('USER_FAX','USER_PHONE');

for (i=0;i<validateTextFields.length;i++) {
	thisValue = validateTextFields[i];
	if (document.infoform[thisValue] != null) {
		if (document.infoform[thisValue].value == "") {
			alert(missingPrefix + textFieldLabels[i] + missingSuffix);
			document.infoform[thisValue].focus();
			return false;
			}
		if(!checkField(thisValue,'infoform'))
			return false;
		}
	}
	
for (i=0;i<checkTextFields.length;i++) {
	thisValue = checkTextFields[i];
	if (document.infoform[thisValue].value != "") {
		if (!checkField(thisValue,'infoform')) {
			document.infoform[thisValue].focus();
			return false;
			}
		}
	}

if (!document.infoform["USER_LAST_NAME"].value && !document.infoform["USER_BUSINESS_NAME"].value) {
		alert("You must have at least the Last Name or Company Name entered");
		document.infoform["USER_LAST_NAME"].focus();
		return false;
		}
		
if (document.infoform["USER_PASSWORD"].value.length < 5) {
	alert("Password must be at least 5 characters long. Please re-enter");
	document.infoform["USER_PASSWORD"].focus();
	return false;
	}

if (document.infoform["USER_PASSWORD"].value != document.infoform["USER_PASSWORD_2"].value) {
	alert("Passwords do not match. Please re-enter");
	document.infoform["USER_PASSWORD_2"].value = "";
	document.infoform["USER_PASSWORD_2"].focus();
	return false;
	}
}

// Supporting Routines
//
// Validates non-required fields for correct format. (i.e. phone, zip, date, etc.)
function checkEntryOnly(formName) {

for (i=0;i<checkTextFields.length;i++) {
	thisValue = checkTextFields[i];
	if (eval('document.' + formName + '[thisValue] != null')) {
		if(eval('document.' + formName + '[thisValue].value')) {
			if(eval('!checkField(thisValue,\'' + formName + '\')'))
				return false;
			}
		}
	}
}

function countCharacters() {
// Check for character limit
testString = document.ABSTRACTS.ABSTRACT.value;
characterNum = testString.length;
document.ABSTRACTS.charactercount.value = characterNum;
if (characterNum > 500) {
	alert('Entry is too long. Limited to 500 characters');
	return false;
	}
}

