
function ShowHideRow(questionRow, showChildren)
{
	var qRow = document.all[questionRow];
	if( qRow )
	{
		if( showChildren == "" )
			qRow.style.display = "none";
		else
			qRow.style.display = "";
	} 
}

//This method validates the child controls are properly displayed when the page is reloaded
//Add all parent controls (controls with children that are shown/hidden based on selection) to the below array
function PageLoad()
{
	var responseControl;
	var responseControl1;
	var responseDiv;
	var controlArray = new Array();
	var controlPrefix = "Q";
	var controlSuffix = "ResponseControl";
	
	var divPrefix = "Q";
	var divSuffix = "C";
	
	controlArray[0] = "12";
	controlArray[1] = "9";
	controlArray[2] = "10";
	controlArray[3] = "11";
	controlArray[4] = "19";
	controlArray[5] = "20";
	controlArray[6] = "21";
	controlArray[7] = "22";
	controlArray[8] = "23";
	controlArray[8] = "13";	
	//Loop through controls and show the chld control divs where appropriate
	for( var index = 0; index < controlArray.length; index++ )
	{
		responseControl = document.all[controlPrefix + controlArray[index] + controlSuffix];
		if( responseControl )
		{
			responseDiv = document.all[divPrefix + GetParentQCode(controlArray[index]) + divSuffix];
			if( responseDiv )
			{
				if( responseControl.checked )
					responseDiv.style.display = "";
				else
					responseDiv.style.display = "none";
			}
		}
	}
	
	//Handle special controls
	//Question 17
	responseControl = document.all[controlPrefix + "17" + controlSuffix];
	responseControl1 = document.all[controlPrefix + "17a" + controlSuffix];
	responseDiv = document.all[divPrefix + GetParentQCode("17") + divSuffix];
	if( responseControl && responseControl1 && responseDiv )
	{
		if( responseControl.checked || responseControl1.checked )
			responseDiv.style.display = "";
		else
			responseDiv.style.display = "none";
	}
	
	//Question 18
	responseControl = document.all[controlPrefix + "18" + controlSuffix];
	responseControl1 = document.all[controlPrefix + "18a" + controlSuffix];
	responseDiv = document.all[divPrefix + GetParentQCode("18") + divSuffix];
	if( responseControl && responseControl1 && responseDiv )
	{
		if( responseControl.checked || responseControl1.checked )
			responseDiv.style.display = "";
		else
			responseDiv.style.display = "none";
	}
	
	
	//Set the displayed page
	var pageNumberCtl = document.all['HiddenPageTextbox'];
	if( pageNumberCtl && parseInt(pageNumberCtl.value) > 0 )
		ShowPage(parseInt(pageNumberCtl.value));
	else
		ShowPage(1);	
	
	//Hide page label, if Only infromation requested
	var serviceTypeCtl = document.all['HiddenServiceTextbox'];
	if( serviceTypeCtl )
	{
		if(serviceTypeCtl.value=='info')
		{
			document.all['PageCountDiv'].innerText = ' ';
		}
	}
	
	//Override the functionality of the postback function on the reset button
	//so that we can reset even if the validators are tripped
	var resetButton = document.all['ResetButton'];
	if( resetButton )
		addEvent(resetButton, "onclick", PostReset);
		
	//Set the expiration of the page
	SetPageExpiration();
}

function PostReset()
{
	ResetForm();
	if (typeof(Page_ClientValidate) == 'function') 
		Page_ClientValidate();
}


function addEvent(object, eventName, fn)
{ 
	if (object.addEventListener)
	{ 
		obj.addEventListener(eventName, fn, false); 
		return true; 
	} 
	else if (object.attachEvent)
	{ 
		var r = object.attachEvent(eventName, fn); 
		return r; 
	} 
	else 
		return false; 
}


function GetParentQCode(questionCode)
{
	var qc = new String();
	qc = questionCode;
	
	while( qc.length > 0 )
	{
		if( isNaN(qc) )
			qc = qc.substring(0, qc.length - 1);
		else
			break;
	}
		
	return qc;
}


function GetDate()
{
	var date = new Date();
	var dateString = new String();
	
	switch( date.getDay() )
	{
		case 0:
			dateString = "Sunday, ";
			break;
		case 1:
			dateString = "Monday, ";
			break;
		case 2:
			dateString = "Tuesday, ";
			break;
		case 3: 
			dateString = "Wednesday, ";
			break;
		case 4:
			dateString = "Thursday, ";
			break;
		case 5:
			dateString = "Friday, ";
			break;
		case 6:
			dateString = "Saturday, ";
			break;
	}
	
	switch( date.getMonth() )
	{
		case 0:
			dateString += "January ";
			break;
		case 1:
			dateString += "February ";
			break;
		case 2:
			dateString += "March ";
			break;
		case 3: 
			dateString += "April ";
			break;
		case 4:
			dateString += "May ";
			break;
		case 5:
			dateString += "June ";
			break;
		case 6:
			dateString += "July ";
			break;
		case 7:
			dateString += "August ";
			break;
		case 8:
			dateString += "September ";
			break;
		case 9:
			dateString += "October ";
			break;
		case 10: 
			dateString += "November ";
			break;
		case 11:
			dateString += "December ";
			break;
	}
	
	dateString += date.getDate();
	dateString += ", ";
	dateString += date.getFullYear();
	
	document.all["PageHeaderDate"].innerText = dateString;
}

function ResetControls()
{
	var controlID = new String();
	var control = null;
	
	for( var index = 0; index < document.forms[0].elements.length; index++ )
	{
		controlID = document.forms[0].elements[index].id;
		control = document.forms[0].elements[index];
		
		if( controlID && controlID.match("ResponseControl") )
		{
			switch (control.type.toUpperCase() )
			{
				case "CHECKBOX":
					control.checked = false;
					break;
				case "TEXT":
					control.value = "0";
					break;
				case "SELECT-ONE":
					control.selectedIndex = 0;
					break;
//				case "RADIO":
//					if( controlID.lastIndexOf("N") == controlID.length - 1 )
//						control.checked = true;
//					else
//						control.checked = false;
			}
		}
	}
}

function ResetForm()
{
	ResetControls();
	document.body.scrollTop = 0;
	//ShowPage(1);
}

function CheckProceed(control)
{
	var otherControl = null;
	var proceedButton = document.all["ProceedButton"];
	
	if( control.id == "DisagreeCheckBox" )
	{
		otherControl = document.all["AgreeCheckBox"];
		if( control.checked && proceedButton )
			proceedButton.disabled = true;					
	}
	else
	{
		otherControl = document.all["DisagreeCheckBox"];
		if( control.checked && proceedButton )
			proceedButton.disabled = false;
	}
	
	//If neither control is checked, disable
	if( !(otherControl.checked || control.checked) )
		proceedButton.disabled = true;
	
	otherControl.checked = false;
					
}

function OnTextFocus(textbox)
{
	textbox.select();
}

function ShowPage(page)
{
	var maxPage = 0;
	
	for( var index = 1; index < 20; index++ )
	{
		var pageDiv = document.all['DivPage' + index];
		
		if( pageDiv )
		{ 
			if( index == page )
				pageDiv.style.display = '';
			else
				pageDiv.style.display = 'none';
			
			maxPage = index;
		}
	}
	
	//Set the page number header
	var pageCountDiv = document.all['PageCountDiv'];
	if( pageCountDiv )
		pageCountDiv.innerText = 'Page ' + page + ' of ' + maxPage;
		
	//Set the last page viewed
	var pageNumberCtl = document.all['HiddenPageTextbox'];
	pageNumberCtl.value = page;
	
	//Hide the "Loading" div
	pageDiv = document.all['LoadingDiv'];
	if( pageDiv )
		pageDiv.style.display = 'none';
	
}




function SetPageExpiration()
{
	var timeoutMSec = 1200000; //20 minutes
	window.setTimeout("window.close();", timeoutMSec);
	
	//Resize the window
	window.moveTo(0,0);
	window.resizeTo(window.screen.availWidth, window.screen.availHeight);
}

	