// function för effektberäkning
// obs! om dropdownlister används - gäller följande syntax - exempel:
// var zon = effekt1.zon.options[effekt1.zon.selectedIndex].value;
// a= eval(effekt1.zon.options[effekt1.zon.selectedIndex].value)
function adCalc(effekt1) {
var ok = 0;

var zon = valButton(effekt1.zon);
var fonster = valButton(effekt1.fonster);
var temp = valButton(effekt1.temp);
var isolering = valButton(effekt1.isolering);
var omgivning = valButton(effekt1.omgivning);
var ytterv = valButton(effekt1.ytterv);
var golvyta = effekt1.golvyta.value;
var vaggyta = effekt1.vaggyta.value;
var fonsteryta = effekt1.fonsteryta.value;
var exposures = effekt1.exposures.value;

var incomplete = "Du måste klicka i alla alternativ,\noch fylla i alla mått innan du kan beräkna.";

if (zon != "" && fonster != "" && temp != "" && isolering != "" && omgivning != "" && ytterv != "" && vaggyta != "" && golvyta != "" && fonsteryta != "")  
{ 

// replace comma with dot
effekt1.vaggyta.value = effekt1.vaggyta.value.replace(",",".");
effekt1.fonsteryta.value = effekt1.fonsteryta.value.replace(",",".");
effekt1.golvyta.value = effekt1.golvyta.value.replace(",",".");

a= eval(valButton(effekt1.zon))
b= eval(valButton(effekt1.fonster))
c= eval(valButton(effekt1.temp))
d= eval(valButton(effekt1.isolering))
e= eval(valButton(effekt1.omgivning))
f= eval(valButton(effekt1.ytterv))
g= eval(effekt1.vaggyta.value)
h= eval(effekt1.fonsteryta.value)
i= eval(effekt1.golvyta.value)

j=((a+c+d)/100)
k=b*h
l=e*i
m=f*g
n=(k+l+m)*j
o=Math.round(n*100)/100
effekt1.exposures.value=o
ok++
}

if (!ok) alert(incomplete);  
}

// function valButton(btn)
function valButton(btn) {
 var cnt = -1;
 for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
  if (cnt > -1) return btn[cnt].value;
 else return null;
}


// Funktion för att slumpa bilder
// Usage: <SCRIPT LANGUAGE="javascript"><!-- document.write(visa_bild()) //--></SCRIPT>
function visa_bild()
{
//***---Här skriver du vilka bilder som ska kunna komma. Ha hur många bilder du vill.
bild=new Array("/assets/slump/startimg_1.jpg","/assets/slump/startimg_2.jpg","/assets/slump/startimg_3.jpg","/assets/slump/startimg_4.jpg","/assets/slump/startimg_5.jpg","/assets/slump/startimg_6.jpg","/assets/slump/startimg_7.jpg","/assets/slump/startimg_8.jpg")
visa_bilden=bild[Math.floor(Math.random()*bild.length)]
visa_bilden="<IMG SRC=\"" + visa_bilden + "\">"
return visa_bilden
}


function PopUpGeneric(URL, width, height, text)
	{
	// Popup window with links to image library. 
	var popleft=((document.body.clientWidth - 440) / 2)+window.screenLeft; 
	var poptop=(((document.body.clientHeight - 460) / 2))+window.screenTop-40;		
	window.open(URL,"_blank","resizable=1,scrollbars=auto,width=" + width + ",height=" + height + ",left="+popleft+",top="+poptop)
	}

// Function for poping-up images : Reference it like this in the html: 
// <a href="javascript:;" onClick="PopUpImg('jpg','/assets/layout/my_image.jpg','640','480','Image 1','0','0')">Click!</a> 
function PopUpImg(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
 screenh = window.screen.height;
 screenw = window.screen.width;
 posLeft = (screenw-imageWidth)/2;
 posTop = (screenh-imageHeight)/2;
 theWindow = window.open("","theWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
 theWindow.document.open();
 theWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
 theWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="'+alt+'" onClick="javascript:window.self.close();" galleryimg="no">');
 theWindow.document.write('</body></html>');
 theWindow.document.close();
 theWindow.focus()
}

// Function that displays wait message when submitting a form
// css-style: .waitMsg { visibility:hidden; color: red; }
// sample code: <span class="waitMsg" ID="id_waitmsg">Loading Data. Please Wait...<br><img id=pbar src="/assets/shop/layout/loading.gif"></span>
function ShowWaitMsg()
{
if(id_waitmsg) id_waitmsg.style.visibility = 'visible';
setTimeout('document.images["pbar"].src = "/assets/shop/layout/loading.gif"', 200);
}

// function for statustext onMouseOver
function WinStat(sMessage) 
{ window.status = sMessage; }

//Function to go to URL
// usage: <input type=button value=""Avbryt"" onClick=gotoURL('" & THIS_SCRIPT & "?mode=listSchemas')>
function gotoURL(url)
{ self.location.href = url; }


// SPECIAL - FUNCTIONS RELATED TO COURSES //
// ************************************** //

function copyInvoiceAddress_SE() // Swedish form
{
 document.forms[0].Faktura_kontaktperson.value = document.forms[0].Namn.value;
 document.forms[0].Faktura_adress.value = document.forms[0].Bostadsadress.value;
 document.forms[0].Faktura_postnr.value = document.forms[0].Bostadsadress_postnr.value;
 document.forms[0].Faktura_ort.value = document.forms[0].Bostadsort.value;
 document.forms[0].Faktura_email.value = document.forms[0].Email.value;
}

function copyInvoiceAddress_EN() // English form
{
 document.forms[0].Invoice_contactname.value = document.forms[0].Name.value;
 document.forms[0].Invoice_address.value = document.forms[0].Address.value;
 document.forms[0].Invoice_zip.value = document.forms[0].Zip.value;
 document.forms[0].Invoice_city.value = document.forms[0].City.value;
 document.forms[0].Invoice_email.value = document.forms[0].Email.value;
}