// JavaScript Document
// Требуется подключение:
// - sd/js/jquery/jquery.js
// - sd/js/core/sd_standart.js
// **************************************************
function body_resize()
{
body_width=document.body.clientWidth;/* Ширина контента */
body_height=document.body.clientHeight;/* Высота контента */
j_footer_down=$('#footer_down_m');
j_content=$('#content');
content_height=pti(j_content.height());
content_top=pti(j_content.css('top'));
if ((content_height+content_top)>pti(j_footer_down.css('top')))
{ j_footer_down.css('top',(content_height+content_top));
}
}
// **************************************************
/* jQuery */
$(document).ready(start_www);
// **************************************************
// старт страницы
function start_www()
{
$(window).bind('resize',body_resize);// назначить функцию для реагирование на изменение размера браузера
body_resize();// сделать полный ресайз
}
// фунция переключает галочку на регуляторе
function roller(_index)
{
$('#roller').html('<img src="images/roller'+_index+'.png" /></div>');
return;
}

// ********************************************
// Калькулятор окон
// цена окон за 1 к.м.
price_ok=new Array(2030,3150,3550,4300,3300,3870,4440,3010,3300,3870,3760,4230);
// цена подоконника за 1 к.м.
price_podok=new Array(220.07,256.75,296.05,365.74,410.28,481.01,543.89,628.78,713.66,762.39,811.12,811.12,811.12);
// цена отлива за 1 к.м.
price_w_outflow=new Array(147.41,166.80,205.23,217.98,243.65,269.33);
// цена доставки
price_dos=1400;
// цена установки 1 к.м. окна
price_ust=810;
var num_ok=0;
var dl=0;
var shr=0;
pictures=new Array()
for(i=0;i<12;i++)
{ pictures[i]=new Image();
  pictures[i].src='images/calc/window-'+(i+1)+'.gif';
}
// функция отвечает за изменения картинки окна
function l_image()
{ num_ok=document.form_calc.item.selectedIndex;
  document.getElementById('tool').src=pictures[num_ok].src;
}
function calc()
{ if (validate())
  { dl=document.getElementById('form_calc').w_height.value.replace(/,/,'.')/1000;
    shr=document.getElementById('form_calc').w_width.value.replace(/,/,'.')/1000;
    var price=dl*shr*price_ok[num_ok];//считаем длинна*ширина*кол-во м.
    if (document.getElementById('form_calc').w_service.checked) { price+=price_dos; }//прибавляем цену доставки
    if (document.getElementById('form_calc').w_install.checked) { price+=(price_ust*(dl*shr)); }// прибавляем цену установки
    price+=(price_podok[document.getElementById('form_calc').w_sill.value]*shr);//  прибавляем цену подокнника
    price+=(price_w_outflow[document.getElementById('form_calc').w_outflow.value]*shr);//  прибавляем цену отлива
    price=Math.round(price);
    document.getElementById('pr').innerHTML="<br><b>Цена окна:</b> "+price+" руб.";
  }
  else
    alert('Вы ввели некоректные данные!');
}
function validate()
{ if (document.getElementById('form_calc').w_height.value<=200||document.getElementById('form_calc').w_height.value=="")
  { document.getElementById('form_calc').w_height.focus();
    return 0;
  }
  if (document.getElementById('form_calc').w_width.value<=200||document.getElementById('form_calc').w_width.value=="")
  { document.getElementById('form_calc').w_height.focus();
    return 0;
  }
  if (!document.getElementById('form_calc').w_height.value.match(/^\d+([,\.]\d+)?$/)) 
  { document.getElementById('form_calc').w_height.focus();
    return 0;
  }
  if (!document.getElementById('form_calc').w_width.value.match(/^\d+([,\.]\d+)?$/))
  { document.getElementById('form_calc').w_height.focus();
    return 0;
  }
  return 1;
}

