
function AutoJump(destination) {
	window.location=destination
}

//===========Support Functions============

//========================================
//--------------------------Required Entry
//========================================

function FrmElement_NonNull(FrmIndx_li, EleIndx_li) {
	//This function will return true if the element it is refered to is non-null
	//It is fairly specific to  Surveys because it makes asumptions
	//on how questions are names so that it can check a group of check boxes
	//radio buttons, etc...

	ReturnFlag_lb = new Boolean(false); //used to cut down code repetition

	with(document.forms[FrmIndx_li].elements[EleIndx_li]) {

		//This is sort of a waste, but if there is an option in this list with the 
		//value of "" then this function will not return false if that option is selected

		if (type == "select-one") {
			if (options[selectedIndex].value != "") ReturnFlag_lb = true;
		}
		
		//Generic text required Entry. If the value is null, then the function returns false.
		if ((type == "text") || (type == "textarea")){
			if (value != "") ReturnFlag_lb = true;
		}
	}//end with

	//This part of the function is similiar to the Chk_AtLstX function
	//in that it makes sure that at least one check box has been checked
	//This does some name processing to figure which check boxes go together

	if (document.forms[FrmIndx_li].elements[EleIndx_li].type == "checkbox") {
		i = 0;
		while (document.forms[FrmIndx_li].elements[EleIndx_li].name.charAt(i) != "_") i++; // cut out name of the question (Q4_1 will extract Q4 out)
		MainQName_ls = document.forms[FrmIndx_li].elements[EleIndx_li].name.slice(0,i);
		i = EleIndx_li;
		while (document.forms[FrmIndx_li].elements[i].name.search(MainQName_ls) != -1) {
			if (document.forms[FrmIndx_li].elements[i].checked) {
				ReturnFlag_lb = true;
			}
			i++;
		}
	}
	
	//This checks a group of radio buttons to see if there is one selected. It groups radio buttons together which are 
	//contigous and have the same name

	if (document.forms[FrmIndx_li].elements[EleIndx_li].type == "radio") {
		i = EleIndx_li;
		while (document.forms[FrmIndx_li].elements[i].name == document.forms[FrmIndx_li].elements[EleIndx_li].name) {
			if (document.forms[FrmIndx_li].elements[i].checked) ReturnFlag_lb = true;
			i++;
		}
	}

	if (ReturnFlag_lb == true) return true;
	else return false;
}

//========================================
//--------------------Check Boxes At Least
//========================================
function Chk_atLstX(FrmIndx_li, EleIndx_li, Limit_li) {
	//alert("Chk_atLstX(" + FrmIndx_li + ", " + EleIndx_li + ", " + Limit_li + ");");     
	//this function will check a set of checkboxes (same QXX of QXX_nnn) in name
	//and return true if at least Limit_li are checked.

	NumChecked_li = new Number(0); //number of items checked
	QuesName_ls = new String(""); //string which will hold the QXX part of the name

	//first, extract the Question Number
	with(document.forms[FrmIndx_li].elements[EleIndx_li]) {
		i = 0;
		while (name.charAt(i) != "_") i++;
		//i is now index of the _ in the name of the first checkbox
		QuesName_ls = name.slice(0,i);
	} //end with

	//now, check all the checkboxes which have that first part in their name
	j=EleIndx_li;
	while (document.forms[FrmIndx_li].elements[j].name.slice(0,i) == QuesName_ls) {
		if (document.forms[FrmIndx_li].elements[j].checked) NumChecked_li++;
		j++;
	}

	//now test to see if the number checked is at least Limit_li
	if (NumChecked_li >= Limit_li) {
		return true;
	}else{
		return false;
	}

} //end function

//========================================
//---------------------Check Boxes At Most
//========================================
function Chk_atMstX(FrmIndx_li, EleIndx_li, Limit_li) {
	//this function will check a set of checkboxes (same QXX of QXX_nnn)
	//and return true if at most that many are checked.

	NumChecked_li = new Number(0); //number of items checked
	QuesName_ls = new String(""); //string which will hold the QXX part of the name
	
	//first, extract the Question Number
	with(document.forms[FrmIndx_li].elements[EleIndx_li]) {
		i = 0;
		while (name.charAt(i) != "_") i++;
		//i is now index of the _ in the name of the first checkbox
		QuesName_ls = name.slice(0,i);
	} //end with

	//now, check all the checkboxes which have that first part in their name
	j=EleIndx_li;
	while (document.forms[FrmIndx_li].elements[j].name.slice(0,i) == QuesName_ls) {
		if (document.forms[FrmIndx_li].elements[j].checked) NumChecked_li++;
		j++;
	}
	//now test to see if the number checked is at most Limit_li
	if (NumChecked_li <= Limit_li) return true;
	else return false;
} //end function

//========================================
//---------------------Check Boxes Exactly
//========================================
function Chk_ExactX(FrmIndx_li, EleIndx_li, Limit_li) {
	//this function will check a set of checkboxes (same QXX of QXX_nnn)
	//and return true if exactly that many are checked.
	NumChecked_li = new Number(0); //number of items checked
	QuesName_ls = new String(""); //string which will hold the QXX part of the name
	
	//first, extract the Question Number
	with(document.forms[FrmIndx_li].elements[EleIndx_li]) {
		i = 0;
		while (name.charAt(i) != "_") i++;
		//i is now index of the _ in the name of the first checkbox
		QuesName_ls = name.slice(0,i);
	} //end with

	//now, check all the checkboxes which have that first part in their name
	j=EleIndx_li;
	while (document.forms[FrmIndx_li].elements[j].name.slice(0,i) == QuesName_ls) {
		if (document.forms[FrmIndx_li].elements[j].checked) NumChecked_li++;
		j++;
	}
	//now test to see if the number checked is at least Limit_li
	if (NumChecked_li == Limit_li) return true;
	else return false;
} //end function

//========================================
//--------------------------Fill In Totals
//========================================

function Str_FillInTot(FrmIndx_li, EleIndx_li, TotalSum_lc) {
	// This function will compute the total sum of a fillin question
	// and return true if that total sum is equal to TotalSum

	// It will ignore any fields which contain non-numeric values. ie it is up to the
	// user to make sure that the fields are numeric values.

	// Uses standard  Survey Solutions Form Elemnt numbering to find out how many
	// subsequent questions are to be added together to find the total.

	//QuestName_ls is the name of the main question ie. Q2 in Q2_1, Q2_2, etc...
	i = 0;
	while (document.forms[FrmIndx_li].elements[EleIndx_li].name.charAt(i) != "_") i++;
	
	QuestName_ls = document.forms[FrmIndx_li].elements[EleIndx_li].name.slice(0,i);
	FormSum_li = new Number(0);

	i = EleIndx_li;
	SumModified_lb = false;
	while(document.forms[FrmIndx_li].elements[i].name.search(QuestName_ls) != -1) {
		if (document.forms[FrmIndx_li].elements[i].value != ""){
			FormSum_li += parseFloat(document.forms[FrmIndx_li].elements[i].value);
			SumModified_lb = true;
		}
		i++;
	}

	//return true if total is good, or if no data has been entered.
	if ((FormSum_li == TotalSum_lc) || (SumModified_lb == false)) return true;
	else return false;
	
}

//========================================
//-------Email Checking Function & Support
//========================================
function isGoodForm(SearchString) {
	//this should be modified--these rules are not all that good. All will check for is for form*@*.
	i = new Number(0);
	while ((SearchString.charAt(i) != '@') && (i < SearchString.length)) i++;
		if (i==SearchString.length) return false;
	while ((SearchString.charAt(i) != '.') && (i < SearchString.length)) i++;
		if (i==SearchString.length) return false;
	return true;
}

function noBadPeriods(SearchString) {
	//makes sure that the email address does not begin or end with a period
	if ((SearchString.charAt(0) == '.') || (SearchString.charAt(SearchString.length) == '.')) return false;
	return true;
}

function hasOneAmp(SearchString) {
	//returns true if 1 and only 1 @ is in Search String
	count = new Number(0);
	for (i=0;i<SearchString.length;i++) {
		if (SearchString.charAt(i) == '@') count++;
	}
	if (count == 1) return true;
	else return false;
}
function isMember(SearchArray, key) {
	//returns true if key is a member of Search Array
	i = new Number(0);
	for (i=0;i<SearchArray.length;i++) {
		if (SearchArray[i] == key) return true;
	}
	return false;
}

function parseDomain(SearchString) {
//Parses the domain from an EmailAddress
//***this function assumes that there is at lease one period in the SearchString somewhere
	SearchDomain = new String("");
	i = new Number(SearchString.length);

	while (SearchString.charAt(i) != '.') i--;
	i++; //go past the period that we just found
	for (var j=i;j < SearchString.length;j++) {
		SearchDomain = (SearchDomain.concat(SearchString.charAt(j)));
	}
	return SearchDomain;
}
function Str_IsValidEmailAddress(FrmIndx_li, EleIndx_li) {
	//returns true if Email address is a valid under the following criteria, or value is null:
	//1. form *@*.*
	//2. does not begin or end in periods
	//3. one @
	//4. domain is valid
	
	//abort immediately if value is null 
	//Standard behavior--return true unless there is data entered
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;


	//-------------------
	//Set up array of valid domains
	ArrayOfDomains = new Array("com", "net", "edu", "kr", "ca", "org", "us", "au", "in", "gov", "uk", "jp", "de", "mil", 

"sg", "cn", "tw", "br", "za", "se", "my", "es", "nz", "il", "it", "vn", "fr", "mx", "no", "nl", "ru", "hk", "ie", "be", "fi", 

"ch", "th", "dk", "tr", "ar", "pl", "hu", "ph", "id", "ae", "pk", "cz", "gr", "at", "sk", "om", "ua", "co", "ro", "pe", "pt", 

"si", "su", "lt", "ve", "sa", "yu", "cl", "bg", "lb", "hr", "bh", "eg", "is", "jm", "tt", "uy", "cu", "lv", "ee", "ir", "cr", 

"lk", "np", "zw", "int", "bo", "jo", "ke", "qa", "cy", "ec", "mk", "na", "fo", "bm", "bw", "zm", "kw", "do", "uz", "by", 

"py", "bs", "lc", "lu", "tz", "ma", "mt", "mz", "fj", "gt", "gy", "ag", "sn", "to", "bf", "mu", "ni", "nu", "am", "bn", "ci", 

"cm", "ky", "kz", "mg", "mr", "ne", "fm", "vi", "ge", "gn", "hn", "pg", "ad", "an", "ba", "kh", "dm", "td", "tg", "tj", "tm", 

"tn", "md", "ml", "ug", "mo", "mv", "nc", "gh", "gi", "gu", "pa", "pf", "al", "aw", "ye", "tv");
	//-------------------

	EmailAddress = document.forms[FrmIndx_li].elements[EleIndx_li].value

//debugging information
	//alert("Is Good Form--" + isGoodForm(EmailAddress));
	//alert("Is Good with periods--" + noBadPeriods(EmailAddress));
	//alert("Is Good with one @--" + hasOneAmp(EmailAddress));
	//if (isGoodForm(EmailAddress)) {
	//	var EmailDomain = parseDomain(EmailAddress);
	//	alert("Is Good with domains--" + isMember(ArrayOfDomains, EmailDomain));
	//}
//end debugging information
PassedTests_lb = new Boolean("true");

	if (!isGoodForm(EmailAddress)) {
		PassedTests_lb = false;
	} else if (!noBadPeriods(EmailAddress)) {
		PassedTests_lb = false;
	} else if (!hasOneAmp(EmailAddress)) {
		PassedTests_lb = false;
	} else if (!isMember(ArrayOfDomains, parseDomain(EmailAddress))) {
		PassedTests_lb = false;
	}
	return PassedTests_lb;
}

//========================================
//--------String Length Checking Functions
//========================================

function Str_IsShorterThan(FrmIndx_li, EleIndx_li, MaxLength) {
	// returns true if string is shorter than MaxLength
	// returns false otherwise

	// returns true if value is null, as is standard javaboy practice
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	if (!(document.forms[FrmIndx_li].elements[EleIndx_li].value.length <= MaxLength)) {
		return false;
	} else return true;
}

function Str_IsLongerThan(FrmIndx_li, EleIndx_li, MinLength) {
	// returns true if string is shorter than MinLength
	// returns false otherwise

	// returns true if value is null
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	if (!(document.forms[FrmIndx_li].elements[EleIndx_li].value.length >= MinLength)) {
		return false;
	} else return true;
}

function Str_IsExactly(FrmIndx_li, EleIndx_li, Limit_li) {
	//Returns true if string is shorter than Limit_li
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value.length != Limit_li) {
		return false;
	} else return true;
}

//========================================
//----------------------String Is a Number
//========================================

function Str_IsNumber(FrmIndx_li, EleIndx_li, DecPnt_lc) {
	// passed a string and returns true if Str_Value is a valid number 
	// (contains only digits, periods, commas, and uses normal standard notation (1,000.00 for example)

	// This might need to be clarified in the future to deal with 
	// international numeric formats which is what I am doing right now

	
	NumeralFlag_b = new Boolean(false);
	Str_Value = document.forms[FrmIndx_li].elements[EleIndx_li].value;
	//allow null string
	if (Str_Value == "") return true;
	

	//disallow any string which contains a non (numeral or "." or ",")
	if (Str_Value.search("[^0-9.,]") != -1) return false;

	//require at least one numeral
	if (Str_Value.search("[0-9]") == -1) return false; 

	//make sure that there is only one decimal marker included
	PntCnt_li = 0;
	for (var i=0;i<Str_Value.length;i++) {
		if (Str_Value.charAt(i) == DecPnt_lc) PntCnt_li++;
	}
	if (PntCnt_li > 1) return false; 

	//make sure that the decimal marker is the farthest right non numeral'
	//since . is a code for reg expressions, we need to make one using \.
	T_re = new RegExp("\\" + DecPnt_lc);
	if (Str_Value.search(T_re) != -1) {
		DecHit_lb = false;
		i = Str_Value.length;
		while(i>=0) {
			if (Str_Value.charAt(i) == DecPnt_lc) break;
			if (Str_Value.charAt(i) == ((DecPnt_lc == ".") ? "," : ".")) {
				return false;
			}
		i--;
		}
	}	

	return true;
}

//========================================
//-------------------String Matches RegExp
//========================================

function Str_MatchRegExp(FrmIndx_li, EleIndx_li, MatchCase_ls, RegExp_ls) {
	// This function will return true of the value field of the chosen form element
	// contains a match for the RegExp_ls regular expression
	// 
	// MatchCase_ls is a string of flags for Regular Expressions. Refer to documentation for more extensive information
	// in general: i for case _i_nsensitive, g for "global". gi for both, "" for neither
	//
	// The regular expression can be any valid RegExp type that javascript allows
	// See Validation suite documentation, or javascript documentation:
	// http://developer.netscape.com/docs/manuals/communicator/jsref/index.htm

	//Standard  DC--if value == null, return with true
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	T_lr = new RegExp(RegExp_ls, MatchCase_ls);
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value.search(T_lr) == -1) {//in other words, it is not matched
		return false;
	} else return true;
}

//========================================
//------------String Does not Match RegExp
//========================================

function Str_NoMatchRegExp(FrmIndx_li, EleIndx_li, MatchCase_ls, RegExp_ls) {
	// This function will return the opposite of Str_MatchRegExp()

	//Standard  DC--if value == null, return with true
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	T_lr = new RegExp(RegExp_ls, MatchCase_ls);
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value.search(T_lr) != -1) {//in other words, it is matched
		return false;
	} else return true;
}

//========================================
//----------Numerical Comparison Functions
//========================================

function Number_IsGreaterThan (FrmIndx_li, EleIndx_li, Limit_li) {
	//Implements the > operator in a function
	//will return true if no value has been typed

	//our standard policy again
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	if (!(parseInt(document.forms[FrmIndx_li].elements[EleIndx_li].value) > Limit_li)) {
		return false;
	} else return true;
}

function Number_IsGreaterThanOrEqualTo (FrmIndx_li, EleIndx_li, Limit_li) {
	//Implements the >= operator in a function
	//will return true if no value has been typed

	//our standard policy again
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	if (!(parseInt(document.forms[FrmIndx_li].elements[EleIndx_li].value) >= Limit_li)) {
		return false;
	} else return true;
}

function Number_IsLessThan (FrmIndx_li, EleIndx_li, Limit_li) {
	//Implements the < operator in a function
	//will return true if no value has been typed

	//our standard policy again
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	if (!(parseInt(document.forms[FrmIndx_li].elements[EleIndx_li].value) < Limit_li)) {
		return false;
	} else return true;
}

function Number_IsLessThanOrEqualTo (FrmIndx_li, EleIndx_li, Limit_li) {
	//Implements the <= operator in a function
	//will return true if no value has been typed

	//our standard policy again
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	if (!(parseInt(document.forms[FrmIndx_li].elements[EleIndx_li].value) <= Limit_li)) {
		return false;
	} else return true;
}

function Number_IsEqualTo (FrmIndx_li, EleIndx_li, Limit_li) {
	//Implements the == operator in a function
	//will return true if no value has been typed

	//our standard policy again
	if (document.forms[FrmIndx_li].elements[EleIndx_li].value == "") return true;

	if (!(parseInt(document.forms[FrmIndx_li].elements[EleIndx_li].value) == Limit_li)) {
		return false;
	} else return true;
}



//========================================
//-------------------------Forced Rankings
//========================================

function Frm_NoDupRank(FrmIndx_li, EleIndx_li, NumOptPerChoice_li, NumChoice_li) {
	// This function will return true if there are no duplicates in a 
	// forced ranking survey question.
	//  EleIndx_li is the starting element in the 
	//   array, associated with the forced rankings
	//  NumOptPerChoice_li is the number of buttons per choice
	//  NumChoice_li is the number of choices offered

	Responses_l = new Array(0);

	for (var i=0;i<NumChoice_li;i++) {
		for (var j=0;j<NumOptPerChoice_li;j++) {
			if (document.forms[FrmIndx_li].elements[EleIndx_li + (i * NumOptPerChoice_li) + j].checked) {
				Responses_l = Responses_l.concat((document.forms[FrmIndx_li].elements[EleIndx_li + (i * 

NumOptPerChoice_li) + j].value));
			}
		}
	}
	for (var i=0;i<Responses_l.length - 1;i++) {
		for (var j=i+1;j<Responses_l.length;j++) {
			if (Responses_l[i] == Responses_l[j]) {
				return false;
			}
		}
	}
	return true;
}

//========================================
//------------------Disallowing Selections
//========================================
function Sel_NoChoose(FrmIndx_li, EleIndx_li, DisAllwd_ls) {
	// function will disallow a specific choice in a dropdown list box.
	// not surprisingly, the DisAllwd_li is the value which is disallowed
	// for this specific question.
	// data is good. Things like out of bounds errors, while they do not stop Javascript,
	// will probably wreak havoc on this function; I do no checking to keep code to a 
	// minimum on the client side, and hence expect good data from the Valiation String

	//quite simple really. Just check that the slected item is not the disallowed one
	with (document.forms[FrmIndx_li].elements[EleIndx_li]) {
		if (options[options.selectedIndex].value == DisAllwd_ls) {
			return false;
		} else return true;
	}
}


//============Main Validation Functions========

//========================================
//--------------Error Message Array Search
//========================================
function ValErrMsgArr_Search(Key_ls) {
	//this function will return the array index in the error message array
	//whose first part "command|identifier|option1|option2|option3..." matches
	//Key_ls. Used for finding appropriate error messages.
	//returns a -1 if there is no match
	//Try 1. Implement a simple, linear search. Horriblly inefficient, but easy to code.

	IndxToReturn_li = -1;
	PosToTest_li = 0;
	while (PosToTest_li < ValErrMsgArr.length) {
		if (ValErrMsgArr[PosToTest_li].slice(0,Key_ls.length) == Key_ls) {
			IndxToReturn_li = PosToTest_li;
			break;
		}
		PosToTest_li ++;
	}
	return IndxToReturn_li;
}

//========================================
//---------Error Message Parameter Fill in
//========================================
function Str_FillInErrorParameters (MessageStr_zs, Parameters_as) {
	//fills in the parameters specified in the MessageStr_zs as {{X}} with the 
	//Parameters_as[X] array entry. 
	//eg. if Parameters_as[0] = 2
	//    "You Must Enter {{0}} characters" => "You Must Enter 2 characters"

	var BeginPos_li = 0;
	var Length_li   = 0;
	var NewStr_ls   = "";
	
	while ((BeginPos_li + 1) < MessageStr_zs.length) {
		if 	((MessageStr_zs.charAt(BeginPos_li) == "{") && (MessageStr_zs.charAt(BeginPos_li + 1) == "{")) {
			break;
		} else {
			BeginPos_li++;
		}
	}
	
	//If we are at the end of the string (no substutions were found)
	if ((BeginPos_li + 1) == MessageStr_zs.length) {
		return MessageStr_zs;
	} else {
		//assume number is 1 character long ( {{X}} )
		//if this is a bad assumption, don't do substution
		Length_li = 5;
		
		if ((Length_li + BeginPos_li) > MessageStr_zs.length) {
			return MessageStr_zs; 
		}
		
		if ((MessageStr_zs.charAt(BeginPos_li + 3) == "}") && (MessageStr_zs.charAt(BeginPos_li + 4) == "}")) {
			//take out the number and do the substution
			Index_li = new Number(MessageStr_zs.slice(BeginPos_li + 2, BeginPos_li + 3));
			NewStr_ls =  MessageStr_zs.slice(0,BeginPos_li);
			NewStr_ls += Parameters_as[Index_li] || Parameters_as[0];
			NewStr_ls += MessageStr_zs.slice((BeginPos_li + Length_li), MessageStr_zs.length);
			return NewStr_ls;			
		} else {
			return MessageStr_zs;
		}
	}
}

//========================================
//--Convert between element name and index
//========================================
//Given an element name, returns the index in the element array
//which corresponds to that name
function Str_GetFrmIndex(ElementName_zs, ElementArray_as) {
	var i;
	for(i=0;i<ElementArray_as.length;i++) {
		if (ElementArray_as[i].name == ElementName_zs) {
			return i;
		}
	}
	//Element name not found. return -1
	return -1
}
	


//========================================
//--------------Survey Validation Function
//========================================

function Sur_Validate(SetFocus_lb, validate_only) {

	// 2007/02/04 - Chris Aybar - Set finish time.
	if (Str_GetFrmIndex("PDCPDCFTime", document.forms[0].elements) >= 0)
	{
		document.forms[0].elements[Str_GetFrmIndex("PDCPDCFTime", document.forms[0].elements)].value = getCurrentTime();
	}

	//This function will read the ValArr and ValErrMsgArr global arrays, and it will
	//execute the validations contained therein. See Documentation for details.
	//returns false if any of the validation commands returns false
	//This function contains no error checking for the validation strings, so make
	//sure that they are in the propper format
	//ValArr:
	//"x|y|command|identifier|option1|option2|option3..."
	//ValErrMsg:
	//"command|identifier|option1|option2|option3..."
	//the first parts of the error message string is information to match validation
	//requirements and the correct error message. If there is no match between 
	//the two arrays, a standard error dialog will be used. Setting the identifier to be
	//either s, or n will also have special effects.
	//If the identifier in the ValArr is s, then the standard error message will always be used
	//if the identifier is n then no alerts will be given.

	//Pieces to Parse out of ValArr
	//alert("Sur_Validate");
	FormIndex_li = new Number(0);
	ElementIndex_li = new Number(0);
	ValidationType_ls = new String("");
	Identifier_ls = new String("");
	ExtraParameters_la = new Array(0);
	PosBegCom_li = new Number(0); //the position of the beginning of the command
	PosBegExtPara_li = new Number(0); //The position of the beginning of the extra options. Eliminates some messness down the road with pipes in regular expressions

	CurPos = new Number(0); //current position in the string
	T_ls = new String(); //temp string for parsing
	ExtraParameters_la = new Array(); //Array for holding any extra parameters needed
	TestOutcome_lb = new Boolean(true); //the outcome of the individual validation function
	StdErrMsg_ls = new String(""); //string which will hold the standard error message
	//This is the main FOR loop. It works on each string of the ValArr Array

	//Split up the contents of the validation field using the ; as a separator
	ValArr = new Array();
	ElementIndex_li = Str_GetFrmIndex("PDCPDCVld", document.forms[0].elements);
	//if validation present
	if (ElementIndex_li != -1) {
		T_ls = document.forms[0].elements[ElementIndex_li].value;
		ValArr = T_ls.split(";");
	}
		
	
	//Split up the error messages the same way
	ValErrMsgArr = new Array();
	ElementIndex_li = Str_GetFrmIndex("PDCPDCVldErrMsg", document.forms[0].elements);
	//if validation present
	if (ElementIndex_li != -1) {
		T_ls = document.forms[0].elements[ElementIndex_li].value;
		ValErrMsgArr = T_ls.split(";");
	}
			
	//Begin main processing loop
	for (var i=0;i<ValArr.length;i++){
		CurrentString = new String(ValArr[i]);
		//alert("for i = " + i + "; CurrentString = '" + CurrentString + "'");
		if (CurrentString.length > 0) {
	 		with(CurrentString) {
			
				//clear the extra parameters array so that each string gets its own
				ExtraParameters_la.length = 0;

				//first parse out the parts that we are interested in from the string
				//-----Form Index-------
				CurrPos = 0;
				T_ls = "";
				//alert("while1 begin");
				while (charAt(CurrPos) != "|") {
					T_ls = T_ls.concat(charAt(CurrPos));
					CurrPos++;
				}
				//alert("while1 end");
				FormIndex_li = parseInt(T_ls);

				//-----Element Index-------
				CurrPos++;
				T_ls = "";
				//alert("while2 begin");
				while (charAt(CurrPos) != "|") {
					T_ls = T_ls.concat(charAt(CurrPos));
					CurrPos++;
				}
				//alert("while2 end");
				ElementIndex_li = parseInt(T_ls);
				if (isNaN(ElementIndex_li)) {
					//If using nonnumeric form element names
					ElementIndex_li = Str_GetFrmIndex(T_ls, document.forms[FormIndex_li].elements);
				}

				PosBegCom_li = CurrPos + 1;
				//This stores the postion of the first element which has the command in it;

				//so that we can do efficient searches for error messages
				//----Validation Type-------
				CurrPos++;
				T_ls = "";
				while (charAt(CurrPos) != "|") {
					T_ls = T_ls.concat(charAt(CurrPos));
					CurrPos++;
				}
				ValidationType_ls = T_ls;
	
				//--------Identifier--------
				CurrPos++;
				T_ls = "";
				while (charAt(CurrPos) != "|") {
					T_ls = T_ls.concat(charAt(CurrPos));
					CurrPos++;
				}
				Identifier_ls = T_ls;

				PosBegExtPara_li = CurrPos+1; 
				//This is for later on when we need to get regular expressions 
				//without having to restring the extra parameters together


				//-----Extra Parameters-------
				while (CurrPos < (length - 1)) {
	
					T_ls = "";
					CurrPos++;
					while ((charAt(CurrPos) != "|") && (CurrPos < length)) {
						T_ls = T_ls.concat(charAt(CurrPos));
						CurrPos++;
					}
					ExtraParameters_la = ExtraParameters_la.concat(T_ls);
				}
			
			}//end with

			//debugging stuff
			//alert("FrmIndex="+FormIndex_li);
			//alert("EleIndex="+ElementIndex_li);
			//alert("Validation Type="+ValidationType_ls);
			//alert("Identifier="+Identifier_ls);
			//alert("Extra Parameters="+ExtraParameters_la);
		
			//-------Now, perform validation based on the array entry just parsed
			//1. The function will alert the correct message based on the ValErrMsgArr format discussed earlier
			//2. The function will set the focus and select(if permitted) the offending 
			//       Element

			//Use switch (case) statement to determine what validation function to use.
			//set up a valid command in T_ls (temp string) to set value of TestOutcome_lb correctly

			switch (ValidationType_ls) {
				case "ReqAns" : { 	
					T_ls = "FrmElement_NonNull(FormIndex_li, ElementIndex_li)";
					StdErrMsg_ls = "Please answer this question.";
					break;
				}
				case "ChkMin" : {
					T_ls="Chk_atLstX(FormIndex_li, ElementIndex_li, ExtraParameters_la)";
					StdErrMsg_ls = "Please select at least {{0}} choices.";
					break;
				}
				case "ChkMax" : {
					T_ls="Chk_atMstX(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Only {{0}} choices are permitted to this question.";
					break;
				}
				case "ChkExc" : {
					T_ls="Chk_ExactX(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Please select exactly {{0}} choices to this question.";
					break;
				}
				case "ReqSum" : {
					T_ls="Str_FillInTot(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answers do not add up to the correct sum of {{0}}.";
					break;
				}
				case "IsEml" : {
					T_ls="Str_IsValidEmailAddress(FormIndex_li, ElementIndex_li)";
					StdErrMsg_ls = "Invalid e-mail address.";
					break;
				}
				case "MinLen" : {
					T_ls="Str_IsLongerThan(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answer is shorter than the minimum allowed length of {{0}} characters.";
					break;
				}
				case "MaxLen" : {
					T_ls="Str_IsShorterThan(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answer is longer than the maximum allowed length of {{0}} characters.";
					break;
				}
				case "ExcLen" : {
					T_ls="Str_IsExactly(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
	   			StdErrMsg_ls = "Your answer must be exactly {{0}} characters in length.";
					break;
				}
				case "IsNum" : {
					T_ls="Str_IsNumber(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answer is not a number.";
					break;
				}
				case "IncRegExp" : {
					T_ls="Str_MatchRegExp(FormIndex_li, ElementIndex_li, ExtraParameters_la[0], ExtraParameters_la[1])";
					StdErrMsg_ls = "Your answer does not match the criteria set for this question.";
					break;
				}
				case "ExcRegExp" : {
					T_ls="Str_NoMatchRegExp(FormIndex_li, ElementIndex_li, ExtraParameters_la[0], ExtraParameters_la[1])";
					StdErrMsg_ls = "Your answer contains a pattern which is invalid for this question.";
					break;
				}
				case ">" : {
					T_ls="Number_IsGreaterThan(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answer is less than {{0}}, the minimum allowed for this question.";
					break;
				}
				case ">=" : {
					T_ls="Number_IsGreaterThanOrEqualTo(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answer is less than {{0}}, the minimum allowed for this question.";
					break;
				}
				case "<" : {
					T_ls="Number_IsLessThan(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answer is greater than {{0}}, the maximum allowed for this question.";
					break;
				}
				case "<=" : {
					T_ls="Number_IsLessThanOrEqualTo(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answer is greater than {{0}}, the maximum allowed for this question.";
					break;
				}
				case "==" : {
					T_ls="Number_IsEqualTo(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "Your answer is not the same as {{0}}, which is the required answer for this question.";
					break;
				}
				case "ReqRnk" : {
					T_ls="Frm_NoDupRank(FormIndex_li, ElementIndex_li, ExtraParameters_la[0], ExtraParameters_la[1])";
					StdErrMsg_ls = "You must choose a different answer for each part of this question.";
					break;
				}
				case "ExcSelCho" : {
					T_ls="Sel_NoChoose(FormIndex_li, ElementIndex_li, ExtraParameters_la[0])";
					StdErrMsg_ls = "You have chosen an invalid selection for this question";
					break;
				}
				default : {
					alert("An invalid validation command was specified (" + ValidationType_ls + ").");
					return true;
				}
			}
			
			//evaluate the expression we created above so that we know if the element passed
			//the test
	
			TestOutcome_lb = eval(T_ls);
			//alert(T_ls + " TestOutcome_lb = " + TestOutcome_lb);

			//if test failed
			if (TestOutcome_lb == false) {
		   
 				//Now, set the focus if that is the desire
				//if we want, we could also have the text boxes select here at this time

				with(document.forms[FormIndex_li].elements[ElementIndex_li]) {
					if(SetFocus_lb == true) {
						//focus();  by Chris Aybar 07/17/2002

                                                // by Chris Aybar 07/17/2002
                                                // make the browser go to the anchor above form input tag
                                                tempArray = new Array ();
                                                tempArray = CurrentString.split("|");
                                                tempString = new String(tempArray[1]);
                                                location.hash=tempString;
					}
					if ((type == "text") || (type == "textarea")) {
						select();
					}
				} //end with
	
				//Now, display the appropriate error message
				//Remember, we are searching for "command|identifier|options....|" in the ValErrMsgArr array
				//Using our handy ValErrMsgArr_Search() Function (which should be optimized)
				//this is where we use our PosBegCom_li variable which we had before
				//---
				//if the Identifier is "n" don't alert anything
				if (Identifier_ls == "n") continue;

				// 2007.02.22 - Chris Aybar - Hack to allow custom error messages...
				// For example:
				//    <input type="hidden" id="PDCPDCVldErrMsg_Q6A" value="ReqAns|a|You must complete the first question in Section 6.|;">
				if (document.getElementById('PDCPDCVldErrMsg_'+tempString) != undefined) {
					var custom_error_message = document.getElementById('PDCPDCVldErrMsg_'+tempString).value.split("|");
					alert (custom_error_message[2]);
				} else if ((ValErrMsgArr_Search(ValArr[i].slice(PosBegCom_li)) == -1) || (Identifier_ls == "s")) {
					StdErrMsg_ls = Str_FillInErrorParameters(StdErrMsg_ls, ExtraParameters_la);
					alert(StdErrMsg_ls+" ("+tempString+")");		
				} else {	
					KeyInErrMsgArr = ValArr[i].slice(PosBegCom_li);
					PosInErrMsgArr = ValErrMsgArr_Search(KeyInErrMsgArr);
					BeginPosErrMsg = ValArr[i].length - PosBegCom_li ;
					EndPosErrMsg = ValErrMsgArr[PosInErrMsgArr].length -1;
					StdErrMsg_ls = ValErrMsgArr[PosInErrMsgArr].slice(BeginPosErrMsg, EndPosErrMsg);
					StdErrMsg_ls = Str_FillInErrorParameters(StdErrMsg_ls, ExtraParameters_la);
					alert(StdErrMsg_ls+" ("+tempString+")");
				}
		
				//If the execution point reaches this line, it means that the outcome was false
				//and hence, the function execution should stop here
				//and the function should return false
	
				return false;

			}

	   } // end if loop

	} // end for loop

	// 2007/03/31 - Chris Aybar - Add ability to validate survey only.
	if (validate_only != undefined && validate_only == true)
	{
		return true;
	}
	else
	{
		return AllowNoDups();
	}
} 


// give feedback to the respondent about the state of their submission
function AllowNoDups(Form_aw){
   var tsv = document.forms[0].elements[Str_GetFrmIndex("PDCPDCSvrFil", document.forms[0].elements)].value;
   // alert('in script');
   // put your hand in the cookie jar
   var cookie_ls = document.cookie;
   // if you come up with a cookie indicating this was voted on already
   if (cookie_ls.indexOf(tsv) > -1) {
      // tell the user
      alert("You've already voted on this survey. Thank you for your interest!");
      return false;
   }else{
      // bake a cookie, put it in the cookie jar for next time and mark it with a freshness date
      //document.cookie = window.location.href + " from " + document.referrer + "; path=/; expires=Wed, 31-Dec-2008 00:00:01 GMT;";
      document.cookie = tsv + "; path=/; expires=Wed, 31-Dec-2008 00:00:01 GMT;";
      // you can change the expiration date of the cookie, as long as you use the format above
      return true;
   };
};


/************************************************************************************
 Save & Load Surveys v0.1
 Chris Aybar 11/01/2002
*************************************************************************************

 Release Notes:

 (1) To AUTOMATICALLY Save & Load respondent survey data,
     insert the following line of code anywhere in <BODY>:

       onload="loadSurvey()" onunload="saveSurvey()"

 (2) To allow the user to MANUALLY Save & Load their survey data,
     insert the following lines of code just before </FORM>:

      <SCRIPT>
          <!--
           SaveLoadButton ();
          // -->
      </SCRIPT>

 NOTE: If using option 2, do not insert a "Submit Survey" button, as this code will insert it automatically.
*************************************************************************************/

/************************************************************************************/
function resetForm () { document.forms[0].reset (); }

/************************************************************************************/
function hide (div)
{
  if (document.getElementById(div) != undefined)
  {
    document.getElementById(div).style.display = "none";
  }
}

/************************************************************************************/
function show (div)
{
  if (document.getElementById(div) != undefined)
  {
    document.getElementById(div).style.display = "";
  }
}

/************************************************************************************/
function checkEmail(email)
{
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (!filter.test(email))
  {
    alert ('Invalid email address');
  }
}

/************************************************************************************/
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

/************************************************************************************/
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/************************************************************************************/
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

/************************************************************************************/
function loadSurvey ()
{
  SurveyProject = new String (document.forms[0].elements[Str_GetFrmIndex("PDCPDCProjectID", document.forms[0].elements)].value.replace(/\s+/g,'_'));
  Input = new Array ();
  var Index, Type, Name, Value; 

  var CookieData = getCookie (SurveyProject);

  if (CookieData != null)
  {
    //var LoadSurveyWin = openWindow (LoadSurveyWin, 'BRLLoadSurvey.htm', 'LoadSurvey');
    var CookieArray = CookieData.split ('<ROW>');

    for (var i = 0; i < CookieArray.length; i++)
    {
      // Format: Index::Type::Name::Value
      Input = CookieArray[i].split ('::');

      Index = Input[0];
      Type  = Input[1];
      Name  = Input[2]; // Not really used
      Value = Input[3];      
      
      if (Type == 'text' || Type == 'textarea')
      { document.forms[0].elements[Index].value = Value; }
      else if (Type == 'checkbox' || Type == 'radio')
      { document.forms[0].elements[Index].checked = true; }
      else if (Type == 'select-one')
      { document.forms[0].elements[Index].options.selectedIndex = Value; }
    }

    //closeWindow (LoadSurveyWin);
    //window.focus ();
  }
  window.status = "Save and Resume is enabled";
}

/************************************************************************************/
function saveSurvey (show_window)
{
  SurveyProject = new String (document.forms[0].elements[Str_GetFrmIndex("PDCPDCProjectID", document.forms[0].elements)].value.replace(/\s+/g,'_'));
  var expDays = 30;
  var exp = new Date(); 
  exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
  var Delimiter = '<ROW>';
  var CookieData = '';

  if (show_window != undefined && show_window == true)
  {
    var SaveSurveyWin = openWindow (SaveSurveyWin, 'BRLSaveSurvey.htm', 'SaveSurvey');
  }

  deleteCookie (SurveyProject);

  for (var i = 0; i < document.forms[0].elements.length; i++)
  {
    //DEBUG: alert ("Name=" + document.forms[0].elements[i].name + "\nType=" + document.forms[0].elements[i].type + "\nChecked=" + document.forms[0].elements[i].checked + "\nValue=" + document.forms[0].elements[i].value);
    if (i == (document.forms[0].elements.length - 1)) { Delimiter = ''; }

    // Format: Index::Type::Name::Value

    if (((document.forms[0].elements[i].type == 'checkbox' || document.forms[0].elements[i].type == 'radio') && document.forms[0].elements[i].checked) ||
        document.forms[0].elements[i].type == 'select-one' ||
        ((document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'textarea') && document.forms[0].elements[i].value.length > 0))
    {
      if (document.forms[0].elements[i].type == 'checkbox' || document.forms[0].elements[i].type == 'radio')
      { CookieData = CookieData + i + '::' + document.forms[0].elements[i].type + '::' + document.forms[0].elements[i].name + '::' + document.forms[0].elements[i].value + Delimiter; }
      else if (document.forms[0].elements[i].type == 'select-one')
      { CookieData = CookieData + i + '::' + document.forms[0].elements[i].type + '::' + document.forms[0].elements[i].name + '::' + document.forms[0].elements[i].options.selectedIndex + Delimiter; }
      else
      { CookieData = CookieData + i + '::' + document.forms[0].elements[i].type + '::' + document.forms[0].elements[i].name + '::' + document.forms[0].elements[i].value + Delimiter; }
    }
  }

  //DEBUG: alert ('CookieData=' + CookieData);  

  setCookie (SurveyProject, CookieData, exp);

  //if (show_window != undefined && show_window == true)
  //{
  //  closeWindow (SaveSurveyWin);
  //  window.focus ();
  //}
}

/************************************************************************************/
function SaveLoadButton ()
{
  SurveyProject = new String (document.forms[0].elements[Str_GetFrmIndex("PDCPDCProjectID", document.forms[0].elements)].value.replace(/\s+/g,'_'));

  var SaveLoadCookie = getCookie (SurveyProject);

  //DEBUG: document.write ("<P>Cookie Data: " + SaveLoadCookie + "<P>");

  document.write ("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>\n" + "<TR><TD COLSPAN=2><HR NOSHADE SIZE=1></TD></TR>\n" + "<TR><TD ALIGN=Left><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit Survey\"></TD><TD ALIGN=Right>");
  if (!SaveLoadCookie) { document.write ("<INPUT TYPE=\"button\" NAME=\"ACTION\" VALUE=\"Save Survey\" onClick=\"saveSurvey()\">"); }
  else                 { document.write ("<INPUT TYPE=\"button\" NAME=\"ACTION\" VALUE=\"Save Survey\" onClick=\"saveSurvey()\"> <INPUT TYPE=\"button\" NAME=\"ACTION\" VALUE=\"Load Survey\" onClick=\"loadSurvey()\">"); }
  document.write ("</TD></TR>\n" + "<TR><TD COLSPAN=2><HR NOSHADE SIZE=1></TD></TR>\n" + "</TD></TR></TABLE>\n");
}

/************************************************************************************/
function openWindow (newWin, URL, Title)
{
  // Save & Load window Width and Height
  var Width = 430, Height = 200;
  if (document.all) { var xMax = screen.width, yMax = screen.height; }
  else              { if (document.layers) { var xMax = window.outerWidth, yMax = window.outerHeight; } else { var xMax = 640, yMax=480; } }
  var xOffset = (xMax - Width) / 2;
  var yOffset = (yMax - Height) / 2;

  if (newWin == null || newWin.closed) { newWin = open (URL, Title, 'screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',width='+Width+',height='+Height+',toolbar=no,location=no,directories=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,status=no'); }
  else { newWin.focus (); }

  return newWin;
}

/************************************************************************************/
function closeWindow (closeWin) { closeWin.focus (); closeWin.close (); }

/************************************************************************************/
function trim (value)
{
   var temp = value;
   var obj = /\s+/;
   if (obj.test(temp)) { temp = temp.replace(obj, ''); }
   return temp;
}

/************************************************************************************
 Custom Code: CARFAX Employee Satisfaction Survey
*************************************************************************************/
function validateCARFAX (qname, qvalue)
{
  groupMaster = new String (qname.substring (0,3));
  var groupIndex = new Array (0,0,0,0,0,0,0,0,0);

  // For any row, i.e., where all values are equal, but none are checked, enable all... 
  for (var i = 0; i < document.forms[0].elements.length; i++)
  {
    groupQuestion = document.forms[0].elements[i].name.substring(0,3);
    for (var v = 1; v <= 9; v++) { if (groupMaster == groupQuestion && document.forms[0].elements[i].value == v && document.forms[0].elements[i].checked == true) { groupIndex[v-1]++; break; } }
  }
  for (var i = 0; i < document.forms[0].elements.length; i++)
  {
    groupQuestion = document.forms[0].elements[i].name.substring(0,3);
    for (var v = 1; v <= 9; v++) { if (groupMaster == groupQuestion && document.forms[0].elements[i].value == v && groupIndex[v-1] == 0) { document.forms[0].elements[i].disabled = false; } }
  }

  // Disable all button of same value
  for (i = 0; i < document.forms[0].elements.length; i++)
  {
    groupQuestion = document.forms[0].elements[i].name.substring(0,3);

	if (groupQuestion == groupMaster && document.forms[0].elements[i].name != qname && document.forms[0].elements[i].value == qvalue)
    {
	  document.forms[0].elements[i].disabled = true;
    }
  }
}

/************************************************************************************
 Custom Code: COUNTRYWIDE Exit Survey 2004
*************************************************************************************/
function validateCOUNTRYWIDEQ7 (obj,question)
{
  var options_checked = 0;
  var question_length = question.length;
  for (i = 0; i < question_length; i++ )
  {
      if (question[i].checked == true) {
        options_checked++;
      }
      if (options_checked > 5)
      {
        alert ("You may select up to five factors only.");
        obj.checked = false;
        return false;
      }
  }
}

/************************************************************************************
 Custom Code: COUNTRYWIDE Exit Survey 2003
*************************************************************************************/
function validateCOUNTRYWIDEQ17 (qname)
{
  qname.value = trim (qname.value);

  if (qname.value.length >= 1)
  {
    if (qname.value < 1 ||qname.value > 5)
    {
      alert (qname.value + " is invalid.\n\n" + "Please rank from 1 - 5");
      qname.value = "";
      return 1;

    } else if (qname.value >= 1 && qname.value <= 5)
    {
      var groupIndex = new Array ('Q17_1', 'Q17_2', 'Q17_3', 'Q17_4', 'Q17_5', 'Q17_6', 'Q17_7', 'Q17_8', 'Q17_9', 'Q17_10', 'Q17_11', 'Q17_12', 'Q17_13', 'Q17_14');

      // Ensure no two items have the same ranking...
      for (var i = 0; i < groupIndex.length; i++)
      {
        if (document.forms[0].elements[groupIndex[i]].toString != qname.toString && document.forms[0].elements[groupIndex[i]].value.length >= 1)
        {
	   //DEBUG: alert (groupIndex[i] + "\n\n" + document.forms[0].elements[groupIndex[i]].value    + " == " + qname.value);

    	  if (document.forms[0].elements[groupIndex[i]].value == qname.value)
          {
            alert (qname.value + " has already been entered.\n\n" + "Please rank from 1 - 5");
            qname.value = '';
            break;
          }
        }
      }
    }
  }
}

/************************************************************************************
 Custom Code: Find/SVP Survey 2003
*************************************************************************************/
function validateFINDSVPQ14 (qname)
{
  qname.value = trim (qname.value);

  if (qname.value.length >= 1)
  {
    if (qname.value < 1 ||qname.value > 8)
    {
      alert (qname.value + " is invalid.\n\n" + "Please rank from 1 - 8");
      qname.value = "";
      return 1;

    } else if (qname.value >= 1 && qname.value <= 8)
    {
      var groupIndex = new Array ('Q14_1', 'Q14_2', 'Q14_3', 'Q14_4', 'Q14_5', 'Q14_6', 'Q14_7', 'Q14_8');

      // Ensure no two items have the same ranking...
      for (var i = 0; i < groupIndex.length; i++)
      {
        if (document.forms[0].elements[groupIndex[i]].toString != qname.toString && document.forms[0].elements[groupIndex[i]].value.length >= 1)
        {
	   //DEBUG: alert (groupIndex[i] + "\n\n" + document.forms[0].elements[groupIndex[i]].value    + " == " + qname.value);

    	  if (document.forms[0].elements[groupIndex[i]].value == qname.value)
          {
            alert (qname.value + " has already been entered.\n\n" + "Please rank from 1 - 8");
            qname.value = '';
            break;
          }
        }
      }
    }
  }
}

/************************************************************************************
 Custom Code: Horizon Bay Survey 2005
*************************************************************************************/
function validateHORIZONBAYQ12 (qname, language)
{
  qname.value = trim (qname.value);

  if (qname.value.length >= 1)
  {
    if (qname.value < 1 ||qname.value > 9)
    {
      if (language == "en" )
          alert (qname.value + " is invalid.\n\n" + "Please rank from 1 - 9");
      else if (language == "sp" )
          alert (qname.value + " es invalido.\n\n" + "Por favor use los números del 1 al 9");

      qname.value = "";
      return 1;

    } else if (qname.value >= 1 && qname.value <= 9)
    {
      var groupIndex = new Array ('Q12_RANK_1', 'Q12_RANK_2', 'Q12_RANK_3', 'Q12_RANK_4', 'Q12_RANK_5', 'Q12_RANK_6', 'Q12_RANK_7', 'Q12_RANK_8', 'Q12_RANK_9');

      // Ensure no two items have the same ranking...
      for (var i = 0; i < groupIndex.length; i++)
      {
        if (document.forms[0].elements[groupIndex[i]].toString != qname.toString && document.forms[0].elements[groupIndex[i]].value.length >= 1)
        {
	   //DEBUG: alert (groupIndex[i] + "\n\n" + document.forms[0].elements[groupIndex[i]].value    + " == " + qname.value);

    	  if (document.forms[0].elements[groupIndex[i]].value == qname.value)
          {
            if (language == "en" )
                alert (qname.value + " has already been entered.\n\n" + "Please rank from 1 - 9");
            else if (language == "sp" )
                alert (qname.value + " ha sido usado.\n\n" + "Por favor use los números del 1 al 9");

            qname.value = '';
            break;
          }
        }
      }
    }
  }
}

/************************************************************************************
 Custom Code: EXTRACTION Exit Survey 2004
*************************************************************************************/
function validateEXTRACTIONQ12 (qname)
{
  qname.value = trim (qname.value);

  if (qname.value.length >= 1)
  {
    if (qname.value < 1 ||qname.value > 16)
    {
      alert (qname.value + " is invalid.\n\n" + "Please rank from 1 - 16");
      qname.value = "";
      return 1;

    } else if (qname.value >= 1 && qname.value <= 16)
    {
      var groupIndex = new Array ('P2_Q12_1', 'P2_Q12_2', 'P2_Q12_3', 'P2_Q12_4', 'P2_Q12_5', 'P2_Q12_6', 'P2_Q12_7', 'P2_Q12_8', 'P2_Q12_9', 'P2_Q12_10', 'P2_Q12_11', 'P2_Q12_12', 'P2_Q12_13', 'P2_Q12_14', 'P2_Q12_15', 'P2_Q12_16');

      // Ensure no two items have the same ranking...
      for (var i = 0; i < groupIndex.length; i++)
      {
        if (document.forms[0].elements[groupIndex[i]].toString != qname.toString && document.forms[0].elements[groupIndex[i]].value.length >= 1)
        {
	   //DEBUG: alert (groupIndex[i] + "\n\n" + document.forms[0].elements[groupIndex[i]].value    + " == " + qname.value);

    	  if (document.forms[0].elements[groupIndex[i]].value == qname.value)
          {
            alert (qname.value + " has already been entered.\n\n" + "Please rank from 1 - 16");
            qname.value = '';
            break;
          }
        }
      }
    }
  }
}

/************************************************************************************
 Custom Code: MPS Survey 2005
*************************************************************************************/
function validateMPSQ1 (qname)
{
  qname.value = trim (qname.value);

  if (qname.value.length >= 1)
  {
    if (qname.value < 1 ||qname.value > 9)
    {
      alert (qname.value + " is invalid.\n\n" + "Please rank from 1 - 9");
      qname.value = "";
      return 1;

    } else if (qname.value >= 1 && qname.value <= 9)
    {
      var groupIndex = new Array ('Q1_1', 'Q1_2', 'Q1_3', 'Q1_4', 'Q1_5', 'Q1_6', 'Q1_7', 'Q1_8', 'Q1_9');

      // Ensure no two items have the same ranking...
      for (var i = 0; i < groupIndex.length; i++)
      {
        if (document.forms[0].elements[groupIndex[i]].toString != qname.toString && document.forms[0].elements[groupIndex[i]].value.length >= 1)
        {
	   //DEBUG: alert (groupIndex[i] + "\n\n" + document.forms[0].elements[groupIndex[i]].value    + " == " + qname.value);

    	  if (document.forms[0].elements[groupIndex[i]].value == qname.value)
          {
            alert (qname.value + " has already been entered.\n\n" + "Please rank from 1 - 9");
            qname.value = '';
            break;
          }
        }
      }
    }
  }
}

/************************************************************************************
 Custom Code: CITY OF FRESNO 2006
*************************************************************************************/
function validateCITYOFFRESNOQ20 (division)
{
  var DIVISIONS = new Array (); 

  DIVISIONS[0] = '';
  DIVISIONS[1] = new Array ();  
  DIVISIONS[2] = new Array ();
  DIVISIONS[3] = new Array ();
  DIVISIONS[4] = new Array ();
  
  DIVISIONS[5] = new Array ();
  DIVISIONS[5][0] = 'Administration/Budget';
  DIVISIONS[5][1] = 'Accounting';
  DIVISIONS[5][2] = 'Utility Billing and Collections';
  
  DIVISIONS[6] = new Array ();
  DIVISIONS[6][0] = 'Administrative Services';
  DIVISIONS[6][1] = 'Fire Suppression and Emergency Response';
  DIVISIONS[6][2] = 'Fire Prevention and Investigation';
  DIVISIONS[6][3] = 'Fire Training and Support Services';



  var division11 = document.getElementById
  if (division <= 4) 
  {
    
  }
  var options_checked = 0;
  var question_length = question.length;
  for (i = 0; i < question_length; i++ )
  {
      if (question[i].checked == true) {
        options_checked++;
      }
      if (options_checked > 5)
      {
        alert ("You may select up to five factors only.");
        obj.checked = false;
        return false;
      }
  }
}

/************************************************************************************/
function validateRATINGS (qarray, qname, min, max)
{
  qname.value = trim (qname.value);

  if (qname.value.length >= 1)
  {
    if (qname.value < min || qname.value > max)
    {
      alert (qname.value + " is invalid.\n\n" + "Please rank from " + min + " to " + max + ".");
      qname.value = "";
      return 1;
    }
    else if (qname.value >= min && qname.value <= max)
    {
      var groupIndex = qarray;

      // Ensure no two items have the same ranking...
      var send_alert = false;
      for (var i = 0; i < groupIndex.length; i++)
      {
        if (document.forms[0].elements[groupIndex[i]].toString != qname.toString && document.forms[0].elements[groupIndex[i]].value.length >= 1)
        {
	   //DEBUG: alert (groupIndex[i] + "\n\n" + document.forms[0].elements[groupIndex[i]].value    + " == " + qname.value);

    	  if (document.forms[0].elements[groupIndex[i]].value == qname.value)
          {
            send_alert = true;
            qname.value = '';
          }
        }
      }
 
      if (send_alert)
      {
            alert ("Value has already been entered.\n\n" + "Please rank from " + min + " to " + max + ".");
      }
    }
  }
}

/************************************************************************************/
function getOpenEnd (rating)
{
  return prompt ("Please specify why you chose: " + rating, '');
}

/************************************************************************************/
function resetQuestion (Q)
{
  for (var i = 0; i < document.forms[0].elements.length; i++)
  {
    if ( document.forms[0].elements[i].name == Q || document.forms[0].elements[i].name.indexOf(Q+'_') != -1 )
    {
      if (   ((document.forms[0].elements[i].type == 'checkbox' || document.forms[0].elements[i].type == 'radio') && document.forms[0].elements[i].checked)
          || ((document.forms[0].elements[i].type == 'select-one'))
          || ((document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'textarea') && document.forms[0].elements[i].value.length > 0))
      {
        if (document.forms[0].elements[i].type == 'checkbox' || document.forms[0].elements[i].type == 'radio')
        {      
            document.forms[0].elements[i].checked = false;
        }
        else if (document.forms[0].elements[i].type == 'select-one')
        { 
          document.forms[0].elements[i].options.selectedIndex = '';
        }
        else
        {
          document.forms[0].elements[i].value = '';
        }
      }
    }
  }
}

/************************************************************************************/
function getCurrentTime()
{
  var now = new Date();
  return now.getFullYear() + '/' + ((now.getMonth()+1 < 10) ? '0'+(now.getMonth()+1) : now.getMonth()+1) + '/' + ((now.getDate() < 10) ? '0'+now.getDate() : now.getDate()) + ' ' + ((now.getHours() < 10) ? '0'+now.getHours() : now.getHours()) + ':' + ((now.getMinutes() < 10) ? '0'+now.getMinutes() : now.getMinutes()) + ':' + ((now.getSeconds() < 10) ? '0'+now.getSeconds() : now.getSeconds());
}

function printTimeFields()
{
  document.write("<input type=\"hidden\" name=\"PDCPDCSTime\" value=\"" + getCurrentTime() + "\">\n");
  document.write("<input type=\"hidden\" name=\"PDCPDCFTime\" value=\"\">\n");
}

/************************************************************************************/
// Capture ENTER key press
function kH(e)
{
  var pK = document.all? window.event.keyCode:e.which;
  return pK != 13;
}

document.onkeypress = kH;

if (document.layers)
{
  document.captureEvents(Event.KEYPRESS);
}

/************************************************************************************/
function popUp(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480,left = 320,top = 272');");
}
