

/*
window.addEvent('domready', function() {
	var serviceTab = document.getElementsByTagName('div');  
	for (i in serviceTab){ 
	 if(serviceTab[i].className == 'sz2' || serviceTab[i].className == 'sz3' ) { 
	 serviceTab[i].onmouseover = function(){ 
	 var nodes = this.childNodes; for (e in nodes) if (nodes[e].className == 'talal') nodes[e].className ='talal2' 
	 } 
	 serviceTab[i].onmouseout = function(){ 
	 var nodes = this.childNodes; for (e in nodes) if (nodes[e].className == 'talal2') nodes[e].className ='talal' 
	 } 
	 } 
	} 
});*/
function concatObject(obj) {
  str='';
  for(prop in obj)
  {
    str+=prop + " value :"+ obj[prop]+"\n";
  }
  return(str);
}


function ajaxRequest(file, returnid, related) {
	var req = new Request.HTML({
		method: 'get',
		url: file,
		onSuccess: function(html) {if (related == 1) {$('ide').innerHTML=""; $('ide').adopt(html)}},
		//data: { 'id' : '7' },
		//onRequest: function() { alert('Request made. Please wait...'); },
		update: $(returnid)
		//onComplete: function(response) { alert('Request completed successfully.'); $(returnid).setStyle('background','#fffea1'); }
	}).send();

}
/*
Element.implement({
    highlight: function(search, insensitive){
    	var regex = new RegExp('(<[^>]*>)|(\\b'+ search.escapeRegExp() +')', insensitive ? 'ig' : 'g');
    	return this.set('html', this.get('html').replace(regex, function(a, b, c){
    		return (a.charAt(0) == '<') ? a : '<span class="filc">' + c + '</span>'; 
    	}));
    }
});
*/

/*
function keywords(word) {
	var suti = Cookie.read("keywords");
	if (suti) {
		if (word && suti.split("<||>").length >= 10) {
			var charlen = suti.lastIndexOf("<||>");
			var myCookie  = Cookie.write("keywords", word + "<||>" + suti.substr(0,charlen), {duration: 90});
		} else if (word) {
			var myCookie  = Cookie.write("keywords", word + "<||>" + suti, {duration: 90});
		} 
	} else if (word) {
		var myCookie  = Cookie.write("keywords", word, {duration: 90});
	}
}
*/

	var Highlighter = new Class({
			
	/* implements */
	Implements: [Options],

	/* options */
	options: {
		autoUnhighlight: true,
		caseSensitive: false,
		elements: '*',
		className: '',
		onlyWords: false,
		tag: 'span'
	},
	
	/* initialization */
	initialize: function(options) {
		/* set options */
		this.setOptions(options);
		this.elements = $$(this.options.elements);
		this.words = [];
	},
	
	/* directs the plugin to highlight elements */
	highlight: function(words,elements,className) {
		
		/* figure out what we need to use as element(s) */
		var elements = $$(elements || this.elements);
		var klass = className || this.options.className;
		if (words.constructor === String) { words = [words]; }
		
		/* auto unhighlight old words? */
		if(this.options.autoUnhighlight) { this.unhighlight(); }
		
		/* set the pattern and regex */
		var pattern = this.options.onlyWords ? '\\b' + pattern + '\\b' : '(' + words.join('|') + ')';
		var regex = new RegExp(pattern, this.options.caseSensitive ? '' : 'i');
		
		/* run it for each element! */
		elements.each(function(el) { this.recurse(el,regex,klass); },this);
		
		/* make me chainable! */
		return this;
	}, 
	
	/* unhighlights items */
	unhighlight: function(words) {
		//var selector = this.options.tag + (word ? '[rel=' + word + ']' : '');
		if (words.constructor === String) { words = [words]; }
		words.each(function(word) {
			word = (this.options.caseSensitive ? word : word.toUpperCase());
			if(this.words[word]) {
				var elements = $$(this.words[word]);
				elements.set('class','');
				elements.each(function(el) {
					var tn = document.createTextNode(el.get('text'));
					el.getParent().replaceChild(tn,el);
				});
			}
		},this);
		return this;
	},
	
	/* recursed function */
	recurse: function(node,regex,klass) {
			if (node.nodeType === 3) {
				var match = node.data.match(regex);
				if (match) {
					/* new element */
					var highlight = new Element(this.options.tag);
					highlight.addClass(klass);
					var wordNode = node.splitText(match.index);
					wordNode.splitText(match[0].length);
					var wordClone = wordNode.cloneNode(true);
					highlight.appendChild(wordClone);
					wordNode.parentNode.replaceChild(highlight, wordNode);
					highlight.set('rel',highlight.get('text'));
					var comparer = highlight.get('text');
					if(!this.options.caseSensitive) { comparer = highlight.get('text').toUpperCase(); }
					if(!this.words[comparer]) { this.words[comparer] = []; }
					this.words[comparer].push(highlight);
					return 1;
				}
			} else if ((node.nodeType === 1 && node.childNodes) && !/(script|style)/i.test(node.tagName) && !(node.tagName === this.options.tag.toUpperCase() && node.className === klass)) {
				for (var i = 0; i < node.childNodes.length; i++) {
					i += this.recurse(node.childNodes[i],regex,klass);
				}
			}
			return 0;
		}
	});
	
	function main_check(){
		if(Cookie.read('mainbox')=='close'){
			div = document.getElementById('para_wel');
			div.style.display='none';
		}
	}
	
	function main_close(){
		$('para_wel').fade('out');
		(function(){
		div = document.getElementById('para_wel');
		div.style.display='none';
		}).delay(450)
		Cookie.write('mainbox', 'close', {duration: 90});
	}
	
	
	function login_close(){
			    body = document.getElementsByTagName('body')
                            log0 = document.getElementById('log0')
                            login = document.getElementById('signin')
                            
                            $('page0').addEvent('click',function(){
                                if(login.style.display=='block')
                                    document.getElementById('mezo').keres.focus();
                                    login.style.display='none'
                                    
                                });
                            $('log0').addEvent('click',function(){
                                    login.style.display='block'
                                    document.form2.email.focus();
                                });
                            
                            window.addEvent('domready', function() {
                                document.getElementById('mezo').keres.focus();
                            });
	}
	
	function ie6open(){
		
                                login = document.getElementById('welcome2')
				login2 = document.getElementById('welcome2-bottom')
				login.style.display='block'
				login2.style.display='block'
                
		
	}
	
	function kuld(text){
	    url = 'http://szorcs.hu/apis/type.php?keres='+text
	    //alert(url)
	    if(text.length>0)
	    ajaxRequest(url);
	}
	
	function ajaxRequest2(file, returnid, related) {
		
	window.addEvent('domready', function() {
		setTimeout(function(){
	    var req = new Request.HTML({
		    method: 'get',
		    url: file,
		    onSuccess: function(html) {if (related == 1) {$('ide').innerHTML=""; $('ide').adopt(html)}},
		    //data: { 'id' : '7' },
		    //onRequest: function() { alert('Request made. Please wait...'); },
		    update: $(returnid)
		    //onComplete: function(response) { alert('Request completed successfully.'); $(returnid).setStyle('background','#fffea1'); }
	    }).send();
		},10000);
	});

	}
	
	function ajaxRequest3(file, returnid, related) {
	  var div = document.getElementById(returnid);
	  var para = document.getElementById(returnid+"P");
	  var button =  document.getElementById(returnid+"SZ");
	  // div.fade(0.4);
	var req = new Request.HTML({
		method: 'get',
		url: file,
		onSuccess: function(html) {div.fade(1); if (related == 1) {$('ide').innerHTML=""; $('ide').adopt(html);} button.innerHTML="";},
		//data: { 'id' : '7' },
		//onRequest: function() { alert('Request made. Please wait...'); },
		update: $(returnid)
		//onComplete: function(response) { alert('Request completed successfully.'); $(returnid).setStyle('background','#fffea1'); }
	}).send();
	
}
	function ajaxRequest4(file, returnid, tipus) {
	  var div = document.getElementById(returnid);
	  var para = document.getElementById(returnid+"P");
	  var button =  document.getElementById(returnid+"SZ");
	  div.fade(0.4);

	var req = new Request.HTML({
		method: 'get',
		url: file,
		onSuccess: function(html) {button.setStyle('display','none'); button.innerHTML=""; div.fade(1);},
		//data: { 'id' : '7' },
		//onRequest: function() { alert('Request made. Please wait...'); },
		update: $(returnid)
		//onComplete: function(response) { alert('Request completed successfully.'); $(returnid).setStyle('background','#fffea1'); }
	}).send();
	// alert (tipus);
	if (tipus == "1") { button.innerHTML='<p style="background-image: none;"><img src="layout/images/img/betolto.gif"><strong style="position: relative; left: -4px;">Friss tartalmak keresése</strong></p>'; }
	if (tipus == "2") { button.innerHTML='<p style="background-image: none;"><img src="layout/images/img/betolto.gif"><strong style="position: relative; left: -4px;">Keresés videók között</strong></p>'; }
	if (tipus == "3") { button.innerHTML='<p style="background-image: none;"><img src="layout/images/img/betolto.gif"><strong style="position: relative; left: -4px;">Blogbejegyzések keresése</strong></p>'; }
	if (tipus == "4") { button.innerHTML='<p style="background-image: none;"><img src="layout/images/img/betolto.gif"><strong style="position: relative; left: -4px;">Keresés a twitteren</strong></p>'; }
	if (tipus == "5") { button.innerHTML='<p style="background-image: none;"><img src="layout/images/img/betolto.gif"><strong style="position: relative; left: -4px;">Képek keresése</strong></p>'; }
	
	
}