var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
  try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function loadFragmentInToElement(fragment_url, element_id) {
    var element = document.getElementById(element_id);
    element.innerHTML = 'Loading ...';
    xmlhttp.open("GET", fragment_url);
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      element.innerHTML = xmlhttp.responseText;
      }
    }
    xmlhttp.send(null);
} 


function construct_line(){
var airportel=document.getElementById('airport');
var airportselidx=airportel.selectedIndex;
airport=airportel.options[airportselidx].value;
//alert(airport);
sd=document.getElementById('sDate').value + '+' + document.getElementById('sHour').value + ':' + document.getElementById('sMinute').value;
ed=document.getElementById('eDate').value + '+' + document.getElementById('eHour').value + ':' + document.getElementById('eMinute').value;
//alert(ms.sDate);
var gate = document.getElementById('gate');
var line='GeometryFromText(\'LINESTRING(';
	for(var i=1; i<map_x.length; i++){
		line+=parseInt(map_x[i-1]) +' '+ parseInt((map_y[i-1])) +',';
	}
	line+=parseInt(map_x[map_x.length-1]) +' '+ parseInt((map_y[map_x.length-1]))+')\',-1)';
	//alert(line);
	//return line;
	var url="../scripts/gate_simple.php?";
	url+="geom="+line+"&sdate="+sd+"&edate="+ed+"&airport="+airport;
	//alert(url);
    gate.innerHTML = 'Loading ....';
    xmlhttp.open("GET", url);
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	  var s=xmlhttp.responseText.split("-----");
      gate.innerHTML = s[0];
	  //	new xTooltipGroup(['gate'], 'tip', 'top', -75, -45,[s[1]]);
		
      }
    }
    xmlhttp.send(null);
	//document.getElementById('gate').innerHTML=url;
}

function geocode() {
var gr=document.getElementById("geocode_results");
var address = document.getElementById("address").value;
var statuselement = document.getElementById("statuselement");
var url="../scripts/pg_geocode.php?";
url += address;

gr.innerHTML = 'Loading ...';
    xmlhttp.open("GET", url);
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	  var s=xmlhttp.responseText.split("-----");
      gr.innerHTML = s[0];
	  if (parseInt(s[1])>0){
	  geocode_x=parseInt(s[1]);parseInt(geocode_y=s[2]);
	  document.getElementById("address").value=s[3].substring(1,50);
	  b_setExtentFromRadius(parseInt(s[1]),parseInt(s[2]),8000);b_draw();
	  //	main.sync();
		//legend.sync();
		}
      }
    }
    xmlhttp.send(null);
}