function ChangeFoto_Sp(nr,url_sp,url_ne_sp,style){
document.getElementById("v_foto_"+nr).innerHTML='<img style="'+style+'" onMouseOut="ChangeFoto_Ne_Sp(\''+nr+'\',\''+url_sp+'\',\''+url_ne_sp+'\',\''+style+'\')" src="'+url_sp+'" alt="" />';
}

function ChangeFoto_Ne_Sp(nr,url_sp,url_ne_sp,style){
document.getElementById("v_foto_"+nr).innerHTML='<img style="'+style+'" onMouseOver="ChangeFoto_Sp(\''+nr+'\',\''+url_sp+'\',\''+url_ne_sp+'\',\''+style+'\')" src="'+url_ne_sp+'" alt="" />';
}

function openWindow(url, name, properties, openerName) {
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
	winReference = window.open('about:blank', name, properties);
	setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else {
	winReference = window.open(url, name, properties);
	}
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);

	if (openerName) self.name = openerName;
	return winReference;
}

function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {

	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1 && (agent.indexOf("msie 4") != -1 || agent.indexOf("msie 5.0") != -1) ) {
	height += (status) ? 17 : 2;
	}
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;
	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
	var reference = openWindow(url, name, properties, openerName);

	return reference;
}

function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {

	var x, y = 0;
	if (screen) {
	x = (screen.availWidth - width) / 2;
	y = (screen.availHeight - height) / 2;
	}
	if (!status) status = '';
	if (!openerName) openerName = '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;
}

function openImagePopupCentered(url, width, height, window_name, title, flash){
  if(title + "" == "undefined"){
		title = "-";
	}
	var win = openCenteredWindow("", window_name, parseInt(width), parseInt(height), 0, 0, "");
	var body = '<html><head><title>'+title+'</title></head><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">_uacct = "UA-3798973-1";urchinTracker();</script>';
	if(!flash){
		body += "<table width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td align=\"center\" valign=\"center\"><img style=\"\" onclick=\"window.close();\" alt=\"\" src=\""+url+"\"></td></tr></table>";
	}
	else{
		body += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+url+'"><param name="quality" value="high"><param name="menu" value="false"><embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width='+width+' height='+height+'></embed></object>';
	}
	body += "</body></html>";

	win.document.write(body);
	win.document.close();
	return false;
}

function OpenImagePopup(dir,width, height, window_name, title, flash) {

 window.open(dir+url_orig,'_blank','height=600,width=800,status=yes,toolbar=no,menubar=no,location=no,resizable=yes');
        
}

function ChangeFoto_Proj(dir,nr1,nr2,nr3,url_orig1,url_orig2,url_orig3,url1,url2,url3,url_sp1,url_sp2,url_sp3,style){   
var pic='';

  if (url_orig1!=''){
  pic += '<div style="margin:11px;background-color:#FFFFFF;" onclick="OpenImagePopup(\''+dir+'\',\''+url_orig1+'\')" id="v_foto_'+nr1+'"><div><img style="'+style+'" onMouseOver="ChangeFoto_Sp(\''+nr1+'\',\''+dir+url_sp1+'\',\''+dir+url1+'\',\''+style+'\')" src="'+dir+url1+'" alt="" /></div></div>';
  }
  if (url_orig2!=''){
  pic += '<div style="margin:11px;background-color:#FFFFFF;" onclick="OpenImagePopup(\''+dir+'\',\''+url_orig2+'\')" id="v_foto_'+nr2+'"><div><img style="'+style+'" onMouseOver="ChangeFoto_Sp(\''+nr2+'\',\''+dir+url_sp2+'\',\''+dir+url2+'\',\''+style+'\')" src="'+dir+url2+'" alt="" /></div></div>';
  }
  if (url_orig3!=''){
  pic += '<div style="margin:11px;background-color:#FFFFFF;" onclick="OpenImagePopup(\''+dir+'\',\''+url_orig3+'\')" id="v_foto_'+nr3+'"><div><img style="'+style+'" onMouseOver="ChangeFoto_Sp(\''+nr3+'\',\''+dir+url_sp3+'\',\''+dir+url3+'\',\''+style+'\')" src="'+dir+url3+'" alt="" /></div></div>';
  }
document.getElementById("img_proj").innerHTML = pic;
}


function noKeychars(el,e,from,to){
var keynum;
var keychar;
var numcheck;
var allkeychar ="";
var elval = document.getElementById(el).value;
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum);
allkeychar += elval + keychar;
	if (keynum!=8){
		if (keynum < 48 || keynum > 57 || allkeychar < from){
		return false;
		}
	}
}
function calcSkaiciuokle(){

var prad_in_output; 
procentas=5.1;
        var princ = document.getElementById("kain").value;
		if (princ!=''){
			var prad_in = document.getElementById("inasas").value;
			var term = document.getElementById("terminas").value;
				if (prad_in!=''){
				prad_in_output = Math.round((parseInt(princ)*parseInt(prad_in)/100));
				princ = parseInt(princ)-parseInt(prad_in_output);
				} else { prad_in_output = 0;}
	        intRate = (procentas/100) / 12;
	        months = term * 12;
				if (term!=''&&term!=0){
		        men = Math.round(Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100);
				} else { men ='';}
		}
		else { men=''; prad_in_output='';}
  document.getElementById("imoka_hansa").value= men;
  document.getElementById("pradinis").value = prad_in_output;
  document.getElementById("pradinis_hansa").value= Math.round(prad_in_output);
}

function CalcFinSkaiciuokle(pask_suma,term_metais,valiuta,graz_grafikas,gryn_pajamos,fin_isipareigojimai){
var rez1;var rez2;
var acl = 625;
var lt_eur =3.4528;
var procentas=5.1;

if (graz_grafikas=="Linijinis"){

rez1 = Math.round(pask_suma*procentas/12/100+pask_suma/term_metais/12);
temp_rez1 = Math.round(pask_suma*(procentas+2)/12/100+pask_suma/term_metais/12); 
}
else {
    princ = pask_suma;
    intRate = (procentas/100) / 12;
    months = term_metais * 12;
    men = Math.round(Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100);
	rez1 = men;
temp_rez1 = Math.round(Math.floor((princ*(((procentas+2)/100)/12))/(1-Math.pow(1+(((procentas+2)/100)/12),(-1*months)))*100)/100);	
}
var im_paj_san = Math.round(((parseInt(fin_isipareigojimai)+parseInt(temp_rez1))*100)/gryn_pajamos);
if(gryn_pajamos<=900){var max_im_paj_san = 30;}
else if(gryn_pajamos<=3000){var max_im_paj_san = 40;}
else if(gryn_pajamos<=7000){var max_im_paj_san = 57;}
else {var max_im_paj_san = 60;}
rez2 = gryn_pajamos - fin_isipareigojimai - rez1;
	if (rez2<rez1||rez1<0){//jei paskolos imoka didesne nei lieka pragyvenmui
	document.getElementById("pranesimas").innerHTML="Pranešimas: Nepakankamos pajamos!";
	document.getElementById("rez1").innerHTML="-";document.getElementById("rez2").innerHTML="-";
	}
	else if(rez1==0){
	document.getElementById("pranesimas").innerHTML="";
	document.getElementById("rez1").innerHTML="-";
	document.getElementById("rez2").innerHTML="-";
	}
	else {
	document.getElementById("pranesimas").innerHTML="";
	document.getElementById("rez1").innerHTML=rez1;document.getElementById("rez2").innerHTML=rez2;
	}
document.getElementById("pranesimas_uzkl").innerHTML="";
}

function finSkaiciuokle(mod){
	var seb_email = "info@seb.lt;";
	var hansa_email = "info@hansa.lt;";
	var nordea_email = "laurinta.elinskaite@nordea.com;raimonda.cernovaite@nordea.com;info@nordea.lt;";
	var sampo_email = "aiste.kuzminaite@sampobankas.lt;";
	var to_email = "mindaugas.zemaitis@reals.lt;";
	var err ="";
	var pask_suma           = document.getElementById("pask_suma"          ).value;
	var term_metais         = document.getElementById("term_metais"        ).value;
	var valiuta             = document.getElementById("valiuta"            ).value;
	var graz_grafikas       = document.getElementById("graz_grafikas"      ).value;
	var gryn_pajamos        = document.getElementById("gryn_pajamos"       ).value;
	var fin_isipareigojimai = document.getElementById("fin_isipareigojimai").value;
	if (document.getElementById("prad_in").value!=0){
	pask_suma = parseInt(document.getElementById("pask_suma").value) - parseInt(document.getElementById("prad_in").value);}
	var fname    = document.getElementById("fname"   ).value;
	var fsurname = document.getElementById("fsurname").value;
	var fphone   = document.getElementById("fphone"  ).value;
	var faddress = document.getElementById("faddress").value;
	var femail   = document.getElementById("femail"  ).value;
	var fmiestas = document.getElementById("fmiestas").value;
	var arr_skaic_laukai = ["pask_suma","term_metais","valiuta","graz_grafikas","gryn_pajamos","fin_isipareigojimai","prad_in"];
	for (var n=0; n<arr_skaic_laukai.length; n++){
		if (document.getElementById(arr_skaic_laukai[n]).value==""){
		err=1;
		if (mod=="skaic"){//jei ne visi laukai uzpildyti
		document.getElementById("pranesimas").innerHTML="Pranešimas: Užpildykite skaičiuoklės tuščius laukus!";
		document.getElementById("pranesimas_uzkl").innerHTML="";
		document.getElementById("rez1").innerHTML="-";document.getElementById("rez2").innerHTML="-";
		}
		break;
		}
	}
	if (err!=1&&mod=="skaic"){
		if (term_metais>40||term_metais==0){//jei terminas daugiau uz 40 metu ar lygu 0
		document.getElementById("pranesimas").innerHTML="Pranešimas: Paskolos terminas nuo 1 iki 40 metų!";
		document.getElementById("pranesimas_uzkl").innerHTML="";
		document.getElementById("rez1").innerHTML="-";
		document.getElementById("rez2").innerHTML="-";
		}
		else {//skaiciuojami rezultatai
		document.getElementById("pranesimas").innerHTML="";
		document.getElementById("pranesimas_uzkl").innerHTML="";
		CalcFinSkaiciuokle(pask_suma,term_metais,valiuta,graz_grafikas,gryn_pajamos,fin_isipareigojimai);
		}
	}
	//uzklausos atveju
	if (mod=="uzkl"){
		if (document.getElementById("rez1").innerHTML==0||document.getElementById("rez2").innerHTML==0||document.getElementById("rez1").innerHTML=="-"||document.getElementById("rez2").innerHTML=="-"||document.getElementById("rez1").innerHTML=="<b>-</b>"||document.getElementById("rez2").innerHTML=="<b>-</b>"){
		
		document.getElementById("pranesimas_uzkl").innerHTML="Pranešimas: Nėra skaičiuoklės rezultatų!";
		}
		else if (fname==""||fsurname==""||fphone==""||fmiestas==""||faddress==""){//jei ne visi laukai uzpildyti
		document.getElementById("pranesimas_uzkl").innerHTML="Pranešimas: Užpildykite Vardo, Pavardės, Telefono, Miesto, Adreso laukus!"; 
		}
		else {
		err = 4;
		document.getElementById("pranesimas_uzkl").innerHTML="";
		if(document.getElementById("chb_seb").checked){var chb_seb=1;} else {var chb_seb=0;}
		if(document.getElementById("chb_hansa").checked){var chb_hansa=1;} else {var chb_hansa=0;}
		if(document.getElementById("chb_nordea").checked){var chb_nordea=1;} else {var chb_nordea=0;}
		if(document.getElementById("chb_sampo").checked){var chb_sampo=1;} else {var chb_sampo=0;}
	
		var rez11 = document.getElementById("rez1").innerHTML;
		var rez22 = document.getElementById("rez2").innerHTML;
		//siunciami email
		makeRequest("./include/dinaminiai_includai/skaiciuokle/finansai.php?seb_email="+seb_email+"&hansa_email="+hansa_email+"&sampo_email="+sampo_email+"&nordea_email="+nordea_email+"&to_email="+to_email+"&err="+err+"&chb_seb="+encodeURI(chb_seb)+"&chb_hansa="+encodeURI(chb_hansa)+"&chb_nordea="+encodeURI(chb_nordea)+"&chb_sampo="+encodeURI(chb_sampo)+"&fname="+encodeURI(fname)+"&fsurname="+encodeURI(fsurname)+"&femail="+encodeURI(femail)+"&fphone="+encodeURI(fphone)+"&fmiestas="+encodeURI(fmiestas)+"&faddress="+encodeURI(faddress)+"&pask_suma="+pask_suma+"&term_metais="+term_metais+"&valiuta="+valiuta+"&graz_grafikas="+graz_grafikas+"&gryn_pajamos="+gryn_pajamos+"&fin_isipareigojimai="+fin_isipareigojimai+"&rez11="+rez11+"&rez22="+rez22,"pranesimas_uzkl");	
		}
	}
}

function makeRequest( url, kitas_elemntas1) {

        kitas_elemntas=kitas_elemntas1;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Runtime Error!');
            return false;
        }
        http_request.onreadystatechange = showContents;
        http_request.open('GET', url, true);
        http_request.send(null);

    } 
    
    
   function showContents() {
 if (http_request.readyState == 4) {
			if (http_request.status == 200) {
   document.getElementById(kitas_elemntas).innerHTML=http_request.responseText;
   }}
   }

function pic(id,sk) {

var lenta = document.getElementById("foto_list")
var old_sk = document.getElementById("old_sk").value;
document.getElementById("p"+old_sk).style.backgroundColor='#9DAAB0';
document.getElementById("p"+sk).style.backgroundColor='#E77919';
document.getElementById("old_sk").value=sk;
}