//alert("2nd");
// Don't pass in anything other than strings or nodes.
function $(o) {
	if (typeof(o) == "string")
		return document.getElementById(o)
	else
		return o;
}

DOM = {
	// Remove all the children of the given node
	nuke: function(id){
		var o=$(id); if (!o) return;
		while(0 < o.childNodes.length)
			o.removeChild(o.childNodes[0]);
	},
	
	before: function(id, node, nodeType){
		var o=$(id); if (!o) return;
		if (typeof(node) == "string"){
			var newNode = document.createElement(nodeType || "div")
			newNode.innerHTML = node
			node = newNode
		}
		o.parentNode.insertBefore(node, o)
	},
	
	after: function(id, node, nodeType){
		var o=$(id); if (!o) return;
		if (typeof(node) == "string"){
			var newNode = document.createElement(nodeType || "div")
			newNode.innerHTML = node
			node = newNode
		}
		o.parentNode.insertBefore(node, o.nextSibling)
	},
	
	// Sets the visibility of the given node
	set_visible: function(id,visible){
		if (visible) Display.show(id); else Display.hide(id)
	},
	
	// Hides the given node by setting CSS display: none
	hide: function(id){Display.show(id, "none")},
	// Displays the given node by clearing the CSS display property
	// This resets display: to the default value for that element type
	show: function(id, style){
		var o=$(id); if (!o) return;
		o.style.display = style || "";
	},
		
	// Toggle the visibility of the given node
	toggle: function(id){
		var o=$(id); if (!o) return;
		(o.style.display == "none") ? Display.show(o) : Display.hide(o)
	},
	
	// Enables the given node (useful for form elements.)
	enable: function(id){
		var o=$(id); if (!o) return;
		o.disabled="";
	},
		
	// Disables the given node (useful for form elements.)
	disable: function(id){
		var o=$(id); if (!o) return;
		o.disabled="disabled";
	},
	
	background: function(id, color){
		var o=$(id); if (!o) return;
		o.style.background=color
	}
}

function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;	
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#mydialog").height();
	var popupWidth = $("#mydialog").width();
	//centering
	$("#mydialog").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#background-dialog").css({
		"height": windowHeight
	});
}
var 	popupStatus = 1;

function callDepart(ftype){
	centerPopup();
	document.getElementById('fld').value=ftype;
	document.getElementById("acountry").selectedIndex='';
	document.getElementById("country").selectedIndex='';
	document.getElementById('searchby').style.display='none';
	$("#mydialog").fadeIn("slow");
	//document.getElementById('background-dialog').style.display='block';
	$("#background-dialog").css({
			"opacity": "0.7"
	 });
	$("#background-dialog").fadeIn("slow");
	popupStatus = 1;
}

function post_value(value2,fieldvalue){
      var fldValue=document.getElementById('fld').value;
      document.getElementById(fieldvalue).value=value2;	  
	  $("#mydialog").fadeOut("slow");
	  $("#background-dialog").fadeOut("slow");
	  if(fieldvalue == "StartAirp_input"){
		$("#StartAirp_label").hide();	  
	 }else{
		$("#EndAirp_label").hide();	   
	 }
	  
	  
	  
	  popupStatus = 0;
  
}

function closeMe(){
	$("#mydialog").fadeOut("slow");
	$("#background-dialog").fadeOut("slow");
	popupStatus = 0;
}


function dialogHandler(e) {
      var kC  = (window.event) ?    // MSIE or Firefox?
                 event.keyCode : e.keyCode;
      var Esc = (window.event) ?   
                27 : e.DOM_VK_ESCAPE // MSIE : Firefox
      if(kC==Esc && popupStatus == 1){        
		$("#mydialog").fadeOut("slow");
		$("#background-dialog").fadeOut("slow");
		popupStatus = 0;
	  }
   }



function getlocation(str,tag,fieldvalue)
{
	window.location="airportcode.php?fld="+fieldvalue+"&filter="+str+"&tag="+tag;
}

