
//default_variablen//
var brennst=4;
var brennNr=1;
var kollnr=1;
var daemNr=0;
var version;
var pending=0;
var repending=0;
var waitforcities=true;
var DomNotReady=true;

window.onload = function() {
DomNotReady=false;
}

function sendForm()
{   
if (waitforcities || DomNotReady){} 
else
{
//opacity from 0 to 0 => no "resultflash"
	new Effect.Opacity('results', {duration:0, from:0, to:0});
	new Effect.Opacity('printBtn', {duration:0, from:0, to:0});
	
	$('loader').show();
	$('please').hide();
	
	pending=1;
	$('anlage').enable();
	$('printresult').disable();
	repending=0;
	var SystemData = $('anlage').serialize(true);
	$('anlage').disable();
	var url ="/calculation/thermal/system/result?"+SystemData; 
	new Ajax.Updater('results', url, {method: 'post',parameters:SystemData,onSuccess:function(transport){resultSuccess(transport)}});
}
}




function sendPrint_ww()
{

	$('anlage').action="/calculation/thermal/printpreview/ww";
	$('anlage').target="_print";
	$('anlage').submit();
	
}
function sendPrint_wwh()
{

	$('anlage').action="/calculation/thermal/printpreview/wwh";
	$('anlage').target="_print";
	$('anlage').submit();
	
}
function sendPrint_uvs()
{

	$('anlage').action="/calculation/thermal/printpreview/uvs";
	$('anlage').target="_print";
	$('anlage').submit();
	
}


function resultSuccess(transport)
{
	
	
	$('loader').hide();
	$('anlage').enable();
	
	$('printresult').value=transport.responseText;
	FormObserver.lastValue=$('anlage').serialize();
	new Effect.Opacity('results', {duration:1, from:0, to:1});
	pending=0;
	$('printBtn').show();
	new Effect.Opacity('printBtn', {duration:1, from:0, to:1});
	
}




function hideResult()
{ 
	if (0==pending&0==repending)		
		{		
		new Effect.Opacity('results', {duration:1, from:1.0, to:0});
		repending=1;
		$('please').show();
		new Effect.Opacity('printBtn', {duration:1, from:1.0, to:0});
		}
}


function getCities()
{
    var country = $('country').getValue();
    new Ajax.Request('/calculation/thermal/system/cities', {method: 'post',parameters: 'country=' + country,
        onSuccess: function(transport)
		{
            citiesSuccess(transport)
            waitforcities=false;
        },
        onFailure: function(transport)
		{
            errorHandler(transport)
        }
    											}
					)
}
function citiesSuccess(transport)
{
	$('cityList').update(transport.responseText);
}
function errorHandler(transport)
{
	alert(transport.responseText);
}
var brennstoffe = new Array;
for(var i = 1; i <= brennst; i++) {
	brennstoffe[i] = new Image();
	brennstoffe[i].scr="/calculation/thermal/images/brennstoff"+i+".jpg";}

var kollektoren = new Array;
kollektoren[0] = new Image();
kollektoren[0].scr="/calculation/thermal/images/roehrenkollektor.gif";
kollektoren[1] = new Image();
kollektoren[1].scr="/calculation/thermal/images/flachkollektor.gif";
//////////////////////////////////////////////
function PopupFenster(lang) 
//////////////////////////////////////////////
{                                                   
if (lang=='de')                               
	{F = window.open("/thermal/popup/de","Popup","width=307,height=372"); 
	} 	
	else
	{F = window.open("/thermal/popup/en","Popup","width=307,height=372");
	}		           
}       
//////////////////////////////////////////////
function setDaemmung()
//////////////////////////////////////////////
{	
	if(!$('daem')){}//if not $('daem') then the system is ww
	else
	{
	$('daemmung').src="/calculation/thermal/images/daem_" + $('daem').value+".gif";
	$('daemmung').alt="daem_" + $('daem').value+".gif";
	}
}
    
//////////////////////////////////////////////                                                                          
function setKompass()
//////////////////////////////////////////////
{
	$('kompassImg').src="/calculation/thermal/images/kompass_" + $('az').value + ".gif";
}	
//////////////////////////////////////////////
function setKollektor()
//////////////////////////////////////////////
{
	if (kollnr == 1 )
	{kollnr = 0;}
	else 	{kollnr = 1 ;}
	$('kollektor').src=kollektoren[kollnr].scr;
	$('kollektor').alt="kollektoren"+kollnr;
	$('koll').value=kollnr;	
}

//////////////////////////////////////////////
function setBrennstoff()
//////////////////////////////////////////////
{
	if (brennNr < brennst)
	{
		brennNr++;
	} else {
		brennNr = 1;
	}
	$('imgbrennstoff').src=brennstoffe[brennNr].scr;
	$('imgbrennstoff').alt="brennstoff"+brennNr;
	$('brennstoff').value=brennNr;
}

//////////////////////////////////////////////
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 MM_showHideLayers() { //v6.0
//////////////////////////////////////////////
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}

//////////////////////////////////////////////
function ini()
//////////////////////////////////////////////
{
	setBrennstoff();
	setDaemmung();
	setKompass();
	MM_preloadImages('/calculation/thermal/images/auswahlbutton_ro.jpg');
	$('kollektor').src=kollektoren[kollnr].scr;
	$('kollektor').alt="kollektoren"+kollnr;
	$('loader').hide();
	FormObserver= new Form.Observer(  'anlage',  0.2,  // 200 milliseconds
  									function(form, value){hideResult();}
 								   )
 	$('printBtn').hide();
 	new Effect.Opacity('printBtn', {duration:1, from:0, to:0});
 							   
 	getCities();
 			
}






