var today = new Date();
var thisMonth = today.getMonth() + 1;
var thisYear = today.getFullYear();
var thisDay = today.getDate();

if ( thisDay <= 9 ) thisDay = "0" + thisDay;
if ( thisMonth <= 9 ) thisMonth = "0" + thisMonth;

var todayDate = '' + thisYear + thisMonth + thisDay;


function ShowWindowMap()
{
  var newWinMap;
				  
  if (!newWinMap || newWinMap.closed)
  {
    newWinMap = window.open("map/index.html","MapView","width=800,height=540,left=40,top=40,resizable=yes,scrollbars=yes,status=no,location=no,menubar=no,toolbar=no");
    if (!newWinMap.opener)
        newWinMap.opener = window;
  }
  else
      newWinMap.focus();
}



function ShowWindowCarrier(as_QueryParm)
{
  var newWinCarrier;
				  
  if (!newWinCarrier || newWinCarrier.closed)
  {
    newWinCarrier = window.open("../reports/Car_Link.asp?title=Airline&" + as_QueryParm,"Carrier","width=640,height=480,left=50,top=50,resizable=yes,scrollbars=yes,status=yes,location=yes,menubar=yes,toolbar=yes");
    if (!newWinCarrier.opener)
      {
        newWinCarrier.opener = window;
      }
  }
  else
  {
      newWinCarrier.focus();
  }
}

function Search_Flts()
{  
  if ( document.Main.destination.value != '' )
  {  
    if ( document.Main.DPT_Date.value != '' )
    {
      if ( Valid_Dates() )
      {
		    document.forms[0].target = "Results";
	        document.forms[0].action = "htmapork.asp";
		    document.forms[0].submit();
	    }
	  }
	  else if ( document.Main.DPT_Date.value == '' && document.Main.RTN_Date.value == '' )
	  {
	    document.forms[0].target = "Results";
      document.forms[0].action = "htmapork.asp";
	    document.forms[0].submit();
	  }
	  else if ( document.Main.DPT_Date.value == '' && document.Main.RTN_Date.value != '' )
	  {
	  alert('Please select a valid depart date.');
	  }
	  else if ( document.Main.DPT_Date.value != '' && document.Main.RTN_Date.value == '' )
	  {
	  alert('Please select a valid return date.');
	  } 
	}
	else
	{
	  alert('Please select a destination.');
	}    
}

function Valid_Dates()
{
  DateArray = new Array();
	var DPT_YYMMDD, RTN_YYMMDD;				
	
	if ( document.Main.DPT_Date.value != '' )
	{
	  DateArray = document.Main.DPT_Date.value.split('-');
	  DPT_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];
	}
	
	if ( document.Main.RTN_Date.value != '' )
	{  
	  DateArray = document.Main.RTN_Date.value.split('-');
	  RTN_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];
	}
	else
	{
	  if ( document.Main.one_way.checked )
	  {
	    RTN_YYMMDD = '99999999';  
	  }
	  else
	  {
	    RTN_YYMMDD = '00000000';
	  }
	}	
	//Debug:
	//alert('DPT_YYMMDD = ' + DPT_YYMMDD + '   RTN_YYMMDD = ' + RTN_YYMMDD + '   todayDate = ' + todayDate);
	
	if ( DPT_YYMMDD < todayDate )
	{
	  alert ("Please select a valid depart date.");
	  return false;
	}
	else
	{
	  if ( RTN_YYMMDD < DPT_YYMMDD )
	  {
	    alert ("Please select a valid return date.");
	    return false;
	  }
	  else
	  {
	    return true; 
	  }	  
	}
}

function Update_Date(newdate,dpt)
{
  DateArray = new Array();
  var DPT_YYMMDD, RTN_YYMMDD;				
        
  DateArray = newdate.split('-');
  DPT_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];      	
        
  DateArray = parent.Search.document.forms['Main'].RTN_Date.value.split('-');
  RTN_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];
  //alert('DPT_YYMMDD = ' + DPT_YYMMDD + '   RTN_YYMMDD = ' + RTN_YYMMDD);      
  
  if ( dpt == 'dep')
  { 
    parent.Search.document.forms['Main'].DPT_Date.value = newdate;
    if ( DPT_YYMMDD > RTN_YYMMDD )
    {            
      parent.Search.document.forms['Main'].RTN_Date.value = parent.Search.document.forms['Main'].DPT_Date.value;
    }
  }
        
  if ( dpt == 'ret') parent.Search.document.forms['Main'].RTN_Date.value = newdate;
  
  parent.Search.document.forms['Main'].target="Results";
  parent.Search.document.forms['Main'].action = "htmapork.asp";
	parent.Search.document.forms['Main'].submit();
}

function Switch_Image(img_name,img_src)
{
  document[img_name].src=img_src;
}

function Focus_Destination()
{
  window.document.forms['Main'].elements['destination'].focus();        
}

/* --> Functions to place destination list: <-- */
function setLyr(obj, lyr)
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
      	
	if (lyr == 'arrival') newY = 68;
	var x = new getObj(lyr);
      	
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
}
      
function findPosX(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 findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
      	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	  curtop += obj.y;
	  return curtop;
}
		  
function getObj(name)
{
  if (document.getElementById)
  {
    this.obj = document.getElementById(name);
    this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
    this.obj = document.all[name];
    this.style = document.all[name].style;
  }
  else if (document.layers)
  {
    if (document.layers[name])
    {
      this.obj = document.layers[name];
      this.style = document.layers[name];
    }
    else
    {
      this.obj = document.layers.arrival.layers[name];
      this.style = document.layers.arrival.layers[name];
    }
  }
}