/* 
 * More info at: http://kevin.vanzonneveld.net/techblog/category/php2js
 * 
 * php.js is copyright 2008 Kevin van Zonneveld.
 * 
 * Portions copyright Ates Goral (http://magnetiq.com), Legaev Andrey,
 * _argos, Jonas Raoni Soares Silva (http://www.jsfromhell.com),
 * Webtoolkit.info (http://www.webtoolkit.info/), Carlos R. L. Rodrigues, Ash
 * Searle (http://hexmen.com/blog/), Tyler Akins (http://rumkin.com), mdsjack
 * (http://www.mdsjack.bo.it), Alexander Ermolaev
 * (http://snippets.dzone.com/user/AlexanderErmolaev), Andrea Giammarchi
 * (http://webreflection.blogspot.com), Bayron Guevara, Cord, David, Karol
 * Kowalski, Leslie Hoare, Lincoln Ramsay, Mick@el, Nick Callen, Peter-Paul
 * Koch (http://www.quirksmode.org/js/beat.html), Philippe Baumann, Steve
 * Clay, booeyOH
 * 
 * Licensed under the MIT (MIT-LICENSE.txt) license.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES 
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/* numberFormat [php.js]
 **************************************************************************************************************
 */
numberFormat = function(number, decimals, decPoint, thouSeparator) {
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = decPoint == undefined ? "," : decPoint;
	var t = thouSeparator == undefined ? "." : thouSeparator, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	
	return s + (j ? i.substr(0, j) + t : "") +
					i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) +
					(c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

/* array [php.js]
 **************************************************************************************************************
 */
array = function() {
	return Array.prototype.slice.call(arguments);
}

/* intval [php.js]
 **************************************************************************************************************
 */
intval = function(mixedVar, base) {
	var tmp;
	
	if(typeof(mixedVar) == 'string') {
		tmp = parseInt(mixedVar * 1);
		if(isNaN(tmp) || !isFinite(tmp)) {
			return 0;
		} else {
			return tmp.toString(base || 10);
		}
	} else if(typeof(mixedVar) == 'number' && isFinite(mixedVar)) {
		return Math.floor(mixedVar);
	} else {
		return 0;
	}
}

/* strReplace [php.js]
 **************************************************************************************************************
 */
strReplace = function(search, replace, subject) {
	var f = search, r = replace, s = subject;
	var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
	
	while(j = 0, i--) {
		if(s[i]) {
			while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f) {};
		}
	};

	return sa ? s : s[0];
}

/* empty [php.js]
 **************************************************************************************************************
 */
empty = function(mixedVar) {
	var key;
	
	if(mixedVar === "" || mixedVar === 0 || mixedVar === "0" || mixedVar === null || mixedVar === false || mixedVar === undefined) {
		return true;
	}
	
	if(typeof mixedVar == 'object') {
		for(key in mixedVar) {
			if(typeof mixedVar[key] !== 'function' ) {
				return false;
			}
		}
		return true;
	}
	
	return false;
}

/* time
 **************************************************************************************************************
 */
time = function() {
	var oDate = new Date();
	var iSeconds = oDate.getTime();
	
	return iSeconds;
}
