var whitespace = " \t\n\r";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz01234567890_-"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-"

function isEmpty(s){
  return ((s == null) || (s.length == 0))
}// End isEmpty

function isWhitespace (s){
  var i;

  // Is s empty?
  if (isEmpty(s)) return true;

  // Search through string's characters one by one
  // until we find a non-whitespace character.
  // When we do, return false; if we don't, return true.

  for (i = 0; i < s.length; i++){
  // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) return false;
  }

  // All characters are whitespace.
  return true;
}// End isWhiteSpace

function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.
function stripWhiteSpace (s){
  return stripCharsInBag (s, whitespace)
}

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

function isLetter (c)
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}

function isAlphabetic (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }
    return true;
}

// Returns true if character c is a digit
// (0 .. 9).
function isDigit (c){
  return ((c >= "0") && (c <= "9"))
}

function isInteger (s){
  var i;
  if (isEmpty(s))
  return true;

  // Search through string's characters one by one
  // until we find a non-numeric character.
  // When we do, return false; if we don't, return true.

  for (i = 0; i < s.length; i++){
    // Check that current character is number.
    var c = s.charAt(i);

    if (!isDigit(c)) return false;
  }

  // All characters are numbers.
  return true;
}

function isFloat (s, decimalPointDelimiter){
  var i;
  var seenDecimalPoint = false;
  
  if (isEmpty(s))
  return true;

  // Search through string's characters one by one
  // until we find a non-numeric character.
  // When we do, return false; if we don't, return true.
  for (i = 0; i < s.length; i++){
    // Check that current character is number.
    var c = s.charAt(i);

    if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
  }

  // All characters are numbers.
  return true;
}

function isEmail (s){
  if (isEmpty(s)) return true;

  // is s whitespace?
  if (isWhitespace(s)) return false;

  // there must be >= 1 character before @, so we
  // start looking at character position 1
  // (i.e. second character)
  var i = 1;
  var sLength = s.length;

  // look for @
  while ((i < sLength) && (s.charAt(i) != "@")){
    i++;
  }

  if ((i >= sLength) || (s.charAt(i) != "@")) return false;
  else i += 2;

  // look for .
  while ((i < sLength) && (s.charAt(i) != ".")){
    i++;
  }

  // there must be at least one character after the .
  if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
  else return true;
}

function hasApostrophe (s){
  var i;

  // Is s empty?
  if (isEmpty(s)) return false;

  // Search through string's characters one by one
  // until we find a apstrophe character.

  for (i = 0; i < s.length; i++){
    var c = s.charAt(i);
    if (c == "'") return true;
  }

  return false;
}// End hasApostrophe

function LTrim(str){
  var whitespace = new String(" \t\n\r");
  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...
    var j=0, i = s.length;
    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
      j++;
    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }
  return s;
}

function RTrim(str){
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...
    var i = s.length - 1;       // Get length of string
    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;
    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }
  return s;
}

function Trim(str){
  return RTrim(LTrim(str));
}

// Remove dangerous characters from str
function clearString(str){
  var s = str;
  
  s = s.replace(/\'/g, "\'\'");
  s = s.replace(/\"/g, '\\"');
  
  return s;
}//end function

function displayPopup(url, height, width, scrollbars) {
  if (scrollbars!='1') scrollbars = '0'
  properties = "toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars="+scrollbars+",resizable=1";
  properties += ",height=" + height;
  properties += ",width=" + width;
  properties += ",left=0,top=0";
  popupHandle = open(url, "tipwindow", properties);
}// End displayPopup

//Customer Service
function StringIsDate(s){
  if (s==null){
    return (false);
  }
  if (s.length!=10){
    return (false);
  }
  if (s.substring(4,5)!="-" || s.substring(7,8)!="-"){
    return (false);
  }
  syear=s.substring(0,4);
  smonth=s.substring(5,7);
  sday=s.substring(8,11);
  d=new Date(syear,smonth-1,sday);
  year=d.getFullYear();
  if (year<=100){
    year+=1900;
  }
  month=d.getMonth()+1;
  day=d.getDate();
  return ((year==syear || (year+1900)==syear) && month==smonth && day==sday);
}

function StringToDate(s){
  // returns a date from YYYY/MM/DD fromatted s string or null
  if (!StringIsDate(s)){
    return (null);
  }
  syear=s.substring(0,4);
  smonth=s.substring(5,7);
  sday=s.substring(8,11);
  
  d=new Date(syear,smonth-1,sday);
  return (d);
}

function Filter_Keys(){
  var c = event.keyCode;
  
  if((c==222 || c==192) || (c==222 && window.event.shiftKey ))
    event.returnValue=false;
}

// Sometimes is very useful
function doNothing(){
}

function LayerObj(obj) {
  if(document.getElementById){ //DOM
    this.o = document.getElementById(obj);
    this.css = document.getElementById(obj).style;
  }
  else{
    if(document.all){// IE
      this.o = document.all[obj];
      this.css = document.all[obj].style;
    }
    if(document.layers){//NS
      this.o = document.layers[obj];
      this.css = document.layers[obj];
    }
  }
}
