// ALAP JS

UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};

function preloadimages()
{
	imgfolder = "/images/";
	allimg = new Array("mainmenu_01b.gif","mainmenu_02b.gif","mainmenu_03b.gif","mainmenu_04b.gif");
	document.newimg = new Array();
	for(var i = 0; i<allimg.length; i++)
	{
		document.newimg[i] = new Image;
		document.newimg[i].src = imgfolder+allimg[i];
	}
}

function menumouse(obj,img)
{	
	obj.src = "/images/"+img;
}

function trim(str)
{
	str = str.replace(/^\s+/,"");
	str = str.replace(/\s+$/,"");
	return str;	
}

function CreateAjax()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//A böngésző nem támogatja az ajaxot
				return false;
			}
		}
	}
	return xmlHttp;
}

function ajax(url,querystr,complete) {
	var xmlHttp = new CreateAjax();
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState==4)
		{
			complete(xmlHttp.responseText);
		}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=iso-8859-2");
	xmlHttp.setRequestHeader("Request-type","XMLHttpRequest");		
	if (xmlHttp.overrideMimeType)	xmlHttp.setRequestHeader("Connection","close");
	xmlHttp.send(querystr);
}


function keepalive()
{
	var ajaxLoad = new ajax("/admin/keepalive.php","",function(responseText){});
	var i = setTimeout(keepalive,900000);
}

function get(id) {
	return document.getElementById(id);
}

function isempty(str)
{
	r = new RegExp("^ *$");
	return r.test(str);
}

function checkValidEmail(mailstr) {
	r = new RegExp("^[0-9a-zA-Z._-]{2,}@([0-9a-zA-Z_-]{2,}\\.){1,7}[a-zA-Z]{2,3}$");
	return r.test(mailstr);
}  

function checkValidTel(telstr) {
	r = new RegExp("^[0-9]{6,7}$");
	return r.test(telstr);
}

function iecheck()
{
	var r = new RegExp("MSIE","g");
	return r.test(navigator.userAgent);
}

function ie_png_check()
{
	var pos = navigator.userAgent.indexOf("MSIE ");
	if (pos == -1) return false;
	var version = navigator.userAgent.substring(pos + 5);
	return ((version.indexOf("5.5") == 0) || (version.indexOf("6") == 0));
}

// PNG ALPHA CHANNEL IMG-RE //
function iepng_alphachannel(imgid,timg,size)
{
	if(ie_png_check())
	{
		d = (imgid.nodeType==1) ? imgid : document.getElementById(imgid);
		origsrc = d.src;
		d.src = timg;
		d.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + origsrc + "',sizingMethod='image')";
		d.width = size[0];
		d.height = size[1];
	}
}

// PNG ALPHA CHANNEL DIV BACKGROUND //
function iepng_alphachannel_bg(divid,bgimg,size)
{
	d = document.getElementById(divid);
	d.style.width = size[0]+"px";
	d.style.height = size[1]+"px";
	if(ie_png_check())
	{
		d.style.backgroundImage = '';
		d.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bgimg + "',sizingMethod='image')";
	}
}

// PNG ALPHA CHANNEL DIV BACKGROUND WITH CSS SELECTOR//
function iepng_alphacss_bg(node,clsname,bgimg,size)
{
	var sNode = document.getElementsByTagName(node), i;
	var elems = new Array();
	// 
	for(i=0;i<sNode.length;i++)
	{
		if(sNode[i].className==clsname) elems.push(sNode[i]);
	}

	for(i=0;i<elems.length;i++)
	{
		d = elems[i];
		d.style.width = size[0]+"px";
		d.style.height = size[1]+"px";
		if(ie_png_check())
		{
			d.style.backgroundImage = '';
			d.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bgimg + "',sizingMethod='image')";
		}
	}
}

String.prototype.strReverse = function()
{
	var newstring = "";
	for (var s=0; s < this.length; s++)
	{
		newstring = this.charAt(s) + newstring;
	}
	return newstring;
};

// getPageScroll() by quirksmode.com
function getPScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	return new Array(xScroll,yScroll) 
}

function sablonokOpen()
{
	var invite = '\
		<div><img src="/images/closelabel.gif" alt="" width="66" height="22" class="hand vmid floatright"\
		onclick="jQuery(document).trigger(\'close.facebox\')" />\
		<br class="clear" /></div><br />\
		<div style="float:left;">\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/001.gif\'" src="/images/sablonok/001_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/002.gif\'" src="/images/sablonok/002_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/003.gif\'" src="/images/sablonok/003_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/004.gif\'" src="/images/sablonok/004_small.gif" alt="" style="margin-bottom:5px; cursor:pointer;" /><br />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/005.gif\'" src="/images/sablonok/005_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/006.gif\'" src="/images/sablonok/006_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/007.gif\'" src="/images/sablonok/007_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/008.gif\'" src="/images/sablonok/008_small.gif" alt="" style="margin-bottom:5px; cursor:pointer;" /><br />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/009.gif\'" src="/images/sablonok/009_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/010.gif\'" src="/images/sablonok/010_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		<img onclick="document.getElementById(\'showsablon\').src=\'/images/sablonok/011.gif\'" src="/images/sablonok/011_small.gif" alt="" style="margin-right:5px; margin-bottom:5px; cursor:pointer;" />\
		</div>\
		<div style="float:left; padding-left:10px;">\
		<img id="showsablon" src="/images/sablonok/001.gif" alt="" />\
		</div>\
		<br class="clear" />\
	';
	jQuery.facebox(invite);
	$('#facebox .body').css('width', 720);
	$('#facebox').css('left', ($(window).width() / 2) - ($('#facebox table').width() / 2));
	$('#facebox').css('top', (($(window).height() / 2 ) + getPScroll()[1]) - ($('#facebox table').height() / 2));
}

/* SWF SETTINGS */
function insertFlash(swf,size,cel,fv)
{
	var str = "";
	var fvstr = "";
	for(var i = 0; i<fv.length; i++)
	{
		fvstr += fv[i][0]+"="+fv[i][1]+"&";
	}
	fvstr = fvstr.substr(0,fvstr.length-1);
	if(iecheck())
	{
		str +='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,12,36" width="'+size[0]+'" height="'+size[1]+'">';
		str +='	<param name="movie" value="'+swf+'" />';
		str +='	<param name="quality" value="high" />';
		str +=' <param name="menu" value="false" />';
		if(fvstr) str += '<param name="flashvars" value="'+fvstr+'" />';
		str +='</object>';

	}
	else
	{
		
		str +='<object type="application/x-shockwave-flash" data="'+swf+'" width="'+size[0]+'" height="'+size[1]+'">';
		str +='<param pluginurl="http://www.macromedia.com/go/getflashplayer">';
		str +='	<param name="menu" value="false" />';
		str +='	<param name="quality" value="high" />';
		if(fvstr) str += '<param name="flashvars" value="'+fvstr+'" />';
		str +='</object>';
	}
	document.getElementById(cel).innerHTML = str;
}

function FlashError()
{	
	get("multiup").innerHTML = 'A tartalom működéséhez legalább <b class="red">Flash Player 10<\/b> szükséges! <a href="http://get.adobe.com/flashplayer/?promoid=BUIGP" target="_blank">Flash Player letöltése<\/a>';
}

function nextQuestion(sor,id,qid,x)
{	
	var i, a=0, n = get("chooseboxid").childNodes;
	for(i=0;i<n.length;i++)
	{
		if(n[i].nodeType===1) { a++; } else { get("chooseboxid").removeChild(n[i]); }
	}
	var origdiv = n[n.length-1];
	origdiv.innerHTML = "";
	var loader = new Image();
	loader.src="/images/loadercsik.gif";
	loader.width=8;
	loader.height=39;
	loader.style.marginTop = "1px";
	origdiv.appendChild(loader);

	if(!id.match(/^0/))
	{
	// nyujtas
		get("chooseboxid").style.height = (((sor+1)*50)+10)+"px";
	}
	
	var d = document.createElement("DIV");
	d.className="question";
	d.style.backgroundImage = "url(/images/questionbg.png)";
	d.style.marginTop = "207px";
	get("chooseboxid").appendChild(d);

	var j = new ajax(
	"/process/getquestions.php",
	"&action=next&id="+id+"&qid="+qid+"&vnum="+x+"&sor="+sor,
	function(responseText)
	{
		iepng_alphacss_bg("DIV","question","/images/questionbg.png",new Array(667,40));
		var vege = responseText.split("<!--");
		origdiv.innerHTML = vege[1].substring(0,vege[1].length-3);
		d.innerHTML = responseText;
			// savszelesseg lekerdezes
			/*
			var bw = new ajax(
			"/process/getquestions.php",
			"&action=bandwith&id="+id.substring(2)+"&URI="+URI,
			function(bwText)
			{
				d.innerHTML = bwText;
			});				
			*/
			if(id.match(/^0/))
			{
				select_option(id.substring(2))
			}
			else
			{
				kozelit(d,10);
			}				
	});
}

function resultPackage(pid,oid,band)
{
	var n = get("chooseboxid").childNodes;
	var origdiv = n[n.length-1];
	origdiv.innerHTML = "";
	var loader = new Image();
	loader.src="/images/loadercsik.gif";
	loader.width=8;
	loader.height=39;
	loader.style.marginTop = "1px";
	origdiv.appendChild(loader);

	var a = new ajax(
	"/process/getquestions.php",
	"&action=result&pid="+pid+"&oid="+oid+"&URI="+URI,
	function (endText)
	{
		get("csboxfoot").className = "chooseboxfoot";
		get("vegeredmeny").innerHTML = endText;
		// kivonat keszites
		var t = get("bandwidth_"+pid);
		if(t)
		{
			var nt = document.createElement("TABLE");
			var lastCell = 4;

			nt.width="100%";
			nt.cellspacing = "0";
			nt.cellpadding = "0";
			nt.style.borderCollapse = "collapse";
			var ph = get("packageheader");
			
			var fr = nt.insertRow(0);
			fr.className = "tabla_header_arlista header_"+PAGE_COLOR;
			fr.style.fontSize = "11px";
			var fd1 = fr.insertCell(0);			
			fd1.className = "cella_head border_"+PAGE_COLOR;
			fd1.align ="left";
			fd1.innerHTML = ph.rows[0].cells[0].innerHTML;
			
			var fd2 = fr.insertCell(1);
			fd2.className = "cella_head border_"+PAGE_COLOR;
			fd2.align = "center";
			fd2.width = 40;
			fd2.innerHTML =  ph.rows[0].cells[1].innerHTML;
			
			var fd3 = fr.insertCell(2);
			fd3.className = "cella_head border_"+PAGE_COLOR;
			fd3.align = "right";
			fd3.width = 80;
			fd3.innerHTML =  ph.rows[0].cells[2].innerHTML;
			
			var fd4;
			if(t.rows[0].cells.length == 5)
			{
				fd4 = fr.insertCell(3);
				fd4.className = "cella_head border_"+PAGE_COLOR;
				fd4.align = "right";
				fd4.width = 237;
				fd4.innerHTML =  ph.rows[0].cells[3].innerHTML;

			}
			else
			{				
				lastCell = 5;
				fd4 = fr.insertCell(3);
				fd4.className = "cella_head border_"+PAGE_COLOR;
				fd4.align = "right";
				fd4.width = 110;
				fd4.innerHTML =  ph.rows[0].cells[3].innerHTML;
				
				fd4p = fr.insertCell(4);
				fd4p.className =  "cella_head border_"+PAGE_COLOR;
				fd4p.width = 110;
				fd4p.align = "right";
				fd4p.innerHTML = ph.rows[0].cells[4].innerHTML;
			}
			
			var fd5 = fr.insertCell(lastCell);
			fd5.className = "cella_head";
			fd5.width = 110;
			fd5.align = "center";
			fd5.innerHTML =  ph.rows[0].cells[lastCell].innerHTML;
			
			// ------------------------------------------------------------------- //
			// TARTALOM SOR //
			var nr = nt.insertRow(1);
			// elso oszlop // NEVE
			var nd1 = nr.insertCell(0);
			nd1.className = "cells border_"+PAGE_COLOR;
			nd1.valign = "top";
			var cval = t.rows[0].cells[0].getElementsByTagName("TD");
			nd1.innerHTML = cval[0].innerHTML;
			
			// masodik oszlop // HUSEGIDO
			var nd2 = nr.insertCell(1);
			nd2.className = "f14 cells border_"+PAGE_COLOR; //f14 ;
			nd2.valign = "top";
			nd2.align = "center";
			nd2.width = 40;
			nd2.style.fontWeight = "bold";
			nd2.style.fontSize = "14px";
			nd2.innerHTML = t.rows[0].cells[1].innerHTML;
			
			// harmadik oszlop // EGYSZERI DIJ
			var nd3 = nr.insertCell(2);
			nd3.className = "f14 cells border_"+PAGE_COLOR;
			nd3.valign = "top";
			nd3.align = "right";
			nd3.width = 80;
			nd3.innerHTML = t.rows[0].cells[2].innerHTML;
			
			// negyedik oszlop // HAVI DIJ
			if(t.rows[0].cells.length == 5)
			{
				var nd4 = nr.insertCell(3);
				nd4.className = "f14 text_"+PAGE_COLOR+" cells border_"+PAGE_COLOR;
				nd4.valign= "top";
				nd4.align = "right";
				nd4.width = 237;
				nd4.style.fontSize = "14px";
				nd4.innerHTML = t.rows[0].cells[3].innerHTML;
			}
			else
			{
				var nd4 = nr.insertCell(3);
				nd4.className = "f14 text_"+PAGE_COLOR+" cells border_"+PAGE_COLOR;
				nd4.valign= "top";
				nd4.align = "right";
				nd4.width = 110;
				nd4.style.fontSize = "14px";
				nd4.innerHTML = t.rows[0].cells[3].innerHTML;

				var nd4p = nr.insertCell(4);
				nd4p.className = "f14 text_"+PAGE_COLOR+" cells border_"+PAGE_COLOR;
				nd4p.valign= "top";
				nd4p.align = "right";
				nd4p.width = 110;
				nd4p.style.fontWeight = "bold";
				nd4p.style.fontSize = "14px";
				nd4p.innerHTML = t.rows[0].cells[4].innerHTML;
			}
			
			// otodik oszlop // MEGRENDELÉS
			var nd5 = nr.insertCell(lastCell);
			nd5.className = "cells";
			nd5.valign= "top";
			nd5.align = "center";
			nd5.width = 110;
			nd5.style.backgroundColor = "#9af158";
			var lnk = t.rows[0].cells[lastCell].getElementsByTagName("A");
			nd5.innerHTML = '<img src="/images/megrendelem.gif" width="103" height="55" alt="Megrendelem" border="0" class="hand" onclick="'+lnk[0].href.replace(/javascript:/,'')+'" />';
			
			get("csecontent").innerHTML = "";
			get("csecontent").appendChild(nt);
			get("cskivonat").style.display = "block";
			origdiv.innerHTML = band + " sávszélességet szeretnék.";
			window.location = "#kivonatposition";
		}
	});
}

function resetChoose()
{	
	var i, a=0, n = get("chooseboxid").childNodes;
	// clear nodes
	for(i=0;i<n.length;i++)
	{
		if(n[i].nodeType===1) { a++; } else { get("chooseboxid").removeChild(n[i]); }
	}
	
	// remove nodes
	if(n.length>1)
	{
		get("chooseboxid").style.height = "60px";
		while(get("chooseboxid").childNodes.length>1)
		{
			get("chooseboxid").removeChild(n[1]);
		}
		
		var x = new ajax(
		"/process/getquestions.php",
		"&action=reset&URI="+URI,
		function(responseText)
		{
			n[0].innerHTML = responseText;
		});
	}
	
	// remove eredmeny
	get("csboxfoot").className = "chooseboxfootbg";
	get("csecontent").innerHTML = "";
	get("cskivonat").style.display = "none";
	get("vegeredmeny").style.display = "none";
	get("vegeredmeny").innerHTML = "";
	get("tariff").innerHTML = opts_full;
}

function viewCsDetails()
{
	get("vegeredmeny").style.display = "block";
	get("vegeredmeny").focus();
	window.location = "#chooseboxfoot";
}

function kozelit(d,cel)
{
		var m = parseFloat(d.style.marginTop.replace(/[^0-9.]/g,""));
		m += (cel-m)/2;
		d.style.marginTop = m+"px";
		if(Math.abs(10-m)>0.1) setTimeout(function(){kozelit(d,cel)},50);
}
