// függőségek
if ("undefined" == typeof AITIA) {
	alert("AITIA include missing!");
} else if ("undefined" == typeof AITIA_COOKIE) {
	alert("AITIA_COOKIE include missing!");
}

// tĂśbbszĂśrĂśs include
if ("undefined" != typeof AITIA_URL) {
	 alert("AITIA_URL multiple insert!");
}

AITIA_URL = 1;

Aitia.Url = {};

/** ez visszaadja a get parametereket egy tombben
  * @param empty ha true, akkor ures parametereket is visszaadja, default: true
  * @return egy tomb, melyben nevvel lehet elerni a kulcsokat
  */
Aitia.Url.parseLocationSearch = function(empty) {
  var empty=(empty != null) ? empty : true;
  var ret=new Array();
  var search=location.search;

  if (search != '') {
    search=search.substr(1);  //? levagasa
    search=unescape(search);
    var t=search.split('&');
    for (var i=0; i<t.length; ++i) {
      if (t[i]) {
        var t2=t[i].split('=');
        if (empty || t2[1]) {
          //ha uresek is kellenek, akkor mindenkeppen kell
          //amugy csak akkor, ha nem ures
          ret[t2[0]]=t2[1];
        }
      }
    }
  }
  
  return ret;
} // parseLocationSearch


/** A PHPSESSID erteket adja vissza vagy get-bol, vagy cookie-bol
  * @param sessionName opcialisan megadhato, hogy milyen nevu valtozot keressen, def: PHPSESSID
  * @return a php session id-ja
  */
Aitia.Url.getSessionId = function(sessionName) {
  var sessionName = (sessionName != null) ? sessionName : "PHPSESSID";
 
  var getValues = Aitia.Url.parseLocationSearch();
  if (getValues[sessionName]) {
    //ha _GET-ben utazik a session
    return getValues[sessionName];
  } else {
    //ha _COOKIE-ban utazik a session
    return getCookie(sessionName);
  }
  return ""; 
} // getSessionId





/* * * * * * * * * * * * * *
	START PageQuery class
 * * * * * * * * * * * * * */

// Egy url get paramĂŠter rĂŠszĂŠt manipulĂĄlĂł osztĂĄly
function PageQuery(q) {
	q = trim(q);
	var originQ = q;
	
	this.href = '';
	if ( q.indexOf('?')>0 ) {
		this.href = q.substring(0,q.indexOf('?'));
		q = q.substring(q.indexOf('?'));
	}
	
	this.q = ( q.indexOf('?')==0 ? q.substring(1, q.length) : q );
	
	this.hash = '';
	if ( this.q.lastIndexOf('#')>0 ) {
		this.hash = this.q.substring(this.q.lastIndexOf('#')+1);
		this.q = this.q.substring(0,this.q.lastIndexOf('#'));
	}

	this.keyValuePairs = new Array();

	if( q.length>0 ) {
		for(var i=0; i<this.q.split("&").length; i++) {
			var qIndex = trim(this.q.split("&")[i].split("=")[0]);
			var qValue = ( typeof this.q.split("&")[i].split("=")[1]!='undefined' ? this.q.split("&")[i].split("=")[1] : '' );
			
			if ( qIndex!='' ) {
				this.keyValuePairs.push( Array(qIndex,qValue) );
			}
		}
	}

	this.getKeyValuePairs = function() { return this.keyValuePairs; }

	this.getLength = function() { return this.keyValuePairs.length; } 
	
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j][0] == s) return this.keyValuePairs[j][1];
		}
	
		return false;
	}
	
	this.setValue = function(s,newValue) {
		var isSet = false;
		
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j][0] == s) {
				this.keyValuePairs[j][1] = newValue;
				isSet = true;
			}
		}
		
		if ( !isSet ) {
			this.keyValuePairs.push( Array(s,newValue) );
		}
	}
	
	this.removeKey = function(s) {
		var keyCount = 0;

		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j][0] == s) {
				this.keyValuePairs.splice(j, 1);
				keyCount += 1;
			}
		}

		if ( keyCount>0 ) {
			return true;
		} else {
			return false;
		}
	}

	this.getQuery = function() {
		var outStr = '';

		for (var i=0;i<this.keyValuePairs.length;i++) {
			if ( i>0 ) {
				outStr += '&';
			}
			outStr += this.keyValuePairs[i][0]+'='+this.keyValuePairs[i][1];
		}

		return outStr;
	}

	this.getURL = function() {
		var outStr = '';
		
		var urlSearch = this.getQuery();
		
		if ( this.hash!='' ) outStr = '#'+this.hash;
		if ( urlSearch!='' ) outStr = '?'+urlSearch+outStr;
		if ( this.href!='' ) outStr = this.href+outStr;

		return outStr;
	}
}

/* * * * * * * * * * * * * *
	END PageQuery class
 * * * * * * * * * * * * * */