﻿function viewPhoto(strPath)	{
	window.open('assets/viewphoto.aspx?strPath=' + strPath, 'Viewver', 'width=780, height=500, scrollbars=yes, status=yes, resizable=yes')
}

function ResizePhotoViewer(window) {
	var img = document.getElementById('imgPhoto')
	var x = img.width + 50;
	var y = img.height + 175;
	
	if (screen.availWidth<x) { 
		x = screen.availWidth - 28; 
	}
	
	window.resizeTo(x,y);
}

function showEmail(strName, strDomain, strLinkText) {
	var strEmail = strName + '@' + strDomain;
	if (!strLinkText) {strLinkText = strEmail;}
	
	document.write('<a class="email" href="mailto:' + strEmail + '">' + strLinkText + '</a>');
}

function PlayFlash(src, cssclass)	{
	document.write("<object class=\"" + cssclass + "\" type=\"application/x-shockwave-flash\" data=\"" + src + "\">")
	document.write("<param name=\"movie\" value=\"" + src + "\" />")
	document.write("</object>") 
}

function HidePhoto()	{
	document.getElementById('largeimage').style.display='none';
}

function Enlarge(photoId)	{
	if (document.getElementById('largeimage').style.display=='block')	{
		document.getElementById('largeimage').style.display='none';
	}
	else	{
		document.getElementById('imglarge').src='assets/dbphoto.aspx?tablename=CE_News&ColNameData=FileData&ColNameSize=FileSize&ColNameId=cntNewsId&id=' + photoId + '&width=500';
		document.getElementById('largeimage').style.display='block';
	}
}

function Toggle(obj)	{
	if (document.getElementById(obj).style.display=='block')	{
		document.getElementById(obj).style.display='none';
	}
	else	{
		document.getElementById(obj).style.display='none';
		document.getElementById(obj).style.display='block';
	}
}

//----------------------------------------------------------------------------------------------

var bilTotal = null
var styrelseTotal = null
var ovrigtTotal = null

function SummeraBil(Suffix, ID)	{
	objStracka = document.getElementById(Suffix + 'txtBilStracka' + ID)
	//PrisEtt = document.getElementById(Suffix + 'txtBilSummaA' + ID)
	PrisTva = document.getElementById(Suffix + 'txtBilSummaB' + ID)

	//PrisEtt.value = Math.round(objStracka.value * 1.6);
	// 18.50 kr per mil = 1.85 per km
	i = (objStracka.value/10) * 18.50;
	PrisTva.value = Math.round(i*Math.pow(10,2))/Math.pow(10,2);
	
	if (PrisTva.value == 'NaN')	{
		PrisTva.value = 'FEL';
	}
	
	if (PrisTva.value == '0')	{
		PrisTva.value = '';
	}
	
	SummeraTotal(Suffix, 'tblBilersattning', 'txtBilSummaB');
}
function SummeraStyrelse(Suffix, ID)	{		
	var objTotalt = document.getElementById(Suffix + 'txtStyrelseTotal' + ID);
	var objAntalTimmar = document.getElementById(Suffix + 'txtStyrelseAntalTim' + ID);
		
	//alert(objAntalTimmar.value);
	var x = (objAntalTimmar.value*165)*0.7;
	objTotalt.value = Math.round(x*Math.pow(10,2))/Math.pow(10,2);		
		
	if (objTotalt.value == 'NaN')	{
		objTotalt.value = 'FEL';
	}
	if (objTotalt.value == '0')	{
		objTotalt.value = '';
	}
	
	SummeraTotal(Suffix, 'tblStyrelse', 'txtStyrelseTotal');			
}


function SummeraOvrigt(Suffix, ID)	{		
	var objTotalt = document.getElementById(Suffix + 'txtOvrigtSumma' + ID);
				
	SummeraTotal(Suffix, 'tblOvrigt', 'txtOvrigtSumma');			
}

function SummeraTotal(Suffix, ObjectId, FieldName)
{
    var FieldValue = null;
    var tableNode = document.getElementById(Suffix + ObjectId);
    var Total = document.getElementById(Suffix + 'txtTotalSum');		    
    var inputNodes = tableNode.getElementsByTagName('input');
    
    if (ObjectId == 'tblStyrelse')
    {
        styrelseTotal = 0
    }
    else if (ObjectId == 'tblBilersattning')
    {
        bilTotal = 0 
    }
    else
    {
        ovrigtTotal = 0
    }
    
    for(i=0; i < inputNodes.length; i++)
    {
        var inputNode = inputNodes[i];
        if (inputNode.value != '' && inputNode.id.indexOf(FieldName) > 0)
        {
            FieldValue += parseFloat(inputNode.value);
        }
    }
    
    if (ObjectId == 'tblStyrelse')
    {
        styrelseTotal = FieldValue
    }
    else if (ObjectId == 'tblBilersattning')
    {
        bilTotal = FieldValue 
    }
    else
    {
        ovrigtTotal = FieldValue
    }
    
    Total.value = styrelseTotal + bilTotal + ovrigtTotal
}
		
//----------------------------------------------------------------------------------------------
