if(document.images)
	{
	calstarton 			= new Image();
	calstarton.src 		= "../images/calendardown.gif";
	calstartoff 		= new Image();
	calstartoff.src 	= "../images/calendar.gif";
	calendon 			= new Image();
	calendon.src 		= "../images/calendardown.gif";
	calendoff 			= new Image();
	calendoff.src 		= "../images/calendar.gif";
	agreementsboxoff	= new Image();
	agreementsboxoff.src= "../images/plus.gif";
	agreementsboxon		= new Image();
	agreementsboxon.src	= "../images/minus.gif";
	troubleboxoff		= new Image();
	troubleboxoff.src	= "../images/plus.gif";
	troubleboxon		= new Image();
	troubleboxon.src	= "../images/minus.gif";
	generalboxoff		= new Image();
	generalboxoff.src	= "../images/plus.gif";
	generalboxon		= new Image();
	generalboxon.src	= "../images/minus.gif";
	back_arrowoff		= new Image();
	back_arrowoff.src	= "../images/back_off.gif";
	back_arrowon		= new Image();
	back_arrowon.src	= "../images/back_on.gif";
	go_pagingon 		= new Image();
	go_pagingon.src 	= "../images/go_on.gif";
	go_pagingoff		= new Image();
	go_pagingoff.src 	= "../images/go.gif";
	go_pagingdown		= new Image();
	go_pagingdown.src 	= "../images/go_down.gif";
	go_pagingup			= new Image();
	go_pagingup.src 	= "../images/go_out.gif";
	}
	
function swapOn(name) 
	{
	document.all[name].src = eval(name + "on.src");
	}
			
function swapOff(name) 
	{
	document.all[name].src = eval(name + "off.src");
	}
	
function mouseOver(name) 
	{
	document.all[name].src = eval(name + "on.src");
	}		
		
function mouseOut(name) 
	{
	document.all[name].src = eval(name + "off.src");
	}
	
function mouseDown(name) 
	{
	document.all[name].src = eval(name + "down.src");
	}	
	
function mouseUp(name) 
	{
	document.all[name].src = eval(name + "up.src");
	}
	
function updateChargeDisplay(itemsubtotal,labelitem,lineitem,amount,container,checkedValue)
	{
	/* blur the line item to appear removed
	for(i=0;i<document.imports.FeeExclusions.length;i++) 
		{			
		if(document.imports.FeeExclusions[i].value==lineitem)
			{
			if(document.imports.FeeExclusions[i].checked == false)
				{
				document.getElementById("fee_"+lineitem).style.color = '#cccccc';
				}
			else
				{
				
				}
			}
		}
	*/
	//get the current grand total
	var grandTotal = document.all["grand_total"].innerHTML;
	
	//get the current subtotal for that container
	var subContainerSubTotal = document.all["subtotal_" + container].innerHTML;

	var adjustAmount;
	if (checkedValue)
		{
		adjustAmount = parseFloat(subContainerSubTotal) + parseFloat(amount);
		grandTotal = parseFloat(grandTotal) + parseFloat(amount);
		document.getElementById(labelitem).style.color = '#000000';
		document.getElementById(itemsubtotal).style.color = '#000000';
		}
	else
		{
		adjustAmount = parseFloat(subContainerSubTotal) - parseFloat(amount);
		grandTotal = parseFloat(grandTotal) - parseFloat(amount);
		document.getElementById(labelitem).style.color = '#AAAAAA';
		document.getElementById(itemsubtotal).style.color = '#AAAAAA';
		}

	//modify the subtotal
	document.all["subtotal_" + container].innerHTML = currency(adjustAmount);

	//modify the grand total
	document.all["grand_total"].innerHTML = currency(grandTotal);
	}
	
function currency( num ) 
	{ 
	var prefix = ""; 
	var suffix = ""; 
	if (num < 0)
		{ 
		prefix = "("; 
		suffix = ")"; 
		num = - num; 
		} 
	var temp = Math.round( num * 100.0 ); // convert to pennies! 
	if ( temp < 10 ) return prefix + "0.0" + temp + suffix; 
	if ( temp < 100 ) return prefix + "0." + temp + suffix; 
	temp = prefix + temp; // convert to string! 
	return temp.substring(0,temp.length-2) + "." + temp.substring(temp.length-2) + suffix; 
	} 
	
function ValidateDem()
	{
	//quick check to see if start date preceeds end date
	schedEnd = new Date(document.dem.enddate.value)

	if (isDate(document.dem.enddate.value)==false)
		{
		document.dem.enddate.select();
		return false;
		}
	}	

function openWin(sLink,w,h)
	{
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers) var xMax = window.outerWidth, yMax = window.outerHeight;
        else var xMax = 640, yMax=480;
    var xOffset = (xMax - h)/2, yOffset = (yMax - w)/2;
	newWin = open(sLink,"win","scrollbars=yes,resizable=yes,status=no,height="+w+",width="+h+",toolbar=no,menubar=no,screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+"'"); 
	newWin.focus();
	}
	
function openWinCal(sLink,w,h)
	{
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers) var xMax = window.outerWidth, yMax = window.outerHeight;
        else var xMax = 640, yMax=480;
    var xOffset = (xMax - h)/2, yOffset = (yMax - w)/2;
	newWin = open(sLink,"win","scrollbars=no,resizable=yes,status=no,height="+w+",width="+h+",toolbar=no,menubar=no,screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+"'"); 
	newWin.focus();
	}
	
function Page(wherewegoin)
	{
	document.paging.action.value = wherewegoin
	document.paging.submit();
	}
	
function BkgClearAll()
	{
	document.booking.b_number.value="";
	document.booking.b_line.value="";
	document.booking.b_number.focus();
	}

function PreArrivalClearAll()
	{
	document.prearrival.b_number.value="";
	document.prearrival.b_line.value="";
	document.prearrival.b_number.focus();
	}

function EDOClearAll()
	{
	document.edo.b_number.value="";
	document.edo.b_line.value="";
	document.edo.b_number.focus();
	}
	
function SchClearAll()
	{
	document.schedule.vessel.value="";
	document.schedule.voyage.value="";
	document.schedule.startdate.value="";
	document.schedule.enddate.value="";
	}
	
function registerWindow(sLink,w,h) {
    var xMax, yMax;
    if (document.all)
        xMax = screen.width, yMax = screen.height;
    else
        if (document.layers) xMax = window.outerWidth, yMax = window.outerHeight;
    else xMax = 640, yMax=480;
    var xOffset = (xMax - h)/2, yOffset = (yMax - w)/2;
    newWin = open(sLink,"avail","scrollbars=no,resizable=yes,status=no,height=" + w + ",width=" + h + ",toolbar=no,menubar=no,screenX=" + xOffset + ",screenY=" + yOffset + ",top="+yOffset+",left="+xOffset+"'"); 
    newWin.focus();
}

function goRegister()
	{
	document.goReg.submit();
	}

function showLayer(itemone,itemtwo) 
	{
	if(document.all.typed.checked)
		{
		document.all[itemone].style.display = 'block';
		document.all[itemtwo].style.display = 'none';
		document.login.userid.value="";
		document.login.userid.focus();
		}
	else 
		{
		document.all[itemone].style.display = 'none';
		document.all[itemtwo].style.display = 'block';
		document.login.email.value="";
		document.login.email.focus();
		}
	document.login.pw.value="";
	}
	
function ClearEquipFields()
	{
	document.equipinquiry.number.value=""
	} 

function updateParent(companyid)
	{
	opener.document.all["companyid"].value = companyid;
	opener.focus();
	window.close();
	}

function updateParentIDType(companyid,companytype)
	{
	parent.opener.document.accounts.companyid.value = companyid;
	parent.opener.document.accounts.companytype.value = companytype;
	parent.opener.focus();
	parent.window.close();
	}
	
function CompanyListWindow(sLink,w,h)
	{
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers) var xMax = window.outerWidth, yMax = window.outerHeight;
        else var xMax = 640, yMax=480;
    var xOffset = (xMax - h)/2, yOffset = (yMax - w)/2;
	newWin = open(sLink,"avail","scrollbars=yes,resizable=yes,status=yes,height="+w+",width="+h+",toolbar=no,menubar=no,screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+"'"); 
	newWin.focus();
	}

function getDisplayElements(z)
	{
	switch(z.name)
		{
		case 'form_agreement':
		    document.all["agreement_agreement"].value = document.all["agreements"].style.display;
			document.all["agreement_trouble"].value = document.all["trouble"].style.display;
			document.all["agreement_general"].value = document.all["general"].style.display;
			break;
		case 'form_trouble':
		    document.all["trouble_agreement"].value = document.all["agreements"].style.display;
			document.all["trouble_trouble"].value = document.all["trouble"].style.display;
			document.all["trouble_general"].value = document.all["general"].style.display;
			break;
		case 'form_general':
		    document.all["general_agreement"].value = document.all["agreements"].style.display;
			document.all["general_trouble"].value = document.all["trouble"].style.display;
			document.all["general_general"].value = document.all["general"].style.display;
			break;
		}
	}

function ShowOrHide(id)
	{
	var id;
	if(document.all[id].style.display == 'none')
		{
		document.all[id].style.display = 'block';
		document.images[id+"box"].src = eval(id + "boxon.src");
		}
	else
		{
		document.all[id].style.display = 'none';
		document.images[id+"box"].src = eval(id + "boxoff.src");
		}
	}	
	
function submitNotify()
	{
	document.agreementsnotify.submit()
	}	

function termLink(val, context)
	{
	if(val!="")
		{
		if(val=="terminalnews")
			{
			document.location.href = context + '/home/default.do';
			}
		else
			{
			document.location.href = context + '/home/default.do?method=page&id=' + val;
			}
		}
	}

function ResetImportForm()
	{
	var selectsearch = document.all["select_search_type"].value;
	if(selectsearch=="container")
		{
		document.all["cell_containers"].style.display = "block";
		document.all["cell_bol"].style.display = "none";		
		document.all["fld_containers"].value="";
		}
	else 
		{	
		document.all["cell_containers"].style.display = "none";
		document.all["cell_bol"].style.display = "block";	
		document.all["fld_bol"].value="";
		document.all["fld_scac"].value="";
		}
	}
	
function ZipRequiredForCountry(CountryId)
	{
	//we require a postal code for these countries [USA, CANADA and PUERTO RICO]
	var sCountriesRequiringPostalCode = new Array("US","CA","PR");
	bZipRequired = false;
	for(i=0;i<sCountriesRequiringPostalCode.length;i++)
		{
		if(CountryId==sCountriesRequiringPostalCode[i])
			{
			bZipRequired = true;
			break;
			}
		}
	if(bZipRequired == true)
		{
		return true;
		}
	else
		{
		return false;		
		}
	}

function getNumber(strValue) {
	if (strValue.search(/\$?[\d,.]+/) != -1)
		return parseFloat((strValue.match(/\$?([\d,.]+)/)[1]).replace(/,/, ''));
	
	return -1;
}
	
function FormatCurrency(num) {
 // returns the num in the .99 format
 var fmtnum = new Number(num);
 return '$' + (!isNaN(fmtnum) ? fmtnum.toFixed(2) : '0.00'); 
}

function LoadingText() 
	{
	document.getElementById('preloadtext').style.visibility='hidden';
	}

function ClearCargoSearch(frm)
	{
	document.cargosearch.sernumber.value="";
	document.cargosearch.filenumber.value="";
	document.cargosearch.bol.value="";
	document.cargosearch.mso.value="";
	document.cargosearch.cargotype.value="";
	document.cargosearch.vessel.value="";
	document.cargosearch.voyage.value="";
	document.cargosearch.location.value="";
	}
	
function ClearCargoMaintenance(frm)
	{
	document.cargomaintenance.sernumber.value="";
	document.cargomaintenance.cargotype.value="";
	document.cargomaintenance.vessel.value="";
	document.cargomaintenance.voyage.value="";
	document.cargomaintenance.bol.value="";
	}	

function GoToCargoPage(c_gkey,c_type,c_ser,i_size,i_gkey,frm_action)
	{
	document.forms["cargo"].action = frm_action;
	document.forms["cargo"].cargo_gkey.value = c_gkey;
	document.forms["cargo"].cargo_type.value = c_type;
	document.forms["cargo"].cargo_ser.value = c_ser;
	document.forms["cargo"].image_size.value = i_size;
	document.forms["cargo"].image_gkey.value = i_gkey
	document.forms["cargo"].submit();
	}
	
function GoToPaymentHistoryPage(trans_id,company_id,company_type)
	{
	document.forms["paymenthistoryprinterview"].transid.value = trans_id;
	document.forms["paymenthistoryprinterview"].companyid.value = company_id;
	document.forms["paymenthistoryprinterview"].companytype.value = company_type;
	document.forms["paymenthistoryprinterview"].submit();
	}

function CheckForInvalidChars(elem)
	{
	if(invalidChars(elem.value)==false)
		{
		elem.focus();
		return false;
		}
	}
	
function SelectAllList(CONTROL)
	{
	for(var i = 0;i < CONTROL.length;i++)
		{
		CONTROL.options[i].selected = true;
		}
	}

function DeselectAllList(CONTROL)
	{
	for(var i = 0;i < CONTROL.length;i++)
		{
		CONTROL.options[i].selected = false;
		}
	}
	
function SelectAllList(elem)
	{
	for(var i = 0;i < elem.length;i++)
		{
		elem.options[i].selected = true;
		//document.all["possiblelabel"].innerHTML = "<a href='javascript:DeselectAllList(document.EditConsignees.possible_consignees);' class='mediumlink'>Deselect All</a>"
		//document.all["selectedlabel"].innerHTML = "<a href='javascript:SelectAllList(document.EditConsignees.selected_consignees);' class='mediumlink'>Select All</a>"
		}
	}

function DeselectAllList(elem)
	{
	for(var i = 0;i < elem.length;i++)
		{
		elem.options[i].selected = false;
		//document.all["possiblelabel"].innerHTML = "<a href='javascript:SelectAllList(document.EditConsignees.possible_consignees);' class='mediumlink'>Select All</a>";
		//document.all["selectedlabel"].innerHTML = "<a href='javascript:DeselectAllList(document.EditConsignees.selected_consignees);' class='mediumlink'>Deselect All</a>"
		}
	}

function one2two(userType) 
	{	
	if(userType == "CO_CONSIGNEE")
		{
		var possibleUserType = document.EditConsignees.possible_consignees;
		var selectedUserType = document.EditConsignees.selected_consignees;
		}
	else if(userType == "CO_SHIPPER")
		{
		var possibleUserType = document.EditConsignees.possible_shippers;
		var selectedUserType = document.EditConsignees.selected_shippers;
		}	
	
    possibleUserTypelen = possibleUserType.length;
    for ( i=0; i<possibleUserTypelen ; i++)
		{
        if (possibleUserType.options[i].selected == true) 
			{
            selectedUserTypelen = selectedUserType.length;
            selectedUserType.options[selectedUserTypelen]= new Option(possibleUserType.options[i].text,possibleUserType.options[i].value);
	        }
    	}
    for ( i = (possibleUserTypelen -1); i>=0; i--)
		{
        if (possibleUserType.options[i].selected == true) 
			{
            possibleUserType.options[i] = null;
	        }
    	}
	}

function two2one(userType) 
	{
	if(userType == "CO_CONSIGNEE")
		{
		var possibleUserType = document.EditConsignees.possible_consignees;
		var selectedUserType = document.EditConsignees.selected_consignees;
		}
	else if(userType == "CO_SHIPPER")
		{
		var possibleUserType = document.EditConsignees.possible_shippers;
		var selectedUserType = document.EditConsignees.selected_shippers;
		}	

    selectedUserTypelen = selectedUserType.length;

	for ( i=0; i<selectedUserTypelen ; i++)
		{
		if (selectedUserType.options[i].selected == true) 
			{
			possibleUserTypelen = possibleUserType.length;
			possibleUserType.options[possibleUserTypelen]= new Option(selectedUserType.options[i].text,selectedUserType.options[i].value);
			}
		}
	for ( i=(selectedUserTypelen-1); i>=0; i--) 
		{
		if (selectedUserType.options[i].selected == true) 
			{
			selectedUserType.options[i] = null;
			}
		}
	//make sure there is some options in the list before resorting - saves an action
	if(selectedUserTypelen >= 1)
		{
		sortSelect(possibleUserType, compareText)
		}
	}
	
function compareText (option1, option2) {
  return option1.text < option2.text ? -1 :
    option1.text > option2.text ? 1 : 0;
}

function compareValue (option1, option2) {
  return option1.value < option2.value ? -1 :
    option1.value > option2.value ? 1 : 0;
}

function compareTextAsFloat (option1, option2) {
  var value1 = parseFloat(option1.text);
  var value2 = parseFloat(option2.text);
  return value1 < value2 ? -1 :
    value1 > value2 ? 1 : 0;
}

function compareValueAsFloat (option1, option2) {
  var value1 = parseFloat(option1.value);
  var value2 = parseFloat(option2.value);
  return value1 < value2 ? -1 :
    value1 > value2 ? 1 : 0;
}

function sortSelect (select, compareFunction) {
  if (!compareFunction)
    compareFunction = compareText;
  var options = new Array (select.options.length);
  for (var i = 0; i < options.length; i++)
    options[i] = 
      new Option (
        select.options[i].text,
        select.options[i].value,
        select.options[i].defaultSelected,
        select.options[i].selected
      );
  options.sort(compareFunction);
  select.options.length = 0;
  for (var i = 0; i < options.length; i++)
    select.options[i] = options[i];
}

function AdminChangeBackground(cell_on,cellone_off,celltwo_off,bResetColors)
	{
	if(bResetColors!="true")
		{
	    document.getElementById(cell_on).style.backgroundColor = "#d3e9fe";
		document.getElementById(cellone_off).style.backgroundColor = "#EEEEEE";
		document.getElementById(celltwo_off).style.backgroundColor = "#EEEEEE";
		}
	else
		{
		document.getElementById(cell_on).style.backgroundColor = "#EEEEEE";
		document.getElementById(cellone_off).style.backgroundColor = "#EEEEEE";
		document.getElementById(celltwo_off).style.backgroundColor = "#EEEEEE";
		}
	}
	
function CheckDeclined()
	{
	var bReset = "true";
	if(document.approve.reason.value.length > 0)
		{
		ChangeBackground('dec','appup','app')
		document.approve.apptype[2].checked = true;
		}
	else
		{
		ChangeBackground('dec','appup','app',bReset);
		document.approve.apptype[2].checked = false;
		}
	}

function ConditionCheckAll(condition, notone, nottwo)
	{
	var the_form = document.cargomaintenanceedit;
	
	for(var i=0; i<the_form.length; i++)
		{
		if(the_form.elements[i].type == "radio")
			{
			//adjust the backgrounds
			var elementname = the_form.elements[i].name.substring(10);
			var on_elem = "id_" + elementname + "_" + condition;
			var undo_one = "id_" + elementname + "_" + notone;
			var undo_two = "id_" + elementname + "_" + nottwo;
			document.getElementById(on_elem).style.backgroundImage = "url(../../images/lineback.gif)";
			document.getElementById(undo_one).style.backgroundImage = "";	
			document.getElementById(undo_two).style.backgroundImage = "";

			//check the box
			if(the_form.elements[i].value==condition)
				{
				the_form.elements[i].checked = true;					
				}				
			}
		}
	}

function ChangeBackground(cell_on,cellone_off,celltwo_off)
	{
    document.getElementById(cell_on).style.backgroundImage = "url(../../images/lineback.gif)";
	document.getElementById(cellone_off).style.backgroundImage = "";
	document.getElementById(celltwo_off).style.backgroundImage = "";
	}
	
function getCookieLanguage()
	{
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("language=");
	
	if (pos != -1)
		{
		var start = pos + 9;
		var end = allcookies.indexOf(";",start);
		if(end == -1) end = allcookies.length;
		var x = allcookies.substring(start,end);
		x = unescape(x);
		}
	return x;
	}
	
function SendBackValue(bConfirm)
	{		
	window.returnValue = bConfirm;
	window.close();
	}
	
function reverseChecks(checkBoxes,len) 
	{
    for (var i=0;i<len;i++) 
		{
		if(checkBoxes[i].disabled!=true)
			{
	        checkBoxes[i].checked = !checkBoxes[i].checked;
			}
    	}	
	}

function ChangeFeeDate(strContainerNumber, iEquipmentKey, strChargeSetting) 
	{
    document.forms['imports'].ChargeDateChangeDate.value = document.forms['imports'].GuaranteedThruDate.value;
    document.forms['imports'].ChargeDateChangeContainer.value = strContainerNumber;
    document.forms['imports'].ChargeDateChangeEquipmentKey.value = iEquipmentKey;
    document.forms['imports'].ChargeSetting.value = strChargeSetting;
    document.forms['imports'].PageAction.value = 10; // UPDATES_DEMURRAGE
    document.forms['imports'].submit();
	}

function goToPage(pageNumber)
	{
	document.paging.intpage.value = pageNumber;
	document.paging.submit();
	}
	
function createBlank(child)
	{
	var child;
	child.options[0] = new Option("", "", false, false);
	}
	
function fillDetail(parentID)
	{
	if(detailData[parentID])
		{
		
		for(voyagenum in detailData[parentID])
			{
			var sDesc = detailData[parentID][voyagenum];
			var valOption = new Option(sDesc);
	 		valOption.value = voyagenum;
	 		objChild.options[objChild.length] = valOption;
			}
		if (objChild.length > 0) 
			{
			objChild.options[0].selected = true;
			}
		}			
		objChild = null;
		objParent = null;
	}
	
function clearList(obj)
	{
	if (obj.length)
		{
		obj.options.length = 0;
		}
	}
	
function disableCustomsCompanyType(type) {
	if(type!=null) {
		if(type.value=="CO_CUSTOMS") {
			document.accounts.companyid.value = "";
			document.accounts.companyid.style.backgroundColor = '#EEEEEE';
			document.accounts.companyid.disabled = true;
		}
		else {
			document.accounts.companyid.style.backgroundColor = '#FFFFFF';
			document.accounts.companyid.disabled = false;
		}
	}
}

function openCalendarWindow(fieldInFocus, formatter, lang, country, context)
	{
		var strOptions;
		fieldInFocus.value = ""
		fieldInFocus.focus();
		strOptions = "resizable=yes;dialogWidth=250px;dialogHeight=210px;status=No;scroll=No;help=No;";
		var returnedValue = window.showModalDialog ( context + "/home/default.do?method=calendar&siteLanguage=" + lang + "_" + country,"12,12,"+fieldInFocus.value,strOptions);
		if(formatter) {
			returnedValue = formatter(returnedValue,lang + "_" + country);
		}
		if(returnedValue != null) {
			fieldInFocus.value = returnedValue;
		}
	}
	
function disableAdminField(fldvalue) {
	if(fldvalue=="CO_CUSTOMS") {
		document.accounts.access.checked=false;
		document.accounts.access.disabled=true;
		document.accounts.access.value="";
	} else {
		document.accounts.access.disabled=false;
	}
}

function DistantClick(idLink) {
	var pageElement = document.getElementById(idLink);
	pageElement.click();
}

function MarkTest() {
    alert("From Common.JS")
}

/**
 * Constructs an array of Option elements representing voyages.  This
 * is used by pages that have a synchronized vessel/voyage list.
 * @param list Reference to the object serving as an associative array of
 *        vessel/voyage information.
 * @param entryid The vessel for which to show voyages
 * @param voyages Reference to the form field to populate
 *        with voyage data.
 * @param selected Voyage value to pre-select in the list.
 */
function buildVoyageList(list, entryid, voyages, selected) {
        voyages.options.length = 0;
        voyages.options[0] = new Option('', '');
        if (entryid) {
        var entry = list[entryid];
          for (var i = 0; i < entry.voyages.length; i++) {
                  var voy = entry.voyages[i];
                  var value = voy.id;
                  var text = voy.id + ' ' + (voy.dir == 'I' ? '(In)' : '(Out)');
                  voyages.options[i + 1] = new Option(text, value, false, (value == selected));
          }
        }
}

/**
 * Constructs an array of Option elements representing vessels.  This
 * is used by pages that have a synchronized vessel/voyage list.
 * @param list Reference to the object serving as an associative array of
 *        vessel/voyage information.
 * @param vessels Reference to the for field to populate
 * @param selected Vessel value to pre-select in the list.
 */
function buildVesselList(list, vessels, selected) {
        var index = 1;
        vessels.options.length = 0;
        vessels.options[0] = new Option('', '');
        for (var id in list) {
                vessels.options[index++] = new Option(list[id].name, id, false, (id == selected));
        }
}

function enableNotes(chkbx, noteField) {
    if(noteField) {
      var parts = noteField.split("|");
      var notification = parts[0];
      var type = parts[1];
      if(type == "email") {
          if(chkbx.checked) {
              document.getElementById((notification + "_NOTE").toUpperCase()).disabled = false;
              document.getElementById((notification + "_NOTE").toUpperCase()).style.backgroundColor = "#FFFFFF";
              document.getElementById((notification + "_NOTE").toUpperCase()).value = "";
              //alert("checked" + noteField);
          } else {
              document.getElementById((notification + "_NOTE").toUpperCase()).disabled = true;
              document.getElementById((notification + "_NOTE").toUpperCase()).style.backgroundColor = "#EEEEEE";
              document.getElementById((notification + "_NOTE").toUpperCase()).value = "";
              //alert("not checked" + noteField);
          }
      }
    }
}

function trim(strValue) {
	if(strValue != null && strValue.length > 0) {
		return strValue.replace(/^\s+|\s+$/g, "");
	}

	return strValue;
}

function hasData(value) {
    return trim(value).length > 0;
}

topNavTab = new RegExp;
topNavTab['Home'] = ('NEWS|CONTACT|HOURS|DRIVING|CAMERAS|SCHEDULE');
topNavTab['Import'] = ('AVAILABILITY');
topNavTab['Export'] = ('BOOKING|EDO');
topNavTab['Gate'] = ('EQUIPMENT|ACTIVITY|TROUBLE|PREARRIVAL');
topNavTab['Fees'] = ('CREATETRANSACTION|HISTORY');
topNavTab['MyAccount'] = ('PROFILE|MYNOTIFICATIONS|MYPREARRIVALS|INTERCHANGE');
topNavTab['Admin'] = ('PENDINGREGISTRATIONS|ACCOUNTS|SITEMAINTENANCE|TRANSACTIONSETTINGS|SUPPORT');

function toggleMenu(menuname, submenu) {
    alert(submenu)
    if(submenu=="NEWS") {
        homePage = true;
    } else {
        homePage = false;
    }

    if(menuname == null || menuname.length == 0) {
        return;
    }

    if(submenu == null || submenu.length == 0) {
        return;
    }

    for(i in topNavTab) {
        if(i = menuname) {
            document.getElementById(menuname + "Tab").className = "current";

            //set topnav style
            currentTab = i;
            links = topNavTab[i].split("|");

            for(var z = 0; z < links.length; z++) {
                if(links[z] == submenu) {
                    document.getElementById(submenu).className = "subnavon";
                }
            }
            break;
        }
    }
}
