/*
 * js/gallery.js
 */

var p_a = -1;
var h_i = -1;

var h_m = new Array(
	function () {
		return new ActiveXObject('Msxml2.XMLHTTP');
	},
	function () {
		return new ActiveXObject('Microsoft.XMLHTTP');
	},
	function () {
		return new XMLHttpRequest();
	}
);

for (var n = 0; n < h_m.length; n++) {
	try {
		h_m[n]();
		h_i = n;
		break;
	} catch (e) {
	}
}


function e(m) {
	var s = document.getElementById('statusbar');
	s.innerHTML = m;
}

function p(l, n, o, q) {
	if (h_i < 0) {
		return true;
	}

	new _p(l, n, o, q);
	return false;
}

function _p(l, n, o, q) {
	var req = this;

	//this.i = i;
	//this.j = j;
	this.n = n;
	this.o = o;
	this.q = q;
		
	this.h = h_m[h_i]();
	this.h.onreadystatechange = function () {
		b(req);
	};
	this.h.open('GET', l + '&js=1&target=' + n, true);
	this.h.send(null);

	return false;
}

function splitCode(str) {
        var strEntryArray = str.split('<separator>');
        this.brandvalue = strEntryArray[0];
        this.othercode = strEntryArray[1];
	this.firstvalue = strEntryArray[2];
}

function b(req) {
	if (req.h.readyState != 4) {
		return;
	}

	if (req.h.status == 200) {
		var code = req.h.responseText;
		//var p = document.getElementById('p' + req.i);
		/*if (p) {
			p.className = '';
		}*/

		/*if (p_a > 0) {
			p = document.getElementById('p' + p_a);
			p.className = '';
		}*/

		/*var p = document.getElementById('p' + req.j);
		p.className = 'active';
		p_a = req.j;
		*/
		var pe = document.getElementById(req.n);
		var newcode = splitCode(code);

		if (this.othercode) {
			pe.innerHTML = this.othercode;
		} else {
			pe.innerHTML = code;
		}

		if (req.o && req.q) {
			req.o = req.o + this.brandvalue;
			p(req.o, req.q);
		}
	} else {
		e('HTTP hiba történt (' + req.h.status + ')');
	}

	delete req;
}
