function right(e) {
if (navigator.appName == 'Netscape' &&
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
alert("Functions associated with the right mouse button have been disabled.");
return false;
}
return true;
}

//CR #826 – Add ability to only persist certain questions to the database
// Added On:	 2007.10.08
// Added By:	 MBoisvert
// Description: Add ability to only persist certain questions to the database
function setPersistQuestions(questionGroup, answerGroup, questions)
{
    var objName = "BS_QuestionsToPersist_QG" + questionGroup + "_AG" + answerGroup;
    var tempObj = document.getElementsByName(objName)[0];
    if(tempObj != null)
    {
        tempObj.value = questions;
    }
}

 function IgnoreEvents(e)
 {
   //turn image off here
   OnOutImage(cur_image,'normal_image');

   window.top.onclick=AllowEvents;
   return false;
 }

function AllowEvents(e) {

}

 function OnOverImage()
 {
document.onkeydown = IgnoreEvents;
document.onmousedown = right;
document.onmouseup = right;

if (document.images){
for (var x=0;
x<OnOverImage.arguments.length;
x+=2) {
document[OnOverImage.arguments[x]].src = eval(OnOverImage.arguments[x+1] + ".src");
cur_image = OnOverImage.arguments[x];
}

   }
 }

 function OnOutImage()
 {
document.onkeydown = AllowEvents;
document.onmousedown = AllowEvents;
document.onmouseup = AllowEvents;

if (document.images){
for (var x=0;
x<OnOutImage.arguments.length;
x+=2) {
document[OnOutImage.arguments[x]].src = eval(OnOutImage.arguments[x+1] + ".src");
cur_image = "";
}

   }
 }






function trim(str) {
	var i = 0, j = 0;
	while ( str.charAt(i)==" " ) i++;
	j = str.length-1;
	while ( str.charAt(j)==" " ) j--;
	return str.substring(i,j+1);
}


// ----------------------------------------------------------------------------
// 
// Description: BayaPop
//
// Change History
// ----------------------------------------------------------------------------
// Date         CR  Author  Description
// ----------------------------------------------------------------------------
// 2006.11.01   370 KAD     And a call to focus on window object for BayaPop
//
// ----------------------------------------------------------------------------
function BayaPop(displayArgs, identifierArgs, width, height, dcmID, cardID, multiPage )
{
    // CR #299 - BayaPop javascript fails under Firefox.
	var language = document.getElementById("BS_CurrentLanguage");
	if (!language)
	    language= document.getElementsByName("BS_CurrentLanguage")[0];
	    
	// CR #382 - Merge multi view bayapop code in the tip
	// Added On: 2006.11.07
	// Added By: kdwyer
	// Description:
	if (!multiPage)
	{
	    var tmp = displayArgs.split(';');
	    multiPage = (tmp.length > 1);	        
	}
	
    var Url = 'PopupInfo.aspx?dargs=' + displayArgs + '&iargs=' + identifierArgs + '&lng=' + language.value + '&dcmID=' + dcmID + '&cardID=' + cardID + '&multiPageMode=' + ((multiPage) ? '1' : '0' );  
    var WindowWidth = 750;
    if (width) WindowWidth = width;
    var WindowHeight = 850;
    if (height) WindowHeight = height;
    var WindowTop = (screen.availHeight/2) - (WindowHeight/2);
    var WindowLeft = (screen.availWidth/2) - (WindowWidth/2);
    var WindowProps = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable,width='+WindowWidth+',height='+WindowHeight+',left='+WindowLeft+',top='+WindowTop+',screenx='+WindowLeft+',screeny='+WindowTop;
    PoppedWindow = window.open(Url,"PoppedWindow",WindowProps);
    if (PoppedWindow.focus)
    PoppedWindow.focus();
}

//CR #1146 - CIH
function HighlightIntersection(obj, classname) {
    obj.className = classname;
}

function HighlightQuestionAndAnswer(questionName, questionclassname, answerName, answerclassname) {
	//alert ('anwer='+answerName+',questionname='+questionName);
	//form = document.forms[0];
	//answerTD = eval("form." + answerName);
	
	var cells = document.getElementsByTagName("td");
	for ( ii = 0; ii < cells.length; ii++ )
	{
	    if ( cells[ii].id.substr(0,questionName.length) == questionName ) 
	        cells[ii].className = questionclassname;
	        
	    if ( cells[ii].id.substr(0,answerName.length) == answerName ) 
	        cells[ii].className = answerclassname;	        
    }
	
	/*
	answerTD = document.getElementById(answerName);
	answerTD.className=answerclassname;

	questionTD = document.getElementById(questionName);
	questionTD.className=questionclassname;
    */
}

// ----------------------------------------------------------------------------
//
// function: CalculateTotal
//
//                           * * NOTE * *
// If content of this function should change to implement a custom calculation
// rule then the server side validation NEEDS to updated as well!!!!
//
// ----------------------------------------------------------------------------
function CalculateTotal(textbox, percentBoxes, tallyBoxes, comma, prec)
{
	if (tallyBoxes.length > 0 && percentBoxes.length > 0) {
	form = document.forms[0];
	textBoxes = percentBoxes.split(',');
	tallyBoxes = tallyBoxes.split(',');
	var curtbObject
	var resultMsg = "";
	var total = 0;
	var v =0;
	for (pbIdx = 0; pbIdx < textBoxes.length; ++pbIdx) {
		curtbObject = eval('form.' + textBoxes[pbIdx]);	
		try
		{
		    v = curtbObject.value;	
		}
		catch(err)
		{
		    v = '0';
		}
		v = v.replace( /,/g , '' );				
		if (trim(v) != '') {
			if (isNaN(v)) {
				resultMsg = "Not a Number";
				break;
			}
			else {
				total = total + (1 * v);
			}
		}			
	}
	if (trim(resultMsg) == "") {
	    if (prec && prec > 0)
	        total = total.toFixed(prec);
	    if (comma)     
	        total = addCommas(total);	        
		resultMsg = total;        		   
	}
	for (pbIdx = 0; pbIdx < tallyBoxes.length; ++pbIdx) {
		curtbObject = eval('form.' + tallyBoxes[pbIdx]);
		if (curtbObject)
		    curtbObject.value = resultMsg;
	}
	}
	
	
}

function addCommas(nStr)
{
    nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;

}


function formatCurrency(num) {
	//num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if (cents == 0 )
	{
	    cents = "00";
    }
	else 
	{
	    if(cents<10)
	        cents = "0" + cents;    
    }
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	//return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + num + '.' + cents);}

function CalculateMPTotal(textbox, cbArrayName, checkBoxes, percentBoxes, tallyBoxes) {
	form = document.forms[0];
	checkBoxes = checkBoxes.split(',');
	textBoxes = percentBoxes.split(',');
	tallyBoxes = tallyBoxes.split(',');
	var curtbObject
	var resultMsg = "";
	var total = 0;
	var isNumber = true;
	for (pbIdx = 0; pbIdx < textBoxes.length; ++pbIdx) {
		curtbObject = eval('form.' + textBoxes[pbIdx]);
		if (trim(curtbObject.value) != '') {
			if (isNaN(curtbObject.value)) {
				resultMsg = "Not a Number";
				isNumber = false;
				break;
			}
			else {
				cbArray = eval('form.' + cbArrayName);
				indexID = checkBoxes[pbIdx];
				if (cbArray[pbIdx].checked) {
					total = total + (1 * curtbObject.value);
				}
			}
		}			
	}
	if (trim(resultMsg) == "") {
		
		if (isNumber) {
		  resultMsg = formatCurrency(total);
		}
		else {
			resultMsg = total;
		}
	}
	for (pbIdx = 0; pbIdx < tallyBoxes.length; ++pbIdx) {
		curtbObject = eval('form.' + tallyBoxes[pbIdx]);
		curtbObject.value = resultMsg;
	}
	
	
}


function RadioOtherKeyUpNew(textbox, radioArrayName, answerName, answerNumber,defaultValue) {
	form = document.forms[0];
	radioValue = answerNumber;
	radioArray = eval("form." + radioArrayName);
	radioName = "";
	assocRadio = null;
	for (rIdx = 0; rIdx < radioArray.length; ++rIdx) {
		if (radioArray[rIdx].value == radioValue) {
			assocRadio = radioArray[rIdx];
			break;
		}
	}
	shouldCheck = (trim(textbox.value) != "");
	if (shouldCheck != assocRadio.checked) {
		assocRadio.checked = shouldCheck;
		RadioCheckNew(assocRadio, radioArrayName, answerName, answerNumber,defaultValue);
	}
		
	if ( !shouldCheck )
	{
        if ( defaultValue.length > 0  )
		{
		    var rArray = eval('form.' + radioArrayName );
		    for ( ii = 0; ii < rArray.length; ii++ )
		    {
		        if ( rArray[ii].value == defaultValue )
		        {
		            rArray[ii].checked = true;
		            checkedRadios[radioArrayName] = defaultValue;
                }
            }
		}	
	}
	
} // End function

function RadioCellClick(strElement, strValue)
 {
    var radioObj = document.getElementsByName(strElement);
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
	    radioObj.checked = true;
		radioObj.click();
	}

	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].value == strValue) {
		    radioObj[i].checked = true;
			radioObj[i].click();
		}
	}
 }

var checkedRadios = new Object();
function RadioCheckNew(radioObject, radioArrayName, answerName, answerNumber,defaultValue) {
	if (checkedRadios[radioArrayName]==null) {
		checkedRadios[radioArrayName] = -1;
	}
	
	if (checkedRadios[radioArrayName] == answerNumber) {		
		radioObject.checked = false;
		if ( defaultValue.length > 0  )
		{
		    var rArray = eval('form.' + radioObject.name );
		    for ( ii = 0; ii < rArray.length; ii++ )
		    {
		        if ( rArray[ii].value == defaultValue )
		        {
		            rArray[ii].checked = true;
		            checkedRadios[radioArrayName] = defaultValue;
                }
            }
		}
		else
		{
		checkedRadios[radioArrayName] = -1;
	}
	}
	
	form = document.forms[0];
	
	//var1 = 'form.q' + question + '[' + (countx - 1) + ']';
	//var2 = eval(var1);
	//alert(form + ";" + cbObject.checked + ':' + cbObject.value + ':' + cbObject.name);
	rArray = eval('form.' + radioArrayName);
	radioObjectType = eval('form.' + answerName + "_META");
	for (rIdx = 0; rIdx < rArray.length; ++rIdx) {		
		curcbObjectType = eval('form.' + radioArrayName + '_' + rArray[rIdx].value + "_META");
		//curcbObjectType = eval('form.' + rArray[rIdx].value + "_META");
		if (true || rArray[rIdx] != radioObject) {
			if (curcbObjectType.value == "S") {
				otherName = 'form.' + radioArrayName + '_' + rArray[rIdx].value + "_OTHER";
				if (!rArray[rIdx].checked) {
					eval(otherName).value = "";
				}
				else {
					eval(otherName).focus();
				}
			}
		}
	}

	if (radioObject.checked) {
		checkedRadios[radioArrayName] = answerNumber;
	}		
	
}


// last blurred text box is a workaround for the screwy event handling order that javascript has (at least in IE)
// this needs rigorous testing on all platforms.
// It solves the issue of not being able to uncheck an other specify checkbox because the onblur event logic gets in the way.
// The prerequisite is that the otherspecify does not have focus (with the associatedCB unchecked) when the form loads.
var lastBlurredTextBox = "";
function CBOtherBlurNew(textbox, cbArrayName, answerName, answerNumber, defaultControlId) {
	form = document.forms[0];
	cbValue = answerNumber;
	cbArray = eval("form." + cbArrayName);
	cbName = "";
	assocCheckBox = null;
	for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
		if (cbArray[cbIdx].value == cbValue) {
			assocCheckBox = cbArray[cbIdx];
			break;
		}
	}
	shouldCheck = (trim(textbox.value) != "");
	if (shouldCheck != assocCheckBox.checked) {
		assocCheckBox.checked = shouldCheck;
		lastBlurredTextBox = "";
		CBCheckNew(assocCheckBox, cbArrayName, answerName, answerNumber, defaultControlId);
	}
	lastBlurredTextBox = textbox;
} // End function

var currentFocusCB = "";
function CBOnFocus(checkbox) {
	currentFocusCB = checkbox;
}

function CBOtherKeyUpNew(textbox, cbArrayName, answerName, answerNumber, defaultControlId) {
	form = document.forms[0];
	cbValue = answerNumber;
	cbArray = eval("form." + cbArrayName);
	if (!cbArray.length)
		cbArray = document.getElementsByName(cbArrayName);
	cbName = "";
	assocCheckBox = null;
	for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
		if (cbArray[cbIdx].value == cbValue) {
			assocCheckBox = cbArray[cbIdx];
			break;
		}
	}
	shouldCheck = (trim(textbox.value) != "");
	if (shouldCheck != assocCheckBox.checked) {
		assocCheckBox.checked = shouldCheck;
		CBCheckNew(assocCheckBox, cbArrayName, answerName, answerNumber, defaultControlId);
	}
} // End function


function CBFunctionMetaSubValue(metaValue,valueIdx)
{
    var subMetaValues = metaValue.split(',');
    return subMetaValues[valueIdx];
}

function CheckCellClick(strElement, strValue)
 {
    var radioObj = document.getElementsByName(strElement);
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
	    if(radioObj.checked)
		{
		    radioObj.checked = false;
		}
		else
		{
		    radioObj.checked = true;
		}
	    
		radioObj.click();
	}

	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].value == strValue) {
		    if(radioObj[i].checked)
		    {
		        radioObj[i].checked = true;
		    }
		    else
		    {
		        radioObj[i].checked = false;
		    }
			radioObj[i].click();
		}
	}
 }

function CBCheckNewEx(cbObject, cbArrayName, answerName, answerNumber)
{
	var form = document.forms[0];
	var cbArray = eval('form.' + cbObject.name);
	var cbObjectType = eval('form.' + answerName + "_META");		
	var metaArray = cbObjectType.value.split(',');
	for ( objTypeIdx = 0; objTypeIdx < metaArray.length; objTypeIdx++ )
	{
	    var curObjectType = metaArray[objTypeIdx];	    
	    if (curObjectType == 'E') {  //all or exclusive
		    if (cbObject.checked) {
			    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				    curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
				    if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) != 'Z' )
				    {
				        if (cbArray[cbIdx] != cbObject) {
					        cbArray[cbIdx].checked = false;
				        }
				        if (CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == "S") {
					        eval('form.'+cbArrayName + '_' +cbArray[cbIdx].value+'_OTHER').value = "";
				        }
				    }
			    }
		    }
	    }
	    else if (curObjectType == 'A') {
		    if (cbObject.checked) {
			    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				    if (cbArray[cbIdx] != cbObject) {
				        curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
				        if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) != 'Z' )
				        {
					        if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'N') {
						        cbArray[cbIdx].checked = true;
					        }
					        else if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'E') {
						        cbArray[cbIdx].checked = false;
					        }
				        }
				    }
			    }
		    }
		    else {
			    allChecked = true;
			    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				    curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
				    if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) != 'Z' )
				    {
				        if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'N') {
					        allChecked = allChecked && cbArray[cbIdx].checked;
				        }
				        if (cbArray[cbIdx] != cbObject) {
					        if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'E') {
						        cbArray[cbIdx].checked = false;
					        }
				        }
				    }
			    }
			    if (allChecked) {
				    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
					    curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
					    if (CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'A') {
						    cbArray[cbIdx].checked = true;
					    }
				    }
			    }
		    }
	    }
	    else if (curObjectType == 'S') {
		    curTextBox = eval('form.'+answerName+'_OTHER');

		    if (cbObject.checked && (lastBlurredTextBox == "" || lastBlurredTextBox == curTextBox)) {
			    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				    if (cbArray[cbIdx] != cbObject) {
					    curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
					    if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) != 'Z' )
					    {
					        if (CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'E') {
						        cbArray[cbIdx].checked = false;
					        }
					    }
				    }
			    }
			    curTextBox.focus();
		    }
		    else {
			    cbObject.checked = false;
			    curTextBox.value = "";
		    }
	    }
	    else if ( curObjectType == 'N' ) {
		    if (!cbObject.checked) {
			    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				    if (cbArray[cbIdx] != cbObject) {
					    curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
					    if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) != 'Z' )
					    {
					        if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'A' || CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'E') {
						        cbArray[cbIdx].checked = false;
					        }
					    }
				    }
			    }
		    }
		    else {
			    allChecked = true;
			    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				    curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
				    if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) != 'Z' )
				    {
				        if (CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'N') {
					        allChecked = allChecked && cbArray[cbIdx].checked;
				        }
				        if (cbArray[cbIdx] != cbObject) {
					        if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) == 'E') {
						        cbArray[cbIdx].checked = false;
					        }
				        }
				    }
			    }
			    if (allChecked) {
				    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
					    curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
					    if ( CBFunctionMetaSubValue( curcbObjectType.value, objTypeIdx ) != 'Z' )
					    {
					        if (CBFunctionMetaSubValue(curcbObjectType.value, objTypeIdx ) == 'A') {
						        cbArray[cbIdx].checked = true;
					        }
					    }
				    }
			    }
		    }
	    }
	    lastBlurredTextBox = "";	
	
	} // end for (objTypeIdx)
	

} // End function

function CBCheckNew(cbObject, cbArrayName, answerName, answerNumber,defaultControlId)
 { 
	form = document.forms[0];
	//var1 = 'form.q' + question + '[' + (countx - 1) + ']';
	//var2 = eval(var1);
	//alert(form + ";" + cbObject.checked + ':' + cbObject.value + ':' + cbObject.name);
	cbArray = eval('form.' + cbObject.name);
	cbObjectType = eval('form.' + answerName + "_META");
	var groupID = eval('form.' + answerName + '_GROUP_META');
	if (cbObjectType.value == 'E') {  //all or exclusive
		if (cbObject.checked) {		    
		    for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
			    curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");			    
			    if (cbArray[cbIdx] != cbObject) {
			        var curGroupID = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + '_GROUP_META' );
			        if ( curGroupID.value == '0' || groupID.value == '0' || curGroupID.value == groupID.value )
				        cbArray[cbIdx].checked = false;
			    }
			    if (curcbObjectType.value == "S") {
				    eval('form.'+cbArrayName + '_' +cbArray[cbIdx].value+'_OTHER').value = "";
			    }
		    }
		}
	}
	else if (cbObjectType.value == 'A') {
		if (cbObject.checked) {
			for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				if (cbArray[cbIdx] != cbObject) {
				curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
				var curGroupID = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + '_GROUP_META' );
				    if ( curGroupID.value == '0' || curGroupID.value == groupID.value )
				    {
					    if (curcbObjectType.value == 'N') {					    					    
						        cbArray[cbIdx].checked = true;
					    }
					    else if (curcbObjectType.value == 'E') {
						    cbArray[cbIdx].checked = false;
					    }
					}
				}
			}
		}
		else {
			allChecked = true;
			for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
				if (curcbObjectType.value == 'N') {
					allChecked = allChecked && cbArray[cbIdx].checked;
				}
				if (cbArray[cbIdx] != cbObject) {
					if (curcbObjectType.value == 'E') {
					    var curGroupID = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + '_GROUP_META' );
					    if ( curGroupID.value == '0' || curGroupID.value == groupID.value )
						    cbArray[cbIdx].checked = false;
					}
				}
			}
			if (allChecked) {
				for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
					curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
					if (curcbObjectType.value == 'A') {
					    var curGroupID = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + '_GROUP_META' );
					    if ( curGroupID.value == '0' || curGroupID.value == groupID.value )
						    cbArray[cbIdx].checked = true;
					}
				}
			}
		}
	}
	else if (cbObjectType.value == 'S') {
		curTextBox = eval('form.'+answerName+'_OTHER');

		if (cbObject.checked && (lastBlurredTextBox == "" || lastBlurredTextBox == curTextBox)) {
			for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				if (cbArray[cbIdx] != cbObject) {
					curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
					if (curcbObjectType.value == 'E') {
					    var curGroupID = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + '_GROUP_META' );
					    if ( curGroupID.value == '0' || curGroupID.value == groupID.value )
						    cbArray[cbIdx].checked = false;
					}
				}
			}
			if (curTextBox.style.display != 'none'){curTextBox.focus();}
		}
		else {		    
			cbObject.checked = false;
			curTextBox.value = "";
		}
	}
	else {
		if (!cbObject.checked) {			    
			for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				if (cbArray[cbIdx] != cbObject) {
					curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
					if (curcbObjectType.value == 'A' || curcbObjectType.value == 'E') {
					    var curGroupID = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + '_GROUP_META' );
					    if ( curGroupID.value == '0' || curGroupID.value == groupID.value )
						    cbArray[cbIdx].checked = false;
					}
				}
			}
		}
		else {
			allChecked = true;			
			for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
				curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
				if (curcbObjectType.value == 'N') {
					allChecked = allChecked && cbArray[cbIdx].checked;
				}
				if (cbArray[cbIdx] != cbObject) {
					if (curcbObjectType.value == 'E') {
					    var gid = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + '_GROUP_META');
					    if ( gid.value == '0' || gid.value == groupID.value )
    				        cbArray[cbIdx].checked = false;
					}
				}
			}
			if (allChecked) {
				for (cbIdx = 0; cbIdx < cbArray.length; ++cbIdx) {
					curcbObjectType = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + "_META");
					if (curcbObjectType.value == 'A') {
					    var curGroupID = eval('form.' + cbArrayName + '_' + cbArray[cbIdx].value + '_GROUP_META' );
					    if ( curGroupID.value == '0' || curGroupID.value == groupID.value )
						    cbArray[cbIdx].checked = true;
					}
				}
			}
		}
	}
		
	// BOC ()
	// Added On: 20060810
	// Added By: kad
	if ( defaultControlId )
	{
	    if ( defaultControlId.length > 0 )
	    {
	        var selectedCount = 0;
	        for ( ii = 0; ii < cbArray.length; ii++ )
		        if ( cbArray[ii].checked )
		            selectedCount++;
    		        
            if ( selectedCount == 0 )
    	        for ( ii = 0; ii < cbArray.length; ii++ )
	    	        if ( cbArray[ii].value == defaultControlId )
	    	        {
	    	            cbArray[ii].checked = true;
	    	            break;
	    	        }
	    }
	}
	// EOC ()
	
	lastBlurredTextBox = "";
} // End function


// --
// function: PercentageCallPieChart
// description: This javascript function gather the information from the screen
//  and then sets the src property for th iframe forcing the application to
//  render a new pie chart to the respondent.
// arguments:
//  senderId - the object that triggered the information.
//  questionNumber -
//  intersectionNames - 
// returns:
// 
// history
//  2006.10.05 430 Pie Chart functionality not working within FireFox
function PercentageCallPieChart(senderId,questionNumber,intersectionNames)
{
    var imageUrl = 'values=';
    var arrintersectionNames = intersectionNames.split(',');
    for ( arrIdx = 0; arrIdx < arrintersectionNames.length; arrIdx++ )
    {
        var tb =  document.getElementById( arrintersectionNames[arrIdx] );
        if (!tb)
            tb = document.getElementsByName( arrintersectionNames[arrIdx] )[0];
            
        if (!tb)
            return;
        
        if (isNaN(tb.value))
            return;
        
        if ( arrIdx > 0 )
            imageUrl = imageUrl + ',';
                        
        imageUrl = imageUrl + arrintersectionNames[arrIdx] + ',' + tb.value;
        
    } // end for (arrIdx)
    
    var iframeObj = document.getElementById('iframePieChart' + questionNumber );
    if ( iframeObj == null )
    {
        window.alert( 'Could not find ' + 'iframePieChart' + questionNumber + '!');
        return;
    }
        
    iframeObj.src = 'ImageBroker.aspx?image_type=pie&sender=' + senderId + '&' + imageUrl;
}

var gAllSupport = document.all != null;

function getOffset(el,which)
{
  var amount= el["offset"+which];
  if ( which == "Top" )
    amount+= el.offsetHeight;
  el = el.offsetParent;
  while ( el != null )
  {
    amount += el["offset" + which];
    el = el.offsetParent;
  }
  return amount;
}

function Tooltip_Show(sender,id)
{
    var d = document.getElementById(id);
    if ( d == null || d == undefined )
        return;

    // Holds the iframe that sits behind the tooltip
    var ifr = document.getElementById('_iframe_holder' + id);
    if ( ifr == null || ifr == undefined )
    	return;

	// Set the iframe size relative to the tooltip it's behind
	// Called here to escape table issues
	resetIframeSize(id);

    if ( gAllSupport )
    {
        d.style.pixelTop = getOffset( sender, "Top" );
        d.style.pixelLeft = getOffset( sender, "Left" );
        ifr.style.pixelTop = getOffset( sender, "Top" );
        ifr.style.pixelLeft = getOffset( sender, "Left" );
    }
    else
    {
        el.top = getOffset( d, "Top" );
        el.left = getOffset( d, "Left" );
        el_fr.top = getOffset( ifr, "Top" );
        el_fr.left = getOffset( ifr, "Left" );
    }
                    
    if ( gAllSupport )
    {
        d.style.visibility = 'visible';
        ifr.style.visibility = 'visible';
    }
    else
    {
        d.visibility = 'visible';
        ifr.visibility = 'visible';
    }
}


function Tooltip_Hide(sender,id)
{
    var d = document.getElementById(id);
    if ( d == null || d == undefined )
        return;
        
    // Holds the iframe that sits behind the tooltip
    var ifr = document.getElementById('_iframe_holder' + id);
    if ( ifr == null || ifr == undefined)
	    return;

    if ( gAllSupport )
    {
        d.style.visibility = 'hidden';
        ifr.style.visibility = 'hidden';
    }
    else
    {
        d.visibility = 'hidden';
        ifr.visibility = 'hidden';
    }
}


// Creates a tooltip and an iframe with a lower z-index to stand behind the tooltip
function Tooltip_Create(id,tooltipText)
{   
    var el = document.getElementById(id);
    var el_fr = document.getElementById('_iframe_holder' + id);

    if ( el == null || el == undefined )
    {
        document.writeln(
            "<div id=\"" + id + "\" style=\"visibility: hidden; position: absolute; z-index: 500;\" class=\"BS_TOOLTIP_POP\" >" +
                tooltipText + 
            "</div>" );

   		//	Add a div containing an iframe loading the webpage about:blank to put behind the tooltip
    	document.writeln( "<div id=\"_iframe_holder" + id + "\" style=\"visibility: hidden; position: absolute; z-index: 100;\"> <iframe src=\"about:blank\" id=\"_ifrm" + id + "\" name=\"_ifrm\" frameborder=\"0\" scrolling=\"no\" style=\"position: absolute;\"></iframe> </div>" );
    }
}


// Pass the ID of the object you want your iframe to resize to fit
function resetIframeSize(id)
{
    var tip_width = document.getElementById(id).offsetWidth;
	var tip_height = document.getElementById(id).offsetHeight;
	// All iframes are have an ID of: '_iframIDNUM' where IDNUM is the ID number of the tooltip it's related to
	var my_iframe = document.getElementById('_ifrm' + id);
	
	my_iframe.style.width = tip_width;
	my_iframe.style.height = tip_height;
}


// - 
// function:
function ReviewQuestion(uniqueID,listID,srcID,lngID,respondentID,questionID,width,height)
{    
    var sUrl = 'index.aspx' + 
        '?s=' + uniqueID + 
        '&BS_BucketID=' + listID +
        '&BS_SourceID=' + srcID + 
        '&BS_CurrentLanguage=' + lngID + 
        '&BS_ReviewQuestion=' + questionID + 
        '&BS_RespondentNumber=' + respondentID + 
        '&BS_ReadOnly=true';
    var WindowWidth = 750;
    if (width) WindowWidth = width;
    var WindowHeight = 850;
    if (height) WindowHeight = height;
    var WindowTop = (screen.availHeight/2) - (WindowHeight/2);
    var WindowLeft = (screen.availWidth/2) - (WindowWidth/2);
    var WindowProps = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable,width='+WindowWidth+',height='+WindowHeight+',left='+WindowLeft+',top='+WindowTop+',screenx='+WindowLeft+',screeny='+WindowTop;        
    var winPop = window.open( sUrl, 'QuestionReview', WindowProps );
}

/* ----------------------------------------------------------------------------
 *
 * Function: closeWindow
 * Arguments: N/A
 * Returns: N/A
 * Description:  This function was introduced for an issue with Firefox 
 *  browsers.  Within Firefox if a window is not opened with (java)script then
 *  the window can not be closed by scripting after several hours of searching
 *  the net I found the below code that would close the window.
 *
 * History 
 * ----------------------------------------------------------------------------
 * Date         Author  CR      Description (short)
 * ----------------------------------------------------------------------------
 * 2007.07.27   KAD     235     Close button does not work in Firefox
 * ----------------------------------------------------------------------------
 */
function closeWindow()
{
  if ( navigator.userAgent.indexOf("Firefox") != -1 )
        window.open('','_parent');
  window.close();
}


/* ----------------------------------------------------------------------------
 *
 * Function: SPQuestionOtherSpecify
 * Arguments: N/A
 * Returns: N/A
 * Description:  
 *
 * History 
 * ----------------------------------------------------------------------------
 * Date         Author  CR      Description (short)
 * ----------------------------------------------------------------------------
 * 2006.09.29   KAD     305     Question other specify is not cleared when 
 *                              singe punch is unselected.
 * 2007.11.29	BHiles	877		Javascript error is thrown when this is called 
 *								by non-other specify radios
 * ----------------------------------------------------------------------------
 */
function SPQuestionOtherSpecify(sender,questionOtherSpecify,radioArrayName)
{        
    var form = document.forms[0];	
	var radioArray = eval("form." + radioArrayName);

    for (rIdx = 0; rIdx < radioArray.length; ++rIdx)
		if (radioArray[rIdx].checked)
		    return;
        
    // if there is no answer present then clear the other specify value.
    var otherSpecify = document.getElementById(questionOtherSpecify);
    if (otherSpecify)
    {
      otherSpecify.value = '';
    }
}

// CR #421 - Popup are not working within the Safari browser.
// Added On: 2006.11.30
// Added By: kdwyer
// Description:  Within the safari browser the onmouseout 
//  event was not firing (known implemention of the browser)
//  so code was handle to handle the div 
var gLastPopID = '';
var gSarafiSeenEvent = false;

// CR #1122 - Popups should not be hidden if moused over
// Added on: 2009.1.12
// Added By: pclark
// Description: Added code that will result in mouseovers not being hidden when the mouseover itself is moused over
//		Also changed the positioning of the mouseover popup since flickering is no longer a concern

var openPopUpID = '';

function PopUp_OnMouseOut(sender,id)
{
    var el = document.getElementById(id);
    if (!el)
        el = document.getElementsByName(id)[0];
        
    openPopUpID = id;
    setTimeout("closePopUp()",5);
}

function closePopUp()
{
   if (openPopUpID.length > 0)
   {
      var el = document.getElementById(openPopUpID);
      if (!el)
          el = document.getElementsByName(openPopUpID)[0];
       if (el.title.length>0)
       {
          el.style.display = 'none'; 
          gLastPopID = '';
          openPopUpID = '';
       }
    }
}

function closePopUpForced()
{
   var el = document.getElementById(openPopUpID);
   if (!el)
       el = document.getElementsByName(openPopUpID)[0];
       
   if (el)
   {
      el.style.display = 'none'; 
      gLastPopID = '';
   }
   openPopUpID = '';
}

// CR #1005 - Mouse overs don't function correctly in firefox
// Added On: 2008.07.21
// Added By: PClark and BHiles
// Description:  Mouseovers were not functioning in firefox, and were being displayed off of the screen in some cases 
function PopUp_OnMouseOver(sender,id)
{
   if (openPopUpID.length > 0)
      closePopUpForced();
      
   if ( gLastPopID != '' )
    	PopUp_OnMouseOut( sender, gLastPopID );
    	
    var el = document.getElementById(id);
    if (!el)
        el = document.getElementsByName(id)[0];
       
    el.style.display = 'block';
    el.title = '!';
    
    el.onmouseover = function(){this.title = '';};
    el.onmouseout = function(){this.title = '!';PopUp_OnMouseOut(this,this.id);};
    
    var above = tempY - el.offsetHeight - 5;
    if (above >= document.body.scrollTop)
       el.style.top = above;
    else
       el.style.top = document.body.scrollTop;

    var centered = tempX - el.offsetWidth/2;
    if (centered >= document.body.scrollLeft)
       el.style.left = centered;
    else
       el.style.left = document.body.scrollLeft;

    if (IsSafari())
    {
    	gLastPopID = id;
    	gSarafiSeenEvent = true;
    }
}



function IsSafari()
{
   return ( navigator.userAgent.toLowerCase().indexOf( 'safari' ) > -1 );
}

function PopUp_ClosePops()
{
	if ( IsSafari() )
	{
		if (!gSarafiSeenEvent)
		{
			if ( gLastPopID != '' && openPopUpID.Length==0)	
			{
				var el = document.getElementById(gLastPopID);
				if (!el)
				       el = document.getElementsByName(gLastPopID)[0];
	
				el.style.display = 'none'; 
				gLastPopID = '';				
			}
		}
		else
		{
			gSarafiSeenEvent = false;
		}
	}
}

document.body.onmouseover = PopUp_ClosePops;




function BS_SetFocusTextBox(elementId)
{
    var el = document.getElementById(elementId);
    if (!el)
        el = document.getElementsByName(elementId)[0];
            
    if (el)
    {
        if (el.focus)
            el.focus();
    }
}

function BS_SetFocusPunch(elementId,value)
{       
    var els = document.getElementsByName(elementId);    
    for ( ii = 0; ii < els.length; ii++ )
    {
        var el = els[ii];        
        if ( el.value == value )
        {
            if (el.focus)
                el.focus();
            break;
        }
    } // end for ( ii )
}

function CBDontKnow(sender,baseVarName,answerCount,answerNum,answerGroupType)
{
    // if the check box is not checked then exit gracefully
    // out of this function doing nothing to the document.
    if (sender.checked==false)
        return;

    var el = null;
    var elId = '';
    for ( idx = 1; idx < answerCount; idx++ )
    {
        if ( answerNum == idx )
            continue;
    
        switch ( answerGroupType )
        {
                // SurveyAnswerGroup.QTYPE_NUMBER
            case 4:
            case 5:
            case 6:
            case 7:
                {
                    elId = baseVarName + '_' + idx.toString();
                    el = document.getElementById(elId);
                    if (!el)
                        el = document.getElementsByName(elId)[0];
                    
                    if (el)
                    {
                        el.value = '';
                        el.focus();
                        this.focus();
                    }
                }
                break;
            case 8:
                {
                    elId = baseVarName + '_' + idx.toString();
                    el = document.getElementById(elId);
                    if (!el)
                        el = document.getElementsByName(elId)[0];
                    
                    if (el)
                    {
                        el.value = '';
                        el.focus();
                        this.focus();
                    }
                }
                break;
        } // end switch (answerGroupType )
    } //end for (idx)
}

// ---
// Function: TextDontKnowKeyUp
// Description:
function TextDontKnowKeyUp(sender,variableName,variableValue)
{
    if ( sender.value.length > 0 )
    {
        var els = document.getElementsByName(variableName);
        for ( idx = 0; idx < els.length; idx++ )        
        {
            var el = els[idx];
            if ( el.value == variableValue )
            {
                el.checked = false;
                return;
            } // end if (el.value)
        } // end for (idx)
    } // end if (sender.value.length>0)
}

/* ----------------------------------------------------------------------------
 *
 * Function:
 * Arguments:
 * Returns:
 *
 * History 
 * ----------------------------------------------------------------------------
 * Date         Author  CR      Description (short)
 * ----------------------------------------------------------------------------
 * 2007.03.07   kdwyer  551     Drop-down Other specifies do not generate 
 *                              appropriate names
 * ----------------------------------------------------------------------------
 */
function DDLSelectNew(sender,otherSepcifyAvailable,otherSpecifyId)
{
    var el = document.getElementsByName(otherSpecifyId)[0];
    if (el)
        el.disabled = otherSepcifyAvailable[ sender.selectedIndex ];
}

/* ----------------------------------------------------------------------------
 *
 * Function:
 * Arguments:
 * Returns:
 *
 * History 
 * ----------------------------------------------------------------------------
 * Date         Author  CR      Description (short)
 * ----------------------------------------------------------------------------
 * 2007.03.07   kdwyer  551     Drop-down Other specifies do not generate 
 *                              appropriate names
 * ----------------------------------------------------------------------------
 */
function DDLOtherKeup(sender,ddlId,firstOtherSpecifyIndex)
{
  if ( sender.value.length == 0 )
  {
     var el = document.getElementsByName(ddlId)[0];     
     if (el)
        el.selectedIndex = firstOtherSpecifyIndex;
  }
}


function CurrencyOtherKeyup( sender, tbName )
{
    var s = trim(sender.value);
    var el = document.getElementsByName(tbName)[0];
    if (el)
        el.readonly = ( s.length == 0 );
}

function CurrencyOtherBlur( sender, tbName )
{
    var s = trim(sender.value);
    var el = document.getElementsByName(tbName)[0];
    if (el)
        el.readonly = ( s.length == 0 );
}


function BSSlideImageClicked( groupName, valueToSet, selectedImage, unselectedImage  )
{
    var els = document.getElementsByName(groupName);
    for ( idx = 0; idx < els.length; idx++ )
    {
        els[idx].checked = ( els[idx].value == valueToSet );
        if (els[idx].checked)
        {
            document.getElementById(groupName + '_' + els[idx].value).src = selectedImage;            
        }  
        else
        {
            document.getElementById(groupName + '_' + els[idx].value).src = unselectedImage;
        }  
    }
}

/*
 *
 */
function CalculateCurrencyTotal(textbox, percentBoxes, tallyBoxes, allowCommas) {
	if (tallyBoxes.length > 0 && percentBoxes.length > 0) {
	form = document.forms[0];
	textBoxes = percentBoxes.split(',');
	tallyBoxes = tallyBoxes.split(',');
	var curtbObject
	var resultMsg = "";
	var total = 0;
	for (pbIdx = 0; pbIdx < textBoxes.length; ++pbIdx) {
		curtbObject = eval('form.' + textBoxes[pbIdx]);
		var v = curtbObject.value;		
		if (allowCommas)
		    v = v.replace( /,/g , '' );
		if (trim(v) != '') {
			if (isNaN(v)) {
				resultMsg = "Not a Number";
				break;
			}
			else {
				total = total + (1 * v);
			}
		}			
	}
	if (trim(resultMsg) == "") {
		resultMsg = total;
	}
	for (pbIdx = 0; pbIdx < tallyBoxes.length; ++pbIdx) {
		curtbObject = eval('form.' + tallyBoxes[pbIdx]);
		if ( resultMsg == "Not a Number" )
		    curtbObject.value = resultMsg;
		else
		    curtbObject.value = formatCurrency(resultMsg);
	}
	}	
}

function OnBlurAddComma(sender)
{
    if (sender)
        sender.value = addCommas(sender.value.replace(/,/g , ''));
}

var BrowserDetect = 
{
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
		this.OSVersion = this.searchString(this.dataOSVersion) || "";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Internet Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	],
	dataOSVersion : [
	    {
	        string: navigator.userAgent,
	        subString: "Windows NT 6.0",
	        identity: "Vista"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows NT 5.2",
	        identity: "Server 2003; XP x64 Edition"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows NT 5.1",
	        identity: "XP"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows NT 5.01",
	        identity: "2000, Service Pack 1 (SP1)"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows NT 5.0",
	        identity: "2000"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows NT 4.0",
	        identity: "NT 4.0"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows 98; Win 9x 4.90",
	        identity: "Millennium Edition (Windows Me)"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows 98",
	        identity: "98"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows 95",
	        identity: "95"
	    },
	    {
	    	string: navigator.userAgent,
	        subString: "Windows CE",
	        identity: "CE"
	    },
	]
};
	
BrowserDetect.init();

function UpdateClientBrowserInformation()
{
    UpdateSpecificBrowserSetting('BS_BROWSER_TYPE_VAR', BrowserDetect.browser + ' ' + BrowserDetect.version);
    UpdateSpecificBrowserSetting('BS_OS_TYPE_VAR', BrowserDetect.OS + ' ' + BrowserDetect.OSVersion);
    UpdateSpecificBrowserSetting('BS_RESOLUTION_VAR', screen.width + ' x ' + screen.height);
    UpdateSpecificBrowserSetting('BS_COLOR_DEPTH_VAR', window.screen.colorDepth);
    UpdateSpecificBrowserSetting('BS_TIME_ZONE', GetBSTimeZoneOffset());
    UpdateSpecificBrowserSetting('BS_PLUGINS', encodestring(GetBrowserPlugins()));
 
}

function encodestring(StringToEncode) {
        var res = "";
        for (i = 0; i < StringToEncode.length; i++) {
            res += StringToEncode.charCodeAt(i).toString(16).toUpperCase();
        }
        return res;
}

function GetBSTimeZoneOffset()
{
    var dCurrent = new Date();
    return (dCurrent.getTimezoneOffset() / 60 * -1);
}

function GetBrowserPlugins()
{
    var strPlugins = "";
    for (i = 0; i < navigator.plugins.length; i++) 
    {
        strPlugins += navigator.plugins[i].name + "|" + navigator.plugins[i].filename + "||"
    }

    var WMPisInstalled = false;
    var WMPversion = null;
    if (window.ActiveXObject) {
        var control = null;
        try {
            control = new ActiveXObject('WMPlayer.OCX');
        } catch (e) {
            //return;
        }
        if (control) {
            WMPisInstalled = true;
            WMPversion = parseFloat(control.versionInfo);
            strPlugins += "WMP|" + WMPversion + "||";
        }
    } else {    }
    
    
    
    var SWFisInstalled = false;   
    var SWFversion = null;   
    if (window.ActiveXObject) {   
        var control = null;   
        try {   
            control = new ActiveXObject('SWCtl.SWCtl');   
        } catch (e) {   
            //return;   
        }   
        if (control) {   
            SWFisInstalled = true;   
            SWFversion = control.ShockwaveVersion('').split('r');
            SWFversion = parseFloat(SWFversion[0]);
            strPlugins += "SWF|" + SWFversion + "||";
        }   
    } else {   }  
    
    
    
    var FLSisInstalled = false;   
    var FLSversion = null;   
    if (window.ActiveXObject) {   
        var control = null;   
        try {   
            control = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');   
        } catch (e) {   
            //return;   
        }   
        if (control) {   
            FLSisInstalled = true;   
            FLSversion = control.GetVariable('$version').substring(4);
            FLSversion = FLSversion.split(',');
            FLSversion = parseFloat(FLSversion[0] + '.' + FLSversion[1]);
            strPlugins += "FLS|" + FLSversion + "||"; 
        }   
    } else {  }

    
    
    var ARCisInstalled = false;   
    var ARCversion = null;   
    if (window.ActiveXObject) {   
        var control = null;   
        try {   
            // AcroPDF.PDF is used by version 7 and later   
            control = new ActiveXObject('AcroPDF.PDF');   
        } catch (e) {   
            // Do nothing   
        }   
        if (!control) {   
            try {   
                // PDF.PdfCtrl is used by version 6 and earlier   
                control = new ActiveXObject('PDF.PdfCtrl');   
            } catch (e) {   
                //return;   
            }   
        }   
        if (control) {   
            ARCisInstalled = true;   
            ARCversion = control.GetVersions().split(',');   
            ARCversion = ARCversion[0].split('=');
            ARCversion = parseFloat(ARCversion[1]);
            strPlugins += "ARC|" + ARCversion + "||"; 
        }   
    } else {   
    }
    
    
    
    var QTisInstalled = false;   
    var QTversion = null;   
    if (window.ActiveXObject) {   
        var control = null;   
        try {   
            control = new ActiveXObject('QuickTime.QuickTime');   
        } catch (e) {   
            // Do nothing   
        }   
        if (control) {   
            // In case QuickTimeCheckObject.QuickTimeCheck does not exist   
            isInstalled = true;   
            strPlugins += "QT|0||"; 
        }   
    }   



    if (strPlugins.length > 2) {
        if (strPlugins.substring(strPlugins.length, strPlugins.length - 2) == "||") {
            strPlugins = strPlugins.substring(0, strPlugins.length - 2);
        }
    }
    return strPlugins;
}

function UpdateSpecificBrowserSetting(settingID, settingValue)
{
    var clientSettingsObj = document.getElementById(settingID);

    if (clientSettingsObj.value != settingValue)
    {
        document.getElementById('BS_CLIENT_INFO_CHANGED').value = 'true';
        clientSettingsObj.value = settingValue;
    }
}


function clearText(caller)
{
	if (caller.checked == true)
	{
		var callingName = caller.name;
		callingName = callingName.substring(0, callingName.length - 1);
		var objs = document.getElementsByName(callingName + '1_1');
		var txtBox = objs[0];

		txtBox.value = "";
	}
}

function clearTextList(caller, numA)
{
	if (caller.checked == true)
	{
		var callingName = caller.name;
		callingName = callingName.substring(0, callingName.length - 1);
		//alert(numA);
		
		for (var i=1; i<=numA; i++){
		  var objs = document.getElementsByName(callingName + '1_' + i);
		  //alert (callingName+ '1_' + i);
      
      for (var j=0; j<objs.length; j++){
        var txtBox = objs[j];
        if (txtBox.value)
  		    txtBox.value = "";
		  }
	  }
	}
}

function clearCheck(caller)
{
	var callingName = caller.name;
	for (var i=0; i<2; i++){
		var LastIndexNum = callingName.lastIndexOf('_');
		callingName = callingName.substring(0, LastIndexNum);
	}	
	var objs = document.getElementsByName(callingName + '_2');
	for(x=0;x<objs.length;x++)
	{
  	var checkBox = objs[x];
  	checkBox.checked = false;
  }
}

function clearSpecificText(caller, itemsToClear)
{
	if (caller.checked == true)
	{
		var itemList = itemsToClear.split(',');
		for (var i = 0; i < itemList.length; i++)
		{
			var objs = document.getElementsByName(itemList[i]);
			if(objs.length>0)
			{
        var txtBox = objs[0];
			  txtBox.value = "";
			}
		}
	}
}

function clearSpecificText_To0(caller, itemsToClear, OtherNumber)
{
	if (caller.checked == true)
	{
		var itemList = itemsToClear.split(',');
		for (var i = 0; i < itemList.length; i++)
		{
			var objs = document.getElementsByName(itemList[i]);
			var txtBox = objs[0];
			if (txtBox.name != (OtherNumber)){
				txtBox.value = "0";
			} else {
				var OtherName = document.getElementsByName(txtBox.name+"_OTHER");
				txtBox.value = "";
				OtherName[0].value="";
			}
		}
	}
}

function clearSpecificTextTo0TwoLists(caller, itemsToClear1, itemsToClear2, OtherNumber)
{
  var itemsToClear = '';
  if (caller.name.substr(caller.name.indexOf('_')+1,1) == '1'){
    itemsToClear = itemsToClear1;
  } else {
    itemsToClear = itemsToClear2;
  }
	if (caller.checked == true)
	{
		var itemList = itemsToClear.split(',');
		for (var i = 0; i < itemList.length; i++)
		{
			var objs = document.getElementsByName(itemList[i]);
			var txtBox = objs[0];
			if (txtBox.name != (OtherNumber)){
				txtBox.value = "0";
			} else {
				var OtherName = document.getElementsByName(txtBox.name+"_OTHER");
				txtBox.value = "";
				OtherName[0].value="";
			}
		}
	}
}

function clear2D(caller, numQ)
{   
  cn = caller.name.split('_');
  caller_radio = document.getElementsByName(caller.name);
  
  var caller_num = 0;
  for (var i=0; i<caller_radio.length; i++){
    if (caller_radio[i].checked == true)
      caller_num = i;
  }  

  for (var i=1; i<=numQ; i++){
    if (i!=cn[1]){
      var radio = document.getElementsByName(cn[0]+'_'+i+'_'+cn[2])[caller_num];      
      if (radio)
        radio.checked = false;
    }
  }
}

function clear2D(caller, numQ, numA)
{   
  cn = caller.name.split('_');
  caller_radio = document.getElementsByName(caller.name);
  
  var caller_num = 0;
  for (var i=0; i<caller_radio.length; i++){
    if (caller_radio[i].checked == true)
      caller_num = i;
  }  

  for (var i=1; i<=numQ; i++){
    if (i!=cn[1]){
      var radio = document.getElementsByName(cn[0]+'_'+i+'_'+cn[2])[caller_num];      
      if (radio)
        radio.checked = false;
    }
  }
  for (var j=1; j<=numA; j++){
    if (j!=cn[2]){
      var radio = document.getElementsByName(cn[0]+'_'+cn[1]+'_'+j)[caller_num];
      if (radio)
        radio.checked = false;
    }
  }
}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} 
function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} 
function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} 
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}

var IE = document.all?true:false;
if (!IE) document.addEventListener(Event.MOUSEMOVE,getMouseXY,false)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}  
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  
return true;
}
// CR #1000 - Need to be able to move answer level other specifies in a grid to the row/column header
// Added On: 2008.11.18
// Added By: PClark
// Description:  Answer level other specifies render the specify box in the cell with each answer
//		 Many clients would prefer that the specify box be in the answer header and applied to each answer
//		 This will make the change using JavaScript and will leave the survey fully functional for respondents without JavaScript
function MoveSpecifyToAnswerHeader(QuestionGroupNum, AnswerGroups, NumQuestions, Answers)
{
   var AnswerGroupsSplit = AnswerGroups.split(',');
   var AnswersSplit = Answers.split(',');
   
   for (var i=0; i<AnswerGroupsSplit.length; i++)
   {
      for (var j=0; j<AnswersSplit.length; j++)
      {
         document.getElementById('QG' + QuestionGroupNum + '_A' + AnswersSplit[j]).innerHTML = '<input type="text" class="BS_GRID_OTHER_SPECIFY" id="QG' + QuestionGroupNum + '_A' + AnswersSplit[j] + '_OTHER" onkeyup="DistributeSpecifies(' + QuestionGroupNum + ',\'' + AnswerGroups + '\',' + NumQuestions + ',\'' + Answers + '\');">';  

         for (var k=1; k<=NumQuestions; k++)
         {
         
            var specify = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i] + '_' + AnswersSplit[j] + '_OTHER')[0];
            if (specify)
            {
               if (specify.value.length > 0)
                  document.getElementById('QG' + QuestionGroupNum + '_A' + AnswersSplit[j] + '_OTHER').value = specify.value;
               specify.style.display = 'none';
            }
         
            var textbox = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i] + '_' + AnswersSplit[j])[0];
            if (textbox)
               textbox.onchange = function(){DistributeSpecifies(QuestionGroupNum, AnswerGroups , NumQuestions, Answers);};  
            
            var radios = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i]);
            for (var x=0; x<radios.length; x++)
            {
               if (radios[x].value == AnswersSplit[j])
                  radios[x].onchange = function(){setTimeout('DistributeSpecifies(' + QuestionGroupNum + ', \'' + AnswerGroups + '\' , ' + NumQuestions + ', \'' + Answers + '\');', 5);};  

                  
            }
         }        
      }
   }  
}

function DistributeSpecifies(QuestionGroupNum, AnswerGroups, NumQuestions, Answers)
{
   var AnswerGroupsSplit = AnswerGroups.split(',');
   var AnswersSplit = Answers.split(',');
   
   for (var i=0; i<AnswerGroupsSplit.length; i++)
   {
      for (var j=0; j<AnswersSplit.length; j++)
      {
         var Specify = document.getElementById('QG' + QuestionGroupNum + '_A' + AnswersSplit[j] + '_OTHER');
         if (Specify)
         {
            for (var k=1; k<=NumQuestions; k++)
            {
               var textbox = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i] + '_' + AnswersSplit[j])[0];
               if (textbox)
               {
                  if (textbox.value.length > 0)
                  {
                     var specifyIntersection = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i] + '_' + AnswersSplit[j] + '_OTHER')[0];
                     if (specifyIntersection)
                        specifyIntersection.value = Specify.value;
                  }
                  else
                  {
                     var specifyIntersection = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i] + '_' + AnswersSplit[j] + '_OTHER')[0];
                     if (specifyIntersection)
                        specifyIntersection.value = '';
                  }               
               }
               
               var radios = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i]);
               for (var x=0; x<radios.length; x++)
               {
                  if (radios[x].value == AnswersSplit[j])
                  {
                     if (radios[x].checked)
                     {
	        	     var specifyIntersection = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i] + '_' + AnswersSplit[j] + '_OTHER')[0];
	        	     if (specifyIntersection)
	        	        specifyIntersection.value = Specify.value;
                     }
                     else
                     {
	        	     var specifyIntersection = document.getElementsByName('Q' + QuestionGroupNum + '_' + k + '_' + AnswerGroupsSplit[i] + '_' + AnswersSplit[j] + '_OTHER')[0];
	        	     if (specifyIntersection)
	        	        specifyIntersection.value = '';
                     }
                  }
               }
  	    }
         }
      }
   }
}

