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 go_Back()
{
	document.forms[0].action = "Default.asp";
	document.forms[0].submit();
} 

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()
{  
  if ( Valid_Stations() )
  {
    if ( Valid_Dates() )
    {
      document.forms[0].action = "htmaplis.asp";
	    document.forms[0].submit();
	  }
	}
}

function Re_Submit(strHitId)
{  
	//**************************************** 
	//Rick added code on 07/28/2006 to pass in
	//HitId which creates a a query string with
	//the HitId in it. 
	//**************************************** 

	var strQryStr;
	if (null != strHitId) {
	    strHitId = trimLeftAndRight(strHitId);
	    if (null == strHitId) {
	    	//htmaplis page name 
	    	strQryStr = "htmaplis.asp";
	    } else {
	    	//Default page name and query string
			strQryStr = "htmaplis.asp" + "?HitId=" + strHitId
	    }
	}

	document.forms[0].action = strQryStr;
	document.forms[0].submit();
}

function Valid_Stations()
{
  if ( document.forms['Schedules'].dpt_station.value != "" )
  {
    if ( document.forms['Schedules'].arv_station.value != "" )
	  {
      return true;
	  }
	  else
	  {
	    document.forms['Schedules'].arv_station.focus();
	    alert ("Please select an arrival airport.");
	    return false;
	  }
	}
	else
	{
	  document.forms['Schedules'].dpt_station.focus();
	  alert ("Please select a depart airport.");
	  return false;
	}
}

function Valid_Dates()
{
  DateArray = new Array();
	var DPT_YYMMDD, RTN_YYMMDD;				
	
	DateArray = document.Schedules.DPT_Date.value.split('-');
	DPT_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];

	DateArray = document.Schedules.RET_Date.value.split('-');
	RTN_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];
	
	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,strHitId)
{
  DateArray = new Array();
	var DPT_YYMMDD, RTN_YYMMDD;				
	
	DateArray = newdate.split('-');
	DPT_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];

	DateArray = document.Schedules.RET_Date.value.split('-');
	RTN_YYMMDD = DateArray[2] + DateArray[1] + DateArray[0];
	
  if ( dpt == 'dep')
  { 
    document.forms['Schedules'].DPT_Date.value = newdate;    
    if ( DPT_YYMMDD > RTN_YYMMDD )
    {
      document.forms['Schedules'].RET_Date.value = document.forms['Schedules'].DPT_Date.value;
    }
  }
  
  if ( dpt == 'ret') document.forms['Schedules'].RET_Date.value = newdate;
  
	//**************************************** 
	//Rick added code on 07/28/2006 to pass in
	//HitId which creates a a query string with
	//the HitId in it. 
	//**************************************** 

	var strQryStr;
	if (null != strHitId) {
	    strHitId = trimLeftAndRight(strHitId);
	    if (null == strHitId) {
	    	//htmaplis page name 
	    	strQryStr = "htmaplis.asp";
	    } else {
	    	//Default page name and query string
			strQryStr = "htmaplis.asp" + "?HitId=" + strHitId
	    }
	}
	document.forms[0].action = strQryStr;
	document.forms[0].submit();
}

function Get_Stations(strPage, strQryStr)
{
	//**************************************** 
	//Rick added code on 07/27/2006 to pass in
	//HitId which is set by the COM Object. 
	//This value is passed back to the Default
	//page as a query string. 
	//**************************************** 

	var strTemp;
	if (null != strQryStr) {
	    strQryStr = trimLeftAndRight(strQryStr);
	    if (null == strQryStr) {
	    	//Default page name 
	    	strTemp = strPage;
	    } else {
	    	//Default page name and query string
			strTemp = strPage + "?HitId=" + strQryStr
	    }
	}

	document.forms[0].action = strTemp;
	document.forms[0].submit();
} 

//**************************************** 
//Rick added code on 07/27/2006 to trim
//string on the left and right. 
//**************************************** 

function trimLeftAndRight(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
