String.prototype.replaceAll = function(strTarget, strSubString){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
  
 	while (intIndexOfMatch != -1){
 		strText = strText.replace( strTarget, strSubString );
 		intIndexOfMatch = strText.indexOf( strTarget );
 	}
	return( strText );
}
function rand (min, max) {
    var argc = arguments.length;
    if (argc === 0) {min = 0;max = 2147483647;} 
    else if (argc === 1) {throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');}
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function locationRedirect(url){setTimeout(function(){window.location = url;},0);}

function strtolower( str ) {return (str+'').toLowerCase();}
function empty(mixed_var) {
    var key;
    
    if (mixed_var === "" || mixed_var === null || mixed_var === false || mixed_var === undefined){key = null; return true;}
 
    if (typeof mixed_var == 'object') {
        for (key in mixed_var){key = null; return false;}
        key = null; return true;
    }
    key = null;
    return false;
}
function clearInnerHTML(obj){while(obj.firstChild) obj.removeChild(obj.firstChild);}

function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i;
    return re.test(email);
} 


function urlencode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) 
  {
	var match = regex.exec(clearString.substr(x));
	if (match != null && match.length > 1 && match[1] != '') 
    	{
		output += match[1];
    		x += match[1].length;
    	} 
	else 
	{
      		if (clearString[x] == ' '){output += '+';}
      		else 
      		{
        		var charCode = clearString.charCodeAt(x);
        		var hexVal = charCode.toString(16);
        		output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
        		
        		charCode = null;
        		hexVal = null;
      		}
      		x++;
    	}
  }
  
  x = null;
  regex = null;
  
  return output;
}


function urldecode (encodedString) {
  var output = encodedString;
  
  if(!empty(output))
  {
	var binVal, thisString;
	var myregexp = /(%[^%]{2})/;
	while ((match = myregexp.exec(output)) != null
		&& match.length > 1
		&& match[1] != '') {
		
	binVal = parseInt(match[1].substr(1),16);
	thisString = String.fromCharCode(binVal);
	output = output.replace(match[1], thisString);
	}
	output = output.replaceAll("+"," ");
  }
  return output;
}

function trim(stringValue){return stringValue.replace(/(^\s*|\s*$)/, "");}
function isNumber(n) {
	return !isNaN(parseFloat(n)) && isFinite(n);
}
