// Displays the specified image in the center of the screen
function DisplayZoomImage(ImageURL, Description, Photographer)
{
  //Provided the browser supports images
  if (document.images)
  {
    //We use variables to make Firefox happy
    var imgZoom = document.getElementById("ImageZoom");
    var divZoom = document.getElementById("DivImageZoom");
    
    var spanDescription =  document.getElementById("ctl00_LabelDescription");
    var spanPhotographer =  document.getElementById("ctl00_LabelPhotographer");
    
    //Set the image and display the div
    imgZoom.src=ImageURL;
    divZoom.style.visibility = "visible";
    
    spanDescription.innerHTML = Description;
    spanPhotographer.innerHTML = Photographer;
    
  }
}
 
//Used to hide the zoomed image
function HideZoomImage()
{
  if (document.images)
  {
    //Locate the zoomed image div and hide it
    var divZoom = document.getElementById("DivImageZoom");
    divZoom.style.visibility = "hidden";
    
    //locate the zoom image
    var imgZoom = document.getElementById("ImageZoom");

    var spanDescription =  document.getElementById("ctl00_LabelDescription");
    var spanPhotographer =  document.getElementById("ctl00_LabelPhotographer");
    
    //Reset the default image to let the user know the
    //next requested image is downloading
    imgZoom.src = "/Images/Image-Downloading-600x400.jpg";
        
    spanDescription.innerHTML = '';
    spanPhotographer.innerHTML = '';
        
  }
}
 
//Preload images used by the display zoom image function
function PreLoadZoomImages(ImageURL) 
{   
  if (document.images)
  {
    //Generate a new image object and preload it's image
    var imgPreLoad = new Image();
    imgPreLoad.src = ImageURL;
  }
}

// Displays the specified image in the supplied image control
function ShowZoomImageDiv(DivID,ImageID,ImageURL)
{
  //Provided the browser supports images
  if (document.images)
  {
    //We use variables to make Firefox happy
    var divZoom = document.getElementById(DivID);
    var imgZoom = document.getElementById(ImageID);
    
    //Set the image and display the div
    imgZoom.src=ImageURL;
    divZoom.style.visibility = "visible";
  }
}
 
//Hide the specified zoom image
function HideZoomImageDiv(DivID)
{
  if (document.images)
  {
    //Locate the zoomed image div and hide it
    var divZoom = document.getElementById(DivID);
    divZoom.style.visibility = "hidden";
  }
}

//Used to confirm deletion of a record
function ConfirmDeleteStudent()
{
  return confirm('Are you sure you wish to delete this Student?'); 
}

// Changes the email link to the valid email address when a user 
// clicks on it and cancels the navigation if it is the first click
function FixEmailHyperlink(AnchorID,EmailHref,EmailAddress)
{
  
  //We use variables to make Firefox happy
  var anchorEmail = document.getElementById(AnchorID);
  
  //Provided the email hyperlink could be found
  if (anchorEmail != null)
  {

    //The hyperlink has already been changed so
    //go ahead and execute the hyperlink
    if (anchorEmail.href == EmailHref)
    {
      return true
    }
    else
    {
      //Change the hyperlinks and cancel the navigation
      anchorEmail.href = EmailHref
      anchorEmail.innerHTML = EmailAddress
      alert('Email addresses are Spam protected. Click the link again to generate an email.')
      return false
    }
  }
}

//Works out the number of days to the Members members birthday - needs
//to be JavaScript to account for the user's timezone
function CalculateBirthdayDays()
{
  //Calculate a single day in milliseconds
  var intMilliSecondsDay = 24*60*60*1000

  //Grab today's date
  dateToday = new Date()

  //Find the hidden birthday day and month fields
  var hiddenDOBDay = 
    document.getElementById("ctl00_BodyContentCenter_SkydiveTownsvilleContentEdit1_HiddenDOBDay")
  var hiddenDOBMonth = 
    document.getElementById("ctl00_BodyContentCenter_SkydiveTownsvilleContentEdit1_HiddenDOBMonth")

  //Provided the hidden birthday day and month fields could be found
  if ((hiddenDOBDay != null) && (hiddenDOBMonth != null))
  {
    var intDOBDay = hiddenDOBDay.value
    var intDOBMonth = hiddenDOBMonth.value
    
    //Generate a date variable containing the birthday
    var dateBirthday = new Date(dateToday.getFullYear(), intDOBMonth, intDOBDay)

    //If today's month is greater than the birthday month, move to next year
    if (dateToday.getMonth() > intDOBMonth)
      dateBirthday.setFullYear(dateBirthday.getFullYear()+1)
    else
    {
      //The birthday is in the current month and the day has passed, move to next year
      if ((dateToday.getMonth() == intDOBMonth) && (dateToday.getDate() > intDOBDay))
        dateBirthday.setFullYear(dateBirthday.getFullYear()+1)
    }

    //Find the birthday label
    var labelBirthday = 
      document.getElementById("ctl00_BodyContentCenter_SkydiveTownsvilleContentEdit1_LabelBirthdayDisplay")

    //Milliseconds between two dates divided by total milliseconds 
    //in a day and rounded up to the nearest whole number
    var intDays = Math.ceil((dateBirthday.getTime() - dateToday.getTime()) / intMilliSecondsDay)

    //Asume birthday is today
    var stringDays = " (Today!)"

    //Check for birthday tomorrow and set the label string
    if (intDays == 1)
      stringDays = " (Tomorrow!)"
      else
        {
          //The birthday is more than a day away, set the label to indicate the number of days
          if (intDays > 1)
            stringDays = " (" + intDays + " days to go)"
        }
        
    //If the birthday label can be found
    if (labelBirthday != null)
    {
      labelBirthday.innerHTML = labelBirthday.innerHTML + stringDays
    }    
  } //End of hidden fields exist
}

//Change the image button to down
function ImageButtonChange(ImageButtonID,ImageURL)
{
  if (document.images)
  {
    //Locate the zoomed image div and hide it
    var imagebutton = document.getElementById(ImageButtonID);
    imagebutton.src = ImageURL;
  }
}

// Display the specified gallery image in Portrait mode
function DisplayGalleryPortrait(
  DivWrapperID, DivZoomID, ImageZoomID, ImageURL,
  CaptionID, Caption, PhotographerID, Photographer)
{

  //Provided the browser supports images
  if (document.images)
  {
  
      //We use variables to make Firefox happy
    var divWrapper = document.getElementById(DivWrapperID);
    var divZoom = document.getElementById(DivZoomID);
    var imgZoom = document.getElementById(ImageZoomID);
    var labelCaption = document.getElementById(CaptionID);
    var labelPhotographer = document.getElementById(PhotographerID);
    
    //Hide so the changes don't flicker
    divWrapper.style.visibility = "hidden";
    
    //Set the downloading image first
    imgNewDownloading = new Image();
    imgNewDownloading.src = '/Images/Image-Downloading-200x300.jpg';
    imgZoom.src = imgNewDownloading.src;
    imgZoom.style.height = '300px';
    imgZoom.style.width = '200px';
    divZoom.style.height = '300px';
    divZoom.style.width = '200px';
    divZoom.style.left = '-108px';
    divZoom.style.top = '-158px';
    
    //Set the yellow side bars next to the image
    divWrapper.style.backgroundImage = 'url(/Images/Gallery-Border-Portrait.jpg)';
    
    //Show the changes
    divWrapper.style.visibility = "visible";
  
    //Set the caption and photographer
    labelCaption.innerHTML = Caption;
    labelPhotographer.innerHTML = Photographer;
    
    //Set the new image
    imgNew = new Image();
    imgNew.src = ImageURL;
    imgZoom.src = imgNew.src;    
    
  }
}

// Display the specified gallery image in Landscape mode
function DisplayGalleryLandscape(
  DivWrapperID, DivZoomID, ImageZoomID, ImageURL, 
  CaptionID, Caption, PhotographerID, Photographer)
{

  //Provided the browser supports images
  if (document.images)
  {
  
    //We use variables to make Firefox happy
    var divWrapper = document.getElementById(DivWrapperID);
    var divZoom = document.getElementById(DivZoomID);
    var imgZoom = document.getElementById(ImageZoomID);
    var labelCaption = document.getElementById(CaptionID);
    var labelPhotographer = document.getElementById(PhotographerID);
    
    //Hide so the changes don't flicker
    divWrapper.style.visibility = "hidden";
    
    //Set the downloading image first
    imgNewDownloading = new Image();
    imgNewDownloading.src = '/Images/Image-Downloading-300x200.jpg';
    imgZoom.src = imgNewDownloading.src;
    imgZoom.style.height = '200px';
    imgZoom.style.width = '300px';
    divZoom.style.height = '200px';
    divZoom.style.width = '300px';
    divZoom.style.left = '-158px';
    divZoom.style.top = '-108px';
    
    //Set the yellow side bars next to the image
    divWrapper.style.backgroundImage = 'url(/Images/Gallery-Border-Landscape.jpg)';
    
    //Show the changes
    divWrapper.style.visibility = "visible";
  
    //Set the caption and photographer
    labelCaption.innerHTML = Caption;
    labelPhotographer.innerHTML = Photographer;
    
    //Set the new image
    imgNew = new Image();
    imgNew.src = ImageURL;
    imgZoom.src = imgNew.src;
    
  }
}

// Displays the product details
function ShowHideStudentDetails(DivDetailsID, DivThumbnailID)
{

  //Provided the browser supports images
  if (document.images)
  {
    //We use variables to make Firefox happy
    var divProductDetails = document.getElementById(DivDetailsID); 
    var divThumbnail = document.getElementById(DivThumbnailID); 
    
    if (divProductDetails.style.visibility == "visible")
    {
      divProductDetails.style.visibility = "hidden";
      divProductDetails.style.display = "none";
      divThumbnail.style.backgroundColor = "white";
    }
    else
    {
      divProductDetails.style.visibility = "visible";
      divProductDetails.style.display = "block";
      divThumbnail.style.backgroundColor = "#AAAAAA";
    }
  }
}

//Highlights the div border colour for the supplied Div
function SetHoverBorderColour(DivID)
{

  //Provided the browser supports images
  if (document.images)
  {
    //We use variables to make Firefox happy
    var divThumbnail = document.getElementById(DivID); 
    
    divThumbnail.style.borderColor = "green";
    
  }
}

//Removes the div border colour for the supplied Div
function RemoveHoverBorderColour(DivID)
{

  //Provided the browser supports images
  if (document.images)
  {
    //We use variables to make Firefox happy
    var divThumbnail = document.getElementById(DivID); 
    
    divThumbnail.style.borderColor = "#ADD8E6";
    
  }
}

// Displays the product details
function ShowHidePhotographDetails(DivDetailsID, DivThumbnailID)
{

  //Provided the browser supports images
  if (document.images)
  {
    //We use variables to make Firefox happy
    var divProductDetails = document.getElementById(DivDetailsID); 
    var divThumbnail = document.getElementById(DivThumbnailID); 
    
    if (divProductDetails.style.visibility == "visible")
    {
      divProductDetails.style.visibility = "hidden";
      divProductDetails.style.display = "none";
      divThumbnail.style.backgroundColor = "white";
    }
    else
    {
      divProductDetails.style.visibility = "visible";
      divProductDetails.style.display = "block";
      divThumbnail.style.backgroundColor = "#BBBBBB";
    }
  }
}