

function Toggle(activityTypeId)
{
	var ac = new String(activityTypeId);
	var s = new String();

	s='1,2,3,4,5,6,7';
	document.all.wrapperDate.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';
	
	s='1,2,3,4';
	document.all.wrapperCommodity.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';
	
	s='1,3,4,6,7';
	document.all.wrapperInternalLocation.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';	

	s='2';
	document.all.wrapperExternalLocation.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';	

	s='6,7';
	document.all.wrapperDepotReference.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';	

	s='1,2,3,4';
	document.all.wrapperFeeder.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='2';
	document.all.wrapperReturnToTerminal.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='2,3,4';
	document.all.wrapperBooking.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='2,3,4';
	document.all.wrapperBookingNumber.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='1,2,3,4';
	document.all.wrapperVoyage.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='2,3';
	document.all.wrapperDirection.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='2,3';
	document.all.wrapperFeederLoad.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='2,3,4';
	document.all.wrapperDischargePort.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='2,3';
	document.all.wrapperTransporter.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='1,2,3,4';
	document.all.wrapperWeightPayload.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='1,2,3,4,6,7';
	document.all.wrapperSeal.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='1,2,3,4';
	document.all.wrapperSeal_II.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='1,2,3,4';
	document.all.wrapperSeal_III.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='4';
	document.all.wrapperSlot.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='1,2,3,4,5,6,7';
	document.all.wrapperRemarks.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='6,7';
	document.all.wrapperInvoice.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	s='2,3';
	document.all.wrapperGateInterchangeReceipt.style.display = (s.indexOf(ac) == -1) ? 'none' : 'inline';

	InitActivityForm();
}

function InitActivityForm()
{
	var form = window.top.document.all['iFrameActivity'].contentWindow.document.forms.frmActivity;
	if (form == null)
		return;

	//Enable all controls
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		var name = new String(e.name);
		e.disabled = false;
	}

	var wrapper = window.top.document.all['activityWrapper'];
	wrapper.style.display = 'inline';
	
	form.cmbActivityType.focus();
	
	//Fill in the bookings
	var bookingList = window.top.document.all['iFrameContainer'].contentWindow.bookingList;
	for (var i=form.cmbBooking.length;i>=0; i--) 
    	form.cmbBooking[i] = null;
	form.cmbBooking[form.cmbBooking.length] = new Option('---None---', 0);		
	if (bookingList != null)
	{	
		window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.style.color = '#FF0000';
		for (i=0;i<bookingList.bookingid.length;i++)
			form.cmbBooking[form.cmbBooking.length] = new Option(bookingList.bookingreference[i] +" [Voyage: "+bookingList.voyage[i]+"]", bookingList.bookingid[i]);
	}
	else
		window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.style.color = '#000000';

	//Select a booking if the container is allready connected to one
	var currentBooking = window.top.document.all['iFrameContainer'].contentWindow.currentBooking;
	form.cmbBooking.disabled = false;
	if (currentBooking != null)
	{
		form.cmbBooking.value = currentBooking.bookingid;	
		form.cmbBooking.disabled = true;
		
		window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.title = currentBooking.bookingdate.toLocaleString() + "\n";
		window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.title += "Voyage: "+currentBooking.voyage + "\n";
		form.txtBookingNumber.disabled = true;
		
		//Reset booking on toggle (Probably never in use for currentBooking, but keep it for consistency
		if (currentBooking['resetOnToggle'] == true)
		{
			window.top.document.all['iFrameContainer'].contentWindow.currentBooking = null;
			
			//Removes the booking from the booking list. (Only the bookingid, as thats what we loop on a few lines up the code)
			var tmpArr = new Array();
			for (i=0;i<bookingList.bookingid.length;i++)
			{
				if (bookingList.bookingid[i] != currentBooking['bookingid'])
					tmpArr[i] = currentBooking['bookingid'];
			}
			bookingList.bookingid = tmpArr;
		}
	}
	
	
	//Check if it's an edit
	var activityId = window.top.document.all['iFrameActivity'].contentWindow.document.forms.frmActivity.ActivityId.value;
	if (activityId != 0)
	{
		//There can be edit javascript objects
		var bookingEdit = window.top.document.all['iFrameContainer'].contentWindow.bookingEdit;
		form.cmbBooking.disabled = false;
		if (bookingEdit != null)
		{
			form.cmbBooking.value = bookingEdit.bookingid;	
			form.cmbBooking.disabled = true;
			
			window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.title = bookingEdit.bookingdate.toLocaleString() + "\n";
			window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.title += "Voyage: "+bookingEdit.voyage + "\n";
			form.txtBookingNumber.disabled = true;
			
			//Reset booking on toggle
			if (bookingEdit['resetOnToggle'] == true)
			{
				window.top.document.all['iFrameContainer'].contentWindow.bookingEdit = null;
				
				//Removes the booking from the booking list. (Only the bookingid, as thats what we loop on a few lines up the code)
				var tmpArr = new Array();
				for (i=0;i<bookingList.bookingid.length;i++)
				{
					if (bookingList.bookingid[i] != bookingEdit['bookingid'])
						tmpArr[i] = bookingEdit['bookingid'];
				}
				bookingList.bookingid = tmpArr;
			}
		}	
	
		wrapper.style.backgroundColor = "#FFFFFF";
		return;
		
	}

	//"Reset" stuff
	Today('',0);
	Direction();
	form.cmbCommodity.selectedIndex = 0;
	form.cmbInternalLocation.selectedIndex = 0; 
	form.cmbExternalLocation.selectedIndex = 0; 
	form.txtDepotReference.value = '';
	form.cmbFeeder.selectedIndex = 0;
	form.cmbReturnToTerminal.selectedIndex = 0;
	form.txtBookingNumber.value = '';
	form.txtVoyage.value = '';
	form.cmbFeederLoad.selectedIndex = 0;
	form.cmbDischargePort.selectedIndex = 0;
	form.cmbTransporter.selectedIndex = 0;
	form.txtWeightPayload.value = 0;
	form.txtSeal.value = '';
	form.txtSeal_II.value = '';
	form.txtSeal_III.value = '';
	form.txtSlot.value = '';
	form.txtRemarks.value = '';
	form.chkInvoice.checked = true;


	//Fill in from the latest registered activity on the container
	var la = window.top.document.all['iFrameContainer'].contentWindow.latestActivity;
	var lastActivity = window.top.document.all['iFrameContainer'].contentWindow.lastActivity;
	if (la == null)
	{
		if (lastActivity != null)
			la = lastActivity;
	}

	if (la != null)
	{	
		switch(Number(form.cmbActivityType.value))
		{
			case 1:
			{
				form.cmbCommodity.value = la['commodityid'];
				form.cmbFeeder.value = la['feederid'];
				form.txtWeightPayload.value = la['weightpayload'];
				form.txtSeal.value = la['seal'];
				form.txtSeal_II.value = la['seal_ii'];
				form.txtSeal_III.value = la['seal_iii'];
				
				break;
			}
			//Gate Out
			case 2:
			{
				//We only care about if the previous move was discharge
				if (la['activitytypeid'] != 1)
					break;
				form.cmbCommodity.value = la['commodityid'];
				form.cmbFeeder.value = 55; //Vehicle
				form.txtVoyage.value = la['voyage'];
				form.txtWeightPayload.value = la['weightpayload'];
				form.txtSeal.value = la['seal'];
				form.txtSeal_II.value = la['seal_ii'];
				form.txtSeal_III.value = la['seal_iii'];
				form.txtRemarks.value = la['remarks'];
				break;
			}
			//Gate In
			case 3:
			{
				if (la['activitytypeid'] != 2)
					break;
				form.txtVoyage.value = la['voyage'];
				form.txtBookingNumber.value = la['reference'];
				break;
			}
			//Load
			case 4:
			{
				//We only care about if the previous move was gate in
				if (la['activitytypeid'] != 3)
					break;
				form.cmbInternalLocation.value = la['locationid'];
				form.cmbCommodity.value = la['commodityid'];
				form.cmbFeeder.value = la['feeder2id'];
				form.cmbDischargePort.value = la['portofdischarge'];
				form.txtVoyage.value = la['voyage'];
				form.txtBookingNumber.value = la['reference'];
				form.txtWeightPayload.value = la['weightpayload'];
				form.txtSeal.value = la['seal'];
				form.txtSeal_II.value = la['seal_ii'];
				form.txtSeal_III.value = la['seal_iii'];
				form.txtRemarks.value = la['remarks'];
				break;
								
			}
			//Strip
			case 5:
			{
				form.txtRemarks.value = la['remarks'];
				break;
			}
			//Depot In
			case 6:
			{
				if (la['activitytypeid'] == 1 || la['activitytypeid'] == 3)
				{
					form.cmbInternalLocation.value = la['locationid'];
					form.txtRemarks.value = la['remarks'];
					form.txtSeal.value = la['seal'];
				}
				break;
			}
	
			//Depot Out
			case 7:
			{
				if (la['activitytypeid'] != 6)
					break;
				form.cmbInternalLocation.value = la['locationid'];
				form.txtRemarks.value = la['remarks'];
				form.txtSeal.value = la['seal'];
				break;
			}
		}
	}
	//Fill in the booking things
	if (Number(form.cmbActivityType.value) == 2 || Number(form.cmbActivityType.value) == 3 || Number(form.cmbActivityType.value) == 4)
		FillInBooking(form,form.cmbBooking.value);
		
	wrapper.style.backgroundColor = "#FFFFFF";		
}

function FillInBooking(form,bookingId)
{
	window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.title = "Select the booking you want connect the container to.";

	if (form == null)
		return;
		
	var bookingList = window.top.document.all['iFrameContainer'].contentWindow.bookingList;
	if (bookingList == null)
		return;

	//Enable all controls
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		var name = new String(e.name);
		if (name != 'cmbBooking')
			e.disabled = false;
	}
	
	form.txtBookingNumber.value = '';
	form.cmbDischargePort.selectedIndex = 0;
	form.cmbExternalLocation.selectedIndex = 0;	
	form.cmbFeeder.selectedIndex = 0;
	form.cmbFeederLoad.selectedIndex = 0;
	form.txtVoyage.value = '';
	window.top.document.all['iFrameActivity'].contentWindow.document.all.bookingNotes.innerHTML = '';

	if (bookingId == 0)
		return;

	for (var i=0;i<bookingList.bookingreference.length;i++)
	{
		if (bookingList.bookingid[i] == bookingId)
		{
			form.txtBookingNumber.value = bookingList.bookingreference[i];
			form.txtBookingNumber.disabled = true;
			
			form.cmbDischargePort.value = bookingList.portofdischargeid[i];
			if (form.cmbDischargePort.value != 0)
				form.cmbDischargePort.disabled = true;

			if (bookingList.locationid[i] != 0)
			{
				form.cmbExternalLocation.value = bookingList.locationid[i];
				form.cmbExternalLocation.disabled = true;
			}

			if (form.cmbActivityType.value == 4)
			{
				form.cmbFeeder.value = bookingList.loadfeederid[i];
				if (form.cmbFeeder.value != 59)
					form.cmbFeeder.disabled = true;
			}
			else
			{
				form.cmbFeederLoad.value = bookingList.loadfeederid[i];
				if (form.cmbFeederLoad.value != 59)
					form.cmbFeederLoad.disabled = true;				
			}
			
			form.txtVoyage.value = bookingList.voyage[i];
			form.txtVoyage.disabled = true;			
			
			window.top.document.all['iFrameActivity'].contentWindow.document.all.bookingNotes.innerHTML = bookingList.notes[i];
			
			window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.title = bookingList.bookingdate[i].toLocaleString() + "\n";
			window.top.document.all['iFrameActivity'].contentWindow.document.all.lblBooking.title += "Voyage: "+ bookingList.voyage[i] + "\n";

			break;
		}
	}
}


function LoadContainerUI(display,containerNumber,containerId,activityId)
{
	try
	{
		
		_display = new String(display);
		_containerNumber = new String(containerNumber);
		_containerId = new Number(containerId);
		_activityId = new Number(activityId);
		
		window.top.document.all['activityWrapper'].style.backgroundColor = "#FF0000";
		window.top.document.all['containerWrapper'].style.height = 290;
		window.top.document.all['iFrameContainer'].height = 270;
		window.top.document.all['containerWrapper'].style.display = _display;

		var icon = new String("expand.jpg");
		if(_display == 'inline')
			icon = "collapse.jpg";
		window.top.document.all['imgContainerWrapper'].src="../../../../images/web/"+icon;	
		
		window.top.document.all['iFrameContainer'].src = 'default.cfm?Page=UIContainer&ActivityId='+_activityId+'&ContainerId='+containerId+'&display='+_display+'&containerNumber='+containerNumber+'&UseFramework=false&rand='+Math.random();
	}
	catch(err)
	{
		alert("Unable to setup container UI.\n" + err.message);
	}
	
	
}

function LoadActivityUI(display,containerId,containerNumber,activityId,interchangeReceipt)
{
	try
	{
		_display = new String(display);
		_containerId = new Number(containerId);
		_containerNumber = new String(containerNumber);
		_activityId = new Number(activityId);
		_interchangeReceipt = interchangeReceipt == null ? new Boolean(false) : interchangeReceipt;
		
		window.top.document.all['activityWrapper'].style.height = 710;
		window.top.document.all['iFrameActivity'].style.height = 690;
		window.top.document.all['activityWrapper'].style.display = _display;

		var setSource = true;

		if (window.top.document.all['iFrameActivity'].src != '')
		{	
			if (activityId == 0)
				setSource = false;
				
			if (window.top.document.all['iFrameActivity'].contentWindow.document.forms.frmError != null)
				setSource = true;
		}
		
		if (setSource)
			window.top.document.all['iFrameActivity'].src = "default.cfm?Page=UIActivity&ActivityId="+_activityId+"&ContainerId="+_containerId+"&InterchangeReceipt="+_interchangeReceipt+"&UseFramework=false&rand="+Math.random();	
		else
			window.top.document.all['iFrameActivity'].contentWindow.LoadValues(_activityId,_containerId,_containerNumber);

		var icon = new String("expand.jpg");
		if(_display == 'inline')
			icon = "collapse.jpg";
		window.top.document.all['imgActivityWrapper'].src="../../../../images/web/"+icon;			
	}
	catch(err)
	{
		alert("Unable to setup activity UI.\n" + err.description);
	}
}


function Direction()
{
	var form = document.forms.frmActivity;
	
	//alert(form.cmbCommodity.value);
	
	if (form.cmbActivityType.value == 2)
		{
			if (form.cmbCommodity.value == 1)
				form.cmbDirection.value = 2;
			else
				form.cmbDirection.value = 3;
		}
	else
		{
			if (form.cmbCommodity.value == 1)
				form.cmbDirection.value = 0;
			else
				form.cmbDirection.value = 2;
		}
}








	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, April 2006
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	

	var ajaxBox_offsetX = 0;
	var ajaxBox_offsetY = 0;
	var ajax_list_externalFile = 'default.cfm';	// Path to external file
	var minimumLettersBeforeLookup = 1;	// Number of letters entered before a lookup is performed.
	
	var ajax_list_objects = new Array();
	var ajax_list_cachedLists = new Array();
	var ajax_list_activeInput = false;
	var ajax_list_activeItem;
	var ajax_list_optionDivFirstItem = false;
	var ajax_list_currentLetters = new Array();
	var ajax_optionDiv = false;
	var ajax_optionDiv_iframe = false;

	var ajax_list_MSIE = false;
	if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)ajax_list_MSIE=true;
	
	var currentListIndex = 0;
	
	function ajax_getTopPos(inputObj)
	{
		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
	}
	function ajax_list_cancelEvent()
	{
		return false;
	}
	
	function ajax_getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  
	  return returnValue;
	}
	
	function ajax_option_setValue(e,inputObj)
	{
		
		if(!inputObj)
			inputObj=this;
		var tmpValue = inputObj.innerHTML;
		
		if(ajax_list_MSIE)
			tmpValue = inputObj.innerText;
		else 
			tmpValue = inputObj.textContent;
		
		if(!tmpValue)
			tmpValue = inputObj.innerHTML;
			
		ajax_list_activeInput.value = tmpValue;
		
		if(document.getElementById(ajax_list_activeInput.name + '_hidden'))
			document.getElementById(ajax_list_activeInput.name + '_hidden').value = inputObj.id; 
			
		ajax_options_hide();
		
		
	}
	
	function ajax_options_hide()
	{
		if(ajax_optionDiv)ajax_optionDiv.style.display='none';	
		if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='none';
	}

	function ajax_options_rollOverActiveItem(item,fromKeyBoard)
	{
		if(ajax_list_activeItem)ajax_list_activeItem.className='optionDiv';
		item.className='optionDivSelected';
		ajax_list_activeItem = item;
		
		if(fromKeyBoard){
			if(ajax_list_activeItem.offsetTop>ajax_optionDiv.offsetHeight){
				ajax_optionDiv.scrollTop = ajax_list_activeItem.offsetTop - ajax_optionDiv.offsetHeight + ajax_list_activeItem.offsetHeight + 2 ;
			}
			if(ajax_list_activeItem.offsetTop<ajax_optionDiv.scrollTop)
			{
				ajax_optionDiv.scrollTop = 0;	
			}
		}
	}
	
	function ajax_option_list_buildList(letters,paramToExternalFile)
	{
		
		ajax_optionDiv.innerHTML = '';
		ajax_list_activeItem = false;
		if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length<=0)
		{
			ajax_options_hide();
			return;			
		}
		
		
		
		ajax_list_optionDivFirstItem = false;
		var optionsAdded = false;
		for(var no=0;no<ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length;no++)
		{
			if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].length==0)continue;
			optionsAdded = true;
			var div = document.createElement('DIV');
			var items = ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].split(/%%%/gi);
			
			if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length==1 && ajax_list_activeInput.value == items[0]){
				ajax_options_hide();
				return;						
			}
			
			div.innerHTML = items[items.length-1];
			div.id = items[0];
			div.className='optionDiv';
			div.onmouseover = function(){ ajax_options_rollOverActiveItem(this,false) }
			div.onclick = ajax_option_setValue;
			if(!ajax_list_optionDivFirstItem)
				ajax_list_optionDivFirstItem = div;

			ajax_optionDiv.appendChild(div);
		}	
		if(optionsAdded){
			ajax_optionDiv.style.display='block';
			if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='';
			ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
		}
					
	}
	
	//Callback function///////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,whichIndex)
	{
		if(whichIndex!=currentListIndex)
			return;
			
		var letters = inputObj.value;
		var content = ajax_list_objects[ajaxIndex].response;
		content = content.substring(content.indexOf("'")+1,content.lastIndexOf("'"));
		var elements = content.split('|');
		ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()] = elements;
		ajax_option_list_buildList(letters,paramToExternalFile);

		//alert(content);
		if (content == '')
			ajax_options_hide();
		
	}
	
	function ajax_option_resize(inputObj)
	{
		ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
		ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
		if(ajax_optionDiv_iframe){
			ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
			ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;			
		}		
	}
	
	//Caller function/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function ajax_showOptions(inputObj,paramToExternalFile,e)
	{
		//alert(e.keyCode);
		if(e.keyCode==13 || e.keyCode==9)
			return;
			
		if(ajax_list_currentLetters[inputObj.name]==inputObj.value)
			return;
			
		if(!ajax_list_cachedLists[paramToExternalFile])
			ajax_list_cachedLists[paramToExternalFile] = new Array();
			
		ajax_list_currentLetters[inputObj.name] = inputObj.value;
		
		if(!ajax_optionDiv)
		{
			ajax_optionDiv = document.createElement('DIV');
			ajax_optionDiv.id = 'ajax_listOfOptions';	
			document.body.appendChild(ajax_optionDiv);
			
			if(ajax_list_MSIE){
				ajax_optionDiv_iframe = document.createElement('IFRAME');
				ajax_optionDiv_iframe.border='0';
				ajax_optionDiv_iframe.style.width = ajax_optionDiv.clientWidth + 'px';
				ajax_optionDiv_iframe.style.height = ajax_optionDiv.clientHeight + 'px';
				ajax_optionDiv_iframe.id = 'ajax_listOfOptions_iframe';
				
				document.body.appendChild(ajax_optionDiv_iframe);
				
			}
			
			var allInputs = document.getElementsByTagName('INPUT');
			for(var no=0;no<allInputs.length;no++){
				if(!allInputs[no].onkeyup)allInputs[no].onfocus = ajax_options_hide;
			}			
			var allSelects = document.getElementsByTagName('SELECT');
			for(var no=0;no<allSelects.length;no++){
				allSelects[no].onfocus = ajax_options_hide;
			}

			var oldonkeydown=document.body.onkeydown;
			if(typeof oldonkeydown!='function'){
				document.body.onkeydown=ajax_option_keyNavigation;
			}else{
				document.body.onkeydown=function(){
					oldonkeydown();
				ajax_option_keyNavigation() ;}
			}
			var oldonresize=document.body.onresize;
			if(typeof oldonresize!='function'){
				document.body.onresize=function() {ajax_option_resize(inputObj); };
			}else{
				document.body.onresize=function(){oldonresize();
				ajax_option_resize(inputObj) ;}
			}
				
		}
		
		if(inputObj.value.length<minimumLettersBeforeLookup){
			ajax_options_hide();
			return;
		}
				

		ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
		ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
		if(ajax_optionDiv_iframe){
			ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
			ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;			
		}
		
		ajax_list_activeInput = inputObj;
		ajax_optionDiv.onselectstart =  ajax_list_cancelEvent;
		currentListIndex++;
		/*
		if(ajax_list_cachedLists[paramToExternalFile][inputObj.value.toLowerCase()])
		{
			ajax_option_list_buildList(inputObj.value,paramToExternalFile,currentListIndex);			
		}
		else
		{
		*///NO caching
			var tmpIndex=currentListIndex/1;
			ajax_optionDiv.innerHTML = '';
			var ajaxIndex = ajax_list_objects.length;
			ajax_list_objects[ajaxIndex] = new sack();
			var url = ajax_list_externalFile + '?' + paramToExternalFile + '&letters=' + inputObj.value.replace(" ","+") + "&rand=" +Math.random();
			ajax_list_objects[ajaxIndex].requestFile = url;	// Specifying which file to get
			ajax_list_objects[ajaxIndex].onCompletion = function(){ ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,tmpIndex); };	// Specify function that will be executed after file has been found
			ajax_list_objects[ajaxIndex].runAJAX();		// Execute AJAX function		
		//}
	}
	
	function ajax_option_keyNavigation(e)
	{
		if(document.all)e = event;
		
		if(!ajax_optionDiv)return;
		if(ajax_optionDiv.style.display=='none')return;
		
		if(e.keyCode==38){	// Up arrow
			if(!ajax_list_activeItem)return;
			if(ajax_list_activeItem && !ajax_list_activeItem.previousSibling)return;
			ajax_options_rollOverActiveItem(ajax_list_activeItem.previousSibling,true);
		}
		
		if(e.keyCode==40){	// Down arrow
			if(!ajax_list_activeItem){
				ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
			}else{
				if(!ajax_list_activeItem.nextSibling)return;
				ajax_options_rollOverActiveItem(ajax_list_activeItem.nextSibling,true);
			}
		}
		
		if(e.keyCode==13 || e.keyCode==9){	// Enter key or tab key
			if(ajax_list_activeItem && ajax_list_activeItem.className=='optionDivSelected')
				ajax_option_setValue(false,ajax_list_activeItem);
			
			if(e.keyCode==13)
				return false; 
			else 
				return true;
		}
		if(e.keyCode==27){	// Escape key
			ajax_options_hide();			
		}
	}
	
	
	document.documentElement.onclick = autoHideList;
	
	function autoHideList(e)
	{
		if(document.all)e = event;
		
		if (e.target) source = e.target;
			else if (e.srcElement) source = e.srcElement;
			if (source.nodeType == 3) // defeat Safari bug
				source = source.parentNode;		
		if(source.tagName.toLowerCase()!='input' && source.tagName.toLowerCase()!='textarea')ajax_options_hide();
		
	}






/*


function GetContainers()
{
	var tmpIndex=currentListIndex/1;
	ajax_optionDiv.innerHTML = '';
	var ajaxIndex = ajax_list_objects.length;
	ajax_list_objects[ajaxIndex] = new sack();
	var url = ajax_list_externalFile + '?' + paramToExternalFile + '&letters=' + inputObj.value.replace(" ","+") + "&rand=" +Math.random();
	ajax_list_objects[ajaxIndex].requestFile = url;	// Specifying which file to get
	ajax_list_objects[ajaxIndex].onCompletion = function(){ ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,tmpIndex); };	// Specify function that will be executed after file has been found
	ajax_list_objects[ajaxIndex].runAJAX();		// Execute AJAX function		
}
*/













