$(document).ready(
	function() {

       right_width = (document.getElementById("right").offsetWidth)+"px";
       document.getElementById("logo_bottom").style.width = right_width;

       for(i=1; i<30; i++){
             td_height1 = (document.getElementById("td"+i+"_1").offsetHeight)+"px";
             if(td_height1){
               td_height2 = (document.getElementById("td"+i+"_2").offsetHeight)+"px";
               if(td_height1<=td_height2){ height = td_height2; }else{ height = td_height1;}
               document.getElementById("div"+i+"_1").style.height = height;
               document.getElementById("div"+i+"_2").style.height = height;
             }
       }

    }
);

function orangeMenuOver(name){
 $(name).addClass("selected2");
}
function orangeMenuOut(name){
 $(name).addClass("selected2");
}

function show(id){
       if($("#" + id).css("display") == "none"){
          $("#" + id).slideDown("slow");
       }
       else{
          $("#" + id).slideUp("slow");
       }
}

function span_change(id){

       var cl = $("span#" + id).attr("class");

       if(cl=='search_header'){
          $("span#" + id).attr("class",'search_header_selected');
       }
       else{
          $("span#" + id).attr("class",'search_header');
       }
}

function calculate(){
    show("filters");
    show("calculate");
    span_change("filters_link");
    span_change("calculate_link");
}

function calculate_result(){

    var S = $("input#S").attr("value");
    var h = $("input#h").attr("value");
    var q = $("select#q").attr("value");
    var comps = $("#comps").attr("value");
    var n_um = $("input#n_um").attr("value");
    var n_fiz = $("input#n_fiz").attr("value");

  if (!S || S=='0.0')
  {
    alert("Введите, пожалуйста, площадь помещения.");
    $("input#S").focus();
    return false;
  }
  if(S!=parseFloat(S)){
    alert("Площадь помещения должна быть целым числом.");
    $("input#S").focus();
    return false;
  }

  if (!h || h=='0.0')
  {
    alert("Введите, пожалуйста, высоту потолков.");
    $("input#h").focus();
    return false;
  }
  if(h!=parseFloat(h)){
    alert("Высота потолков должна быть целым числом.");
    $("input#h").focus();
    return false;
  }

  if (!comps)
  {
    alert("Введите, пожалуйста, число компьютеров");
    $("input#comps").focus();
    return false;
  }
  if(comps!=parseInt(comps)){
    alert("Число компьютеров должно быть целым числом.");
    $("input#comps").focus();
    return false;
  }

  if (!n_um)
  {
    alert("Введите, пожалуйста, количество работников умственного труда");
    $("input#n_um").focus();
    return false;
  }
  if(n_um!=parseInt(n_um)){
    alert("Количество работников умственного труда должно быть целым числом.");
    $("input#n_um").focus();
    return false;
  }

  if (!n_fiz)
  {
    alert("Введите, пожалуйста, количество работников физического труда");
    $("input#n_fiz").focus();
    return false;
  }
  if(n_fiz!=parseInt(n_fiz)){
    alert("Количество работников физического труда должно быть целым числом.");
    $("input#n_fiz").focus();
    return false;
  }

  $("div#result2").fadeIn("slow");
  $("div#result2 span").html("<img src='/images/loading.gif' width='16' height='16'>");

  $.get("/calculate.php?S=" + S +"&h="+h+"&comps="+comps+"&n_um="+n_um+"&n_fiz="+n_fiz+"&q="+q, function(result){
       $("div#result2 span").html(result);
       $("input#result").attr("value", result);
       $("input#search_models").attr("disabled",'');
  });

}


function change_val(id){

    $().load("/cookie_valuta.php?id="+id, function(){
       window.location.reload();
    });

}

function compare(tab,name){

   name1 = encodeURI(name);

   $.get("/add_compare.php?tab="+tab+"&name="+name1, function(answer){

     if(answer = parseInt(answer)){

        $("td#models").append('<div id="compare'+answer+'"><a href="/'+tab+'.htm" target="_blank">'+name+'</a> <span class="link" onclick="del('+answer+')">удалить</span></div>');

        if($("div#compare").css("display") == "none"){
            $("div#compare").slideDown("slow", function(){
            alert('Товар добавлен в блок сравнения.');
            });
        }
        else{
            alert('Товар добавлен в блок сравнения.');
        }

     }
     else{
        alert('Этот товар уже был добавлен в блок сравнения!');
     }

   });

}


function clear_compare(){
    $.get("/clear_compare.php", function(){
      $("div#compare").hide("slow");
      $("td#models").html('');
    });

}

function clear_compare2(){
    $.get("/clear_compare.php", function(){
       window.close();
    });
}


function del(i){
    $.get("/delete_cookie.php?i="+i, function(){
         $("div#compare"+i).css("display", "none");
    });
}

function del_compare(i){
    $.get("/delete_cookie.php?i="+i, function(){
       window.location.reload();
    });
}



