// Cookie kezelő függvények - http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

var IE = document.all?true:false

function newwindow(url,w,x,y) {
    window.open(url,w,'width='+x+',height='+y+',scrollbars=1,status=0,menubar=1,location=0,resizable=1')
    return false;
}

function popup_window(url,w,x,y) {
    window.open(url,w,'width='+x+',height='+y+',scrollbars=1,status=0,menubar=0,location=0,resizable=1')
    return false;
}

function link(url,x,y) {
    window.open(url,"",'width='+x+',height='+y+',scrollbars=0,status=0,menubar=0,location=0,resizable=1')
}

function wo(url,w,x,y) {
    if (!x) { x=500; }
    if (!y) { y=460; }
    window.open(url,w,'width='+x+',height='+y+',scrollbars=yes,status=0,menubar=0,location=0,resizable=1');
    return false;
}

function emailcimjoe(emilcim) {
    a=emilcim.indexOf('@');
    b=emilcim.indexOf('.',a);
    if(a>0 && b>0 && b>a+1 && b<emilcim.length-1) return true;
    else return false;
}


function getParent(obj,tagname) {
    var p = 0;
	if(!obj) return false;
	if(obj.tagName=='BODY') return false;
	p = obj.parentNode;
	if(!p) return false;
	var p1 = null;
    if(p.tagName==tagname) return p;
	while(p.tagName!='BODY' && p.parentNode) {
		p1 = p.parentNode;
		if(p1.tagName==tagname) return p1;
        p = p1;
		p1 = null;
    }
    return null;
}

function tabHandler(tabprefix, handlerprefix) {
	this.tabprefix = tabprefix;
	this.handlerprefix = handlerprefix;
	this.currenttab = 0;
	this.switchTab = tabHandler_switchTab;
}

function tabHandler_switchTab(tab) {
	if(document.all) {
		var ct = document.all[this.tabprefix+'_'+this.currenttab];
		var ch = document.all[this.handlerprefix+'_'+this.currenttab];
		var ot = document.all[this.tabprefix+'_'+tab];
		var oh = document.all[this.handlerprefix+'_'+tab];
	} else {
		var ct = document.getElementById(this.tabprefix+'_'+this.currenttab);
		var ch = document.getElementById(this.handlerprefix+'_'+this.currenttab);
		var ot = document.getElementById(this.tabprefix+'_'+tab);
		var oh = document.getElementById(this.handlerprefix+'_'+tab);
	}
	ct.style.display = 'none';
	ot.style.display = 'block';
	ch.style.zIndex = 100-this.currenttab;
	ch.style.fontWeight = 'normal';
	oh.style.fontWeight = 'bold';
	oh.style.zIndex = '1000';
	this.currenttab = tab;
}


function form2array(formname) {
	var f = document.forms[formname];
	if(!f) return false;
	var j = false;
	var arr = new Object;
	for(i in f.elements) {
		j = f.elements[i];
		if(!j || !j.type) continue;
		switch(j.type) {
			case "text":
			case "textarea":
			case "hidden":
				arr[j.name] = j.value;
				break;

			case "checkbox":
			case "radio":
				if(j.checked) arr[j.name] = j.value;
				else arr[j.name] = "";
				break;

			case "select-one":
				arr[j.name] = j.value;
				break;

			case "select-multiple":
				var arr2 = new Array;
				for(ii=0; ii<j.options.length; ii++) {
					jj = j.options[ii];
					if(jj.selected) arr2[arr2.length] = jj.value;
				}
				arr[j.name] = arr2;
		}
	}
	return arr;
}

/*common cuccok*/
function setOpacity(obj,b){
    b = b*20;
    if(b<0){b=0;} if(b>100){b=100;}
    var c=b/100;
    var d=document.getElementById(obj);
    if(typeof(d.style.filter)=='string'){d.style.filter='alpha(opacity:'+b+')';}
    if(typeof(d.style.KHTMLOpacity)=='string'){d.style.KHTMLOpacity=c;}
    if(typeof(d.style.MozOpacity)=='string'){d.style.MozOpacity=c;}
    if(typeof(d.style.opacity)=='string'){d.style.opacity=c;}
}

function isValid(string,allowed) {
    for (var i=0; i< string.length; i++) {
		if (allowed.indexOf(string.charAt(i)) != -1)
		return false;
    }
	return true;
}

function getAbsoluteY(obj) {
	var parentY = 0;
	if(obj && obj.offsetParent) parentY = getAbsoluteY(obj.offsetParent);
	return obj.offsetTop+parentY;
}

function getAbsoluteX(obj) {
	var parentX = 0;
	if(obj && obj.offsetParent) parentX = getAbsoluteX(obj.offsetParent);
	return obj.offsetLeft+parentX;
}

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var mouseX = 0
var mouseY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
  	try {
    mouseX = event.clientX + document.body.scrollLeft;
    mouseY = event.clientY + document.body.scrollTop;
  	} catch(err) {}
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  // document.Show.MouseX.value = mouseX
  // document.Show.MouseY.value = mouseY
  return Array(mouseX, mouseY);
}

function Fly_start() {
	this.state = 1;
	this.frame = 0;
	this.obj.style.visibility = 'visible';
	this.distance = Math.sqrt((this.start_x-this.end_x)*(this.start_x-this.end_x)+(this.start_y-this.end_y)*(this.start_y-this.end_y));
	this.steps = Math.ceil(this.distance/this.speed);
	this.vx = Math.round((this.end_x-this.start_x)/this.steps);
	this.vy = Math.round((this.end_y-this.start_y)/this.steps);
	this.obj.style.left = this.start_x+'px';
	this.obj.style.top = this.start_y+'px';
	this.top = this.start_y;
	this.left = this.start_x;
	a = this;
	this.timer = window.setInterval(new Function('a.run(a)'), this.interval);
}

function Fly_stop() {
	this.obj.style.visibility = 'hidden';
	this.state = 0;
	clearInterval(this.timer);
}

function Fly_run(a) {
	a.frame++;
	if(a.frame>=a.steps) {
		a.stop();
		return;
	}
	a.left = a.left+a.vx;
	a.top = a.top+a.vy;
	a.obj.style.left = a.left+'px';
	a.obj.style.top = a.top+'px';
}

function Fly(start_x, start_y, end_x, end_y) {
	this.interval = 10;
	this.start_x = start_x;
	this.end_x = end_x;
	this.start_y = start_y;
	this.end_y = end_y;
	this.repeat = false;
	this.speed = 30;
	this.state = 0;
	this.distance = 0;
	this.obj = false;
	this.frame = 0;
	this.vx = 0;
	this.vy = 0;
	this.top = 0;
	this.left = 0;


	this.run = Fly_run;
	this.st = Fly_start;
	this.stop = Fly_stop;
}

	function Animation_start() {
		this.state = 1;
		a = this;
		this.timer = window.setInterval(new Function('a.run(a)'), 1000/this.framerate);
	}

	function Animation_stop() {
		this.state = 0;
		clearInterval(this.timer);
	}

	function Animation_run(a) {
		if(a.frame>=a.images.length) {
		  if(!a.repeat) a.stop();
		  a.frame = 0;
		}
		if(a.frame>0) a.images[a.frame-1].style.display = 'none';
		else a.images[a.images.length-1].style.display = 'none';
		a.images[a.frame].style.display = 'inline';
		a.frame++;
	}

	function Animation_preload() {
		var i=0;
		var tmp = false;
		var tmpimage = false;
		while(i<1000 && document.getElementById(this.image+i)) {
			tmp = document.getElementById(this.image+i);
			tmpimage = new Image();
			tmpimage.src = tmp.src;
			this.images[i] = tmp;
			i++;
		}
	}

	function Animation() {
	  this.framerate = 15;
	  this.repeat = false;
	  this.images = new Array();
	  this.timer = false;
	  this.state = 0;  // 0: stopped, 1: running
	  this.frame = 0;
		this.image = false;

	  this.st = Animation_start;
	  this.stop = Animation_stop;
	  this.run = Animation_run;
	  this.preload = Animation_preload;
	}

/*font meret*/
var font_size = 12;
var MAX = 24;
var MIN = 11;

function setFont(num){
  font_size += num;
 if(font_size > MAX){
      font_size = MAX;
 }
 if(font_size < MIN) {
      font_size = MIN;
 }
var oParagraphDiv = document.getElementById("cikkMain");
 oParagraphDiv.style.fontSize = font_size + "px";
 for (j = 0; j < oParagraphDiv.childNodes.length; j++){
  var oP = oParagraphDiv.childNodes[j];
  if ((oP.nodeName == "P") || (oP.nodeName == "A")){
    oP.style.fontSize = font_size + "px";
  }
 }
}

// Cookie osztaly
// HTTP.Cookies - Burak G?rsoy <burak[at]cpan[dot]org>
if (!HTTP) var HTTP = {}; // create base class if undefined

HTTP.Cookies = function () { // HTTP.Cookies constructor
   this.JAR = ''; // data cache
}

HTTP.Cookies.VERSION = '1.01';

HTTP.Cookies.Date = function () { // expire time calculation class
   this.format = {
   's' : 1,
   'm' : 60,
   'h' : 60 * 60,
   'd' : 60 * 60 * 24,
   'M' : 60 * 60 * 24 * 30,
   'y' : 60 * 60 * 24 * 365
   };
}

HTTP.Cookies.Date.prototype.parse = function (x) {
   if(!x || x == 'now') return 0;
   var date = x.match(/^(.+?)(\w)$/i);
   var of = 0;
   return (this.is_num(date[1]) && (of = this.is_date(date[1],date[2]))) ? of : 0;
}

HTTP.Cookies.Date.prototype.is_date = function (num, x) {
   if (!x || x.length != 1) return 0;
   var ar = [];
   return (ar = x.match(/^(s|m|h|d|w|M|y)$/) ) ? num * 1000 * this.format[ar[0]] : 0;
}

HTTP.Cookies.Date.prototype.is_num = function (x) {
   if (x.length == 0) return;
   var ok = 1;
   for (var i = 0; i < x.length; i++) {
      if ("0123456789.-+".indexOf(x.charAt(i)) == -1) {
         ok--;
         break;
      }
   }
   return ok;
}

HTTP.Cookies.prototype.date = new HTTP.Cookies.Date; // date object instance

// Get the value of the named cookie. Usage: password = cookie.read('password');
HTTP.Cookies.prototype.read = function (name) {
   var value  = '';
   if(!this.JAR) {
		this.JAR = {};
      var array  = document.cookie.split(';');
      for (var x = 0; x < array.length; x++) {
         var pair = array[x].split('=');
         if(pair[0].substring (0,1) == ' ') pair[0] = pair[0].substring(1, pair[0].length);
         if(pair[0] == name) {
            value = pair[1];
         }
         this.JAR[pair[0]] = pair[1];
      }
   } else {
      for(var cookie in this.JAR) {
         if(cookie == name) {
            value = this.JAR[cookie];
         }
	   }
   }
   return value ? unescape(value) : '';
}


// Create a new cookie or overwrite existing. Usage: cookie.write('password', 'secret', '1m');
HTTP.Cookies.prototype.write = function (name, value, expires, path, domain, secure) {
   var extra = '';
   if (!expires) expires = '';
   if (expires == '_epoch') {
      expires = new Date(0);
   } else if (expires != -1) {
      var Now  = new Date;
      Now.setTime(Now.getTime() + this.date.parse(expires));
      expires = Now.toGMTString();
   }
   if(expires) extra += "; expires=" + expires;
   //if(path   )
   extra += "; path=/";
   if(domain ) extra += "; domain="  + domain;
   if(secure ) extra += "; secure="  + secure;
   document.cookie = name + "=" + escape(value) + extra;
}

// Delete the named cookie. Usage: cookie.remove('password');
HTTP.Cookies.prototype.remove = function (name, path, domain, secure) {
   this.write(name, '', '_epoch', path, domain, secure);
}


/*osztalyok vege*/

function insertEmotion(file_name, title) {
        title = tinyMCE.getLang(title);

        if (title == null)
        title = "";

        // XML encode
        title = title.replace(/&/g, '&amp;');
        title = title.replace(/\"/g, '&quot;');
        title = title.replace(/</g, '&lt;');
        title = title.replace(/>/g, '&gt;');

        var html = '<img src="' + tinyMCE.baseURL + "/plugins/emotions/images/" + file_name + '" mce_src="' + tinyMCE.baseURL + "/plugins/emotions/images/" + file_name + '" border="0" alt="' + title + '" title="' + title + '" />';

        tinyMCE.execCommand('mceInsertContent', false, html);
    }


function insertEmotion_v3(file_name, title) {

        if (title == null)
        title = "";

        // XML encode
        title = title.replace(/&/g, '&amp;');
        title = title.replace(/\"/g, '&quot;');
        title = title.replace(/</g, '&lt;');
        title = title.replace(/>/g, '&gt;');

        var html = '<img src="/js/tiny_mce/plugins/emotions/images/' + file_name + '" mce_src="/js/tiny_mce/plugins/emotions/images/' + file_name + '" border="0" alt="' + title + '" title="' + title + '" />';

        tinyMCE.execCommand('mceInsertContent', false, html);
    }
    
function jelszo_ellenor(pass, white){
			var a;
			var c=1;
			var b=0;
			var d=0;
			var tmp;
			var numb_db=0;
			var bet_db=0;
			var spec_db=0;
			var betuk = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's' , 't', 'u', 'v', 'w', 'x', 'y', 'z', 'ö', 'ü', 'ó', 'ű', 'ő', 'ú', 'é', 'á', 'í']; 
			var spec = ['&#33','%','=','<','>','#','&',',','@',';',':','-',''];
			var spec2 = ['%','=','<','>','#','&',',','@',';',':','-'];
			//rossz: *, |, +
			var kimenet;
			
			//hossz
			a=pass.length;
			
			if(a>4){
				//betu-szam eloszlas
				var i=0;
				while(i<betuk.length && bet_db<1){
					if(pass.search(betuk[i])>-1){
						bet_db++;
					}
					i++;
				}
				var i=0;
				while(i<10 && numb_db<1){
				//for(var i=0; i<10; i++){
					if(pass.search(i)>-1){
						numb_db++;
					}
					i++;
				}
				
				if(bet_db!=0 && numb_db!=0){
					b=1;
				}
				
				//speci karakterek
				var i=0;
				while(i<spec.length-1 && spec_db<1){
				//for(var i=0; i<spec.length; i++){
					if(pass.search(spec[i])>-1){
						spec_db++;
					}else if(pass.indexOf('+')>-1){
						spec_db++;
					}else if(pass.indexOf('|')>-1){
						spec_db++;
					}else if(pass.indexOf('*')>-1){
						spec_db++;
					}
					i++;
				}
				//alert(spec[i-1]+'  '+spec_db);
				
				if(spec_db!=0){
					d=1;
				}
				
				//kisbetu-nagybetu
				tmp=pass.toLowerCase();
				if(pass.search(tmp)>-1){
					c=0; 
				}
				tmp=pass.toUpperCase();
				if(pass.search(tmp)>-1){ 
					c=0; 
				}
				
				kimenet= Math.min(1, ((a-4)/4)*(1+b+c+d)/4);
			
			}else{
				kimenet=0;
			}
			//alert('A='+a+' B='+b+' C='+c+' D='+d+' Kimenet='+ kimenet + 'pötty='+Math.round(kimenet*11));
			if(white) return('/imgs/jelszo_ertekelo/w_jelszo'+(Math.round(kimenet*11)+1)+'.gif');
			else return('/imgs/jelszo_ertekelo/jelszo'+(Math.round(kimenet*11)+1)+'.gif');
}

/**
 *  Csak számok bevitelét engedi.
 *  Használat: 'javascript:return CsakSzamok(event);' az onkeydown eseményhez 
 */   
  function CsakSzamok(esemeny)
  {
    var keynum;
    var keychar;
    var numcheck;
    
    if(window.event) // IE
      {
      keynum = e.keyCode;
      }
    else if(e.which) // Netscape/Firefox/Opera
      {
      keynum = e.which;
      }
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    return numcheck.test(keychar);
  }


function display_city(azon) {
		if (varos[azon]) {
			document.getElementById('iranyitoszam_varos').innerHTML = varos[azon];
			document.getElementById('hirlevel_varos').value = varos[azon];
			
		} else {
			document.getElementById('iranyitoszam_varos').innerHTML = '';
			document.getElementById('hirlevel_varos').value = '';
		}
	}
  	
//A regisztrációs felhasználói név ajánláshoz tartozó függvények

function JavaslatElfogad( nev )
{
      document.getElementById('NevJavaslat').style.display = 'none';  
      document.getElementById('regisztracio_username').style.background = 'white';
      document.getElementById('regisztracio_username').value = nev;      
}

function JavaslatBeir()
{
  if ((xmlhttp2.readyState == 4) && (xmlhttp2.status == 200))
  {
    if(xmlhttp2.responseText == "ok")
    {
      //nincs lefoglalva a név
      document.getElementById('NevJavaslat').style.display = 'none';
      document.getElementById('regisztracio_username').style.background = 'white';    
    }
    else
    {
      //már van ilyen nevű user
      document.getElementById('NevJavaslat').style.display = 'block';
      document.getElementById('NevJavaslat').innerHTML = xmlhttp2.responseText;
      document.getElementById('regisztracio_username').style.background = 'red';
    }
  }
}

function Javaslat( ertek )
{
  if (ertek.length > 2)
  {
    try
    {
      xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {}
    xmlhttp2.onreadystatechange = JavaslatBeir;
    xmlhttp2.open("GET", 'index.php?block=nev_javaslat&beirt_szoveg='+ertek+'&ajax=1&nincs_merokod=1', true);
    xmlhttp2.send(null);
  }
  else
  {
      document.getElementById('NevJavaslat').style.display = 'none';
      document.getElementById('regisztracio_username').style.background = 'white';  
  }
}

// Cikk kommentek
function commentsLister(status, cikkID)
{
	if (status == 0)	// olvasas
	{
		$('hozzaszoloklink').style.display='block';
        $('megnezemlink').style.display='none';
        
        if ($('uzenet_lista').style.display == 'none')
		{
		// ha zarva ez a div
		new Ajax.Request('/index.php?block=cikk_hozzaszolas_lista_09&ajax=1&cikkid=' + cikkID, 
		{
			method: 'get', 
			onSuccess: function(t) { var msg = t.responseText; $('uzenet_lista').innerHTML = msg; $('uzenet_lista').style.display = 'block';} 
		});
		
		} else 
		if ($('uzenet_lista').style.display == 'block')
		{
			$('uzenet_lista').style.display = 'none';
			$('uzenet_hozzaszolas').style.display = 'none';	
		}	
	}
	else	// iras
	{
	   	$('hozzaszoloklink').style.display='none';
        $('megnezemlink').style.display='none';
		
        if 	($('uzenet_lista').style.display == 'none')
		{
			new Ajax.Request('/index.php?block=cikk_hozzaszolas_lista_09&ajax=1&cikkid=' + cikkID, 
			{
				method: 'get', 
				onSuccess: function(t) { var msg = t.responseText; $('uzenet_lista').innerHTML = msg; $('uzenet_lista').style.display = 'block'; $('uzenet_hozzaszolas').style.display = 'block';} 
			});
		}
		else
		if 	($('uzenet_hozzaszolas').style.display == 'block')
		{
			$('uzenet_lista').style.display = 'block';
			$('uzenet_hozzaszolas').style.display = 'none';	
		}
		else
		{
			$('uzenet_lista').style.display = 'block';
			$('uzenet_hozzaszolas').style.display = 'block';		
		}

	}
}

function countText(field, limit)
{
	var len = $(field).value.length;
	if (len > limit)
	{
		$(field).value = $(field).value.substr(0,limit);
	}
	$("counterfield").innerHTML = limit - len;
	
}

function checkMsg(field)
{
	var msg = $(field).value;
	if (msg.length == 0) { alert('Üres üzenetet nem lehet küldeni!'); return false; }
	if (msg.length > 2000){ alert('Üzeneted maximum 2000 karakter lehet!'); return false; }
	return true;
}

//master.js-bol nyultam
if(!document.getElementsByClassName)document.getElementsByClassName=function(f){function iter(a){return a.blank()?null:"[contains(concat(' ', @class, ' '), ' "+a+" ')]"}f.getElementsByClassName=Prototype.BrowserFeatures.XPath?function(a,b){b=b.toString().strip();var c=/\s/.test(b)?$w(b).map(iter).join(''):iter(b);return c?document._getElementsByXPath('.//*'+c,a):[]}:function(b,c){c=c.toString().strip();var d=[],classNames=(/\s/.test(c)?$w(c):null);if(!classNames&&!c)return d;var e=$(b).getElementsByTagName('*');c=' '+c+' ';for(var i=0,child,cn;child=e[i];i++){if(child.className&&(cn=' '+child.className+' ')&&(cn.include(c)||(classNames&&classNames.all(function(a){return!a.toString().blank()&&cn.include(' '+a+' ')}))))d.push(Element.extend(child))}return d};return function(a,b){return $(b||document.body).getElementsByClassName(a)}}

// nyitott lakatokra atvaltas, ahol a user tag
function switchClosedTopicIcons(accessString) {
	if (accessString.length <= 1) {
		return true; // ures stringre ne fusson le
	}

// 22x22-es ikonok
	var arrIkonok;
	try {
		arrIkonok = document.getElementsByTagName('div').getElementsByClassName('zarticon');
	} catch(err) {
		arrIkonok = getElementsByClassName( document, 'div', 'zarticon');
	}
	for ( i=0; i<arrIkonok.size(); i++ ) {
		var classes = arrIkonok[i].className.split(' ');
		if (classes.size() == 3) {
			var topicid = classes[1].substr(2);
			var pos1=accessString.indexOf(topicid);
			if (pos1 != -1) { // ha a listaban van -- legalabb tag
				classes[2] = classes[2] + "_tag";
			}
			arrIkonok[i].className=(classes[0] + ' ' + classes[1] + ' ' + classes[2]);
		}
	}	
// 24x24-es ikonok
	var arrIkonok;
	try {
		arrIkonok = document.getElementsByTagName('span').getElementsByClassName('zartsag_icon');
	} catch(err) {
		arrIkonok = getElementsByClassName( document, 'span', 'zartsag_icon');
	}
	for ( i=0; i<arrIkonok.size(); i++ ) {
		var classes = arrIkonok[i].className.split(' ');
		if (classes.size() == 3) {
			var topicid = classes[1].substr(2);
			var pos1=accessString.indexOf(topicid);
			if (pos1 != -1) { // ha a listaban van -- legalabb tag
				classes[2] = classes[2] + "_tag";
			}
			arrIkonok[i].className=(classes[0] + ' ' + classes[1] + ' ' + classes[2]);
		}
	}	
	return true;
}

// captcha új kód generáló

function captchaRefresh(captcha_name, img_id) {
	var d = new Date();
	var img = document.getElementById(img_id);
	img.src = '/captcha_image.php?name=' + captcha_name + '&v=' + d.getTime();
}

