var path = "http://energijaplius.lt/";

if( typeof XMLHttpRequest == "undefined" )
  XMLHttpRequest = function() {
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP") }     catch(e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP") }  catch(e) {}
    throw new Error( "This browser does not support XMLHttpRequest or XMLHTTP." )
  };

function ajax_survey(form, element, div, id, url)
{
	if(form != "" && element != "") 
		var value = getCheckedValue(document.forms[form].elements[element]);
	var request = new XMLHttpRequest(); 
	
	request.onreadystatechange = function(){
		if(request.readyState == 4){
			var ajaxDisplay = document.getElementById(div);
			ajaxDisplay.innerHTML = request.responseText;
		}
		if(request.readyState == 3){
			var ajaxDisplay = document.getElementById(div);
			ajaxDisplay.innerHTML = "<table width=500 align=center><tr><td height=\"100\" align=\"right\"><img src='"+path+"class/ajax-loader.gif'></td></tr></table>";
		}
	}
	
	var queryString; 
	if(id == "0") queryString = "answer_id=" + value;
	else if(id == "-1") queryString = "";
	else queryString = "question_id=" + id;
	request.open("GET", url+queryString, true);
	request.send(null); 
	
	
	
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}




function skaiciuoti()
{
	 var kampas  = document.getElementById('kampas').value;
	 var galia  = document.getElementById('galiaa').value;
	 var plotas  = document.getElementById('plotasa').value;
	 var tipas  = document.getElementById('tipas').value;
	 var kaina  = document.getElementById('kaina').value;
	 var kryptis  = document.getElementById('kryptis').value;
	 

	 if(document.getElementById('pp').checked)
	 	var s = 1;
	else
		var s = 2;
	 
	 
	var rez ='aaa';
	
	var saule = Get_Cookie('lietuva');
	
	
	if(s==1)
	{
		galia = plotas/7.5;
	}
	
	var duomenys = new Array(new Array(758, 758, 759, 759, 759, 759, 758), new Array(830, 807, 747, 675, 647, 676 ,748, 808), new Array(863, 829, 726, 52, 522, 585, 729, 830), new Array(868, 829, 712, 544, 465, 547, 729, 830), new Array(862, 819, 691, 504, 394, 507, 694, 821), new Array(821, 777, 635, 430, 292, 433, 639, 778));
	
	
	var D = duomenys[kampas][kryptis] / 1040;

	var R = D * saule*1.05;
	
	
	
	//R = R * saule; // tiek sugeneruotu kilovatu 1 kw jegaine
	
	if(tipas=='poli') R = R - 10;
	
	R = R * galia; // tiek sugeneruos elektros energijos per metus
	R = R.toFixed(2)

	var plotas = galia * 7.5;
	var pajamos = kaina*R;
	pajamos = pajamos.toFixed(2);
	plotas = plotas.toFixed(2);
	
	rez = "Tai yra preliminarūs skaičiavimo rezultatai<br /><br />Sistema sugeneruos* "+R+" kWh per metus<br />Užimamas plotas "+plotas+" m<sup>2</sup><br />Pajamos "+pajamos+" LT per metus<br /><br /><span style=\"color:#999\">*Skaičiavimuose įvertinti ir nuostoliai<br /><br />Pasinaudojus ES parama saulės jėgainės atsipirkimas iki 5 m.</span><br /><br />Dėl detalesnės informacijos prašome kreiptis:<br />Kont. tel.: 8 686 83062<br />el. paštu: info@energijaplius.lt";


	
	var rezas = document.getElementById('rez');
	rezas.innerHTML = rez;
	 

}

function skaiciuoti_v()
{
	 var aukstis  = document.getElementById('aukstis').value;
	 var klase  = document.getElementById('klase').value;
	 var kaina  = document.getElementById('kaina').value;
	 var vejas = Get_Cookie('lietuva');
	 
	 
	 var vertikali  =   document.getElementById('vertikali').value;
	 var horizontali  = document.getElementById('horizontali').value;
	 

	 
	 if(document.getElementById('pp').checked)
	 	var s = 1;
	 else
		var s = 2;
	
	
	if(s==1)
	{
		var galia = vertikali;
	}
	
	if(s==2)
	{
		var galia = horizontali;
	}
	

	
		 
	 var C;
	 var mas = new Array(6.02, 5.55, 4.9, 4.71, 4.5, 3.93, 3.2);
	 
	 var laipsnis = new Array(0.08, 0.11, 0.14, 0.16, 0.19, 0.25, 0.38);
	 
	 if(aukstis==50)
	 {
		var sk = mas[klase]/mas[4]; 
		var greitis = vejas * sk;
	 }
	 else
	 {
		var sk = mas[klase]/mas[4]; 
		var greitis = vejas * sk;

		var a = aukstis/50;
		var l = laipsnis[klase];
		var a = Math.pow(a, l);
		
		var greitis = greitis * a;
		
	 }
	 
	var b = parseInt(greitis);
	greitis = greitis.toFixed(2);
	

	

	var a = new Array();
	a = explode(greitis, '.'); 
	a = a[1]/10;
	
	var koef = 1.3;
	
	if(s==1 && galia=='0.5')
		var ch = new Array(0, 0, 0, 0, 0.100, 0.200, 0.300, 0.400, 0.500, 0.550, 0.560);
	if(s==1 && galia=='1') 
		var ch = new Array(0, 0, 0, 0.05, 0.170, 0.280, 0.430, 0.610, 0.760, 0.920, 1.050);
	if(s==1 && galia=='2')
		var ch = new Array(0, 0, 0, 0.120, 0.270, 0.410, 0.600, 0.900, 1.350, 1.700, 2.000);
	if(s==1 && galia=='3')
		var ch = new Array(0, 0, 0, 0, 0.280, 0.610, 1.020, 1.380, 1.770, 2.230, 2.720);
	if(s==1 && galia=='5')
		var ch = new Array(0, 0, 0, 0, 0.650, 1.250, 1.800, 2.400, 2.900, 3.750, 4.560);
	if(s==1 && galia=='10')
		var ch = new Array(0, 0, 0, 0.2, 0.430, 1.000, 1.700, 2.700, 3.700, 5.100, 6.600);
	
	
	
	if(s==2 && galia=='0.5')
		var ch = new Array(0, 0, 0, 0.030, 0.050, 0.120, 0.170, 0.340, 0.500, 0.620, 0.670);
	if(s==2 && galia=='1')
		var ch = new Array(0, 0, 0, 0.030, 0.080, 0.200, 0.330, 0.600, 0.850, 1.350, 1.500);
	if(s==2 && galia=='2')
		var ch = new Array(0, 0, 0, 0.10, 0.130, 0.30, 0.650, 1.000, 1.300, 1.650, 2.000);
	if(s==2 && galia=='3')
		var ch = new Array(0, 0, 0, 0.100, 0.250, 0.500, 0.750, 1.200, 1.550, 2.300, 3.000);
	if(s==2 && galia=='5')
	{
		var ch = new Array(0, 0, 0, 0.200, 0.500, 1.000, 1.500, 2.200, 3.000, 4.000, 5.000);
		koef = 0.95;
	}
	if(s==2 && galia=='10')
		var ch = new Array(0, 0, 0, 0.200, 0.700, 1.400, 3.000, 4.000, 5.000, 6.900, 8.800)
	if(s==2 && galia=='20')
		var ch = new Array(0, 0, 0, 1.000, 1.800, 4.000, 5.400, 8.200, 10.700, 14.600, 17.000);
	if(s==2 && galia=='30')
	{
		var ch = new Array(0, 0, 0, 0.45, 1.45, 2.700, 4.950, 6.450, 9.200, 12.300, 17.700);
		koef = 3;
	}
	if(s==2 && galia=='50')
	{
		var ch = new Array(0, 0, 0, 0.7, 1.450, 2.700, 5.200, 10.000, 15.200, 22.700, 30.200);
		koef = 4;
	}
	if(s==2 && galia=='225')
	{
		var ch = new Array(0, 0, 0, 0, 5, 12, 29, 55, 86, 117, 145);
		koef = 2;
	}
	if(s==2 && galia=='250')
		var ch = new Array(0, 0, 0, 0, 8, 16, 28, 57, 89, 122, 150);

	
	
	var c = b + 1;
	//alert("("+ch[a]+"("+ch[c]+" - "+ch[b]+")/10) * "+a+") * 8760 * "+koef);


	var g = (ch[b] + ((ch[c] - ch[b])/10) * a) * 8760 * koef;

	
	//alert(g);
	
	// var g = 100;
	g = g.toFixed(2)
	var litai = g * kaina;
	litai = litai.toFixed(2);
	
	var rez = "Tai yra preliminarūs skaičiavimo rezultatai<br /><br />Vėjo jėgainės sugeneruos "+g+" kWh per metus<br />Pajamos "+litai+" LT per metus<br /><span style=\"color:#999\"><br /><br />Pasinaudojus ES parama jėgainės atsipirkimas iki 5 m.</span><br /><br />Dėl detalesnės informacijos prašome kreiptis:<br />Kont. tel.: 8 686 83062<br />el. paštu: info@energijaplius.lt";


	
	var rezas = document.getElementById('rez');
	rezas.innerHTML = rez;
	 

}

function braizyti_statistika() {
	var klase = document.getElementById('klase').value;
	var kos = Get_Cookie('KOS');
	
	if(kos == null) {
		alert("Nepasirinkote nieko žemėlapyje");
		return;	
	}
	
	if(klase == 0) {
		alert("Nepasirinkote kokia statistika išvesti į ekraną");
		return;	
	}
	
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(hasRightVersion) { 
			AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
				'width', '700',
				'height', '300',
				'scale', 'noscale',
				'salign', 'TL',
				'bgcolor', '#777788',
				'wmode', 'opaque',
				'movie', 'class/chart/charts',
				'src', 'class/chart/charts',
				'FlashVars', 'library_path=class/chart/charts_library&xml_source=modules/calculate/data.php?data='+kos+'|'+klase+'', 
				'id', 'my_chart',
				'name', 'my_chart',
				'menu', 'true',
				'allowFullScreen', 'true',
				'allowScriptAccess','sameDomain',
				'quality', 'high',
				'align', 'middle',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'play', 'true',
				'devicefont', 'false'
				); 
		} else { 
			var alternateContent = 'This content requires the Adobe Flash Player. '
			+ '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
			document.getElementById('rez').innerHTML = alternateContent; 
		}
	}	
}

function explode(item,delimiter) {
	tempArray=new Array(1);
	var Count=0;
	var tempString=new String(item);
	
	while (tempString.indexOf(delimiter)>0) {
		tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
		tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
		Count=Count+1
	}

	tempArray[Count]=tempString;
	return tempArray;
} 

function point_it(event, id){
	pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById(id).offsetLeft;
	pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById(id).offsetTop;
	

	
	var left = document.getElementById("highslide-wrapper-0").style.left;   
	var top = document.getElementById("highslide-wrapper-0").style.top; 
	
	left = left.replace('px', '');
	top = top.replace('px', '');
	
	//alert(pos_x+' '+left+'|'+pos_y+' '+top);
	
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		left = -5;
		top = -28;
	}
	
	
	
	
	document.getElementById("saule_cia").style.left = (pos_x-27-left)+'px'  ;
	document.getElementById("saule_cia").style.top = (pos_y-48-top)+'px'  ;
	document.getElementById("saule_cia").style.visibility = "visible" ;
}

function point_its(event, id){
	pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById(id).offsetLeft;
	pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById(id).offsetTop;

	document.getElementById("saule_cia").style.left = (pos_x)+'px' ;
	document.getElementById("saule_cia").style.top = (pos_y)+'px' ;
	document.getElementById("saule_cia").style.visibility = "visible" ;
	
	
	

	

}


function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}





function foo(px,py,pw,ph,baseElement,fid)
{
var win = document.getElementById(this.fid);
}


function dropdown_menu_hack(el)
{
if(el.runtimeStyle.behavior.toLowerCase()=="none"){return;}
el.runtimeStyle.behavior="none";

var ie5 = (document.namespaces==null);
el.ondblclick = function(e)
{
window.event.returnValue=false;
return false;
}

if(window.createPopup==null)
{

var fid = "dropdown_menu_hack_" + Date.parse(new Date());

window.createPopup = function()
{
if(window.createPopup.frameWindow==null)
{
el.insertAdjacentHTML("AfterEnd","<iframe id='"+fid+"' name='"+fid+"' src='about:blank' frameborder='1' scrolling='no'></></iframe>");
var f = document.frames[fid];
f.document.open();
f.document.write("<html><body></body></html>");
f.document.close();
f.fid = fid;


var fwin = document.getElementById(fid);
fwin.style.cssText="position:absolute;top:0;left:0;display:none;z-index:99999;";


f.show = function(px,py,pw,ph,baseElement)
{
py = py + baseElement.getBoundingClientRect().top + Math.max( document.body.scrollTop, document.documentElement.scrollTop) ;
px = px + baseElement.getBoundingClientRect().left + Math.max( document.body.scrollLeft, document.documentElement.scrollLeft) ;
fwin.style.width = pw + "px";
fwin.style.height = ph + "px";
fwin.style.posLeft =px ;
fwin.style.posTop = py ;
fwin.style.display="block";
}


f_hide = function(e)
{
if(window.event && window.event.srcElement && window.event.srcElement.tagName && window.event.srcElement.tagName.toLowerCase()=="select"){return true;}
fwin.style.display="none";
}
f.hide = f_hide;
document.attachEvent("onclick",f_hide);
document.attachEvent("onkeydown",f_hide);

}
return f;
}
}

function showMenu()
{

function selectMenu(obj)
{
var o = document.createElement("option");
o.value = obj.value;
o.innerHTML = obj.innerHTML;
while(el.options.length>0){el.options[0].removeNode(true);}
el.appendChild(o);
el.title = o.innerHTML;
el.contentIndex = obj.selectedIndex ;
el.menu.hide();
}


el.menu.show(0 , el.offsetHeight , 10, 10, el);
var mb = el.menu.document.body;

mb.style.cssText ="border:solid 1px black;margin:0;padding:0;overflow-y:auto;overflow-x:auto;background:white;text-aligbn:center;font-family:Verdana;font-size:12px;";
var t = el.contentHTML;
t = t.replace(/<select/gi,'<ul');
t = t.replace(/<option/gi,'<li');
t = t.replace(/<\/option/gi,'</li');
t = t.replace(/<\/select/gi,'</ul');
mb.innerHTML = t;


el.select = mb.all.tags("ul")[0];
el.select.style.cssText="list-style:none;margin:0;padding:0;";
mb.options = el.select.getElementsByTagName("li");

for(var i=0;i<mb.options.length;i++)
{
mb.options[i].selectedIndex = i;
mb.options[i].style.cssText = "list-style:none;margin:0;padding:1px 2px;width/**/:100%;cursor:hand;cursorointer;white-space:nowrap;"
mb.options[i].title =mb.options[i].innerHTML;
mb.options[i].innerHTML ="<nobr>" + mb.options[i].innerHTML + "</nobr>";
mb.options[i].onmouseover = function()
{
if( mb.options.selected ){mb.options.selected.style.background="white";mb.options.selected.style.color="black";}
mb.options.selected = this;
this.style.background="#333366";this.style.color="white";
}

mb.options[i].onmouseout = function(){this.style.background="white";this.style.color="black";}
mb.options[i].onmousedown = function(){selectMenu(this); }
mb.options[i].onkeydown = function(){selectMenu(this); }


if(i == el.contentIndex)
{
mb.options[i].style.background="#333366";
mb.options[i].style.color="white";
mb.options.selected = mb.options[i];
}
}


var mw = Math.max( ( el.select.offsetWidth + 22 ), el.offsetWidth + 22 );
mw = Math.max( mw, ( mb.scrollWidth+22) );
var mh = mb.options.length * 15 + 8 ;

var mx = (ie5)?-3:0;
var my = el.offsetHeight -2;
var docH = document.documentElement.offsetHeight ;
var bottomH = docH - el.getBoundingClientRect().bottom ;

mh = Math.min(mh, Math.max(( docH - el.getBoundingClientRect().top - 50),100) );

if(( bottomH < mh) )
{

mh = Math.max( (bottomH - 12),10);
if( mh <100 )
{
my = -100 ;

}
mh = Math.max(mh,100);
}


self.focus();

el.menu.show( mx , my , mw, mh , el);
sync=null;
if(mb.options.selected)
{
mb.scrollTop = mb.options.selected.offsetTop;
}




window.onresize = function(){el.menu.hide()};
}

function switchMenu()
{
if(event.keyCode)
{
if(event.keyCode==40){ el.contentIndex++ ;}
else if(event.keyCode==38){ el.contentIndex--; }
}
else if(event.wheelDelta )
{
if (event.wheelDelta >= 120)
el.contentIndex++ ;
else if (event.wheelDelta <= -120)
el.contentIndex-- ;
}else{return true;}




if( el.contentIndex > (el.contentOptions.length-1) ){ el.contentIndex =0;}
else if (el.contentIndex<0){el.contentIndex = el.contentOptions.length-1 ;}

var o = document.createElement("option");
o.value = el.contentOptions[el.contentIndex].value;
o.innerHTML = el.contentOptions[el.contentIndex].text;
while(el.options.length>0){el.options[0].removeNode(true);}
el.appendChild(o);
el.title = o.innerHTML;
}

if(dropdown_menu_hack.menu ==null)
{
dropdown_menu_hack.menu = window.createPopup();
document.attachEvent("onkeydown",dropdown_menu_hack.menu.hide);
}
el.menu = dropdown_menu_hack.menu ;
el.contentOptions = new Array();
el.contentIndex = el.selectedIndex;
el.contentHTML = el.outerHTML;

for(var i=0;i<el.options.length;i++)
{
el.contentOptions [el.contentOptions.length] =
{
"value": el.options[i].value,
"text": el.options[i].innerHTML
}

if(!el.options[i].selected){el.options[i].removeNode(true);i--;};
}


el.onkeydown = switchMenu;
el.onclick = showMenu;
el.onmousewheel= switchMenu;

}

function jegaines_tipas(tipas)
{
	if(tipas == 'mono')
	{
		styles('pav_mono', 'display', 'block');
		styles('pav_poli', 'display', 'none');
	}
	
	if(tipas == 'poli')
	{
		styles('pav_mono', 'display', 'none');
		styles('pav_poli', 'display', 'block');
	}
}

	function keisti_value(id, value, def_value)
	{
		
		var keista = true;
		
		if(document.getElementById(id).value == '')
		{
			document.getElementById(id).value = def_value;
			keista = false;
		}
		
		if(def_value == document.getElementById(id).value && keista)
			document.getElementById(id).value = value;
		
			
	}

