var field='';
var urlap='';
function GetXmlHttpObject(){
	var xmlHttp = null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
	

function showHint(urlap, str, init, id, field, file) {
	if (str.length == 0) { 
		//document.getElementById("time").value = "";
		return;
	}
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url = "inc/" + file +".php?"+id+"="+str;
	window.field = field;
	window.urlap = urlap;
	xmlHttp.onreadystatechange = new Function("stateChanged("+init+")");
	xmlHttp.open("POST", url, true);
	xmlHttp.send(null);
}
	
//berakja az optiont
function insertOption(text, value){
	var y=document.createElement('option');
	y.text=text;
	y.value=value;
	var x=document.getElementById(field);
	try{
		x.add(y,null); // standards compliant
	}
	catch(ex){
		x.add(y); // IE only
	}
}

function stateChanged(init){ 
	if (xmlHttp.readyState==4){

		t = xmlHttp.responseText;
		
		sorok = t.split('||');
		var i=0;
		var z=document.getElementById(field).length;
		
		while(i<=z){
			i=i+1;
			var x=document.getElementById(field);
			x.remove('0');
		}
		
		insertOption(' ', 0);
		for (sor in sorok){
			if(sor > 0){
			ertekek = sorok[sor].split('**');
			insertOption(ertekek[1], ertekek[0]);
			//alert(ertekek[0]);
			}
		}
		
		if (init) {
			var x=document.getElementById(field);

			for (i=0;i<x.length;i++)
			{
				if (x.options[i].value == field) {
					x.options[i].selected = true;
				}
			}
		}
		ready = true;
	}
}