function validateEmail(emailField) {
   // Validate email address
   var str = emailField.value;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid email address.");
                   emailField.value = "";
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid email address.");
                   emailField.value = "";
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Please enter a valid email address.");
                   emailField.value = "";
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Please enter a valid email address.");
                   emailField.value = "";
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Please enter a valid email address.");
                   emailField.value = "";
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Please enter a valid email address.");
                   emailField.value = "";
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Please enter a valid email address.");
                   emailField.value = "";
		    return false;
		 }

 		 return true;
}

function validatePhone(phoneField, format) {
   // Validate phone number for 10 digit US numbers.
   // phoneField - The HTML input field containing the phone number to validate.
   // format - Integer value that defines how to format the text field.
   var num = phoneField.value.replace(/[^\d]/g,'');
   if(num.length != 10) {
        //Alert the user that the phone number entered was invalid.
        alert('Please enter a valid 10 digit phone number including your area code. If you are located outside the U.S., please enter the first ten digits of your phone number in the phone field and then include your complete telephone number in the comments section.');
        phoneField.value = "";
   } else {
        //Email was valid.  If format type is set, format the Phone to the desired style.
      switch(format) {
            case '0': //Format (xxx) xxx-xxxx
               phoneField.value = "(" + num.substring(0,3) + ") " + 
                                    num.substring(3, 6) + "-" + num.substring(6);
               break;
            case '1': //Format xxx-xxx-xxxx
               phoneField.value = num.substring(0,3) + "-" + 
                                    num.substring(3, 6) + "-" + num.substring(6);
               break;
            default: //Format xxxxxxxxxx
               phoneField.value = num;
               break;
        }
   }
}

function getElementsByClass(node,searchClass,tag) {
    var classElements = new Array();
    var els = node.getElementsByTagName(tag); // use "*" for all elements
    var elsLen = els.length;
    var pattern = new RegExp("\\b"+searchClass+"\\b");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function showNumberOfClasses(className) {
    var el = getElementsByClass(document,className,'*');
    alert(el.length);
}

      function indexInLiteral(str, index) {
        var inStrLiteral = 0;
        var inObjLiteral = 0;
        var inArrayLiteral = 0;

        for (var i = 0; i < str.length; i++) {
          if (inStrLiteral) {
            if (str.charAt(i) == "'" || str.charAt(i) == '"') {
              inObjLiteral--;
            }
          } else {
            if (str.charAt(i) == "'" || str.charAt(i) == '"') {
              inObjLiteral++;
            }
          }
          if (!inStrLiteral) {
            if (inObjLiteral) {
              if (i == index) {
                return (true);
              }
              if (str.charAt(i) == "}") {
                inObjLiteral--;
              }
            } else {
              if (str.charAt(i) == "{") {
                inObjLiteral++;
              }
            }
            if (inArrayLiteral) {
              if (i == index) {
                return (true);
              }
              if (str.charAt(i) == "]") {
                inArrayLiteral--;
              }
            } else {
              if (str.charAt(i) == "[") {
                inArrayLiteral++;
              }
            }
          }
        }

        return (false);
      }

      function getLocals(args) {
        var ret = [];
        var reArg = /\(?\s*(\w+)\s*(,|\))/g;
        var reEndArg = /\{/;
        var reHasVar = /(\W|^)var\W/;
        var reGetVar = /(var|,)\s*(\w+)/g;
        var lookForArgs = true;
        var reResult;
        var a;

        if (typeof args == 'function' ) {
          a = args.toString().split("\n");
        } else {
          a = (args) ? args.callee.toString().split("\n") : [];
        }

        ret.push(a[0]); // save the function name for later use
        
        for (var i = 0; i < a.length; i++) {
          if (lookForArgs) {
            reArg.lastIndex = 0;
            while ((reResult = reArg.exec(a[i])) != null) {
              ret.push(reResult[1]);
            }
            reEndArg.lastIndex = 0;
            if (reEndArg.test(a[i])) {
              lookForArgs = false;
            }
          }
          if (!lookForArgs) {
            reHasVar.lastIndex = 0;
            if (reHasVar.test(a[i])) {
              reGetVar.lastIndex = 0;
              while ((reResult = reGetVar.exec(a[i])) != null) {
                if (!indexInLiteral(a[i], reResult.index)) { 
                  ret.push(reResult[2]);
                }
              }
            }
          }
        }
        return (ret);
      }

      function getLocalsOfType(args,type) {
        var ret = [];
        var reArg = /\(?\s*(\w+)\s*(,|\))/g;
        var reEndArg = /\{/;
        var reHasVar = /(\W|^)var\W/;
        var reGetType = /(?:Fx.Slide)/g;
        var reGetVar = /(var|,)\s*(\w+)/g;
        var lookForArgs = true;
        var reResult;
        var reResultType;
        var a;

        if (typeof args == 'function' ) {
          a = args.toString().split("\n");
        } else {
          a = (args) ? args.callee.toString().split("\n") : [];
        }

        ret.push(a[0]); // save the function name for later use
        
        for (var i = 0; i < a.length; i++) {
          //alert(reGetType.exec(a[i]));
          if (lookForArgs) {
            reArg.lastIndex = 0;
            while ((reResult = reArg.exec(a[i])) != null) {
              ret.push(reResult[1]);
            }
            reEndArg.lastIndex = 0;
            if (reEndArg.test(a[i])) {
              lookForArgs = false;
            }
          }
          if (!lookForArgs) {
              if (reGetType.exec(a[i]) == type) {
                reHasVar.lastIndex = 0;
                if (reHasVar.test(a[i])) {
                  reGetVar.lastIndex = 0;
                  while ((reResult = reGetVar.exec(a[i])) != null) {
                    if (!indexInLiteral(a[i], reResult.index)) { 
                      ret.push(reResult[2]);
                    }
                  }
                }
              }
          }
        }
        return (ret);
      }

      function showLocals(func, args) {
        var str = "Variables for ";
        var arrayOfLocals = getLocals(args);
        var v;

        for (var i = 0; i < arrayOfLocals.length; i++) {
          if (i == 0) {
            str += arrayOfLocals[i] + "\n";
          } else {
            if (typeof func == 'function') {
              v = func(arrayOfLocals[i]);
              if (typeof v == 'string') {
                v = '"' + v + '"';
              }
              str += "    " + arrayOfLocals[i] + " = " + v + "\n";
            } else {
              str += "    " + arrayOfLocals[i] + "\n";
            }
          }
        }
        alert(str);
      }

      function doItInside(s) { 
        var x = 5, y = 9;
        var re = /^test$/;

        for (var i = 0; i < 5; i++) {
          var arr = [ 2, 4, 6, 8 ];

          if (arr[i] == i) {
            break;
          }
        }

        var ob = { x: 7, y: 5 };

        showLocals(function($$$$){return(eval($$$$))}, arguments);
      }

      var outsideCheckerFunc;
      function doItOutside(str_param, num_param) {
        var timer = 100;
        outsideCheckerFunc = function($$$$){return(eval($$$$))};

        var f = function(){alert("hi")};
        var a = 55, b = 66, c = 77;
        var regE = new RegExp("^s*tart?");
      }

      function doItOutsideCaller(withEvalFunc) {
        if (withEvalFunc) {
          doItOutside('test param string', 9);
          showLocals(outsideCheckerFunc, doItOutside);
        } else {
          showLocals(null, doItOutside);
        }
      }


/* Returns the class name of the argument or undefined if
   it's not a valid JavaScript object.
*/
function getObjectClass(obj) {
    if (obj && obj.constructor && obj.constructor.toString) {
        var arr = obj.constructor.toString().match(
            /function\s*(\w+)/);

        if (arr && arr.length == 2) {
            return arr[1];
        }
    }

    return undefined;
}

// changes color of an element
function changecolor(id, color) {
    element = document.getElementById(id);
    event.cancelBubble = true;
    oldcolor = element.currentStyle.background;
    element.style.background = color;
}

function GetElement(id){
    if(document.all){
        return document.all[id];
    }else {
        return document.getElementById(id);
    }
}

