// ------------------------------------------------------------------
// -                A Portal kozos JavaScript fajlja                -
// ------------------------------------------------------------------

//backward compatibility
function  submitenter(obj,eventSrc)
{
	return;
}


//hasznalata:
//kategoria: 
// - images: kep eleresi ut
// - messages:  
//images_tspicker_nextmonth

var localizedStrings = new Array();

function centerWindow(url, name, width, height, params) 
{
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;
	
    window.open(url,name,
    'width=' + width + ',height=' + height + ',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',' + params);
}


// a design elemek, amik a kiemeleshez kellenek
var replaceTextStart = '<span class="SearchMark">';
var replaceTextEnd = '</span>';

// kijeloli a megadott HTML-ben a megadott kulcsszavakat
function markText( inputHtml )
{
	// URL-bol kiszedi a queryt
	var queryObj = parseQueryString( location.search );
	txtKeyword = queryObj.query;

	// Ha nincs query visszaadjuk az inputot
	if ( txtKeyword==null || txtKeyword=="" )
		return inputHtml;

	//	alert( 'Before: ' + txtKeyword );

	// karakter konverzio
	txtKeyword = unescapeHTMLEntities2Characters( txtKeyword );

	//alert( 'Middle: ' + txtKeyword );

	// meg egy kis konvertalas a browser segitsegevel :)
	document.write( '<div id="converterdiv"></div>' );
	elemObj = document.getElementById('converterdiv');
	elemObj.innerHTML = txtKeyword;
	txtKeyword = elemObj.innerHTML;
	elemObj.innerHTML = '';

	//	alert( 'After: ' + txtKeyword );

	// kifejezes kereses eseten a " jelek kivetele
	if ( txtKeyword.indexOf( '"' ) >= 0 )
	{	
		while ( txtKeyword.indexOf( '"' ) >= 0 )
		{
			txtKeyword = replaceExact(txtKeyword, '"', '');
		}
	}

	//	alert( '"talan??t??s After: ' + txtKeyword );

	// tobbszavas kereses eseten a + jelek space-sze alakitasa
	if ( txtKeyword.indexOf( '+' ) > 0 )
	{
		while ( txtKeyword.indexOf( '+' ) > 0 )
		{
			word = txtKeyword.substring(0, txtKeyword.indexOf( '+' ) );
			txtKeyword = txtKeyword.substring( txtKeyword.indexOf( '+' )+1, txtKeyword.length );

			inputHtml = markWord( word, inputHtml );
		}
	}

	return markWord( txtKeyword, inputHtml );
}

// Egy szot kiemel
function markWord( txtKeyword, inputHtml ) 
{
	var re; /*regex object*/
	var varMatches; /*matches array*/
	var outHtml; /*output html*/
	var replaceText;/*build the span tag with the keyword in advance*/
		
	re=new RegExp("(\<[^>][^<]*\>)([^<]*)","g"); /*create non-greedy regex match*/
	outHtml=new String('');	/*init html string*/				
			
	while ((varMatches = re.exec(inputHtml)) != null) /*exec sequentially to apply span tags*/
	{
		outHtml+=varMatches[1]; 	/*html tag part*/
		outHtml+=replaceMe( varMatches[2], txtKeyword, replaceTextStart, replaceTextEnd); /*call the search & replace function*/
	}

	return outHtml;
}


// kicsereli a forras szovegben elofordulo megadott szoveget a megadott kifejezesre
function replaceMe( source, originalText, replaceTextStart, replaceTextEnd )
{
	var repl = new RegExp( "[^ ]*" + originalText + "[^ ]*", "gi");

	result = source;	

	while ((varMatches = repl.exec(source)) != null) 
	{
		current = replaceTextStart + varMatches[0] + replaceTextEnd;
		result = result.replace( varMatches[0], current );
	}

	return result;
}

// kicsereli a forras szovegben elofordulo megadott szoveget a megadott kifejezesre
function replaceExact( source, originalText, replaceText )
{
	var repl = new RegExp( originalText, "g");

	result = source;

	while ((varMatches = repl.exec(source)) != null) 
		result = result.replace( varMatches[0], replaceText );

	return result;
}


// Megparsolja a query string-et egy URL-bol
function parseQueryString(queryString) 
{
	if ( queryString.indexOf( '*' )>0 )
		return new Object();

	var queryObject = new Object();
	queryString = queryString.replace(/^.*\?(.+)$/,'$1');

	while ((pair = queryString.match(/([^=]+)=\'?([^\&\']*)\'?\&?/)) && pair[0].length) 
	{
		queryString = queryString.substring( pair[0].length );

		if (/^\-?\d+$/.test(pair[2])) pair[2] = parseInt(pair[2]);
		queryObject[pair[1]] = pair[2];
	}

	return queryObject;
}

// A megjelenitett karakterekhez hasonlo modon escapel
function unescapeHTMLEntities2Characters( source )
{
                                         
	source = replaceExact( source, '%C3%A1', unescape( '%e1' ) ); // a'
	source = replaceExact( source, '%C3%A9', unescape( '%e9' ) );  // e'
	source = replaceExact( source, '%C3%AD', unescape( '%ed' ) );  // i'
	source = replaceExact( source, '%C3%B3', unescape( '%f3' ) );  // o'
	source = replaceExact( source, '%C3%B6', unescape( '%f6' ) );  // o:
	source = replaceExact( source, '%C5%91', '&#337;' );  // o''
	source = replaceExact( source, '%C3%BA', unescape( '%fa' ) );  // u'
	source = replaceExact( source, '%C3%BC', unescape( '%fc' ) );  // u:
	source = replaceExact( source, '%C5%B1', '&#369;' );  // u''

	source = replaceExact( source, '%20', '+' );  // space -> +
	source = replaceExact( source, '%22', '"' );

	source = replaceExact( source, '%C3%81', '&Aacute;' );  // A'
	source = replaceExact( source, '%C3%89', '&Eacute;' );  // E'
	source = replaceExact( source, '%C3%8D', '&Iacute;' );  // I'
	source = replaceExact( source, '%C3%93', '&Oacute;' );  // O'
	source = replaceExact( source, '%C3%96', '&Ouml;' );  // O:
	source = replaceExact( source, '%C5%90', '&#336;' );  // O''
	source = replaceExact( source, '%C3%9A', '&Uacute;' );  // U'
	source = replaceExact( source, '%C3%9C', '&Uuml;' );  // U:
	source = replaceExact( source, '%C5%B0', '&#368;' );  // U''

	return source;
}


// cikk szovegenek meretezeset vegzo fuggvenyke
var fs_state = 0

// fabejaras rekurziv modon
function bejar(delta,node){
	var children = node.childNodes;
	for (var i=0;i<children.length;i++){
		childObj = children[i];
         // heading upper-t nem nagyitjuk,mert az a felso menusor
         // csak azon node-okat nezzuk melyek nem text tipusuak                           
		if (childObj.className != "HeadingUpper" && childObj.nodeType==1){
			meretez(delta,childObj);	
			bejar(delta,childObj);
		}
	}
	return;
}

// ez a fuggveny noveli meg/csokkenti a font meretet delta ertekkel a nodeObj-en
function meretez(delta,nodeObj){
	var fs = nodeObj.style.fontSize;
			
		//ha olyan elem, amit nem tudunk meretezni, visszaterunk	
		if(nodeObj.tagName=="IMG" || nodeObj.tagName=="SCRIPT"){
			return;
		}
			
	if(fs==""){
	nodeObj.style.fontSize=(10+delta)+"px";
	}else{
		nodeObj.style.fontSize=(parseInt(fs)+delta)+"px";
	}
	
	//limit
	fs = nodeObj.style.fontSize
	var fsn = parseInt(fs.substring(0,fs.length-2))
	if(fsn<=6) fs_state=-1;
	if(fsn>=24) fs_state=1
}


// a cikkek meretet nagyitja meg egy rekurziv fabejaras segitsegevel
// az oldal szerkezetebol indul ki, ahol a kozepso cikk megjelenito resz ID-janak content_id ertekkel
// kell rendelkeznie! (egyebkent nem fog mukodni)
// az id-t az XSL-ben allitjuk be
// ezek utan a Content-en belul levo osszes elem meretet nagyitani fogja a bejaras miatt.


function cikkFontMeret( delta, e, classPrefix1, classPrefix2, classPrefix3, classPrefix4, classPrefix5, classPrefix6 )
{
    //itt megkeressuk azt a td elemet, aminek a class-a Content lesz, mert ez lesz kozepen
	var contentElement = e;
	while(contentElement.tagName!="TABLE"){
	  contentElement=contentElement.parentNode;
  }
  
	bejar(delta,contentElement);
}

function getBrowserType()
{
	
	
}

// =============== include helper ============7

var Include = function () {
  var Include = function (src) {
    var reg = null;
    for (var i = 0; reg = Include.registry[i]; i++) {
      if (reg.toLowerCase() == src.toLowerCase()) {
        return false;
      }
    }
    
    var head   = document.getElementsByTagName('head')[0];
    var script = document.createElement("script");
      
    script.src  = src.match(/^\//) ? src : Include.base + src;
    script.type = "text/javascript";
    script.language = "javascript";
      
    head.appendChild(script);
    alert(script.src);
    return script;
  };
  
  Include.registry = [];
  Include.Once = function (src) {
    var script = Include(src);
    Include.registry[Include.registry.length] = src;
    return script;
  };
  
  var base     = document.getElementsByTagName("base")[0];
  Include.base = base ? base.href : "";
  
  return Include;
}();




function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


//lesz egy hashmapunk, amelyik tartalmazni fogja melyik 
//invalid karaktert mire kell cserelnunk
//key: invalid character unicode code
//value: correct 
function HashMap()
{
	this.keys = new Vector(5);
	this.values = new Vector(5);
}
			
	HashMap.prototype.getSize = function(){					 	
	  return this.keys.getSize();
	}			


  HashMap.prototype.addItem = function(key,val){
  	this.keys.addElement(key);
  	this.values.addElement(val);
  }

  HashMap.prototype.getKeyAtIndex = function(i){
  	return this.keys.getElementAt(i);  	
  }

  HashMap.prototype.getValueAtIndex = function(i){
  	return this.values.getElementAt(i);  	
  }


var invalidChars = new HashMap();
 
invalidChars.addItem("\u00e1","a");
invalidChars.addItem("\u00ed","i");
invalidChars.addItem("\u0171","u");
invalidChars.addItem("\u0151","o");
	
invalidChars.addItem("\u00fc","u");
invalidChars.addItem("\u00f6","o");
invalidChars.addItem("\u00fa","u");
invalidChars.addItem("\u00f3","o");
invalidChars.addItem("\u00e9","e");
	
invalidChars.addItem("\u00c1","A");
invalidChars.addItem("\u00cd","I");
invalidChars.addItem("\u0170","U");
invalidChars.addItem("\u0150","O");
	
invalidChars.addItem("\u00dc","U");
invalidChars.addItem("\u00d6","O");
invalidChars.addItem("\u00da","U");
invalidChars.addItem("\u00d3","O");
invalidChars.addItem("\u00c9","E");
	
invalidChars.addItem("\u0020","_");
		

function containsIllegalCharacter(fileName)
{
	
	  var str = fileName;
		var strLength = fileName.length
		var i = 0;
		var containsInvalidChar = false;
		
		//megnezzuk, hogy tartalmaz-e illegal karaktert:
		for(var keysIndexer = 0; keysIndexer<invalidChars.getSize();keysIndexer++){
			if(str.indexOf(invalidChars.getKeyAtIndex(keysIndexer))>=0){
				containsInvalidChar = true;
				break;
			}
		}
		
		return containsInvalidChar;
}

//egy fajlnevet konvertal at szep fajlnevve
//az elso param a fajlnev, a kovetkezo
//param azt adja meg,hgoy legyen-e ellenorzes 
//a konvertalas elott (ha ez hamis, mindenkeppen cserel)
function convertToSafeFileName(fileName,checkFirst)
{
	  var str = fileName;

		var strLength = fileName.length
		var i = 0;
		var containsInvalidChar = true;
		
		if(checkFirst){
			containsInvalidChar = containsIllegalCharacter(fileName);
		}
		
		
		//ha tartalmaz illegal karaktert, akkor vegigmegyunk a fileneven, es lecsereljuk
		if(containsInvalidChar){
      while(i<strLength){
       	i++;
       //vegigszaladva a HashMap-en, az osszes illegal karaktert lecsereljuk
        for(var keysIndexer = 0; keysIndexer<invalidChars.getSize();keysIndexer++){			   				
			    str = str.replace(invalidChars.getKeyAtIndex(keysIndexer),invalidChars.getValueAtIndex(keysIndexer));			   
		    }
		    	
		  }
       		       		
    }
	
			return str;								
} 


//////////////////////////////////////////////////////
// File: vector.js
//
// Author: Jason Geissler
// 
// Date: Sept 3, 2003
//
// Purpose: To have a dynamic collection instead
//          of using arrays when the total quantity
//          is unknown
//////////////////////////////////////////////////////

// Vector Constructor -- constructs the object
function Vector(inc) {
  if (inc == 0) {
    inc = 100;
  }
  
  /* Properties */
  this.data = new Array(inc);
  this.increment = inc;
  this.size = 0;
  
  /* Methods */
  this.getCapacity = getCapacity;
  this.getSize = getSize;
  this.isEmpty = isEmpty;
  this.getLastElement = getLastElement;
  this.getFirstElement = getFirstElement;
  this.getElementAt = getElementAt;
  this.addElement = addElement;
  this.insertElementAt = insertElementAt;
  this.removeElementAt = removeElementAt;
  this.removeAllElements = removeAllElements;
  this.indexOf = indexOf;
  this.contains = contains
  this.resize = resize;
  this.toString = toString;
  this.sort = sort;
  this.trimToSize = trimToSize;
  this.clone = clone;
  this.overwriteElementAt;
}

// getCapacity() -- returns the number of elements the vector can hold
function getCapacity() {
  return this.data.length;
}

// getSize() -- returns the current size of the vector
function getSize() {
  return this.size;
}

// isEmpty() -- checks to see if the Vector has any elements
function isEmpty() {
  return this.getSize() == 0;
}

// getLastElement() -- returns the last element
function getLastElement() {
  if (this.data[this.getSize() - 1] != null) {
    return this.data[this.getSize() - 1];
  }
}

// getFirstElement() -- returns the first element
function getFirstElement() {
  if (this.data[0] != null) {
    return this.data[0];
  }
}

// getElementAt() -- returns an element at a specified index
function getElementAt(i) {
  try {
    return this.data[i];
  } 
  catch (e) {
    return "Exception " + e + " occured when accessing " + i;  
  }  
}

// addElement() -- adds a element at the end of the Vector
function addElement(obj) {
  if(this.getSize() == this.data.length) {
    this.resize();
  }
  this.data[this.size++] = obj;
}

// insertElementAt() -- inserts an element at a given position
function insertElementAt(obj, index) {
  try {
    if (this.size == this.capacity) {
      this.resize();
    }
    
    for (var i=this.getSize(); i > index; i--) {
      this.data[i] = this.data[i-1];
    }
    this.data[index] = obj;
    this.size++;
  }
  catch (e) {
    return "Invalid index " + i;
  }
}

// removeElementAt() -- removes an element at a specific index
function removeElementAt(index) {
  try {
    var element = this.data[index];
    
    for(var i=index; i<(this.getSize()-1); i++) {
      this.data[i] = this.data[i+1];
    }
    
    this.data[getSize()-1] = null;
    this.size--;
    return element;
  }
  catch(e) {
    return "Invalid index " + index;
  }
} 

// removeAllElements() -- removes all elements in the Vector
function removeAllElements() {
  this.size = 0;
  
  for (var i=0; i<this.data.length; i++) {
    this.data[i] = null;
  }
}

// indexOf() -- returns the index of a searched element
function indexOf(obj) {
  for (var i=0; i<this.getSize(); i++) {
    if (this.data[i] == obj) {
      return i;
    }
  }
  return -1;
}

// contains() -- returns true if the element is in the Vector, otherwise false
function contains(obj) {
  for (var i=0; i<this.getSize(); i++) {
    if (this.data[i] == obj) {
      return true;
    }
  }
  return false;
}

// resize() -- increases the size of the Vector
function resize() {
  newData = new Array(this.data.length + this.increment);
  
  for  (var i=0; i< this.data.length; i++) {
    newData[i] = this.data[i];
  }
  
  this.data = newData;
}


// trimToSize() -- trims the vector down to it's size
function trimToSize() {
  var temp = new Array(this.getSize());
  
  for (var i = 0; i < this.getSize(); i++) {
    temp[i] = this.data[i];
  }
  this.size = temp.length - 1;
  this.data = temp;
} 

// sort() - sorts the collection based on a field name - f
function sort(f) {
  var i, j;
  var currentValue;
  var currentObj;
  var compareObj;
  var compareValue;
  
  for(i=1; i<this.getSize();i++) {
    currentObj = this.data[i];
    currentValue = currentObj[f];
    
    j= i-1;
    compareObj = this.data[j];
    compareValue = compareObj[f];
    
    while(j >=0 && compareValue > currentValue) {
      this.data[j+1] = this.data[j];
      j--;
      if (j >=0) {
        compareObj = this.data[j];
        compareValue = compareObj[f];
      }        
    }  
    this.data[j+1] = currentObj;
  }
}

// clone() -- copies the contents of a Vector to another Vector returning the new Vector.
function clone() {
  var newVector = new Vector(this.size);
  
  for (var i=0; i<this.size; i++) {
    newVector.addElement(this.data[i]);
  }
  
  return newVector;
}

// toString() -- returns a string rep. of the Vector
function toString() {
  var str = "Vector Object properties:\n" +
            "Increment: " + this.increment + "\n" +
            "Size: " + this.size + "\n" +
            "Elements:\n";
  
  for (var i=0; i<getSize(); i++) {
    for (var prop in this.data[i]) {
      var obj = this.data[i];
      str += "\tObject." + prop + " = " + obj[prop] + "\n";
    }
  }
  return str;  
}

// overwriteElementAt() - overwrites the element with an object at the specific index.
function overwriteElementAt(obj, index) {
  this.data[index] = obj;
}



