// Array Extensions  v1.0.5
// http://www.dithered.com/javascript/array/index.html
// code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
//
// Netscape 4 introduced a few new methods for the Array object which were not supported by 
// Internet Explorer until the release of version 5.5. This script extends the Array object 
// in Internet Explorer 4.x and 5.0 so that these methods are also available in that family 
// of browsers. The script also allows the use of core Javascript 1.2 Array methods in browsers 
// that support Javascript 1.1.


function isUndefined(property) {
  return (typeof property == 'undefined');
}


// Array.concat() - Join two arrays
if (isUndefined(Array.prototype.concat) == true) {
  Array.prototype.concat = function (secondArray) {
  	var firstArray = this.copy();
  	for (var i = 0; i < secondArray.length; i++) {
  		firstArray[firstArray.length] = secondArray[i];
  	}
  	return firstArray;
  };
}

// Array.copy() - Copy an array
if (isUndefined(Array.prototype.copy) == true) {
  Array.prototype.copy = function() {
  	var copy = new Array();
  	for (var i = 0; i < this.length; i++) {
  		copy[i] = this[i];
  	}
  	return copy;
  };
}

// Array.pop() - Remove the last element of an array and return it
if (isUndefined(Array.prototype.pop) == true) {
  Array.prototype.pop = function() {
  	var lastItem = null;
    if ( this.length > 0 ) {
        lastItem = this[this.length - 1];
        this.length--;
    }
    return lastItem;
  };
}

// Array.push() - Add an element to the end of an array
if (isUndefined(Array.prototype.push) == true) {
  Array.prototype.push = function() {
  	var currentLength = this.length;
  	for (var i = 0; i < arguments.length; i++) {
  		this[currentLength + i] = arguments[i];
  	}
  	return this.length;
  };
}

// Array.shift() - Remove the first element of an array and return it
if (isUndefined(Array.prototype.shift) == true) {
  Array.prototype.shift = function() {
  	var firstItem = this[0];
  	for (var i = 0; i < this.length - 1; i++) {
  		this[i] = this[i + 1];
  	}
  	this.length--;
  	return firstItem;
  };
}

// Array.slice() - Copy several elements of an array and return them
if (isUndefined(Array.prototype.slice) == true) {
  Array.prototype.slice = function(start, end) {
  	var temp;
  	
  	if (end == null || end == '') end = this.length;
  	
  	// negative arguments measure from the end of the array
  	else if (end < 0) end = this.length + end;
  	if (start < 0) start = this.length + start;
  	
  	// swap limits if they are backwards
  	if (end < start) {
  		temp  = end;
  		end   = start;
  		start = temp;
  	}
  	
  	// copy elements from array to a new array and return the new array
  	var newArray = new Array();
  	for (var i = 0; i < end - start; i++) {
  		newArray[i] = this[start + i];
  	}
  	return newArray;
  };
}

// Array.splice() - Splice out and / or replace several elements of an array and return any deleted elements
if (isUndefined(Array.prototype.splice) == true) {
  Array.prototype.splice = function(start, deleteCount) {
  	if (deleteCount == null || deleteCount == '') deleteCount = this.length - start;
  	
  	// create a temporary copy of the array
  	var tempArray = this.copy();
  	
  	// Copy new elements into array (over-writing old entries)
  	for (var i = start; i < start + arguments.length - 2; i++) {
  		this[i] = arguments[i - start + 2];
  	}
  	
  	// Copy old entries after the end of the splice back into array and return
  	for (var i = start + arguments.length - 2; i < this.length - deleteCount + arguments.length - 2; i++) {
  		this[i] = tempArray[i + deleteCount - arguments.length + 2];
  	}
  	this.length = this.length - deleteCount + (arguments.length - 2);
  	return tempArray.slice(start, start + deleteCount);
  };
}

// Array.unshift - Add an element to the beginning of an array
if (isUndefined(Array.prototype.unshift) == true) {
  Array.prototype.unshift = function(the_item) {
  	for (loop = this.length-1 ; loop >= 0; loop--) {
  		this[loop+1] = this[loop];
  	}
  	this[0] = the_item;
  	return this.length;
  };
}







// javascript email validator
function validemail(str) {
	return(/^[-_.a-zA-Z0-9]+@((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i.test(str));

}



// javascript trim functions, thanks to http://www.vermontsoftware.com/
function LTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++;
		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) {
		var i = s.length - 1;
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;
		s = s.substring(0, i+1);
	}
	return s;
}

function Trim(str) {
	return RTrim(LTrim(str));
}