function changeClass(objName, newClass)
{
    obj=MM_findObj(objName);
    if(obj)
    obj.className = newClass;
}


function changeImage(obj, newImage)
{
    obj.src = newImage;
}


function back()
{
    location.replace=window.history.go(-1);
}


function cleanField(obj, defaultVal)
{
    if (obj.value == defaultVal) {
        obj.value = '';
    }
}


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 setHeight()
{
    var arguments = setHeight.arguments;
    if (navigator.appName == 'Netscape') {
        diff = 0;
    } else {
        diff = 0;
    }
    max = 0;
    for(i = 0; i < arguments.length; i++) {
        top_position = getXYcoord(arguments[i] + '_top');
        bottom_position = getXYcoord(arguments[i] + '_bottom');
        height = bottom_position.y - top_position.y;
        if (height > max) {
            max = height;
        }
    }

    for(i = 0; i < arguments.length; i++) {
        document.getElementById(arguments[i]).height = max - diff;
        document.getElementById(arguments[i]).style.height = max - diff;
    }
}


function getXYcoord ( nvn )
{
    var elm = document.images[nvn];
    if ( document.layers ) return elm;
    var rd = { x:0 ,y:0 };
    do {rd.x += parseInt( elm.offsetLeft );
    rd.y += parseInt( elm.offsetTop );
    elm = elm.offsetParent;
    } while ( elm );
    return rd;
}

function jump(form, select) {

    var myindex=select.selectedIndex

    if (select.options[myindex].value != "-1")
    {
        form.submit();
    }
}


function findObj(theObj, theDoc)
{
    var p, i, foundObj;

    if(!theDoc) theDoc = document;
    if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
    {
        theDoc = parent.frames[theObj.substring(p+1)].document;
        theObj = theObj.substring(0,p);
    }
    if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
    for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
    for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
    if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

    return foundObj;
}

function roundoff(amount) {
    return (amount == Math.floor(amount)) ? amount + '.000' : ( (amount*10 == Math.floor(amount*10)) ? amount + '00' : amount);
}

var new_only = 0;

function total(what, number, new_only) {
//    alert(new_only);
    var num = new NumberFormat();

    num.setInputDecimal('.');

    num.setPlaces('3');
    num.setCurrencyValue('');
    num.setCurrency(false);
    num.setCurrencyPosition(num.LEFT_OUTSIDE);
    num.setNegativeFormat(num.LEFT_DASH);
    num.setNegativeRed(true);
    num.setSeparators(true, '.', ',');
//    obj.value = num.toFormatted();

    var grandTotal = 0;
/*
    if (findObj('old_number['+number+']').value == '')
    findObj('old_number['+number+']').value = '0,00'; // fix for Opera.*/

    /*        what.elements['subtotal' + i].value=(what.elements['quantity' + i].value - 0) * (what.elements['price' + i].value - 0);
    if (what.elements['quantity' + i].value == "0")
    what.elements['subtotal' + i].value = "0.00";*/

    subtotal = findObj('new_number['+number+']').value;
    old = findObj('old_number['+number+']').value ;
    consumption = findObj('consumption['+number+']').value ;

    subtotal = subtotal.replace(".", '');
    subtotal = subtotal.replace(",", '.');

    old = old.replace("." ,'');
    old = old.replace("," ,'.');

    consumption = consumption.replace("." ,'');
    consumption = consumption.replace("," ,'.');


    grandTotal = (subtotal - 0) - (old - 0);
    newC = (consumption - 0) + (old - 0);

    subtotal=roundoff(Math.round(subtotal*Math.pow(10,3))/Math.pow(10,3));
    if(new_only == 0 || !new_only) {
        if(old!='' && subtotal!='' && (old-0)!=0 &&  (subtotal-0)!=0){
            t = roundoff(Math.round(grandTotal*Math.pow(10,3))/Math.pow(10,3));
            num.setNumber(t); //
            t =  num.toFormatted();
            findObj('consumption['+number+']').value  = t;

            if(num.NR) {
                findObj('consumption['+number+']').style.background='#F1CFCF';
            }else{
                findObj('consumption['+number+']').style.background='#FFF';
            }
        }
    }
     if(new_only == 1) {
         if(consumption!='' && old!='' && (consumption-0)!=0 &&  (old-0)!=0){
             n = roundoff(Math.round(newC*Math.pow(10,3))/Math.pow(10,3));
             num.setNumber(n); //
             n =  num.toFormatted();
             findObj('new_number['+number+']').value  = n;

             if(num.NR) {
                 findObj('new_number['+number+']').style.background='#F1CFCF';
             }else{
                 findObj('new_number['+number+']').style.background='#FFF';
             }
         }
     }
//     alert(subtotal);
     if(new_only == 2 && (findObj('new_number['+number+']').value =='' || ((subtotal-0)==0&& (old-0)==0))) {
         if(consumption!='' && old!='' && (consumption-0)!=0 &&  (old-0)!=0){
             n = roundoff(Math.round(newC*Math.pow(10,3))/Math.pow(10,3));
             num.setNumber(n); //
             n =  num.toFormatted();
             findObj('new_number['+number+']').value  = n;

             if(num.NR) {
                 findObj('new_number['+number+']').style.background='#F1CFCF';
             }else{
                 findObj('new_number['+number+']').style.background='#FFF';
             }
         }
     }
}

function formatIt(number) {

    var num = new NumberFormat();

    num.setInputDecimal('.');

    num.setPlaces('3');
    num.setCurrencyValue('');
    num.setCurrency(false);
    num.setCurrencyPosition(num.LEFT_OUTSIDE);
    num.setNegativeFormat(num.LEFT_DASH);
    num.setNegativeRed(true);
    num.setSeparators(true, '.', ',');

    newV = findObj('new_number['+number+']').value;
    newV = newV.replace("." ,'');
    newV = newV.replace("," ,'.');

    oldV = findObj('old_number['+number+']').value;
    oldV = oldV.replace("." ,'');
    oldV = oldV.replace("," ,'.');

    consumpV = findObj('consumption['+number+']').value;
    consumpV = consumpV.replace("." ,'');
    consumpV = consumpV.replace("," ,'.');

    num.setNumber(newV);
    if(newV !='' || newV != 0)
    findObj('new_number['+number+']').value = num.toFormatted();

    num.setNumber(oldV);
    if(oldV !='' || oldV != 0)
    findObj('old_number['+number+']').value = num.toFormatted();

    num.setNumber(consumpV);
    if(consumpV !='' || consumpV != 0)
    findObj('consumption['+number+']').value = num.toFormatted();

}
function formatItGen(number) {

    var num = new NumberFormat();

    num.setInputDecimal('.');

    num.setPlaces('2');
    num.setCurrencyValue('');
    num.setCurrency(false);
    num.setCurrencyPosition(num.LEFT_OUTSIDE);
    num.setNegativeFormat(num.LEFT_DASH);
    num.setNegativeRed(true);
    num.setSeparators(true, '.', ',');

    newV = findObj(number).value;
    newV = newV.replace("." ,'');
    newV = newV.replace("," ,'.');

    num.setNumber(newV);
    if(newV !='' || newV != 0)
    findObj(number).value = num.toFormatted();

}

function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4

        if (bgcolor=="") {
                bgcolor="#FFFFFF";
        }
        bgcolor="#FFFFFF";
        var adj=10
        var w = screen.width;
        var h = screen.height;
        var byFactor=1;

        if(w<740){
          var lift=0.90;
        }
        if(w>=740 & w<835){
          var lift=0.91;
        }
        if(w>=835){
          var lift=0.93;
        }
        if (imageWidth>w){
          byFactor = w / imageWidth;
          imageWidth = w;
          imageHeight = imageHeight * byFactor;
        }
        if (imageHeight>h-adj){
          byFactor = h / imageHeight;
          imageWidth = (imageWidth * byFactor);
          imageHeight = h;
        }

        var scrWidth = w-adj;
        var scrHeight = (h*lift)-adj;

        if (imageHeight>scrHeight){
            imageHeight=imageHeight*lift;
          imageWidth=imageWidth*lift;
        }

        var posLeft = 0;
        var posTop = 0;
        hugMargin = 0;
        hugger = "hug image";
        if (hugger == "hug image"){
          if (hugMargin == ""){
            hugMargin = 0;
          }
          var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
          if (scrHeightTemp < scrHeight) {
                scrHeight = scrHeightTemp;
          }
          var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
          if (scrWidthTemp < scrWidth) {
                scrWidth = scrWidthTemp;
          }

          if (scrHeight<100){scrHeight=100;}
          if (scrWidth<100){scrWidth=100;}

          posTop =  ((h-(scrHeight/lift)-adj)/2);
          posLeft = ((w-(scrWidth)-adj)/2);
         }

        if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
                imageHeight=imageHeight-adj;
                imageWidth=imageWidth-adj;
        }
        posTop = parseInt(posTop);
        posLeft = parseInt(posLeft);
        scrWidth = parseInt(scrWidth);
        scrHeight = parseInt(scrHeight);

        var agt=navigator.userAgent.toLowerCase();
        if (agt.indexOf("opera") != -1){
          var args= new Array();
          args[0]='parent';
          args[1]=imageName;
          var i ; document.MM_returnValue = false;
          for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
        } else {

        newWindow = window.open("http://"+  document.location.host +"/picture.html","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
        newWindow.document.open();
// onBlur="self.close()" onClick="self.close()"
        BaseUrl = document.location.protocol + '//' + document.location.host + '/' ;

        if(imageName.indexOf('http:')==0)
	 	BaseUrl = '';
        newWindow.document.write('<html><title>SPL d.d. - '+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+'>');
        newWindow.document.write('<table width='+BaseUrl +imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
        newWindow.document.write('<img src="'+BaseUrl+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="" >');
        newWindow.document.write('</td></tr></table></body></html>');
        newWindow.document.close();
        newWindow.focus();
        }
}

function hide(is_link, _u,_d, _m) {
  var _l   = _u + "@" + _d;
  if(is_link == true)
  document.write("<a href='mailto:"+_l+"'>"+_m+"</a>");
  else
  document.write(_l);
}

function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function jumpMenuGo(selName,targ,restore){ //v3.0

  var selObj = findObj(selName); if (selObj) jumpMenu(targ,selObj,restore);
}



var c = new Array();
var s = -1;
var t = 3;
var r = setTimeout('',1);

function wtd() {
	var d = document.getElementById('img_c');
	//alert(d);
	if (d && (s > -2) && (t > 0) && (c.length > 0)) {
		var i = s+1;
		clearTimeout(r);
		if (i >= c.length) i = 0;
		s = i;
		var we = c[i];
		d.innerHTML = '';
		d.innerHTML = we;
		r = setTimeout('wtd()',t*1000);
	}
}

function switchToForum(elementIdOld, elementIdNew) {
	var inputElementOld = document.getElementById(elementIdOld);
	var inputElementNew = document.getElementById(elementIdNew);
	var submitElementNew = document.getElementById('new_calculation');
	var sendElement = document.getElementById('send');
	inputElementOld.style.display = 'none';
	inputElementNew.style.display = 'block';
	submitElementNew.style.display = 'block';
	sendElement.style.display = 'none';

}

function toggle(elementID){
	var target1 = document.getElementById(elementID)
	if (target1.style.display == 'none') {
		target1.style.display = 'block'
	} else {
		target1.style.display = 'none'
	}
}
