var FINAL = false;

function getHighlighted (idx) {
	atts = highlighted[idx].split(' ');
	out = "<div class='highlighted' id='div_" + 
			atts[0] + "' style='top:" +
			atts[1] + "px;left:" +
			atts[2] + "px;width:" +
			atts[3] + "px;height:" +
			atts[4] + "px;' onclick='highlightIt(this)'> &#160; &#160; &#160; </div>";
	return out;
}
function getHighlighted2 (idx) {
	atts = highlighted2[idx].split(' ');
	out = "<div class='highlighted' id='div_" + 
			atts[0] + "' style='top:" +
			atts[1] + "px;left:" +
			atts[2] + "px;width:" +
			atts[3] + "px;height:" +
			atts[4] + "px;' onclick='highlightIt(this)'> &#160; &#160; &#160; </div>";
	return out;
}


function makeHighlighted(idx) {
	atts = highlighted[idx].split(' ');
	out = "<input type='hidden' id='" + 
			atts[0] + "' name='" +
			atts[0] + "' value='0'/>";
	return out;			
}

function makeHighlighted2(idx) {
	atts = highlighted2[idx].split(' ');
	out = "<input type='hidden' id='" + 
			atts[0] + "' name='" +
			atts[0] + "' value='0'/>";
	return out;			
}


function highlightIt(obj) {
	if (! obj.style.borderWidth) {
		obj.style.borderWidth = "2px";
		setOnOff(obj.id, true);
	}
	else {
		if (obj.style.borderWidth == "2px") {
			obj.style.borderWidth = "0px";
			setOnOff(obj.id, false);
		}
		else {
			obj.style.borderWidth = "2px";
			setOnOff(obj.id, true);
		}
	}
}

function setOnOff(id, value) {
	idvalue = id.split('_')[1];
	target = document.getElementById(idvalue);
	target.value = value;
}

function getInputTag(idx) {
	var s = "";
	if (FINAL) {
		s = " readonly='true' "; 
	}
	fields = text_input[idx].split(' ');
	out = "<input class='hidden' id='" + 
			fields[0] + "' name='" +
			fields[0] + "' style='top:" +
			fields[1] + "px;left:" +
			fields[2] + "px;width:" +
			fields[3] + "px;' value=''" + s + "/>";
	return out;
}


function getInputTag2(idx) {
	var s = "";
	if (FINAL) {
		s = " readonly='true' "; 
	}
	fields = text_input2[idx].split(' ');
	out = "<input class='hidden' id='" + 
			fields[0] + "' name='" +
			fields[0] + "' style='top:" +
			fields[1] + "px;left:" +
			fields[2] + "px;width:" +
			fields[3] + "px;' value=''" + s + "/>";
	return out;
} 


function prefill() {
	 inputs = document.getElementsByTagName('input');
	 for (i = 0; i < inputs.length; i++) {
		ikey = inputs[i].name;
		if (ikey.length > 0) {
		 if (ikey.indexOf('_') > 0) {
			ivalue = ikey.substr(ikey.indexOf('_') + 1);
			ikey = ikey.substr(0, ikey.indexOf('_'));
			if (aArray[ikey]) {
			 if ( aArray[ikey] == ivalue ) {
				if ( (ivalue == "yes") || (ivalue == "no") ) {
				 inputs[i].value = "X";
				}
				else {
				 divID = 'div_' + ikey + '_' + ivalue
				 x = document.getElementById(divID);
				 x.style.borderWidth = "2px";
				}
			 }
			}
		 }
		 else {
			if (aArray[ikey]) {
			 inputs[i].value = aArray[ikey]; 
			}
		 }
		}
	 }

}

			function switchPage() {
				if (document.getElementById('page2').style.display == 'none') {
					document.getElementById('page2').style.display = 'block';
					document.getElementById('page1').style.display = 'none';
				}
				else {
					document.getElementById('page2').style.display = 'none';
					document.getElementById('page1').style.display = 'block';
				}
			}

