//city help
var searchid=1;
function searchHelp(search,e){
	if (document.getElementById('cuvcheie').value.length>=3){
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		//alert (keycode);
		if (keycode==40){
			//alert(keycode);
			if (searchid==1){
				document.getElementById('search1').style.borderBottom='1px solid #69860F';
				document.getElementById('cuvcheie').value=document.getElementById('search1').innerHTML;
				return searchid=searchid+1;
			} else {
				var current='';
				var last='';
				current='search'+searchid;
				a=searchid-1;
				last='search'+a;
				//alert (current);alert (last);
				if (document.getElementById(current)){
					document.getElementById('cuvcheie').value=document.getElementById(current).innerHTML;
					document.getElementById(last).style.borderBottom='';
					document.getElementById(current).style.borderBottom='1px solid #69860F';
					return searchid=searchid+1;
				} else {
					document.getElementById(last).style.borderBottom='';
					document.getElementById('search1').style.borderBottom='1px solid #69860F';
					document.getElementById('cuvcheie').value=document.getElementById('search1').innerHTML;
					return searchid=2;
				}
			}
		} else if (keycode==38){
			//alert (keycode)
			if (searchid==1){
				document.getElementById('search1').style.borderBottom='';
				return searchid=1;
			} else {
				var current='';
				var last='';
				a=searchid-2;
				current='search'+a;
				a=searchid-1;
				last='search'+a;
				//alert (current);alert (last);
				if (document.getElementById(current)){
					document.getElementById('cuvcheie').value=document.getElementById(current).innerHTML;
					document.getElementById(last).style.borderBottom='';
					document.getElementById(current).style.borderBottom='1px solid #69860F';
					return searchid=searchid-1;
				} else {
					document.getElementById('search1').style.borderBottom='';
					document.getElementById('cuvcheie').value=document.getElementById('search1').innerHTML;
					return searchid=1;
				}
			}
		} else {
			var xmlHttpReq = false;
		    // Mozilla/Safari
		    if (window.XMLHttpRequest) {
		    	xmlHttpReq = new XMLHttpRequest();
		    }
		    // IE
		    else if (window.ActiveXObject) {
		    	xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		    }
		    xmlHttpReq.open('GET', '/ajax_search_help.php?search='+search, true);
		  	xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		 	xmlHttpReq.onreadystatechange = function() {
			    if (xmlHttpReq.readyState == 4) {
			        var str = xmlHttpReq.responseText
			        if (str!='no'){
						document.getElementById('search_help').innerHTML=str;
						document.getElementById('search_help').style.display='block';
						//alert(document.getElementById('city_help').innerHTML);
			        } else {
			        	document.getElementById('search_help').style.display='none';
			        }
			    }
		    }
		    xmlHttpReq.send(null);
		}
	}
}
function searchHelpClick(search){
	search=search.replace("_"," ");
	document.getElementById('cuvcheie').value=search;
	document.getElementById('search_help').style.display='none';
}
function searchDropReverse(e){
	//alert('a');
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	if (keycode==0){
		document.getElementById('cuvcheie').focus();
	}
}