/* JQUERY REQUIRED */

var scripts = document.getElementsByTagName("script");
eval( scripts[ scripts.length - 1 ].innerHTML );
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('r.E.W=7(c,d){c=c||".";d=q d=="7"?d:7(){};6.K(7(e){g a=e.i?e.i:e.h?e.h:0;2(a==k&&6.N.J()=="G"){5 3}f 2(a==k){5 j}g b=j;2((e.4&&a==y)||(e.4&&a==v))5 3;2((e.4&&a==t)||(e.4&&a==u))5 3;2((e.4&&a==V)||(e.4&&a==S))5 3;2((e.4&&a==R)||(e.4&&a==Q))5 3;2((e.4&&a==P)||(e.4&&a==O)||(e.L&&a==p))5 3;2(a<I||a>H){2(a==p&&6.l.F==0)5 3;2(a==c.n(0)&&6.l.o(c)!=-1){b=j}2(a!=8&&a!=9&&a!=k&&a!=D&&a!=C&&a!=M&&a!=B&&a!=A){b=j}f{2(q e.i!="z"){2(e.h==e.m&&e.m!=0){b=3}f 2(e.h!=0&&e.i==0&&e.m==0){b=3}}}2(a==c.n(0)&&6.l.o(c)==-1){b=3}}f{b=3}5 b}).x(7(){g a=r(6).w();2(a!=""){g b=T U("^\\\\d+$|\\\\d*"+c+"\\\\d+");2(!b.s(a)){d.X(6)}}});5 6}',60,60,'||if|true|ctrlKey|return|this|function||||||||else|var|keyCode|charCode|false|13|value|which|charCodeAt|indexOf|45|typeof|jQuery|exec|120|88|65|val|blur|97|undefined|46|39|36|35|fn|length|input|57|48|toLowerCase|keypress|shiftKey|37|nodeName|86|118|90|122|67|new|RegExp|99|numeric|apply'.split('|'),0,{}))

$(document).ready(function(){
	
	$("#tab-list A").filter(":first").addClass("act");
	$(".faq > LI > A").toggle( function() { $(this).css("background-position", "0 -25px"); $("#"+this.name).slideDown("fast"); },
							   function() { $(this).css("background-position", "0 0"); $("#"+this.name).slideUp("fast"); } );

	$("#pg > LI > A").click(function() { 
								window.open(this.name, 'subWnd' , 'height=50, width=50, scrollbars=no, toolbar=no, menubar=no, left=200, top=50'); 
							});
	
	$("#sitemap UL > LI:first").css("margin-left", "-20px");
	
	$("A[href='#']").attr("href", "javascript:void(0)");
	
	$("#subscription_btn").click(function() {
										  
												$("#subscription_msg").hide();
												$("#subscription_email").css("background", "#fff");
												$.post(BASE_HREF + 'ajax/subscribe.php', 
												   { email: $("#subscription_email").val(),
												   	 lng: LANG },
												   function (data) {
											   			$("#ajax").html(data);
												   }
											    );
												
											 });

	$("#print_btn").click( function () { printpage() } );
	
	$(".hide_email").each(function () { 
									$(this).attr("href", "mailto:" + $(this).attr("name") + "@" + $(this).attr("title"))
										   .html($(this).attr("name") + "@" + $(this).attr("title")); });
	
	$("#fueltype").change( function () { calculate($("#fueltype"), $("#area"), $("#h"), $("#coef")) } );
	$("#price").numeric().keyup( function () { calculate($("#fueltype"), $("#area"), $("#h"), $("#coef"), $("#price").val()) } );
	$("#fueltype").keyup( function () { calculate($("#fueltype"), $("#area"), $("#h"), $("#coef")) } );
	$("#area").numeric().keyup( function () { calculate($("#fueltype"), $("#area"), $("#h"), $("#coef")) } );
	$("#h").numeric().keyup( function () { calculate($("#fueltype"), $("#area"), $("#h"), $("#coef")) } );
	$("#coef").numeric().keyup( function () { calculate($("#fueltype"), $("#area"), $("#h"), $("#coef")) } );
	
	function calculate(type, area, h, coef, price) {
		
		var _area = $(area).val();
		var _type = $(type).val();
		var _h 	  = $(h).val();
		var _coef = $(coef).val();
		
		var prices 	= Array(0, 130, 1.58, 1.58, 570, 450, 0.33, 0.15, 2650, 0.33, 500, 130);
		var q 		= Array(0, 2160, 9.47, 9.47, 7300, 4600, 1, 1, 12790, 1, 4700, 2000);
		var kpd 	= Array(0, 0.75, 1.08, 0.93, 0.75, 0.8, 3, 1, 0.93, 0.99, 0.9, 0.75);
		
		if (typeof price === 'undefined') {
			price = prices[_type];
		}
		
		
		var volume = _area * _h;
		
		var maxq = Math.round((0.001* (0.54 + (22 / 42) ) * (1.52 / Math.sqrt(Math.sqrt(Math.sqrt(volume)))) * volume * 42) * _coef * 100) / 100;
		
		var power = Math.round(maxq * 1.2 + 4);
		
		var pricekwh = Math.round(price/q[_type]/kpd[_type]*10000) / 100;

		var t = (0.0009*(0.54+(22/20.5))*(1.52/Math.sqrt(Math.sqrt(Math.sqrt(volume))))*volume*20.5)*_coef;
		var temp = (Math.round( ( (t*24*192)/q[_type]/kpd[_type] ) * 100 ) / 100)
		var priceseason = Math.round(price * temp);

		var pricemonth = Math.round(100 * (priceseason / 192 * 30)) / 100;
		
		var fuelamount = Math.round(temp*100)/100;
		
		$("#price").val(price);
		$("#power").val(power);		
		$("#maxq").val(maxq);
		$("#pricekwh").val(pricekwh);
		$("#priceseason").val(priceseason);
		$("#pricemonth").val(pricemonth);		
		$("#fuelamount").val(fuelamount);	
		
	}
	
	calculate($("#fueltype"), $("#area"), $("#h"), $("#coef"));
	
});

function show(id) {
	if (id == 1) {
		$("#news-cat-2").hide();
		$("#news-cat-1").show();
		$("#tab-list A").filter(":first").addClass("act");
		$("#tab-list A").filter(":last").removeClass("act");
	} else {
		$("#news-cat-1").hide();
		$("#news-cat-2").show();
		$("#tab-list A").filter(":first").removeClass("act");
		$("#tab-list A").filter(":last").addClass("act");
	}
}

function printpage() {
	var url = document.location.href;
	
	for (i = url.length; i > 0; i--) {
		if (url[i] == '?') {
			url = url + '&';
			break;
		} else if ((url[i] == '/') || (url[i] == '\\')) {
			url = url + '?';
			break;
		}
	} // pridet ? jei nera paramu, pridet & jei yra paramu

	win = window.open(url + 'do=print', 'popup', 'toolbar = 0, scrollbars = 1, status = 0');
	win.window.print();
}
