// ----------------------------------------------------------------------------------------------------
// Screen Refresh
// ----------------------------------------------------------------------------------------------------
function setRefreshRate(millisecs)
{
	// Timeout
	setTimeout('refreshWindow()', millisecs);
}

function refreshWindow()
{
	document.chartForm.submit();
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// View Options
// ----------------------------------------------------------------------------------------------------
function viewOption(formAction, formElement)
{
	selectValue = document.viewForm[formElement].value;
	
	if ((selectValue == 'null') || (selectValue == ''))
	{
		alert('Please make a valid selection from the drop-down list.');
	}
	else
	{
		document.viewForm.action = formAction;
		document.viewForm.submit();
		
		showLoadingScreen();
	}
	
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Switching Panels
// ----------------------------------------------------------------------------------------------------
var visiblePanel	= "viewPanelVesselGeneral";
var selectedTab		= "viewPanelTabGeneral"

function showPanel(panel, tab)
{
	document.getElementById(visiblePanel).style.display = "none";
	document.getElementById(panel).style.display = "block";
	
	document.getElementById(selectedTab).className = "tab";
	document.getElementById(tab).className = "sel";
	
	visiblePanel	= panel;
	selectedTab		= tab;
}
// ----------------------------------------------------------------------------------------------------


// ----------------------------------------------------------------------------------------------------
// Switching Panels
// ----------------------------------------------------------------------------------------------------

function fadePanel(panel, tab)
{
    if (visiblePanel != panel)
    {
        // fade out the current panel
	    new Effect.Fade(visiblePanel);
	    // fade in the new panel
	    new Effect.Appear(panel);
	    // change the tab for the current panel to inactive
	    document.getElementById(selectedTab).className = "tab";
	    // change the tab for the new panel to active
	    document.getElementById(tab).className = "sel";
	    // store the details of the new current panel and tab
	    visiblePanel	= panel;
	    selectedTab		= tab;
	}
	else
	{
	    new Effect.Highlight(panel, {startcolor:'#9FACAC', endcolor:'#FFFFFF'});
	}
}
// ----------------------------------------------------------------------------------------------------


// ----------------------------------------------------------------------------------------------------
// Loading Screen
// ----------------------------------------------------------------------------------------------------
function showLoadingScreen()
{
	var elementOver = document.getElementById('overlay');
	var elementLoad = document.getElementById('loadingScreen');
	
	var arrayPageSize = getPageSize();
	
	hideSelectBoxes();
	
	elementOver.style.height = arrayPageSize[1] + "px";
	elementLoad.style.left = (arrayPageSize[0] / 2) - 180 + "px";
	elementLoad.style.top = "234px";
	elementOver.style.visibility = elementLoad.style.visibility = "visible";
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Charting
// ----------------------------------------------------------------------------------------------------
function refreshChart(scale, prevScale, centreLat, centreLon, minLat, minLon, maxLat, maxLon)
{
	var chartForm = window.document.chartForm;
	
	showLoadingScreen();
	
	chartForm.chartScale.value		= scale;
	chartForm.prevChartScale.value	= prevScale;
	chartForm.chartCentreLat.value	= centreLat;
	chartForm.chartCentreLon.value	= centreLon;
	chartForm.minLat.value			= minLat;
	chartForm.minLon.value			= minLon;
	chartForm.maxLat.value			= maxLat;
	chartForm.maxLon.value			= maxLon;
	
	chartForm.submit();
}

function maximiseChart()
{
	var arrayPageSize = getPageSize();
	
	document.charting.chartMaximised.value	= 'true';
	document.charting.clientW.value			= arrayPageSize[2];
	document.charting.clientH.value			= arrayPageSize[3];
	
	//alert('Page Size: ' + arrayPageSize[2] + ',' + arrayPageSize[3]);
	
	document.charting.submit();
}

function minimiseChart()
{
	document.charting.chartMaximised.value	= 'false';
	document.charting.submit();
}

function resizeChart(chartMaximise, chartRefresh)
{
	if (chartMaximise)
	{
		var arrayPageSize = getPageSize();
	
		document.charting.clientW.value			= arrayPageSize[2];
		document.charting.clientH.value			= arrayPageSize[3];
	}
	else
	{
		document.charting.chartMaximise.value	= chartMaximise;
		document.charting.submit();
	}
}

// ----------------------------------------------------------------------------------------------------
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
// ----------------------------------------------------------------------------------------------------
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Show and Hide Select Boxes
// ----------------------------------------------------------------------------------------------------
function showSelectBoxes()
{
	var selects = document.getElementsByTagName("select");
	
	for (i = 0; i != selects.length; i++)
	{
		selects[i].style.visibility = "visible";
	}
}

function hideSelectBoxes()
{
	var selects = document.getElementsByTagName("select");
	
	for (i = 0; i != selects.length; i++)
	{
		selects[i].style.visibility = "hidden";
	}
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Calendar
// ----------------------------------------------------------------------------------------------------
function popupCalendar(formName, formElement)
{
	var calendarWindow;
	var selDate;
	
	selDate = document.getElementById(formElement).value;
	if (selDate == "DD/MM/YYYY")
		selDate = "";
	
	calendarWindow = window.open('/Framework/Input/Calendar.aspx?form_element=' + formName + '.' + formElement + '&sel_date=' + selDate, 'calendar_window', 'width=195,height=225,top=100,left=100status=1,scrollbars=0,toolbar=0,resizable=1');
	calendarWindow.focus;
}

function popupCalendard(formName, formElement)
{
	var calendarWindow;
	var selDate;
	
	selDate = document.getElementById(formElement).value;
	if (selDate == "DD/MM/YYYY")
		selDate = "";
	
	calendarWindow = window.open('/Framework/Input/Calendard.aspx?form_element=' + formName + '.' + formElement + '&sel_date=' + selDate, 'calendar_window', 'width=195,height=225,top=100,left=100status=1,scrollbars=0,toolbar=0,resizable=1');
	calendarWindow.focus;
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Check for Vessels in a Division
// ----------------------------------------------------------------------------------------------------
function validVessels()
{
	vessels = document.allDone.vessels.value;
	
	if (vessels == 'False')
	{
		alert('You do not have any vessels in your Division! Please add a vessel.');
		return false;
	}
	else
	{
	    document.allDone.action = "/scope/view/division/chart.asp";
	    document.allDone.submit();
	}
	return true;
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Manage Users
// ----------------------------------------------------------------------------------------------------
function removeUser(access, userName, userType)
{
	var confirmed = confirm('Are you sure that you want to remove user ' + userName + '?');
	
	if (confirmed)
	{
		document.manageUser.userName.value		= userName;
		document.manageUser.userType.value		= userType;
		
		switch (userType)
		{
			case 1:
				document.manageUser.divisionName.value = access;
				document.manageUser.action = "/scope/view/division/removeuser.asp";
				break;
			case 3:
				document.manageUser.terminalISN.value = access;
				document.manageUser.action = "/scope/view/vessel/removeuser.asp";
				break;
		}
		
		document.manageUser.submit();
	}
}

function updateUser(terminalISN, userName, userType)
{
	document.manageUser.terminalISN.value	= terminalISN;
	document.manageUser.userName.value		= userName;
	document.manageUser.userType.value		= userType;
	
	document.manageUser.action = "/scope/view/vessel/updateuser.asp";
	document.manageUser.submit();
}

function editUser(terminalISN, userName, userType)
{
	document.manageUser.terminalISN.value	= terminalISN;
	
	document.manageUser.action = "/scope/view/vessel/edituser.asp";
	document.manageUser.submit();
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Manage Contacts
// ----------------------------------------------------------------------------------------------------
function removeContact(contactMethod, contactDetail, mode)
{
	var confirmed = confirm('Are you sure that you want to remove contact ' + contactDetail + '?');
	
	if (confirmed)
	{
		document.contactForm.contactMethod.value = contactMethod;
		document.contactForm.contactDetail.value = contactDetail;
		document.contactForm.contactType.value = mode;
		document.contactForm.submit();
	}
}

function editContact(contactMethod, contactDetail, mode)
{
	document.contactForm.contactMethod.value = contactMethod;
	document.contactForm.contactDetail.value = contactDetail;
	document.contactForm.pageAction.value = "edit";
	document.contactForm.contactType.value = mode;
	document.contactForm.action = "/scope/view/vessel/managecontact.asp";
	document.contactForm.submit();
}

function enableContact(contactMethod, contactDetail, mode)
{
	document.contactForm.contactMethod.value = contactMethod;
	document.contactForm.contactDetail.value = contactDetail;
	document.contactForm.pageAction.value = "enable";
	document.contactForm.contactType.value = mode;
	document.contactForm.action = "/scope/view/vessel/managecontact.asp";
	document.contactForm.submit();
}

function disableContact(contactMethod, contactDetail, mode)
{
	document.contactForm.contactMethod.value = contactMethod;
	document.contactForm.contactDetail.value = contactDetail;
	document.contactForm.pageAction.value = "disable";
	document.contactForm.contactType.value = mode;
	document.contactForm.action = "/scope/view/vessel/managecontact.asp";
	document.contactForm.submit();
}

function createContact(mode)
{
 	// mode - 1:SSAS, 2:geofence, 3:intruder, 4:monitor
	document.contactForm.pageAction.value = "create";
	document.contactForm.contactType.value = mode;
	document.contactForm.action = "/scope/view/vessel/managecontact.asp";
	document.contactForm.submit();
}

function cancelContact(selectedVessel, contactTypeString)
{	
    selectedVessel = document.contactForm.terminalISN.value;
    selectedTab = document.contactForm.contactTypeString.value;
	document.contactForm.action = '/scope/view/vessel/chart.asp?selectedVessel=' + selectedVessel + '&selectedTab=' + selectedTab;
	document.contactForm.submit();
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Edit Vessel
// ----------------------------------------------------------------------------------------------------
function cancelEditVessel(selectedVessel)
{	
    selectedVessel = document.editVessel.terminalISN.value;
	//document.editVessel.action = '/scope/view/vessel/chart.asp?selectedVessel=' + selectedVessel;
	document.editVessel.submit();
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Manage Divisions
// ----------------------------------------------------------------------------------------------------
function manageDivision(selectedDivision, terminalISN, pageAction)
{
	document.divisionForm.terminalISN.value = terminalISN;
	document.divisionForm.pageAction.value = pageAction;
	
	document.divisionForm.action = 'manage.asp?selectedDivision=' + encodeURIComponent(selectedDivision);
	document.divisionForm.submit();
}

function deleteDivision(selectedDivision)
{
	var confirmed = confirm('Are you sure that you want to delete division ' + selectedDivision + ' ?');
	
	if (confirmed)
	{
		document.divisionForm.pageAction.value = "DELETE";
		
		document.divisionForm.action = 'manage.asp?selectedDivision=' + selectedDivision;
		document.divisionForm.submit();
	}
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// selectRadio(formName, formElement, radioIndex)
// ----------------------------------------------------------------------------------------------------
function selectRadio(formName, formElement, radioIndex)
{
	var radioArray = document.forms[formName].elements[formElement];
	var radioElement = radioArray[radioIndex];
	
	if (radioElement.checked == false)
	{
		radioElement.checked = true;
	}
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Validation
// ----------------------------------------------------------------------------------------------------
function validDateEntry(value)
{
	var dateArray = value.split('/');
	var d, m, y;
	var valid = false;
	
	if (dateArray.length == 3)
	{
		d = parseInt(dateArray[0], 10);
		m = parseInt(dateArray[1], 10);
		y = parseInt(dateArray[2], 10);
		
		valid = validDate(d, m, y);
	}
	
	return valid;
}

 function validDate_old(d, m, y)
 {
 	var minYear = 2000;
 	var maxYear = 2020;
 	var valid = false;

 	if ((y < maxYear) && (y > minYear))
 	{
 		if ((m <= 12) && (m >= 1))
 		{
 			if ((d <= 31) && (d >= 1)) 
 			{
 		        valid = true;
 			}
 		}
 	}
 	return valid;
 }

function validDate(d, m, y)
{
	var minYear = 2000;
	var maxYear = 2020;
	var valid = false;
	
	if ((y < maxYear) && (y > minYear))
	{
	  if (d > 0) {
      switch (m) {
        case 1:
                  if (d <= 31) valid = true; break;
        case 2:
				  if (d <= daysInFebruary(y)) valid = true; break;
        case 3:
				  if (d <= 31) valid = true; break;
        case 4:
				  if (d <= 30) valid = true; break;
        case 5:
				  if (d <= 31) valid = true; break;
        case 6:
				  if (d <= 30) valid = true; break;
        case 7:
				  if (d <= 31) valid = true; break;
        case 8:
				  if (d <= 31) valid = true; break;
        case 9:
				  if (d <= 30) valid = true; break;
        case 10:
				  if (d <= 31) valid = true; break;
        case 11:
				  if (d <= 30) valid = true; break;
        case 12:
				  if (d <= 31) valid = true; break;
      }
		}
	}
	return valid;
}

function daysInFebruary (year){
  // February has 29 days in any year evenly divisible by four,
  // except for centurial years which are not also divisible by 400.
  return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

// updated to check for inverse date ranges and max
// 30 day range for multimap modes, 03/2007, JL
function validDateFilter(multiMapMode)
{
  var retVal = true;
  var oneDay = 1000*60*60*24;
  if (multiMapMode == "TMAP")
  {
    dateFilterLo = document.aspForm.dateRangeMin.value;
    dateFilterHi = document.aspForm.dateRangeMax.value;
  }
  else
  {
    dateFilterLo = document.dateFilter.dateFilterLo.value;
    dateFilterHi = document.dateFilter.dateFilterHi.value;
  }
  if (validDateEntry(dateFilterLo) && validDateEntry(dateFilterHi))
  {
    // create Date objects for both dates
    var loArray = dateFilterLo.split('/');
    var loDate = new Date();
    loDate.setFullYear(loArray[2], loArray[1]-1, loArray[0]);
    var hiArray = dateFilterHi.split('/');
    var hiDate = new Date();
    hiDate.setFullYear(hiArray[2], hiArray[1]-1, hiArray[0]);
    
    // make sure the high date is higher than the low date
    if (hiDate < loDate)
    {
      alert ('Invalid Entry! Max Date must be greater than Min Date.');
      retVal = false;
    } 
    else
    {
      if (multiMapMode == "MMAP")
      { // this is multimap mode, so we do some additional checking..
        if (((hiDate-loDate)/oneDay) > 30)
        { // if the difference between the two dates is greater than 30 days..
  				// work out a new date, 30 days later than the min date
					loDate = new Date(hiDate);
          loDate.setDate(loDate.getDate()-30)
          // let the user know what's going on
          alert ('The chosen dates are more than 30 days apart, which is the maximum range\n ' +
								 'supported for MultiMap cartography. The Min Date has been set to 30 days\n' +
								 'before the Max Date specified.');
					// put the corrected date in the form field
          document.dateFilter.dateFilterLo.value = (loDate.getDate() + '/' + (loDate.getMonth() + 1) + '/' + loDate.getFullYear());
        }
      }
    }
  }	else
  {
    alert('Invalid Entry! Please ensure that all dates are entered in the correct format (DD/MM/YYYY).');
    retVal = false;
  }
  return retVal;
}
// old version here...
//function validDateFilter()
//{
//	dateFilterLo = document.dateFilter.dateFilterLo.value;
//	dateFilterHi = document.dateFilter.dateFilterHi.value;
//	
//	if (validDateEntry(dateFilterLo) && validDateEntry(dateFilterHi))
//	{
//		return true;
//	}
//	else
//	{
//		alert('Invalid Entry! Please ensure that all dates are entered in the correct format (DD/MM/YYYY).' + dateFilterLo + "," + dateFilterHi);
//		return false;
//	}
//}

function validContactDetail()
{
	var contactMethod = document.contactForm.contactMethod.value;
	var contactDetail = document.contactForm.contactDetail.value;
	var valid = false;
	
	switch (contactMethod)
	{
		case 'SMS':
			valid = validSMS(contactDetail);
			break;
		case 'Email':
			valid = validEmail(contactDetail);
			break;
	}
	
	return valid;
}

function validEmail(value)
{
	var aPos	= value.indexOf('@');
	var dotPos	= value.lastIndexOf('.');
	var valid	= false;
	
	if (value.length > 4)
	{
		if (aPos < 1 || dotPos - aPos < 2)
		{
			alert('Please ensure that you have entered a valid email address.');
		}
		else 
		{
			valid = true;
		}
	}
	else
	{
		alert('Please enter an email address.');
	}
	
	return valid;		
}

function validSMS(value)
{
	var plusPos	= value.indexOf('+');
	var valid = false;
	
	if (value.length >= 10)
	{
		if (plusPos != 0)
		{
			alert('Please ensure that the SMS number is in the correct format (+<COUNTRY-CODE>0000111222).');
		}
		else 
		{
			valid = true;
		}
	}
	else
	{
		alert('Please enter an SMS number.');
	}
	
	return valid;
}

function validDivisionName()
{
	var divisionName = document.divisionForm.divisionName.value;
	
	var validationRegexp = /[a-zA-Z0-9 &\-\.,:]/;
	
	if (divisionName.length == 0)
	{
		alert('Please enter a name for your new division.');
		return false;
	}
	else if (!validationRegexp.test(divisionName))
	{
		alert('The division name may contain only alphanumeric characters, the space character, or the following symbols: &-.,:');
		return false;
	}
	
	return true;
}

var startOptionIndex	= 0;
var expiryOptionIndex	= 0;

function validCreateUser()
{
	var userName			= document.createUser.userName.value;
	var passWord			= document.createUser.passWord.value;
	var selectOption		= document.createUser.selectOption.value;
	var email       		= document.createUser.email.value;
	
	
	if (userName.length < 6)
	{
		alert('Invalid Entry! Please ensure that the username is at least 6 characters in length.');
		document.createUser.userName.focus();
		return false;
	}
	
	if (passWord.length < 6)
	{
		alert('Invalid Entry! Please ensure that the password is at least 6 characters in length.');
		document.createUser.passWord.focus();
		return false;
	}
	
	if ((selectOption == 'null') || (selectOption == ''))
	{
		alert('Invalid Entry! Please make a valid selection from the drop-down list.');
		document.createUser.passWord.focus();
		return false;
	}
	
	if (startOptionIndex == '1')
	{
		var startDate = document.createUser.startDate.value;
	
		if (!validDateEntry(startDate))
		{
			alert('Invalid Entry! Please enter the start date in the correct format (DD/MM/YYYY).');
			document.createUser.startDate.focus();
			return false;
		}
	}
	
	if (expiryOptionIndex == '1')
	{
		var expiryDate = document.createUser.expiryDate.value;
	
		if (!validDateEntry(expiryDate))
		{
			alert('Invalid Entry! Please enter the expiry date in the correct format (DD/MM/YYYY).');
			document.createUser.expiryDate.focus();
			return false;
		}
	}
	
	return validEmail(email);
	
	return true;
}

function createUserRadioClick(option, index)
{
	switch (option)
	{
		case 'startOption':
			startOptionIndex = index;
			break;
		case 'expiryOption':
			expiryOptionIndex = index;
			break;
	}		
	return true;
}

function validEditUser(mode)
{
	if (mode == 0)
	{
		var usernameNew = document.editUsernameForm.usernameNew.value;
		
		return validUsername(usernameNew);
	}
	else if (mode == 1)
	{
		var passwordCurrent = document.editPasswordForm.passwordCurrent.value;
		var passwordNew		= document.editPasswordForm.passwordNew.value;
		var passwordConfirm	= document.editPasswordForm.passwordConfirm.value;
		
		return validPassword(passwordNew, passwordConfirm);
	}
	//alert('Pause.');
}

function validEditUserFleet()
{
	var usernameNew = document.aspForm.usernameNew.value;
	var passwordNew = document.aspForm.passwordNew.value;
	var passwordConfirm = document.aspForm.passwordConfirm.value;

	return validUsername(usernameNew) && validPassword(passwordNew, passwordConfirm);
}

function validUsername(usernameNew)
{
	if (usernameNew.length < 6)
	{
		alert('Invalid Entry! Please ensure that the username is at least 6 characters in length.');
		return false;
	}
	else
	{
		return true;
	}
}

function validPassword(passwordNew, passwordConfirm)
{
	if (passwordNew != passwordConfirm)
	{
		alert('Invalid Entry! Please ensure that the new and confirmation passwords match.');
		return false;
	}
	else
	{
		if (passwordNew.length < 6)
		{
			alert('Invalid Entry! Please ensure that the new password is at least 6 characters in length.');
			return false;
		}
		else
		{
			return true;
		}
	}
}

function validNotice()
{
	var notice = document.addnotices.notice.value;
	var noticeType = document.addnotices.noticeType.value;
	var individualUserName = document.addnotices.individualUserName.value;
	
	if (noticeType == "individual")
	{
	    if (individualUserName.length < 6)
	    {
		    alert('Please enter a valid Username.');
		    return false;
	    }
	}
	
	if (notice.length == 0)
	{
		alert('Please enter a Notice.');
		return false;
	}
	
	return true;
}

function validEmailDocustore()
{
	if (document.emaildocustore.email.value == "Send Email")
	{
	    if (document.emaildocustore.recordExists.value == 0)
	    {
	        alert('Error! No records for this Vessel. Please add some information before emailing this document!');
            document.docustore.hullIDNumber.focus();
		    return false;
	    }
	
	//if (document.emaildocustore.emailToCheckbox.value == "on")
	
	    return validEmail(document.emaildocustore.emailToForm.value)
	    document.emaildocustore.emailToForm.focus();
	    return false;
	}
	
    return true;
}

function validDocustore()
{
	var hullIDNumber = document.docustore.hullIDNumber.value;
	
	if (hullIDNumber.length < 6)
	{
        alert('Please enter a valid Hull ID number!');
        document.docustore.hullIDNumber.focus();
		return false;
	}
	
	if (!validDateEntry(document.docustore.epirbDate.value) && (document.docustore.epirbDate.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.epirbDate.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.sartDate.value) && (document.docustore.sartDate.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.sartDate.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.epirb1Date.value) && (document.docustore.epirb1Date.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.epirb1Date.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.epirb2Date.value) && (document.docustore.epirb2Date.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.epirb2Date.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.epirb3Date.value) && (document.docustore.epirb3Date.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.epirb3Date.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.epirb4Date.value) && (document.docustore.epirb4Date.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.epirb4Date.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.epirb5Date.value) && (document.docustore.epirb5Date.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.epirb5Date.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.epirb6Date.value) && (document.docustore.epirb6Date.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.epirb6Date.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.flareDate.value) && (document.docustore.flareDate.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.flareDate.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.lifeRaftDate.value) && (document.docustore.lifeRaftDate.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.lifeRaftDate.focus();
		return false;
	}
    if (!validDateEntry(document.docustore.fireRaftDate.value) && (document.docustore.fireRaftDate.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.fireRaftDate.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.flareGrabDate.value) && (document.docustore.flareGrabDate.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.flareGrabDate.focus();
		return false;
	}
	if (!validDateEntry(document.docustore.epirbGrabDate.value) && (document.docustore.epirbGrabDate.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.epirbGrabDate.focus();
		return false;
	}
    if (!validDateEntry(document.docustore.insuranceDate.value) && (document.docustore.insuranceDate.value != "" ))
	{
		alert('Invalid Entry! Please enter the date in the correct format (DD/MM/YYYY).');
		document.docustore.insuranceDate.focus();
		return false;
	}
	
	return true;
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// Navigation - misc
// ----------------------------------------------------------------------------------------------------
function goBack()
{
	history.go(-1);
}

function popUp(URL)
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=1,statusbar=1,menubar=0,resizable=1,width=350,height=350');");
}

function popupDialogue(form, dialogueName)
{
	if (!window.focus) return true;
	window.open('', dialogueName, 'height=360,width=500,scrollbars=yes');
	form.target = dialogueName;
	return true;
}

function popupDialogueSized(form, name, h, w)
{
	if (!window.focus) return true;
	window.open('', name, 'height=' + h + ',width=' + w + ',scrollbars=yes');
	form.target = name;
	return true;
}

function popupOpen(form, size)
{
	var popupWindow;
	popupWindow = window.open(form, 'countryInfo', size);
	popupWindow.focus();
}

function popupClose()
{
	var popupWindow;
	popupWindow = window.close();
}

function popupPrint()
{
	var popupWindow;
	popupWindow = window.print();
}

function loginHelp()
{
    alert('If you are experiencing any difficulties in logging in then please email support@marinetrack.com');
	return false;
}

function emailSent()
{
    alert('Users email has ben sent');
	return false;
}

function ackAlert(alertCode, mode)
{
  var aForm = window.document.ackAlertForm;
	aForm.alertCode.value = alertCode;
	aForm.mode.value = mode;
	aForm.submit();
}
// ----------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------------------
// MIDAS Weather UI Support Functions (called by scope/view/vessel/chart.asp)
// ----------------------------------------------------------------------------------------------------

function fillWeatherTimeSelector(currentHour) {
  var mForm = window.document.midasForm;
	var cForm = window.document.chartForm;
  // clear the selector
  mForm.SELTIME.options.length = 0;
  // build the new selector
  var hourDelay = 3; // weather service data delay, in hours
  var thisTime = new Date();
  thisTime.setHours(currentHour); // set time to server time
  if (mForm.SELDAY.options[mForm.SELDAY.selectedIndex].text == 'Yesterday') {
    // build list for yesterday, up to hourDelay hours ago
    var offset = 0;
    if (thisTime.getHours() - hourDelay < 0) offset = thisTime.getHours() - hourDelay;
    for (i = 0; i <= 23 + offset; i++) {
      var timeString = i + ":00"; if (i < 10) timeString = "0" + timeString;
      mForm.SELTIME.options[i] = new Option(timeString, timeString + ":00", false);
		if (mForm.SELTIME.options[i].value == cForm.selTime.value) mForm.SELTIME.options[i].selected = true;
    }
  } else {
    // else build list for today, up to current time minus hourDelay
    if (thisTime.getHours() >= hourDelay) {
      for (i = 0; i <= thisTime.getHours() - hourDelay; i++) {
        var timeString = i + ":00"; if (i < 10) timeString = "0" + timeString;
        mForm.SELTIME.options[i] = new Option(timeString, timeString + ":00", false);
			  if (mForm.SELTIME.options[i].value == cForm.selTime.value) mForm.SELTIME.options[i].selected = true;
      }
    } else {
      // no hours are available for today, so add a single dummy option
      mForm.SELTIME.options[0] = new Option("--:--:--", "-", false);
    }
  }
}

function refreshWeather() {
  if (tryParseWeatherForm()) {
    showLoadingScreen();
    document.chartForm.submit();
  }
}

function tryParseWeatherForm() {
 success = false;
  // sanity-check user input
  if (document.midasForm.LAYERS.value=="") {
    alert("Problem with weather request:\n\nPlease select one or more weather layers from the list box.\n\n(Hold CTRL, or drag, to make a multiple selection)");
  } else if (document.midasForm.SELTIME.value=="-") {
    alert("Problem with weather request:\n\nThere is no weather data for the selected time. Please choose a different day/time.");
  } else {
  // input is good, fill the chartForm
    var layers = "";
		var layersControl = document.midasForm.LAYERS;
    // construct comma-delimited list of selected layers
    for (i = 0; i < layersControl.options.length; i++) {
      if (layersControl.options[i].selected) {
        layers += layersControl.options[i].value + ",";
      }
    }
	// remove final comma
    layers = layers.substring(-1, layers.length-1);
	// fill the form
    document.chartForm.layers.value = layers;
    document.chartForm.selDate.value = document.midasForm.SELDAY.value;
    document.chartForm.selTime.value = document.midasForm.SELTIME.value;			  
	success = true;
}
return success;
}

function toggleWeather() {
  if (document.chartForm.showWeather.value=="") {
// if weather layer is off, parse user settings and turn it on
	  if (tryParseWeatherForm()) {
			document.chartForm.showWeather.value="1";
		  showLoadingScreen();
      document.chartForm.submit();
		}
  } else {
// if weather layer is on, turn it off		  	
    document.chartForm.showWeather.value="";
  	showLoadingScreen();
    document.chartForm.submit();
  }
}
// ----------------------------------------------------------------------------------------------------

