//Disable error messages
//Turn this off for debugging
//window.onerror = function(){ return true; }
var AdminMail = "Admin";
var DomainMail = "petermoyes.wa.edu.au";

function AdminMailAddress()
{
	document.write("<A href=\"mailto");
	document.write(":" + AdminMail + "@");
	document.write(DomainMail + "\">" + AdminMail + "@" + DomainMail + "<\/a>");
}

function CheckNumericOnly(sString)
{
  var checkOK = "0123456789";
  var checkStr = sString;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  if (sString == "" || sString == null)
  {
    return (false);
  }

  if (sString.length < 1)
  {
    return (false);
  }
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  
  if (!allValid)
  {
    return (false);
  }

  return true;
}

function UpdateText(sTextName, sComboName)
{
  eval("document.forms.EditItem." + sTextName).value = eval("document.forms.EditItem." + sComboName).value;
  return true;
}

function ClearCombo(sComboName)
{
  eval("document.forms.EditItem." + sComboName).value = "";
  return true;
}

function OpenMadEdit(sItemName, sTargetStyle)
{

  var fWidthSpeed = 48;
  var fHeightSpeed = 32;
  var iSizeWidth = 100;
  var iSizeHeight = 100
  var iWinWidth = 805; //795 internal
  var iWinHeight = 566; //530 internal
  var sWindowProps = "height=" + iSizeHeight + ",width=" + iSizeWidth + ",menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";

  //Check for compatible browser
  if ((window.resizeTo) && (navigator.userAgent.indexOf("Opera")==-1))
  {
    var objSizer = window.open("", "petermoyesedit","left=99999,top=99999,"+ sWindowProps);
    
    while ((iSizeHeight < iWinHeight) || (iSizeWidth < iWinWidth))
    {
      //Position window in the center of the screen for its current size
      iWinLeft = (window.screen.availWidth - iSizeWidth) / 2;
      iWinTop = (window.screen.availHeight - iSizeHeight) / 2;
      objSizer.moveTo(iWinLeft, iWinTop);

      //Resize window
      objSizer.resizeTo(iSizeWidth, iSizeHeight);

      //Check for final width reached
      if (iSizeWidth < iWinWidth)
      {
        iSizeWidth += fWidthSpeed;
      }
      else
      {
        iSizeWidth = iWinWidth;
      }

      //Check for final height reached
      if (iSizeHeight < iWinHeight)
      {
        iSizeHeight += fHeightSpeed;
      }
      else
      {
        iSizeHeight = iWinHeight;
      }

    }
    //Set final size and position
    objSizer.resizeTo(iWinWidth, iWinHeight);
    iWinLeft = (window.screen.availWidth - iWinWidth) / 2;
    iWinTop = (window.screen.availHeight - iWinHeight) / 2;
    objSizer.moveTo(iWinLeft, iWinTop);

    //Load editor
    objSizer.location = "madedit.aspx?ta=" + sItemName + "&st=" + sTargetStyle;
  }
  else
  {
    //Open the editor window with all window features disabled
//    window.open("map/", "mpcmap", "height=530,width=795,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
    window.open("madedit.aspx?ta=" + sItemName + "&st=" + sTargetStyle, "MADEdit", "height=530, width=795, toolbar=0, resizable=1, menubar=0, scrollbars=0, status=0");
  }
  
}

function OpenFileUpload(sSubWebFolderPath, sItemName)
{

  var iWinLeft;
  var iWinTop;
  var iWinWidth = 410; //400 internal
  var iWinHeight = 163; //140 internal
  var sWindowProps = "height=" + iWinHeight + ",width=" + iWinWidth + ",menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
  var objSizer = window.open("", "FileUpload","left=99999,top=99999,"+ sWindowProps);

  //Set window location to centre of screen
  iWinLeft = (window.screen.availWidth - iWinWidth) / 2;
  iWinTop = (window.screen.availHeight - iWinHeight) / 2;
  objSizer.moveTo(iWinLeft, iWinTop);

  //Load editor
  objSizer.location = sSubWebFolderPath + "fileupload.aspx?ta=" + sItemName;

  //Open webbuilder editor
//  window.open(sSubWebFolderPath + "madfileupload.aspx?ta=" + sItemName, "MADFileUpload", "height=180, width=600, toolbar=0, resizable=1, menubar=0, scrollbars=0, status=0");
}

function xOpenMadEdit(sSubWebFolderPath, sItemName, sTargetStyle)
{
  //Open webbuilder editor
  window.open(sSubWebFolderPath + "madedit.aspx?ta=" + sItemName + "&st=" + sTargetStyle, "MADEdit", "height=530, width=795, toolbar=0, resizable=1, menubar=0, scrollbars=0, status=0");
}

function OpenMadHelp(sURL)
{
  // Open the help menu with no tool bars
  window.open(sURL, "MADHelp", "height=500, width=800, toolbar=0, resizable=1, menubar=0, scrollbars=1, status=0");
  return false;
}

// image mouseover
function SwapImage(x, y)
{
  document.getElementById(x).src = y;
}

//====================================================================================
//= Method:        OpenMapApplication
//= Author:        Dave Catley / Karen Tucker
//= Date Created:  8/7/2002
//=
//= Description:   Open a new window to display the map application.
//=
//= Updated By:    <Author>
//= Date Updated:  <Date Updated>
//= Reason:        <Reason>
//=
//=                                 © Praetorium 2002
//====================================================================================
function OpenMapApplication()
{

  var fWidthSpeed = 48;
  var fHeightSpeed = 32;
  var iSizeWidth = 100;
  var iSizeHeight = 100
  var iWinWidth = 805; //795 internal
  var iWinHeight = 566; //530 internal
  var sWindowProps = "height=" + iSizeHeight + ",width=" + iSizeWidth + ",menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";

  //Check for compatible browser
  if ((window.resizeTo) && (navigator.userAgent.indexOf("Opera")==-1))
  {
//    var iWinLeft = (window.screen.availWidth - iSizeWidth) / 2;
//    var iWinTop = (window.screen.availHeight - iSizeHeight) / 2;
    var objSizer = window.open("", "mpcmap","left=99999,top=99999,"+ sWindowProps);
    
    while ((iSizeHeight < iWinHeight) || (iSizeWidth < iWinWidth))
    {
      //Position window in the center of the screen for its current size
      iWinLeft = (window.screen.availWidth - iSizeWidth) / 2;
      iWinTop = (window.screen.availHeight - iSizeHeight) / 2;
      objSizer.moveTo(iWinLeft, iWinTop);

      //Resize window
      objSizer.resizeTo(iSizeWidth, iSizeHeight);

      //Check for final width reached
      if (iSizeWidth < iWinWidth)
      {
        iSizeWidth += fWidthSpeed;
      }
      else
      {
        iSizeWidth = iWinWidth;
      }

      //Check for final height reached
      if (iSizeHeight < iWinHeight)
      {
        iSizeHeight += fHeightSpeed;
      }
      else
      {
        iSizeHeight = iWinHeight;
      }

    }
    //Set final size and position
    objSizer.resizeTo(iWinWidth, iWinHeight);
    iWinLeft = (window.screen.availWidth - iWinWidth) / 2;
    iWinTop = (window.screen.availHeight - iWinHeight) / 2;
    objSizer.moveTo(iWinLeft, iWinTop);

    //Load map
    objSizer.location = "map/";
  }
  else
  {
    //Open the map application window with all window features disabled
    window.open("map/", "mpcmap", "height=530,width=795,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
  }
  
}

//Show the navigation description on the home page
function ShowNavDescription(sTitle, sDescrition, sImgName)
{

  //Get main document name
  var sDocName = parent.main.document.location.toString();

  //Check for home page loaded
  if (sDocName.search(/home.aspx/g) != -1)
  {

    //Show the layer
    parent.main.document.all.HomeNewsNavImg.src = sImgName;
    parent.main.document.frames.HomeNewsFrame.document.all['HomeNavLayer'].style.visibility = "visible";
    parent.main.document.frames.HomeNewsFrame.document.all['HomeNewsLayer'].style.visibility = "hidden";
    parent.main.document.all['HomeNewsCell'].className = "HomeNavBorder";
    parent.main.document.frames.HomeNewsFrame.document.body.className = "HomeNavBody";

    //Show the title and description
    parent.main.document.frames.HomeNewsFrame.document.all['HomeNavTitle'].innerHTML = sTitle;
    parent.main.document.frames.HomeNewsFrame.document.all['HomeNavContent'].innerHTML = sDescrition;

  }
  
}

//Hide the navigation description on the home page
function HideNavDescription(sImgName)
{

  //Get main document name
  var sDocName = parent.main.document.location.toString();

  //Check for home page loaded
  if (sDocName.search(/home.aspx/g) != -1)
  {

    //Hide the layer
    parent.main.document.all.HomeNewsNavImg.src = sImgName;
    parent.main.document.frames.HomeNewsFrame.document.all['HomeNavLayer'].style.visibility = "hidden";
    parent.main.document.frames.HomeNewsFrame.document.all['HomeNewsLayer'].style.visibility = "visible";
    parent.main.document.all['HomeNewsCell'].className = "HomeNewsBorder";
    parent.main.document.frames.HomeNewsFrame.document.body.className = "HomeNewsBody";
  
  }
  
}

//Validate a date string is in the dd/mm/yyyy format
function IsDate(sDate, bAllowNull)
{

  var sDay;
  var sMonth;
  var sYear;
  var sDateSplit;
  var TestDate;

  //Check for an empty date
  if ( (bAllowNull == true) && (sDate == "") )
  {
    return true;
  }

  //Split date into its day month year parts
  sDateSplit = sDate.split("/");

  //Create a date object from the date string
  TestDate = new Date(sDateSplit[2], sDateSplit[1]-1, sDateSplit[0]);

//  alert("[" + sDate + "]-[" + sDateSplit[0] + "][" + sDateSplit[1] + "][" + sDateSplit[2] + "]");
//  alert("[" + TestDate + "]-[" + TestDate.getDate() + "][" + (TestDate.getMonth()+1) + "][" + TestDate.getYear() + "]");

  // Validate date object parts are the same as the date string parts
  if ( (TestDate.getDate() == sDateSplit[0]) && ((TestDate.getMonth() + 1) == sDateSplit[1]) && (TestDate.getYear() == sDateSplit[2]) )
  {
    return true;
  }
  else
  {
    return false;
  }

}

//Validate a time string is in the hh:mm format
function IsTime(sTime, bAllowNull)
{

  var sDay;
  var sMonth;
  var sYear;
  var sTimeSplit;

  //Check for an empty time
  if ( (bAllowNull == true) && (sTime == "") )
  {
    return true;
  }

  //Split time into its hours minutes parts
  sTimeSplit = sTime.split(":");
  //Split time into its minutes am/pm parts
  sTimeSplit2 = sTimeSplit[1].split(" ");

//  alert("[" + sTime + "]-[" + parseInt(sTimeSplit[0]) + "][" + parseInt(sTimeSplit2[0]) + "][" + sTimeSplit2[1] + "]");

  // Validate time string parts
  if ( (isNaN(parseInt(sTimeSplit[0])) == false) && (isNaN(parseInt(sTimeSplit2[0])) == false) )
  {
    if ( (parseInt(sTimeSplit[0]) < 1) || (parseInt(sTimeSplit[0]) > 12) )
    {
      return false;
    }
    else if ( (parseInt(sTimeSplit2[0]) < 0) || (parseInt(sTimeSplit2[0]) > 59) )
    {
      return false;
    }
    else if ( (sTimeSplit2[1] != "AM") && (sTimeSplit2[1] != "PM") && (sTimeSplit2[1] != "am") && (sTimeSplit2[1] != "pm") && (sTimeSplit2[1] != "") && (sTimeSplit2[1] != null) )
    {
      return false;
    }
    else
    {
      return true;
    }
  }
  else
  {
    return false;
  }

}

//Generates and returns a random number between 1 and the specified number
function RandomNum(iNum)
{

  var iRandomNum;
  
  iRandomNum = Math.floor(Math.random()*(iNum));
  
  return iRandomNum + 1;

}