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
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } 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 nyeremenyjatek_check(){
 if(!nyeremenyjatek()){
  alert('A játékban való részvételhez minden adat megadása szükséges!');
  return false;
 }
 return true;
}

function nyeremenyjatek(){
 if($('ny_kod').value==''){return false;} 
 if(!($('ny_meret_a').checked || $('ny_meret_b').checked || $('ny_meret_c').checked || $('ny_meret_d').checked)){return false;}
 if($('ny_name').value==''){return false;}
 if($('ny_hely').value==''){return false;}
 if($('ny_ir').value==''){return false;}
 if($('ny_utca').value==''){return false;}
 if($('ny_mail').value==''){return false;}
 if (!(document.getElementsByName('ny_mail')[0].value.indexOf('@')>0 && document.getElementsByName('ny_mail')[0].value.indexOf('@')<document.getElementsByName('ny_mail')[0].value.length-1))
    {
      alert("Rossz e-mail cím!");
      return false;
    }

 return true;
}
