function ss_initEvent(aEvent, aFun) {
    if (window.addEventListener) {
        window.addEventListener(aEvent, aFun, false);
    } else if (window.attachEvent) {
        window.attachEvent("on" + aEvent, aFun);
    }
}
//initEvent("load", function () {
//    alert('Event 2');
//});
//window.onload = function () {
//    alert('Event 1');
//};

function ss_round(value, decimalPlace) {
    var power_of_ten = 1;
    var i = decimalPlace;
    while (i-- > 0)
        power_of_ten *= 10.0;
    return Number(Math.round(value * power_of_ten) / power_of_ten).toFixed(decimalPlace);
}


function ss_formatMoneyDelta(dMoney) {
    return (Number(dMoney) == 0 ? "" : (Number(dMoney) > 0 ? "+&nbsp;" : "-&nbsp;")) + ss_formatMoney(Math.abs(dMoney));
}

function ss_formatMoney(dMoney) {
    //    alert("ss_formatMoney: dMoney=" + dMoney);
    return ss_round(Number(dMoney), 2).replace(".", ",");
}

function ss_formatKilogrammes(dWeightKillogrammes) {
    var res = ss_round(dWeightKillogrammes, 1);


    if (res.indexOf(".0")==(res.length-2))
    {
        res = res.substr(0, res.length - 2);
    }

    return res.replace(".", ",");
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getRadioCheckedValue(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 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;
}


 function moveElement(elm, x, y) {
	  // move the element with id to x,y
	  // where x,y are the horizontal
	  // and vertical position in pixels

	  if (!elm)
	  {
		// browser not supported or element not found
	  }
	  else if (elm.style)
	  {

		// browser implements part of W3C DOM Style
		// Gecko, Internet Explorer 4+, Opera 5+

		if (typeof(elm.style.left) == 'number')
		{
		  // Opera 5/6 do not implement the standard correctly
		  // and assume that elm.style.left and similar properties
		  // are numbers.
		  elm.style.left = x;
		  elm.style.top  = y;
		}
		else
		{
		  // Gecko/Internet Explorer 4+
		  // W3C DOM Style states that elm.style.left is a string
		  // containing the length followed by the unit. e.g. 10px
		  // Gecko will allow you to omit the unit only in Quirks
		  // mode.
		  // Gecko REQUIRES the unit when operating in Standards
		  // mode.
		  elm.style.left = x + 'px';
		  elm.style.top  = y + 'px';
		}
	  }
	  else if (typeof(elm.left) == 'number')
	  {
		// Navigator 4
		elm.left = x;
		elm.top  = y;
	  }
};

//
//function process_discount_products() {
//    var objs = document.getElementsByName("discount-plist-image");
//
//    for (i = 0; i < objs.length; i++)
//    {
//        var x = findPosX(objs[i])-11;
//        var y = findPosY(objs[i])-13;
//
////        var imageObj = document.createElement("<img style='position: absolute; top:" + y + "px;left:" + x + "px; ' src='/static/img/discount/discount.png'>");
//        var imageObj = document.createElement("img");
//        imageObj.src = '/static/img/discount/discount.png';
//        imageObj.style.position = 'absolute';
//
//
//        document.body.appendChild(imageObj);
//        moveElement(imageObj, x, y);
////        alert("x=" + x + " y=" + y);
//    }
//}




