// JavaScript Document

//<script> <!--

window.__ua = (window.__ua || new (function() {
		this.use_proto = "http" + (("https:" == document.location.protocol) ? "s" : "");
		this.gen_len = 3;
		this.gen_retry_max = 32;
		this.run_complete = 0;
		this.s = [];
		this.conf = {
				id: "",
				desc: "",
				referer: "",
				zone: "",
				position: "",
				campaign: "",
				advert_id: "",
				time: "",
				uber_host: "",
				no_country: ""
			};

		this.format = function(str) {
				for(var i=1;i<arguments.length;i++) {
					var re = new RegExp('\\{' + (i) + '\\}','gm');
					str = str.replace(re, arguments[i]);
				}
				return str;
			};

		this.genId = function(prefix) {
				if (!prefix) prefix = "UAg";
				var chrs = "abcdef0123456789";
				var ret = "";
				var tries = 0;
				while(tries < this.gen_retry_max && ret == "")
				{
					for (var i=0,j,k;i<this.gen_len;i++) {
						ret += chrs.charAt(Math.ceil(16*Math.random())-1);
					}

					for (var i=0;i<this.s.length;i++) {
						if (this.s[i].id == ret) {
							tries++;
							ret = "";
							break;
						}
					}
				}
				return (((prefix.length > 0) ? (prefix + "-") : "") + ret);
			};

		function UberOp(remote, conf) {
				var sendVals = [ "advert_id", "desc", "referer", "zone", "position", "campaign", "time", "no_country" ];

				this.op_conf = conf;
				this.op_id = remote.genId();
				this.remote = remote;
				this.payload = "";

				for (var i = 0; i < sendVals.length; i++)
				{
					this.op_conf[sendVals[i]] = this.op_conf[sendVals[i]] ? this.op_conf[sendVals[i]] : this.remote.conf[sendVals[i]];

					if (this.op_conf[sendVals[i]] && this.op_conf[sendVals[i]].length != 0)
					{
						if (this.payload.length != 0) this.payload += "&";
						this.payload += escape("_p[" + this.op_id + "][" + sendVals[i] + "]") + "=" + escape(this.op_conf[sendVals[i]]);
					}
				}
			};

		this.run = function() {
				var payload = "";

				if (!this.conf.uber_host || this.conf.uber_host.length == 0)
					this.conf.uber_host = "ua.badongo.com";

				if (this.run_complete == 1) return;
				this.run_complete = 1;

				for (var i = 0; i < this.s.length; i++) {
					if (payload.length != 0) payload += "&";
					payload+=this.s[i].payload;
					
					if (i != 0 && ((i % 4) == 0))
					{
						this.loadScript("UA-scr-" + Math.floor(i / 4), this.use_proto + "://" + this.conf.uber_host + "/js.php?file=ra&" + payload);
						payload = "";
					}
				}

				if (payload != "")
				{
					this.loadScript("UA-scr-end", this.use_proto + "://" + this.conf.uber_host + "/js.php?file=ra&" + payload);
					payload = "";
				}

				window.__uh.hookEm();
			};

		this.getTS = function() {
				with(new Date())
				{
					return "" + getFullYear() + "." + getMonth() + "." + getDate() + "." + getHours() + "." + getMinutes() + "." + getSeconds();
				}

				return "" + Math.ceil(89999999*Math.random()) + 10000000;
			};

		this.preCalc = function(pc_host, pc_opts) {
				var pc_vars = "&_t=" + this.getTS();

				if (!pc_host) return;
				if (!pc_opts) pc_opts = {};

				if (pc_opts.zone)
				{
					pc_vars += "&zone=" + escape(pc_opts.zone);
					this.conf.zone = pc_opts.zone;
				}

				if (pc_opts.desc)
				{
					pc_vars += "&desc=" + escape(pc_opts.desc);
					this.conf.desc = pc_opts.desc;
				}

				if (!pc_opts.referer)
				{
					try { pc_opts.referer = ("" + document.referrer).substring(0,768); }
					catch (c) { pc_opts.referer = ""; }
				}
				if (pc_opts.referer.length != 0)
				{
					this.conf.referer = pc_opts.referer;
					pc_vars += "&referer=" + escape(pc_opts.referer);
				}

				this.loadScript("uapcscr", this.use_proto + "://" + pc_host + "/js.php?file=pze" + pc_vars);
			};

		this.loadScript = function(scr_id, scr_src) {
				var scr = "script";
				var p = this;
				with (document.getElementsByTagName("head")[0].appendChild(document.createElement("script"))) {
					setAttribute("id", scr_id, 0);
					setAttribute("type", "text/javascript", 0);
					setAttribute("src", scr_src, 0);
				}
			};

		this.getOpt = function(name) {
				return this.conf[name];
			};

		this.setOpt = function(name,value) {
				this.conf[name] = value;
			};

		this.showAd = function(conf) {
				if (!conf) conf = {};
				var divCls = "";
				var opIdx = this.s.length;
				var posType = "";
				var vScr = "script";

				if (conf.position)
				{
					var posSplit = conf.position.split("-");

					if (posSplit[1])
					{
						posType = posSplit[1];
					}
				}

				if (posType == "FakeIM" || posType == "Inline" || posType == "Interstitial")
				{
					var imOp = new UberOp(this, conf);
					document.write("<" + vScr + " src=\"" + this.use_proto + "://" + this.conf.uber_host + "/js.php?file=ia&" + imOp.payload + "\"></" + vScr + ">");
				}
				else if (posType == "Leaderboard" || posType == "Leaderboard2" || posType == "Square" || posType == "Extra1" || posType == "Extra2")
				{
					with (new UberOp(this, conf))
					{
						document.write("<" + vScr + " id=\"" + op_id + "\" src=\"" + remote.use_proto + "://" + remote.conf.uber_host + "/js.php?file=rai&" + payload + "\"></" + vScr + ">");
					}
				}
				else
				{
					this.s[opIdx] = new UberOp(this, conf);

					if (conf.divCls && conf.divCls.length != 0)
						divCls = this.format(" class=\"{1}\"", conf.divCls);

					document.write(this.format("<div id=\"{1}\" name=\"{1}\"{2}> </div>", this.s[opIdx].op_id, divCls));
				}
			};

		this.updateAd = function(id, data, dataType) {
				if (dataType != "land")
				{
					document.getElementById(id).innerHTML = null;
					document.getElementById(id).innerHTML = data;
				}
				else
				{
					eval(data);
				}
			};
	}));

window.__uh = (window.__uh || {
	hooks: [],
	winHnd: [],
	winOpt: "toolbar=1,location=1,directories=0,status=0,scrollbars=0,resizable=1,width=720,height=300",

	hookEvent: function(o, e, f) {
		if (o.addEventListener) {
			o.addEventListener(e, f, false);
			return true;
		} else if (o.attachEvent) {
			var r = o.attachEvent("on"+e, f);
			return r;
		} else {
			return false;
		}
	},
	addItem: function(obj) {
			if (!obj) return;
			window.__uh.hooks[window.__uh.hooks.length] = obj;
		},
	doIt: function () {
		var cur_hooks = window.__uh.hooks;
		var hn = cur_hooks.length;

		if (hn > 0)
		{
			// clear the hooks that will be run
			window.__uh.hooks = [];

			var i;
			for (i = 0; i < hn; i++)
			{
				if (typeof(cur_hooks[i].dstUrl) == "string")
				{
					if (cur_hooks[i].dstUrl.length != 0)
					{
						var winOpt = window.__uh.winOpt;

						if (cur_hooks[i].winOpt)
						{
							winOpt = cur_hooks[i].winOpt;
						}

						window.__uh.winHnd[i] = window.open(cur_hooks[i].dstUrl, "bdgp" + Math.floor(Math.random()*99999), winOpt);
						window.focus();
					}
				}
			}
		}
	},
	hookGroup: function (nodes, hookType, recursive) {
		if (nodes && nodes.length)
		{
			var nn;
			nn = nodes.length;
			for (i = 0; i < nn; i++)
			{
				window.__uh.hookIt(nodes[i], hookType, recursive);
			}
		}
	},
	hookIt: function(node, hookType, recursive) {
		if (!node) return;

		// add hook
		window.__uh.hookEvent(node, hookType, window.__uh.doIt);

		if (recursive)
		{
			// walk children
			if (node && node.childNodes && node.childNodes.length)
			{
				var nn = node.childNodes.length
				if (nn && nn > 0)
				{
					var i;
					for (i = 0; i < nn; i++)
					{
						window.__uh.hookIt(node.childNodes[i], hookType, recursive);
					}
				}
			}
		}
	},
	hookEm: function() {
		window.__uh.hookGroup(document.getElementsByTagName("A"), "click");
		window.__uh.hookGroup(document.getElementsByTagName("BODY"), "click");
		window.__uh.hookGroup(document.getElementsByTagName("DIV"), "click");
		window.__uh.hookGroup(document.getElementsByTagName("IMG"), "click");
		window.__uh.hookGroup(document.getElementsByTagName("INPUT"), "click");
		window.__uh.hookGroup(document.getElementsByTagName("SPAN"), "click");
		window.__uh.hookGroup(document.getElementsByTagName("TEXTAREA"), "click");
	}
});

var __w = window;
with(__w.__uh) {
	hookEvent(window, "load", function(e) {
		if (!this.single) this.single = 0;
		if (this.single != 1) __w.__ua.run(e);
		this.single++;
	});
}

