// JavaScript Document

function AjaxLoading(url_relative, padding) {
	var result = "<div class=\"ajax_load\" style=\"padding: " + padding + "px 0px " + padding + "px 0px;\"><img src=\"" + url_relative + "images/web/ajax_load.gif\" alt=\"loading...\" /></div>"
	return result;
}

function ClickTab(div_tab_parent, div_tab_child, div_content_parent, div_content_child) {
	for (i = 1; i <= 10; i++) {
		if (document.getElementById(div_tab_parent + "_" + i)) {
			document.getElementById(div_tab_parent + "_" + i).className = "tab";
		}
	}
	document.getElementById(div_tab_child).className = "tab active";
	if (document.getElementById(div_content_child)) {
		document.getElementById(div_content_parent).innerHTML = document.getElementById(div_content_child).innerHTML;
	}
}

function ChangeDiv(div_parent, div_child) {
	if (document.getElementById(div_child)) {
		document.getElementById(div_parent).innerHTML = document.getElementById(div_child).innerHTML;
	}
}

function ChangeBanner(div, id, total, delay) {
	document.getElementById(div).innerHTML = document.getElementById(div + "_" + id).innerHTML;
	if (total > 1) {
		setTimeout("ChangeBanner('" + div + "', " + ((id + 1) % total) + ", " + total + ", " + delay + ");", delay);
	}
}

function BannerPopup(id) {
	var xmlHttp = GetXmlHttpObject();
	if (!xmlHttp) {
		return;
	}
	var url = "../include/ajax_banner.php";
	var par = "id=" + id + "&mr=" + Math.random();
	OpenPopUp(500, 480);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			var arr_xmlHttp = xmlHttp.responseText.split("|=|");
			document.getElementById("div_popup_title").innerHTML = arr_xmlHttp[0];
			document.getElementById("div_popup_content").innerHTML = arr_xmlHttp[1];
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", par.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(par);
}

function CheckKey(e, reg) {
	var key = window.event ? e.keyCode : e.charCode;
	var keychar = String.fromCharCode(key);

	return reg.test(keychar);
}

function TextAreaCounter(obj, maxlimit) {
	if (obj.value.length > maxlimit) {
		obj.value = obj.value.substring(0, maxlimit);
	}
}

function UrlEncode(str) {
	var result = str;

	result = escape(result);
	result = result.replace(/\*/g, "%2A");
	result = result.replace(/\+/g, "%2B");
	result = result.replace(/\//g, "%2F");
	result = result.replace(/\@/g, "%40");
	result = result.replace(/\%20/g, "+");

	return result;
}

function UrlDecode(str) {
	var result = str;

	result = result.replace(/\+/g, " ");
	result = unescape(result);

	return result;
}

function number_format(number) {
	var number2 = (number == "") ? "0" : number;
	var result = new String (parseInt(number2));
	var i;
	for (i = 5; i > 0; i--) {
		if (result.length > i * 3) {
			result = result.substring(0, result.length - (i * 3)) + "." + result.substring(result.length - (i * 3), result.length);
		}
	}

	return result;
}

function AddOnloadEvent(fnc) {
	if (typeof window.addEventListener != "undefined" ) {
		window.addEventListener("load", fnc, false);
	} else if (typeof window.attachEvent != "undefined" ) {
		window.attachEvent("onload", fnc);
	} else {
		if (window.onload != null) {
			var old_onload = window.onload;
			window.onload = function (e) {
				old_onload(e);
				window[fnc]();
			};
		} else {
			window.onload = fnc;
		}
	}
}

