function goPage(src)
{
  window.location.href = src;
}

function addToFavorites(url, title)
{
  if (window.external)
  {
    window.external.AddFavorite(url, title);
  }
  else
  {
    alert("Sorry! Your browser doesn't support this function."); 
  }
}

function sqlEscape(s)
{
  if ( trim(s) == "" || s == null )
    return s;
 else
   // Replace all instances of a single quote with two single quotes
   return (s.replace(/'/g, "''"));
}

function createCookie(name,value,days)
{
  if (days)
  {
    var date = new Date();
	date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
	var expires = ";expires=" + date.toGMTString();
  }
  else
    var expires = "";
  
  document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  
  for(var i = 0; i < ca.length; i++)
  {
    var c = ca[i];
	while (c.charAt(0)==' ')
	  c = c.substring(1, c.length);
  	  
	if (c.indexOf(nameEQ) == 0)
	  return c.substring(nameEQ.length, c.length);
  }
  
  return null;
}

function eraseCookie(name)
{
  createCookie(name, "", -1);
}


function validateZip(field)
{
  var valid = "0123456789-";
  var hyphencount = 0;

  if (field.length!=5 && field.length!=10)
  {
    //alert("Please enter your 5 digit or 5 digit+4 zip code.");
    return false;
  }
  
  for (var i=0; i < field.length; i++)
  {
    temp = "" + field.substring(i, i+1);
    if (temp == "-")
	  hyphencount++;
    
	if (valid.indexOf(temp) == "-1")
	{
      //alert("Invalid characters in your zip code.  Please try again.");
      return false;
    }

    if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-"))
	{
      //alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
      return false;
    }
  }
  return true;
}


function trim(s)
{
  while (s.substring(0,1) == ' ')
    s = s.substring(1,s.length);

  while (s.substring(s.length-1,s.length) == ' ')
    s = s.substring(0,s.length-1);

  return s;
}

function shortenString(str, maxLength)
{
  // Subtract 3 for the three periods at the end
  maxLength -= 3;
  
  // If the string is longer than maximum length, return only the beginning of the string up to the maximum length
  if (str.length > maxLength)
    return str.substring(0, maxLength) + "..."
  return str
}

function isInteger(s)
{
  var i
  for (i = 0; i < s.length; i++)
  {   
    // Check that current character is number.
    var c = s.charAt(i)
    if ( (c < "0") || (c > "9") )
      return false
  }
  
  // All characters are numbers.
  return true
}

function checkLoginForm()
{
  var strError = ""

  if (trim(document.login.username.value).length == 0)
  {	
	strError += "Please provide your user name"
  }
  
  if (trim(document.login.password.value).length == 0)
  {
    if (strError != "")
	  strError = strError + "\r\n"
	
	strError += "Please provide your password"
  }

  if (strError != "")
  {
    alert(strError)
	return false
  }
  else
    return true
}

function checkPoll(radioButtonSet)
{
  var answered = false;

  for (i = 0; i < radioButtonSet.length; i++) 
  {
    if (radioButtonSet[i].checked)
      answered = true; 
  }

  if (!answered)
  {
    alert("Choose an answer before submitting vote")
    return (false);
  }
  
  return (true);
}

function isValidEmail(str)
{
  var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
  
	if ( !str.match(re) )
    return false;
	else
    return true;
}

function PCase(STRING)
{
  var strReturn_Value = "";
  var iTemp = STRING.length;

  if(iTemp == 0)
  {
    return "";
  }

  var UcaseNext = false;
  strReturn_Value += STRING.charAt(0).toUpperCase();
  for (var iCounter=1; iCounter < iTemp; iCounter++)
  {
    if(UcaseNext == true)
    {
      strReturn_Value += STRING.charAt(iCounter).toUpperCase();
    }
    else
    {
      strReturn_Value += STRING.charAt(iCounter).toLowerCase();
    }

    var iChar = STRING.charCodeAt(iCounter);
    if (iChar == 32 || iChar == 45 || iChar == 46)
	{
      UcaseNext = true;
    }
    else
	{
      UcaseNext = false
    }

    if (iChar == 99 || iChar == 67)
	{
      if (STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109)
	  {
        UcaseNext = true;
      }
    }
  } //End For

  return strReturn_Value;
} //End Function

function addDays(myDate, days)
{
  // myDate = a Date object
  // days = +/- days from date
  
  d = new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000);

  return (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getYear()
}