﻿function fnSearch(sQuery) {
  window.location = '/RGWeb/search/results.aspx?k=' + escape(sQuery);
}

function fnTriggerSearch(thisEvent, field) {
  var kCode = String.fromCharCode(thisEvent.keyCode);

  if (kCode == "\n" || kCode == "\r") {
    thisEvent.returnValue = false;

    fnSearch(field.value);
  }
}

function fnShowHide(itemID) {
  var item = document.getElementById(itemID);

  //Show or hide the item.
  if (item.style.display == '' || item.style.display == 'none') {
    item.style.display = 'block';
  }
  else {
    item.style.display = 'none';
  }
}


function fnClear(field) {
  field.value = '';
}

function fnSwap(field, newID) {
  field.style.display = 'none';
  document.getElementById(newID).style.display = 'inline';
  document.getElementById(newID).focus();
}

function fnShowUpdateLocation() {
  document.getElementById("divCurrentUpdate").style.display = 'block';
}

function fnShowOther(otherID) {
  var otherItem = document.getElementById("divOther" + otherID);

  //Show the other item.
  otherItem.style.display = 'block';
}

function fnHideOther(otherID, textID) {
  var otherItem = document.getElementById("divOther" + otherID);
  var otherText = document.getElementById(textID);

  //Show the other item.
  otherItem.style.display = 'none';

  //Clear the other value.
  otherText.value = '';
}

function fnShowHideUpdates() {
  var divUpdates = document.getElementById("divUpdates");
  var imgRight = document.getElementById("imgArrowRight");
  var imgDown = document.getElementById("imgArrowDown");

  //Check if the updates are shown or hidden.
  if (divUpdates.style.display == "none") {
    //Show the updates.
    divUpdates.style.display = "block";

    //Show hide the arrows.
    imgRight.style.display = "none";
    imgDown.style.display = "inline";
  }
  else {
    //Hide the updates.
    divUpdates.style.display = "none";

    //Show hide the arrows.
    imgRight.style.display = "inline";
    imgDown.style.display = "none";
  }
}

function fnWriteDate() {
  var currentDate = new Date();
  var weekday = new Array(7);
  var month = new Array(12);
  
  weekday[0] = "Sun";
  weekday[1] = "Mon";
  weekday[2] = "Tue";
  weekday[3] = "Wed";
  weekday[4] = "Thu";
  weekday[5] = "Fri";
  weekday[6] = "Sat";

  month[0] = "January";
  month[1] = "February";
  month[2] = "March";
  month[3] = "April";
  month[4] = "May";
  month[5] = "June";
  month[6] = "July";
  month[7] = "August";
  month[8] = "September";
  month[9] = "October";
  month[10] = "November";
  month[11] = "December";

  document.write(weekday[currentDate.getDay()] + " " + month[currentDate.getMonth()] + " " + currentDate.getDate().toString() + ", " + currentDate.getFullYear().toString());
}

function fnFormatDate(dateValue, sep) {
  var dd = dateValue.getDate();
  var mm = dateValue.getMonth() + 1;
  var yyyy = dateValue.getFullYear();

  if (dd < 10) {
    dd = "0" + dd;
  }

  if (mm < 10) {
    mm = "0" + mm;
  }

  return mm + sep + dd + sep + yyyy;
}
