var min_width = 995;
var max_width = 1172;
var tosearch_text = '';
var orderother_text = 'введите описание заказа';



//  IE6 background images blinking bug
var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand;
try{ if(!!m) { m("BackgroundImageCache", false, true) } } catch(oh){};
///////////////////////////////////////



if (window.attachEvent) { window.attachEvent('onload', mmwidth);  }  else { window.addEventListener('load', mmwidth, false);   }
if (window.attachEvent) { window.attachEvent('onresize', mmwidth);}  else { window.addEventListener('resize', mmwidth, false); }

function mmwidth() {    
  init_rootwidth();
                        
  var cw = get_clientwidth(); 
  var w = get_rootwidth(cw);  
  document.getElementById('header_root').style.width = w + "px";      
  document.getElementById('main_root').style.width = w + "px";        
  document.getElementById('footer_root').style.width = w + "px";      

  document.getElementById('header_measurer').style.width =  w + "px";  
  document.getElementById('main_measurer').style.width =  w + "px";  
  document.getElementById('footer_measurer').style.width =  w + "px";  

  var hw = 0;
  if (cw>w) hw = Math.floor((cw-w)/2);  
  document.getElementById('header_root').style.marginLeft   =  (cw - w - hw) + "px";      
  document.getElementById('header_root').style.marginRight  =  hw + "px";      
  document.getElementById('header_left_border').style.width =  hw + "px";  
  document.getElementById('footer_bg3').style.width =  hw + "px";  

  // Mozilla 1.0 bug
  var d = document.getElementById('main_style1');
  if (d.offsetTop < 264) d.style.visibility = 'hidden';
}

function init_rootwidth() {       
  document.getElementById('header_root').style.width = min_width + "px"; 
  document.getElementById('main_root').style.width = min_width + "px"; 
  document.getElementById('footer_root').style.width = min_width + "px"; 
  document.getElementById('header_left_border').style.width = "0px"; 
}

function get_clientwidth() {
  return (document.compatMode && document.compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth;
}

function get_rootwidth(cw) {
  var s = "";
  
  if (cw < min_width) { 
    s = min_width
  } else  { 
     if (cw > max_width)  { 
        s = max_width
     } else  { 
        s = cw 
     }
  }
  return s;
}

function tosearch_focus(t) {
  if (tosearch_text == '') tosearch_text = t.value;
  if (t.className == 'unactive') t.value = '';
  t.className = 'active';
}

function tosearch_blur(t) {
  if (t.value == '') { 
    t.value = tosearch_text;
    t.className = 'unactive';
  }
}

function check_tosearchform(t) {
  return (t.wrd.value != '' && t.wrd.className == 'active');
}

function submit_tosearchform() {
  var t = document.getElementById('tosearch_form');
  if (check_tosearchform(t)) t.submit();
  return false;
}

function showoptions() {
  var d = document.getElementById('options');

  if (d.style.display!='block') {
    d.style.display = 'block';
    d.style.visibility = 'visible';
  } else {
    d.style.display = 'none';
    d.style.visibility = 'hidden';
  }
  return false;
}
function changeoptions(t) {
  var d = document.getElementById('order_value');
  d.value = t.innerHTML;
  d.readOnly = true;
  d.className = 'unactive';
  showoptions();
  return false;
}
function changeoptions_other(t) {
  var d = document.getElementById('order_value');
  d.value = orderother_text;
  d.readOnly = '';
  d.className = 'unactive';
  showoptions();
  return false;
}

function orderother_focus(t) {
  if (t.readOnly) return;
  if (t.className == 'unactive') t.value = '';
  t.className = 'active';
}

function orderother_blur(t) {
  if (t.value == '') { 
    t.value = orderother_text;
    t.className = 'unactive';
  }
}
