
//cityarray is the list of city names to be used in the drop down. Currently it includes all places in tiger_00_places.shp
var cityarray = new Array('Acton','Adelanto','Agoura Hills','Alameda','Alamo','Albany','Alhambra','Aliso Viejo','Almanor','Alondra Park','Alpaugh','Alpine','Alpine Village','Alta Sierra','Altadena','Alturas','Alum Rock','Amador City','American Canyon','Amesti','Anaheim','Anderson','Angels City','Angwin','Antioch','Apple Valley','Aptos','Aptos Hills-Larkin Valley','Arbuckle','Arcadia','Arcata','Arden-Arcade','Armona','Arnold','Aromas','Arroyo Grande','Artesia','Arvin','Ashland','Atascadero','Atherton','Atwater','Auberry','Auburn','August','Avalon','Avenal','Avery','Avocado Heights','Azusa','Bakersfield','Baldwin Park','Banning','Barstow','Bay Point','Bayview','Bayview-Montalvin','Baywood-Los Osos','Beale AFB','Bear Valley','Bear Valley Springs','Beaumont','Beckwourth','Belden','Bell','Bell Gardens','Bellflower','Belmont','Belvedere','Ben Lomond','Benicia','Berkeley','Bermuda Dunes','Bertsch-Oceanview','Bethel Island','Beverly Hills','Big Bear City','Big Bear Lake','Big Bend','Big Pine','Big River','Biggs','Biola','Bishop','Black Point-Green Point','Blackhawk-Camino Tassajara','Blairsden','Bloomington','Blue Lake','Bluewater','Blythe','Bodega Bay','Bodfish','Bolinas','Bombay Beach','Bonadelle Ranchos-Madera Ranchos','Bonita','Bonsall','Bootjack','Boron','Boronda','Borrego Springs','Bostonia','Boulder Creek','Bowles','Boyes Hot Springs','Bradbury','Bradley','Brawley','Brea','Brentwood','Bret Harte','Brisbane','Broadmoor','Bucks Lake','Buellton','Buena Park','Buena Vista','Burbank','Burbank_sj','Burlingame','Burney','Buttonwillow','Byron','Bystrom','C-Road','Cabazon','Calabasas','Calexico','California City','Calimesa','Calipatria','Calistoga','Calwa','Camarillo','Cambria','Cambrian Park','Cameron Park','Camp Pendleton North','Camp Pendleton South','Campbell','Cantua Creek','Canyon Lake','Canyondam','Capitola','Caribou','Carlsbad','Carmel Valley Village','Carmel-by-the-Sea','Carmichael','Carpinteria','Carrick','Carson','Cartago','Caruthers','Casa Conejo','Casa de Oro-Mount Helix','Castro Valley','Castroville','Cathedral City','Cayucos','Ceres','Cerritos','Challenge-Brownsville','Channel Islands Beach','Charter Oak','Cherry Valley','Cherryland','Chester','Chico','Chilcoot-Vinton','China Lake Acres','Chinese Camp','Chino','Chino Hills','Chowchilla','Chualar','Chula Vista','Citrus','Citrus Heights','Claremont','Clayton','Clearlake','Clearlake Oaks','Clio','Cloverdale','Clovis','Clyde','Coachella','Coalinga','Cobb','Colfax','Colma','Colton','Columbia','Colusa','Commerce','Compton','Concord','Concow','Copperopolis','Corcoran','Corning','Corona','Coronado','Corralitos','Corte Madera','Costa Mesa','Cotati','Coto de Caza','Cottonwood','Country Club','Covelo','Covina','Crescent City','Crescent City North','Crescent Mills','Crest','Crestline','Crockett','Cromberg','Cudahy','Culver City','Cupertino','Cutler','Cutten','Cypress','Daly City','Dana Point','Danville','Darwin','Davis','Day Valley','Deer Park','Del Aire','Del Mar','Del Monte Forest','Del Rey','Del Rey Oaks','Del Rio','Delano','Delhi','Delleker','Denair','Derby Acres','Desert Hot Springs','Desert Shores','Desert View Highlands','Diablo','Diamond Bar','Diamond Springs','Dillon Beach','Dinuba','Discovery Bay','Dixon','Dixon Lane-Meadow Creek','Dollar Point','Dorrington','Dorris','Dos Palos','Downey','Duarte','Dublin','Ducor','Dunsmuir','Durham','Dustin Acres','Earlimart','East Blythe','East Compton','East Foothills','East Hemet','East La Mirada','East Los Angeles','East Oakdale','East                 Orosi','East Palo Alto','East Pasadena','East Porterville','East Quincy','East Richmond Heights','East San Gabriel','East Shore','East Sonora','Easton','Edgewood','Edwards AFB','El Cajon','El Centro','El Cerito_la','El Cerrito','El Dorado Hills','El Granada','El Monte','El Paso de Robles (Paso Robles)','El Rio','El Segundo','El Sobrante','El Verano','Eldridge','Elk Grove','Elkhorn','Elmira','Emerald Lake Hills','Emeryville','Empire','Encinitas','Escalon','Escondido','Esparto','Etna','Eureka','Exeter','Fair Oaks','Fairbanks Ranch','Fairfax','Fairfield','Fairview','Fall River Mills','Fallbrook','Farmersville','Farmington','Fellows','Felton','Ferndale','Fetters Hot Springs-Agua Caliente','Fillmore','Firebaugh','Florence-Graham','Florin','Folsom','Fontana','Foothill Farms','Foothill Ranch','Ford City','Forest Meadows','Foresthill','Forestville','Fort Bragg','Fort Jones','Fortuna','Foster City','Fountain Valley','Fowler','Frazier Park','Freedom','Fremont','French Camp','French Gulch','Fresno','Friant','Fruitdale','Fullerton','Furnace Creek','Galt','Garden Acres','Garden Grove','Gardena','Gazelle','Georgetown','Gerber-Las Flores','Gilroy','Glen Avon','Glen Ellen','Glendale','Glendora','Gold River','Golden Hills','Goleta','Gonzales','Goshen','Graeagle','Grand Terrace','Granite Bay','Granite Hills','Grass Valley','Graton','Grayson','Green Valley','Greenfield','Greenhorn','Greenview','Greenville','Grenada','Gridley','Groveland-Big Oak Flat','Grover Beach','Guadalupe','Guerneville','Gustine','Hacienda Heights','Half Moon Bay','Hamilton Branch','Hamilton City','Hanford','Harbison Canyon','Hawaiian Gardens','Hawthorne','Hayfork','Hayward','Healdsburg','Heber','Hemet','Hercules','Hermosa Beach','Hesperia','Hickman','Hidden Hills','Hidden Meadows','Hidden Valley Lake','Highgrove','Highland','Highlands-Baywood Park','Hillsborough','Hilmar-Irwin','Hollister','Holtville','Home Garden','Home Gardens','Homeland','Homewood Canyon-Valley Wells','Hornbrook','Hughson','Humboldt Hill','Huntington Beach','Huntington Park','Huron','Hydesville','Idyllwild-Pine Cove','Imperial','Imperial Beach','Independence','Indian Falls','Indian Wells','Indio','Industry','Inglewood','Interlaken','Inverness','Inyokern','Ione','Iron Horse','Irvine','Irwindale','Isla Vista','Isleton','Ivanhoe','Jackson','Jamestown','Jamul','Johannesburg','Johnsville','Joshua Tree','Julian','Keddie','Keeler','Keene','Kelseyville','Kennedy','Kensington','Kentfield','Kerman','Kernville','Kettleman City','Keyes','King City','Kings Beach','Kingsburg','Kirkwood','Klamath','Knightsen','La Canada Flintridge','La Crescenta-Montrose','La Habra','La Habra Heights','La Mesa','La Mirada','La Palma','La Porte','La Presa','La Puente','La Quinta','La Riviera','La Verne','Ladera Heights','Lafayette','Laguna','Laguna Beach','Laguna Hills','Laguna Niguel','Laguna West-Lakeside','Laguna Woods','Lagunitas-Forest Knolls','Lake Almanor Country Club','Lake Almanor Peninsula','Lake Almanor West','Lake Arrowhead','Lake Davis','Lake Elsinore','Lake Forest','Lake Isabella','Lake Los Angeles','Lake Nacimiento','Lake San Marcos','Lake Wildwood','Lake of the Pines','Lake of the Woods','Lakehead-Lakeshore','Lakeland Village','Lakeport','Lakeside','Lakeview','Lakewood','Lamont','Lanare','Lancaster','Larkfield-Wikiup','Larkspur','Las Flores','Las Lomas','Lathrop','Laton','Lawndale','Laytonville','Le Grand','Lebec','Lemon Cove','Lemon Grove','Lemoore','Lemoore Station','Lennox','Lenwood','Lewiston','Lexington Hills','Lincoln','Lincoln  Village','Linda','Linden','Lindsay','Little Grass Valley','Littlerock','Live Oak','Live Oak -CV','Livermore','Livingston','Lockeford','Lodi','Loma Linda','Loma Rica','Lomita','Lompoc','London','Lone Pine','Long Beach','Loomis','Los Alamitos','Los Alamos','Los Altos','Los Altos Hills','Los Angeles','Los Banos','Los Gatos','Los Molinos','Lost Hills','Lower Lake','Loyalton','Loyola','Lucas Valley-Marinwood','Lucerne','Lynwood','Macdoel','Madera','Madera Acres','Magalia','Malibu','Mammoth Lakes','Manhattan Beach','Manteca','Manton','March AFB','Maricopa','Marina','Marina del Rey','Mariposa','Markleeville','Martinez','Marysville','Mayflower Village','Maywood','McArthur','McCloud','McFarland','McKinleyville','McKittrick','Meadow Valley','Meadow Vista','Mecca','Meiners Oaks','Mendocino','Mendota','Menlo Park','Mentone','Merced','Mesa','Mesa Vista','Mettler','Mi-Wuk Village','Middletown','Mill Valley','Millbrae','Millville','Milpitas','Mineral','Mira Loma','Mira Monte','Mission Canyon','Mission Hills','Mission Viejo','Modesto','Mohawk Vista','Mojave','Mokelumne Hill','Mono Vista','Monrovia','Montague','Montara','Montclair','Monte Rio','Monte Sereno','Montebello','Montecito','Monterey','Monterey Park','Montgomery Creek','Moorpark','Morada','Moraga','Moreno Valley','Morgan Hill','Morongo Valley','Morro Bay','Moss Beach','Moss Landing','Mount Hebron','Mount Shasta','Mountain Mesa','Mountain Ranch','Mountain View','Mountain View Acres','Mountain View_CC','Muir Beach','Murphys','Murrieta','Murrieta Hot Springs','Muscoy','Myrtletown','Napa','National City','Nebo Center','Needles','Nevada City','Newark','Newman','Newport Beach','Newport Coast','Nice','Niland','Nipomo','Norco','North Auburn','North Edwards','North El Monte','North Fair Oaks','North Highlands','North Lakeport','North Woodbridge','Norwalk','Novato','Nuevo','Oak Park','Oak View','Oakdale','Oakhurst','Oakland','Oakley','Occidental','Oceano','Oceanside','Ocotillo','Oildale','Ojai','Olancha','Olivehurst','Ontario','Onyx','Opal Cliffs','Orange','Orange Cove','Orangevale','Orcutt','Orinda','Orland','Orosi','Oroville','Oroville East','Oxnard','Pacheco','Pacific Grove','Pacifica','Pajaro','Palermo','Palm Desert','Palm Springs','Palmdale','Palo Alto','Palo Cedro','Palo Verde','Palos Verdes Estates','Paradise','Paramount','Parksdale','Parkway-South Sacramento','Parkwood','Parlier','Pasadena','Patterson','Paxton','Pearsonville','Pedley','Penn Valley','Perris','Petaluma','Phoenix Lake-Cedar Ridge','Pico Rivera','Piedmont','Pine Hills','Pine Mountain Club','Pine Valley','Pinole','Piru','Pismo Beach','Pittsburg','Pixley','Placentia','Placerville','Planada','Pleasant Hill','Pleasanton','Plumas Eureka','Plymouth','Point Arena','Point Reyes Station','Pollock Pines','Pomona','Poplar-Cotton Center','Port Costa','Port Hueneme','Porterville','Portola','Portola Hills','Portola Valley','Poway','Prattville','Prunedale','Quail Valley','Quartz Hill','Quincy','Rail Road Flat','Rainbow','Raisin City','Ramona','Rancho Calaveras','Rancho Cordova','Rancho Cucamonga','Rancho Mirage','Rancho Murieta','Rancho Palos Verdes','Rancho San Diego','Rancho Santa Fe','Rancho Santa Margarita','Rancho Tehama Reserve','Randsburg','Red Bluff','Redding','Redlands','Redondo Beach','Redway','Redwood City','Reedley','Rialto','Richgrove','Richmond','Ridgecrest','Ridgemark','Rio Dell','Rio Linda','Rio Vista','Rio del Mar','Ripon','Riverbank','Riverdale','Riverdale Park','Riverside','Rocklin','Rodeo','Rohnert Park','Rolling Hills','Rolling Hills Estates','Rollingwood','Romoland','Rosamond','Rosedale','Roseland','Rosemead','Rosemont','Roseville','Ross','Rossmoor','Round Mountain','Round Valley','Rowland Heights','Rubidoux','Running Springs','Sacramento','Salida','Salinas','Salton City','Salton Sea Beach','San Andreas','San Anselmo','San Antonio Heights','San Ardo','San Bernardino','San Bruno','San Carlos','San Clemente','San Diego','San Diego Country Estates','San Dimas','San Fernando','San Francisco','San Gabriel','San Geronimo','San Jacinto','San Joaquin','San Joaquin Hills','San Jose','San Juan Bautista','San Juan Capistrano','San Leandro','San Lorenzo','San Lucas','San Luis Obispo','San Marcos','San Marino','San Martin','San Mateo','San Miguel','San Pablo','San Rafael','San Ramon','Sand City','Sanger','Santa Ana','Santa Barbara','Santa Clara','Santa Clarita','Santa Cruz','Santa Fe Springs','Santa Maria','Santa Monica','Santa Paula','Santa Rosa','Santa Venetia','Santa Ynez','Santee','Saratoga','Sausalito','Scotts Valley','Seal Beach','Searles Valley','Seaside','Sebastopol','Sedco Hills','Seeley','Selma','Seven Trees','Shackelford','Shafter','Shandon','Shasta Lake','Shaver Lake','Shingle Springs','Shingletown','Shoshone','Sierra Madre','Signal Hill','Simi Valley','Solana Beach','Soledad','Solvang','Sonoma','Sonora','Soquel','Soulsbyville','South Dos Palos','South El Monte','South Gate','South Lake Tahoe','South Oroville','South Pasadena','South San Francisco','South San Gabriel','South San Jose Hills','South Taft','South Whittier','South Woodbridge','South Yuba City','Spreckels','Spring Garden','Spring Valley','Springville','Squaw Valley','Squirrel Mountain Valley','St. Helena','Stallion Springs','Stanford','Stanton','Stinson Beach','Stockton','Storrie','Stratford','Strathmore','Strawberry','Suisun City','Summerland','Sun City','Sunnyside-Tahoe City','Sunnyslope','Sunnyvale','Sunol','Sunol-Midtown','Susanville','Sutter','Sutter Creek','Taft','Taft Heights','Taft Mosswood','Tahoe Vista','Talmage','Tamalpais-Homestead Valley','Tara Hills','Taylorsville','Tecopa','Tehachapi','Tehama','Temecula','Temelec','Temple City','Templeton','Tennant','Terra Bella','Thermalito','Thousand Oaks','Thousand Palms','Three Rivers','Tiburon','Tierra Buena','Tipton','Tobin','Tomales','Toro Canyon','Torrance','Tracy','Tranquillity','Traver','Trinidad','Truckee','Tulare','Tulelake','Tuolumne City','Tupman','Turlock','Tustin','Tustin Foothills','Twain','Twain Harte','Twentynine Palms','Twentynine Palms Base','Twin Lakes','Ukiah','Union City','Upland','Upper Lake','Vacaville','Val Verde','Valinda','Valle Vista','Vallecito','Vallejo','Valley Acres','Valley Center','Valley Ranch','Valley Springs','Vandenberg AFB','Vandenberg Village','Ventura','Vernon','Victorville','View Park-Windsor Hills','Villa Park','Vincent','Vine Hill','Vineyard','Visalia','Vista','Waldon','Wallace','Walnut','Walnut Creek','Walnut Grove','Walnut Park','Wasco','Waterford','Watsonville','Weaverville','Weed','Weedpatch','Weldon','West Athens','West Bishop','West Carson','West Compton','West Covina','West Hollywood','West Menlo Park','West Modesto','West Point','West Puente Valley','West Sacramento','West Whittier-Los Nietos','Westhaven-Moonstone','Westlake Village','Westley','Westminster','Westmont','Westmorland','Westwood','Wheatland','Whitehawk','Whittier','Wildomar','Wilkerson','Williams','Willits','Willow Creek','Willowbrook','Willows','Wilton','Winchester','Windsor','Winter Gardens','Winterhaven','Winters','Winton','Wofford Heights','Woodacre','Woodcrest','Woodlake','Woodland','Woodside','Woodville','Wrightwood','Yorba Linda','Yosemite Lakes','Yosemite Valley','Yountville','Yreka','Yuba City','Yucaipa','Yucca Valley');
               


/* Event Functions */

// Add an event to the obj given
// event_name refers to the event trigger, without the "on", like click or mouseover
// func_name refers to the function callback when event is triggered
function addEvent(obj,event_name,func_name){
	if (obj.attachEvent){
		obj.attachEvent("on"+event_name, func_name);
	}else if(obj.addEventListener){
		obj.addEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = func_name;
	}
}

// Removes an event from the object
function removeEvent(obj,event_name,func_name){
	if (obj.detachEvent){
		obj.detachEvent("on"+event_name,func_name);
	}else if(obj.removeEventListener){
		obj.removeEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = null;
	}
}

// Stop an event from bubbling up the event DOM
function stopEvent(evt){
	evt || window.event;
	if (evt.stopPropagation){
		evt.stopPropagation();
		evt.preventDefault();
	}else if(typeof evt.cancelBubble != "undefined"){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	return false;
}

// Get the obj that starts the event
function getElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.currentTarget;
	}
}
// Get the obj that triggers off the event
function getTargetElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.target;
	}
}
// For IE only, stops the obj from being selected
function stopSelect(obj){
	if (typeof obj.onselectstart != 'undefined'){
		addEvent(obj,"selectstart",function(){ return false;});
	}
}

/*    Caret Functions     */

// Get the end position of the caret in the object. Note that the obj needs to be in focus first
function getCaretEnd(obj){
	if(typeof obj.selectionEnd != "undefined"){
		return obj.selectionEnd;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToEnd",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
// Get the start position of the caret in the object
function getCaretStart(obj){
	if(typeof obj.selectionStart != "undefined"){
		return obj.selectionStart;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToStart",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
// sets the caret position to l in the object
function setCaret(obj,l){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(l,l);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',l);
		m.collapse();
		m.select();
	}
}
// sets the caret selection from s to e in the object
function setSelection(obj,s,e){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(s,e);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',s);
		m.moveEnd('character',e);
		m.select();
	}
}

/*    Escape function   */
String.prototype.addslashes = function(){
	return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
/* --- Escape --- */

/* Offset position from top of the screen */
function curTop(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return toreturn;
}
function curLeft(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return toreturn;
}
/* ------ End of Offset function ------- */

/* Types Function */

// is a given input a number?
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

/* Object Functions */

function replaceHTML(obj,text){
	while(el = obj.childNodes[0]){
		obj.removeChild(el);
	};
	obj.appendChild(document.createTextNode(text));
}

function actb(obj,ca){
	/* ---- Public Variables ---- */
	this.actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
	this.actb_lim = 10;    // Number of elements autocomplete can show (-1: no limit)
	this.actb_firstText = true; // should the auto complete be limited to the beginning of keyword?
	this.actb_mouse = true; // Enable Mouse Support
	this.actb_delimiter = new Array(';',',');  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
	this.actb_startcheck = 1; // Show widget only after this number of characters is typed in.
	/* ---- Public Variables ---- */

	/* --- Styles --- */
	this.actb_bgColor = '#FFFFFF';
	this.actb_textColor = '#000000';
	this.actb_hColor = '#BCD6BA';
	this.actb_fFamily = 'Verdana';
	this.actb_fSize = '11px';
	this.actb_hStyle = 'text-decoration:underline;font-weight="bold"';
	/* --- Styles --- */

	/* ---- Private Variables ---- */
	var actb_delimwords = new Array();
	var actb_cdelimword = 0;
	var actb_delimchar = new Array();
	var actb_display = false;
	var actb_pos = 0;
	var actb_total = 0;
	var actb_curr = null;
	var actb_rangeu = 0;
	var actb_ranged = 0;
	var actb_bool = new Array();
	var actb_pre = 0;
	var actb_toid;
	var actb_tomake = false;
	var actb_getpre = "";
	var actb_mouse_on_list = 1;
	var actb_kwcount = 0;
	var actb_caretmove = false;
	this.actb_keywords = new Array();
	/* ---- Private Variables---- */
	
	this.actb_keywords = ca;
	var actb_self = this;

	actb_curr = obj;
	
	addEvent(actb_curr,"focus",actb_setup);
	function actb_setup(){
		addEvent(document,"keydown",actb_checkkey);
		addEvent(actb_curr,"blur",actb_clear);
		addEvent(document,"keypress",actb_keypress);
	}

	function actb_clear(evt){
		if (!evt) evt = event;
		removeEvent(document,"keydown",actb_checkkey);
		removeEvent(actb_curr,"blur",actb_clear);
		removeEvent(document,"keypress",actb_keypress);
		actb_removedisp();
	}
	function actb_parse(n){
		if (actb_self.actb_delimiter.length > 0){
			var t = actb_delimwords[actb_cdelimword].trim().addslashes();
			var plen = actb_delimwords[actb_cdelimword].trim().length;
		}else{
			var t = actb_curr.value.addslashes();
			var plen = actb_curr.value.length;
		}
		var tobuild = '';
		var i;

		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}
		var p = n.search(re);
				
		for (i=0;i<p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "<font style='"+(actb_self.actb_hStyle)+"'>"
		for (i=p;i<plen+p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "</font>";
			for (i=plen+p;i<n.length;i++){
			tobuild += n.substr(i,1);
		}
		return tobuild;
	}
	function actb_generate(){
		if (document.getElementById('tat_table')){ actb_display = false;document.body.removeChild(document.getElementById('tat_table')); } 
		if (actb_kwcount == 0){
			actb_display = false;
			return;
		}
		a = document.createElement('table');
		a.cellSpacing='2px';
		a.cellPadding='1px';
              a.style.width = '240px';
              a.style.borderLeft = '1px solid #888888';
              a.style.borderTop = '1px solid #888888';
              a.style.borderRight = '1px solid #000000';
              a.style.borderBottom = '1px solid #000000';
		a.style.position='absolute';
              a.style.zindex='3';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor=actb_self.actb_bgColor;
		a.id = 'tat_table';
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_self.actb_mouse){
			a.onmouseout = actb_table_unfocus;
			a.onmouseover = actb_table_focus;
		}
		var counter = 0;
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				counter++;
				r = a.insertRow(-1);
				if (first && !actb_tomake){
					r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_pos = counter;
				}else if(actb_pre == i){
					r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_pos = counter;
				}else{
					r.style.backgroundColor = actb_self.actb_bgColor;
				}
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = actb_self.actb_fFamily;
				c.style.fontSize = actb_self.actb_fSize;
				c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick=actb_mouseclick;
					c.onmouseover = actb_table_highlight;
				}
				j++;
			}
			if (j - 1 == actb_self.actb_lim && j < actb_total){
				r = a.insertRow(-1);
				r.style.backgroundColor = actb_self.actb_bgColor;
				c = r.insertCell(-1);
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = 'arial narrow';
				c.style.fontSize = actb_self.actb_fSize;
				c.align='center';
				replaceHTML(c,'\\/');
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick = actb_mouse_down;
				}
				break;
			}
		}
		actb_rangeu = 1;
		actb_ranged = j-1;
		actb_display = true;
		if (actb_pos <= 0) actb_pos = 1;
	}
	function actb_remake(){
		document.body.removeChild(document.getElementById('tat_table'));
		a = document.createElement('table');
		a.cellSpacing='2px';
		a.cellPadding='1px';
              a.style.width = '240px';
              a.style.borderLeft = '1px solid #888888';
              a.style.borderTop = '1px solid #888888';
              a.style.borderRight = '1px solid #000000';
              a.style.borderBottom = '1px solid #000000';
		a.style.position='absolute';
              a.style.zindex='3';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor=actb_self.actb_bgColor;
		a.id = 'tat_table';
		if (actb_self.actb_mouse){
			a.onmouseout= actb_table_unfocus;
			a.onmouseover=actb_table_focus;
		}
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_rangeu > 1){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			c = r.insertCell(-1);
			c.style.color = actb_self.actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			replaceHTML(c,'/\\');
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_up;
			}
		}
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				if (j >= actb_rangeu && j <= actb_ranged){
					r = a.insertRow(-1);
					r.style.backgroundColor = actb_self.actb_bgColor;
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
					c.style.color = actb_self.actb_textColor;
					c.style.fontFamily = actb_self.actb_fFamily;
					c.style.fontSize = actb_self.actb_fSize;
					c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
					c.id = 'tat_td'+(j);
					c.setAttribute('pos',j);
					if (actb_self.actb_mouse){
						c.style.cursor = 'pointer';
						c.onclick=actb_mouseclick;
						c.onmouseover = actb_table_highlight;
					}
					j++;
				}else{
					j++;
				}
			}
			if (j > actb_ranged) break;
		}
		if (j-1 < actb_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			c = r.insertCell(-1);
			c.style.color = actb_self.actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			replaceHTML(c,'\\/');
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_down;
			}
		}
	}
	function actb_goup(){
		if (!actb_display) return;
		if (actb_pos == 1) return;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos--;
		if (actb_pos < actb_rangeu) actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_godown(){
		if (!actb_display) return;
		if (actb_pos == actb_total) return;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos++;
		if (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_movedown(){
		actb_rangeu++;
		actb_ranged++;
		actb_remake();
	}
	function actb_moveup(){
		actb_rangeu--;
		actb_ranged--;
		actb_remake();
	}

	/* Mouse */
	function actb_mouse_down(){
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos++;
		actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_mouse_up(evt){
		if (!evt) evt = event;
		if (evt.stopPropagation){
			evt.stopPropagation();
		}else{
			evt.cancelBubble = true;
		}
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos--;
		actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_mouseclick(evt){
		if (!evt) evt = event;
		if (!actb_display) return;
		actb_mouse_on_list = 0;
		actb_pos = this.getAttribute('pos');
		actb_penter();
	}
	function actb_table_focus(){
		actb_mouse_on_list = 1;
	}
	function actb_table_unfocus(){
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_table_highlight(){
		actb_mouse_on_list = 1;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos = this.getAttribute('pos');
		while (actb_pos < actb_rangeu) actb_moveup();
		while (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	/* ---- */

	function actb_insertword(a){
		if (actb_self.actb_delimiter.length > 0){
			str = '';
			l=0;
			for (i=0;i<actb_delimwords.length;i++){
				if (actb_cdelimword == i){
					prespace = postspace = '';
					gotbreak = false;
					for (j=0;j<actb_delimwords[i].length;++j){
						if (actb_delimwords[i].charAt(j) != ' '){
							gotbreak = true;
							break;
						}
						prespace += ' ';
					}
					for (j=actb_delimwords[i].length-1;j>=0;--j){
						if (actb_delimwords[i].charAt(j) != ' ') break;
						postspace += ' ';
					}
					str += prespace;
					str += a;
					l = str.length;
					if (gotbreak) str += postspace;
				}else{
					str += actb_delimwords[i];
				}
				if (i != actb_delimwords.length - 1){
					str += actb_delimchar[i];
				}
			}
			actb_curr.value = str;
			setCaret(actb_curr,l);
		}else{
			actb_curr.value = a;
		}
		actb_mouse_on_list = 0;
		actb_removedisp();
	}
	function actb_penter(){
		if (!actb_display) return;
		actb_display = false;
		var word = '';
		var c = 0;
		for (var i=0;i<=actb_self.actb_keywords.length;i++){
			if (actb_bool[i]) c++;
			if (c == actb_pos){
				word = actb_self.actb_keywords[i];
				break;
			}
		}
		actb_insertword(word);
		l = getCaretStart(actb_curr);
	}
	function actb_removedisp(){
		if (actb_mouse_on_list==0){
			actb_display = 0;
			if (document.getElementById('tat_table')){ document.body.removeChild(document.getElementById('tat_table')); }
			if (actb_toid) clearTimeout(actb_toid);
		}
	}
	function actb_keypress(e){
		if (actb_caretmove) stopEvent(e);
		return !actb_caretmove;
	}
	function actb_checkkey(evt){
		if (!evt) evt = event;
		a = evt.keyCode;
		caret_pos_start = getCaretStart(actb_curr);
		actb_caretmove = 0;
		switch (a){
			case 38:
				actb_goup();
				actb_caretmove = 1;
				return false;
				break;
			case 40:
				actb_godown();
				actb_caretmove = 1;
				return false;
				break;
			case 13: case 9:
				if (actb_display){
					actb_caretmove = 1;
					actb_penter();
					return false;
				}else{
					return true;
				}
				break;
			default:
				setTimeout(function(){actb_tocomplete(a)},50);
				break;
		}
	}

	function actb_tocomplete(kc){
		if (kc == 38 || kc == 40 || kc == 13) return;
		var i;
		if (actb_display){ 
			var word = 0;
			var c = 0;
			for (var i=0;i<=actb_self.actb_keywords.length;i++){
				if (actb_bool[i]) c++;
				if (c == actb_pos){
					word = i;
					break;
				}
			}
			actb_pre = word;
		}else{ actb_pre = -1};
		
		if (actb_curr.value == ''){
			actb_mouse_on_list = 0;
			actb_removedisp();
			return;
		}
		if (actb_self.actb_delimiter.length > 0){
			caret_pos_start = getCaretStart(actb_curr);
			caret_pos_end = getCaretEnd(actb_curr);
			
			delim_split = '';
			for (i=0;i<actb_self.actb_delimiter.length;i++){
				delim_split += actb_self.actb_delimiter[i];
			}
			delim_split = delim_split.addslashes();
			delim_split_rx = new RegExp("(["+delim_split+"])");
			c = 0;
			actb_delimwords = new Array();
			actb_delimwords[0] = '';
			for (i=0,j=actb_curr.value.length;i<actb_curr.value.length;i++,j--){
				if (actb_curr.value.substr(i,j).search(delim_split_rx) == 0){
					ma = actb_curr.value.substr(i,j).match(delim_split_rx);
					actb_delimchar[c] = ma[1];
					c++;
					actb_delimwords[c] = '';
				}else{
					actb_delimwords[c] += actb_curr.value.charAt(i);
				}
			}

			var l = 0;
			actb_cdelimword = -1;
			for (i=0;i<actb_delimwords.length;i++){
				if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length){
					actb_cdelimword = i;
				}
				l+=actb_delimwords[i].length + 1;
			}
			var ot = actb_delimwords[actb_cdelimword].trim(); 
			var t = actb_delimwords[actb_cdelimword].addslashes().trim();
		}else{
			var ot = actb_curr.value;
			var t = actb_curr.value.addslashes();
		}
		if (ot.length == 0){
			actb_mouse_on_list = 0;
			actb_removedisp();
		}
		if (ot.length < actb_self.actb_startcheck) return this;
		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}

		actb_total = 0;
		actb_tomake = false;
		actb_kwcount = 0;
		for (i=0;i<actb_self.actb_keywords.length;i++){
			actb_bool[i] = false;
			if (re.test(actb_self.actb_keywords[i])){
				actb_total++;
				actb_bool[i] = true;
				actb_kwcount++;
				if (actb_pre == i) actb_tomake = true;
			}
		}

		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
		actb_generate();
	}
	return this;
}