/* 
RFS # 021205112545 - improve email edit. domain suffix must be a length of 2 or 3.
$Author: dp011476 $ User who last changed the file 
$Date: 2011/05/04 20:37:31 $ Date and time of last checkin 
$Modtime: 1/26/05 9:58a $ Date and time of last modification 
$Revision: 1.25.2.4.62.1.36.1.54.1.16.1.4.1.18.1.56.1.110.1.48.1.36.1.118.1.100.1 $ VSS version number 
*/
var documentList	= new Array("doc","xls","txt","htm","html","jsp","java","csv","prop","pdf","ppt");
var imageList		= new Array("gif","jpg","bmp","png");

var errorMessage = new Array("WARNING: Please Check the Highlighted\nFields for Errors or Omitted Information.",
								"ATTENTION: S.V.P. vérifier les champs surlignés pour omissions ou erreurs.",
								"La ADVERTENCIA: Verifique por favor el Destacado\nFields para Errores o Informacion Omitida.");
								
var additionalInfo = "";
var optFields = new Array();
								
function hasValue(field)	{
	if(field && field.value) {
		if(field.value.length < 1)	{
			return false;
		} else if(field.value.indexOf(" ") == 0) {
			return true;
		} else {
			return true;
		}
	} else {
		return false;
	}
}
								
function getValidColor(id) {
	className = document.getElementById(id).className;
	switch(className) {
		case "tab" :
			return "#594404";	
			break
		case "drillNav" : 
			return "#000033";
			break
		
		case "sectionHeader" :
			return "#424242";
			break
		
		case "mroSolutionHeader" :
			return "#424242";
			break
		
		case "mroSolution" :
			return "#424242";
			break
		
		case "subLink" :
			return "#424242";
			break
		
		case "hiddenWhiteText" :
			return "#FFFFFF";	
			break
			
		case "hiddenGreenText" :
			return "#EFF2EE";	
			break

		case "menuLink" :
			return "#FFFFFF";	
			break
		
		case "dropDown" :
			return "#594404";	
			break
		
		case "fieldLabel" :
			return "#594404";
			break
		
		case "fieldLabelRight" :
			return "#594404";
			break
		
		case "instruction" :
			return "#594404";
			break
		
		case "instructionSmall" :
			return "#594404";
			break
		
		case "textBox" :
			return "#594404";
			break
		
		case "tableHeader" :
			return "#424242";
			break
		
		case "tableText" :
			return "#424242";
			break
		
		case "tableSecondaryText" :
			return "#993300";
			break
		
		case "tableTextBold" :
			return "#424242";
			break
		
		case "tableTextParametricBold" :
			return "#424242";
			break
		
		case "psTableText" :
			return "#424242";
			break
		
		case "tableFooter" :
			return "#993300";
			break
		
		case "paraText" :
			return "#424242";
			break
		
		case "footerText" :
			return "#696969";
			break
		
		case "footerLink" :
			return "#696969";
			break
		
		case "link" :
			return "#424242";
			break
		
		case "brownLink" :
			return "#594404";
			break
		
		case "smallBrownLink" :
			return "#594404";
			break
		default :
			return "#424242";
	}
}

function requiredField(name,label,type,fmt) {
	this.name 	= name;
	this.label 	= label;
	this.type  	= type;
	this.fmt	= fmt;
}

function formattedNumber(name,length,desc) {
	this.name = name;
	this.length = length;
	this.desc = desc;
}

function dependantFields(i1, i2){
	//this object function represents two inputs that are dependant on each other.
	//the second input must have a value only if the first does
	this.i1			= i1;	
	this.i2			= i2;
	this.yo			="yo";
}

function textArea(name,minLength,maxLength) {
	this.name = name;
	this.minLength = minLength;
	this.maxLength = maxLength;
}

function creditCard(name,type) {
	this.name = name;
	this.type = type;
}

function dateField(mon,day,year) {
	this.month = mon;
	this.day   = day;
	this.year  = year;
}

function genericField(val){
	this.value = val;
}

function emailConfirmation(email_1,email_2) {
	this.emailOne = email_1;
	this.emailTwo = email_2;
}

function fileField(name,extList) {
	this.name = name;
	this.extList = extList;
}

function dateSpan(toM,toD,toY,fromM,fromD,fromY) {
	this.toMonth 	= toM;
	this.toDay   	= toD;
	this.toYear  	= toY;
	this.fromMonth 	= fromM;
	this.fromDay   	= fromD;
	this.fromYear  	= fromY;
}
function numberSpan(fromNumber,toNumber) {
	this.fromNumber= fromNumber;
	this.toNumber= toNumber;
}

function limitedDateSpan(toM,toD,toY,fromM,fromD,fromY,spanType,span) {
	this.toMonth 	= toM;
	this.toDay   	= toD;
	this.toYear  	= toY;
	this.fromMonth 	= fromM;
	this.fromDay   	= fromD;
	this.fromYear  	= fromY;
	this.spanType = spanType; // M,Y
	this.span	= span;
}

function singleFieldDateSpan(sDate,eDate,fmt) {
	this.startDate 	= sDate;
	this.endDate   	= eDate;
	this.fmt  		= fmt;
}

function selectBox(name,badIndex) {
	this.name = name;
	this.index = badIndex;
}

function getCardNumLength(type) {
	switch(type) {
		case "AMEX":
			return 15;
		case "VISA":
			return 16;
		case "MAST":
			return 16;
		case "DINE":
			return 14;
		default:
			return 16;
	}
}

function getAllowedExtensionList(ext) {
	if(ext.indexOf("List") > -1)
		return eval(ext);
	else
		return eval(ext + "List");
}

function validateColor(id,color) {
	if(color)	{
		if(document.getElementById(id))	{
			document.getElementById(id).style.color = color;
		}
	} else {
		if(document.getElementById(id))	{
			document.getElementById(id).style.color = getValidColor(id);
		}
	}
}

function optionalParam(paramFieldLabel) {
	var paramFieldName = paramFieldLabel.replace("_label", "");
	for(var i = 0; i < optFields.length; i++) {
		var test = optFields[i];
		if(test == paramFieldName)
			return true;
	}

	return false;
}

function validatePage(fieldArray,lang,_addInfo,_optFields) {
	invalidColor = "#D63B41";
	additionalInfo = "";
	if(_addInfo)
		additionalInfo = _addInfo;
	
	if(_optFields)
		optFields = _optFields;
	else
		optFields = new Array();
		
	var first	 = new String("");
	var result 	 = true;
	var language = 0;
	if(lang)
		language = lang;
	for(var i = 0; i < fieldArray.length; i++) {
		var item = fieldArray[i];
		switch(item.type.toUpperCase()) {
			case "TEXT" :
				if(validText(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "TEXTAREA" :
				if(validTextAreaChk(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "FILE" :
				if(validFile(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name.name;
					result = false;
				}
				break
			case "PASSWORD" :
				if(validPassword(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "MINO" :
				if(validMINO(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "MFRID" :
				if(validMFRID(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "GROUPSERIAL" :
				if(validGROUPSERIAL(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "ITEMNUMBER" :
				if(validItemNumber(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "CVIPONUMBER" :
				if(validCVIPONumber(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
				
			case "PHONE" :
				if(validPhone(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "CREDIT_CARD" :
				if(validateCard(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "OCN" :
				if(validOCN(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "SHIPPER_CTL_NO" :
				if(validShpCtlNo(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "EMAIL" :
				if(validEmail(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "EMAIL_COMPARE" :
				if(validEmailCompare(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "FORMATTED_NUMBER" :
				if(validFormattedNumber(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "NUMBER" :
				if(validNumber(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "CARRIER_NUMBER" :
				if(validCarrierNumber(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "NUMBER_SPAN" :
				if(validNumberSpan(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "SINGLE_FIELD_DATE":
				if(validSingleFieldDate(document.forms[0].elements[item.name],item.label,item.fmt))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "SINGLE_FIELD_DATE_SPAN":
				if(validSingleFieldDateSpan(item.name,item.label,item.fmt))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "DATE" :
				if(validDate(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name.month;
					result = false;
				}
				break
			case "AFTER_TODAY" :
				if(afterToday(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name.month;
					result = false;
				}
				break
			case "DATE_SPAN" :
				if(validDateSpan(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name.toMonth;
					result = false;
				}
				break
			case "LIMITED_DATE_SPAN" :
				if(validLimitedDateSpan(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name.toMonth;
					result = false;
				}
				break
			case "DEPENDANTFIELDS" :	
				if(validDependantFields(item.name, item.label)){
					validateColor(item.label);
				}else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name.i2.name;
					result = false;
				}
				break
			case "MULTI_ENTRY":
				if(validMultiEntry(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name.name;
					result = false;
				}
				break
			case "SELECT" :
				if(validSelection(item.name,item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name.name;
					result = false;
				}
				break
			case "CHECKBOX" :
				if(isChecked(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
			case "MI_LOC" :
				if(validMiLoc(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					if(first.length == 0)
						first = item.name;
					result = false;
				}
				break
				
			case "RADIO" :
				if(validRadio(document.forms[0].elements[item.name],item.label))
					validateColor(item.label);
				else {
					validateColor(item.label,invalidColor);
					result = false;
				}
				break
			case "INVALID" :
				validateColor(item.label,invalidColor);
				if(first.length == 0)
					first = item.name;
				result = false;
				break
			case "VALID" :
				validateColor(item.label);
				break
			default :
				result = false;
		}
	}
	if(first.length > 0)	{
		try {
			if(document.forms[0].elements[first])
				document.forms[0].elements[first].focus();
		} catch(e) {}
	}
	if(!result)
		alert(errorMessage[language] + "\n\n" + additionalInfo);
	return result;
}

function getFieldLabel(_objID) {
	var t = document.getElementById(_objID).innerHTML;
	if(t.indexOf("<SELECT") > -1 ||
		t.indexOf("<INPUT") > -1 ||
		t.indexOf("<A") > -1) {
		t = t.substring(0,t.indexOf("<"))
	} else {
		while(t.indexOf("<") > -1) {
			t = (t.substring(0,t.indexOf("<")) + " " + t.substring(t.indexOf(">")+1,t.length));
		}
	}
	if(t.indexOf("&nbsp;") > -1)
		t = t.replace(new RegExp("[&nbsp;]","g"),"");

	if(t.indexOf(":") > -1)
		t = t.replace(new RegExp("[:]","g"),"");

	return t;
}

function validMiLoc(field,label)	{
	if(field) {
		if(field.value.length < 1)	{
			additionalInfo += "-- " + getFieldLabel(label) + " is Empty.\n";
			return false;
		} else if(field.value.indexOf(" ") == 0) {
			additionalInfo += "-- " + getFieldLabel(label) + " begins with a space.\n";
			return false;
		} else if(field.value.length != 4) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid MI Location.\n";
			return false;
		} else if(field.value.length == 4) {
			var test = field.value;
			if(!isNaN(test.substring(0,2)) && isNaN(test.substring(2))) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid MI Location.\n";
				return false;
			}
			return true;
		} else {
			return true;
		}
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.\n";
		return false;
	}
}

function validSingleFieldDateSpan(field,label,fmt){
	if (validSingleFieldDate(document.forms[0].elements[field.startDate],label,fmt)){
		if (validSingleFieldDate(document.forms[0].elements[field.endDate],label,fmt)){
			var toDate 		= getDateFromSingleFieldDate(document.forms[0].elements[field.startDate],fmt);
			var fromDate 	= getDateFromSingleFieldDate(document.forms[0].elements[field.endDate],fmt);
			if(toDate <= fromDate)	{
				return true;
			}
			additionalInfo += "-- " + getFieldLabel(label) + " does not contain a valid date range.\n";
		}
		else {
			additionalInfo += "-- " + getFieldLabel(label) + " End Date is invalid.\n";
		}	
	}
	else {
		additionalInfo += "-- " + getFieldLabel(label) + " Start Date is invalid.\n";
	}	
	return false;
}



function validSingleFieldDate(field,label,fmt){
	if(field && fmt){
		var tempField = "";

		if(field.value.length != fmt.length){
			for (fmtIdx=0,fieldIdx=0;fmtIdx < fmt.length && fieldIdx < field.value.length;fmtIdx++){
				if (fmt.substr(fmtIdx,1).toUpperCase() != 'M' && fmt.substr(fmtIdx,1).toUpperCase() != 'D' && fmt.substr(fmtIdx,1).toUpperCase() != 'Y'){
					tempField = tempField + fmt.substr(fmtIdx,1);
					if (field.value.substr(fieldIdx,1) == fmt.substr(fmtIdx,1)){
						fieldIdx++;
					}
				}
				else {
					tempField = tempField + field.value.substr(fieldIdx,1);
					fieldIdx++;
				}
			}
			field.value = tempField;
		}
	
		if(field.value.length != fmt.length){
			additionalInfo += "-- " + getFieldLabel(label) + " must be in '"+fmt+"' format.\n";
			return false;
		}

		var curDateField = parseSingleFieldDate(field,fmt);

		if (!curDateField){
			additionalInfo += "-- " + getFieldLabel(label) + " must be in '"+fmt+"' format.\n";
			return false;
		}		
		else {
			return validDate(curDateField,label,true);
		}
	}
	else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.\n";
		return false;
	}
}

function getDateFromSingleFieldDate(field,fmt){
	var curDateField = parseSingleFieldDate(field,fmt);
	if (!curDateField)
		return null;
	
	var passedDate = new Date();
	passedDate.setFullYear(parseInt(curDateField.year,10),parseInt(curDateField.month,10)-1,parseInt(curDateField.day,10));

	return passedDate;
}

function parseSingleFieldDate(field,fmt){
	var month = '';
	var day = '';
	var year = '';
	if (fmt == 'mm/dd/yy' || fmt == 'mm-dd-yy'){
		if (field.value.substring(2,3) != fmt.substring(2,3) || field.value.substring(5,6) != fmt.substring(5,6)){
			//wrong seperator
			return null;
		}
		month = field.value.substring(0,2);
		day = field.value.substring(3,5);
		year = field.value.substring(6,8);
	}
	else if (fmt == 'mm/dd/yyyy' || fmt == 'mm-dd-yyyy'){
		if (field.value.substring(2,3) != fmt.substring(2,3) || field.value.substring(5,6) != fmt.substring(5,6)){
			//wrong seperator
			return null;
		}
		month = field.value.substring(0,2);
		day = field.value.substring(3,5);
		year = field.value.substring(6,10);
	}
	else if (fmt == 'dd-mm-yyyy'){
		if (field.value.substring(2,3) != fmt.substring(2,3) || field.value.substring(5,6) != fmt.substring(5,6)){
			//wrong seperator
			return null;
		}
		day = field.value.substring(0,2);
		month = field.value.substring(3,5);
		year = field.value.substring(6,10);
	}
	else {
		additionalInfo += "-- unknown date format.\n";
		return null;
	}

	if(year.length == 3) {
		return null;
	} else if(year<100) {
		if(parseInt(year,10)<10)
			year="200" + parseInt(year,10);
		else if(parseInt(year,10)<70)
			year="20" + parseInt(year,10);
		else
			year="19" + year;
	} 
	return new dateField(month,day,year);
}

function validText(field,label)	{
	if(field) {
		if(field.value.length < 1)	{
			additionalInfo += "-- " + getFieldLabel(label) + " is Empty.\n";
			return false;
		} else if(field.value.indexOf(" ") == 0) {
			additionalInfo += "-- " + getFieldLabel(label) + " begins with a space.\n";
			return false;
		} else {
			return true;
		}
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.\n";
		return false;
	}
}

//This function name was changed from validTextArea to validTextAreaChk because a function named
//validTextArea is also defined in the ccm.js.  The functionality of these two validTextArea functions 
//are different and therefore depending upon how they are loaded, sometimes the function defined in ccm.js
//would be used and sometimes the below function would be used.  Therefore remove the conflicting situation
//and to minimize the impact of the change, the name of the validTextArea function below was changed since
//this function is only being used internal to this file.
function validTextAreaChk(field,label)	{
	var text = document.forms[0].elements[field.name];
	if(text) {
		if(validText(text,label)) {
			var textLength = text.value.length;
			if(field.minLength > textLength || field.maxLength < textLength) {
				if (field.minLength != field.maxLength) {
					additionalInfo += "-- " + getFieldLabel(label) + " length is invalid. Please enter between " + field.minLength + " and " + field.maxLength + " characters.\n";
				}
				else{
					additionalInfo += "-- " + getFieldLabel(label) + " length is invalid. Please enter " + field.minLength + " characters.\n";
				}
				return false;
			} else {
				return true;
			}
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function validDependantFields(field, label) {
	if(completed(field.i1))
		if(completed(field.i2))
			return true;
		else{
			//alert("Please enter a " + getFieldLabel(label) + " value.");
			return false;
		}
	else
		return true;
}	

function completed(i){
//this function is a helper to validDependantFields()
//add input types as needed
	var iType = i.type;	
	if(iType.indexOf("select") > -1){
		var count = -1;
		if(i.options[0].value == "")
			count = 0
		if(i.selectedIndex > count)
			return true;
		else
			return false;				
	} else if(iType == "text"){
		if(i.value.length < 1)
			return false;
		else
			return true;
			
	}
}		

function validFile(field,label) {
	var fileName = document.forms[0].elements[field.name];
	var ext		 = field.extList;
	if(fileName && ext) {
		if(fileName.value.length < 1) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid file.  " + getFieldLabel(label) + " was not provided.\n";
			return false;
		} else if(fileName.value.indexOf(" ") > -1) {
			var justTheName = fileName.value.substring(fileName.value.lastIndexOf("\\") + 1, fileName.value.length);
			if(justTheName.indexOf(" ") > -1) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not valid.  " + getFieldLabel(label) + " \"" + justTheName + "\" contains a space.\n";
				return false;
			}
		} 
		
		if(fileName.value.indexOf("\\") < 0) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid file.  No directory path provided.\n";
			return false;
		} else if(fileName.value.indexOf(":") < 1) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid file.\n";
			return false;
		} else if(fileName.value.indexOf(".") < 1) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid file.  No file extension.\n";
			return false;
		} else {
			var extension = fileName.value.substring(fileName.value.indexOf(".") + 1, fileName.value.length);
			var list = getAllowedExtensionList(ext);
			for(r = 0; r < list.length; r++) {
				if(extension == list[r])
					return true;
			}
			additionalInfo += "-- " + getFieldLabel(label) + " is not valid.  The file extension does not match the supported types (" + list + ")\n";
			return false;
		}
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is not a valid file.\n";
		return false;
	}
}

function validPassword(field,label)	{
	if(field) {
		if ((field.value.length < 5) ||
			(8 < field.value.length)){
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid length.\n";
			return false;
		} else if(lettersOnly(field.value)) {
			return true;
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid format.\n";
			return false;
		}
	} else {
		return false;
	}
}

function validMFRID(field,label) {
	if(field) {
		if(validNumber(field,label)) {
			if(field.value.length < 5) {
				var temp = "";
				for(r=5; r > field.value.length; r--)
					temp += "0";
				field.value = temp + field.value;
				return true;
			} else if(field.value.length == 5) {
				return true;
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid manufacturer id.\n";
				return false;
			}
		} else
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid manufacturer id.\n";
			return false;
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.\n";
		return false;
	}
}

function validGROUPSERIAL(field,label) {
	if(field) {
		if(field.value.length == 6) {
			if(isNaN(field.value.substring(0,1))) {
				if(isNaN(field.value.substring(1,6))) {
					additionalInfo += "-- " + getFieldLabel(label) + " is not a valid group serial number.\n";
					return false;
				} else
					return true;
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid group serial number.\n";
				return false;
			}
		} else if(field.value.length == 7) {
			if(isNaN(field.value.substring(0,1))) {
				if(isNaN(field.value.substring(2,7))) {
					additionalInfo += "-- " + getFieldLabel(label) + " is not a valid group serial number.\n";
					return false;
				} else {
					field.value = field.value.substring(0,1) + field.value.substring(2,7);
					return true;
				}
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid group serial number.\n";
				return false;
			}
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid group serial number.\n";
			return false;
		}
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.\n";
		return false;
	}
}

function validMINO(field,label)	{
		var regexpChar 	= new RegExp("[A-Za-z]+","gi");
		var regexpDgt 	= new RegExp("[0-9]+","gi");
		var regexpOnlyCharDig 	= new RegExp("[^A-Za-z0-9]+","gi");
		field.value = field.value.replace(regexpOnlyCharDig,'');
		
		if(isNaN(field.value)) {
			var beginCount = "";
			var endCount = "";
			var charLoc = "--";
			for(x=0; x < field.value.length;x++) {
				regexpChar.compile("[A-Za-z]+","gi");
				regexpDgt.compile("[0-9]+","gi");
				s = field.value.substr(x,1);
				if(regexpChar.exec(s)) {
					if(charLoc == "--") {
						charLoc = s;
					} else {
						additionalInfo += "-- " + getFieldLabel(label) + " is not a valid motion part number.\n";
						return false;
					}
						
				} else if(regexpDgt.exec(s)) {
					if(charLoc == "--") {
						beginCount += s;
					} else {
						endCount += s;
					}
				} else {
					additionalInfo += "-- " + getFieldLabel(label) + " is not a valid motion part number.\n";
					return false;
				}
			}
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid motion part number.\n";
			return false;
		}

		if(beginCount.length == 0 || endCount.length == 0) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid motion part number.\n";
			return false;
		} else {
			var temp = "";
			for(r=5; r > beginCount.length; r--)
				temp += "0";

			beginCount = temp + beginCount;
			temp = "";
			for(r=5; r > endCount.length; r--)
				temp += "0";

			endCount = temp + endCount;

			field.value = beginCount + charLoc + endCount;
			return true;
		}
			
}

/*
function validMINO(field,label)	{
	if(field) {
		if(field.value.length == 9)
			field.value = "00" + field.value;
		else if(field.value.length == 10)
			field.value = "0" + field.value;
		else if(field.value.length < 9) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid mino.\n";
			return false;
		} else if(field.value.length > 12 && field.value.indexOf(" ") != 5) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid mino.\n";
			return false;
		} else if(field.value.indexOf(" ") == 5) {
			field.value = field.value.substring(0,field.value.indexOf(" ")) + field.value.substring(field.value.indexOf(" ")+1,12);
		}
		if((field.value.length == 12 && !isNaN(field.value.substring(6,7))) ||
			(field.value.length == 11 && !isNaN(field.value.substring(5,6)))) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid mino.\n";
			return false;
		} else
			return true;
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.\n";
		return false;
	}
}
*/

function validItemNumber(field,label)	{
	if(field && hasValue(field)) {
		if(field.value.length < 8 && !isNaN(field.value)) {
			while (field.value.length < 8) {
				   field.value = "0" + field.value;
			}
		}
		if(field.value.length != 8) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid item number.\n";
			return false;
		} else if(field.value.substring(0,1).toUpperCase() == "Z" && !isNaN(field.value.substring(1,8))) {
			return true;
		} else if(isNaN(field.value)) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid item number.\n";
			return false;
		} else
			return true;
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.\n";
		return false;
	}
}

function validCVIPONumber(field,label)	{
	if(field) {
		if(validNumber(field,label)) {
			if(field.value.length < 8 &&
				field.value.length > 0) {
				var temp = "";
				for(r=8; r > field.value.length; r--)
					temp += "0";
				field.value = temp + field.value;
				return true;
			} else if(field.value.length == 8) {
				return true;
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid po number.\n";
				return false;
			}
		} else
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid po number.\n";
			return false;
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.\n";
		return false;
	}
}

function validPhone(field,label)	{
	if(field) {
		if(field.value.length < 1) {
			additionalInfo += "-- " + getFieldLabel(label) + " is empty.\n";
			return false;
		}
		if(field.value.length < 10) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid phone number.  e.g. (205) 956-1122\n";
			return false;
		}
		var num = stripNonNumbers(field.value);
		if(num.length < 10 || isNaN(num)) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid phone number.  e.g. (205) 956-1122\n";
			return false;
		} else {
			field.value = num;
			return true;
		}
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is invalid.  e.g. (205) 956-1122\n";
		return false;
	}
}

function validCreditCard(field,label)	{
	var cc = document.forms[0].elements[field.name];
	if(cc) {
		var num = stripNonNumbers(cc.value);
		var ccNumLength = parseInt(getCardNumLength(field.type),10);
		if(isNaN(num) || num.length != ccNumLength) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid credit card.\n";
			return false;
		} else {
			cc.value = num;
			return true;
		}
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is not a valid credit card.\n";
		return false;
	}
}

//**************************************
//     
// Name: Credit Card Validator
// Description:These functions thoroughl
//     y attempt to invalidate American Express
//     , Discover, MasterCard and Visa with len
//     gth, character validation, prefix matchi
//     ng, check digit, and expiration date tes
//     ts. The html test document by no means w
//     ill attempt to forward your credit card 
//     numbers. The action of the form is set t
//     o an invalid URL
// By: vsim
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=2493&lngWId=2//for details.//**************************************
//     
/*
validateCard(cardNumber,cardType,cardMonth,cardYear)
	parameters:
		all paramaters are string values.
		Month & Year come from the select input fields in the form, so they are defined.
		cardType can be:
			'a' for American Express
			'd' for Discover
			'm' for MasterCard
			'v' for Visa
	description:
		this function will check string length, valid characters, specific credit card prefixes and test
		the Mod 10 (LUHN Formula) for validating possible credit card numbers. this function can only
		authorize that the given card data is potentially valid. You would still need to run actual
		card validation routines to verify the actual account.
	returns:
		this function returns true if the card number could be valid for the card type and expiration date.
		false otherwise.	
supporting functions:
mod10( cardNumber )
	parameters:
		this function takes the text string card number and runs the Mod 10 formula on its respective digits.
	description:
		Mod 10 is the check digit formula for the supported cards these functions attempt to validate.
	returns:
		this function returns true if the number passes the check digit test.
		false otherwise.
expired( cardMonth, cardYear )
	parameters:
		this function takes the text string values given by the html form.
	description:
		this function basically will check to make sure todays date is less than the expiration date the user inputs.
		this function is not locked into using 2 digit dates.
	returns:
		this fucntion returns true if the card is expired.
		false otherwise.
*/

function mod10( cardNumber ) { // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;

   	for( i = 0; i < cardNumber.length; ++i )
   		ar[i] = parseInt(cardNumber.charAt(i));

   	for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
   		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
   		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
   	}										 // if the double digit is > 9, ADD those individual digits together 


   	for( i = 0; i < ar.length; ++i )
   		sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds

   	return (((sum%10)==0)?true:false);	 	
}

function expired( month, year ) {
   	var now = new Date();							// this function is designed to be Y2K compliant.
   	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
   	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
   	if(now.getTime() < expiresIn.getTime()) 
		return false;
	else
	   	return true;								// then we get the miliseconds, and do a long integer comparison
}

function validateCard(field,label) {
	var cc 			= document.forms[0].elements[field.name]; // Credit Card Form Field
	var cardNumber 	= stripNonNumbers(cc.value);	// Credit Card Number, without spaces or dashes
	var cardType 	= field.type;					// Credit Card Type, 'AMEX', 'MAST', 'VISA'
   	var len 		= cardNumber.length;			//perform card specific length and prefix tests

	if(len == 0 ) {						//most of these checks are self explanitory
		additionalInfo += "-- " + getFieldLabel(label) + " is not a valid credit card number.\n";
   		return false;				
   	}
	
	if(isNaN(cardNumber)) {
		additionalInfo += "-- " + getFieldLabel(label) + " is not a valid credit card.\n";
		return false;
	}

  	switch( cardType ) {

   		case "AMEX":
  			if( len != 15 ) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid American Express Card number.\n";
   				return false;
   			}

   			var prefix = parseInt( cardNumber.substring(0,2));
   			if( prefix != 34 && prefix != 37 ) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid American Express Card number.\n";
   				return false;
   			}
   			break;

       		case "DISC":
      			if( len != 16 ) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Discover Card number.\n";
	   				return false;
      			}

       			var prefix = parseInt( cardNumber.substring(0,4));
       			if( prefix != 6011 ) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Discover Card number.\n";
	   				return false;
       			}
       			break;

       		case "MAST":
       			if( len != 16 ) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Master Card number.\n";
	   				return false;
       			}
       			var prefix = parseInt( cardNumber.substring(0,2));

       			if( prefix < 51 || prefix > 55) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Master Card number.\n";
	   				return false;
       			}
       			break;

       		case "VISA":

       			if( len != 16 && length != 13 ) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Visa Card number.\n";
	   				return false;
       			}

       			var prefix = parseInt( cardNumber.substring(0,1));
       			if( prefix != 4 ) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Visa Card number.\n";
	   				return false;
       			}
       			break;
		
		case "DINE":
		
			if( len != 14) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Diners Club Card number.\n";
				return false;
       	}

			var prefix = parseInt( cardNumber.substring(0,1));
			if( prefix != 3 ) {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Diners Club Card number.\n";
				return false;
			}
			break;
		}
		

       	if( !mod10( cardNumber ) ) { 		// run the check digit algorithm
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid credit card number.\n";
			return false;
       	}
		cc.value = cardNumber;
       	return true; // at this point card has not been proven to be invalid
}
//-->
function validCarrierNumber(field,label)	{
	if(field) {
		if(validNumber(field,label)) {
			if(field.value.length == 6 ||
				field.value.length == 8) {
				return true;
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not valid. UPS Account Number must be 6 or 8 digits.\n";
				return false;
			}
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not valid. UPS Account Number must be 6 or 8 digits.\n";
			return false;
		}
	} else {
		return false;
	}
}

function validShpCtlNo(field,label)	{
	if(field) {
		if(validNumber(field,label)) {
			if(field.value.length < 6 &&
				field.value.length > 0) {
				var temp = "";
				for(r=6; r > field.value.length; r--)
					temp += "0";
				field.value = temp + field.value;
				return true;
			} else if(field.value.length == 6) {
				return true;
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Shipper Ctl No.\n";
				return false;
			}
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid Shipper Ctl No.\n";
			return false;
		}
	} else {
		return false;
	}
}

function validFormattedNumber(field,label) {
	if(document.forms[0].elements[field.name]) {
		var num = document.forms[0].elements[field.name];
		var len = parseInt(field.length,10);
		if(validNumber(num,label)) {
			if(num.value.length < len &&
				num.value.length > 0) {
				var temp = "";
				for(r=len; r > num.value.length; r--)
					temp += "0";
				num.value = temp + num.value;
				return true;
			} else if(num.value.length == 6) {
				return true;
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid " + field.desc + ".\n";
				return false;
			}
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid " + field.desc + ".\n";
			return false;
		}
	} else {
		return false;
	}
}

function validOCN(field,label)	{
	if(field) {
		if(validNumber(field,label)) {
			if(field.value.length < 6 &&
				field.value.length > 0) {
				var temp = "";
				for(r=6; r > field.value.length; r--)
					temp += "0";
				field.value = temp + field.value;
				return true;
			} else if(field.value.length == 6) {
				return true;
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not a valid OCN.\n";
				return false;
			}
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid OCN.\n";
			return false;
		}
	} else {
		return false;
	}
}

function validEmailCompare(field,label) {
	if(validEmail(document.forms[0].elements[field.emailOne],label) &&
		validEmail(document.forms[0].elements[field.emailTwo],label) &&
		(document.forms[0].elements[field.emailOne].value == document.forms[0].elements[field.emailTwo].value)) {
		return true;
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " email addresses do not match.\n";
		return false;
	}
}

function validEmail(field,label)	{
	if(field) {
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if(filter.test(field.value) != true) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid email address.\n";
			return false;
		} else if(field.value.length < 3 ||
			field.value.indexOf("@") < 0 ||
			field.value.indexOf(".") < 0 || 
			field.value.indexOf(" ") != -1 ||
			field.value.lastIndexOf("@") > field.value.lastIndexOf(".")) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid email address.\n";
			return false;
		} else	{
			return true;
		}
	} else {
		additionalInfo += "-- " + getFieldLabel(label) + " is not a valid email address.\n";
		return false;
	}
}

function validNumber(field,label)	{
	if(field) {
		if(field.value.length < 1 ||
			isNaN(field.value) || 
			field.value.indexOf(" ") != -1)	{
			additionalInfo += "-- " + getFieldLabel(label) + " is not a number.\n";
			return false;
		} else {
			return true;
		}	
	} else {
		return false;
	}
}

function validNumberSpan(field,label) {
	var num1 = document.forms[0].elements[field.toNumber].value;
	var num2 = document.forms[0].elements[field.fromNumber].value;

	if (isNaN(parseInt(num1)) || isNaN(parseInt(num2)))
	{ additionalInfo += "-- " + getFieldLabel(label) + " must be Numeric.\n";
		return false;
	} else {
	
		if (parseInt(num2) <= parseInt(num1)) {
			return true;
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " does not contain a valid Numeric Range.\n";
			return false;
		}
	}
}

//month					The month portion of the date the user entered.
//day					The day portion of the date the user entered.
//year					The year portion of the date the user entered.
//
// *** The following params are needed because sometimes all date segments are not required.
// *** For instance, some reports only require a month and year.
//monthSegmentRequired	If true, tests that the month is not null, not blank, and not "mm"
//daySegmentRequired	If true, tests that the day is not null, not blank, and not "dd"
//yearSegmentRequired	If true, tests that the year is not null, not blank, not "yy", and not "yyyy"
//
//Returns:		true if ALL tests specified above are true.  Otherwise false.
function attemptedDateEntry(month, day, year, monthSegmentRequired, daySegmentRequired, yearSegmentRequired){
	if(monthSegmentRequired){
		if(month){
			if(month.length > 0 && month != 'mm')
				return true;
		}
	}
	
	if(daySegmentRequired){
		if(day){
			if(day.length > 0 && day != 'dd')
				return true;
		}
	}
	
	if(yearSegmentRequired){
		if(year){
			if(year.length > 0 && year != 'yy' && year != 'yyyy')
				return true;
		}
	}
	
	return false;
}

function validDate(field,label,acceptPassedField) {
	var m1 = '';
	var d1 = '';
	var y1 = '';

	if (acceptPassedField){ 				//added this so that 'dateFields' that 
		m1 = new genericField(field.month);	//weren't connect to an actual field on
		d1 = new genericField(field.day);	//the page could be evaluated 
		y1 = new genericField(field.year);	//(see validSingleFieldDate() above)
	} 
	else {
		m1 = document.forms[0].elements[field.month];
		d1 = document.forms[0].elements[field.day];
		y1 = document.forms[0].elements[field.year];
	}
	
	//If it's an optional param then do not try to validate
	//unless the user attempted to enter something
	if(optionalParam(label)){
		if(!attemptedDateEntry(m1.value, d1.value, y1.value, true, true, true))
			return true;
	}
	
	if(m1 && d1 && y1) {
		if(isNaN(parseInt(m1.value,10)) || 
			isNaN(parseInt(d1.value,10)) || 
			isNaN(parseInt(y1.value,10))) {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid date.\n";
			return false;
		}
	
		if(y1.value.length == 3) {
			additionalInfo += "-- " + getFieldLabel(label) + " the year is not valid.\n";
			return false;
		} else if(y1.value<100) {
			if(parseInt(y1.value,10)<10)
				y1.value="200" + parseInt(y1.value,10);
			else if(parseInt(y1.value,10)<70)
				y1.value="20" + parseInt(y1.value,10);
			else
				y1.value="19" + y1.value;
		} 

		var origMonth 	= parseInt(m1.value,10);
		var origDay 	= parseInt(d1.value,10);
		var origYear 	= parseInt(y1.value,10);
		var date1 		= new Date(origYear,origMonth-1,origDay);
		var dateString  = origMonth + "/" + origDay + "/" + origYear;
		var verifyDateString = (date1.getMonth() + 1) + "/" + date1.getDate() + "/" + date1.getFullYear();
		if(verifyDateString == dateString) {

			m1.value = stripNonNumbers(m1.value);

			if(m1.value.length < 2)
				m1.value = "0" + m1.value;
	
			d1.value = stripNonNumbers(d1.value);

			if(d1.value.length < 2)
				d1.value = "0" + d1.value;
			
			y1.value = stripNonNumbers(y1.value);
			return true;
/*
		} else if(confirm("Did you mean to enter the following?\n\n      " + 
				(date1.getMonth()+1) + "/" + date1.getDate() + "/" + 
				date1.getFullYear() +"\n\nIf not, select cancel and re-enter a valid date.\n"))	{
			m1.value=date1.getMonth()+1;
			d1.value=date1.getDate();	
			y1.value=date1.getFullYear();	
			return true;
*/
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid date.\n";
			return false;
		}
	} else {
		return false;
	}
}

function skipDateValidation(obj) {
	
	var m1 = document.forms[0].elements[obj.month];
	var d1 = document.forms[0].elements[obj.day];
	var y1 = document.forms[0].elements[obj.year];
	
	if(m1 && d1 && y1) {
	
		var date = m1.value + d1.value + y1.value;
		var dateEN 	= /m{2}d{2}y{4}/gi
		var dateGL	= /[madjy]/gi
		var dateFR	= /m{2}j{2}a{4}/gi
		var dateNum = /[0-9]{1,8}/gi
		var spaces	= /\s{3}/gi
		
		if(dateEN.test(date) || dateFR.test(date)) {
			return true;
		} else if(date.length == 0) {
			m1.value = "mm";
			d1.value = "dd";
			y1.value = "yyyy";
			return true;
		} else if(dateGL.test(date) && !dateNum.test(date)) {
			m1.value = "mm";
			d1.value = "dd";
			y1.value = "yyyy";
			return true;
		} else if(dateNum.test(date)) {
			return false;
		} else {
			return false;
		}
	} else
		return false;
}

function afterToday(field,label)	{

	if(validDate(field,label)) {

		var m1 = document.forms[0].elements[field.month];
		var d1 = document.forms[0].elements[field.day];
		var y1 = document.forms[0].elements[field.year];
		
		if(m1 && d1 && y1) {
			var today		= new Date();
			var checkDate 	= new Date(parseInt(y1.value,10),parseInt(m1.value,10)-1,parseInt(d1.value,10),
										today.getHours(),today.getMinutes(),today.getSeconds(),today.getMilliseconds());
		
			if(checkDate >= today) {
				return true;
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " is not after today.\n";
				return false;
			}
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " is not a valid date.\n";
			return false;
		}
	} else
		return false;
}

function validDateSpan(field,label)	{
	if(validDate(new dateField(field.toMonth,field.toDay,field.toYear),label)) {
	
		var m1 = document.forms[0].elements[field.toMonth];
		var d1 = document.forms[0].elements[field.toDay];
		var y1 = document.forms[0].elements[field.toYear];
		
		if(validDate(new dateField(field.fromMonth,field.fromDay,field.fromYear),label)) {
	
			var m2 = document.forms[0].elements[field.fromMonth];
			var d2 = document.forms[0].elements[field.fromDay];
			var y2 = document.forms[0].elements[field.fromYear];
			
			if(m1 && d1 && y1 && m2 && d2 && y2) {
		
				//If it's an optional param then do not try to validate
				//unless the user attempted to enter something
				if(optionalParam(label)){
					if(!attemptedDateEntry(m1.value, d1.value, y1.value, true, true, true))
						if(!attemptedDateEntry(m2.value, d2.value, y2.value, true, true, true))
							return true;
				}
		
				var toDate 		= new Date(parseInt(y1.value,10),parseInt(m1.value,10)-1,parseInt(d1.value,10));
				var fromDate 	= new Date(parseInt(y2.value,10),parseInt(m2.value,10)-1,parseInt(d2.value,10));
				if(toDate >= fromDate)	{
					return true;
				} else {
					additionalInfo += "-- " + getFieldLabel(label) + " does not contain a valid date range.\n";
					return false;
				}
			} else {
				additionalInfo += "-- " + getFieldLabel(label) + " one or both of the date entires are invalid.\n";
				return false;
			}
		} else
			return false;
	} else
		return false;
}

function validLimitedDateSpan(field,label)	{

	if(validDate(new dateField(field.toMonth,field.toDay,field.toYear),label)) {
	
		var m1 = document.forms[0].elements[field.toMonth];
		var d1 = document.forms[0].elements[field.toDay];
		var y1 = document.forms[0].elements[field.toYear];
		var today		= new Date();
		
		if(validDate(new dateField(field.fromMonth,field.fromDay,field.fromYear),label)) {
	
			var m2 = document.forms[0].elements[field.fromMonth];
			var d2 = document.forms[0].elements[field.fromDay];
			var y2 = document.forms[0].elements[field.fromYear];
			
			
			if(m1 && d1 && y1 && m2 && d2 && y2) {
			
				//If it's an optional param then do not try to validate
				//unless the user attempted to enter something
				if(optionalParam(label)){
					if(!attemptedDateEntry(m1.value, d1.value, y1.value, true, true, true))
						if(!attemptedDateEntry(m2.value, d2.value, y2.value, true, true, true))
							return true;
				}
		
				var toDate 		= new Date(parseInt(y1.value,10),parseInt(m1.value,10)-1,parseInt(d1.value,10),
										today.getHours(),today.getMinutes(),today.getSeconds(),today.getMilliseconds());
				
				var fromDate 	= new Date(parseInt(y2.value,10),parseInt(m2.value,10)-1,parseInt(d2.value,10),
										today.getHours(),today.getMinutes(),today.getSeconds(),today.getMilliseconds());
				var checkDate	= new Date(parseInt(y2.value,10),parseInt(m2.value,10)-1,parseInt(d2.value,10),
										today.getHours(),today.getMinutes(),today.getSeconds(),today.getMilliseconds());
				if(toDate >= fromDate)	{
					if(field.spanType == "M")	{
						checkDate = new Date(checkDate.getFullYear(), checkDate.getMonth() + parseInt(field.span,10), checkDate.getDate(),
										today.getHours(),today.getMinutes(),today.getSeconds(),today.getMilliseconds());
					} else if(field.spanType == "Y") {
						checkDate = new Date(checkDate.getFullYear()+ parseInt(field.span,10), checkDate.getMonth(), checkDate.getDate(),
										today.getHours(),today.getMinutes(),today.getSeconds(),today.getMilliseconds());
					} else if(field.spanType == "D") {
						checkDate = new Date(checkDate.getFullYear(), checkDate.getMonth(), checkDate.getDate() + parseInt(field.span,10),
										today.getHours(),today.getMinutes(),today.getSeconds(),today.getMilliseconds());
					} else {
						additionalInfo += "-- " + getFieldLabel(label) + " validation error, spanType is undefined.\n";
						return false;
					}

					if(toDate > checkDate) {
						additionalInfo += "-- " + getFieldLabel(label) + " does not contain a date range within the specific time frame -- " + field.span + " " + getTimeSpanDesc(field.spanType) + ".\n";
						return false;
					} else {
						return true;
					}
				} else {
					additionalInfo += "-- " + getFieldLabel(label) + " does not contain a valid date range.\n";
					return false;
				}
			} else {
				return false;
			}
		} else
			return false;
	} else
		return false;
}

function validMultiEntry(field,label)	{
	box  = document.forms[0].elements[field.name];
	if(box) {
		if(box.options == null || box.options.length  == 0)	{
			additionalInfo += "-- " + getFieldLabel(label) + " please enter at least 1 item.\n";
			return false;
		} else	{
			return true;
		}
	} else {
		return false;
	}
}

function validSelection(field,label)	{
	box  = document.forms[0].elements[field.name];
	if(box) {
		var count = 0;
		if(field.index)
			count = field.index;
		if(box.selectedIndex < count)	{
			additionalInfo += "-- " + getFieldLabel(label) + " please select at least 1 option.\n";
			return false;
		} else	{
			return true;
		}
	} else {
		return false;
	}
}
	
function isChecked(field,label) {
	if(field) {
		if(field.checked) {
			return true;
		} else {
			additionalInfo += "-- " + getFieldLabel(label) + " please select at least 1 option.\n";
			return false;
		}
	} else {
		return false;
	}
}

function validRadio(field,label)	{
	if(field) {
		var count = field.length;
		for(i=0;i<count;i++)	{
			if(field[i].checked) {
				return true;
			}
		}
		additionalInfo += "-- " + getFieldLabel(label) + " please select at least 1 option.\n";
		return false;
	} else {
		return false;
	}
}

function removeChars (stringToSplit,separator) {
	newNum = new String;
	arrayOfStrings = stringToSplit.split(separator);
	
	for (var i=0; i < arrayOfStrings.length; i++) newNum = newNum.concat(arrayOfStrings[i]);

	return newNum;
}	

function stripNonNumbers(val) {
	var phoneNum = val;
//	backSlash = /[\\]/g;
//	re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/
	phoneNum	= phoneNum.replace(new RegExp("[)]","g"),"");
	phoneNum	= phoneNum.replace(new RegExp("[-]","g"),"");
	phoneNum	= phoneNum.replace(new RegExp("[ ]","g"),"");
	phoneNum	= phoneNum.replace(new RegExp("[(]","g"),"");
	phoneNum	= phoneNum.replace(new RegExp("[/]","g"),"");
	phoneNum	= phoneNum.replace(new RegExp("[.]","g"),"");
	phoneNum	= phoneNum.replace(new RegExp("[,]","g"),"");
//	phoneNum	= phoneNum.replace(backSlash,"");

	return phoneNum;	
}

function filterPhoneHack(field){

	dash = new String("-");
	space = new String(" ");
	dot = new String(".");
	leftParen = new String("(");
	rightParen = new String(")");
	comma = new String(",");
	fSlash = new String("\\");
	bSlash = new String("/");

	return (removeChars
				(removeChars
					(removeChars
						(removeChars
							(removeChars
								(removeChars
									(removeChars
										(removeChars(field.value, dash), 
									space), 
								dot), 
							leftParen), 
						rightParen), 
					comma), 
				fSlash), 
			bSlash));
}

function lettersOnly(s){
	var pass = s.toUpperCase();
	for(var i = 0; i < s.length; i++){
		if ((pass.charCodeAt(i) < 65) ||
			(pass.charCodeAt(i) > 90)){
				return false;
		}
	}
	return true;
}

function getTimeSpanDesc(s){
	if(s=='M') return "Month(s)"
	else if(s=='Y') return "Year(s)"
	else if(s='D') return "Day(s)"
}


