function selectTop(id,clear){
    //alert("selectTop");
    top_id= id; //сохраняем выбранное   
    cl = clear;
    if(top_id > 0){
        wait1('test');
        makeRequest("b_id="+top_id+"&clear="+cl);
        
        var pic1= document.getElementById('pic1');
        var pic2= document.getElementById('pic2');
        var pic3= document.getElementById('pic3');
        pic1.className='notselected';
        pic2.className='notselected';
        pic3.className='notselected';
        eval("var select_obj= document.pic"+top_id);
        
        select_obj.className='selected';
    }
    else
        clearArea('test');
}

function makeRequest(params){
    //alert("makeRequest");
    var newScript= document.createElement('script');    
    newScript.src= "http://www.cvetlit.ru/request.php?"+params;
    //alert("newScript.src="+newScript.src);
    newScript.type= "text/javascript";
    //alert("before document.body.appendChild(newScript);");
    document.body.appendChild(newScript);
    //alert("after document.body.appendChild(newScript);");
}

function clearArea(name){
        var test_obj= document.getElementById(name);
        if (test_obj!=null)
        test_obj.innerHTML = '';
    }

function wait1(name){
        var test_obj= document.getElementById(name);
        test_obj.innerHTML = '<center><h2>Подождите...</h2></center>';
        test_obj.innerHTML += '<br /><center><img src="pic/hour.gif"></center>';
    }


function calc(id){
    //alert("Calc"+id);
      
    var D1 = document.getElementById(id+'D1');
    var L  = document.getElementById(id+'L');
    var d  = document.getElementById(id+'d');
    var mt = document.getElementById('mat'+id);
    
    var material  = (mt.options[mt.selectedIndex].text);
    
    //alert (material);
    var mt  = (mt.value);
    //alert (mt);
    listArray = mt.split("+");
    p   = parseFloat(listArray[0]);
    pr  = parseFloat(listArray[1]);
       
    D1 = parseFloat (D1.value);
    L  = parseFloat (L.value);
    d  = parseFloat (d.value);
    D  = 1;
    l  = 1;
    if (id==2){
      var D = document.getElementById('D');
      var l = document.getElementById('l');      
      D  = parseFloat (D.value);
      l  = parseFloat (l.value);
      //alert (D);
    }
    if (D1<=0 || isNaN(D1) || L<=0 || isNaN(L) || d<=0 || isNaN(d) || D<=0  || isNaN(D) || l<=0 || isNaN(l))
       alert ("Размер не может быть меньше 0");
    else{     

      if (id==1){
         var pr_obj= document.getElementById("pr1");
         massa = 0.785*((D1 / 100)*(D1 / 100)-(d / 100)*(d / 100))*L*0.01*p;
         cost=massa*pr;
      
      }else{
         var pr_obj= document.getElementById("pr2");      
         massa= 0.785*((D/100)*(D/100)-(d/100)*(d/100))*l*0.01*p+0.785*((D1/100)*(D1/100)-(d/100)*(d/100))*(L-l)*0.01*p;    
         cost=massa*pr;
      }
      
      pr_obj.innerHTML = "";
      
      pr_obj.innerHTML += "<input type='hidden' name='material"+id+"' value='"+material+"' />";
            
      pr_obj.innerHTML += "<h5>Результаты расчета</h5>";      
      if (massa<=0){
         pr_obj.innerHTML += "<label><strong></strong>Вы ввели не корректные данные</label>";
      }else{
         pr_obj.innerHTML += "<label><strong>Масса изделия, кг.:</strong>"+massa+"</label>";
         pr_obj.innerHTML += "<label><strong>Стоимость, руб.:</strong>"+cost+"</label>";  
      }
    }

}