var min_width=0;
var max_width=0;
var min_drop=0;
var max_drop=0;
var price=0;
var shape_price=0;
var discount=0;
var delivery = 0;
var skip_recheck_cafe_rods = false;

var cassette_price = 0;
var extra_control_price = 0;

var discountrm=0;
var price_rm=0;
var price_mm=0;

function sortArrayPrice(a,b){
  return(a-b);
}

// MM
var arr = new Array();
arr = eval('Array('+blackoutmm_arr[4][3]+')');
var sorter = new Array();
sorter = arr.sort(sortArrayPrice);

// RM
var arrRM = new Array();
if(typeof(blackout_arr) != "undefined" && blackout_arr.length > 0) {
  arrRM = eval('Array('+blackout_arr[3]+')');
}
var sorterRM = new Array();
sorterRM = arrRM.sort(sortArrayPrice);

function getMinimumPrice(){
  var minpriceMM = minpriceRM = 9999;

  // MM
  minP = sorter;
  //var discount_ = blackoutmm_arr[4]; (se ia direct din js)
  minpriceMM = (minP[0].toFixed(2) * (1-discount_)).toFixed(2);
  //alert("MM: " + minpriceMM);

  // RM
  if(typeof(blackout_arr) != "undefined" && blackout_arr.length > 0) {
    minPRM = sorterRM;
    var discountRM = blackout_arr[0];
    minpriceRM = (minPRM[0].toFixed(2) * (1-discountRM)).toFixed(2);
    //alert("RM: " + minpriceRM);
  }

  var minArray = new Array();
  minArray[0] = minpriceMM;
  minArray[1] = minpriceRM;
  var minPrice = minArray.sort(sortArrayPrice);

  //alert("MinPrice: " + minPrice[0]);
  //document.getElementById('minprice').innerHTML = minPrice[0]; // REMOVED
  document.getElementById('minprice').innerHTML = minpriceMM;

}

function CheckReferrer() {
  var ref = document.referrer;

  params = getParams();
  var nd = 0; // nextday parameter
  if(params["nd"] == 1)
    nd = 1;

  // nextday selection
  if(ref != "http://www.blindsuk.net/blackout-next-day.html" && nd == 0) {
    document.form_calcblackoutmm.nextday.selectedIndex = 1; // select default "Standard, 7 days" when not coming from above links
  }
  else {
    document.form_calcblackoutmm.nextday.selectedIndex = 0; // select default NEXTDAY
//    document.form_calcblackoutmm.nextday.selectedIndex = 1; // for bank holiday
  }

  // control selection
  if(ref != "http://www.blindsuk.net/rollermm/spring-roller-blinds.html" && ref != "http://www.blindsuk.net/rollermm/spring-roller-blinds-page1.html") {
    document.form_calcblackoutmm.controls.selectedIndex = 0; // select standard control
  }
  else {
    document.form_calcblackoutmm.controls.selectedIndex = 4; // select spring control
  }

}

function getParams()
{
  var idx = document.URL.indexOf('?');
  var params = new Array();
  if (idx != -1)
  {
    var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
    for (var i=0; i<pairs.length; i++)
    {
      nameVal = pairs[i].split('=');
      params[nameVal[0]] = nameVal[1];
    }
  }
  return params;
}

function SetOtherParams()
{
    params = getParams();
    if (params["controls"] && params["recess"])
    {
        document.form_calcblackoutmm.controls.value = params["controls"];
        //document.form_calcblackoutmm.finish_shape.value = params["scallop"];
        //selectFinish(document.form_calcblackoutmm.finish_shape.value);
        //document.form_calcblackoutmm.braid.value = params["braid"];
        //selectBraid(document.form_calcblackoutmm.braid.value);
        //document.form_calcblackoutmm.cafe_rods.value = params["rods"];
        document.form_calcblackoutmm.recess.value = params["recess"];
        //selectRecess(document.form_calcblackoutmm.recess.value);
    }
}

function SetOtherParams()
{
    params = getParams();
    if (params["controls"] && params["recess"])
    {
        document.form_calcblackoutmm.controls.value = params["controls"];
        document.form_calcblackoutmm.recess.value = params["recess"];
    }
}

function SetParams()
{
  min_width=parseInt(blackoutmm_arr[0]);
  max_width=parseInt(blackoutmm_arr[1]);
  min_drop=parseInt(blackoutmm_arr[2]);
  max_drop=parseInt(blackoutmm_arr[3]);

  //discount=parseFloat(blackoutmm_arr[4]);
  discount=discount_;

  params = getParams();

  width = params["width"];
  drop = params["drop"];

  outside = params["outside"];

  // default recess OUTSIDE when coming from QQ
  if((outside!="")&&(typeof(outside) != "undefined")) {
    document.form_calcblackoutmm.recess.value = "Outside";
    var recess=document.form_calcblackoutmm.recess.value;
  }

  if((width!="")&&(typeof(width) != "undefined"))
    document.form_calcblackoutmm.custom_width.value=unescape(width);
  if((drop!="")&&(typeof(drop) != "undefined"))
    document.form_calcblackoutmm.custom_drop.value=unescape(drop);

  if((document.form_calcblackoutmm.custom_width.value!="")&&(document.form_calcblackoutmm.custom_drop.value!=""))
    GetCustomPrice();
}

function formatDecimal(argvalue, addzero, decimaln) {
  var numOfDecimal = (decimaln == null) ? 2 : decimaln;
  var number = 1;

  number = Math.pow(10, numOfDecimal);

  argvalue = Math.round(parseFloat(argvalue) * number) / number;

  argvalue = "" + argvalue;

  if (argvalue.indexOf(".") == 0)
    argvalue = "0" + argvalue;

  if (addzero == true) {
    if (argvalue.indexOf(".") == -1)
      argvalue = argvalue + ".";

    while ((argvalue.indexOf(".") + 1) > (argvalue.length - numOfDecimal))
      argvalue = argvalue + "0";
  }

  return argvalue;
}

function ChangePrice(custom_ctrl, form_calc)
{
  custom_ctrl.value="";
  form_calc.price.value="";
  form_calc.saveprice.value="";
}

function GetPrice(prices_arr, width, drop, comision)
{
  var min_dif_width=-1, min_dif_drop=-1;
  var sel_width=-1, sel_drop=-1;
  var price=0;
  for(i=0;i<prices_arr[0].length;i++)
  {
    var cur_dif_width=prices_arr[1][i]-width;
    var cur_dif_drop=prices_arr[2][i]-drop;
    //alert("dif curenta: "+cur_dif_width+"   width: "+sizes_arr[1][i]+" custom width:"+custom_width);
    if(((min_dif_width==-1)||(cur_dif_width<min_dif_width))&&(cur_dif_width>=0))
    {
      min_dif_width=cur_dif_width;
      sel_width=prices_arr[1][i];
      sel_drop=-1;
      min_dif_drop=-1;
    }

    if(prices_arr[1][i]==sel_width)
      if(((min_dif_drop==-1)||(cur_dif_drop<min_dif_drop))&&(cur_dif_drop>=0)&&(min_dif_width!=-1))
      {
        min_dif_drop=cur_dif_drop;
        sel_drop=prices_arr[2][i];
        price = (!comision)? prices_arr[3][i] : prices_arr[4][i];
      }
  }
  return price;
}

function GetRMPrice(custom_width, custom_drop)
{
  document.form_calcblackoutmm.blackout.value=0;
  var priceRM = 0;

  //document.form_calcblackout.price.value = '';
  //document.form_calcblackout.saveprice.value = '';
  for(i=0; i<blackout_arr[1].length; i++)
  {
    if(custom_width == blackout_arr[1][i] && custom_drop == blackout_arr[2][i])
    {
      /*
      var salesave = blackout_arr[3][i]*blackout_arr[0];
      var saleprice = blackout_arr[3][i]-salesave;
      document.form_calcblackoutmm.price.value=formatDecimal(saleprice, true, 2);
      document.form_calcblackoutmm.saveprice.value=formatDecimal(salesave, true, 2);
      document.form_calcblackoutmm.blackout.value=i+1;
      */
      document.form_calcblackoutmm.blackout.value=i+1;
      priceRM = blackout_arr[3][i];

    }
  }

  return priceRM;
}

function GetMaxWidth(prices_arr, drop)
{
  var max_width=0;
  var min_dif_drop=-1;
  var sel_drop=-1;
  for(i=0;i<prices_arr[0].length;i++)
  {
    var cur_dif_drop=prices_arr[2][i]-drop;
    if(((min_dif_drop==-1)||(cur_dif_drop<min_dif_drop))&&(cur_dif_drop>=0))
    {
      min_dif_drop=cur_dif_drop;
      sel_drop=prices_arr[2][i];
      max_width=0;
    }

    if((prices_arr[2][i]==sel_drop)&&(max_width<prices_arr[1][i]))
      max_width=prices_arr[1][i];
  }
  return max_width;
}

function GetCustomPrice()
{
//  return ('get_custom_price').fire('click');
//  ProductObject.get_price();

  var price = 0;
  var custom_width=parseInt(document.form_calcblackoutmm.custom_width.value);
  var custom_drop=parseInt(document.form_calcblackoutmm.custom_drop.value);

  if((min_width>custom_width)||(max_width<custom_width)||(isNaN(custom_width)))
  {
    alert("Please enter width between "+min_width+"mm (min) and "+max_width+"mm (max)");
    return false;
  }
  if((min_drop>custom_drop)||(max_drop<custom_drop)||(isNaN(custom_drop)))
  {
    alert("Please enter drop between "+min_drop+"mm (min) and "+max_drop+"mm (max)");
    return false;
  }
//  if (document.form_calcblackoutmm.nextday.selectedIndex != 1)
//  {
//    alert ("Unfortunately the next day option for this type of blinds is not available at the moment.\r\nThis service will be resumed on Monday the 29th after noon.");
//    document.form_calcblackoutmm.nextday.selectedIndex = 1;
//  }

  var recess=document.form_calcblackoutmm.recess.value;
  document.form_calcblackoutmm.blackout.value=0;

  if(recess=="Inside")
    custom_width -= 3;

  /* REMOVED
  if(typeof(blackout_arr) != "undefined" && document.form_calcblackoutmm.nextday.value == 0) { // maybe RM price, but not on nextday!
    discountrm = blackout_arr[0];
    discount=discountrm;
    //alert("Width : " + custom_width + "\nDrop: " + custom_drop);
    price=GetRMPrice(custom_width, custom_drop);
    price_rm=price;
    //alert("Price RM: " + price);
  }
  else
    price_rm = 0;
  */
  price_rm = 0;

  if(recess=="Inside")
    custom_width += 3;

  price_mm = GetPrice(blackoutmm_arr[4], custom_width, custom_drop);

  if(!price || price == 0)
  {
    //alert('NU AM PRET DE RM!');
    //discount=parseFloat(blackoutmm_arr[4]); // MM discount
    discount = discount_;
    price = price_mm;
    if(price == 0) {
      var strMaxWidth=GetMaxWidth(blackoutmm_arr[4], custom_drop);
      alert("Maximum width for the selected drop is "+strMaxWidth+" mm");
      return;
    }
  }

  // nextday price
  var delivery = document.form_calcblackoutmm.nextday;
  //if ((custom_width > 1840 && custom_drop > 1700) || (custom_drop > 2750)){ // no nextday dimensions -- OLD! --
  /*
  if ((custom_width > 1900 && custom_drop >= 1700) || (custom_drop > 2700)){ // no nextday dimensions (JOINT!)
    if(delivery.selectedIndex == 0){
      alert("Next day service is not available for these sizes!");
    }
    delivery.selectedIndex = 1; // select standard
    document.form_calcblackoutmm.nextday2.selectedIndex = 1; // select standard
  }
  */
  var delivery_price = 0;

  /* *** for bank holiday *** */
  if(delivery.value != 0 && false) {
    alert("Sorry, nextday service is no longer available on this product.");
    document.form_calcblackoutmm.nextday.selectedIndex = 1;
    delivery.value = 0;
  }

  if (delivery.value != 0)
    delivery_price = 5 / (1 - discount);


  cassette_price = 0;
  if($('top_cassette') && $('top_cassette').value != 0)
  {
    if (check_sizes_interval()==false)
    {
      document.form_calcblackoutmm.top_cassette.selectedIndex = 0;
      new ComboCassette('cassette_color_container', {handler:'event_handler', populate_data:null, input:'cassette_color'});
    }
    else {
      if ($('top_cassette').value  == '3' && $('use_new_contrasting_system').value == '1')
        cassette_price = GetCassettePrice(2, custom_width, custom_drop);
      else cassette_price = GetCassettePrice($('top_cassette').value, custom_width, custom_drop);
    }
  }

  /* *** NO NEXTDAY FOR SOME PRODS  *** */
  /* REMOVED
  var pid = 0;
  if(assigned_scallop != null && assigned_scallop['blackoutmm_product_id'] != "undefined") {
    pid = assigned_scallop['blackoutmm_product_id'];
  }
  if(delivery.value != 0 && (pid == 70 || pid == 147)) {
    alert("Sorry, the NEXT DAY service is not available for this product.");
    document.form_calcblackoutmm.nextday.selectedIndex = 1;
    delivery_price = 0;
    delivery.value = 0;
  }
  */
  /* *************************** */

  // controls price
  /* ******************************************************* */


  if ($('cafe_rods').length > 1 && skip_recheck_cafe_rods == false) {
    checkCafeRodsControls(true);
  }

  /* Spring minimum width 470mm. Max width and max drop 1800x1800 */
  var sel_controls = document.form_calcblackoutmm.controls.selectedIndex;
  if((custom_width < 470 || custom_width > 2200 || custom_drop > 1800) && (sel_controls != 0 && sel_controls != 1 && sel_controls != 2 && sel_controls != 3)) {
    alert("The selected control option is not available for these sizes!");
    document.form_calcblackoutmm.controls.selectedIndex = 0;
  }

  /* TEMPORARY: NO NEXTDAY FOR SPRING CONTROLS */
  // if not normal controls (plastic left, plastic right, metal left, metal right)
  /*
  if(sel_controls != 0 && sel_controls != 1 && sel_controls != 2 && sel_controls != 3 && delivery.selectedIndex == 0) {
    alert("Next day service is not available on this option!");
    delivery_price = 0;
    delivery.selectedIndex = 1; // select standard
    //document.form_calcblackoutmm.nextday2.selectedIndex = 1; // select standard - REMOVED
  }
  */
  /* [END] NO NEXTDAY FOR SPRING CONTROLS */

  var controls_price = 0;
  var controls = document.form_calcblackoutmm.controls.value;
  if(controls == "Right Metal" || controls == "Left Metal") {
    if(custom_drop <= 1000)
      controls_price = 0.62;
    else if(custom_drop > 1000 && custom_drop <= 2000)
      controls_price = 1.26;
    else if(custom_drop > 2000)
      controls_price = 2.32;
  } //end if metal controls
  /*
  else if(controls == "Clear Ball")
    controls_price = 1.2 + 1.26; // 1 (+vat) + 1.05 (+vat)
  */
  else if(controls == "Bullet Nickel")
    controls_price = 1.2 + 0.84; // 1 (+vat) + 0.7 (+vat)
  else if(controls == "Bullet Brass")
    controls_price = 1.2 + 0.66; // 1 (+vat) + 0.55 (+vat)
  else if(controls == "Bullet Black")
    controls_price = 1.2 + 0.70; // 1 (+vat) + 0.59 (+vat)
  else if(controls == "Cylinder Pine" || controls == "Cylinder Walnut")
    controls_price = 1.2 + 0.33; // 1 (+vat) + 0.28 (+vat)
  else if(controls == "Brushed Steel")
    controls_price = 1.2 + 1.64; // 1 (+vat) + 1.37 (+vat)
  else if(controls == "Ball Jute")
    controls_price = 1.2 + 1.02; // 1 (+vat) + 0.85 (+vat)
  else if(controls == "Spring")
    controls_price = 2.4; // 1 + prof + vat

  controls_price = controls_price / (1 - discount);

  // [END] CONTROLS
  /* ******************************************************* */

  /***** SCALLOPS  ****/
  /*sel = new ComboSelect('braids');
    sel.select_braids(22);*/
  //custom_width, custom_drop



  if($('scallops')){
    selected_scallop = $('scallops')[$('scallops').options.selectedIndex].innerHTML.strip();
  }

  if(document.form_calcblackoutmm.recess.value == 'Outside' || document.form_calcblackoutmm.recess.value == 'Inside' ){
    if(custom_width > 2963 && (selected_scallop == 'classic' || selected_scallop == 'provence') ){
      $('scallops')[0].selected = true;
      new ScallopsOptions();
      return alert('Maximum width for the selected scallop is 2963 mm.');
    }
    if(custom_width > 2980 && selected_scallop == 'colonial'){
      $('scallops')[0].selected = true;
      new ScallopsOptions();
      return alert('Maximum width for the selected scallop is 2980 mm.');
    }
    if(custom_width > 2927 && selected_scallop == 'coronet'){
      $('scallops')[0].selected = true;
      new ScallopsOptions();
      return alert('Maximum width for the selected scallop is 2927 mm.');
    }
  }

  if(document.form_calcblackoutmm.recess.value == 'Cloth'){
    if(custom_width > 2928 && (selected_scallop == 'classic' || selected_scallop == 'provence')){
      $('scallops')[0].selected = true;
      new ScallopsOptions();
      return alert('Maximum width for the selected scallop is 2928 mm.');
    }
    if(custom_width > 2945 && selected_scallop == 'colonial'){
      $('scallops')[0].selected = true;
      new ScallopsOptions();
      return alert('Maximum width for the selected scallop is 2945 mm.');
    }
    if(custom_width > 2892 && selected_scallop == 'coronet'){
      $('scallops')[0].selected = true;
      new ScallopsOptions();
      return alert('Maximum width for the selected scallop is 2892 mm.');
    }
  }

  if(custom_width < 660 && selected_scallop == 'coronet'  ){
    $('scallops')[0].selected = true;
    new ScallopsOptions();
    return alert('Minimum width for the selected scallop is 660 mm.');
  }



  comision = GetPrice(blackoutmm_arr[4], custom_width, custom_drop, true);
  if(document.form_calcblackoutmm.braid || document.form_calcblackoutmm.braid.type != 'hidden')
  {
      if(document.form_calcblackoutmm.braid.value == 0 || selected_scallop == 'straight finish' )
    {
      if( selected_scallop != 'straight finish' && document.form_calcblackoutmm.bottombar.value == 0 )
        braids_price = 1.5  * comision * minus * (1+com);
      else
        braids_price = 0;
    }
    else
    {
      braids_price  = (parseFloat(new GetScallopsPrice(document.form_calcblackoutmm.braid.value, custom_width, custom_drop).s_price)+1.5) * comision * minus * (1+com);
    }
  }
  else
  {
    braids_price = 0;
  }
  if(document.form_calcblackoutmm.bottombar)
  {
    if(document.form_calcblackoutmm.bottombar.value == 0)
      bottombar_price = 0;
    else
    {
      if ($('use_new_contrasting_system').value == '1')
        bottombar_price = (parseFloat(new GetContrastingBarPrice(document.form_calcblackoutmm.bottombar.value, custom_width, custom_drop).s_price))  * comision * minus * (1+com);
      else
        bottombar_price = 1.5  * comision * minus * (1+com);
    }
  }
  else
  {
    bottombar_price = 0;
  }
  if(document.form_calcblackoutmm.cafe_rods && document.form_calcblackoutmm.cafe_rods.type != 'hidden' )
    caferods_price = parseFloat(new GetScallopsPrice(document.form_calcblackoutmm.cafe_rods.value, custom_width, custom_drop).s_price)  * comision * minus * (1+com);
  else
    caferods_price = 0;

  m_extra_cass_price = 0;
  if ($('top_cassette').value  == '3' && $('use_new_contrasting_system').value == '1')
    m_extra_cass_price = (parseFloat(new GetContrastingBarPrice(document.form_calcblackoutmm.cassette_color.value, custom_width, custom_drop).s_price));

  //console.log('Braids: '+braids_price +"\r\n"+'Bottom bar: '+bottombar_price+'\r\nCafe rods: '+caferods_price);
  var total_price =
          price +
          delivery_price +
          controls_price +
          bottombar_price +
          braids_price+
          caferods_price +
          m_extra_cass_price;


  var save_price = formatDecimal(total_price * discount, true, 2);

  document.form_calcblackoutmm.price.value = formatDecimal((total_price - save_price)+cassette_price, true, 2);
  document.form_calcblackoutmm.saveprice.value = formatDecimal(save_price, true, 2);

  document.form_calcblackoutmm.addtobasket.disabled=false;
//  ('get_custom_price').fire('click');
  RRP.get();

}

/* change controls depending on cafe rod selection */
/* ----------------------------------------------- */
function checkCafeRodsControls(cafe_rod) {
  var options_arr=new Array();

  // general controls
  options_arr[0]= new Array("White Chain on Right", "Right");
  options_arr[1]= new Array("White Chain on Left", "Left");
  options_arr[2]= new Array("Metal Chain on Right", "Right Metal");
  options_arr[3]= new Array("Metal Chain on Left", "Left Metal");

  if(cafe_rod) { // control options for scallops with cafe rod
    var custom_width=parseInt(document.form_calcblackoutmm.custom_width.value);
    if ($('top_cassette').value != 0) {
      if (custom_width >= 500) options_arr[4]= new Array("Spring","Spring");
    }
    else {
    if (custom_width >= 470) options_arr[4]= new Array("Spring", "Spring");
  }
  }
  else { // controls for no cafe rods
    //options_arr[4] = new Array("Spring Clear Ball", "Clear Ball");
    options_arr[4] = new Array("Spring Bullet Nickel", "Bullet Nickel");
    options_arr[5] = new Array("Spring Bullet Brass", "Bullet Brass");
    options_arr[6] = new Array("Spring Bullet Black", "Bullet Black");
//    options_arr[7] = new Array("Spring Cylinder Pine", "Cylinder Pine");
//    options_arr[7] = new Array("Spring Cylinder Walnut", "Cylinder Walnut");
    options_arr[7]= new Array("Spring Cylinder Brushed Steel", "Brushed Steel");
    options_arr[8]= new Array("Spring Ball Jute", "Ball Jute");
  }

  //delete current options
  var controls_select = document.form_calcblackoutmm.controls;
  var current_selected = controls_select.options.selectedIndex;
  controls_select.options.length=0;
  selected_text = true;
  for(i=0; i<options_arr.length; i++)
  {
    controls_select.options[i]=new Option(options_arr[i][0], options_arr[i][1], selected_text, false)
    selected_text = false;
  }
  if (controls_select.options.length-1 >= current_selected) controls_select.options[current_selected].selected = true;
}

function changeControls(cafe_rod) {
  checkCafeRodsControls(cafe_rod);
  skip_recheck_cafe_rods = true;
  GetCustomPrice();
  skip_recheck_cafe_rods = false;
}
/* ----------------------------------------------- */

function VerifyBlackoutMMForm(form)
{
  if(form.price.value<=0)
  {
    alert('Please insert width and drop first and click the button "Calculate Price"');
    return false;
  }
  return true;
}

function SelectProdType(prodtype)
{
    window.location = prodtype;
}

function onChangeCloth(){
  if (document.form_calcblackoutmm.recess.value == "Cloth"){
    alert("Please note that the end brackets will add to the cloth size 35mm - 50mm and may not fit inside recess.");
  }
}

function SelNextday(source_value, destination) {
  if(source_value == 0) // no nextday
    destination.selectedIndex = 1; // select standard
  else
    destination.selectedIndex = 0; // select nextday
//    destination.selectedIndex = 1; // for bank holiday
}

function check_sizes_interval() {

  var custom_width=parseInt(document.form_calcblackoutmm.custom_width.value);
  var custom_drop=parseInt(document.form_calcblackoutmm.custom_drop.value);
  var controls_value = document.form_calcblackoutmm.controls.value;
  var min_cassette_width = 0;
  if (controls_value == 'Right' || controls_value == 'Left' || controls_value == 'Right Metal' || controls_value == 'Left Metal') min_cassette_width = 300;
  else min_cassette_width = 500;

  var return_var = true;

  if (custom_width < min_cassette_width || custom_width > 2200) return_var = false;
  if (custom_drop < 200 || custom_drop > 2000) return_var = false;
  if (custom_width >= 2000 && custom_drop >= 2000) return_var = false;
  if (custom_width >= 1500 && custom_drop >= 2000) return_var = false;
  if (return_var == false) {
    alert("Sorry but cassette is only available in the following combinations:\nwidth between " + min_cassette_width + " and 2200 and drop between 300 and 2000");
    return false;
  }
  return true;
}

function GetCassettePrice(selected_cassette, custom_width, custom_drop)
{
  var m_cass_price = 0;
  new Ajax.Request('http://www.blindsuk.net/inc/roller_scallops.php',{
    method:'post',
    asynchronous:false,
    parameters:{action: 'get_cassette_price', cassette_type: selected_cassette, type: 'blackout', controls: document.form_calcblackoutmm.controls.value, width: parseInt(document.form_calcblackoutmm.custom_width.value), drop: parseInt(document.form_calcblackoutmm.custom_drop.value)},
    onComplete:function(transport)
    {
      var my_resp = transport.responseText.evalJSON();
      if (my_resp.status == 'failed') {
        alert (my_resp.msg);
        return 0;
      }
      else {
        m_cass_price = my_resp.data.price;
      }
    }
  });
  return m_cass_price;
}
