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=no,menubar=yes,toolbar=yes");
    if (!newWinCarrier.opener)
      {
        newWinCarrier.opener = window;
      }
  }
  else
  {
      newWinCarrier.focus();
  }
}

function Search_Flts()
{  
  if (( document.Main.DPT_Date.value != '' && document.Main.RET_Date.value == '') || (document.Main.DPT_Date.value != '' && document.Main.RET_Date.value != '') )
  {
    if ( Valid_Dates() )
    {
      document.forms[0].target="Results";
      document.forms[0].action = "htmapsnn.asp";
	    document.forms[0].submit();
	  }
	}
	else
	{
		
	  document.forms[0].target="Results";
    document.forms[0].action = "htmapsnn.asp";
	  document.forms[0].submit();
	  //Debug:
	  //alert('DPT_Date.value= ' + document.Main.DPT_Date.value + '   RET_Date.value= ' + document.Main.RET_Date.value);
	}  
}

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] ;
	}
	else
	{
	  DPT_YYMMDD = todayDate;
	}

	if ( document.Main.RET_Date.value != '' )
	{
	  DateArray = document.Main.RET_Date.value.split('-');
	  RTN_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];
	}
	else
	{
	  RTN_YYMMDD = (todayDate - 1);
	}
	//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 )
	  {
	  	
	  if (document.Main.One_Way.checked == 0)
    {
    	 alert ("Please select a valid return date.");
	   	 
	    	return false;
    }
    else
  	{
  			
	    	return true;
  	}
	  
	  }
	  else
	  {
	  	
	  
	    return true; 
	  }	  
	}
}

function SetControlsVisibilityValues()
{
	if (document.Main.One_Way.checked == 0)
    {
    	document.Main.One_Way.value="Off";
	   	 document.getElementById("divReturnDateLabel").style.visibility="visible"
	    	document.getElementById("divReturnDateCalendar").style.visibility="visible"
	    	document.getElementById("divReturnDateTextBox").style.visibility="visible"
	    	
    }
    else
  	{
  		document.Main.One_Way.value="On";
  		document.getElementById("divReturnDateLabel").style.visibility="hidden"
	    	document.getElementById("divReturnDateCalendar").style.visibility="hidden"
	    	document.getElementById("divReturnDateTextBox").style.visibility="hidden"
	    	
  	}
}


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'].RET_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'].RET_Date.value = parent.Search.document.forms['Main'].DPT_Date.value;
    }
  }
        
  if ( dpt == 'ret') parent.Search.document.forms['Main'].RET_Date.value = newdate;
  
  parent.Search.document.forms['Main'].target="Results";
  parent.Search.document.forms['Main'].action = "htmapsnn.asp";
	parent.Search.document.forms['Main'].submit();
}

function Re_Submit_Form()
{
	if(document.Main.One_Way.checked==1)
	{
   	document.Main.hidDirectsOnlyAndOneWaySelected.value="on";
  }
  document.forms[0].target="Search";
  document.forms[0].action = "SNN_Search.asp";
  document.forms[0].submit();
  
}

function Switch_Image(img_name,img_src)
{
  document[img_name].src=img_src;
}