var BOX_WIDTH = 77;
var BOX_HEIGHT = 51;
var BOX_X_RES = 48;
var BOX_Y_RES = 32;
var INDOOR_BOX_PRICE = 2350;
var OUTDOOR_BOX_PRICE = 2796.5;

var indoor_preselect_on  = 'gfx/scr01_rv_in_on.jpg';
var outdoor_preselect_on = 'gfx/scr01_rv_out_on.jpg';

function _request(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if (results == null) {
    return "";
  } else {
    return results[1];
  }
}
function haggle(called_from, b_width, b_height, b_width_cm, b_height_cm) {
  b_width.value     = b_width.value.replace(/[^0-9]/g, '');
  b_height.value    = b_height.value.replace(/[^0-9]/g, '');
  b_width_cm.value  = b_width_cm.value.replace(/[^0-9]/g, '');
  b_height_cm.value = b_height_cm.value.replace(/[^0-9]/g, '');
  if (called_from.id == 'b_width'
     ||
     called_from.id == 'b_height'
     ||
     called_from.id == 'round') {
    b_width_cm.value = b_width.value * BOX_WIDTH;
    b_height_cm.value = b_height.value * BOX_HEIGHT;
  } else if (called_from.id == 'b_width_cm' || called_from.id == 'b_height_cm') {
    var new_val = (b_width_cm.value - b_width_cm.value % BOX_WIDTH) / BOX_WIDTH;
    if (new_val==0) { new_val++; }
    b_width.value = new_val;
    new_val = (b_height_cm.value - b_height_cm.value % BOX_HEIGHT) / BOX_HEIGHT;
    if (new_val == 0) { new_val++; }
    b_height.value = new_val;
  }
  if (document.getElementById('round')) {
    var deb_val = (b_width_cm.value - b_width_cm.value % BOX_WIDTH) + '*' + (b_height_cm.value - b_height_cm.value % BOX_HEIGHT);
    if ( b_width_cm.value + '*' + b_height_cm.value != deb_val ) {
      document.getElementById('round').src = 'gfx/round.png';
    } else {
      document.getElementById('round').src = 'gfx/round_mono.png';
    }
  }
}
function calc02(called_from) {
  if (!called_from) {
    return;
  }
  var b_width     = document.getElementById('b_width');
  var b_height    = document.getElementById('b_height');
  var b_width_cm  = document.getElementById('b_width_cm');
  var b_height_cm = document.getElementById('b_height_cm');
  haggle(called_from, b_width, b_height, b_width_cm, b_height_cm);
}
function calc(called_from) {
  if (!called_from) {
    var called_from = document.getElementById('b_width');
  }
  if (called_from.id == 'outdoor' || called_from.id == 'indoor') {
    if (called_from.checked != true) {
      alert(called_from.id + ' ' + called_from.value);
    }
  }
  var b_width     = document.getElementById('b_width');
  var b_height    = document.getElementById('b_height');
  var b_width_cm  = document.getElementById('b_width_cm');
  var b_height_cm = document.getElementById('b_height_cm');
  haggle(called_from, b_width, b_height, b_width_cm, b_height_cm);
  if (document.getElementById('res_total')) {
    var res_total = document.getElementById('res_total');
    res_total.innerHTML = (b_width.value * BOX_X_RES) + 'x' + (b_height.value * BOX_Y_RES);
  }
  if (document.getElementById('box_total')) {
    var box_total = document.getElementById('box_total');
    box_total.innerHTML = (b_width.value * b_height.value);
  }
  if (document.getElementById('price_total')) {
    var price_total = document.getElementById('price_total');
    var box_price = INDOOR_BOX_PRICE;
    if (document.getElementById('outdoor').checked) {
      box_price = OUTDOOR_BOX_PRICE;
    }
    price_total.innerHTML = (b_width.value * b_height.value * box_price) + ' ¤';
  }
  if (document.getElementById('led_total')) {
    var led_total = document.getElementById('led_total');
    led_total.innerHTML = (b_width.value * b_height.value * BOX_X_RES * BOX_Y_RES * 4)
  }
  if (document.getElementById('pixel_total')) {
    var pixel_total = document.getElementById('pixel_total');
    pixel_total.innerHTML = (b_width.value * b_height.value * BOX_X_RES * BOX_Y_RES)
  }
}
/* strange mouse-over js begin */
function scr_swapImgRestore() {
  var i,x,a=document.DisplayConfig_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function DisplayConfig_findObj(n, d) {
  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=DisplayConfig_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function scr_swapImage() {
  var i,j=0,x,a=scr_swapImage.arguments;
  document.DisplayConfig_sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
    if ((x=DisplayConfig_findObj(a[i]))!=null) {
      document.DisplayConfig_sr[j++]=x;
      if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
    }
}
/* strange mouse-over js end */

