function set_checked(obj) {
    if ($('input[id=' + obj + ']').attr('checked')){
        $('input[id=' + obj + ']').attr("checked", '');
    }else{
        $('input[id=' + obj + ']').attr("checked", 'false');
    }
}

function StatDealer(address){
  
    ADFtrack(11945,51329,[address,'']); 
    kenshoo_conv('8d997f30-3c61-4b52-b1a0-4199aec13a62','Reseller','1','',address,'SEK');
}

function kenshoo_conv(id,type,value,orderId,promoCode,valueCurrency) {
    var url = "http://11.xg4ken.com/media/redir.php?track=1&id=" +
    id + "&type=" + type + "&val=" + value + "&orderId=" + orderId + "&valueCurrency=" + valueCurrency + "&promoCode=" + promoCode + "&ref=" + document.referrer;
    var a = new Image(1,1);
    a.src = url;
    a.onload = function() { _uVoid(); }
  }

function toogleMode(val)
{
	var intItems = 2;
	var objSelect = document.getElementById("select" + val);
	var objFlashContainer = document.getElementById("flashItem" + val);
	for(i=1;i<= intItems; i++)
	{
		document.getElementById("select" + i).className = "item";
		document.getElementById("flashItem" + i).style.display = "none";
	}
	
	objSelect.className = "item selected";
	objFlashContainer.style.display = "block";
}

function addremove(obj, strUnit)
{
	var itemValue = obj.value;
	var arrValues = itemValue.split(";")
	var intCarItem = parseInt(arrValues[0]);
	var intPriceItem = parseFloat(arrValues[1]);
	var intPriceItemTax = parseFloat(arrValues[2]);
	var intPriceItemWoutTax = parseFloat(arrValues[3]);
	
	var lblBasicPrice = document.getElementById("car" + intCarItem  + "BasicPrice");
    var lblEquipmentPrice = document.getElementById("car" + intCarItem  + "EquipmentPrice");

	if(obj.type=="radio")
	{
		lblBasicPrice.value = intPriceItem;
		document.getElementById("car" + intCarItem + "basic").innerHTML = formatPrice(lblBasicPrice.value, strUnit);
	if(document.getElementById("car" + intCarItem + "basicTax"))
		document.getElementById("car" + intCarItem + "basicTax").innerHTML = formatPrice(intPriceItemTax, strUnit);
	if(document.getElementById("car" + intCarItem + "basicWoutTax"))
		document.getElementById("car" + intCarItem + "basicWoutTax").innerHTML = formatPrice(intPriceItemWoutTax, strUnit);
	}
	else
	{
		if(obj.checked)
		{
			lblEquipmentPrice.value = roundNumber(parseFloat(lblEquipmentPrice.value) + intPriceItem,2);
		}
		else
		{
			lblEquipmentPrice.value = roundNumber(parseFloat(lblEquipmentPrice.value) - intPriceItem, 2);
		}
		document.getElementById("car" + intCarItem + "Equipment").innerHTML = formatPrice(lblEquipmentPrice.value, strUnit);
	}
	var totalPrice = roundNumber(parseFloat(lblBasicPrice.value) + parseFloat(lblEquipmentPrice.value), 2);
	document.getElementById("car" + intCarItem).innerHTML = formatPrice(totalPrice, strUnit);
	document.getElementById("car_" + intCarItem).innerHTML = formatPrice(totalPrice, strUnit);
}

function roundNumber(num, dec) {
	var result = Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec);
	return result;
}

function formatPrice(intPrice, strUnit)
{
	var arrPrice = intPrice.toString().split(".")
	var varPricePrim = arrPrice[0];
	var intPriceDec = arrPrice[1];

	var strPrice = varPricePrim.toString();
	var strOut = "";
	for(i=0; i<strPrice.length; i++)
	{
		if(i==(strPrice.length-3)) strOut += " " + strPrice.charAt(i);
		else strOut += strPrice.charAt(i);
	}
	if(strOut=="0") {
        strOut = "-";
	} else { 
	 //   if(intPriceDec!="undefined" && intPriceDec!="0") {
	    if(intPriceDec!=undefined) {
           strOut += ",";
	        strOut += intPriceDec ;
	    }
        strOut +=  strUnit;
	}
	return strOut;
}

function initPrices(strUnit)
{
    var radioList = document.getElementsByTagName("input");
    for(var i=0; i<radioList.length; i++)
    {
        if(radioList[i].type == "radio")
        {
            if(radioList[i].checked==true)
            {
				addremove(radioList[i], strUnit)
            }
        }
    }
}

function addEvent(obj, type, fn) 
{
	if (!document.getElementById)
		return;
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) 
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent("on"+type, obj[type+fn]);
	}
}

function showStartPopup()
{
    obj = document.getElementById("popUpStart");
    objwrapper = document.getElementById("startMainImageWrapper")
    obj.style.left = findPosX(objwrapper) + 140 + "px";
    obj.style.top = findPosY(objwrapper) + 80 + "px";
    obj.style.display = "block";
    
}

function hidePop()
{
    obj = document.getElementById("popUpStart");
    obj.style.display = "none";
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
        curleft += obj.offsetLeft;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
        curtop += obj.offsetTop;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}