
// this function gets the cookie, if it exists
function getCookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function setCookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function changeBeside(besideObj, newBeside) {
//    if(ajaxData && ajaxData.targetName && ajaxData.targetName != besideObj) return;
	var TObject = getElement(besideObj + "_beside");
	if(TObject) {
	   var childObj = TObject.firstChild;
	   if(!childObj) {
	      childObj = document.createTextNode("");
	      TObject.appendChild(childObj);
	   }
	   var values;
	   if (!ajaxData.focus && ajaxData && ajaxData.items[0] && ajaxData.items[0].childNodes) {
          values = ajaxData.items[0].childNodes;
       } else {
          if(ajaxData.focus && ajaxData.items && ajaxData.items[ajaxData.focus]) {
  	           values = ajaxData.items[ajaxData.focus].childNodes;
  	      } else {
             childObj.nodeValue = '';
             return;
          }
	   }
       var beside = values[1].childNodes[0];
       if(beside) {
          childObj.nodeValue = beside.nodeValue;
       }
    } else {
       alert("no tobject");
    } 
	return besideObj; // not sure if needed
}

function focusFirst(FormId)
{
	var currField=document.forms[FormId].elements;
    var found = false;
	for (var i = 0; i < currField.length; i++) 
	{
        if (i==0) {
            try {
                currField[i].focus();
                found = true;
            } catch (err) {
            }
         }
         if (!found) {
             try {
                currField[i].focus();
                found = true;
            } catch (err) {
            }
         }
         if (found) {
         	break;
         }
     }
}

function executeSearch(event, FormId)
{
    if(event.keyCode == 13) {       
        var formElms=document.forms[FormId].elements;
        var sButton;
    	for (var i = 0; i < formElms.length; i++)  {
    	    if(formElms[i].type == 'submit') {
    	       if(formElms[i].name.search(/buttonSearch/) != -1) {
    	          sButton = formElms[i];
    	       }
    	    }
        }
		if(!sButton) { 
		   // do nothing
		   return;
		} else {
			event.keyCode = 0;
			sButton.click();	
		}
	}
}

function setFormField(FormId, FieldId, Value)
{
	document.forms[FormId][FieldId].value=Value;
}

function selectTableRow(FormId, FieldId, RowNum)
{
	setFormField(FormId, FormId, FormId);
	setFormField(FormId, FieldId, RowNum);
	document.forms[FormId].submit();
}

function selectTableAction(FormId, RowId, RowNum, ActionID, ActionNum)
{
	setFormField(FormId, FormId, FormId);
	setFormField(FormId, RowId, RowNum);
	setFormField(FormId, ActionID, ActionNum);
	document.forms[FormId].submit();
}

function selectTableRowAction(FormId, RowId, RowNum, ColId, ColNum, ActionID, ActionNum)
{
	setFormField(FormId, FormId, FormId);
	setFormField(FormId, RowId, RowNum);
	setFormField(FormId, ColId, ColNum);
	setFormField(FormId, ActionID, ActionNum);
	document.forms[FormId].submit();
}

function selectTreeAction(FormId, CompId, NodeId)
{
	setFormField(FormId, FormId, FormId);
	setFormField(FormId, CompId, NodeId);
	document.forms[FormId].submit();
}

function selectMenuAction(FormId, CompId)
{
	setFormField(FormId, FormId, FormId);
	setFormField(FormId, CompId, 'clicked');
	document.forms[FormId].submit();
}

function tablePagingAction(FormId, CompId, Action)
{
	setFormField(FormId, FormId, FormId);
	setFormField(FormId, CompId, Action);
	document.forms[FormId].submit();
}



function getElementX(element){
    var targetLeft = 0;
    if (element.offsetParent) {
        while (element.offsetParent) {
            targetLeft += element.offsetLeft;
            element = element.offsetParent;
        }
    } else if (element.x) {
        targetLeft += element.x;
    }
    return targetLeft;
}

function getElementY(element){
    var targetTop = 0;
    if (element.offsetParent) {
        while (element.offsetParent) {
            targetTop += element.offsetTop;
            element = element.offsetParent;
        }
    } else if (element.y) {
        targetTop += element.y;
    }
    return targetTop;
}


function attachElement(elem,anchor){
    var x = getElementX(anchor); 
    var y = getElementY(anchor) + anchor.offsetHeight + 2;
    
    if (x + elem.clientWidth + 50> document.body.offsetWidth ) {
      x = getElementX(anchor) + anchor.offsetWidth - elem.clientWidth;      
    }
    elem.style.left = x + "px";        
    elem.style.top = y + "px";
    elem.style.visibility = "visible";
}

function overlap(elem1, elem2) {

   var x1 = getElementX(elem1);
   var x2 = getElementX(elem2);
   var y1 = getElementY(elem1);
   var y2 = getElementY(elem2);
   var w1 = elem1.clientWidth;
   var w2 = elem2.clientWidth;
   var h1 = elem1.clientHeight;
   var h2 = elem2.clientHeight;

   return  x1 < x2+w2 && x2 < x1+w2 && 
           y1 < y2+h2 && y2 < y1+h2;
   
}

function hideSelects(MenuId) {
  var MenuObject = document.getElementById(MenuId);
	if(MenuObject) {
      var dropDowns = document.getElementsByTagName("select");
      for (loop = 0; loop < dropDowns.length; loop++) {
        if (overlap(dropDowns[loop],MenuObject)) dropDowns[loop].style.visibility = "hidden";
      }
    }
} 
function showSelects(MenuId) {
    var MenuObject = document.getElementById(MenuId);
	if(MenuObject) {
      var dropDowns = document.getElementsByTagName("select");
      for (loop = 0; loop < dropDowns.length; loop++) {
        if (overlap(dropDowns[loop],MenuObject)) dropDowns[loop].style.visibility = "visible";
      }
    }
} 

function toggle_submenu(MenuId) 
{    
	var MenuObject = document.getElementById(MenuId);
	if(MenuObject) {
		if(MenuObject.style.display=='none') {
 			MenuObject.style.display='inline';
			setTimeout("hideSelects('"+MenuId+"');",10);
 		} else {
			MenuObject.style.display='none';
			setTimeout("showSelects('"+MenuId+"');",10);			
		}	
	} else {
		alert("Menuobject [" + MenuId + "] does not exist!");
	}
}


function toggle_submenu_inline(MenuId, FormId, FieldId) 
{
	var MenuObject = document.getElementById(MenuId);
	if(MenuObject) {
		if(MenuObject.style.display=='none') {
			MenuObject.style.display='inline';
			setFormField(FormId, FieldId, '1');
		} else {
			MenuObject.style.display='none';
			setFormField(FormId, FieldId, '0');
		}	
	} else {
		alert("Menuobject [" + MenuId + "] does not exist!");
	}
}


function getElement(id) {
    var elem = document.getElementById(id);
    if (!elem) target=document.getElementsByName(id)[0];
    return elem;
}


var ajaxReq;

function ajaxCallBack() {
    if (ajaxReq.readyState < 4) {
       if (ajaxShowLoad) ajaxShowLoad();
    } else if (ajaxReq.readyState == 4) {
       if (ajaxHideLoad) ajaxHideLoad();               
    }
}
 
function ajaxRequestPOST(url, params) {

   if (window.XMLHttpRequest) {
      ajaxReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
  	ajaxReq.open("POST", url, false);
  	ajaxReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
    ajaxReq.onreadystatechange = ajaxCallBack;
    ajaxReq.send(params);

}     
  
    
function ajaxRequestImpl(handler, action, params, async) {

   if (window.XMLHttpRequest) {
      ajaxReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	var url = "Ajax?handler="+handler+"&action="+action+"&"+params;
    ajaxReq.open("GET", url, async);
    ajaxReq.onreadystatechange = ajaxCallBack;
    ajaxReq.send(null);

} 


   

function ajaxRequestXML(handler, action, params) {
    ajaxRequestImpl(handler, action, params, false)     
    if (ajaxReq.status == 200) {
       return ajaxReq.responseXML;
    } else {
       return null;
    }
}

function ajaxRequestHtml(handler, action, params) {
    ajaxRequestImpl(handler, action, params, false)     
    if (ajaxReq.status == 200) {
       return ajaxReq.responseText;
    } else {
       return null;
    }
}

function ajaxRequestAsync(handler, action, params) {
    ajaxRequestImpl(handler, action, params, true) 
    return ajaxReq;   
}


function ajaxPostForm(formId, buttonId, copyDivArray) {
	var postString = "";
    var form = document.forms[formId];
	if(form) {
      var inputs = form.getElementsByTagName("input");
      for (loop = 0; loop < inputs.length; loop++) {
        if  ( inputs[loop].type == 'submit' ) {
        	if ( inputs[loop].id == buttonId )
        	   postString = postString + inputs[loop].name +"=" + encodeURI( inputs[loop].value ) + "&";        	
        } else if ( inputs[loop].type == 'checkbox' ) {
            if ( inputs[loop].checked )
               postString = postString + inputs[loop].name +"=" + encodeURI( inputs[loop].value ) + "&";
        } else if ( inputs[loop].type ) {
			postString = postString + inputs[loop].name +"=" + encodeURI( inputs[loop].value ) + "&";	      
	    }
      }
      var selects = form.getElementsByTagName("select");
      for (loop = 0; loop < selects.length; loop++) {
        postString = postString + selects[loop].name +"=" + encodeURI( selects[loop].value ) + "&";
      }
      
      var url = form.action;
      
      ajaxRequestPOST(url,postString);
      if (ajaxReq.status == 200) {
        var body = document.getElementsByTagName('body')[0];
        var oldDivs = body.getElementsByTagName('div');
        var div = document.createElement("div");
        div.innerHTML = ajaxReq.responseText;
        var divs = div.getElementsByTagName('div');
        
        for (var d=0; d <copyDivArray.length; d++) { 
            var  copyDivId = copyDivArray[d];     
        	for (loop = 0; loop < oldDivs.length; loop++) {
		      if (oldDivs[loop].id == copyDivId) oldDiv = oldDivs[loop];
		    }        

	        for (loop = 0; loop < divs.length; loop++) {
		      if (divs[loop].id == copyDivId) newDiv=divs[loop];
		    }   	    
		    oldDiv.parentNode.replaceChild( newDiv, oldDiv);
		}
	     
		elemCache = new Object();    
	  }      
    }
} 

//ajax
var ajaxData = new Object();
var ajaxMenuDiv;
var timeoutId = null;

function ajaxOnKeyDown(event,targetName,escmode) {	
    if(event.keyCode=='13') event.keyCode=9;
	if(event.keyCode==40) {
		ajaxData.focus++;
		if (ajaxData.focus==ajaxData.items.length) ajaxData.focus = ajaxData.items.length-1;
 	    ajaxData.allowQuery=false;
 	    markFocus(ajaxData.table);
 	    chooseFocus(true);
 	    event.keyCode=0;
	} else if(event.keyCode==38) {
		ajaxData.focus--;
		if (ajaxData.focus<0) ajaxData.focus = 0;
 	    ajaxData.allowQuery=false;
 	    markFocus(ajaxData.table);
 	    chooseFocus(true);
 	    event.keyCode=0;
	} else if (event.keyCode==8 || event.keyCode>40 || event.keyCode==32 ) {
	    ajaxData.allowQuery=true;
	} else if (event.keyCode==27) {
		if(escmode=='ignore') {
		   event.keyCode=0;
		} else {
			// on escape perform abort and tab out.
			abortCompletion(escmode);
			event.keyCode=9;
		}
	} else {	  
	  //alert(event.keyCode);	
	}
}


function abortCompletion(escmode) {
// TODO implement escape modes
    ajaxData.focus=-1;
    if(escmode=='clear') {
	   for (loop = 0; loop < ajaxData.fields.length; loop++) {
	      var target = document.getElementById(ajaxData.fields[loop]);
	      if(target) {
	        target.value = "";
	      }
	   }
	   stopCompletion();
	} else if (escmode=='reset') {
	   for (loop = 2; loop < ajaxData.fields.length; loop++) {
	      var target = document.getElementById(ajaxData.fields[loop]);
          if (!target && ajaxData.fields[loop]) target = document.getElementsByName(ajaxData.fields[loop])[0];
          if (target) {
             target.value = ajaxData.oldFields[loop-1];
          }
       }
       ajaxData.target.value = ajaxData.oldFields[0];
    }
}

function ajaxOnKeyUp(minlength,ajaxId,targetName,field1,field2,field3,field4,field5) {
	ajaxOnKeyUpBD(minlength,ajaxId,targetName,null,field1,field2,field3,field4,field5);
}

function ajaxOnKeyUpBD(minlength,ajaxId,targetName,besideDesc,field1,field2,field3,field4,field5) {
   if (!ajaxData.allowQuery) return;
   var target = document.getElementById(targetName);
   if (!target) target=document.getElementsByName(targetName)[0];
   clearTimeout(timeoutId);
   if (target.value.length<minlength) return;  
   timeoutId=setTimeout(
       "doCompletion('"+ajaxId+"','"+targetName+"','"+besideDesc+"','"+
       field1+"','"+field2+"','"+field3+"','"+
       field4+"','"+field5+"')",
       300);
}

function ajaxOnFocus(minlength,ajaxId,targetName,field1,field2,field3,field4,field5) {
	ajaxOnFocusBD(minlength,ajaxId,targetName,null,field1,field2,field3,field4,field5);
}

function ajaxOnFocusBD(minlength,ajaxId,targetName,besideDesc,field1,field2, field3, field4,field5) {
    var target = document.getElementById(targetName);
    if (!target) target=document.getElementsByName(targetName)[0];
    target.select();
    if (target.value.length>=minlength && !ajaxMenuDiv) {
      doCompletion(ajaxId,targetName,besideDesc,field1,field2,field3,field4,field5);
    } else if (target.value.length>=minlength && ajaxData.targetName!=targetName) {
      doCompletion(ajaxId,targetName,besideDesc,field1,field2,field3,field4,field5)
    } else if (target.value.length<minlength && ajaxData.targetName!=targetName) {
	  clearTable(ajaxData.table);
    } else if (ajaxMenuDiv) {
      attachElement(ajaxMenuDiv,target);
      markFocus(ajaxData.table);
    }
}

function ajaxOnBlur(ajaxId,targetName) {
   if (ajaxData.query) clearTimeout(timeoutId);
   ajaxData.sendBackAjaxId = null;
   stopCompletionOnBlur(targetName);
}

function ajaxOnBlurSendBack(ajaxId,targetName) {
   if (ajaxData.query) clearTimeout(timeoutId);
   ajaxData.sendBackAjaxId = ajaxId;   
   stopCompletionOnBlur(targetName);
}

function doCompletion(ajaxId,targetName,besideDesc,field1,field2,field3,field4,field5) {
    var target = getElement(targetName);

    if (ajaxData.query && ajaxData.query==target.value &&
        ajaxData.targetName && ajaxData.targetName==targetName ) return;
    
    var menuName = "ajaxMenu";//+ajaxId;
    if (!ajaxMenuDiv) ajaxMenuDiv = getElement(menuName);
    if (!ajaxMenuDiv) {
       var body = document.getElementsByTagName("body")[0];
	   ajaxMenuDiv = document.createElement("div");
	   ajaxMenuDiv.className = "ajaxDiv";	   
	   ajaxMenuDiv.id = menuName;
	   var t = document.createElement("table");
	   t.className = "ajaxMenu";	   
	   ajaxMenuDiv.appendChild(t);
	   body.appendChild(ajaxMenuDiv);
    }
    ajaxMenuDiv.style.overflow="auto";
    ajaxMenuDiv.style.width  = "";
	ajaxMenuDiv.style.height = "";
    var table = ajaxMenuDiv.childNodes[0];
	ajaxMenuDiv.style.position = "absolute";
    table.width = target.offsetWidth +"px";

    ajaxData = new Object();
    ajaxData.fields = new Array();
    ajaxData.items = new Array();
    ajaxData.fields[0] = targetName;
    ajaxData.fields[1] = besideDesc;    
    ajaxData.fields[2] = field1;
    ajaxData.fields[3] = field2;
    ajaxData.fields[4] = field3;
    ajaxData.fields[5] = field4;
    ajaxData.fields[6] = field5;
    ajaxData.oldFields = new Array();
    ajaxData.oldFields[0] = target.value;
    ajaxData.oldFields[1] = field1 == null ? null : field1.value;
    ajaxData.oldFields[2] = field2 == null ? null : field2.value;
    ajaxData.oldFields[3] = field3 == null ? null : field3.value;
    ajaxData.oldFields[4] = field4 == null ? null : field4.value;
    ajaxData.oldFields[5] = field5 == null ? null : field5.value;
    ajaxData.focus = 0;
    ajaxData.scrollPos = 0;
    ajaxData.sendBackId = null;
    ajaxData.table = table;
    ajaxData.targetName = targetName;
    ajaxData.target = target;
    ajaxData.menuName = menuName;
    ajaxData.query = target.value

    var params = "context=" + escape(ajaxId) + "&query=" + escape(target.value);
    response = ajaxRequestXML("completion","complete",params);  
    
    if (response) {
       parseMessages(table,response);
       attachElement(ajaxMenuDiv,ajaxData.target); 
       if (target.value != "")  chooseFocus(false); 
       hideSelects('ajaxMenu');       
    } else {	  
       clearTable(ajaxData.table);
    }       
}

function chooseFocus(forced){
    if ( ajaxData.focus==null) return //|| !ajaxData.items[ajaxData.focus]) return;
    if ( ajaxData.items[ajaxData.focus] == null ) return; 
    var values = ajaxData.items[ajaxData.focus].childNodes;
     for (loop = 0; loop < values.length; loop++) {
	 	var target = document.getElementById(ajaxData.fields[loop]);
        if (!target && ajaxData.fields[loop]) target = document.getElementsByName(ajaxData.fields[loop])[0];
        if (target) {
          if (values[loop].childNodes[0]) {
             var v = unescape(decodeURI(values[loop].childNodes[0].nodeValue));
	         if (loop==0 && !forced && v.toLowerCase().indexOf(ajaxData.query.toLowerCase())!=0) return;
             target.value = v
	         if (loop == 0) {
	         	var r = target.createTextRange();
	         	if (r && ajaxData.query) {
	          		if (v.toLowerCase().indexOf(ajaxData.query.toLowerCase())==0 ) {//prefix
	          		    //r.findText(ajaxData.query,0)) {
	            		r.moveStart("character",ajaxData.query.length);
	          			r.moveEnd("character",v.length);
   	          			r.select();
   	          		}
   	         	}
   	         }
          }
          else target.value="";
        }
     }
}


function chooseItem(number) {    
    ajaxData.focus=number;
    if (ajaxData.items[number]) {
     var values = ajaxData.items[number].childNodes;

     for (loop = 0; loop < values.length; loop++) {
	 	var target = document.getElementById(ajaxData.fields[loop]);
        if (!target && ajaxData.fields[loop]) target = document.getElementsByName(ajaxData.fields[loop])[0];
        if (target) {
          if (values[loop].childNodes[0]) target.value = unescape(decodeURI(values[loop].childNodes[0].nodeValue));
          else target.value="";
        }
     }
    } 
    stopCompletion();
}

function stopCompletionOnBlur(targetName){
    var target = document.getElementById(targetName); 
    if (!target) target=document.getElementsByName(targetName)[0];  
     if (ajaxData.items && ajaxData.items.length>0) chooseItem(ajaxData.focus);
        
    if (ajaxData.sendBackAjaxId) {//sendback
    			
	    var params;
	    if (ajaxData.items && ajaxData.items.length>0) {
		  params = "context=" + escape(ajaxData.sendBackAjaxId) + "&select=" + escape(ajaxData.focus);
		} else {
		  params = "context=" + escape(ajaxData.sendBackAjaxId) + "&select=-1"
		}
        response = ajaxRequestXML("completion","select",params);  

    }
    stopCompletion();

}


function stopCompletion() {
    if (ajaxMenuDiv != null) {           
       var table = ajaxMenuDiv.childNodes[0];
       //clearTable(table);
       ajaxMenuDiv.style.visibility = "hidden";
       showSelects('ajaxMenu');
    }    
}



function parseMessages(names,response) {
    clearTable(names);
    var items = response.getElementsByTagName("items")[0];
    for (loop = 0; loop < items.childNodes.length; loop++) {
        var item = items.childNodes[loop];
        appendItem(names, item, loop);
        ajaxData.items[loop] = item;
    }
    var otherfield = null;
    if(ajaxData.fields[1]) { // beside descriptor indicates linked field
    	otherfield = getElement(ajaxData.fields[1]);
    	if (otherfield && otherfield.value) {
	      for (loop = 0; loop < items.childNodes.length; loop++) {
             if ( otherfield.value ==
                  items.childNodes[loop].childNodes[1].firstChild.nodeValue) {
                  ajaxData.focus = loop;
              }    
    	  }    	
    	}
    }
    
    //set width of columns
    for (loop = 0; loop < items.childNodes.length; loop++) {
      var td1=names.childNodes[0].childNodes[loop].childNodes[0];
      var td2=names.childNodes[0].childNodes[loop].childNodes[1];
      td1.style.width=td1.offsetWidth;
      td2.style.width=td2.offsetWidth;
    }
    markFocus(names);
}

function clearTable(names) {
    if (names) {
      for (loop = names.childNodes.length -1; loop >= 0 ; loop--) {
        names.removeChild(names.childNodes[loop]);
      }
    }
}

var focusLock=null;
function markFocus(names) {
    setTimeout("focusLock=null",50);
    if (focusLock == 1 ) {
	    setTimeout(function(){markFocus(names)},300);
    	return ;
    }
    focusLock = 1;
    
    if (names) {
      var tbody = names.firstChild;
      if (tbody) {
    	  if (ajaxData.scrollPos + 6  < ajaxData.focus ) ajaxData.scrollPos = ajaxData.focus - 6;
    	  if (ajaxData.scrollPos < 0 ) ajaxData.scrollPos = 0; 

          if (ajaxData.focus <= ajaxData.scrollPos && ajaxData.scrollPos > 0) ajaxData.scrollPos--;
          if (ajaxData.focus >= ajaxData.scrollPos + 6  && ajaxData.scrollPos < tbody.childNodes.length - 7 ) ajaxData.scrollPos++;
	      for (loop = tbody.childNodes.length -1; loop >= 0 ; loop--) {
    	    var row = tbody.childNodes[loop];    	    
        	if (row) {
        	 	if (loop==ajaxData.focus) row.className = "ajaxItemFocus";
		    	else row.className = "ajaxItem";
		    	if (loop >= ajaxData.scrollPos && loop <= ajaxData.scrollPos+6) row.style.display = "";
		    	else  row.style.display = "none";
		    }
    	  }
    	  
      }
    }
}

function appendItem(names, item, number) {
    var firstNameCell;
    var lastNameCell;
    
    var name = "";
    if (item.childNodes[0].firstChild) name = unescape(decodeURI(item.childNodes[0].firstChild.nodeValue));
    var info = "";
    if (item.childNodes[1].firstChild) info = unescape(decodeURI(item.childNodes[1].firstChild.nodeValue));
    if (document.all) { //isIE
        row = names.insertRow(names.rows.length);
        row.onmouseover=function() {ajaxData.focus=number; markFocus(ajaxData.table);}
        nameCell = row.insertCell(0);
        infoCell = row.insertCell(1);
        if (name=="" && info=="") nameCell.height=10;        
    } else {
        row = document.createElement("tr");
        row.onmouseover=function() {ajaxData.focus=number; markFocus(ajaxData.table);}
        nameCell = document.createElement("td");
        row.appendChild(nameCell);
        infoCell = document.createElement("td");
        row.appendChild(infoCell);
        names.appendChild(row);
    }
	nameCell.className = "ajaxDisplay";
	nameCell.noWrap = true;
    infoCell.className = "ajaxInfo";
    if (number==ajaxData.focus)row.className = "ajaxItemFocus";
    else row.className = "ajaxItem";
    if (name!="") nameCell.appendChild(document.createTextNode(name));    
	else nameCell.appendChild(document.createTextNode("  "));    
    infoCell.noWrap = true;
    infoCell.appendChild(document.createTextNode(info));
}


