﻿/*Muveletek az oldal betöltodésekor*/
function addOnLoad(func){
	if (window.addEventListener) {
		window.addEventListener("load",func,false);
	} else if (window.attachEvent) {
		window.attachEvent("onload",func);
	} else {
		if ((typeof window.onload) != 'function' ) {
			var func2 = window.onload;
			window.onload = function() {func2(); func();};
		} else
			window.onload = func;
	}
}
//Hibaüzenet elrejtése
var errormsg_hidden=0;
function hide_loginerror(id) {
	if(!errormsg_hidden){
		if (document.getElementById(id) != null) {
			toggle(id, 'appear', {to: 0, delay:0, duration:1});
			errormsg_hidden=1;
		}
	}
}

//Macromedia
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function sH(e,i) { e.style.height=i+"px"; }

function oH(e) { return e.offsetHeight; }
function oW(e) { return e.offsetWidth; }

function wH() {
	var h = 0; 
	if (self.innerHeight) {
		h = self.innerHeight; 
	} else if (document.documentElement && document.documentElement.clientHeight) {
		h = document.documentElement.clientHeight; 
	} else if (document.body) {
		h = document.body.clientHeight;
	}
	return h;
}
function wW() {
	var w = 0; 
	if (self.innerWidth) {
		w = self.innerWidth; 
	} else if (document.documentElement && document.documentElement.clientWidth) {
		w = document.documentElement.clientWidth; 
	} else if (document.body) {
		w = document.body.clientWidth;
	}
	return w;
}

function $(id) { return document.getElementById(id); }

function login_layout(loginboxID) {
	var loginbox = $(loginboxID);
	if (loginbox != null) {
		var windowWidth = wW();
		var windowHeight = wH();
		var loginboxWidth = oW(loginbox);
		var loginboxHeight = oH(loginbox);
		var Xcenter = windowWidth/2-loginboxWidth/2;
		var Ycenter = windowHeight/2-loginboxHeight/2;
		loginbox.style.left = Xcenter+"px";
		loginbox.style.top = Ycenter+"px";
	}
}

function post(name) {
	document.forms[name].submit();
}
function post_redirect(name) {
	var oldaction = new String(document.forms[name].action);
	var oldurl = new String(document.location);
	var len = oldurl.indexOf("index.php") + 16;
	//document.forms[name].action = oldaction + "&url=" + escape(oldurl.substr(len, oldurl.length-len));
	document.forms[name].action = oldaction + ((oldaction.indexOf("?")>0)?"&":"?") + "url=" + escape(oldurl);
	document.forms[name].submit();
}
function gotopage(url){
	location.href=url;
}
mutat_allapot={};
var azon='';
function toggleIds(){
	mutat_allapot[azon]=0;
	azon='';
}
function mutat_menu(id, id2) {
	mutat_allapot[id]=1;
	document.getElementById(id2+"_div").innerHTML=document.getElementById('public_top_menu').innerHTML;
	document.getElementById('public_top_menu').innerHTML=document.getElementById(id+"_div").innerHTML;
	document.getElementById(id+"_div").innerHTML='';
	azon=id2;
	setTimeout("toggleIds();", 100);
}

function mutat_otletekrol_almenu(id) {
	if(!mutat_allapot[id]) {
		mutat_menu(id, 'public_green_submenu');
	}
}

function mutat_rolunk_almenu(id) {
	if(!mutat_allapot[id]) {
		mutat_menu(id, 'public_orange_submenu');
	}
}
function count_rate_of_return(){
document.getElementById('result').style.display='none';
//try {
var company_size=parseInt(document.getElementById('company_size').value);
var project_num=3;//project_num=parseInt(document.getElementById('project_num').value);
var rate1=parseInt(document.getElementById('rate1').value)/100;
var rate2=parseInt(document.getElementById('rate2').value)/100;
var rate3=parseInt(document.getElementById('rate3').value)/100;
var income1=parseInt(document.getElementById('income1').value);
var income2=parseInt(document.getElementById('income2').value);
var income3=parseInt(document.getElementById('income3').value);
var income_avg=income1*rate1+income2*rate2+income3*rate3;months=12;
var user_rate=0.5;var view_index=0.3;var inf_usage=0.05;
var committed_yes=0.22;var committed_no=0.63;var committed_med=0.15;
var damage_no=0.15;var damage_med=0.34;
var correction_no=0.02;var correction_med=0;
var fluct_raise1=0.01;var fluct_raise2=0.01;var fluct_raise3=0.01;
var b4=3;var b5=1;var b6=1;var b7=2;var b8=4;var b9=7;var b13=0.1;
var l1=(b4*(b4-1)/2)*b7*income1+b4*b7*(income2+income3);
var l2=(b5*(b5-1)/2)*b8*income2+b5*b8*(income1+income3);
var l3=(b6*(b6-1)/2)*b9*income3+b6*b9*(income1+income2);
var loss=(l1+l2+l3)*b13;
var rate=user_rate*view_index*inf_usage*company_size*project_num;
 var inf_flow=loss*rate;
var damage_before=income_avg*company_size*months*committed_no*damage_no+income_avg*company_size*months*committed_med*damage_med;
var damage_after=income_avg*company_size*months*(committed_no-correction_no*project_num)*damage_no+income_avg*company_size*months*committed_med*(damage_med-correction_med*project_num);
 var commitment_grow=damage_before-damage_after;
var loss1=1.3*((4+5+5)*income2/22/8+2*income2/22/8+(1-0.7)*0.5*income1+3*income1+2*0.1*income1);
var loss2=1.2*((8+15+15)*income2/22/8+4*income2/22/8+(1-0.7)*2*income2+3*income2+2*0.2*income2);
var loss3=1.1*((16+30+50)*income2/22/8+8*income2/22/8+(1-0.7)*6*income3+3*income3+1*0.3*income3);
var saving1=company_size*rate1*fluct_raise1*project_num*loss1
var saving2=company_size*rate2*fluct_raise2*project_num*loss2;
var saving3=company_size*rate3*fluct_raise3*project_num*loss3;
 var commitment_fall=saving1+saving2+saving3;
var sum = inf_flow+commitment_grow+commitment_fall;
document.getElementById('inf_flow').innerHTML=split3(Math.round(inf_flow))+" Ft/év";
document.getElementById('commitment_grow').innerHTML=split3(Math.round(commitment_grow))+" Ft/év";
document.getElementById('commitment_fall').innerHTML=split3(Math.round(commitment_fall))+" Ft/év";
document.getElementById('sum').innerHTML=split3(Math.round(sum))+" Ft/év";
//} catch (e) { alert("Hibás adatok."); return; }
try {
new Effect.Appear('result');
new Effect.Highlight('inner_result');
} catch (err) {
document.getElementById('result').style.display='block';
}
//document.getElementById('result').style.display='block';
}
split3 = function (num) {
    var to = String(num);
    var tmp = "";
    while (to != (tmp = to.replace(/^([+-]?\d+)(\d\d\d)/,"$1 $2"))){
        to = tmp;
    }
    return to;
}
