﻿var bPopup = false;
var optYes = -1999997237;
var optNo = -1999997236;

//2906
//var reloading = false;
var bChanged = false;
function changed() {
	bChanged = true;
}

function beforeUnload() {
	bPopup = false;
	if (bChanged) {// && !bPopup ) {
		return 'If you continue you will lose your unsaved changes.\r\nClick Cancel if you wish to save your information using the button at the bottom of the page.';
	}
}

function textAreaKeyUp(v, length) 
{
	alert( 'Warning: Value has been truncated to the maximum length of ' + length );
	return v.substr( 0, length );
}

function submit() {
	document.mainForm.submit();
}

function optSelected(obj) {
    return obj.options[obj.selectedIndex].value;
}

//2972 - added call to msgBoxShow, and removed all logic now redundant under lightbox
function onTimeout() {
    if(bChanged) {
        clearInterval(tim);
        msgBoxShow();
        getSingleElement('savAndSub').style.visibility = 'hidden';
        getSingleElement('confirmText').innerHTML = '<p>Please save your information now.</p><p>Please press the SAVE button now to save any changes you have made to this page. You will still be able to continue editing this page.</p>';
        //2906
       getSingleElement('confirmsave').focus();; return false;
    }
}

//Multi Select lists
function SelectAll(ElementName){
	chk = document.getElementsByName(ElementName);
	selAll = getSingleElement(ElementName + 'SelAllChk').checked;
	for( i=0; i<=chk.length-1; i++ )
		chk[i].checked = selAll;
	SelectedAll(ElementName);
	if(window.changed) changed();
}

function SelectedAll(ElementName){
	var sel=1;
	var c = document.getElementsByName(ElementName);
	for( i=0; i<=c.length-1; i++ ) {
		if (c[i].checked == false) {
			sel=0;
		}
	}
	getSingleElement(ElementName + 'SelAll').value=sel;
	getSingleElement(ElementName + 'SelAllChk').checked=(sel==1);
	if(window.changed) changed();
}

function AnySelected(ElementName){
	var c = document.getElementsByName(ElementName);
	for( i=0; i<=c.length-1; i++ ) {
		if (c[i].checked == true) {
			return true;
		}
	}
	return false;
}

//parent child
function showChildRows(parent) {
	var rows = document.getElementById("mainForm").getElementsByTagName("TR");
	var i, row, q;
	for(i=0;i<rows.length;i++) {
		row = rows[i];
		if( ("q" + row.getAttribute("parentQ")) == parent.id) {
			if( getAncestor(parent,"TR").style.display == '' && row.getAttribute("parentA").indexOf(parent.value + ",") != -1  )
				row.style.display = '';
			else
				row.style.display = 'none';
			q = row.getElementsByTagName("SELECT");
			if(q.length>0) showChildRows(q[0]);
		}
	}
}

//Associated Forms
function AssocForm(questionId) {
	var formId=AssocFormId(questionId);
	var fa = getSingleElement("q"+questionId+"fa");
	if(formId) {
		fa.style.display = "";
		}
	else {
		fa.style.display = "none";
		}			
}	

function AssocFormId(questionId) {
	var answer = getSingleElement("q"+questionId).value;
	if (answer) {
		return eval("af"+questionId+"["+answer+"]");
		}
}	

function popUpAssocForm(questionId, CoId) {
	popupImproved("pre-more.aspx?CoId="+CoId+"&formId="+AssocFormId(questionId), 'asok', 600, 400, false, true);
}	




