function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showLines(objnum, namepart)
{
  obj0 = "line0";
  obj1 = "line1";
  obj2 = "line2";
  obj3 = "line3";
  obj4 = "line4";
  obj5 = "line5";

VariantIspolnenie = namepart;
    
if (objnum == 0)
{
  document.getElementById(obj0).style.display = 'block';
  document.getElementById(obj1).style.display = 'none';
  document.getElementById(obj2).style.display = 'none';
  document.getElementById(obj3).style.display = 'none';
  document.getElementById(obj4).style.display = 'none';
  document.getElementById(obj5).style.display = 'none';
}
else if (objnum == 1)
{
  document.getElementById(obj0).style.display = 'none';
  document.getElementById(obj1).style.display = 'block';
  document.getElementById(obj2).style.display = 'none';
  document.getElementById(obj3).style.display = 'none';
  document.getElementById(obj4).style.display = 'none';
  document.getElementById(obj5).style.display = 'none';
}
else if (objnum == 2)
{
  document.getElementById(obj0).style.display = 'none';
  document.getElementById(obj1).style.display = 'block';
  document.getElementById(obj2).style.display = 'block';
  document.getElementById(obj3).style.display = 'none';
  document.getElementById(obj4).style.display = 'none';
  document.getElementById(obj5).style.display = 'none';
}
else if (objnum == 3)
{
  document.getElementById(obj0).style.display = 'none';
  document.getElementById(obj1).style.display = 'block';
  document.getElementById(obj2).style.display = 'block';
  document.getElementById(obj3).style.display = 'block';
  document.getElementById(obj4).style.display = 'none';
  document.getElementById(obj5).style.display = 'none';
}
else if (objnum == 4)
{
  document.getElementById(obj0).style.display = 'none';
  document.getElementById(obj1).style.display = 'block';
  document.getElementById(obj2).style.display = 'block';
  document.getElementById(obj3).style.display = 'block';
  document.getElementById(obj4).style.display = 'block';
  document.getElementById(obj5).style.display = 'none';
}
else if (objnum == 5)
{
  document.getElementById(obj0).style.display = 'none';
  document.getElementById(obj1).style.display = 'block';
  document.getElementById(obj2).style.display = 'block';
  document.getElementById(obj3).style.display = 'block';
  document.getElementById(obj4).style.display = 'block';
  document.getElementById(obj5).style.display = 'block';
}
}

function showvars(im_type, data1, data2)
{
  var nvg = navigator.userAgent;
  if (nvg.indexOf("MSIE 6") != -1)
  {
     document.getElementById("isp_vars").style.top = (getBodyScrollTop() + 25) + 'px';
  }
  document.getElementById("data-pic").innerHTML = "";
  document.getElementById("flash-pic").innerHTML = "";
  //document.getElementById("img-pic").innerHTML = "";

  if (nvg.indexOf("MSIE 6") != -1)
  {
    document.getElementById("stk").className= 'stkvis';
  }
  else
  {
    document.getElementById("stk").style.width = '100%';
    document.getElementById("stk").style.height = '100%';
  }
  obj = "isp_vars";
  document.getElementById(obj).style.display = 'block';
  if (im_type == 0) // flash-block
  {
    obj = "flash-pic";
    flashTXT = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="615" height="453" id="main" align="middle">';
    flashTXT += '<param name="allowScriptAccess" value="sameDomain" />';
    flashTXT += '<param name="allowFullScreen" value="false" />';
    flashTXT += '<param name="movie" value="' + data1 + '" /><param name="quality" value="high" /><param name="wmode" value="opaque"/><param name="bgcolor" value="#ffffff" />';
    flashTXT += '<embed src="'+ data1 + '" quality="high" wmode="opaque" bgcolor="#ffffff" width="615" height="453" name="main" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" /></object>';
    document.getElementById(obj).innerHTML = flashTXT;
    document.getElementById(obj).style.display = 'block';
    obj = "img-pic";
    document.getElementById(obj).style.display = 'none';
    obj = "data-pic";
    document.getElementById(obj).style.display = 'none';
  }
  else
  if (im_type == 1) // picture block
  {
    obj = "flash-pic";
    document.getElementById(obj).style.display = 'none';
    obj = "data-pic";
    document.getElementById(obj).style.display = 'none';
    obj = "img-pic";
    document.getElementById("okno_variant_picture").src = data1;
    document.getElementById("tkani_h").innerHTML = "<h2>"+data2+"</h2>";
    document.getElementById(obj).style.display = 'block';
  }
  else
  if (im_type == 2) // "ткани" block
  {
    DrapCloser1 = true;
    DrapType = data2; // устанавливаем, какую ткань выбираем - основную или компаньон
    obj = "flash-pic";
    document.getElementById(obj).style.display = 'none';
    obj = "img-pic";
    document.getElementById(obj).style.display = 'none';
    
    ShownMainDrap = data1;
    if (ShownMainDrap == OldShownMainDrap)
    {
      document.getElementById("data-pic").innerHTML = TempMainDrapData;
    }
    else
    {
      OldShownMainDrap = data1;
      //ResetCompanions();
      TempMainDrapData = "";
      getDrapery(data1);
    }
    obj = "data-pic";
    document.getElementById(obj).style.display = 'block';
  }
  else
  if (im_type == 3) // "ткани-компаньоны" block
  {
    DrapType = data2; // устанавливаем, какую ткань выбираем - основную или компаньон
    obj = "flash-pic";
    document.getElementById(obj).style.display = 'none';
    obj = "img-pic";
    document.getElementById(obj).style.display = 'none';
    if (MainDrapCollectionID != -1)
    {
      AddDrapIndex = parseInt (data1, 10);
      DrapCloser2 = true;
      switch(data1)
      {
        case "1":
          {
          if (Temp1DrapData != "")
          {
            document.getElementById("data-pic").innerHTML = Temp1DrapData;
          }
            else
          {
            getAdditionalDrapery(data1);
            DrapName1 = MainDrapName;
          }
          }
          break;
        case "2":
          {
          if (Temp2DrapData != "")
          {
            document.getElementById("data-pic").innerHTML = Temp2DrapData;
          }
            else
          {
            getAdditionalDrapery(data1);
            DrapName2 = MainDrapName;
          }
          }
          break;
        case "3":
          {
          if (Temp3DrapData != "")
          {
            document.getElementById("data-pic").innerHTML = Temp3DrapData;
          }
            else
          {
            getAdditionalDrapery(data1);
            DrapName3 = MainDrapName;
          }
          }
          break;
        case "4":
          {
          if (Temp4DrapData != "")
          {
            document.getElementById("data-pic").innerHTML = Temp4DrapData;
          }
            else
          {
            getAdditionalDrapery(data1);
            DrapName4 = MainDrapName;
          }
          }
          break;
        case "5":
          {
          if (Temp5DrapData != "")
          {
            document.getElementById("data-pic").innerHTML = Temp5DrapData;
          }
            else
          {
            getAdditionalDrapery(data1);
            DrapName5 = MainDrapName;
          }
          }
      } 
    }
    else
    {
      document.getElementById("data-pic").innerHTML = "<div id=\"err_drap\">Для выбора материала-компаньона, пожалуйста, выберите сначала основной материал обивки<br/>" +
                                                      "(материал-компаньон и основной материал выбираются из одной коллекции)</div>";
                                                      
    }
    obj = "data-pic";
    document.getElementById(obj).style.display = 'block';
  }
  else
  if (im_type == 4) // "отделки" block
  {
    obj = "flash-pic";
    document.getElementById(obj).style.display = 'none';
    obj = "img-pic";
    document.getElementById(obj).style.display = 'none';
    getOtd(data1);
    obj = "data-pic";
    document.getElementById(obj).style.display = 'block';
  }
}


function getOtd(UId) {
    JsHttpRequest.query(
      '/ajax/otd.php',
      {
        'str': UId  
      },
      
      function(result, errors) {
        document.getElementById("data-pic").innerHTML = result["str"];
      }
    );
}

function getDrapery(UId) {
    JsHttpRequest.query(
      '/ajax/drapery.php',
      {
        'str': UId  
      },
      
      function(result, errors) {
        eval(result["code"]);
        document.getElementById("data-pic").innerHTML = result["str"];
        eval(result["scripts"]);
      }
    );
}

function getAdditionalDrapery(num) {
    JsHttpRequest.query(
      '/ajax/add_drap.php',
      {
        'str': MainDrapCollectionID,
        'cNum': num,
        'h_part': (MainDrapCollectionName + ' ('+MainDrapGroup+')'),
        'MName': MainDrapName
      },
      
      function(result, errors) {
        document.getElementById("data-pic").innerHTML = result["str"];
        switch(result["CompNum"])
        {
          case 1:
      	DrapID1 = result["id"];
      	DrapName1 = result["name"];
      	break;
    	    case 2:
      	DrapID2 = result["id"];
      	DrapName2 = result["name"];
      	break;
    	    case 3:
      	DrapID3 = result["id"];
      	DrapName3 = result["name"];
            break;
    	    case 4:
      	DrapID4 = result["id"];
      	DrapName4 = result["name"];
      	break;
          case 5:
      	DrapID5 = result["id"];
      	DrapName5 = result["name"];
        } 
      }
    );
}

function getDrapColors(UId) {
   JsHttpRequest.query(
      '/ajax/drapery2.php',
      {
        'str': UId  
      },
      
      function(result, errors) {
        document.getElementById("vSmallBlock").innerHTML = result["vSmall"];
        document.getElementById("choosen").innerHTML = "<span class='h2like'>Ваш выбор: </span>" + result["hName"];
        MainDrapName = result["first"];
      }
    ); 

}



function closevars()
{
  DrapCloser1 = false;
  DrapCloser2 = false;
  var nvg = navigator.userAgent;
  if (nvg.indexOf("MSIE 6") != -1)
  {
    document.getElementById("stk").className = 'stkunvis';
  }
  else
  {
    document.getElementById("stk").style.width = '0';
    document.getElementById("stk").style.height = '0';
  }
  obj = "isp_vars";
  document.getElementById(obj).style.display = 'none';
}

function closebtn()
{
  if ((!DrapCloser1) && (!DrapCloser2))
    closevars();
  else
  if (DrapCloser1)
  {
    SetMainDrapery();
  }
  else
  if  (DrapCloser2)
  {
    SetAddDrapery(AddDrapIndex);
  }
}

function smallpicright(fullCount, CurrNum)
{
  if (CurrNum < (fullCount - 3))
  {
    SmallPicLBorder++;
    document.getElementById("small1").className='small-img';
    document.getElementById("small2").className='small-img';
    document.getElementById("small3").className='small-img';
    document.getElementById("sPic1").src =  MPics[SmallPicLBorder];
    document.getElementById("sPic2").src =  MPics[SmallPicLBorder+1];
    document.getElementById("sPic3").src =  MPics[SmallPicLBorder+2];
    return(false);
  }
}

function smallpicleft(fullCount, CurrNum)
{
  if (CurrNum > 0)
  {
    SmallPicLBorder--;
    document.getElementById("small1").className='small-img';
    document.getElementById("small2").className='small-img';
    document.getElementById("small3").className='small-img';
    document.getElementById("sPic1").src =  MPics[SmallPicLBorder];
    document.getElementById("sPic2").src =  MPics[SmallPicLBorder+1];
    document.getElementById("sPic3").src =  MPics[SmallPicLBorder+2];
    return(false);
  }
}

function bigPic(posNum)
{
  document.getElementById("BigEstoreImg").src = MPics[posNum+SmallPicLBorder];
  if (posNum==0)
  {
    document.getElementById("small1").className='small-img-act';
    document.getElementById("small2").className='small-img';
    document.getElementById("small3").className='small-img';
  }
  else
  if (posNum==1)
  {
    document.getElementById("small2").className='small-img-act';
    document.getElementById("small1").className='small-img';
    document.getElementById("small3").className='small-img';
  }
  else
  if (posNum==2)
  {
    document.getElementById("small3").className='small-img-act';
    document.getElementById("small1").className='small-img';
    document.getElementById("small2").className='small-img';
  }
  return(false);
}

function ShowDrap(posNum)
{
  document.getElementById("tkaniBigImg").src = DrapPaths[posNum-1+curDrap];
  MainDrapCollectionID = DrapIDs[posNum-1+curDrap];
  document.getElementById("head_h").innerHTML = "<h2>"+GroupName+"<br/>"+DrapNames[posNum-1+curDrap]+" (" + Textures[posNum-1+curDrap] + ")</h2>";
  MainDrapGroup = Textures[posNum-1+curDrap];
  MainDrapCollectionName = DrapNames[posNum-1+curDrap];

  getDrapColors(DrapIDs[posNum-1+curDrap]);
  
  if (posNum==1)
  {
    document.getElementById("tkan1").className='small-tkan-act';
    document.getElementById("tkan2").className='small-tkan';
    document.getElementById("tkan3").className='small-tkan';
    document.getElementById("tkan4").className='small-tkan';
    document.getElementById("tkan5").className='small-tkan';
  }
  else
  if (posNum==2)
  {
    document.getElementById("tkan2").className='small-tkan-act';
    document.getElementById("tkan1").className='small-tkan';
    document.getElementById("tkan3").className='small-tkan';
    document.getElementById("tkan4").className='small-tkan';
    document.getElementById("tkan5").className='small-tkan';
  }
  else
  if (posNum==3)
  {
    document.getElementById("tkan3").className='small-tkan-act';
    document.getElementById("tkan1").className='small-tkan';
    document.getElementById("tkan2").className='small-tkan';
    document.getElementById("tkan4").className='small-tkan';
    document.getElementById("tkan5").className='small-tkan';
  }
  else
  if (posNum==4)
  {
    document.getElementById("tkan4").className='small-tkan-act';
    document.getElementById("tkan1").className='small-tkan';
    document.getElementById("tkan2").className='small-tkan';
    document.getElementById("tkan3").className='small-tkan';
    document.getElementById("tkan5").className='small-tkan';
  }
  else
  if (posNum==5)
  {
    document.getElementById("tkan5").className='small-tkan-act';
    document.getElementById("tkan1").className='small-tkan';
    document.getElementById("tkan2").className='small-tkan';
    document.getElementById("tkan3").className='small-tkan';
    document.getElementById("tkan4").className='small-tkan';
  }
}

function drapsmallpicright(fullCount, CurrNum)
{
  if (CurrNum < (fullCount - 5))
  {
    curDrap++;
    document.getElementById("tkan1").className='small-tkan';
    document.getElementById("tkan2").className='small-tkan';
    document.getElementById("tkan3").className='small-tkan';
    document.getElementById("tkan4").className='small-tkan';
    document.getElementById("tkan5").className='small-tkan';

    document.getElementById("tkan1").src =  DrapPaths[curDrap];
    document.getElementById("tkan2").src =  DrapPaths[curDrap+1];
    document.getElementById("tkan3").src =  DrapPaths[curDrap+2];
    document.getElementById("tkan4").src =  DrapPaths[curDrap+3];
    document.getElementById("tkan5").src =  DrapPaths[curDrap+4];

    document.getElementById("tk-label1").innerHTML =  DrapNames[curDrap];
    document.getElementById("tk-label2").innerHTML =  DrapNames[curDrap+1];
    document.getElementById("tk-label3").innerHTML =  DrapNames[curDrap+2];
    document.getElementById("tk-label4").innerHTML =  DrapNames[curDrap+3];
    document.getElementById("tk-label5").innerHTML =  DrapNames[curDrap+4];

    return(false);
  }
}

function drapsmallpicleft(fullCount, CurrNum)
{
  if (CurrNum > 0)
  {
    curDrap--;
    
    document.getElementById("tkan1").className='small-tkan';
    document.getElementById("tkan2").className='small-tkan';
    document.getElementById("tkan3").className='small-tkan';
    document.getElementById("tkan4").className='small-tkan';
    document.getElementById("tkan5").className='small-tkan';

    document.getElementById("tkan1").src =  DrapPaths[curDrap];
    document.getElementById("tkan2").src =  DrapPaths[curDrap+1];
    document.getElementById("tkan3").src =  DrapPaths[curDrap+2];
    document.getElementById("tkan4").src =  DrapPaths[curDrap+3];
    document.getElementById("tkan5").src =  DrapPaths[curDrap+4];

    document.getElementById("tk-label1").innerHTML =  DrapNames[curDrap];
    document.getElementById("tk-label2").innerHTML =  DrapNames[curDrap+1];
    document.getElementById("tk-label3").innerHTML =  DrapNames[curDrap+2];
    document.getElementById("tk-label4").innerHTML =  DrapNames[curDrap+3];
    document.getElementById("tk-label5").innerHTML =  DrapNames[curDrap+4];

    return(false);
  }
}

function drappicright(fullCount, CurrNum, CurrNum2)
{
  if ((CurrNum2 < 5) && (CurrNum2 < fullCount))
  {
    CurrNum2++;
    
    document.getElementById("tkan1").className='small-tkan';
    document.getElementById("tkan2").className='small-tkan';
    document.getElementById("tkan3").className='small-tkan';
    document.getElementById("tkan4").className='small-tkan';
    document.getElementById("tkan5").className='small-tkan';
    document.getElementById("tkan"+CurrNum2).className='small-tkan-act';
  }
  else
  if (CurrNum2 == 5)
    
  return(false);
}

function drappicleft(fullCount, CurrNum, CurrNum2)
{
  if (CurrNum > 0)
  {
    curDrap--;
    
    document.getElementById("tkan1").className='small-tkan';
    document.getElementById("tkan2").className='small-tkan';
    document.getElementById("tkan3").className='small-tkan';
    document.getElementById("tkan4").className='small-tkan';
    document.getElementById("tkan5").className='small-tkan';

    document.getElementById("tkan1").src =  DrapPaths[curDrap];
    document.getElementById("tkan2").src =  DrapPaths[curDrap+1];
    document.getElementById("tkan3").src =  DrapPaths[curDrap+2];
    document.getElementById("tkan4").src =  DrapPaths[curDrap+3];
    document.getElementById("tkan5").src =  DrapPaths[curDrap+4];

    document.getElementById("tk-label1").innerHTML =  DrapNames[curDrap];
    document.getElementById("tk-label2").innerHTML =  DrapNames[curDrap+1];
    document.getElementById("tk-label3").innerHTML =  DrapNames[curDrap+2];
    document.getElementById("tk-label4").innerHTML =  DrapNames[curDrap+3];
    document.getElementById("tk-label5").innerHTML =  DrapNames[curDrap+4];

    return(false);
  }
}

function FromSmallDrap(name, path, id)
{
  document.getElementById("tkaniBigImg").src = path;
  document.getElementById("choosen").innerHTML = "<span class='h2like'>Ваш выбор: </span>"+name;
  MainDrapName = name;
}

function AddFromSmallDrap(name, path, id, CompNum)
{
  document.getElementById("tkaniBigImg").src = path;
  document.getElementById("choosen").innerHTML = "<span class='h2like'>Ваш выбор: </span>"+name;
  switch(CompNum)
  {
    case 1:
      DrapID1 = id;
      DrapName1 = name;
      break;
    case 2:
      DrapID2 = id;
      DrapName2 = name;
      break;
    case 3:
      DrapID3 = id;
      DrapName3 = name;
      break;
    case 4:
      DrapID4 = id;
      DrapName4 = name;
      break;
    case 5:
      DrapID5 = id;
      DrapName5 = name;
  }
  return(false);
}


function getRadio(RadioGrObj)
{
  for (var i=0; i < RadioGrObj.length; i++)
  {
     if (RadioGrObj[i].checked) return RadioGrObj[i].value;
  }
  return null;
}

function UpdateGood(section)
{
  try {
    MainDrapCategory = getRadio(document.TovarForm.DrapCategory);
  } catch(a) {
    MainDrapCategory = "";
  }
  try {
    TransformType = getRadio(document.TovarForm.transftype);
  } catch(b) {
    TransformType = "";
  }
  
  try {
    OtdType = getRadio(document.TovarForm.otdelka);
  } catch(c) {
    OtdType = ""; 
  }
  
  if ((MainDrapCategory != OldMainDrapCategory) || (TransformType != OldTransformType) || (OtdType != OldOtdType))
  {
    OldMainDrapCategory = MainDrapCategory;
    OldTransformType = TransformType;
    OldOtdType = OtdType;
    
    JsHttpRequest.query(
      '/ajax/updateinfo.php',
      {
        'ModelSection': section,
        'drap': MainDrapCategory,
        'transf': TransformType,
        'otdel': OtdType
      },
      
      function(result, errors) {
        document.getElementById("ResPrice").innerHTML = '&nbsp;' + result["NewPrice"] + ' руб.';
        if (document.getElementById('pr-place1-value').style.display != 'none')
           document.getElementById('pr-place1-value').innerHTML = result["NewGabarit1"];
        if (document.getElementById('pr-place2-value').style.display != 'none')
           document.getElementById('pr-place2-value').innerHTML = result["NewGabarit2"];
      }
    ); 
  }  
}

function SetMainDrapery()
{
  TempMainDrapData = document.getElementById("data-pic").innerHTML;
  if ((OldMainDrapCollectionID != -1) && (MainDrapCollectionID != OldMainDrapCollectionID))
  {
    if ((DrapID1 != -1) || (DrapID2 != -1) || (DrapID3 != -1) || (DrapID4 != -1) || (DrapID5 != -1))
    {
      document.getElementById("data-pic").innerHTML = "<div id=\"mes_drap\">Основной материал обивки выбран из коллекции, отличной от прежнего выбора.<br/>" +
                                                      "Мы рекомендуем сочетать в обивке мебели материалы одной коллекции.<br/>" +
                                                      "Перед добавлением товара в корзину, пожалуйста, повторите выбор материалов-компаньонов</div>";
      ResetCompanions();
    }
  }
  else
  closevars();
  OldMainDrapCollectionID = MainDrapCollectionID;
  return(false);
}

function SetAddDrapery(index)
{
  switch(index)
  {
    case 1:
      Temp1DrapData = document.getElementById("data-pic").innerHTML;
      //DrapName1 = 
      break;
    case 2:
      Temp2DrapData = document.getElementById("data-pic").innerHTML;
      break;
    case 3:
      Temp3DrapData = document.getElementById("data-pic").innerHTML;
      break;
    case 4:
      Temp4DrapData = document.getElementById("data-pic").innerHTML;
      break;
    case 5:
      Temp5DrapData = document.getElementById("data-pic").innerHTML;
  }
  closevars();
  return(false);
}

function ResetCompanions()
{
 DrapID1 = -1;
 DrapName1 = "-";
 DrapID2 = -1;
 DrapName2 = "-";
 DrapID3 = -1;
 DrapName3 = "-";
 DrapID4 = -1;
 DrapName4 = "-";
 DrapID5 = -1;
 DrapName5 = "-";
 
 Temp1DrapData = "";
 Temp2DrapData = "";
 Temp3DrapData = "";
 Temp4DrapData = "";
 Temp5DrapData = "";

 ShownDrap1 = -1;
 OldShownDrap1 = -1;
 ShownDrap2 = -1;
 OldShownDrap2 = -1;
 ShownDrap3 = -1;
 OldShownDrap3 = -1;
 ShownDrap4 = -1;
 OldShownDrap4 = -1;
 ShownDrap5 = -1;
 OldShownDrap5 = -1;
}

// =================================== movers ============================================
function Rmover()
{
  if (lft < 0)
  {
    lft = lft + 20;
    document.getElementById("move").style.left = lft + "px";
  }
  TimeId = setInterval(fnR, 100);
}

function stopRmover()
{
  clearInterval(TimeId);
}

function fnR()
{
  if (lft < 0)
  {
    lft = lft + 20;
    document.getElementById("move").style.left = lft + "px";
  }
}


function fnL()
{
  if ((MovWid + lft) > 796)
  {
    lft = lft - 20;
    document.getElementById("move").style.left = lft + "px";
  }
}

function Lmover()
{
  if ((MovWid + lft) > 796)
  {
    lft = lft - 20;
    document.getElementById("move").style.left = lft + "px";
  }
  TimeId2 = setInterval(fnL, 70);
}

function stopLmover()
{
  clearInterval(TimeId2);
}

// =================================== movers ============================================

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function AddToBasket()
{
  document.getElementById("data-pic").innerHTML = "";
  document.getElementById("flash-pic").innerHTML = "";

  var nvg = navigator.userAgent;
  if (nvg.indexOf("MSIE 6") != -1)
  {
    document.getElementById("stk").className= 'stkvis';
  }
  else
  {
    document.getElementById("stk").style.width = '100%';
    document.getElementById("stk").style.height = '100%';
  }

  obj = "isp_vars";
  document.getElementById(obj).style.display = 'block';

  try {
    DrapCount = getRadio(document.TovarForm.variantIspoln);
  } catch(a) {
    DrapCount = 0;
  }

  try {
    DrapCatg = getRadio(document.TovarForm.DrapCategory);
  } catch(b) {
    DrapCatg = 'no';
  }

  try {
    TrType = getRadio(document.TovarForm.transftype);
  } catch(c) {
    TrType = 'no';
  }

  try {
    OtdTp = getRadio(document.TovarForm.otdelka);
  } catch(d) {
    OtdTp = 'no';
  }
 
  var Err0 = "";
  var Err1 = "";
  var Err2 = "";
  var Err3 = "";
  var Err4 = "";
  var Err5 = "";
  
  if ((DrapCount > 1) && (DrapName1 == '--'))
  {
    Err1 = "- выберите второй обивочный материал<br/>";
  }
  if ((DrapCount > 2) && (DrapName2 == '--'))
  {
    Err2 = "- выберите третий обивочный материал<br/>";
  }
  if ((DrapCount > 3) && (DrapName3 == '--'))
  {
    Err3 = "- выберите четвертый обивочный материал<br/>";
  }
  if ((DrapCount > 4) && (DrapName4 == '--'))
  {
    Err4 = "- выберите пятый обивочный материал<br/>";
  }
  if ((DrapCount > 5) && (DrapName5 == '--'))
  {
    Err5 = "- выберите шестой обивочный материал<br/>";
  }
  if ((DrapCatg != 'no') && (MainDrapName == "-"))
  {
    Err0 = "- выберите основной материал обивки<br/>";
  }
  
  if ((Err0 != "") || (Err1 != "") || (Err2 != "") || (Err3 != "") || (Err4 != "") || (Err5 != ""))
  {
    
    obj = "flash-pic";
    document.getElementById(obj).style.display = 'none';
    obj = "img-pic";
    document.getElementById(obj).style.display = 'none';
    
    document.getElementById("data-pic").innerHTML = "<div class=\"errbask\">Не все требуемые характеристики товара указаны.<br/>" +
                                                      "Перед добавлением в корзину, пожалуйста:<br/><br/>" +
                                                      "<div class=\"errtypes\">" + Err0 + Err1 + Err2 + Err3 + Err4 + Err5 + "</div></div>";
                                                      
    obj = "data-pic";
    document.getElementById(obj).style.display = 'block';
    return(false);
  }

  UID++;
  
  JsHttpRequest.query(
      '/ajax/basket.php',
      {
        'MainDrapName': MainDrapName,
        'UID': UID,
        'sectID': SectionID,
        'transform': TrType,
        'drapcateg': DrapCatg,
        'otdelka': OtdTp,
        'usevarispoln': DrapCount,
        'ispvariant': VariantIspolnenie,
        'add1': DrapName1,
        'add2': DrapName2,
        'add3': DrapName3,
        'add4': DrapName4,
        'add5': DrapName5,
        'comment': document.TovarForm.comments.value
      },
      
      function(result, errors) {
        obj = "flash-pic";
        document.getElementById(obj).style.display = 'none';
        obj = "img-pic";
        document.getElementById(obj).style.display = 'none';
    
        if (result["resultMessage"] == "ok")
        {
          document.getElementById("data-pic").innerHTML = "<div class=\"errbaskgray\">Товар с выбранными характеристиками<br/>добавлен в корзину.<br/>" +
                                                      "Вы можете продолжить просмотр каталога товаров<br/>или перейти к <a title=\"в корзину\" href=\"/personal/cart/\">корзине</a> для оформления заказа.<br/><br/>"+
                                                      "Различных позиций в <a title=\"в корзину\" href=\"/personal/cart/\">корзине</a> - "+result["positions"]+",<br/>всего товаров - " + result["count"] + "</div>";
          document.getElementById("cart_href").innerHTML = '<a class="bask-href" href="/personal/cart/">Корзина (' + result["positions"] + ')</a>';
        }
        else
          document.getElementById("data-pic").innerHTML = "<div class=\"errbask\">Извините, добавить товар в корзину не удалось.<br/>" +
                                                      "Пожалуйста, попробуйте повторить операцию позже.;</div>";
        obj = "data-pic";
        document.getElementById(obj).style.display = 'block';
      }
  );
  return(false);  
}

function setListsDisabled()
{
  document.getElementById("collList").disabled = true;
  document.getElementById("subjList").disabled = true;
}

function setListsEnabled()
{
  document.getElementById("collList").disabled = false;
  document.getElementById("subjList").disabled = false;
}

function updateFilterForm()
{
  WhatToSelect = getRadio(document.filter.specradio);
  document.filter.selectGroup.value = WhatToSelect;
  if (WhatToSelect == "all")
  {
     document.filter.subjectSelect.value = document.filter.subjList.value; 
     document.filter.collectionSelect.value = document.filter.collList.value;
  }
  else
  {
     document.filter.subjectSelect.value = "-"; 
     document.filter.collectionSelect.value = "-";
  }
  return(true);
}

function setFilterForm(DValue)
{
  document.filter.selectGroup.value = "all";
  document.filter.subjectSelect.value = DValue; 
  document.filter.collectionSelect.value = "all";
}

function setDrapFilterForm(DValue)
{
  document.drapfilter.category.value = DValue;
  document.drapfilter.categorylist.value = "all"; 
  document.drapfilter.type.value = "all";
  document.drapfilter.color.value = "all";
  document.drapfilter.collection.value = "all";
}

function updateDrapFilterForm()
{
  document.drapfilter.category.value = document.drapfilter.categorylist.value; 
  return(true);
}

function checkDealers()
{
  if ((document.dealer.org.value == "") || (document.dealer.region.value == "") || (document.dealer.address.value == "")
   || (document.dealer.phone.value == "") || (document.dealer.email.value == "") || (document.dealer.fio.value == "")
   || (document.dealer.sq.value == "") || (document.dealer.prices.value == ""))
  {
    document.getElementById("infodiv").innerHTML = '<div class="send-head"><span class="red">*</span>- Поля, обязательные для заполнения</div>'+
	 '<b>Внимание: </b><span class="red">не все обязательные поля заполнены.<br/>Пожалуйста, заполните все поля, отмеченные знаком <*></span>';      
    return(false);
  }
  else
  return(true);
}

function checkContacts()
{
  if ((document.contactform.fio.value == "") || (document.contactform.phone.value == "") || (document.contactform.email.value == "")
   || (document.contactform.message.value == ""))
  {
    document.getElementById("infodiv").innerHTML = '<div class="conthead2"><span class="red">*</span> - поля, обязательные для заполнения'+
	 '<br/><b>Внимание: </b><span class="red">не все обязательные поля заполнены.<br/>Пожалуйста, заполните все поля, отмеченные знаком <*></span></div>&nbsp;<br/>&nbsp;<br/>&nbsp;';      
    return(false);
  }
  else
  return(true);
}

function delayBasketGood(id)
{
  var nm = 'DELAY_' + id;
  document.forms['mainbasketform'].elements[nm].checked = true;
}

function undelayBasketGood(id)
{
  var nm = 'DELAY_' + id;
  document.forms['mainbasketform'].elements[nm].checked = false;
}

function deleteBasketGood(id)
{
  var nm = 'DELETE_' + id;
  document.forms['mainbasketform'].elements[nm].checked = true;
}

function setquantity(id)
{
  var fromvalue = 'VISIBLEQUANTITY_' + id;
  var tovalue = 'QUANTITY_' + id;
  document.forms['mainbasketform'].elements[tovalue].value = document.forms['mainbasketform'].elements[fromvalue].value;
}

function showbigdrap(id)
{
  isDrap = 1;
  document.getElementById("stk").style.width = '100%';
  index = id;
  document.getElementById("drap-nav-line").innerHTML = (id+1)+'&nbsp;/&nbsp;'+ IDsArray.length;
  JsHttpRequest.query(
      '/ajax/drapcatalog.php',
      {
        'id': IDsArray[id]
      },
      
      function(result, errors) {
        //alert(result["DName"] + " " + result["DCategory"] + " " + result["DCollection"] + " " + result["DFacture"] + " " + result["DPath"] + " " + result["DColor"]);
        
        document.getElementById("big-descr").innerHTML = result["DCategory"] + "<br/>" + result["DFacture"] + "<br/>" + "Коллекция: " + result["DCollection"] +
          "<br/>" + result["DName"] + "<br/>" + "Цвет: " + result["DColor"];
        document.getElementById("big-pos").innerHTML = '<img class="imgInText big-drap-img" src="/drapery/'+result["DPath"]+'" alt="">';  
        var nvg = navigator.userAgent;
        if (nvg.indexOf("MSIE 6") != -1)
        {
          document.getElementById("big_vars").style.top = (getBodyScrollTop() + 25) + 'px';
        }
        
        //document.getElementById("flash-pic").innerHTML = "";
  
        if (nvg.indexOf("MSIE 6") != -1)
        {
          document.getElementById("stk").className= 'stkvis';
          document.getElementById("collection").style.display = 'none';
          document.getElementById("color").style.display = 'none';
          document.getElementById("type").style.display = 'none';
          document.getElementById("categorylist").style.display = 'none';
        }
        else
        {
          document.getElementById("stk").style.width = '100%';
          document.getElementById("stk").style.height = '100%';
        }
        if (document.getElementById("big_vars").style.display != 'block')
          document.getElementById("big_vars").style.display = 'block';
      }
    );
}

function bigclosebtn()
{
  var nvg = navigator.userAgent;
  if (nvg.indexOf("MSIE 6") != -1)
  {
    if (isDrap == 1)
    {
        document.getElementById("collection").style.display = 'block';
        document.getElementById("color").style.display = 'block';
        document.getElementById("type").style.display = 'block';
        document.getElementById("categorylist").style.display = 'block';
    }
    document.getElementById("stk").className = 'stkunvis';
  }
  else
  {
    document.getElementById("stk").style.width = '0';
    document.getElementById("stk").style.height = '0';
  }
  document.getElementById("big_vars").style.display = 'none';
} 

function prevbigdrap()
{
  if (index > 0)
    index--;
  else
    index = IDsArray.length - 1;
  if (isDrap == 1)  
    showbigdrap(index);
  else
  if (isDrap == 0)  
    showbigsale(index);  
}

function nextbigdrap()
{
  if (index < IDsArray.length - 1)
    index++;
  else
    index = 0;
  if (isDrap == 1)  
    showbigdrap(index);
  else
  if (isDrap == 0)  
    showbigsale(index);
}

function showbigsale(id)
{
  isDrap = 0;
  document.getElementById("stk").style.width = '100%';
  index = id;
  document.getElementById("drap-nav-line").innerHTML = (id+1)+'&nbsp;/&nbsp;'+ IDsArray.length;
  document.getElementById("drap-nav-line0").innerHTML = 'Посмотреть следующий предмет:';
    
  JsHttpRequest.query(
      '/ajax/salecatalog.php',
      {
        'id': IDsArray[id]
      },
      
      function(result, errors) {
        //alert(result["DName"] + " " + result["DCategory"] + " " + result["DCollection"] + " " + result["DFacture"] + " " + result["DPath"] + " " + result["DColor"]);
        
        document.getElementById("big-descr").innerHTML = "Модель: " + result["DName"] + "<br/>Старая цена: " + result["DOldPrice"] + "<br/>Новая цена: <b><span style='color:#bb262a;'>" + result["DNewPrice"] +
          "</span></b><br/>Комплектность: " + result["DCompl"];
        document.getElementById("big-pos").innerHTML = '<img class="imgInText big-drap-img" src="/sale-pictures/'+result["DPath"]+'" alt="">';  
        var nvg = navigator.userAgent;
        if (nvg.indexOf("MSIE 6") != -1)
        {
          document.getElementById("big_vars").style.top = (getBodyScrollTop() + 25) + 'px';
        }
        
        if (nvg.indexOf("MSIE 6") != -1)
        {
          document.getElementById("stk").className= 'stkvis';
        }
        else
        {
          document.getElementById("stk").style.width = '100%';
          document.getElementById("stk").style.height = '100%';
        }
        if (document.getElementById("big_vars").style.display != 'block')
          document.getElementById("big_vars").style.display = 'block';
      }
    );
}
