// JavaScript Document// JavaScript Document
var divAC=document.getElementById("divAutoComplete");
var xmlhttp;
var departures = "<a style='color:red' onclick='divAC.style.visibility=&quot;hidden&quot;;'>Κλείσιμο</a><br><a id='603' onclick='setValue(&quot;departure&quot;, &quot;ΗΡΑΚΛΕΙΟ(ΣΤ.ΛΙΜ)&quot;, 603);'>ΗΡΑΚΛΕΙΟ(ΣΤ.ΛΙΜ)</a><br /><a id='867' onclick='setValue(&quot;departure&quot;, &quot;ΑΓ.ΝΙΚΟΛΑΟΣ&quot;, 867);'>ΑΓ.ΝΙΚΟΛΑΟΣ</a><br /><a id='399' onclick='setValue(&quot;departure&quot;, &quot;ΡΕΘΥΜΝΟ&quot;, 399);'>ΡΕΘΥΜΝΟ</a><br /><a id='249' onclick='setValue(&quot;departure&quot;, &quot;ΧΑΝΙΑ&quot;, 249);'>ΧΑΝΙΑ</a><br /><a id='902' onclick='setValue(&quot;departure&quot;, &quot;ΙΕΡΑΠΕΤΡΑ&quot;, 902);'>ΙΕΡΑΠΕΤΡΑ</a><br /><a id='962' onclick='setValue(&quot;departure&quot;, &quot;ΣΗΤΕΙΑ&quot;, 962);'>ΣΗΤΕΙΑ</a><br /><a id='670' onclick='setValue(&quot;departure&quot;, &quot;ΑΝΩ ΑΡΧΑΝΕΣ&quot;, 670);'>ΑΝΩ ΑΡΧΑΝΕΣ</a><br /><a id='530' onclick='setValue(&quot;departure&quot;, &quot;ΜΟΙΡΕΣ&quot;, 530);'>ΜΟΙΡΕΣ</a><br /><a id='742' onclick='setValue(&quot;departure&quot;, &quot;ΚΑΣΤΕΛΙ&quot;, 742);'>ΚΑΣΤΕΛΙ</a><br /><a id='750' onclick='setValue(&quot;departure&quot;, &quot;ΑΡΚΑΛΟΧΩΡΙ&quot;, 750);'>ΑΡΚΑΛΟΧΩΡΙ</a><br />		<a id='526' onclick='setValue(&quot;departure&quot;, &quot;ΑΝΩΓΕΙΑ&quot;, 526);'>ΑΝΩΓΕΙΑ</a><br /><a id='941170' onclick='setValue(&quot;departure&quot;, &quot;ΧΕΡΣΟΝΗΣΟΣ&quot;, 941170);'>ΧΕΡΣΟΝΗΣΟΣ</a><br /><a id='782' onclick='setValue(&quot;departure&quot;, &quot;ΜΑΛΙΑ&quot;, 782);'>ΜΑΛΙΑ</a><br />";
var internationalDepartures = "<a style='color:red' onclick='divAC.style.visibility=&quot;hidden&quot;;'>Close</a><br><a id='603' onclick='setValue(&quot;departure&quot;, &quot;IRAKLIO(Port Station)&quot;, 603);'>IRAKLIO(Port Station)</a><br /><a id='867' onclick='setValue(&quot;departure&quot;, &quot;AG.NIKOLAOS&quot;, 867);'>AG.NIKOLAOS</a><br /><a id='399' onclick='setValue(&quot;departure&quot;, &quot;RETHIMNO&quot;, 399);'>RETHIMNO</a><br /><a id='249' onclick='setValue(&quot;departure&quot;, &quot;CHANIA&quot;, 249);'>CHANIA</a><br /><a id='902' onclick='setValue(&quot;departure&quot;, &quot;IERAPETRA&quot;, 902);'>IERAPETRA</a><br /><a id='962' onclick='setValue(&quot;departure&quot;, &quot;SITIA&quot;, 962);'>SITIA</a><br /><a id='670' onclick='setValue(&quot;departure&quot;, &quot;ANO ARXANES&quot;, 670);'>ANO ARXANES</a><br /><a id='530' onclick='setValue(&quot;departure&quot;, &quot;MIRES&quot;, 530);'>MIRES</a><br /><a id='742' onclick='setValue(&quot;departure&quot;, &quot;KASTELI&quot;, 742);'>KASTELI</a><br /><a id='750' onclick='setValue(&quot;departure&quot;, &quot;ARKALOXORI&quot;, 750);'>ARKALOXORI</a><br />		<a id='526' onclick='setValue(&quot;departure&quot;, &quot;ANOGIA&quot;, 526);'>ANOGIA</a><br /><a id='941170' onclick='setValue(&quot;departure&quot;, &quot;HERSONINOS&quot;, 941170);'>HERSONINOS</a><br /><a id='782' onclick='setValue(&quot;departure&quot;, &quot;MALIA&quot;, 782);'>MALIA</a><br />";
var internationalDepartures_2	 = "<a style='color:red' onclick='divAC.style.visibility=&quot;hidden&quot;;'>Close</a><br><a id='603' onclick='setValue(&quot;departure_2&quot;, &quot;IRAKLIO(Port Station)&quot;, 603);'>IRAKLIO(Port Station)</a><br /><a id='867' onclick='setValue(&quot;departure_2&quot;, &quot;ΑΓ.ΝΙΚΟΛΑΟΣ&quot;, 867);'>AG.NIKOLAOS</a><br /><a id='399' onclick='setValue(&quot;departure_2&quot;, &quot;RETHIMNO&quot;, 399);'>RETHIMNO</a><br /><a id='249' onclick='setValue(&quot;departure_2&quot;, &quot;CHANIA&quot;, 249);'>CHANIA</a><br /><a id='902' onclick='setValue(&quot;departure_2&quot;, &quot;IERAPETRA&quot;, 902);'>IERAPETRA</a><br /><a id='962' onclick='setValue(&quot;departure_2&quot;, &quot;SITIA&quot;, 962);'>SITIA</a><br /><a id='670' onclick='setValue(&quot;departure_2&quot;, &quot;ANO ARXANES&quot;, 670);'>ANO ARXANES</a><br /><a id='530' onclick='setValue(&quot;departure_2quot;, &quot;MIRES&quot;, 530);'>MIRES</a><br /><a id='742' onclick='setValue(&quot;departure_2&quot;, &quot;KASTELI&quot;, 742);'>KASTELI</a><br /><a id='750' onclick='setValue(&quot;departure_2&quot;, &quot;ARKALOXORI&quot;, 750);'>ARKALOXORI</a><br />		<a id='526' onclick='setValue(&quot;departure_2&quot;, &quot;ANOGIA&quot;, 526);'>ANOGIA</a><br /><a id='941170' onclick='setValue(&quot;departure_2&quot;, &quot;HERSONINOS&quot;, 941170);'>HERSONINOS</a><br /><a id='782' onclick='setValue(&quot;departure_2&quot;, &quot;MALIA&quot;, 782);'>MALIA</a><br />";
var internationalDestinations = "<a style='color:red' onclick='divAC.style.visibility=&quot;hidden&quot;;'>Close</a><br><a id='603' onclick='setValue(&quot;destination&quot;, &quot;IRAKLIO(Port Station)&quot;, 603);'>IRAKLIO(Port Station)</a><br /><a id='867' onclick='setValue(&quot;destination&quot;, &quot;AG.NIKOLAOS&quot;, 867);'>AG.NIKOLAOS</a><br /><a id='399' onclick='setValue(&quot;destination&quot;, &quot;RETHIMNO&quot;, 399);'>RETHIMNO</a><br /><a id='249' onclick='setValue(&quot;destination&quot;, &quot;CHANIA&quot;, 249);'>CHANIA</a><br /><a id='902' onclick='setValue(&quot;destination&quot;, &quot;IERAPETRA&quot;, 902);'>IERAPETRA</a><br /><a id='962' onclick='setValue(&quot;destination&quot;, &quot;SITIA&quot;, 962);'>SITIA</a><br /><a id='670' onclick='setValue(&quot;destination&quot;, &quot;ANO ARXANES&quot;, 670);'>ANO ARXANES</a><br /><a id='530' onclick='setValue(&quot;destination&quot;, &quot;MIRES&quot;, 530);'>MIRES</a><br /><a id='742' onclick='setValue(&quot;destination&quot;, &quot;KASTELI&quot;, 742);'>KASTELI</a><br /><a id='750' onclick='setValue(&quot;destination&quot;, &quot;ARKALOXORI&quot;, 750);'>ARKALOXORI</a><br />		<a id='526' onclick='setValue(&quot;destination&quot;, &quot;ANOGIA&quot;, 526);'>ANOGIA</a><br /><a id='941170' onclick='setValue(&quot;destination&quot;, &quot;HERSONINOS&quot;, 941170);'>HERSONINOS</a><br /><a id='782' onclick='setValue(&quot;destination&quot;, &quot;MALIA&quot;, 782);'>MALIA</a><br />";
var departures_2 = "<a style='color:red' onclick='divAC.style.visibility=&quot;hidden&quot;;'>Κλείσιμο</a><br><a id='603' onclick='setValue(&quot;departure_2&quot;, &quot;ΗΡΑΚΛΕΙΟ(ΣΤ.ΛΙΜ)&quot;, 603);'>ΗΡΑΚΛΕΙΟ(ΣΤ.ΛΙΜ)</a><br /><a id='867' onclick='setValue(&quot;departure_2&quot;, &quot;ΑΓ.ΝΙΚΟΛΑΟΣ&quot;, 867);'>ΑΓ.ΝΙΚΟΛΑΟΣ</a><br /><a id='399' onclick='setValue(&quot;departure_2&quot;, &quot;ΡΕΘΥΜΝΟ&quot;, 399);'>ΡΕΘΥΜΝΟ</a><br /><a id='249' onclick='setValue(&quot;departure_2&quot;, &quot;ΧΑΝΙΑ&quot;, 249);'>ΧΑΝΙΑ</a><br /><a id='902' onclick='setValue(&quot;departure_2&quot;, &quot;ΙΕΡΑΠΕΤΡΑ&quot;, 902);'>ΙΕΡΑΠΕΤΡΑ</a><br /><a id='962' onclick='setValue(&quot;departure_2&quot;, &quot;ΣΗΤΕΙΑ&quot;, 962);'>ΣΗΤΕΙΑ</a><br /><a id='670' onclick='setValue(&quot;departure_2&quot;, &quot;ΑΝΩ ΑΡΧΑΝΕΣ&quot;, 670);'>ΑΝΩ ΑΡΧΑΝΕΣ</a><br /><a id='530' onclick='setValue(&quot;departure_2quot;, &quot;ΜΟΙΡΕΣ&quot;, 530);'>ΜΟΙΡΕΣ</a><br /><a id='742' onclick='setValue(&quot;departure_2&quot;, &quot;ΚΑΣΤΕΛΙ&quot;, 742);'>ΚΑΣΤΕΛΙ</a><br /><a id='750' onclick='setValue(&quot;departure_2&quot;, &quot;ΑΡΚΑΛΟΧΩΡΙ&quot;, 750);'>ΑΡΚΑΛΟΧΩΡΙ</a><br />		<a id='526' onclick='setValue(&quot;departure_2&quot;, &quot;ΑΝΩΓΕΙΑ&quot;, 526);'>ΑΝΩΓΕΙΑ</a><br /><a id='941170' onclick='setValue(&quot;departure_2&quot;, &quot;ΧΕΡΣΟΝΗΣΟΣ&quot;, 941170);'>ΧΕΡΣΟΝΗΣΟΣ</a><br /><a id='782' onclick='setValue(&quot;departure_2&quot;, &quot;ΜΑΛΙΑ&quot;, 782);'>ΜΑΛΙΑ</a><br />";			
var destinations = "<a style='color:red' onclick='divAC.style.visibility=&quot;hidden&quot;;'>Κλείσιμο</a><br><a id='603' onclick='setValue(&quot;destination&quot;, &quot;ΗΡΑΚΛΕΙΟ(ΣΤ.ΛΙΜ)&quot;, 603);'>ΗΡΑΚΛΕΙΟ(ΣΤ.ΛΙΜ)</a><br /><a id='867' onclick='setValue(&quot;destination&quot;, &quot;ΑΓ.ΝΙΚΟΛΑΟΣ&quot;, 867);'>ΑΓ.ΝΙΚΟΛΑΟΣ</a><br /><a id='399' onclick='setValue(&quot;destination&quot;, &quot;ΡΕΘΥΜΝΟ&quot;, 399);'>ΡΕΘΥΜΝΟ</a><br /><a id='249' onclick='setValue(&quot;destination&quot;, &quot;ΧΑΝΙΑ&quot;, 249);'>ΧΑΝΙΑ</a><br /><a id='902' onclick='setValue(&quot;destination&quot;, &quot;ΙΕΡΑΠΕΤΡΑ&quot;, 902);'>ΙΕΡΑΠΕΤΡΑ</a><br /><a id='962' onclick='setValue(&quot;destination&quot;, &quot;ΣΗΤΕΙΑ&quot;, 962);'>ΣΗΤΕΙΑ</a><br /><a id='670' onclick='setValue(&quot;destination&quot;, &quot;ΑΝΩ ΑΡΧΑΝΕΣ&quot;, 670);'>ΑΝΩ ΑΡΧΑΝΕΣ</a><br /><a id='530' onclick='setValue(&quot;destination&quot;, &quot;ΜΟΙΡΕΣ&quot;, 530);'>ΜΟΙΡΕΣ</a><br /><a id='742' onclick='setValue(&quot;destination&quot;, &quot;ΚΑΣΤΕΛΙ&quot;, 742);'>ΚΑΣΤΕΛΙ</a><br /><a id='750' onclick='setValue(&quot;destination&quot;, &quot;ΑΡΚΑΛΟΧΩΡΙ&quot;, 750);'>ΑΡΚΑΛΟΧΩΡΙ</a><br />		<a id='526' onclick='setValue(&quot;destination&quot;, &quot;ΑΝΩΓΕΙΑ&quot;, 526);'>ΑΝΩΓΕΙΑ</a><br /><a id='941170' onclick='setValue(&quot;destination&quot;, &quot;ΧΕΡΣΟΝΗΣΟΣ&quot;, 941170);'>ΧΕΡΣΟΝΗΣΟΣ</a><br /><a id='782' onclick='setValue(&quot;destination&quot;, &quot;ΜΑΛΙΑ&quot;, 782);'>ΜΑΛΙΑ</a><br />";

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function ajax_routine(url, target_div){
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
  	{
  		alert ("Your browser does not support XMLHTTP!");
  		return;
  	}
	url = url+"&sid="+Math.random();
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	if(target_div != null){
		
		
			var elem = document.getElementById(target_div);
			elem.innerHTML = xmlhttp.responseText;
	}
}

function getXmlHttpResponse_GET(url, params){
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
  	{
  		alert ("Your browser does not support XMLHTTP!");
  		return;
  	}
	url = url+"?"+params+"&sid="+Math.random();
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	return xmlhttp.responseText;
}

function getXmlHttpResponse_POST(url, params){
	
	http=GetXmlHttpObject();
	if (http==null)
  	{
  		alert ("Your browser does not support XMLHTTP!");
  		return;
  	}
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			
			var elem = document.getElementById("divAutoComplete");
	elem.innerHTML = http.responseText;
			/*return http.responseText;*/
		}
	}
	http.send(params);
	
	//return http.responseText;
}


function getHint(value, autocomplete_div, input_id){
	//alert("get hint");
	//var url = "interface.php?value="+escape(value)+"&input_id="+input_id+"";
	var url = "interface.php?value="+value+"&input_id="+input_id+"";
	//alert(url);
	ajax_routine(url, autocomplete_div);
	/*var url = "interface.php";
	var params = "value="+value+"&input_id="+input_id+"";
 
	var response = getXmlHttpResponse_POST(url, params);
	*/
}
function getDataFromServer(url) { return "fdfdsfd njbjb jbk jbkj bk b bk  b ";
	var response="";
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
    response=xmlhttp.responseText;
	return response;
}


function setupAutoCompDiv(tbxObj)	{
	divAC=document.getElementById("divAutoComplete");
	var posX=(getXpos(tbxObj)+1);
	var posY=(getYpos(tbxObj)+23);

	//alert("X:"+posX);
	//alert("Y:"+posY);
	//alert("Before Div style left="+divAC.style.left+" and top="+divAC.style.top+"");
	divAC.style.left=posX;
	divAC.style.top=posY;
	
	divAC.style.visibility="visible";
}

function autoCompleteSelect(tbxObj, event, default_locations)
{
	
	divAC=document.getElementById("divAutoComplete");
	
	setupAutoCompDiv(tbxObj);

	var newChar=event.which;
	var tbxValue=tbxObj.value;
	var tbxId=tbxObj.id;

	if(newChar==undefined)
		newChar=event.keyCode;

	if(newChar==8)	{
		if(tbxValue.length<=1)
         	tbxValue="";
		else
			tbxValue=tbxValue.substr(0,(tbxValue.length-1));
    } else
		tbxValue=tbxValue+String.fromCharCode(newChar);

	
		divAC.innerHTML= default_locations;
	
		
}

function autoComplete(tbxObj,event, input_id)	{
	divAC=document.getElementById("divAutoComplete");
	
	divAC.innerHTML = "";
	
	setupAutoCompDiv(tbxObj);

	var newChar=event.which;
	var tbxValue=tbxObj.value;
	var tbxId=tbxObj.id;

	if(newChar==undefined)
		newChar=event.keyCode;

	if(newChar==8)	{
		if(tbxValue.length<=1)
         	tbxValue="";
		else
			tbxValue=tbxValue.substr(0,(tbxValue.length-1));
    } else
		tbxValue=tbxValue+String.fromCharCode(newChar);

	if(tbxValue.length>=2){
	//divAC.innerHTML = "shdfjhfgsfgsdh";
	getHint(tbxValue, 'divAutoComplete', input_id);
		//divAC.innerHTML=getDataFromServer("http://anobase.vectorbase.org/ir/autoComplete.php?oid="+tbxId+"&q="+tbxValue);
	}
	else
		divAC.style.visibility="hidden";
}


function getXpos(obj)	{
	var curLeft=0;
	if(obj.offsetParent)
		while(obj.offsetParent)	{
			curLeft+=obj.offsetLeft
			obj=obj.offsetParent;
    	}
    else
    	if(obj.x)
    		curLeft+=obj.x;
  return curLeft;
}

function getYpos(obj)	{
	var curTop=0;
	if(obj.offsetParent)
		while(obj.offsetParent)	{
			curTop +=obj.offsetTop
			obj=obj.offsetParent;
    	}
  	else
  		if(obj.y)
    		curTop +=obj.y;
  return curTop;
}

function setValue(tbxId,value, value_id)	{
  divAC.style.visibility="hidden";
  obj=document.getElementById(tbxId);
  obj.value=value;
  obj=document.getElementById(tbxId+"_id");
  obj.value = value_id
}