﻿//-----------------------------------------------------------------------------
// Project : Emma's Web Site
// File    : ContactMe.js
// Purpose : Javascript functions for the contact form
// Author  : S.C.Raby.
// Date    : 01/07/2009
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// This function resets the validators when the user clicks the reset button
// pre : valatators state unknown
// post: validatos reset - so that no stars are visible
//-----------------------------------------------------------------------------
function resetValidators()
{
  document.getElementById('RequiredFieldValidator1').style.visibility = "hidden";
  document.getElementById('RequiredFieldValidator2').style.visibility = "hidden";
  document.getElementById('RequiredFieldValidator3').style.visibility = "hidden";
  document.getElementById('RequiredFieldValidator4').style.display = "none";
  document.getElementById('RegularExpressionValidator1').style.display = "none";
  document.getElementById('RequiredFieldValidator5').style.visibility = "hidden";
  document.getElementById('RequiredFieldValidator6').style.visibility = "hidden";
}

//-----------------------------------------------------------------------------
// This function trims leading and trailing spaces from a supplied string
// pre : string supplied
// post: string returned with leading and trailing spaces removed
//-----------------------------------------------------------------------------
function trim(str)
{
  return ltrim(rtrim(str));
}

//-----------------------------------------------------------------------------
// This function trims leading spaces from a supplied string
// pre : string supplied
// post: string returned with leading spaces removed
//-----------------------------------------------------------------------------
function ltrim(str)
{
  return str.replace(new RegExp("^[ ]+", "g"), "");
}

//-----------------------------------------------------------------------------
// This function trims trailing spaces from a supplied string
// pre : string supplied
// post: string returned with trailing spaces removed
//-----------------------------------------------------------------------------
function rtrim(str)
{
  return str.replace(new RegExp("[ ]+$", "g"), "");
}

//-----------------------------------------------------------------------------
// This function removes HTML tags, angle brackets and trims leading and trailing spaces from a supplied string
// pre : string supplied
// post: string returned with HTML tags,angle brackets and leading and trailing spaces removed
//-----------------------------------------------------------------------------
function RemoveHTML(str)
{
  var regEx = /<[^>]*>/g;
  var regEx2 = /(<|>)/g;
  return trim(str.replace(regEx, "").replace(regEx2, ""));
}


