/*upgraded tools1(alix js app 1.0)
requirements : jquery1.4
*/

function lz_global_base64_url_encode(_text) {
	if (_text.length == 0)
		return "";

	_text = lz_global_base64_encode(lz_global_utf8_encode(_text.toString()));
	_text = _text.replace(/=/g, "_");
	_text = _text.replace(/\+/g, "-");
	_text = _text.replace(/\//g, ",");
	return _text;
}
function lz_global_base64_encode(_input) {
	var base64_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	do {
		chr1 = _input.charCodeAt(i++);
		chr2 = _input.charCodeAt(i++);
		chr3 = _input.charCodeAt(i++);

		enc1 = chr1 >> 2;
		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		enc4 = chr3 & 63;

		if (isNaN(chr2))
			enc3 = enc4 = 64;
		else if (isNaN(chr3))
			enc4 = 64;

		output = output + base64_chars.charAt(enc1) + base64_chars.charAt(enc2) +
		  base64_chars.charAt(enc3) + base64_chars.charAt(enc4);
	}
	while (i < _input.length);
	return output;
}
function lz_global_utf8_encode(_string, _encodeuri) {
	_string = _string.replace(/\r\n/g, "\n");
	var utftext = "";
	for (var n = 0; n < _string.length; n++) {
		var c = _string.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if ((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	if (_encodeuri)
		return encodeURIComponent(utftext);
	else
		return utftext;
}

String.prototype.utf8_encode = function (_encodeuri) { lz_global_utf8_encode(this, _encodeuri) }
String.prototype.base64_encode = function () { lz_global_utf8_encode(this) }
String.prototype.base64_url_encode = function () { lz_global_utf8_encode(this) }
String.prototype.left = function (n) {
	return this.substring(0, n)
}
String.prototype.right = function (n) {
	with (this) {
		return substring(length - n)
	}
}
String.prototype.lCase = function () {
	return this.toLowerCase()
}
String.prototype.uCase = function () {
	return this.toUpperCase()
}
String.prototype.myIndexOf = function (find, ofEnd) {
	return this[ofEnd ? 'lastIndexOf' : 'indexOf'](find)
}
//find , after this , 1/0(search of end?)
String.prototype.findAfter = function (find, after, ofEnd) {
	with (this) {
		var fromWhr = myIndexOf(after, ofEnd)
		return indexOf(find, fromWhr >= 0 ? fromWhr : length)
	}
}
//vice versa
String.prototype.findBefore = function (find, before, ofEnd) {
	with (this) {
		var fromWhr = myIndexOf(before, ofEnd)
		return lastIndexOf(find, fromWhr >= 0 ? fromWhr : 0)
	}
}
String.prototype.exist = function (str) {
	return this.indexOf(str) > -1
}
//get substring from a substr to another substr
String.prototype.find2find_substr = function (findStart, findEnd, ofEnd) {
	with (this) {
		var fromWhr = myIndexOf(findStart, ofEnd), toWhr = findAfter(findEnd, findStart);
		if (fromWhr < 0) return ''
		if (toWhr < 0) toWhr = length
		return substring(fromWhr, toWhr)
	}
}
String.prototype.replaceAll = function (oldS, newS) {
	var str = new String(this), oldInd = str.indexOf(oldS)
	while (oldInd > -1) {
		str = str.replace(oldS, newS)
		oldInd = str.indexOf(oldS)
	}
	return str
}
String.prototype.getCurrency = function () {
	var amount = this.replaceAll(",", ""),
		arrParts = new Array();
	while (amount.length) {
		arrParts.unshift(amount.right(3));
		amount = amount.left(amount.length - 3);
	}
	return arrParts.join(",")
}

_t = new function () {
	//ini
	var t = this
	var _conf =
		{
			'_static_path': '/AdminPanel/jscripts/',
			'_static_ext': '.js',
			'_direct_path_sign': '*',
			'_default_env': window
		},
		_tmp =
		{
			'loaded_jscripts': {/*name:1*/
		}
	}
	t.conf = _conf; t.tmp = _tmp
	//ini
	_tmp.loaded_jscripts[_conf._static_path + 'tools' + _conf._static_ext] = 1
	//:relax
	t.isSet = function (obj) { return typeof obj != 'undefined' }
	t.isStr = function (obj) { return typeof obj == 'string' }
	//:gatherers
	t.getEnv = function (whr, def) {
		def = def ? t.isStr(def) ? eval(def) : def : _conf._default_env
		return whr ? t.isStr(whr) ? eval(whr) : whr : def
	}
	//:writer
	t.wrt = function (str, whr, def) {
		if (!(whr = t.getEnv(whr, def))) return false
		var doc = whr.document
		doc.open(); doc.write(str); doc.close()
	}
	//:JS Loader
	t.loadJS = function (src) {
		var src =
			(src.charAt(0) == _conf._direct_path_sign) ? src.substr(1) : _conf._static_path + src + _conf._static_ext
		if (_tmp.loaded_jscripts[src]) return true
		_tmp.loaded_jscripts[src] = 1
		t.wrt('<scr' + 'ipt type="text/javascript" language="javascript" src="' + src + '"></scr' + 'ipt>', window)
	}
	t.animateIn = function ($obj, t, CallBack) {
		if(!t)t=500
		$obj.css({ display: 'inline-block', height: 'auto', visibility:'hidden'})
		var h = $obj.height()
		$obj.css({ display: 'block', height: '0px', opacity: 0, overflow: 'hidden', visibility: 'visible' }).
		animate({ height: h + 'px', opacity: 1 }, t, function () {
			$(this).css({ overflow: 'visible'})
			if(CallBack)CallBack()
		})
	}
	t.animateOut = function ($obj, t, CallBack) {
		var h = $obj.height()
		if (!t) t = 500
		$obj.css({ overflow: 'hidden' }).
		animate({ height: '0px', opacity: 0 }, t, function () {
			$(this).css({ display: 'none', overflow: 'visible' })
			if (CallBack) CallBack()
		})
	}
}

if (typeof ($) == 'undefined') {
	if (typeof (window.top.$) != 'undefined')
		jQuery = $ = window.top.jQuery
	else
		_t.loadJS('jquery-1.4.2.min')
}

