function byID(id)
{
	if(document.getElementById(id)) return document.getElementById(id);
	else return false;
}

function loadXML(url)
{
	var mozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
	var ie = (typeof window.ActiveXObject != 'undefined');
	if(mozilla)
    {
	    this.xmlDoc = document.implementation.createDocument("", "", null);
	    this.xmlDoc.strictErrorChecking = false;
	    this.xmlDoc.async = false;
	    this.fail = false;
    }
	else if(ie)
    {
	    this.xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	    this.xmlDoc.async = false;
	    while(this.xmlDoc.readyState != 4) {};
	    this.fail = false;
    }
	else
    {
	    this.xmlDoc = '';
	    this.fail = true;
    }
	if(this.fail != true)
    {
	    try
	    {
	        this.xmlDoc.load(url)
	    }
	    catch(e)
	    {
	        this.fail = true;
	    }
	}
}

function updateIstallo(id)
{	var xml=new loadXML(cleanDomain+'ajax_istallo.php?id='+id);
	if(xml.fail!=false)
	{		//console.log('betöltés sikertelen')	}
	//else console.log('betöltve');

	var x=xml.xmlDoc.getElementsByTagName('istallo');
	//console.log('x: ',print_r(x));
	byID('istalloarckep').src=x[0].getElementsByTagName('arckep')[0].firstChild.nodeValue;
	byID('istallonev').innerHTML=x[0].getElementsByTagName('istallonev')[0].firstChild.nodeValue;	byID('istalloszamnagy').innerHTML=x[0].getElementsByTagName('istalloszam')[0].firstChild.nodeValue;
	byID('istallobovebblink').href=x[0].getElementsByTagName('istallolink')[0].firstChild.nodeValue;
}

function updateNav(id)
{
	$.get(cleanDomain+"ajax_istallo.php?nav="+id, function(data)
	{
		$("div#savkozep").html(data);
	})
}


function setAktivIstallo(id)
{
	updateNav(id);	updateIstallo(id);
	byID('istallonav'+aktivIstallo).className='savelem';
	byID('istallonav'+id).className='savelemaktiv';
	aktivIstallo=id;}

function nextIstallo()
{	aktI=parseInt(aktivIstallo);
	
	var nextI;
	$.get(cleanDomain+"ajax_istallo.php?next="+aktI, function(data)
	{

		nextI=data;
		
		setAktivIstallo(nextI);
		aktivIstallo=nextI;		
		
	});	}

function prevIstallo()
{
	aktI=parseInt(aktivIstallo);
		var prevI;
	$.get(cleanDomain+"ajax_istallo.php?prev="+aktI, function(data)
	{

		prevI=data;
		
		setAktivIstallo(prevI);
		aktivIstallo=prevI;
	});
}

function swapImage(id)
{	var kep=new Image();
	kep.src='images/galeria/'+galeria[id];
	kep.onload=function(){		byID('nagykep').src=kep.src;
		byID('kepalairas').innerHTML=byID('galerialink'+id).title;

		}}

function print_r(x, max, sep, l) {

	l = l || 0;
	max = max || 10;
	sep = sep || ' ';

	if (l > max) {
		return "[WARNING: Too much recursion]\n";
	}

	var
		i,
		r = '',
		t = typeof x,
		tab = '';

	if (x === null) {
		r += "(null)\n";
	} else if (t == 'object') {

		l++;

		for (i = 0; i < l; i++) {
			tab += sep;
		}

		if (x && x.length) {
			t = 'array';
		}

		r += '(' + t + ") :\n";

		for (i in x) {
			try {
				r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1));
			} catch(e) {
				return "[ERROR: " + e + "]\n";
			}
		}

	} else {

		if (t == 'string') {
			if (x == '') {
				x = '(empty)';
			}
		}

		r += '(' + t + ') ' + x + "\n";

	}

	return r;

};


