var selected;
var submitter = null;

function submitFunction() {
    submitter = 1;
}
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.getElementById('payment'[0])) {
    document.getElementById('payment'[buttonSelect]).checked=true;
  } else {
    //document.getElementById('payment'[selected]).checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function popupImageWindow(url) {
  window.open(url,'popupImageWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function FormatNumber(num, decimal, thousand, decimals)
{
  if(isNaN(num)) { num = "0"; }
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num+0.50000000001);
  pot = Math.pow(10, decimals);
  cents = num%pot;
  num = Math.floor(num/pot).toString();
  if(cents<10) { cents = "0" + cents; }
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  {
    num = num.substring(0,num.length-(4*i+3)) + thousand + num.substring(num.length-(4*i+3));
  }
  return (((sign)?'':'-') + num + decimal + cents);
}

function showPrice(form)
{
  var myTotalPrice = 0;
  var showUP = 0;
  var myMathProblem = "";
  var myForms = "";
  var myFirstTry = 0;
  var attrib = 0;
  var myAttributeString = '';
  var found = -1;
  myItemPrice = parseFloat(form.nuPrice.value);
  currency = form.currency.value;

  left = form.left.value;
  right = form.right.value;
  decimal = form.decimal.value;
  thousand = form.thousand.value;
  decimals = form.decimals.value;
  //decimals = 4;

  for (var i = 0; i < form.elements.length; i++) {
    var e = form.elements[i];
    //myForms = myForms + " - " + e.type
    if ( e.type == 'select-one' ) {
      showUP = 1;
      Item = e.selectedIndex;
      myPrice = e.options[Item].text;
      if (left != '') {
        myStart = myPrice.indexOf(left,0);
        found = myStart;
        myLeftSign = myStart + left.length + 1;
        if (right != '') {
          myRightSign = myPrice.indexOf(right,0) - right.length;
        } else {
          myRightSign = myPrice.length;
        }
      } else if (right != '') {
        myRightSign = myPrice.indexOf(right,0);
        found = myRightSign;
        myStart = myPrice.lastIndexOf(" ", myRightSign-2)
        myLeftSign = myStart + 1;
      }
      myEuroSign = myPrice.indexOf(currency,0);
      if ( found != "-1" )
      {
        myParSign = myPrice.lastIndexOf(" ", myEuroSign-2);
        myAttributeString = myPrice.substring(myEuroSign+1, myParSign);
        myAttributeString = myAttributeString.replace(/[,.]/,"");
        myAttributePrice = parseFloat(myAttributeString);
        myMathProblem = myPrice.charAt(myParSign - 1);
      } else { myAttributePrice = 0; }
      if (myMathProblem == "-")
      {
        myTotalPrice = myTotalPrice - myAttributePrice;
      } else {
        myTotalPrice = myTotalPrice + myAttributePrice;
      }
    }
    if ( e.type == 'radio' ) {
      showUP = 1;
      if (e.checked == true) {
        myPrice = getPriceArray(e.value);
        if (left != '') {
          myStart = myPrice.indexOf(left,0);
          found = myStart;
          myLeftSign = myStart + left.length + 1;
          if (right != '') {
            myRightSign = myPrice.indexOf(right,0) - right.length;
          } else {
            myRightSign = myPrice.length;
          }
        } else if (right != '') {
          myRightSign = myPrice.indexOf(right,0);
          found = myRightSign;
          myStart = myPrice.lastIndexOf(" ", myRightSign-2)
          myLeftSign = myStart + 1;
        }
        myEuroSign = myPrice.indexOf(currency,0);
        if ( found != "-1" ) {
          myAttributeString = myPrice.substring(myLeftSign, myRightSign);
          myAttributeString = myAttributeString.replace(/[,.]/,"");
          myAttributePrice = parseFloat(myAttributeString);
          myMathProblem = myPrice.charAt(myStart - 1);
        } else { myAttributePrice = 0; }
        if(isNaN(myAttributePrice)) { myAttributePrice = 0; }
        if (myMathProblem == "-") {
          myTotalPrice = myTotalPrice - myAttributePrice;
        } else {
          myTotalPrice = myTotalPrice + myAttributePrice;
        }
      }
      attrib = attrib + "-" + myTotalPrice;
    }
  }
  if ( showUP == 1 ) {
    myTotalPrice = FormatNumber(myTotalPrice + myItemPrice, decimal, thousand, decimals);
    document.getElementById("productsNEWprice").innerHTML = "Der aktuelle Preis betr&auml;gt <strong>" + left + " " + myTotalPrice + " " + right + "<\/strong>";
    //document.getElementById("productsNEWprice").innerHTML = "Der aktuelle Preis betr&auml;gt <strong>" + left + " " + myEuroSign + " " + myLeftSign + " " + myRightSign + " " + myTotalPrice + " " + attrib + " " + right + "<\/strong>";
  }
}

var preis;

function initPriceArray(max) {
  preis = new Array();
}

function setPriceArray(val,price) {
  preis[val] = price;
}

function getPriceArray(val) {
  return preis[val];
}
