/*
 * *****************************************************************************
 * *****            Copyright (c)  2000 Unisys Corporation.                *****
 * *****                     All rights reserved.                          *****
 * *****                      UNISYS PROPRIETARY                           *****
 * *****************************************************************************
 *
 * Name: script.js
 *
 * Function: Common JavaScript functions
 *
 * Notes:
 *
 * -----------------------------------------------------------------------------
*/

// -----------------------------------------------------------------------------
// Check browser credentials
// -----------------------------------------------------------------------------

if( navigator.appName.indexOf("Netscape") != -1 ) {
	var bsNN = new Object();
    window.bsNN = bsNN;
}

if( navigator.appName.indexOf("Microsoft") != -1 ) {
	var bsIE = new Object();
    window.bsIE = bsIE;
}

// -----------------------------------------------------------------------------
// Global constants
// -----------------------------------------------------------------------------

// Max allowed number of stations
var MAX_STATIONS = 10;

// Action Code text
var ACTION_CODE = new Array();
ACTION_CODE[ "KK" ] = "Confirmed";
ACTION_CODE[ "FC" ] = "Forced booking requested by the booking controlling station";
ACTION_CODE[ "PC" ] = "Partially confirmed";
ACTION_CODE[ "LL" ] = "Waitlisted";
ACTION_CODE[ "UU" ] = "Unable, insufficient space, or special requirememnts cannot be accomodated";
ACTION_CODE[ "UN" ] = "Unable, flight does not operate";
ACTION_CODE[ "KU" ] = "This segment is confirmed, but is awaiting confirmation of the other allotment segments in the booking";
ACTION_CODE[ "RC" ] = "This segment was flight rebooked through container closure or flight finalization";
ACTION_CODE[ "PQ" ] = "Partially confirmed queued";
ACTION_CODE[ "SC" ] = "Unable due to a schedule change";
ACTION_CODE[ "QU" ] = "Queued following a force booking request of a UU booking";
ACTION_CODE[ "NS" ] = "No show, this segment of the bookings was released because no goods arrived at the terminal for this segment of the booking";
ACTION_CODE[ "SL" ] = "Waitlist status lost due to schedule change";
ACTION_CODE[ "RE" ] = "Released segment because of flight rebook process";
ACTION_CODE[ "AL" ] = "This allotment segments weight and volume has been released and is now part of a ULD plan";
ACTION_CODE[ "BL" ] = "This booking segments weight and volume has been released and is now part of a ULD plan";
ACTION_CODE[ "UL" ] = "This unconfirmed segments weight and volume has been released and is now part of a ULD plan";

// Booking Status
var BKG_STATUS = new Array();

// Status - Booked Shipment ( BS )
BKG_STATUS[ "BS#NAR" ] = "The shipment did not arrive";
BKG_STATUS[ "BS#PAR" ] = "The complete shipment arrived for this flight";
BKG_STATUS[ "BS#ARR" ] = "Part of the shipment arrive for this flight";
BKG_STATUS[ "BS#NOS" ] = "The shipment is NO SHOW for this booking";
BKG_STATUS[ "BS#ASG" ] = "The complete shipment is assigned to the flight requested in the input line";
BKG_STATUS[ "BS#AOF" ] = "The complete shipment is assigned, but all or part is assigned to flights other than the one requested in the input line";
BKG_STATUS[ "BS#POF" ] = "Part of the shipment is assigned to a flight other than the one requested in the input line";
BKG_STATUS[ "BS#PAS" ] = "Part of the shipment is assigned to the flight requested in the input line";
BKG_STATUS[ "BS#GCI" ] = "Goods check-in is started for this shipment";
BKG_STATUS[ "BS#FNL" ] = "Goods are delivered";
BKG_STATUS[ "BS#ONH" ] = "The shipment is registered/assigned at a station other than a segment origin station requested in the DBA input";

// Status - Consolidation Booking (CB)

// Status - Non-consolidation Booking (NB)

// Aid to convert month from MMM to MM
var MMMtoNN = new Array( 12 );
MMMtoNN[ "JAN" ] = "01";
MMMtoNN[ "FEB" ] = "02";
MMMtoNN[ "MAR" ] = "03";
MMMtoNN[ "APR" ] = "04";
MMMtoNN[ "MAY" ] = "05";
MMMtoNN[ "JUN" ] = "06";
MMMtoNN[ "JUL" ] = "07";
MMMtoNN[ "AUG" ] = "08";
MMMtoNN[ "SEP" ] = "09";
MMMtoNN[ "OCT" ] = "10";
MMMtoNN[ "NOV" ] = "11";
MMMtoNN[ "DEC" ] = "12";

// -----------------------------------------------------------------------------
// Global variables
// -----------------------------------------------------------------------------

// Regular expressions
var regFlight = /^(\w\w)?\d\d\d\d?[a-zA-Z]?$/				// flight number
var regStation = /^[a-zA-Z]{3}$/							// station name

// -----------------------------------------------------------------------------
// Resize dialog window to fit to last table in page
// -----------------------------------------------------------------------------

function fitWindowToTable() {
	var i;
	var tab;
	var width;
	var height;
	var prt;
	
	if ( navigator.appName == "Netscape" ){
		prt = document.body;
	} else {
		prt = top.document.forms[ 0 ];
	}
	
	do {
		// Find last table
		for( i=0; i<prt.childNodes.length; i++ ) {
			if( prt.childNodes[ i ].tagName == "TABLE" ) {
				tab = prt.childNodes[ i ];
			}
		}
		if( !tab ) prt = top.document.forms[ 0 ];
	}
	while( !tab )
	
	// Measure to farest corner of table ( plus 50px for margins )
	width = tab.offsetLeft + tab.offsetWidth + 50;
	height = tab.offsetTop + tab.offsetHeight + 50;
	
	// Do not extend beyond visible area of screen.
	if ( width > window.screen.availWidth ) width = window.screen.availWidth;
	if ( height > window.screen.availHeight ) height = window.screen.availHeight;
	
	window.resizeTo( width,height )
}

// -----------------------------------------------------------------------------
// Highligt an object
// -----------------------------------------------------------------------------

function highLight( newObj ) {
	while ( newObj.tagName != "TR" ) newObj = newObj.parentElement;
	var tblObj = newObj.parentElement;
	var oldTbl = window.currTbl;
	while ( tblObj.tagName != "TABLE" ) tblObj = tblObj.parentElement;
	
	var oldObj = window.currObj;
	var i = 0;
	if( oldObj ) {
		do {
			oldTbl.rows( oldObj.rowIndex + i ).style.backgroundColor = "";
			i++;
		} while( oldObj.rowIndex + i < oldTbl.rows.length && oldTbl.rows( oldObj.rowIndex + i ).type == "c" )
	}
	
	while ( newObj.type == "c" ) {
		newObj = tblObj.rows( newObj.rowIndex - 1 );
	}
	
	i = 0;
	do {
		tblObj.rows( newObj.rowIndex + i ).style.backgroundColor = "#CCCCCC";
		i++;
	} while ( newObj.rowIndex + i < tblObj.rows.length && tblObj.rows( newObj.rowIndex + i ).type == "c" )
	
	window.currObj = newObj;
	window.currTbl = tblObj;
}

// -----------------------------------------------------------------------------
// Open StnSelect2.asp to find matching stations
// -----------------------------------------------------------------------------

function selectStation( formn, inpn1, seln1, inpv1, inpn2, seln2, inpv2, jshpv ) {
	/* ------------------------------------------------------------------------ *
	 * Inputs:                                                                  *
	 *     formn - Form name of calling page                                    *
	 *     inpn1 - Input text name for first station                            *
	 *     seln1 - Input select name for first station                          *
	 *     inpv1 - Input text value for first station                           *
	 *     inpn2 - Input text name for second station                           *
	 *     seln2 - Input select name for second station                         *
	 *     inpv2 - Input text value for second station                          *
	 *     jshpv - JavaScript function or action to execute when matching       *
	 *             station(s) found                                             * 
	 * ------------------------------------------------------------------------ */
	 var urlm = "";
	 var url1 = "";
	 var url2 = "";
	 var props = "";
	 
	// Build base url for call
	var urlm = "StnSelect.asp?formn=" + formn + "&pagen=" + document.location + "&jshpv=" + jshpv;
	
	// Build url part for first input
	var url1 = "&inpn1=" + inpn1 + "&seln1=" + seln1 + "&inpv1=" + inpv1;
	
	// Build url part for second input if exists
	if( inpn2 != "" )
		var url2 = "&inpn2=" + inpn2 + "&seln2=" + seln2 + "&inpv2=" + inpv2;	
		
	// Build main url
	urlm = urlm + url1 + url2;
	
	// Set properties for the window
	var props = "directories=no,hotkeys=no,menubar=no,location=no,resizable=no,scrollbars=no,status=no,toolbar=no,height=300,width=400";
	
	// Open window
	window.open( urlm, "StationSelect", props );
}

/*
function highLightRow(){
	var elt = event.srcElement;
	if( elt.tagName == "TD" )
	{		if( window.currObj ) 
		{
			window.currObj.style.backgroundColor = "";			document.all.EABSearch.rows(window.currObj.rowIndex + 1).style.backgroundColor = "";			document.all.EABSearch.rows(window.currObj.rowIndex + 2).style.backgroundColor = "";
		}		var row = elt.parentElement;		if (row.type == "c")
		{
			while(row.type == "c")
			{
			 	row = document.all.EABSearch.rows(row.rowIndex - 1);
			}
		}
		row.style.backgroundColor = "#f0f0f0";		document.all.EABSearch.rows(row.rowIndex + 1).style.backgroundColor = "#f0f0f0";
		document.all.EABSearch.rows(row.rowIndex + 2).style.backgroundColor = "#f0f0f0";
		window.currObj = row	}
}
*/
      
 //check for newer browsers that have an image layer, if so image swapping can occur.
      
if (document.images) {
   SortA = new Image();
   SortA.src = "./images/S_Asc.gif";   
   SortD = new Image();
   SortD.src = "./images/S_Desc.gif";
   Sortoff = new Image();
   Sortoff.src = "./images/S_Space.gif"; 
}

// -----------------------------------------------------------------------------
// Function: pageTimeout - Sets the time out obj to reload the signin page
// -----------------------------------------------------------------------------
	var objPageTimeout;
	function pageTimeout (url, ms) {
		var func = 'parent.location.href=\'' + url + '\'';
		
		if (window.opener && !window.opener.closed && 
		    window.opener.objPageTimeout) {
			window.opener.clearTimeout(window.opener.objPageTimeout);
			window.opener.objPageTimeout = window.opener.setTimeout (func, ms);
		}
		else objPageTimeout = setTimeout (func, ms);
	}

