String.prototype.trim = function() { return( this.replace(/(^\s+)|(\s+$)/g, "") ); } String.prototype.is_email = function() { return( /.*@.*\..+/.test(this) ); } Array.prototype.in_array = function(val) { var i, len = this.length; var isarr = (typeof val == "object" && typeof val.in_array != "undefined"); for (i = 0; i < len; i++) { if ( isarr && val.in_array(this[i]) ) return( true ); else if ( !isarr && this[i] == val ) return( true ); } return( false ); } Array.prototype.hasValue = function( val , checkType ) { var i, len = this.length; for (i = 0; i < len; i++) if ( (checkType && this[i] === val) || (!checkType && this[i] == val) ) return( i ); return( false ); } Array.prototype.randomize = function() { var temp, arr = [], hold = this; var len = this.length, temp_len, rand, i; while ( len > 0 ) { rand = Math.floor(Math.random() * len); arr.push( hold[rand] ); temp = []; temp_len = hold.length; for ( i = 0; i < temp_len; i++ ) if ( i != rand ) temp.push( hold[i] ); hold = temp; len = hold.length; } return( arr ); } function get_event(e) { var obj = e; if ( window.event ) { obj.layerX = e.offsetX; obj.layerY = e.offsetY; obj.target = e.srcElement; obj.preventDefault = function() { event.returnValue = false; } obj.stopPropagation = function() { event.cancelBubble = true; } } return( obj ); } function get_node_info(node) { var xPos = 0, yPos = 0, width = 0, height = 0, srcNode = node; while ( node.nodeType == 1 ) { if (node.tagName != "TR") { xPos += node.offsetLeft; yPos += node.offsetTop; } if ( node.offsetParent ) node = node.offsetParent; else break; } if (typeof srcNode.offsetWidth != "undefined") { width = srcNode.offsetWidth; height = srcNode.offsetHeight; } else if (typeof srcNode.width != "undefined") { width = srcNode.width; height = srcNode.height; } return( { x : xPos , y : yPos , w : width , h : height } ); } function set_caret_position(node, startpos, endpos) { if ( document.selection ) // IE Support { node.focus(); var range = document.selection.createRange (); range.moveStart ('character', -node.value.length); range.moveStart ('character', startpos); range.moveEnd ('character', endpos); range.select(); } else if ( node.selectionStart || node.selectionStart == '0' ) { // Firefox support node.selectionStart = startpos; node.selectionEnd = endpos; node.focus(); } } function check_username(str) { var err = []; var min_chars = 5; //var max_chars = 20; if ( str.trim() == "" ) return( true ); var strlen = str.length; if ( strlen > 0 && strlen < min_chars ) err.push("Your username must have at least "+ min_chars +" characters. Your username currently uses "+ strlen); //else if ( strlen > max_chars ) //err.push("Your username cannot have more than "+ max_chars +" characters. Your username currently uses "+ strlen); if ( err.length > 0 ) { alert( "Your username does not meet the following criteria:\n\n"+ err.join("\n") ); return( false ); } else return( true ); } function check_password(str) { if ( str.trim() == "" ) return( true ); var err = []; var min_chars = 7; var max_chars = 20; if ( !(/[0-9]/.test(str)) ) err.push("Password does not contain at least one numeric character."); if ( !(/[A-Z]/i.test(str)) ) err.push("Password does not contain at least one alphabetic character."); if ( str.length < min_chars ) err.push("Password is too short; the minimum password length is "+ min_chars +" characters."); else if ( str.length > max_chars ) err.push("Password is too long; the maximum password length is "+ max_chars +" characters."); if ( err.length > 0 ) { alert( "Your password does not meet the following criteria:\n\n\t"+ err.join("\n\t") ); return( false ); } else return( true ); }