﻿// livesites.js - retain URL links that are deemed as live
//
var livesites = "www.pbtfreight.co.nz#www.pbt.co.nz#www.peterbakertransport.co.nz#www.pbtcouriers.co.nz#www.pbtbulk.co.nz#www.pbtsprint.co.nz#www.thepbtgroup.co.nz#www.pbtlogistics.co.nz#www.pbtfreight.com#www.pbtlogistics.com#pbtfreight.co.nz#pbt.co.nz#peterbakertransport.co.nz#pbtcouriers.co.nz#pbtbulk.co.nz#pbtsprint.co.nz#thepbtgroup.co.nz#pbtlogistics.co.nz#pbtfreight.com#pbtlogistics.com#www.pbttransport.co.nz#pbttransport.co.nz#pbtbulk.com#pbttransport.com#pbtcouriers.com#pbtsprint.com#www.pbt.com#pbt.com";
//removed pbtinternational.co.nz from the list temporarily for testing purposes - Simon Fisher 08/02/2007
var livesitesArray = livesites.split("#");


// ========================================================================
// following script added by Nick 28/08/2003
//      Updated by BKA Interactive 12/12/2006 for use in the new website
// To create link between PBT functions going back to header to pass
// necessary parameters which need to be saved after first sucessful login.
// ========================================================================
var savePin = "";
var saveUser = "";
var saveUname = "";
var saveTTmax = "";
var savePTmax = "";
var saveGST = "";
var uniqueId = "";
var saveCompany = "";
var selcompany = "";
var savePBTTCustNo = "";
var passStr = window.location.search;
var startOfSource = passStr.indexOf("savedpin=");
if (startOfSource != -1) {
	var endOfSource = passStr.indexOf("&", startOfSource+9);
	var savePin = passStr.substring(startOfSource+9, endOfSource);
}
var startOfSource = passStr.indexOf("saveduser=");
if (startOfSource != -1) {
	var endOfSource = passStr.indexOf("&", startOfSource+10);
	var saveUser = passStr.substring(startOfSource+10, endOfSource);
}
var startOfSource = passStr.indexOf("saveduname=");
if (startOfSource != -1) {
	var endOfSource = passStr.indexOf("&", startOfSource+11);
	var saveUname = passStr.substring(startOfSource+11, endOfSource);
}
var startOfSource = passStr.indexOf("savedttmax=");
if (startOfSource != -1) {
	var endOfSource = passStr.indexOf("&", startOfSource+11);
	var saveTTmax = passStr.substring(startOfSource+11, endOfSource);
}
var startOfSource = passStr.indexOf("savedptmax=");
if (startOfSource != -1) {
	var endOfSource = passStr.indexOf("&", startOfSource+11);
	var savePTmax = passStr.substring(startOfSource+11, endOfSource);
}
var startOfSource = passStr.indexOf("savedgst=");
if (startOfSource != -1) {
	var endOfSource = passStr.indexOf("&", startOfSource+9);
	var saveGST = passStr.substring(startOfSource+9, endOfSource);
}
var startOfSource = passStr.indexOf("savedunique=");
if (startOfSource != -1) {
	var endOfSource = passStr.indexOf("&", startOfSource+12);
	var uniqueId = passStr.substring(startOfSource+12, endOfSource);
}
var startOfSource = passStr.indexOf("savedcompany=");
if (startOfSource != -1) {
   var endOfSource = passStr.indexOf("&", startOfSource+13);
   var saveCompany = passStr.substring(startOfSource+13, endOfSource);
}
var startOfSource = passStr.indexOf("savedPBTTCustNo=");
if (startOfSource != -1) {
   var endOfSource = passStr.indexOf("&", startOfSource+16);
   var savePBTTCustNo = passStr.substring(startOfSource+16, endOfSource);
}
var startOfSource = passStr.indexOf("selcompany=");
if (startOfSource != -1) {
   var endOfSource = passStr.indexOf("&", startOfSource+11);
   var selcompany = passStr.substring(startOfSource+11, endOfSource);
}

// ==================================================================
// Check cookie is set or not to ask for security form.
// When any image is clicked go to Security form and obtain details.
// ==================================================================
var ns = (document.layers) ? 1:0;
var ie = (document.all) ? 1:0;
if (ns == 0 && ie == 0) {
   var appName = navigator.appName;
   if (appName == "Netscape") ns = true;
   if (appName == "Microsoft Internet Explorer") ie = true;
}
var securityValue = "";
var hostRef = "";
var myURL = "";
var secTarget = "/nick/weblogin.html";
var pbcollectForm = "/nick/pbcoll.html";
var pbffwdForm = "/nick/pbffwd.html";
var pbppdtktForm = "/nick/pbppdtkt.html";
var mypbtForm = "/nick/myPBT.html";
var mypbtenqForm = "/nick/mypbtenq.html";
var mypbtfunctionsForm = "/nick/myPBTfunctions.html";
var formsForm = "/nick/forms.html?"
var stmtForm = "/nick/invstmt.html";
//var savePin = top.window.savePin;
//var saveUser = top.window.saveUser;
//var saveUname = top.window.saveUname;
//var saveTTmax = top.window.saveTTmax;
//var savePTmax = top.window.savePTmax;
//var saveGST = top.window.saveGST;
//var uniqueId = top.window.uniqueId;
//var passStr = "?savedpin=" + savePin + "&" + "?saveduser=" + saveUser + "&" + "?saveduname=" + saveUname + "&" + "?savedttmax=" + saveTTmax + "&" + "?savedptmax=" + savePTmax + "&" + "?savedgst=" + saveGST + "&" + "?savedunique=" + uniqueId + "&";
var passStr = "";
var securityFlags = "";

function checkCookie(name, option) {
	var saveName = name;
	var passData = "";
	hostRef = '' + document.location;
	//hostRef = "pbt.co.nz";
	var vstart = 2 + hostRef.indexOf('//');
	if (vstart > 2) {
		hostRef = hostRef.substring(vstart);
		vstart = hostRef.indexOf('/');
		hostRef = hostRef.substring(0,vstart);
	}
	var myURL = "http://" + hostRef;
	securityValue = getCookie(saveName);
	if (securityValue == "") {
		// must set cookie up now to activate request for security
		value = "not_set";
		setCookie(saveName,value,28);
		securityValue = value;
	}
	if (securityValue == "not_set" && option != 0) { // transfer to security entry form
		passData = "?savedOption=" + option + "&";
		var secWin;
		secWin = window.open(myURL + secTarget + passData,'secWn',"width=600,height=380,left=10,top=10,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no,titlebar=no");
		secWin.opener = self;
		secWin.focus();
//		if (ns) {
//			opener.location.reload();
//		}
//		else {
//			window.open(window.parent.location.reload(true),"_parent","");
//		}
		return null;
	}
	var saveUser = "";
	var saveCompany = "";
	var savePBTTCustNo = "";
	var selcompany = "";
	passStr = getCookie("PBT_Login"); //saved in cookie after successful login.
	var startOfSource = passStr.indexOf("saveduser=");
	if (startOfSource != -1) {
		var endOfSource = passStr.indexOf("&", startOfSource+10);
		var saveUser = passStr.substring(startOfSource+10, endOfSource);
	}
	var startOfSource = passStr.indexOf("savedcompany=");
	if (startOfSource != -1) {
   		var endOfSource = passStr.indexOf("&", startOfSource+13);
  	    var saveCompany = passStr.substring(startOfSource+13, endOfSource);
	}
	var startOfSource = passStr.indexOf("savedPBTTCustNo=");
	if (startOfSource != -1) {
	   var endOfSource = passStr.indexOf("&", startOfSource+16);
	   var savePBTTCustNo = passStr.substring(startOfSource+16, endOfSource);
	}
	var startOfSource = passStr.indexOf("selcompany=");
	if (startOfSource != -1) {
	   var endOfSource = passStr.indexOf("&", startOfSource+11);
	   var selcompany = passStr.substring(startOfSource+11, endOfSource);
	}
	var adminDet = saveUser.split(".");
	var adminsuff = adminDet[1];
	var admin = 0;
	if (adminsuff == "adm" || adminsuff == "ADM") admin = 1;
	secFlagArr = getCookie("PBT_SecFlags"); //security flags for all users (including admin)
	securityFlags = secFlagArr.split("|");
	var allowPBColl = securityFlags[0];
	var allowFF = securityFlags[1];
	var allowTktPak = securityFlags[3];
	var allowStmtInv = securityFlags[5];
	var allowUrgReq = securityFlags[6];
	if (option == 1) { // transfer to PBCollections form
		if (allowPBColl == "Y") {
                        if (saveCompany == "BOTH") {
		    	// alter selcompany to NULL in passStr to force selection
				passStr = passStr.replace("selcompany=PBTC","selcompany=");
				passStr = passStr.replace("selcompany=PBTT","selcompany=");
			}
			var collectWin;
			if (collectWin && !collectWin.closed) {
				collectWin.location.href = myURL + pbcollectForm + passStr;
			}
			else {
                                if (saveCompany == "BOTH") {
					collectWin = window.open(myURL + pbcollectForm + passStr,'pbcollWn',"width=500,height=300,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
				}
				else {
                                   if (saveCompany == "PBTT") {
                                      collectWn = window.open(myURL + pbcollectForm + passStr,'pbcollWn',"width=780,height=500,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
                                   }
                                   else {
					collectWn = window.open(myURL + pbcollectForm + passStr,'pbcollWn',"width=700,height=500,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
                                   }
				}
				if (ie) {
					collectWin.opener = self;
					collectWin.focus();
				}
//				if (ns) {
//					opener.location.reload();
//				}
//				else {
//					window.open(window.parent.location.reload(true),"_parent","");
//				}
			}
		}
		else {
			alert("We're sorry. Your access set-up does not include this e-service.\nShould you require access, please contact your Administrator who can provide this for you.");
//			if (ns) {
//				opener.location.reload();
//			}
//			else {
//				window.open(window.parent.location.reload(true),"_parent","");
//			}
		}
		return null;
	}
	if (option == 2) { // transfer to Freight Forward form
		if (allowFF == "Y") {
			if (saveCompany == "BOTH") {
		    	// alter selcompany to NULL in passStr to force selection
				passStr = passStr.replace("selcompany=PBTC","selcompany=");
				passStr = passStr.replace("selcompany=PBTT","selcompany=");
			}
			var ffWin;
			if (ffWin && !ffWin.closed) {
				ffWin.location.href = myURL + pbffwdForm + passStr;
			}
			else {
				if (saveCompany == "BOTH") {
					ffWin = window.open(myURL + pbffwdForm + passStr,'ffwdWn',"width=500,height=300,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
				}
				else {
					ffWin = window.open(myURL + pbffwdForm + passStr,'ffwdWn',"width=780,height=500,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
				}
				if (ie) {
					ffWin.opener = self;
					ffWin.focus();
				}
//				if (ns) {
//					opener.location.reload();
//				}
//				else {
//					window.open(window.parent.location.reload(true),"_parent","");
//				}
			}
		}
		else {
			alert("We're sorry. Your access set-up does not include this e-service.\nShould you require access, please contact your Administrator who can provide this for you.");
//			if (ns) {
//				opener.location.reload();
//			}
//			else {
//				window.open(window.parent.location.reload(true),"_parent","");
//			}
		}
		return null;
	}
	if (option == 3) { // transfer to Order Courier Tickets form
		if ((admin != 1 && allowTktPak != "Y") || saveCompany == "PBTT") {
			alert("We're sorry. Your access set-up does not include this e-service.\nShould you require access, please contact your Administrator who can provide this for you.");
			passData = "?savedOption=" + option + "&";
			var secWin;
			if (secWin && !secWin.closed) {
				secWin.location.href = myURL + secTarget + passData;
			}
			else {
				secWin = window.open(myURL + secTarget + passData,'secWn',"width=600,height=380,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no,titlebar=no");
				secWin.opener = self;
				secWin.focus();
//				if (ns) {
//					opener.location.reload();
//				}
//				else {
//					window.open(window.parent.location.reload(true),"_parent","");
//				}
			}
			return null;
		}
		var ppdtktWin;
		if (ppdtktWin && !ppdtktWin.closed) {
			ppdtktWin.location.href = myURL + pbppdtktForm + passStr;
		}
		else {
			ppdtktWin = window.open(myURL + pbppdtktForm + passStr,'ppdticketWn',"width=780,height=500,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
			ppdtktWin.opener = self;
			ppdtktWin.focus();
//			if (ns) {
//				opener.location.reload();
//			}
//			else {
//				window.open(window.parent.location.reload(true),"_parent","");
//			}
		}
		return null;
	}
	if (option == 4) { // transfer to Statement/Invoice/Debit Advice forms
		if ((admin != 1 && allowStmtInv != "Y") || saveCompany == "PBTT") {
			alert("We're sorry. Your access set-up does not include this e-service.\nShould you require access, please contact your Administrator who can provide this for you.");
			passData = "?savedOption=" + option + "&";
			var secWin;
			if (secWin && !secWin.closed) {
				secWin.location.href = myURL + secTarget + passData;
			}
			else {
				secWin = window.open(myURL + secTarget + passData,'secWn',"width=600,height=380,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no,titlebar=no");
				secWin.opener = self;
				secWin.focus();
//				if (ns) {
//					opener.location.reload();
//				}
//				else {
//					window.open(window.parent.location.reload(true),"_parent","");
//				}
			}
			return null;
		}
		var stmtWin;
		if (stmtWin && !stmtWin.closed) {
			stmtWin.location.href = myURL + stmtForm + passStr;
		}
		else {
			stmtWin = window.open(myURL + stmtForm + passStr,'invstmtWn',"width=780,height=500,left=5,top=5,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
			stmtWin.opener = self;
			stmtWin.focus();
//			if (ns) {
//				opener.location.reload();
//			}
//			else {
//				window.open(window.parent.location.reload(true),"_parent","");
//			}
		}
		return null;
	}
	if (option == 6) { // transfer to MyPBTfunctions form
//		if (admin != 1) {
//			var targetForm = mypbtenqForm;
//		}
//		else {
//			var targetForm = mypbtForm;
//		}
//
//		Functions page does security checking based on Admin OR Non-Admin user
//              Admin user is always company acc#.ADM (suffix)
//
        if (saveCompany != "PBTT") {
		   var targetForm = mypbtfunctionsForm;
		   var mypbtWin;
		   if (mypbtWin && !mypbtWin.closed) {
			   mypbtWin.location.href = myURL + targetForm + passStr;
		   }
		   else {
			   mypbtWin = window.open(myURL + targetForm + passStr,'mypbtWin',"width=600,height=380,left=10,top=10,scollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
			   mypbtWin.opener = self;
			   mypbtWin.focus();
		   }
		}
		else {
			alert("We're sorry. Your access set-up does not include this e-service.\nShould you require access, please contact your Administrator who can provide this for you.");
		}
		return null;
	}
}

function getCookie(name) {
	var cvalue = "";
	var dc = document.cookie;
	var cname = name + "=";
	var clen = dc.length;
	var cbegin = 0;
	
	while (cbegin < clen) {
		var vbegin = cbegin + cname.length;
		if (dc.substring(cbegin, vbegin) == cname) {
			var vend = dc.indexOf(";", vbegin);
			if (vend == -1) vend = clen;
			cvalue = unescape(dc.substring(vbegin, vend));
			return cvalue;
		}
		cbegin = dc.indexOf(" ", cbegin) + 1;
		if (cbegin == 0) break; // get out
	}
	return cvalue;
}

function setCookie(name, value, days) {
	if (!days) days = 1; // set expiry 1hour
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + days*86400000);

	document.cookie = name + "=" + escape(value) + "; expires=" + expdate.toGMTString();
}

function deleteCookie(name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = getCookie(name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function openForms(){
	var formWin;
	
	if (formWin && !formWin.closed) {
		formWin.location.href = myURL + formsForm;
	}
	else {
	    //* start added (strange that myURL was not being picked up, assuming this will work correctly)
//	    myURL = "http://www.pbt.co.nz/";
	    //* end added
  		formWin = window.open(myURL + formsForm,'Forms', "width=680,height=500,left=5,top=5,scrollbars=yes,resizable=no,status=no,toolbar=no,menubar=no");
		formWin.opener = self;
		formWin.focus();
//		if (ns) {
//			opener.location.reload();
//		}
//		else {
//			window.open(window.parent.location.reload(true),"_parent","");
//		}
	}
	return null;	
}

	
	// get type of browser and website / serverpool for communication
	
	var ns = (document.layers) ? 1:0;
	var ie = (document.all) ? 1:0;
	if (ns == 0 && ie == 0) {
		var appName = navigator.appName;
		if (appName == "Netscape") ns = true;
		if (appName == "Microsoft Internet Explorer") ie = true;
	}
	var trackWin;
	var hostRef = "";
	hostRef = '' + document.location;
//	hostRef = "www.pbt.co.nz";
	var vstart = 2 + hostRef.indexOf('//');
	if (vstart > 2) {
		hostRef = hostRef.substring(vstart);
		vstart = hostRef.indexOf('/');
		hostRef = hostRef.substring(0,vstart);
	}
	var startURL = "http://" + hostRef;
	var trackForm = "";
	var trackWParams = "";
	var trackUParams = "";
	var dbId = "";
	var cookieSeq = "1";	// if we transfer there will only be one reference
	var alertMsg = "";
	
	var fccheckCommand = "/nick/fctest.cfm?f=bottomFrame";
	
	// determine serverpool to run
	
	serverPool = "pbtctest";
  	for(i=0; i < livesitesArray.length; i++) {
    	if (hostRef == livesitesArray[i]) {
      		serverPool = "pbtclive";
      		i = livesitesArray.length; // get out
		}
  	}
	
//*****************************************************************************************************


// ========================
// Transfer to PBtrack form
// ========================
function trackItem() {

	var TicketNumTextbox =  parent.document.getElementById("TicketNo");

	//if (document.track.TicketNo.value.length != 0 && document.track.TicketNo.value != ' Enter Ticket/Ref/Note No') {
	if (TicketNumTextbox.value != "" || TicketNumTextbox != " Enter Ticket/Ref/Note No") {
	
		if (trackWin != null && !trackWin.closed) {
			trackWin.location.href = startURL + trackForm + trackUParams;
		}
		else {
			trackWin = window.open(startURL + trackForm + trackUParams,'Track',trackWParams);
			trackWin.opener = parent;
			trackWin.focus();
		}
		//document.track.TicketNo.value = "";
		TicketNumTextbox.value = "";
	}
	else {
		showAlert("Please provide a ticket number");
	}	
}

// ====================
// Clear Tracking Input
// ====================
function clearfield(){
	if (ie) {
		if (document.track.TicketNo.value == " Enter Ticket/Ref/Note No") {
			document.track.TicketNo.value = "";
		}
	}
	if (ns) {
		if (document.getElementById('TicketNo').value == " Enter Ticket/Ref/Note No") {
			document.getElementById('TicketNo').value = "";
		}
	}
}

// ==========================
// General functions - alerts
// ==========================
function showAlert(alertMsg) {
	if (ns) playSound("ding");
	alert(alertMsg);
}

function playSound(soundObj) {
	var thisSound = document.getElementById(soundObj);
	if (thisSound != null)
		thisSound.Play();
}

// ==============================
// Check Flashconnect operational
// ==============================
function checkFC() {

	var TicketNumTextbox =  document.getElementById("TicketNo");
	 
	//* old * if (document.track.TicketNo.value == "" || document.track.TicketNo.value == " Enter Ticket/Ref/Note No") {
	if (TicketNumTextbox.value == "" || TicketNumTextbox == " Enter Ticket/Ref/Note No") {
		showAlert("Please enter a Ticket/Consignment Note Number first.");
		return;
	}
	//* old * parent.fnull.location = "http://" + hostRef  + fccheckCommand;
	//document.location = "http://" + "pbt.co.nz"  + fccheckCommand;
	
	var frame = document.getElementById('fnull');
	frame.parent = this;
	frame.src = "http://" + hostRef + fccheckCommand;
	//frame.src = "test1.html";
}

// =============================
// Get detail back from D3/Linux
// =============================
function callBack(info) {

	//    info is separated by | sign
  	if (info == 0 || info == 1 || info == 2 || info == 3) {
  		// this is a status test to see if flashCONNECT is operational
		// If OK then go ahead and get next link
		FCCheck(info);
		if (info == 0) {
			getnextForm();
		}
		return;
  	}
	
	// return from webPBtrack routine with tracking results
	// There may be a single reference in which case display details...otherwise-
	// With multiple references need to pop-up an intermediate selection window
	// First however...check for any error conditions.
	
	var arrayFields = info.split("|");
	ticketNo = arrayFields[0]; 					// Originally entered and passed back
	
	if (arrayFields[1].substring(0,6) == "ERROR-") {
   		showAlert(arrayFields[1].substring(6,info.length));
		document.getElementById('TicketNo').focus();
		return;
 	}
	
	var singleMulti = arrayFields[1];				// single or multiple references indicator
	dbId = arrayFields[2];							// Unique ticket cookie reference (D3 end)
	var arrayDetdates = arrayFields[3];				// detailed view - dates
	var arrayDettimes = arrayFields[4];				// detailed view - times
	var arrayDetservareas = arrayFields[5];			// detailed view - service areas
	var arrayDetdescs = arrayFields[6];				// detailed view - descriptions
	var quickRefno = arrayFields[7];				// quickview - current processing reference
	var quickOrigin = arrayFields[8];				// quickview - origin
	var quickDest = arrayFields[9];					// quickview - destination
	var quickStatus = arrayFields[10];				// quickview - latest status
	var receiver = arrayFields[11];					// receiver details
	var emailConfflag = arrayFields[12];			// Receive email conf flag - 1= delivered
	var directSig = arrayFields[13];				// Vector signature available 1=YES
	var arrayVector = arrayFields[14];				// Vector signature format
	var delsigName = arrayFields[15];				// Delivery Signature Name
	var company = arrayFields[16];					// company 1=PBTC, 2=PBT
	
	if (singleMulti == "MULTI") { 					// 	Need to transfer to selection pop-up
		var tabMax = arrayDetdates;
		trackForm = "/nick/PBtrackselect.html";
		trackWParams = "width=780,height=500,left=10,top=5,resizable=no,scrollbars=yes,toolbar=no,status=no,menubar=no";
		trackUParams = "?Reference=" + ticketNo + "&D3Cookie=" + dbId + "&RefCnt=" + tabMax + "&";
	}
	else {
		if (company == 1) {
			trackForm = "/nick/results.cfm";
			trackWParams = "width=790,height=530,left=25,top=5,scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no";
			trackUParams = "?ticketNo="+ticketNo+"&D3Cookie="+dbId+"&D3Seq="+cookieSeq+"&";
		}
		else {
			trackForm = "/nick/results_transport.cfm";
			trackWParams = "width=790,height=530,left=25,top=5,scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no";
			trackUParams = "?ticketNo="+ticketNo+"&D3Cookie="+dbId+"&D3Seq="+cookieSeq+"&";
		}
	}

	// transfer into appropriate form
	trackItem();

}

// ===========================
// Check flashCONNECT Status
// ===========================
function FCCheck(info) {
	var alertMsg = "We're sorry. We're experiencing some difficulty with our website communications.\n";
	alertMsg = alertMsg + "Our website support team have been notified and are currently working on the fault.\n"
	if (info=="0") {
		// FC is operational
		return;
	}
	if (info=="1") {
		alertMsg = alertMsg + "The WEB SERVER communications service is down.\n";
		alertMsg = alertMsg + "Please try again shortly.";
		showAlert(alertMsg);
		return;
	}
	if (info=="2") {
		alertMsg = alertMsg + "The WEB SERVER communications service is down.\n";
		alertMsg = alertMsg + "Please try again shortly.";
		showAlert(alertMsg);
		return;
	}
	if (info=="3") {
		alertMsg = alertMsg + "The DATABASE SERVER web services manager has stopped.\n";
		alertMsg = alertMsg + "Please try again shortly.";
		showAlert(alertMsg);
		return;
	}
	
	alertMsg = alertMsg + "Undetermined Communications Error has occurred.\n\n";
	alertMsg = alertMsg + info + "\n\n";
	alertMsg = alertMsg + "Please try again shortly.";
	showAlert(alertMsg);

}

// =====================================
// Get details on which form to transfer
// =====================================
function getnextForm() {

	// send the reference to database for validation
	//var myticket = document.track.TicketNo.value;
	var myticket = parent.document.getElementById("TicketNo").value;
	
	var passCookieId = "";
	var passCookieSeq = "";
  	var myURL = startURL + "/cgi-bin/fcisapi.dll?w3exec=webPBtrack&w3ServerPool=" + serverPool;
  	myURL = myURL + "&webvalue=" + myticket + "|" + passCookieId + "|" + passCookieSeq + "|BOTTOMFRAME";
  
  	//parent.fnull.location = myURL;
  	//parent.document.getElementById("fnull").src = myURL;
//  	parent.document.getElementById("fnull").src = "test2.html";
	parent.document.getElementById("fnull").src = myURL;
}

//restores the timeout of the security cookie. If this is not run (eg if the user goes to another site)
// the security cookie will timeout and be lost
function setCookie() {
	var cookieVal = getCookie('PBT_Security');
	if (cookieVal == null || cookieVal == '')
		cookieVal = "not_set";
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + 86400000);
	document.cookie = 'PBT_Security=' + cookieVal + '; expires=' + expdate.toGMTString() + '; path=/';
}

// sets the security cookies to non-persistent. This means they can still be ready if the user stays on the site,
// but as soon as they close the browser the cookie will be lost
function clearCookie() {
	var cookieVal = getCookie('PBT_Security');
	if (cookieVal == null || cookieVal == '')
		cookieVal = "not_set";
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + 120000);
	document.cookie = 'PBT_Security=' + cookieVal + '; expires=' + expdate.toGMTString() + '; path=/';
}

// get rid of security when navigate away from website *Nick 16 May 2008*

function deleteCookie(name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = getCookie(name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

// handles enter key in pbtrack form
function trackKeyDown(evt) {
	if ((evt.which && evt.which == 13) || (evt.keyCode && evt.keyCode == 13)) {
		checkFC();
		return false;
	}
	return true;
}