function findDOM(objectId) {
	if (document.getElementById)
	{
		return (document.getElementById(objectId));
	}
	if (document.all)
	{
		return (document.all[objectId]);
	}
}

function mouseX(evt)
{
  if (evt.pageX) 
    return evt.pageX;
  else if (evt.clientX)
    return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  else return null;
}

function mouseY(evt)
{
  if (evt.pageY) 
    return evt.pageY;
  else if (evt.clientY)
    return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  else return null;
}

function OpenWindow(URL)
{
  // Get screen resolution and use to determine the pop-up window size.
  // Leave a 50 pixel border around the outside ...
  var popupwidth = screen.width - 100;
  var popupheight = screen.height - 100;

  URL += '';

  if (URL.toUpperCase().indexOf("HELP") >= 0)
  {
    var hwidth = 800;
    var hheight = 520;
    if (hwidth < popupwidth) popupwidth=hwidth;
    if (hheight < popupheight) popupheight=hheight;
  }

  popupwidth += '';
  popupheight += '';

window.open(URL,'','scrollbars=yes,menubar=no,height='+popupheight+',width='+popupwidth+',resizable=yes,toolbar=no,location=no,status=no,top=25,left=25');
}

function Popup(Src)
{
  var Txt = Src;
  switch (Src)
  {
   case 'submitbutton':
    Txt = '<p>Note - by clicking on this the entire period will be submitted and will not be available for entering any more readings, please use the save button to save readings. ';
    break;
   case 'save':
    Txt = '<p>Any new readings you have entered, and any changes you have made to existing readings will be saved to the Water Use database.<p>You can edit these again at a later date (until the period has been submitted).';
    break;
   case 'reset':
    Txt = '<p>Any new readings you have enetered on this page will be removed, and any readings you have edited will be returned to their original value.<p>The form will remain open and you can continue adding new readings and/or editing existing readings.';
    break;
   case 'cancel':
    Txt = '<p>Any edited will be discarded and this form will be closed.';
    break;
   case 'activeperiods':
    Txt = '<p>At the top of this page you will find a list of periods for which you currently have not submitted your set of readings.  Click on any of these periods to go to the appropriate data entry screen.';
    break;
   case 'submit':
    Txt = '<p>At the end of each monitoring period, you must check the readings you have entered for the period and then submit the readings.<p>Once the readings are submitted for a period, no more readings can be entered for that period and entered readings cannot be edited.';
    break;
   case 'entering':
    Txt = '<p>A blue box indicates that a reading is required. Previously entered readings are shown with a green background. These can be changed if necessary, to correct mistakes, as long as the data set for this period has not yet been submitted. Submitted data cannot be altered and is shown with a yellow background.';
    break;
   case 'indicating':
    Txt = '<p>To indicate that the pump has not been used for a particular day, enter a dash - in the appropriate box. ';
    break;
   case 'saving':
    Txt = '<p>Once you have entered your readings, click the Save button to save the readings. If you wish to exit this page without saving your changes, click the Cancel button. To undo any changes you have made, but leave this page open, click the Reset button. ';
    break;
   case 'new':
    Txt = "<p>The first reading entered after a new meter has been installed should be preceded by the letter 'm'. For example, if you replace your meter and the first reading taking with the new meter is 24, you should enter m24 in the appropriate date box. If you do not do this, the reading (and all those following it) will be rejected. ";
    break;
   case 'selecting':
    Txt = '<p>To enter data for a different period, click on the appropriate period in the table of Active Periods listed at the top right of this page. Note, you cannot alter or enter any data that has previously been submitted. ';
    break; 
  }
  var P = findDOM('Popup');
  if (P)
  {
    P.style.left = mouseX(event) - 50;
    P.style.top = mouseY(event);
    P.innerHTML = Txt;
    P.style.visibility = 'visible';
  }
}

function Popdown(Src)
{
  var P = findDOM('Popup');
  if (P)
    P.style.visibility = 'hidden';  
}

function SubmitData()
{
  var F = findDOM('frmDataEntry');
  if (F)
  {
    F.action = F.action + '&submit=true';
    F.submit();
  }
}

function hideshowDiv(src) 
{
	var P = findDOM(src);
	if (P.style.visibility == 'hidden')
		P.style.visibility = 'visible';
	else
		P.style.visibility = 'hidden';
}

 


