﻿<!--
function Menu(strObjName, strEID, strCallback) {
	this.itemNum = 0;
	this.items = Array();
	this.curSel = 0;
	this.objName = strObjName;
	this.elementID = strEID;
	this.callback = strCallback;

	this.selClassName = "son";		// Default class name
	this.unselClassName = "soff";		// Default class name
	
	if (arguments.length >= 5) {
		this.selClassName = arguments[3];
		this.unselClassName = arguments[4];

		if (arguments.length == 5) {
			this.maxSelection = arguments[5];
		}
	}
}

Menu.prototype.clear = function() {
	$(this.elementID).innerHTML = "";
	this.itemNum = 0;
	this.items.clear();
	this.curSel = 0;
}

Menu.prototype.add_item = function($content) {
	$(this.elementID).innerHTML += '<div style="cursor:pointer" class="' + this.unselClassName + '" onmouseover="' + this.objName + '.highlight(\'' + this.itemNum + '\')" onmouseout="' + this.objName +'.highlight(\'' + this.itemNum + '\')" onclick="' + this.callback + '(\'' + this.itemNum + '\')" id="MENU_ITEM_' + this.itemNum + '">' + $content + '</div>';
	this.items.push ($content);
	this.itemNum ++;
}

Menu.prototype.highlight = function (id) {
	for (var i = 0; i < this.itemNum; i++) {
		var d = $('MENU_ITEM_' + i);
		if (id == i) {
			d.className = this.selClassName;
			this.curSel = i;
		} else {
			d.className = this.unselClassName;
		}
	}
}

Menu.prototype.sel_next = function () {
	if (this.itemNum == 0)
		return;
	if (this.curSel < this.itemNum - 1) {
		this.highlight (this.curSel + 1);
	}
}

Menu.prototype.sel_prev = function () {
	if (this.itemNum == 0)
		return;
	if (this.curSel > 0) {
		this.highlight (this.curSel - 1);
	}
}

Menu.prototype.get_content = function (id) {
	if (id >= 0 && id < this.itemNum) {
		return $('MENU_ITEM_' + id).innerHTML;
	} else {
		return false;
	}
}

Menu.prototype.get_current_content = function () {
	return this.get_content(this.curSel);
}

var MAX_SELECTION = 10;
var suggestMenu;
var addrQuery ;
function init() {
	suggestMenu = new Menu ('suggestMenu', 'ID_ADDR_SEL', 'choose_addr', "son", "soff");
	addrQuery = "";
}

function choose_addr(id) {
	$('ID_ADDR_INPUT').value = suggestMenu.get_content(id);
	Element.hide ('ID_ADDR_SEL');
	query();
}

function showResult(req) {
	Element.hide('ID_LOADING');	
	if (req.responseText.length > 0) {
		var addrList = req.responseText.split('\n').without('\r', '\n', '');

		if (addrList.length == 0) 
			return;

		Element.show('ID_ADDR_SEL');
		searchSetTimeOut();
		suggestMenu.clear();
		for (var w = 0; w < Math.min(addrList.length, MAX_SELECTION); w++) {
			suggestMenu.add_item (addrList[w]);
		}
		suggestMenu.highlight (0);
	}	
}
function searchSetTimeOut()
{
	try
	{ 
	 window.clearTimeout(searchTime);
	}
	catch(e){}
	searchTime = setTimeout("Element.hide('ID_ADDR_SEL')",5*1000);
}
function searchCleanTimeOut()
{
	try
	{ 
	 window.clearTimeout(searchTime);
	}
	catch(e){}
}
function query() {
	searchCleanTimeOut();
	var user_input = $F('ID_ADDR_INPUT');
	if (user_input.length > 0 && addrQuery != user_input) {
		addrQuery = user_input;
		var parms = 'prefix=' + encodeURI(user_input);
		alert(parms);
		var ajaxQ = new Ajax.Request ('../xml/search.php', 
				{ method: 'get',
				  parameters: parms,
				  onComplete: showResult
				});
		Element.show('ID_LOADING');
	}
	else
	{
		Element.hide('ID_ADDR_SEL')
	}
			
}

function validate_id() {
	Element.update('ID_CHECK', '<img src="../images/circle-ball-dark-antialiased.gif">');
	var ajaxCheckID = new Ajax.Updater ('ID_NOUSE', '../xml/id_validate.php',
				{ method: 'get',
				  parameters: 'uid=' + $('ID_UID').value,
				  evalScripts: true
				});
}
-->