// JavaScript Document
// Collection of Various functions for the Aite Website

/**
 *  Handles basic right click cloaking for IE
 *  Version 1 :: Francesco Peri :: 03/06/05
 */
  function IE_click(warning)
  {
    if (event.button == 2){
    alert(warning);
    return false;
    }
  }

/**
 *  Handles basic right click cloaking for Netscape (Mozilla family)
 *  Version 1 :: Francesco Peri :: 03/06/05
 */
  function NS_click(warning, e)
  {
    if (e.which == 2 || e.which==3){
      alert(warning);
      return false;
    }
  }
  
/**
 *  Event Object Processor for NN4, IE4+, NN6
 */
 function isEnterKey(evt)
 {
   if (!evt) 
     evt = window.event; // Grab IE event object
   else if (!evt.keyCode)
     evt.keyCode = evt.which;  // Grab NN4 event info
   return (evt.keyCode == 13);
 }
 
/**
 *  Event Object Processor for NN4, IE4+, NN6
 */
 function submitOnReturn(frm, evt)
 {
   if(isEnterKey(evt))
   {
     frm.submit();
     return false;
   }
   return true;
 }
 

// List of Error/warning messages
// ---------------------------------------------------------------------------
  ERR_NO_VALUE = " is a required field.\n";
  ERR_INVALID_TEXT_STRICT = " contains invalid characters such as numbers, @#$!%, etc.\n";
  ERR_INVALID_TEXT = " contains invalid characters such as @#$!%, etc.\n";
  ERR_IN_FORM = "Please verify that the information entered in the form is accurate.\n" +
                "We have detected the following problem(s):\n\n";
  ERR_INVALID_EMAIL = " does not appear to be a valid email address.\n";
  ERR_INVALID_ZIP = " does not appear to be a valid ZIP code.\n";
  ERR_INVALID_PHONE = " does not appear to be a valid phone number.\n";
  ERR_CASUAL_EMAIL = " is not an acceptable email domain.\n";
  ERR_ACCESS_DENIED = "ACCESS DENIED!\n\nYou will be redirected to your own domain.";
  MSG_APOLOGY = "We apologize for the inconvenience.";
  MSG_PROBLEMS_W_FORM = "If you are having problems with this form, please send an email to\n" +
                        "webmaster@cesn.org.\n";
  ERR_INVALID_PW = ERR_INVALID_TEXT;
  LF = "\n";
 
// List of unacceptable email and blacklisted email domains
// ---------------------------------------------------------------------------
   var invalid_doms = new Array()
   invalid_doms[0]="rocketmail";
   invalid_doms[1]="zdnetmail";
   // Add more here
 
 
   var blacklist_doms = new Array()
   blacklist_doms[0] = "celent";
   blacklist_doms[1] = "towergroup";
   blacklist_doms[2] = "forrester";
   blacklist_doms[3] = "gartner";
   blacklist_doms[4] = "mercatoradvisorygroup";
   blacklist_doms[5] = "financial-insights";
   
   // Add more here

// List of strings of characters to include/exclude
// ---------------------------------------------------------------------------
    var str_numeric = "0123456789.";
    var str_phone = "0123456789()-+. x";
    var str_badtext = "!@#$%^*()+={}[]|`~<>?/\\";
    var str_badtext_strict = "0123456789!@#$%^&*()+={}[]|:;`~<>,.?/\\";
    var str_badpw = "!@#$%^+=|`~<>?/\\ ";


// SIMPLE STRING VALIDATION FUNCTIONS (FOR FORMS, ETC)
// ---------------------------------------------------------------------------
  function contains(str, str_include)
  {
    for (var i = 0 ; i < str.length ; i++)
      if (str_include.indexOf(str.charAt(i)) == -1)
        return false;
    return true;
  }
  
  function excludes(str, str_exclude)
  {
    for (var i = 0 ; i < str.length ; i++)
      if (str_exclude.indexOf(str.charAt(i)) != -1)
        return false;
    return true;
  }
  
  function isValidText(str) { return excludes(str, str_badtext); }
  function isValidTextStrict(str) { return excludes(str, str_badtext_strict); }
  function isNumeric(str) { return contains(str, str_numeric); }
  function isPhoneNumber(str) { return contains(str, str_phone); }
  function isValidPassword(str) { return excludes(str, str_badpw); }
  
  function isBlank(str)
  {
    if (str == "") return true;
    for(var i = 0; i < str.length; i++) {
      var c = str.charAt(i);
      if ((c != ' ') && (c != '\n') && (c != '\t'))
        return false;
    }
    return true;
  }

  function isValidEmail(str)
  {
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    return filter.test(str);
  }

  function isValidZip(str)
  {
    var filterUS = /(^\d{5}$)|(^\d{5}-\d{4}$)/;                  /* 99999 or 99999-9999*/
    var filterCanada =  /^\D{1}\d{1}\D{1}\-?\d{1}\D{1}\d{1}$/    /* Z5Z-5Z5 orZ5Z5Z5 */
    return filterUS.test(str) || filterCanada.test(str);
  }

  // Expects a valid email address
  function isCasualEmail(str)
  {
    var tempstring ="";

    tempstring = str.split("@");
    tempstring = tempstring[1].split(".");
    for (var i = 0 ; i < invalid_doms.length ; i++)
      if (tempstring[0] == invalid_doms[i])
        return i;  // True
    return -1;  // False
  }
  
  // Expects a valid email address
  function isBannedEmail(str)
  {
    var tempstring ="";

    tempstring = str.split("@");
    tempstring = tempstring[1].split(".");
    for (var i = 0 ; i < blacklist_doms.length ; i++)
      if (tempstring[0] == blacklist_doms[i])
        return i;  // True
    return -1;  // False
  }

  
