/*
  jsFixedDynamicData.  Written by Joe McCormack.  www.virtualsecrets.com.
*/
var optionSelectedIndex = 0, IE_trackPageY = 0, FF_trackPageY = 0;
nv_a = new Array(); nv_b = new Array(); nv_c = new Array(); nv_d = new Array(); nv_e = new Array();
nv_f = new Array(); nv_g = new Array(); nv_h = new Array(); nv_i = new Array(); nv_j = new Array();
nv_k = new Array(); nv_l = new Array(); nv_m = new Array(); nv_n = new Array(); nv_o = new Array();
nv_p = new Array(); nv_q = new Array(); nv_r = new Array(); nv_s = new Array(); nv_t = new Array();
nv_u = new Array(); nv_v = new Array(); nv_w = new Array(); nv_x = new Array(); nv_y = new Array();
nv_z = new Array();
function initFixedDynamics() {
var xypos = "", xpos = 0, ypos = 0; position = new Array();
xypos = query_element(interactiveBoxID, 0, 0);
position = xypos.split(","); xpos = parseInt(position[0]); ypos = parseInt(position[1]);
/* Align Select Box */
if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
							      /*IE*/
							      document.getElementById(MoveContainer).style.top = ypos + 22;
							      document.getElementById(MoveContainer).style.left = xpos;
							      IE_trackPageY = ypos + 22;
							     }
else {
      /*Other*/
      document.getElementById(MoveContainer).style.top = ypos + 22 + "px";
      document.getElementById(MoveContainer).style.left = xpos + "px";
      FF_trackPageY = ypos + 22;
     }
/* Place data into the arrays to begin with */
useNameValues();
}
function query_element(actor, ox, oy) {
var x_posi = 0, y_posi = 0;
if (document.all) { actor = document.all[actor]; }
else { actor = document.getElementById(actor); }
while (actor != null) {
		       x_posi += actor.offsetLeft - actor.scrollLeft;
		       y_posi += actor.offsetTop - actor.scrollTop;
		       /* Recycle */
		       actor = actor.offsetParent;
		      }
return((x_posi + ox) + "," + (y_posi + oy));
}
function DataFind(stringValue, keyPress) {
var lastKeyPressed = keyPress.keyCode ? keyPress.keyCode : keyPress.charCode;
if (lastKeyPressed == 13) {
			   /* Enter key pressed; submit form */
			   submitState();
			  }
else {
      /* If Down arrow is pressed, shift focus to drop-down if it is visible */
      if (lastKeyPressed == 40) {
			         if (document.getElementById(selBoxID).options[0]) {
									            if (document.getElementById(selBoxID).options[0].value.length > 0) { optionSelectedIndex = 0; document.getElementById(selBoxID).focus(); document.getElementById(selBoxID).selectedIndex = optionSelectedIndex; }
									           }
			        }
      else {
	    /* When no data & backspace is pressed ensure drop-down is not visible */
	    if (lastKeyPressed == 8) { if (document.getElementById(interactiveBoxID).value.length == 0) { document.getElementById(selBoxID).style.display = "none"; } }
	    /* Bypass checking for back-arrow */
	    if (lastKeyPressed != 37) {
				       var arrayUse = stringValue.charAt(0).toLowerCase();
				       var strValue = stringValue.toLowerCase();
				       var processAllow = 1;
				       arrayData = new Array();
				       /* Clear the select options */
				       if (document.getElementById(selBoxID).options[0]) {
										          for (list = document.getElementById(selBoxID).length - 1; list >= 0; list--) {
																				        if (document.getElementById(selBoxID).options[list].value.length > 0) { document.getElementById(selBoxID).remove(list); }
																				       }
										         }
				       /* Grab array of data based on first character user entered */
				       if (arrayUse == "a") { try { arrayData = nv_a.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "b") { try { arrayData = nv_b.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "c") { try { arrayData = nv_c.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "d") { try { arrayData = nv_d.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "e") { try { arrayData = nv_e.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "f") { try { arrayData = nv_f.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "g") { try { arrayData = nv_g.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "h") { try { arrayData = nv_h.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "i") { try { arrayData = nv_i.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "j") { try { arrayData = nv_j.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "k") { try { arrayData = nv_k.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "l") { try { arrayData = nv_l.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "m") { try { arrayData = nv_m.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "n") { try { arrayData = nv_n.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "o") { try { arrayData = nv_o.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "p") { try { arrayData = nv_p.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "q") { try { arrayData = nv_q.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "r") { try { arrayData = nv_r.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "s") { try { arrayData = nv_s.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "t") { try { arrayData = nv_t.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "u") { try { arrayData = nv_u.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "v") { try { arrayData = nv_v.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "w") { try { arrayData = nv_w.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "x") { try { arrayData = nv_x.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "y") { try { arrayData = nv_y.slice(); } catch(e) { processAllow = 0; } }
				       else if (arrayUse == "z") { try { arrayData = nv_z.slice(); } catch(e) { processAllow = 0; } }
				       else { processAllow = 0; }
				       if (processAllow == 1) {
							       var numRows = 0, lastRowName = "", lastRowID = "";
							       for (list = 0; list < arrayData.length; list++) {
													        var nameTxt = arrayData[list].split(",")[0].toLowerCase();
													        nameTxt = nameTxt.substr(0, strValue.length);
													        if (nameTxt == strValue) {
																          var selChild = document.createElement("option");
																          selChild.text = arrayData[list].split(",")[0];
																          selChild.value = arrayData[list].split(",")[1];
																          try { document.getElementById(selBoxID).add(selChild, null); }
																          catch(onerror) { document.getElementById(selBoxID).add(selChild); }
																          document.getElementById(selBoxID).style.display = "inline";
																          numRows = numRows + 1; document.getElementById(selBoxID).setAttribute("size", numRows);
																          lastRowName = arrayData[list].split(",")[0]; lastRowID = arrayData[list].split(",")[1];
																         }
													       }
							       if (numRows == 1) {
										  document.getElementById(interactiveBoxID).value = lastRowName;
										  document.getElementById(optIndexTxtElementID).value = lastRowName;
										  document.getElementById(optIndexElementID).value = lastRowID;
										  document.getElementById(selBoxID).style.display = "none";
										  submitState();
										 }
							       else if (numRows == 0) { document.getElementById(selBoxID).style.display = "none"; }
							      }
				       else { document.getElementById(selBoxID).style.display = "none"; }
				      }
	    }
     }
}
function DataSelect(txtName, txtID) {
document.getElementById(interactiveBoxID).value = txtName;
document.getElementById(optIndexTxtElementID).value = txtName;
document.getElementById(optIndexElementID).value = txtID;
}
function DataMovement(txtName, txtID, keyPress) {
var lastKeyPressed = keyPress.keyCode ? keyPress.keyCode : keyPress.charCode;
var maxIndex = document.getElementById(selBoxID).length - 1;
if (lastKeyPressed == 40) {
			   /* Down Arrow Pressed */
			   if (optionSelectedIndex < maxIndex) { optionSelectedIndex = optionSelectedIndex + 1; }
			   document.getElementById(selBoxID).selectedIndex = optionSelectedIndex;
			  }
if (lastKeyPressed == 38) {
			   /* Up Arrow Pressed */
			   if (optionSelectedIndex > 0) { optionSelectedIndex = optionSelectedIndex - 1; }
			   document.getElementById(selBoxID).selectedIndex = optionSelectedIndex;
			  }
if (lastKeyPressed == 13) {
			   /* Enter Pressed */
			   document.getElementById(selBoxID).style.display = "none";
			   selectDataAssign(txtName, txtID);
			  }
}
function DataSelectViaMouse(fontSizePY, fontSizeBuffer, elemID, event) {
var mouseXPos = 0, mouseYPos = 0, txtName = "", txtID = "";
document.getElementById(elemID).focus();
if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
							      /*IE*/
							      mouseXPos = event.clientX; mouseYPos = event.clientY;
							      mouseYPos = mouseYPos - IE_trackPageY;
							     }
else {
      /*Other*/
      mouseXPos = event.pageX; mouseYPos = event.pageY;
      mouseYPos = mouseYPos - FF_trackPageY;
     }
var verticalOptionSize = fontSizePY + fontSizeBuffer;
var optionIndexSelected = parseInt(mouseYPos / verticalOptionSize);
try {
     /* IE Only: Bottom edge of last element was clicked resulting in index miscalculation of one. */
     document.getElementById(elemID).selectedIndex = optionIndexSelected;
     txtName = document.getElementById(elemID).options[optionIndexSelected].text;
     txtID = document.getElementById(elemID).options[optionIndexSelected].value;
    }
catch(onerror) {
		/* IE Only: Offset index by one. */
		optionIndexSelected = optionIndexSelected - 1;
		document.getElementById(elemID).selectedIndex = optionIndexSelected;
		txtName = document.getElementById(elemID).options[optionIndexSelected].text;
		txtID = document.getElementById(elemID).options[optionIndexSelected].value;
	       }
document.getElementById(elemID).style.display = "none";
/* Assign the values */
selectDataAssign(txtName, txtID);
}
function selectDataAssign(txtName, txtID) {
document.getElementById(interactiveBoxID).value = txtName;
document.getElementById(optIndexTxtElementID).value = txtName;
document.getElementById(optIndexElementID).value = txtID;
optIndexElementID = txtID;
document.getElementById(interactiveBoxID).focus();
optionSelectedIndex = -1;
submitState();
}
function submitState() {
/* Submit Data */
document.getElementById(submitButton).focus();
document.getElementById(frmID).submit();
}
