var theDoc = null;

if (!Array.prototype.push) Array.prototype.push = new Function('elem', 'var index=this.length;this[index]=elem;return index;');

var app = navigator.appName;
var ver = parseInt(navigator.appVersion.substring(0, 1));
var is_ie4 = ((app == "Microsoft Internet Explorer") && (ver >= 4)); //browser_check && ((document.all)    ? true : false);
var is_ie5 = ((app == "Microsoft Internet Explorer") && (ver >= 5));
var is_ie6 = (navigator.appVersion.indexOf("MSIE 6")!=-1);
var is_ie7 = (navigator.appVersion.indexOf("MSIE 7")!=-1);
var is_ie = is_ie4 || is_ie5 || is_ie6 || is_ie7;
var is_ns = ((app == "Netscape") && (ver >= 3)); //browser_check && ((document.layers) ? true : false);
var browser_check = is_ie4 || is_ns;

function MIN(a, b) { return (a < b) ? a : b; };
function MAX(a, b) { return (a > b) ? a : b; };
function BOUND(a, min, max) { return (a < min) ? min : (a > max) ? max : a; };

function RAW_COPY(id, app) { var res = ""; var ttt = document.all[id]; if (!ttt) return res; if (app) ttt.insertAdjacentHTML("BeforeEnd", app); res = ttt.outerHTML; ttt.style.visibility = "hidden"; return res; };
function CreateElement(type, id, style, cls, parent) { if (!theDoc) theDoc = document; var res = theDoc.createElement(type); if (!res) return null; res.id = id; if (style) ApplyStyles(res, style); if (cls) res.className = cls; if (parent) parent.appendChild(res); return res; };
function ApplyStyles(obj, styles) { var temp = styles; while (temp.length > 0) { var i = temp.indexOf(":"); var style_name = temp.substring(0, i); var ii = style_name.indexOf("-"); if (ii != -1) { var ttt = style_name.substring(0, ii); ttt += style_name.substring(ii + 1, ii + 2).toUpperCase(); ttt += style_name.substring(ii + 2, style_name.length); style_name = ttt; }; var j = temp.indexOf(";"); var value = temp.substring(i + 1, j); temp = temp.substring(j + 1, temp.length); eval('obj.style.' + style_name + '=' + '"' + value + '"'); }; return true; };

function nop() { event.cancelBubble = true; event.returnValue = false; return false; };

//** array functions
function getFirstElem(obj) {
	if (obj instanceof Array)
		return obj[0];
	else
		return obj;
};
function formArray(obj) {
	var res = new Array();
	try {
		if (obj instanceof Array || (String(obj.length) != "undefined" && obj.length != 0)) {
			for (var i = 0; i < obj.length; i++) {
				res[i] = obj[i];
			};
		} else {
			res.length = 1;
			res[0] = obj;
		};
	} catch (err) {
		res.length = 1;
		res[0] = obj;
	};
	return res;
};

//** single-element DOM functions
function findElement(parent, tagName, id) { return (is_ie4) ? getFirstElem(parent.all[id]) : findNamedItem(parent.getElementsByTagName(tagName), id); };
function findNamedItem(nodeList, id) {
	for (var i = 0; i < nodeList.length; i++) {
		var node = nodeList.item(i);
		if (node.id == id || node.name == id) return node;
	};
	return null;
};

//** multiple-element DOM functions
function findElements(parent, tagName, id) { return (is_ie4) ? formArray(parent.all[id]) : findNamedItems(parent.getElementsByTagName(tagName), id); };
function findNamedItems(nodeList, id) {
	var result = new Array();
	for (var i = 0; i < nodeList.length; i++) {
		var node = nodeList.item(i);
		if (node.id == id || node.name == id) result.push(node);
	};
	return result;
};

/////////////////////////////////////////////////////////////////////
function clientcontrolclick(element) {
	if (element.click) {
		element.click();
	}
	else {
		var href = element.href;
		//strip off the leading 'javascript:'
		var func;

		if (href.indexOf('javascript:') > -1)
			func = href.substr(11);
		else
			func = href;

		if (func.substr(0, 3) == '%20')
			func = func.substr(3);

		eval(func);
	}
}


//** URL functions
function ConcatURL(baseURL, concatURL) {
	var res = String(baseURL), toConcat = String(concatURL);
	if (toConcat.length > 0 && toConcat != "" && toConcat != "undefined") {
		var app_sign = (res.indexOf("?") != -1) ? "&" : "?";
		if ((toConcat.charAt(0) == "?") || (toConcat.charAt(0) == '&'))
			toConcat = toConcat.substring(1, toConcat.length);

		res += app_sign + toConcat;
	};
	return res;
}

function ConcatURLWoQMark(baseURL, concatURL) {
	var res = String(baseURL), toConcat = String(concatURL);
	if (toConcat.length > 0 && toConcat != "" && toConcat != "undefined") {
		var app_sign = (res.indexOf("?") != -1) ? "&" : "";
		if ((toConcat.charAt(0) == "?") || (toConcat.charAt(0) == '&'))
			toConcat = toConcat.substring(1, toConcat.length);

		res += app_sign + toConcat;
	};
	return res;
}

function SetURLValue(baseURL, paramName, paramValue) {
	var url = String(baseURL);
	var res = "";
	var testRG = new RegExp("[?&]?(" + paramName + "=[^&]*)(&|$)", "g");
	if (url.search(testRG) != -1) {
		res = url.replace(RegExp.$1, paramName + "=" + paramValue);
	} else {
		res = ConcatURL(baseURL, paramName + "=" + paramValue);
	};
	return res;
}

function SetURLValueWoQMark(baseURL, paramName, paramValue) {
	var url = String(baseURL);
	var res = "";
	var testRG = new RegExp("[?&]?(" + paramName + "=[^&]*)(&|$)", "g");
	if (url.search(testRG) != -1) {
		res = url.replace(RegExp.$1, paramName + "=" + paramValue);
	} else {
		res = ConcatURLWoQMark(baseURL, paramName + "=" + paramValue);
	};
	return res;
}

function RoundPrec(fltNum, prec) {
	prec = Math.pow(10, prec);
	return Math.round(fltNum * prec) / prec;
}

function OpenWindow(width, height, url) {
	var left = 50, top = 50;
	try {
		left = Math.floor(((window.screen.availWidth - width) / 3));
		top = Math.floor(((window.screen.availHeight - height) / 3));
	} catch (e) { }
	var sFeatures = "resizable=no,scrollbars=0,toolbar=0,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height;
	var oWnd = window.open(url, "text_popup", sFeatures);
	oWnd.focus();
}

function ReplaceIETransparentPngs() {
	if (!((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion.substring(0, 1)) >= 4))) return;
	function t(e, img) { var f = e.currentStyle.filter; f += "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img + "',sizingMethod='crop');"; e.runtimeStyle.filter = f; };
	var el = document.body.all; if (!el) return;
	for (var i = 0; i < el.length; i++) {
		var e = el[i];
		if (e.nodeName == "IMG") {
			if (e.src.indexOf("_trnsp.png") != -1) { var img = e.src; e.src = "img/z.png"; t(e, img); }
		}
		if (e.nodeName == "DIV" || e.nodeName == "TD" || e.nodeName == "TABLE" || e.nodeName == "DD") {
			if (e.currentStyle.backgroundImage == "") continue;
			if (e.currentStyle.backgroundImage.indexOf("_trnsp.png") != -1) { var img = e.currentStyle.backgroundImage.replace('url("', '').replace('")', ''); e.runtimeStyle.background = ""; t(e, img); }
		}
	}
}

function Trim(str) {
	str = str.replace(/^\s+/g, "");
	str = str.replace(/\s+$/g, "");
	return str;
};


