// Perseus JavaScript Functions
// For assistance, please e-mail techsupport@perseus.com
// (c) 2002 Perseus Development Corp.

//Version 3.01 10/13/00
//Version 5.00 03/06/02 BP

var PdcForm;	//Form


// *** SurveyPeople Code ***
function PdcValidate(CookieCheck) {
	var IE=(document.all);
	var N4=(document.layers);
	var W3=(document.getElementById && !IE);
// original Perseus function is      function PdcValidate() {
// *** SurveyPeople Code ***


	var ValidationType 	//String
	var ValCommands;	//Array
	var ElementIndex;	//Number
	var ErrorMessage;	//String
	var ArgOne;			//String
	var ArgTwo;			//String
	var Result;			//Boolean
	var ValArr;			//Array
	var MsgArr;			//Array
	var Message;		//Array
	var MessageTable;	//Object
	var QuestionName;	//String
	var S;				//String

	PdcForm = document.PdcSurvey;

	if (PdcForm.elements["PdcValidation"] == null  ||  PdcForm.elements["PdcValidation"] == undefined) {
		if(CookieCheck == true) return AllowNoDups();
		return true;
	};


	S = PdcForm.elements["PdcValidation"].value;
	if (S != "") {ValArr = S.split(";");}

	S = PdcForm.elements["PdcValidationMessages"].value;
	if (S != "") {
		MsgArr = S.split(";");

		MessageTable = new Array();
		for (var i=0;i<MsgArr.length;i++) {
			//Build an array of the message name/value pairs.
			Message = MsgArr[i].split("|");
			MessageTable[Message[0]] = Message[1];
		}
	}

	for (var i=0;i<ValArr.length;i++){
		CurrentString = new String(ValArr[i]);

		if (CurrentString.length > 0) {

			ValCommands = CurrentString.split("|");

			QuestionName = ValCommands[0];
			ElementIndex = GetFormIndex(QuestionName);

			ValidationType = ValCommands[1];
			ArgOne = ValCommands[2];
			ArgTwo = ValCommands[3];

			switch (ValidationType) {
				//Question validations.
				case "ReqAns": {
					Result = IsQuestionAnswered(QuestionName);
					//Some questions use ArgOne to specify a more descriptive question name.
					//Defect 892. First character lost in descriptive name, add space to compensate.
					//Defect 917. Ensure Answer Required works on all browsers
					if ((ArgOne) && (ArgOne != "")) QuestionName = ' ' + ArgOne;				
					break;
				}
// *** SurveyPeople Code ***
				case "ReqAns2": {
					Result = IsQuestionAnswered(QuestionName);
					//Some questions use ArgOne to specify a more descriptive question name.
					//Defect 892. First character lost in descriptive name, add space to compensate.
					//Defect 917. Ensure Answer Required works on all browsers
					if ((ArgOne) && (ArgOne != "")) QuestionName = ' ' + ArgOne;				
					break;
				}

				case "ReqAns3": {
					Result = IsQuestionAnswered(QuestionName);
					//Some questions use ArgOne to specify a more descriptive question name.
					//Defect 892. First character lost in descriptive name, add space to compensate.
					//Defect 917. Ensure Answer Required works on all browsers
					if ((ArgOne) && (ArgOne != "")) QuestionName = ' ' + ArgOne;				
					break;
				}
// *** SurveyPeople Code ***

				if ((ArgOne != "") && (ArgOne != null) && (ArgOne != undefined)) QuestionName = ArgOne;
					break;
				
				case "ReqSpecify": {
					//If the choice is selected see if the text field has a value.					
					if (eval(ArgOne)) Result = IsSpecifyAnswered(ArgTwo);
					break;
				}
				case "ChkMin": {
					Result = (SelectedCount(QuestionName) >= Number(ArgOne));
					break;
				}
				case "ChkMax": {
					Result = (SelectedCount(QuestionName) <= Number(ArgOne));
					break;
				}
				case "ChkExc": {
					Result = (SelectedCount(QuestionName) == Number(ArgOne));
					break;
				}
				case "ReqSum": {
					//#626 Get the current total as ArgTwo and verify against the expected
					//total (ArgOne). If the question has not been answered ArgTwo will
					//be zero, this is a valid condition.
					ArgTwo = QuestionTotal(QuestionName);
					Result = ((ArgTwo == 0) || (ArgTwo == Number(ArgOne)))
					break;
				}
				case "ReqRnk": {
					Result = ValidateRankings(QuestionName);
					if (ArgOne != "") QuestionName = ArgOne;
					break;
				}

				//Topic validations.
				//#530 Allow for empty field value.
				case "Email": {
					var fieldValue = PdcForm.elements[ElementIndex].value;
					Result = ((fieldValue == "") || (IsValidEmailAddress(fieldValue)));
					break;
				}
				case "Num": {
					var fieldValue = PdcForm.elements[ElementIndex].value;
					Result = ((fieldValue == "") || (IsNumber(fieldValue)));
					break;
				}

				case "MinLen": {
					var fieldValue = PdcForm.elements[ElementIndex].value;
					Result = ((fieldValue == "") || (fieldValue.length >= Number(ArgOne)));
					break;
				}

				case "Range": {
					var fieldValue = PdcForm.elements[ElementIndex].value;
					Result = ((fieldValue == "") || (ValidateNumber(fieldValue, ArgOne, ArgTwo)));
					break;
				}

				default: {
					//Used for debugging.
					//alert("An invalid validation command was specified (" + ValidationType + ").");
					return true;
				}
			}

			if (Result == false) {
				if (ElementIndex != -1) {
				
				with(PdcForm.elements[ElementIndex]) {
					if ((type == "text") || (type == "textarea") || (type == "password")) {
						select();
					} else if ((type == "checkbox") || (type == "radio")) {
// *** SurveyPeople Code ***	
						if (IE || W3) {
							if (disabled) {
								// Do nothing							
							} else {
								focus()
							}
						} else {
							focus();
						}	
// Original Perseus code    focus();						
// *** SurveyPeople Code ***						
					}
				}
			}
				//Jump to the problem question.
				window.location = "#" + QuestionName;

				//Get the error message from the table and replace any placeholders.
				ErrorMessage = MessageTable[ValidationType];
				ErrorMessage = ErrorMessage.replace(/%Q/g, QuestionName.substr(1));
				ErrorMessage = ErrorMessage.replace(/%1/g, ArgOne);
				ErrorMessage = ErrorMessage.replace(/%2/g, ArgTwo);

				//Alert the user.
				alert(ErrorMessage);
				return false;
			}
	   }
	}
	
// *** SurveyPeople Code ***	
	if(CookieCheck == true) return AllowNoDups();
// *** SurveyPeople Code ***
	
	return true;
}



function RandomizeChoices(QuestionName, SelectedValue) {
	//Randomizes the contents of an option list.
	//Don't move the first item which is the placeholder.
	//(e.g., "", or "(Click to choose)")

	var y;
	var XText, XValue;
	var YText, YValue;

	PdcForm = document.PdcSurvey;
	var ChoiceList = PdcForm.elements[GetFormIndex(QuestionName)];
	var OptionCount = ChoiceList.options.length - 1;
	var SelectedIndex = SelectedValue;

	// Loop thru the options.
	for (var x=1;x<OptionCount;x++){
	   	// Swap the current option with a randomly select different option
		y = Math.floor(Math.random() * OptionCount) + 1;
		XText = ChoiceList.options[x].text;
		XValue = ChoiceList.options[x].value;
		YText = ChoiceList.options[y].text;
		YValue = ChoiceList.options[y].value;
		ChoiceList.options[x] = new Option(YText, YValue);
		ChoiceList.options[y] = new Option(XText, XValue);

        // Preserve the selection.
        if (SelectedValue == XValue) {
			SelectedIndex = y;
		} else if (SelectedValue == YValue) {
			SelectedIndex = x;
		}
	}
	// Reset the selection.
	ChoiceList.selectedIndex = SelectedIndex;
	return;
}

// Autojump based on a list selection.
function SelectJump(sel, JumpString) {
   var SelArr = JumpString.split(";");
   var ValArr = new Array();

   for (var i=0;i<SelArr.length;i++){
     if (SelArr[i].length > 0) {
       ValArr = SelArr[i].split("|");
         if((ValArr.length == 2) && (parseInt(sel.options[sel.selectedIndex].value) == parseInt(ValArr[0]))){
            window.location = ValArr[1]
            break;
         }
      }
   }
}

// Support functions.

//Return true if the value falls within the range.
function ValidateNumber(Value, Minimum, Maximum) {
	var result = false;

	//Test if the value is a number. Exit if this fails.
	if (IsNumber(Value)) {
		result = true;
		Value = Number(Value);
	} else {
		return false;
	}

	if (Minimum != "" && Maximum != "") {
		result = ((Value >= Number(Minimum)) && (Value <= Number(Maximum)));
	} else if (Minimum != "") {
		result = (Value >= Number(Minimum));
	} else if (IsNumber(Maximum)) {
		result = (Value <= Number(Maximum));
	}

	return result;
}

//Return true if the supplied value is a number.
function IsNumber(Value) {
	//Use a regular expression to test if the value is a number.
	//Look for an optional minus sign followed by any number of digits
	//an optional decimal place (comma or period), and optional decimal digits.
	return Boolean(Value.match(/^-?\d+[,.]?\d*-?$/));
}

//Return the number of selected choices for the question.
function SelectedCount(QuestionName) {
	var x = 0;
	var r = new RegExp("^" + QuestionName + "_");

	for(var i=0;i<PdcForm.elements.length;i++) {
		//If the element matches the reg exp and is checked add it to the total count.
		if (PdcForm.elements[i].name.match(r) && PdcForm.elements[i].checked) {
			x = x + 1;
		}
	}
	return x
}

//Return the total for the specified question.
function QuestionTotal(QuestionName) {
	var FieldTotal = 0;
	var r = new RegExp("^" + QuestionName + "_");

	for(var i=0;i<PdcForm.elements.length;i++) {
		//If the element matches the reg exp and it's value is not empty add it to the total.
		if (PdcForm.elements[i].name.match(r) && (PdcForm.elements[i].value != "")) {
			FieldTotal += parseFloat(PdcForm.elements[i].value);
		}
	}

	//Return the accumulated total.
	return FieldTotal;
}

//Return true if the email address is valid.
function IsValidEmailAddress(address) {

	// Smallest email address is a@b.c
	if (address.length < 5) return false;

	// look for illegal characters.
	if (address.match(/[,|\/\\]|(@.*@)|(\.\.)|(\.$)/)) return false;

	// Check for proper format.
	if (address.match(/^[\w\-\.]+[\%\+]?[\w\-\.]*\@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/)) {
		return true;
	} else {
		return false;
	}
}


//Return whether the question has been answered.
function IsQuestionAnswered(QuestionName) {

	var r = new RegExp("^" + QuestionName);
	
// *** SurveyPeople Code ***
//DisabledCount keeps track of the number of disabled checkboxes encountered in a question and BoxCount tracks the total number of checkboxes in a question	
	var	DisabledCount = 0
	var BoxCount = 0
	var IE=(document.all);
	var N4=(document.layers);
	var W3=(document.getElementById && !IE);
// *** SurveyPeople Code ***
	
	for(var i=0;i<PdcForm.elements.length;i++) {

		with (PdcForm.elements[i]) {
		
			//If the element matches the reg exp test based on type.
			if (name.match(r)) {

				BoxCount++;
				if (((type == "text") || (type == "textarea") || (type == "password")) && (name.indexOf("Specified")==-1)) {
					return (value != "")
				}
				else if ((type == "checkbox") || (type == "radio")) {
				
						if (checked) return true;

// *** SurveyPeople Code ***
						if (IE || W3) {
							if (disabled) DisabledCount=DisabledCount+1
						} else if (N4) {
							//	Can't get it to work perfectly for N4, so skip it.
						}
// *** SurveyPeople Code ***
						
				} 
				else if ((type == "select-one") || (type == "select-multiple")) {
					var selectedIndex = SelectedOption(options);

					//If there is a selected option and it's value is non-zero (the placeholder
					//value is zero) then return true.
					if ((selectedIndex != 0) && (options[selectedIndex].value != 0)) {
						return true;
					}
				}
			}
		}
	}

// *** SurveyPeople Code ***	
// if all checkboxes are disabled in a question, then mark question as having been answered
	if (IE || W3) {
		if(DisabledCount == BoxCount) {
			return true;
		} else {
			return false;
		}
	} else if (N4) {
		return false;
		//	the function disabled doesnt work in N4, so skip it.
	}
// *** SurveyPeople Code ***

}




//Return whether the specify has been answered.
//Defect 897 Need seperate function to check Specified Required feature, without ignoring headings that contain Specified
function IsSpecifyAnswered(QuestionName) {
	var r = new RegExp("^" + QuestionName);

	for(var i=0;i<PdcForm.elements.length;i++) {

		with (PdcForm.elements[i]) {
			//If the element matches the reg exp test based on type.
			if (name.match(r)) {
				if ((type == "text") || (type == "textarea")) {
					return (value != "");
				}
			}
		}
	}
	return false;
}


//Return the index of the selected option from the array.
function SelectedOption(OptionArray) {

	for(var x=0;x<OptionArray.length;x++) {
		if (OptionArray[x].selected) return x;
	}
	return 0;
}

//Return true if all topics in the table have unique choice selections.
function ValidateRankings(QuestionName) {
	var Index;
	var r = new RegExp("^" + QuestionName + "_");
	var ChoiceValues = new Array();

	for(var i=0;i<PdcForm.elements.length;i++) {
		Index = 0;  //Clear index on each pass.

		with (PdcForm.elements[i]) {
			//If the element matches the reg exp test based on type.
			if (name.match(r)) {

				//Get the index of the selected item.
				if (type == "select-one") {
					Index = SelectedOption(options);
				} else if ((type == "radio") && checked) {
					Index = Number(value);
				}

				//If there is a selected index test if it has already been set.
				if (Index != 0) {
					if (ChoiceValues[Index] == 1) {
						return false;
					} else {
						ChoiceValues[Index] = 1;
					}
				}
			}
		}
	}
	return true;
}

//Return the index of the specified form element.
function GetFormIndex(ElementName) {
	var i;
	for(i=0;i<PdcForm.elements.length;i++) {
		if (PdcForm.elements[i].name == ElementName) {
			return i;
		}
	}
	return -1;
}

// These functions allow forms to be AutoSubmitted.
// If the user doesn't change any values before the timeout
// then the form will be submitted and the results cleared.

var AutoReset;	// Boolean
var InitialValues = new Array(); // Initial values of each control of the form
var LastValues = new Array(); 	 // Values of each control of the form the last time the timer elapsed

// Records initial values and starts the first call to the timer.
function AutoSubmit(ArgOne) {

	PdcForm = document.PdcSurvey;
	AutoReset = Boolean(ArgOne);

	RecordValues();
	RunTimer();
}

// Record the initial values of all of the form elements.
function RecordValues() {

   for (x=0;x<PdcForm.elements.length;x++) {
      if ((PdcForm.elements[x].type == "radio") || (PdcForm.elements[x].type == "checkbox")) {
         InitialValues[x] = PdcForm.elements[x].checked
      } else if ((PdcForm.elements[x].type == "select-one") || (PdcForm.elements[x].type == "select-multiple")) {
         InitialValues[x] = PdcForm.elements[x].options[PdcForm.elements[x].selectedIndex].value
      } else {
         InitialValues[x] = PdcForm.elements[x].value
      }
   }
}

// Set the window timeout.
function RunTimer() {
	// Set the time out to 60 minutes.
	// Specified in thousandths of a second (e.g., 1000 = 1 second, 60000 = 1 minute)
   	var Timeout = 3600000;
	window.setTimeout("CheckValues();", Timeout)
}

function CheckValues() {
   // determine if the control values have changed, and if so, submit and reset
   var ChangeFromInit = false;
   var ChangeFromLast = false;

   // for each form element
   for (x=0;x<PdcForm.elements.length;x++) {
      // if the element doesn't equal the initial value
      if ((PdcForm.elements[x].type == "radio") || (PdcForm.elements[x].type == "checkbox")) {
         if (InitialValues[x] != PdcForm.elements[x].checked)
         	ChangeFromInit = true;
      } else if ((PdcForm.elements[x].type == "select-one") || (PdcForm.elements[x].type == "select-multiple")) {
         if (InitialValues[x] != PdcForm.elements[x].options[PdcForm.elements[x].selectedIndex].value)
         	ChangeFromInit = true;
      } else {
         if (InitialValues[x] != PdcForm.elements[x].value) ChangeFromInit = true;
      }
   }

   // if changed from the initial value
   if (ChangeFromInit) {
      // for each form element
      for (x=0;x<PdcForm.elements.length;x++) {

		 with(PdcForm.elements[x]) {

			 // if the element doesn't equal the last value
			 if ((type == "radio") || (type == "checkbox")) {
				if (LastValues[x] != checked) ChangeFromLast = true;
				LastValues[x] = checked
			 } else if ((type == "select-one") || (type == "select-multiple")) {
				if (LastValues[x] != options[selectedIndex].value) ChangeFromLast = true;
				LastValues[x] = options[selectedIndex].value
			 } else {
				if (LastValues[x] != value) ChangeFromLast = true;
				LastValues[x] = value;
			 }
		 }
      }

      // If not changed from last value submit the form.
      if (!ChangeFromLast) {

		// For a kiosk use of a web survey, reset the form to blank
		// else submit the form.
		if (AutoReset)
			// If Reset Button exists, click it
			if (PdcForm.reset) {
				PdcForm.reset.click();
			// Else perform form reset
			} else {
				PdcForm.reset();
			}
		else
			// If Submit Button exists, click it
			if (PdcForm.submit) {
				PdcForm.submit.click();
			// Else perform form submit
			} else {
				PdcForm.submit();
			}
	  }
   }
   RunTimer();
}

//Store a cookie with the supplied name/value (path and expires are optional).
function SetCookie(Name, Value, Path, Expires) {
	var CookieString;

	CookieString = Name + "=" + escape(Value)

	if (Path) CookieString += "; path=" + Path;
	if (Expires) CookieString += "; expires=" + Expires.toGMTString();

	document.cookie = CookieString
}

//Answer the stored value for the named cookie.
function GetCookieValue(Name) {
	var Cookies;
	var NameValuePair;
	var CookieString = document.cookie;

	//Get an array of cookie pairs by splitting on ;
	Cookies = CookieString.split("; ");

	for (var i=0;i<Cookies.length;i++){
		NameValuePair = Cookies[i].split("=");
		if (NameValuePair[0] == Name) {
			return unescape(NameValuePair[1]);
		}
	}
}

//Save the current page.
function SaveCurrentPage() {
	var d = new Date();

	//Set the cookie to expire in one month.
	d.setMonth(d.getMonth() + 1);
	SetCookie(CurrentPageCookieName(), document.PdcSurvey.PdcCurrentPage.value, "/", d);
}

//Check if there was a previous current page.
function CheckCurrentPage() {
	var CurrentPage = GetCookieValue(CurrentPageCookieName());

	//Verify that current page is non-null and not an empty string.
	//Verify that there is a nextpage field on this page.
	if ((CurrentPage != null) && (CurrentPage != "") && (document.PdcSurvey.PdcNextPage != null))
		document.PdcSurvey.PdcNextPage.value = CurrentPage;
}

//Answer the name of the cookie to save the current page with.
function CurrentPageCookieName() {
	var ProjectName;

	ProjectName = document.PdcSurvey.PdcProjectID.value;
	if (ProjectName == "")
		return "PdcCurrentPage";
	else
		return "Pdc" + ProjectName;
}


//  ****************************************************************************************************************************************************

//   THE FUNCTIONS BELOW ARE COPYRIGHT OF SURVEYPEOPLE CORP., 2002




function noneoftheabove(Qhdg){
//Argument is the question whose check box is to be blanked out. ie. QB4_8
//IE    onclick=noneoftheabove('QB4_8') on "EACH" line of Question QB4
// IMPORTANT - The question number must in single quotes

	var flag =0;
	var i=1;
	var uscore="_";
	var Qcnt=Qhdg.split(uscore);
	var IE=(document.all);
	var N4=(document.layers);
	var W3=(document.getElementById && !IE);
	if (IE || W3) {
		while(i<Qcnt[1] ){
			var QcurrQhdg=Qcnt[0]+uscore+i;
			if(document.forms[0][QcurrQhdg].checked == true){
			 flag=1;
			}
			++i;
		}
		if(flag != 0){
			document.forms[0][Qhdg].disabled = true;
			document.forms[0][Qhdg].checked = false;
		}else{
			document.forms[0][Qhdg].disabled = false;
		}
	}
}



function BlankGroupOfRadioButtons(Qcnt1,Qcnt2,FirstPos,Optnum,Greyout,Order){
//This function can be called from a radio button or from a Checkbox question
//First Argument is the question name of the question calling this subroutine ie QA4[0] or   this
//Second Argument is the question whose radio buttons are to be blanked out, ie QA5a
//Third Argument is the 1st position of the 1st radio button to be to be blanked out, ie 3 (3rd radio button)
//Forth Argument is the number of radio buttons in the question to be blanked out
//Fifth Argument - Greyout- If true then disables buttons, if false, enables button
//Sixth Argument - Order - Use for when called from a Checkbox only. For Radio button call use 0 always or leave blank.
//Example of call -  onclick="BlankGroupOfRadioButtons(this,QB5a,3,8,true,0)";

//The above means that in question QB5a, buttons 3 through 11 will be blanked out

	var i=FirstPos-1;
	var IE=(document.all);
	var N4=(document.layers);
	var W3=(document.getElementById && !IE);
	if (IE || W3) {
	if(Optnum == undefined)  {
		alert("Parameters passed to routine BlankOutRadioButton in "+Qcnt1+" are incorrect");
	}
	if(Order == undefined)  {
		Order = 0
	}

	if(Order == 0){
		if(Qcnt1.checked && Greyout == true){
			while(i<Optnum+FirstPos-1){

				Qcnt2[i].disabled = true;
				Qcnt2[i].checked = false;
				++i;
			}
		}else{
			while(i<Optnum+FirstPos-1){
				Qcnt2[i].disabled = false;
				Qcnt2[i].checked = false;
				++i;
			}
		}
	}else{
		if(Qcnt1.checked == false && Greyout == true){
			while(i<Optnum+FirstPos-1){
				Qcnt2[i].disabled = true;
				Qcnt2[i].checked = false;
				++i;
			}
		}else{
			while(i<Optnum+FirstPos-1){
				Qcnt2[i].disabled = false;
				Qcnt2[i].checked = false;
				++i;
			}
		}
	}
	}
}



function BlankEntireRadioButtonQuestion(Qcnt1,Qcnt2,Optnum,Greyout,Order){

//Do not use this function. It is being phased out and replaced by the more universal BlankGroupOfRadioButtons.

//This function can be called from a radio button or from a Checkbox question
//First Argument is the question name of the question calling this subroutine. Use "this" ie QA4[0]
//Second Argument is the question whose radio buttons are to be blanked out, ie QA5a
//Third Argument is the number of radio buttons in the question to be blanked out
//Fourth Argument - if true then disables buttons, if false, enables button
//Fifth Argument - For when called from a Checkbox only. For Radio button call use 0 always.
//		   If 0, then when checked, greyed out, when unchecked, not greyed out.
//                 If 1, then when checked, not greyed out, when unchecked, greyed out.
//Example of call -  onclick="BlankEntireRadioButtonQuestion(this,QB5a,8,true,1)";

	var i=0;
	var IE=(document.all);
	var N4=(document.layers);
	var W3=(document.getElementById && !IE);
	if (IE || W3) {
	if(Optnum == undefined)  {
		alert("Parameters passed to routine BlankOutRadioButton in "+Qcnt1+" are incorrect");
	}
	if(Order == undefined)  {
		Order = 0
	}

	if(Order == 0){

		if(Qcnt1.checked && Greyout == true){
			while(i<Optnum){
				Qcnt2[i].disabled = true;
				Qcnt2[i].checked = false;
				++i;
			}
		}else{
			while(i<Optnum){
				Qcnt2[i].disabled = false;
				Qcnt2[i].checked = false;
				++i;
			}
		}
	}else{
		if(Qcnt1.checked == false && Greyout == true){
			while(i<Optnum){
				Qcnt2[i].disabled = true;
				Qcnt2[i].checked = false;
				++i;
			}
		}else{
			while(i<Optnum){
				Qcnt2[i].disabled = false;
				Qcnt2[i].checked = false;
				++i;
			}
		}
	}
	}
}





function BlankEntireCheckBoxQuestion(Qcnt1,Qcnt2,Optnum){

// IMPORTANT when calling this function Qcnt2 MUST BE in single quotes  ie 'Q5'  not Q5

//First Argument is the question name of the question calling this subroutine ie QB4_2
//Second Argument is the question whose check box is to be blanked out, ie QB5a
//Third Argument is the number of check boxes in the question to be blanked out
//Example of call -  onclick="BlankEntireCheckBoxQuestion(this,'QB5a',8)";

	var i=1;
	var IE=(document.all);
	var N4=(document.layers);
	var W3=(document.getElementById && !IE);
	var uscore="_"
	if (IE || W3) {	
	if(Optnum == undefined)  {
		if(Optnum == undefined) { 
			alert("Parameters passed to routine BlankEntireQuestion in "+Qcnt1+"  are incorrect");
		}
	}
	if(Qcnt1.checked == true){
		while(i<=Optnum){
			var QcurrQcnt2=Qcnt2+uscore+i;
			document.forms[0][QcurrQcnt2].checked = false;
			document.forms[0][QcurrQcnt2].disabled = true;
			++i;
		}	
	}else{
		while(i<=Optnum){
			var QcurrQcnt2=Qcnt2+uscore+i;
			document.forms[0][QcurrQcnt2].checked = false;
			document.forms[0][QcurrQcnt2].disabled = false;
			++i;
		}
	}
	}
}


 
function BlankOutOneButton(Qcnt1,Qcnt2,Greyout){
//This function blanks out only one radio button or check box in a question (can be called from a radio button or check box question
//First Argument is the question name of the question calling this subroutine. Best to use the word "this" without quotes
//Second Argument is the name of the question or radio button to be blanked out ie   A4_2 for checkbox or A4(1) for 2nd radio button in A4
//Third Argument - if true then disables buttons, if false, enables button. Only need this if Arg 1 is a radio button type (not needed for checkbox)
//Example of call -  onclick="BlankOutOneButton(this,Q5_8)";   or   onclick="BlankOutOneButton(this,Q5(7),true)
	var IE=(document.all);
	var N4=(document.layers);
	var W3=(document.getElementById && !IE);
	if (IE || W3) {
	if(Qcnt1.type == "radio" && Qcnt2.type == "radio") {
			if(Qcnt1.checked == true && Greyout == true){
			Qcnt2.disabled = true;
			Qcnt2.checked = false;
		}else{
			Qcnt2.disabled = false;
			Qcnt2.checked = false;
		}
	}

	if(Qcnt1.type == "radio" && Qcnt2.type == "checkbox"){
		if(Qcnt1.checked && Greyout == true){
           		Qcnt2.disabled = true;
           		Qcnt2.checked = false;
		}else{
           		Qcnt2.disabled = false;
           		Qcnt2.checked = false;
		}
	}
	 
	if(Qcnt1.type == "checkbox" && Qcnt2.type == "radio"){
		if(Qcnt1.checked == true){
			Qcnt2.disabled = true;
			Qcnt2.checked = false;
		}else{
			Qcnt2.disabled = false;
			Qcnt2.checked = false;
		}
	}

	if(Qcnt1.type == "checkbox" && Qcnt2.type == "checkbox"){
		if(Qcnt1.checked == true){
           		Qcnt2.disabled = true;
           		Qcnt2.checked = false;
		}else{
           		Qcnt2.disabled = false;
           		Qcnt2.checked = false;
		}
	}
	}
}

 

function launch(url, name, width, height) {
// This function creates a pop-up window of the specified size.
// Call this function like this
// <a href="testshow.swf" target="pp400x300" onClick="launch('', 'pp400x300', 400,300)">Slide Show Test (in Window)</a></p>

	var win = window.open(url,name,'width='+width+',height='+height+',resizable=no,scrollbars=no');
	win.focus();
}





function AllowNoDups(Form_aw){

// give feedback to the respondent about the state of their submission
//These cookies use the name of PdcThankYouPage as the CookieName, while the individual page cookies use the pdcProjectID value	
// Do not call this function directly, it is called when you specify PdcValidate(true) on the last page of the survey.

   // 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(document.forms[0].PdcThankYouPage.value) > -1) {
      // tell the user
      alert("You've already completed this survey. Thank you!  -   Vous avez déjà accompli cet aperçu. Merci!");
      return false;
   }else{
      // bake a cookie, put it in the cookie jar for next time and mark it with a freshness date
	var nowDate = new Date();
	nowDate .setDate(nowDate.getDate() + 30)
	cookieExpires = nowDate.toGMTString()
      document.cookie = document.forms[0].PdcThankYouPage.value + "=1; path=/; expires=" + cookieExpires;
      // you can change the expiration date of the cookie, as long as you use the format above
      return true;
   };
};



function AllowNoDupsCookieTest(Form_aw){

// give feedback to the respondent about the state of their submission
//These cookies use the name of PdcThankYouPage as the CookieName, while the individual page cookies use the pdcProjectID value	

   // 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(document.forms[0].PdcThankYouPage.value) > -1) {
      // return the value "false"
      return false;
   };
};





  function ProcessLastPageWithCookies() {

// Use this on the last page (before the Thankyou page) and format as follows:
//    function PdcProcessPage(){
//	  ProcessLastPageWithCookies()
//    }
//    return true;

	if(document.PdcSurvey.QSource_1.value == "AdminTest") {
		alert("Administrator test run concluded - Results will be saved to the database, however, will not be included in final calculations or graphs")
     		if(PdcValidate()==false) return false;
    	} 

	if(document.PdcSurvey.QSource_1.value == "ManualEntry") {
     		if(PdcValidate()==false) return false;
    	} 
	
	var QUserIDText = document.PdcSurvey.QUserID_1.value
	if(QUserIDText.search("cookie") != -1) {
     		if(PdcValidate()==false) return false;
    	} else {  
   		if(PdcValidate(true)==false) return false;
	}
   	return true;

  }



function ColumnTotal(QName,QSize,QTotal,QColor1,Color2){
//
//   This function adds a series of text boxes and displays the result in another specified text box
//   To use this function include the following text into the <input type="text" line:
//
//   onblur ="ColumnTotal(QName,QSize,QTotal,QColor1,Color2)" 
//   		QName is the name of the question in quotes as an example 'Q2' ... NOT 'Q2_1'
//  		QSize = the number of text boxes to add together starting in numbering from Q2_1 ... through to Q2_QSize
//  		QTotal = the name of the question where the result is to be placed
//			QColor1 = Color of the "Question Total xx%" text when NOT EQUAL to %100     If not specified, then default is "Red"
//			QColor2 = Color of the "Question Total xx%" text when EQUAL to 100%    If not specified, then default is "Green"
//
//   The complete line would look like this:
//   <input type="text" name="Q2_1" onblur ="ColumnTotal('Q2',4,'Q2_Total','Red','Green')" id="Q2_1" maxlength="255" size="9" />
//
//   The final line would like like this. This is the line which actually displays the result
//     <tr><td><label class="topic-text">Question Total</label></td><td><label class="topic-text" ID="Q2_Total" /> 0 %</label></td></tr>
//
//The following is an example of the entire question (including 4 % response box questions, one text only question and a Column Total line)
//<blockquote><table border="0">
//  <tr><td><label class="topic-text" for="Q2_1">a. buildings 4 stories or less (including homes)</label></td><td><input type="text" name="Q2_1" onblur ="ColumnTotal('Q2',4,'Q2_Total','Red','Green')" id="Q2_1" maxlength="255" size="9" /></td></tr>
//  <tr><td><label class="topic-text" for="Q2_2">b. buildings 5 stories or more</label></td><td><input type="text" name="Q2_2" onblur ="ColumnTotal('Q2',4,'Q2_Total','Red','Green')" id="Q2_2" maxlength="255" size="9" /></td></tr>
//  <tr><td><label class="topic-text" for="Q2_3">c. non-building structures</label></td><td><input type="text" name="Q2_3" onblur ="ColumnTotal('Q2',4,'Q2_Total','Red','Green')" id="Q2_3" maxlength="255" size="9" /></td></tr>
//  <tr><td><label class="topic-text" for="Q2_4">d. other</label></td><td><input type="text" name="Q2_4" onblur ="ColumnTotal('Q2',4,'Q2_Total','Red','Green')" id="Q2_4" maxlength="255" size="9" /></td></tr>
//  <tr><td><label class="topic-text" for="Q2_5">(please specify)</label></td><td><input type="text" name="Q2_5" id="Q2_5" maxlength="255" size="16" /></td></tr>
//  <tr><td><label class="topic-text">Question Total</label></td><td><label class="topic-text" ID="Q2_Total" /> 0 %</label></td></tr>
//</table></blockquote>

	var CTotal = 0
	var QArray = new Array()
	QArray.length = QSize
	objText = 'document.PdcSurvey'
	obj = document.PdcSurvey
	var uscore='_';
	var dot='.'
	if(QColor1 == "") {QColor1 = "Red"}
	if(QColor2 == "") {QColor2 = "Green"}

				
	for(var QNum=1; QNum<=QSize; QNum++) {
		QVal = eval(objText + dot + QName + uscore + QNum +'.value')
		if(QVal == "") {QVal = 0}
		QArray[QNum-1] = QVal
		CTotal = CTotal + parseFloat(QArray[QNum-1])
	}

/*
	The following statement enters the value into a Form Cell (Use if this is required and comment out the myPara line (can't use both since they both reference the same cell in the table.
	The following two statements are quivalent

	document.forms[0][QTotal].value = CTotal      and      obj[QTotal].value = CTotal
	obj[QTotal].value = CTotal

  	Also, the following statements are equivalent (note the document.all[QTotal] is the only way to access this ID tag)
	Q2_Total.innerHTML = CTotal + " %"     and 	    document.all[QTotal].innerHTML = CTotal + " %"
*/

	var IE=(document.all);
	var N4=(document.layers);
	var W3=(document.getElementById && !IE);
	if(CTotal == 100) {
		if (IE) {
// These two are equivalent		Q5_Sum.innerHTML   and   document.all[QTotal].innerHTML
			document.all[QTotal].innerHTML = "<font color="+QColor2+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Question Total&nbsp;&nbsp;&nbsp;&nbsp;= " + CTotal + " % </font>"
		} else if (N4) {
// These two are equivalent		document.Q5_Sum.document.close()   and   document[QTotal].document.close()
//	Can't get it to work perfectly for N4, so skip it.
//			document[QTotal].document.write("<span class=\"question-text\"><font color="+QColor+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Question Total&nbsp;&nbsp;&nbsp;&nbsp;= " + CTotal + " % </font>")
//			document[QTotal].document.close()
		} else if (W3) {
// These two are equivalent	  document.getElementById("Q5_Sum").innerHTML   and 	document.getElementById(QTotal).innerHTML
			document.getElementById(QTotal).innerHTML = "<font color="+QColor2+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Question Total&nbsp;&nbsp;&nbsp;&nbsp;= " + CTotal + " % </font>"
		} else {
			return
		}		
	} else {
		if (IE) {
			document.all[QTotal].innerHTML = "<font color="+QColor1+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Question Total&nbsp;&nbsp;&nbsp;&nbsp;= " + CTotal + " % - (please total the above responses to 100%)</font>"
		} else if (N4) {
//	Can't get it to work perfectly for N4, so skip it.
//			document[QTotal].document.write("<span class=\"question-text\"><font color="+QColor+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Question Total&nbsp;&nbsp;&nbsp;&nbsp;= " + CTotal + " % - (please total the above responses to 100%)</font></span>")
//			document[QTotal].document.close()
		} else if (W3) {
			document.getElementById(QTotal).innerHTML = "<font color="+QColor1+">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Question Total&nbsp;&nbsp;&nbsp;&nbsp;= " + CTotal + " % - (please total the above responses to 100%)</font>"
		} else {
			return
		}
	}		
}



  function ChangeContactInfo(QChange){
/* This Function saves the value of "1" into the checkbox variable name passed through the call command if the information contained in a textbox is modified by the user.
   This is useful to "Flag" when a piece of contact information has been modified.
	The function is called through the statement   onchange="ChangeContactInfo('QAddressChange_1')"  which is to be included into each <input type="text" location which is to be checked for modifications.

	The following is a complete example statement.
  <tr><td><label class="topic-text" for="Q37_1">Company Name</label></td><td><input type="text" name="Q37_1" id="Q37_1" onchange="ChangeContactInfo('QAddressChange_1')" maxlength="255" size="35" /></td></tr>
		
 IMPORTANT NOTE:
The line 	<input type="hidden" name="QAddressChange_1" /> must appear somewhere on the page (it can appear after the call to the function).	
*/

  	obj = document.PdcSurvey
  	obj[QChange].checked=true
  return
}




	function CheckIfRemove(RunType) {
//
//	This function checks whether a UserID, followed by the word "remove" was entered for either QUserID_1 or QSecurityKey_1.
//
//	For this function to work, the following line must be added as the line immediately following "NextPage() in  "function PdcProcessPage()" on the default.htm page. ie
//
//	function PdcProcessPage(){
//  	if(PdcValidate()==false) return false;
//    NextPage();
//    CheckIfRemove("SecurityKey")
//    return true;
//  }
//

	obj = document.PdcSurvey;
	
	if(RunType == "UserID") {
		UserKey = "QUserID_1"
	} else if (RunType == "SecurityKey") {
		UserKey = "QSecurityKey_1"
	} else {
		alert("Warning - Improper call to routine CheckIfRemove - Parameter must be either 'UserID' or 'SecurityKey' - Currently = "+RunType)
	}	
	
	URLArray = obj[UserKey].value.split(' ');
	if(URLArray.length >= 3) {
		alert("Warning - Improper UserID Format Entered.   - Value 1= "+ URLArray[0] +"    Value 2= "+ URLArray[1] +"    Value 3= "+URLArray[2])
	} else if(URLArray.length == 1) {
// Do nothing because only the UserID was entered
	} else if(URLArray.length == 2) {
		if(URLArray[1] == "remove") {
			obj[UserKey].value = URLArray[0];
			obj.QSource_1.value = "Remove Request"
			alert("Thank you. You have requested     UserID = "+URLArray[0]+"    to be removed from our contact list for this survey.")
			obj.PdcNextPage.value = "../scripts/Removed.htm";				
			obj.submit();
		} else {
			alert("Illegal UserID specified.")
		}	
	}
}





	function BrowserTest() {
/* 
This function returns either IE, N4 or N+ depending on the browser being used.
	IE means all IE 4.0 and up
	N4 means Netscape 4.x
	W3 means all W3C compliant browsers including Netscape 6.x and up, Mozilla, etc.

Call this function as:
	Browser = BrowserTest()

Use this function as 
	Browser = BrowserTest()
	if(Browser == "IE") {
//		Place IE code here	
	} else if (Browser == "N4") {
//		Place N4 code here
	} else if (Browser == "W3") {
//		Place W3 code here
	} else if (Browser == "None") {
//		skip operation since they are not supported by the browser
	}		
*/	
		var Browser
		if(document.all) {
			Browser = "IE"
		} else if (document.layers) {
			Browser = "N4"
		} else if (document.getElementById){
			Browser = "N6"
		} else {
			Browser = "None"
		}
		document.PdcSurvey.QBrowser_1.value = Browser			
		return Browser;		
	}





	function   GetUserIDandCookieCheck(RunType,Admin) {
//		RunType parameter options are:
//			if (RunType =  "NoUserIDRestriction") - indicates a normal user run. - Proceeds automatically to next page
//				Survey Loading ... line IS displayed
//				A Cookie is not left on the computer and is not tested for.
//				If a UserID is provided in the URL, then it is used.
//				If a UserID is NOT provided in the URL, then one is created.
//				If remove is found in the URL (ie: ...default.htm?MyUserID?remove) then make UserID as "remove" from database
//				Proceeds automatically to next page.
//
//			if (RunType =  "NoUserIDRestrictionAndWait") - indicates a normal user run. DOES NOT proceed automatically to next page
//				Survey Loading ... line IS NOT displayed
//				A Cookie is not left on the computer and is not tested for.
//				If a UserID is provided in the URL, then it is used.
//				If a UserID is NOT provided in the URL, then one is created.
//				If remove is found in the URL (ie: ...default.htm?MyUserID?remove) then UserID is marked as "remove" from database
//				DOES NOT Proceeds automatically to next page.
//
//			if (RunType == "SecurityKey") - indicates that ID provided through URL or entered must match existing record in Database
//				This option requires that a field in the form be called "SecurityKey_1 - If not, issue programmer alert "Message to SurveyPeople - SecurityKey restriction requested, however, variable SecurityKeyD_1 not found in form"
//				If a SecurityKey is provided in URL, then it is used.
//				If remove is found in the URL (ie: ...default.htm?MyUserID?remove) then make UserID as "Remove Request" from database
//				If a SecurityKey is NOT provided in the URL, then a SecurityKey Text box is provided on the page (this must be created by the programmer).
//				If remove is found in the UserID input box  (ie: MyUserID remove) then make UserID to "Remove Request" from database
//				Does not proceed automatically to next page unless a matching SecurityKey is provided.
//
//			if (RunType == "UserID") - indicates that ID provided through URL or entered "should" match existing record in Database. 
//				If a UserID is provided in URL, then it is used and proceeds automatically to the next page regardless of whether the UserID exists in the database
//				If remove is found in the URL (ie: ...default.htm?MyUserID?remove) then make UserID as "Remove Request" from database
//				If a UseID is NOT provided in the URL, then a UserID Text box is provided on the page (this must be created by the programmer).
//				If remove is found in the UserID input box  (ie: MyUserID remove) then make UserID to "Remove Request" from database.
//				Proceeds automatically to the next page when submit button is pressed.
//
//			if (RunType == "CookieRestriction") - indicates that the survey is to be restricted based on cookies (one response to survey per computer.
//				Survey Loading ... line IS displayed
//				A Cookie is left on the computer after completion of the final page and is tested for on the 1st and final pages. 
//					The final page of the survey (page before the Thankyou page) must include the function call ProcessLastPageWithCookies() which replaces the Perseus statement   "if(PdcValidate()==false) return false;"
//				Proceeds automatically to next page.
//
//			if (RunType == "CookieRestrictionAndWait") - indicates that the survey is to be restricted based on cookies (one response to survey per computer.
//				Survey Loading ... line IS NOT displayed
//				A Cookie is left on the computer after completion of the final page and is tested for on the 1st and final pages. 
//					The final page of the survey (page before the Thankyou page) must include the function call ProcessLastPageWithCookies() which replaces the Perseus statement   "if(PdcValidate()==false) return false;"
//				DOES NOT Proceeds automatically to next page.
//
// 		Admin options
//			if (Admin = "" || Admin = "user") - indicates a normal user is running this page
//
//			if (Admin = "Manual Entry" || Admin = "ManualEntry")	- indicates that an administrator is running the survey.
//				Cookies are saved, but permit completion of the survey with a message to operator
//				value of QSource_1.value is set to "ManualEntry"		
//							
//			if (Admin = "admin" || Admin = "Admin")	- indicates that an administrator is running the survey.
//				Cookies are saved, but permit completion of the survey with a message to operator
//				value of QSource_1.value is set to "AdminTest"		



	BrowserTest()
	
	URLArray = window.location.href.split('?');
	var localTime = new Date();
	document.PdcSurvey.QDate_1.value = localTime.toUTCString()
	obj = document.PdcSurvey
	
	if(RunType == "SecurityKey") {
		var UserKey = "QSecurityKey_1"
	} else {
		var UserKey = "QUserID_1"
	}

//	Check and process remove request from URL	
	if(URLArray.length >= 3) {
		if(URLArray[2] == "remove" ) {
//  The URL format must be  www.surveypeople.com/Surveys/default.htm?UserIDName?remove
			obj[UserKey].value = URLArray[1];
			obj.QSource_1.value = "Remove Request"
			alert("Thank you. You have requested to be removed from our contact list for this survey.")
			obj.PdcNextPage.value = "../scripts/Removed.htm";
			obj.submit();
		} else {
			alert("Warning - Improper URL Format.   - Value 1= "+ URLArray[0] +"    Value 2= "+ URLArray[1] +"    Value 3= "+URLArray[2])
			obj[UserKey].value = URLArray[1];
			obj.QSource_1.value = "E-Mail Link"
			obj.submit();
		}				
	}
		
	if (RunType ==  "NoUserIDRestriction")	{
//	Show the LOADING SURVEY ... Line
			document.write("<br><font color=#000080><b><font size=4>&nbsp;LOADING SURVEY&nbsp;&nbsp; . . . .</font></b><br />")
		if(URLArray.length == 1) {
//	If a UserID was not passed in the URL, then define one based on the getTime method (# of milliseconds since Jan-1-1970) 
				obj[UserKey].value = localTime.getTime()
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else if(Admin == "Manual Entry" || Admin == "ManualEntry"){
					obj.QSource_1.value = "Manual Entry"
				} else {
					obj.QSource_1.value = "No UserID Link"
				}
				obj.submit();
		} else if(URLArray.length == 2) {
// URLArray.length = 2, then a UserID_1 was passed, then get it			
			obj[UserKey].value = URLArray[1];
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else {
					obj.QSource_1.value = "E-Mail Link"
				}
			obj.submit();
		}
	}			

	if (RunType ==  "NoUserIDRestrictionAndWait")	{
		if(URLArray.length == 1) {
//	If a UserID was not passed in the URL, then define one based on the getTime method (# of milliseconds since Jan-1-1970) 
				obj[UserKey].value = localTime.getTime()
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else if(Admin == "Manual Entry" || Admin == "ManualEntry"){
					obj.QSource_1.value = "Manual Entry"
				} else {
					obj.QSource_1.value = "No UserID Link"
				}
		} else if(URLArray.length == 2) {
// URLArray.length = 2, then a UserID_1 was passed, then get it			
			obj[UserKey].value = URLArray[1];
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else {
					obj.QSource_1.value = "E-Mail Link"
				}
		}
	}			


	if (RunType ==  "UserID" || RunType == "SecurityKey") {	
		if(URLArray.length == 1) {
//	If a UserID was not passed in the URL, then one must be entered by the user
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else if(Admin == "Manual Entry" || Admin == "ManualEntry"){
					obj.QSource_1.value = "Manual Entry"
				} else {
					obj.QSource_1.value = "No UserID Link"
				}
		} else if(URLArray.length == 2) {
//	Show the LOADING SURVEY ... Line
			document.write("<br><font color=#000080><b><font size=4>&nbsp;LOADING SURVEY&nbsp;&nbsp; . . . .</font></b><br />")
// URLArray.length = 2, then a UserID_1 was passed, then get it	
			obj[UserKey].value = URLArray[1];
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else {
					obj.QSource_1.value = "E-Mail Link"
				}
			obj.submit();
		}
	}			

	if (RunType ==  "CookieRestriction") {
//	Show the LOADING SURVEY ... Line
		document.write("<br><font color=#000080><b><font size=4>&nbsp;LOADING SURVEY&nbsp;&nbsp; . . . .</font></b><br />")
		if(URLArray.length == 1) {
// If a UserID was not passed in the URL, then define one based on the getTime method (# of milliseconds since Jan-1-1970)		
// Save a cookie as part of the UserID (not standard cookie)			
			obj[UserKey].value = "cookie:"+localTime.getTime()
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else if(Admin == "Manual Entry" || Admin == "ManualEntry"){
					obj.QSource_1.value = "Manual Entry"
				} else {
					obj.QSource_1.value = "No UserID Link"
				}
			alert("You may complete this survey, even though a cookie has been saved on this computer indicating that is has already been used to complete this survey questionnaire previously.")
			obj.submit();
		} else if(URLArray.length == 2) {
// URLArray.length = 2, then a UserID_1 was passed, then get it	
// The CookieRestriction option will allow each UserID to complete the survey once. Access to the survey will be denied for a UserID once that ID has completed a survey.
			obj[UserKey].value = "cookie:"+URLArray[1];
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else {
					obj.QSource_1.value = "E-Mail Link"
				}
			obj.submit();
		}
	}
	
		if (RunType ==  "CookieRestrictionAndWait") {
		if(URLArray.length == 1) {
// If a UserID was not passed in the URL, then define one based on the getTime method (# of milliseconds since Jan-1-1970)		
// Save a cookie as part of the UserID (not standard cookie)			
			obj[UserKey].value = "cookie:"+localTime.getTime()
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else if(Admin == "Manual Entry" || Admin == "ManualEntry"){
					obj.QSource_1.value = "Manual Entry"
				} else {
					obj.QSource_1.value = "No UserID Link"
				}
			alert("You may complete this survey, even though a cookie has been saved on this computer indicating that is has already been used to complete this survey questionnaire previously.")
		} else if(URLArray.length == 2) {
// URLArray.length = 2, then a UserID_1 was passed, then get it	
// The CookieRestriction option will allow each UserID to complete the survey once. Access to the survey will be denied for a UserID once that ID has completed a survey.
			obj[UserKey].value = "cookie:"+URLArray[1];
				if(Admin == "admin" || Admin == "Admin") {
					obj.QSource_1.value = "AdminTest"
				} else {
					obj.QSource_1.value = "E-Mail Link"
				}
		}
	}			
}


function DisableEnter (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		event.cancelBubble = true
		return false;
	} 
}   
// ******************  Image PreLoading & Rollover functions

function MouseOver(ButtonName){
// These three functions must have names that end in normal, over and down.
// Example BackButton1_normal, BackButton1_over, BackButton1_down
// Insert the following into the <input statement   onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmouseDown="MouseDown(this)" onmouseup="MouseUp(this)" onclick="MouseClick(this)" 
// Example  <input type="image" src="images/but1_normal.gif" name="submit" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmouseDown="MouseDown(this)" onmouseup="MouseUp(this)"  onclick="MouseClick(this)" onclick="document.PdcSurvey.PdcButtonPressed.value='submit';" />
 		CurrentGraphic = ButtonName.src
 		CurrentGraphic = CurrentGraphic.toLowerCase()		
		ButtonName.src = CurrentGraphic.replace("normal","over")
	}

  	function MouseOut(ButtonName){
  		CurrentGraphic = ButtonName.src
 		CurrentGraphic = CurrentGraphic.toLowerCase()  		
  		if(CurrentGraphic.search("over") != -1) {
			ButtonName.src = CurrentGraphic.replace("over","normal")
		} else {	
			ButtonName.src = CurrentGraphic.replace("down","normal")
		}	
	}

  	function MouseDown(ButtonName){
  		CurrentGraphic = ButtonName.src
  		CurrentGraphic = CurrentGraphic.toLowerCase() 
  		if(CurrentGraphic.search("over") != -1) {
			ButtonName.src = CurrentGraphic.replace("over","down")
		} else {	
			ButtonName.src = CurrentGraphic.replace("normal","down")
		}	
	}

  	function MouseUp(ButtonName){
  		CurrentGraphic = ButtonName.src
  		CurrentGraphic = CurrentGraphic.toLowerCase() 		
		ButtonName.src = CurrentGraphic.replace("down","normal")
	}


function PreloadImage(GraphicName,Type) {
// Type = single - Loads single image from specified location
// Type = rollover - loads normal, down, over images from images/Button_normal.jpg directory
	GraphicName = GraphicName.toLowerCase()
	Type = Type.toLowerCase()

	if(Type == "single") {
		Image1 = new Image()
		Image1.src = GraphicName;
	} else if (Type == "rollover")  {
		Image1 = new Image()
		Image2 = new Image()
		Image3 = new Image()
		Image1.src = "images/" + GraphicName
		Image2.src = "images/" + GraphicName.replace("normal","down")
		Image3.src = "images/" + GraphicName.replace("normal","over")
	} else {
		alert("unrecognized Type specified for PreloadImage Function for GraphicName = "+GraphicName)
	}		
}

