﻿var ei,ve;
var ea,va;
var el,vl;
var ef,vf;
var vd;
var art_id;
var lPoint;
var det_id;
var stl;
var sti;
var al;
var ai;
var artCallBackObject = new Object();
var cartWindow;

function CDCart()
{

  if (cartWindow != null)
    {
      if (!cartWindow.closed)
            cartWindow.focus(); 
      else
        cartWindow =  window.open('cart.aspx?cid=' + userID,null,'height=800,width=900,status=no,toolbar=no,menubar=no,location=no,scrollbars=no'); 
    }else
   cartWindow =  window.open('cart.aspx?cid=' + userID,null,'height=800,width=900,status=no,toolbar=no,menubar=no,location=no,scrollbars=no'); 
}




function AddBag(id)
{
    if (ebmeddedScript==true)
    {
      reloadForEmbed(id,1,false);
    }
    else
    {
        WaitShowCart(id);
        var priceId = "vk_" + id; 
        var price = $get(priceId).innerHTML;
        CentroDigitalNETVB.CDK.AddToCart(userID,id,price, BGnr,1,land,bNkw,loginDataObject,AddToBag_suc,ErrorHandler);
        MarkArt(id);
    }
}

function AddBagDet(id,count)
{
    if (ebmeddedScript==true)
    {
        reloadForEmbed(id,count,true);
    }
    else
    {
        var priceId = "vk_" + id; 
        var price = $get(priceId).innerHTML;
        WaitShowCart(id);
        CentroDigitalNETVB.CDK.AddToCart(userID,id,price, BGnr,count,land,bNkw,loginDataObject,AddToBag_suc,ErrorHandler);
        MarkDet(id);
    }
}

function reloadForEmbed(id,count,isDet)
{
    
    var tr = $get(id);
    var einspNr = tr.getAttribute("einsp_nr");
    var einspName = tr.getAttribute("einsp_name");
    var priceId = "vk_" + id; 
    var price = $get(priceId).innerHTML;
    var bez = "";
    var nr = "";
    var td = tr.getElementsByTagName("td");
    if (isDet==true)
    {
        bez = td[1].innerHTML ;
        if(document.all)
           nr = td[0].innerText;
        else
           nr = td[0].textContent ;
        MarkDet(id);
    }
    else
    {
        bez = td[1].innerHTML + td[2].innerHTML;
        nr = td[0].innerHTML;
        MarkArt(id);
    }
    
    
    var parameter = new Object();
    parameter.ArtNr = nr;
    parameter.Price = price;
    parameter.Description = bez;
    parameter.EinspName = einspName;
    parameter.EinspNr = einspNr;
    
    //alert(nr + "  "+ bez+ "  "+ price + "  "+ einspName + "  "+  einspNr );
    window.location = window.location + "?AdToShop="+ Math.random() + "#"+JSONstring.make(parameter)  ;
}




function  ShowCartError(id,message)
{
    document.getElementById('cartAddError_'+id).alt = message;
    document.getElementById('cartAddError_'+id).onmouseover = function() { Tip(message,ABOVE,true); };
    document.getElementById('cartAddError_'+id).onmouseout = function() { UnTip(); };
    document.getElementById('cartAddError_'+id).style.display="inline";
    document.getElementById('cartAddImg_'+id).style.display="none"; 
    document.getElementById('cartAddWait_'+id).style.display="none";
    document.getElementById('cartLoader_'+id).style.display="none";
}

function WaitShowCart(id)
{
    document.getElementById('cartAddImg_'+id).style.display="none"; 
    document.getElementById('cartAddWait_'+id).style.display="inline";
    document.getElementById('cartLoader_'+id).style.display="inline";
    document.getElementById('cartAddError_'+id).style.display="none";
}

function HideShowCart(id)
{
    document.getElementById('cartAddImg_'+id).style.display="inline";
    document.getElementById('cartAddWait_'+id).style.display="none";
    document.getElementById('cartLoader_'+id).style.display="none";
}

function showTooltip(e)
{
    (e.alt);
}


function RefreshCart()
{
if (cartWindow != null)
if (cartWindow.closed != true)
if (cartWindow.document)
if (cartWindow.document.getElementById('content')!= null)
  {
    cartWindow.location.reload(true);
  }
}

function SubBag(id)
{
 CentroDigitalNETVB.CDK.AddToCart(userID,id, BGnr,-1,land,bNkw,AddToBag_suc,ErrorHandler);
 MarkArt(id);
}

function AddToBag_suc(e)
{
  RefreshCart();
// if (e.id != null) 
// {
//  var obj;
// var id;
// id='AtB_'+e.orgArtId;
// obj = document.getElementById(id);
// if ( obj != null )
//  {
//   if (e.cnt>0)
//   {
//    obj.innerHTML = e.cnt;
//   }
//   else
//   {
//    obj.innerHTML = '';
//   }
//  }
// }
// 
 if (e.isError)
    ShowCartError(e.orgArtId,e.Message);
 else
    HideShowCart(e.orgArtId);   
    
  if (loginDataObject.UseExternalCart)
    {
      artCallBackObject.userName = loginDataObject.userName;
      artCallBackObject.nr =e.nr;
      artCallBackObject.description = e.description;
      artCallBackObject.producer = e.producer ;
      artCallBackObject.producerNr = e.producerNr;
      artCallBackObject.price =  e.price;
      artCallBackObject.quantity = e.cnt;
      artCallBackObject.field1 =  loginDataObject.Par1;
      artCallBackObject.field2 =  loginDataObject.Par2;
      artCallBackObject.field3 =  loginDataObject.Par3; 
      artCallBackObject.field4 =  loginDataObject.Par4; 
      artCallBackObject.field5 =  loginDataObject.Par5; 
       
      if (loginDataObject.LogedInFunctionCallback)
         {  
             var parametr = "";
              parametr = loginDataObject.callerUrl.indexOf('?') > -1 ? '&' : '?';
              window.opener.location = loginDataObject.callerUrl + parametr+ "AdToShop="+ Math.random() ;//+"#" + JSONstring.make(artCallBackObject)    ;   
          }
      
     // eval(loginDataObject.ArtAddedFunctionCallback+'(artCallBackObject)');
    }
}

function ChangeEinsp(name){

    var einspContainer = document.getElementById('einsp_content_einsp');
     for( var x = 0; x < einspContainer.childNodes.length; x++ ) {
        if( einspContainer.childNodes[x].id == name ) 
        {
            einspContainer.childNodes[x].style.display="block";
            var contentDiv = "einsp"+name.substr(name.length-1);
            var einspDiv = $get(contentDiv);
            if (einspDiv)
                if (einspDiv.childNodes)
                    if (einspDiv.childNodes.length>0)
                            {
                                var number = einspDiv.childNodes[0].id;
                                number = number.replace("e","");
                                GetArts(number);
                            }
        
        }
        else 
            einspContainer.childNodes[x].style.display="none";
   }
    openCloseIcon(name.substr(name.length-1));                  
}


function MarkDet(id)
{
 det_id=id;
 if (ef != 0) ea = RetId(ef,vf);
 if (el != 0) ea = RetId(el,vl);
 RetDetId();
 if (id!=null)
 {
  ef = 'f'+id;
  vf = MarkId(ef);
  el = 'l'+id;
  vl = MarkId(el);
  
  if (a3 == true)
    MarkDetId(id);
 }
}


function MarkDetSub(id)
{
 det_id = id;
 var splited = id.split("_");
 var img_det_id =  splited[2];
  
 if (ef != 0) ea = RetId(ef,vf);
 RetDetId();
 if (id!=null)
 {
    ef = id; 
    vf = MarkId(id);
    if (a3 == true)
      MarkDetId(img_det_id);
 }
}

function MarkDetId(id)
{
 vd = null;
 if (id != null) 
 {
  var obj;
  obj = document.getElementById('d'+id);
  if ( obj != null )
  {
   vd='d'+id;
   obj.className='picdeta';
   for (var i=1;  obj != null; i++)
   {
    obj = document.getElementById('d'+id+'_'+i);
    if ( obj != null )
    {
     vd+=';d'+id+'_'+i;
     obj.className='picdeta';
    } 
   } 
  }
 }
}

function DisplayToInlinine(me)
{
me.style.display="inline";
}

function CheckNoPicture(me)
{
}


function ShowEinspeiserInfo(e)
{
var el = document.getElementById("einspdetails");
if (el)
if (el.innerHTML == "")
    {
        alert("Keine Informationen fur diese Einspeiser");     
    }
    else
        {
        $get('EinspDetailsModalPanel').innerHTML = "";
        
        
        $get('EinspDetailsModalPanel').style.display = "block";
        ShowWaitIcon();
        CentroDigitalNETVB.CDK.GetInfoPanel(ShowEinspeiserInfo_SUCC,ErrorHandler)
     }

}
var einspBackgroundShown  = false;
function ShowEinspeiserInfo_SUCC(e)
{

if ($get('modalBackground').style.display=="none")
{
      einspBackgroundShown = true;
      ShowModalBackground();
}

$get('EinspDetailsModalPanel').innerHTML  = e;
var el = document.getElementById("einspdetails");
if (el)
  {
  $get('ImgInfoContainerLogo').src = $get('einspeiserMiniLogo').src  ;
  $get('InfoContainerContent').innerHTML = el.innerHTML;
  } 
 HideWaitIcon();
}


function CloseEinspeiserInfo()
{
 if (einspBackgroundShown==true) 
 {
  HideModalBackground();
  einspBackgroundShown = false
 }
  $get('EinspDetailsModalPanel').style.display = "none";
}


function RetDetId()
{
 if (vd != null)
 {
  var obj;
  var td=vd.split(';')
  for (var i=0; i<td.length;i++)
  {
   obj = document.getElementById(td[i]);
   if ( obj != null )
   {
    obj.className='picdetp';
   }
  }
 }
}

function RetDet()
{
 RetDetId();
 if (ef != 0) ea = RetId(ef,vf);
 //if (el != 0) el = RetId(el,vl);
}

var stckListeDetailsMode = false;
function SelDet(id)
{
    ADSub();
}

function SelDetSub(id)
{
    ADSub();
}


function MarkArt(id)
{
 art_id=id;
 var element = document.getElementById(id);
 if (element)
    {
        var lp = element.getAttribute("lPoint")
        if (lp) lPoint = lp;
    }
 if (ea != 0) ea = RetId(ea,va);
 if (id!=null)
 {
  ea = id;
  va = MarkId(ea);
 }
}

function ReArt()
{
 if (ea != 0) ea = RetId(ea,va);
}

function ArtSel(id)
{
 MarkArt(id);
}

function GetArts(einsp)
{
ClearHistory();
if (( $get('navTree').innerHTML != "")&&( $get('navTree').innerHTML != " "))
    if ((car_id>0) && (tree_id>0))
    {
        ForceWait();
        einsp_nr=einsp;
        CentroDigitalNETVB.CDK.GetArts(car_id, tree_id, einsp_nr, land, BGnr,bNkw,GetArts_suc_ForceNoWait,ErrorHandler);
    }
}


function deselecttext() {
    var sel ;
    
    if (document.selection && document.selection.empty){
        try
        {
            document.selection.empty() ;
        }
        catch(err)
        {}
        
    } else 
        if(window.getSelection) {
            sel=window.getSelection();
                if(sel && sel.removeAllRanges)
                    sel.removeAllRanges() ;
    }
}

function GoArts(id)
{
UnTip();

for (executor in requestArray)
{
  if (requestArray[executor].get_executor().get_started())
    {
        requestArray[executor].get_executor().abort();
    }
 }
 requestArray = new Array();
 deselecttext();
 if(id>0)
 {
  tree_id=id;
  GetArts(0);
 }
}


function ClearCarAndArtLabel()
{
    $get('navCar').innerHTML = "";
    $get('navTree').innerHTML = "";
    
}


function InitAlternativeFind()
{
 ClearCarAndArtLabel();
 //current_car = null; 
 //car_id = 0; na razie ...
 if (find_art!=null)
 {
    SetHTML("nf",find_art);
    CentroDigitalNETVB.CDK.FindArtAlt(art_id,lPoint, land, BGnr,bNkw,GetAltArts_suc,ErrorHandler);
  }
  else
    CentroDigitalNETVB.CDK.BuildFind(bNkw,BuildFindPanelSucc,ErrorHandler);
}

function BuildFindPanelSucc(e)
{
  find_art=e.nf;
  SetHTML("nf",e.nf);
  CentroDigitalNETVB.CDK.FindArtAlt(art_id,lPoint, land, BGnr,bNkw,GetAltArts_suc,ErrorHandler);
}


function GetAltArts_suc(e)
{   
    $get('faNr').value = e.nr;
    
    GetArts_suc(e);
    
}

function GetArts_suc_ForceNoWait(e)
{
 GetArts_suc(e);
 if ((loginDataObject.AutomaticWebshopUse==false) || (loginDataObject.UseWebshop==false))
    ForceNoWait();
}

function GetArtsFind_suc(e)
{
    GetArts_suc(e);
    if ((e.li == "") && (e.id == null))
       SetHTML("pa", '<div style="color:red;font-weight:bold;margin-left:10%;margin-top:10px;">Ihr Suchkriterium wurde nicht gefunden</div>');
        
}


function GetArts_suc(e)
{
 deselecttext();
 HideCarDet();
 if ((ei > 0) && (e.idEinsp >0)) ei = RetId("e"+ei,ve);
 SetHTML("d",e.dt);
 SetHTML("nf",e.nf);
 SetHTML("pa",e.pa);
 SetHTML("pr"," ");
 
 if ( current_car!= null)
    SetHTML("fzgDetForArtList",current_car.pd);
 
 var A_Visible = true;
 var B_Visible = true;
 var ShowWeitere  = true;
  
 if (($get("einsp_content_einspA") != null)&& (e.pea != null) && (e.peb != null)&& (e.pew != null))
 {
     if ((e.pea != "") )
        {
           SetHTML("einspA",e.pea);
           A_Visible = true;
           ShowWeitere = false;
           openCloseIcon("A");
           $get("einsp_content_einspA").style.display = "block";
        }
      else
      {       
        $get("etbA").style.display="none";
         A_Visible = false;
      }
     
     if ((e.peb != "") )
     {
       SetHTML("einspB",e.peb);
       if (A_Visible==false) 
        {
            B_Visible = true;
            ShowWeitere = false;
            openCloseIcon("B");     
            $get("etbA").style.display = "none";
            $get("einsp_content_einspB").style.display = "block";
        }
      }  
         else
      {
       $get("etbB").style.display="none";
       B_Visible = false;
      }
     
     
     if ((e.pew != "") && (ShowWeitere==true) )
     {
        SetHTML("einspW",e.pew);
        if ((B_Visible==false) && ( A_Visible == false))
            { 
            openCloseIcon("W");
            $get("etbB").style.display = "none";
            $get("einsp_content_einspW").style.display = "block";
            }
       
     }  
     else
     {
       $get("etbW").style.display="none";
     } 
      
 }
 if (a1==true)
 {
     SetHTML("einsp_krit_content",e.nc);
 }
 else
 {
    if ($get('einsp_krit'))
        $get('einsp_krit').style.display = "none";
    if ($get('einsp_content_einsp'))
        $get('einsp_content_einsp').style.bottom = "0%";
        //tt border-bottom:0 none Black;
        //treeIcons display none
 }
  ai=e.li; //to jest lista identyfikatorów przekazywana do prev nexta
 
 if (e.idEinsp >0) 
 {
  ei = e.idEinsp;
  ve = MarkId("e"+ei);
  einsp_nr = ei;
 }
 if (e.idTree >0) tree_id=e.idTree;
 if (e.id != 0) MarkArt(e.id);
 
 FixWebshopButtons();
 FixHistoryButton();
 AutomaticWebshopOrNoWait();
 
}

function FixWebshopButtons()
{
 if ((loginDataObject.UseWebshop == true) && (loginDataObject.AutomaticWebshopUse==false))
 {
    if ($get('GetWebshopArticleInfo_btn'))
        $get('GetWebshopArticleInfo_btn').style.display = "inline";
    if ($get('GetWebshopAllArticleInfo_btn'))
        $get('GetWebshopAllArticleInfo_btn').style.display = "inline";
 }
 else
 {
  if ($get('GetWebshopArticleInfo_btn'))
        $get('GetWebshopArticleInfo_btn').style.display = "none";
    if ($get('GetWebshopAllArticleInfo_btn'))
        $get('GetWebshopAllArticleInfo_btn').style.display = "none";
 }

if ((loginDataObject.AutomaticWebshopUse==true)&&(loginDataObject.UseWebshop == true))
   {
    if ($get('GetWebshopArticleInfo_btn'))
        $get('GetWebshopArticleInfo_btn').style.display = "inline";
    }

}
function FixHistoryButton()
{
    if($get('GetHistory_btn'))
    {
    if (histArray.length >0) 
        $get('GetHistory_btn').style.display='inline';
     else
        $get('GetHistory_btn').style.display='none';
    }
}



function openCloseIcon(openWhat)
{
if ( $get("ALiefOpen")!= null)
{
    if (openWhat == "A")
    {    
    $get('etbA').style.fontWeight = "bold"
    $get("ALiefOpen").style.display = "inline";
    $get("ALiefClose").style.display = "none";

    $get('etbB').style.fontWeight = "normal"        
    $get("BLiefOpen").style.display = "none";
    $get("BLiefClose").style.display = "inline";
        
    $get('etbW').style.fontWeight = "normal"        
    $get("WLiefOpen").style.display = "none";
    $get("WLiefClose").style.display = "inline";
    }
    
    if (openWhat == "B")
    {
    $get('etbA').style.fontWeight = "normal"    
    $get("ALiefOpen").style.display = "none";
    $get("ALiefClose").style.display = "inline";

    $get('etbB').style.fontWeight = "bold"        
    $get("BLiefOpen").style.display = "inline";
    $get("BLiefClose").style.display = "none";
        
    $get('etbW').style.fontWeight = "normal"        
    $get("WLiefOpen").style.display = "none";
    $get("WLiefClose").style.display = "inline";
    }
    if (openWhat == "W")
    {
    $get('etbA').style.fontWeight = "normal"    
    $get("ALiefOpen").style.display = "none";
    $get("ALiefClose").style.display = "inline";
    
    $get('etbB').style.fontWeight = "normal"   
    $get("BLiefOpen").style.display = "none";
    $get("BLiefClose").style.display = "inline";
        
    $get('etbW').style.fontWeight = "bold"    
    $get("WLiefOpen").style.display = "inline";
    $get("WLiefClose").style.display = "none";
    }
  }
}       



function ALDet()
{
UnTip();
 if (art_id!=null)
 {
  Wait();
  CentroDigitalNETVB.CDK.GetArtDet(car_id, tree_id, art_id,ai, land, BGnr,bNkw,GetArtDet_suc,ErrorHandler);
 }
}

function ALFind()
{
 if (art_id!=null)
 {
  
  Wait();
  AddToHistory();
  InitAlternativeFind();
 }
}

function ALD(id)
{
deselecttext();
 if (id!=null)
 if (id!='0;0')
 {
  art_id=id;
  ALDet();
 }
}

function ADNxt()
{
 if (art_id!=null)
 if (art_id!='0;0')
 {
  Wait();
  CentroDigitalNETVB.CDK.GetArtNxt(car_id, tree_id, art_id,ai, land, BGnr,bNkw,GetArtDet_sucl,ErrorHandler);
 }
}

function ADPrv()
{
 if (art_id!=null)
  if (art_id!='0;0')
  {
  Wait();
  CentroDigitalNETVB.CDK.GetArtPrv(car_id, tree_id, art_id,ai, land, BGnr,bNkw,GetArtDet_sucl,ErrorHandler);
 }
}

var pa;
function ADRet()
{
 SetHTML("d",pa);
 MarkArt(art_id);
}

function GetArtDet_suc(e)
{
deselecttext();
 
 ReArt();
 pa=GetHTML('d');
 SetHTML("d",e.dt);
 SetHTML("nf",e.Find);
 SetHTML("nr",e.Result);
 SetHTML("hd1",e.Tb1);
 SetHTML("hd2",e.Tb2);
 SetHTML("cd1",e.P1);
 if(e.stl!='-') stl=e.stl
 sti=e.sti;
 SetHTML("cd2",e.P2+stl);
 MarkId(car_id);
 MarkDet(e.id);
 FixWebshopButtons();
 AutomaticWebshopOrNoWait();
 
}

function GetArtDet_sucl(e)
{
deselecttext();
 SetHTML("hd1",e.Tb1);
 SetHTML("hd2",e.Tb2);
 SetHTML("cd1",e.P1);
 if(e.stl!='-') stl=e.stl
 sti=e.sti;
 SetHTML("cd2",e.P2+stl);
 MarkId(car_id);
 MarkDet(e.id);
 art_id=e.aid;
AutomaticWebshopOrNoWait();
 FixWebshopButtons();
}

function GetArtDet_sucr(e)
{
 deselecttext();
 if (stckListeDetailsMode)
    SetHTML("stckDetPanelRight",e.P2);
 else
    SetHTML("cd2",e.P2);
 MarkId(car_id);
    NoWait();
}

function GetArtDet_sucpic(e)
{
deselecttext();
 if (stckListeDetailsMode)
    SetHTML("stckDetPanelRight",e.P2);
 else
    SetHTML("cd2",e.P2+stl);
 
 var artDetPicb = $get('artdetpictb');
 var divTounbold = artDetPicb.getElementsByTagName("div");
 var x ;
 for (x=0; x < divTounbold.length; x++)
    divTounbold[x].style.fontWeight = "normal";
 var APic = $get('APic');
 var imgs = APic.getElementsByTagName("img");
 if (imgs)
    if (imgs.length>0)
    {
        var imgId = imgs[0].alt;
        var elem = $get(imgId).style.fontWeight = "bold";
    }
 MarkDet(det_id);
AutomaticWebshopOrNoWait();
}

function GetArtDet_sucpicForStck(e)
{
deselecttext();
 SetHTML("stckDetPanelRight",e.P2);
 MarkDet(det_id);
 AutomaticWebshopOrNoWait();
  
}

function AutomaticWebshopOrNoWait()
{
if ((loginDataObject.AutomaticWebshopUse==true) && (loginDataObject.UseWebshop==true))
    {
        if (stckListeDetailsMode == false)
        {
            if ($get('stckTableList'))
                GetDetWebshopAllArticleInfo();
            else
                GetWebshopAllArticleInfo();
        }
        else
            NoWait();
     }
     else
        NoWait();
}


function ADList()
{
 ScrollId('ADlist');
}

function ADBase()
{
 ScrollId('ADbasic');
}

 function ADStuckBase()
 {
  ScrollId('ADbasicStuck');
 }

function ADStuckBaseSub()
 {
  ScrollId('ADbasicStuckSub');
 }



function ADZub()
{
 ScrollId('ADzub');
}

function ADPrice()
{
 ScrollId('ADpric');
}

function ADInfo()
{
 ScrollId('ADinfo');
}

function ADPic(name)
{
 if (art_id!=null)
 {
  Wait();
  CentroDigitalNETVB.CDK.GetArtDetPic(car_id, tree_id, art_id, name, land, BGnr,bNkw,GetArtDet_sucpic,ErrorHandler);
 }
}

function ADCars()
{
 
 {
  Wait();
   if (stckListeDetailsMode)
   {
    if (det_id!=null)
    CentroDigitalNETVB.CDK.GetArtDetCars(car_id, tree_id, det_id, land, BGnr,bNkw,GetArtDet_sucr,ErrorHandler);
   }
   else
   {
    if (art_id!=null)
    CentroDigitalNETVB.CDK.GetArtDetCars(car_id, tree_id, art_id, land, BGnr,bNkw,GetArtDet_sucr,ErrorHandler);
   }
 }
}

function ADParent()
{
 if (art_id!=null)
 {
  Wait();
  CentroDigitalNETVB.CDK.GetArtDetParents(car_id, tree_id, art_id, land, BGnr,bNkw,GetArtDet_sucr,ErrorHandler);
 }
}

function GenArtSel(id)
{
 //alert('GenArtSel'+id);
}

//function ADSub()
//{
// alert('ADSub:'+det_id);
//}

function ADSub()
{
 if ((art_id!=null)&&(det_id!=null))
 {
  Wait();
  CentroDigitalNETVB.CDK.GetArtDetSub(car_id, tree_id, art_id,det_id,sti, land, BGnr,bNkw,GetArtSub_suc_ForStckList,ErrorHandler);
 }
}

function ADSNxt()
{
 if ((art_id!=null)&&(det_id!=null))
 {
  Wait();
  CentroDigitalNETVB.CDK.GetArtDetNxt(car_id, tree_id, art_id,det_id,sti, land, BGnr,bNkw,GetArtSub_sucl,ErrorHandler);
 }
}

function ADSPrv()
{
 if ((art_id!=null)&&(det_id!=null))
 {
  Wait();
  CentroDigitalNETVB.CDK.GetArtDetPrv(car_id, tree_id, art_id,det_id,sti, land, BGnr,bNkw,GetArtSub_sucl,ErrorHandler);
 }
}

var tads;
var pads;
function GetArtSub_suc(e)
{
deselecttext();
 RetDet();
 tads=GetHTML('hd2');
 pads=GetHTML('pAd2');
 SetHTML("pAd2",e.p);
 //SetHTML("nf",e.Find);
 //SetHTML("nr",e.Result);
 SetHTML("hd2",e.tb);
 SetHTML("hds1",e.Tb1);
 SetHTML("hds2",e.Tb2);
 SetHTML("cds1",e.P1);
 SetHTML("cds2",e.P2);
 NoWait();
}


function GetArtSub_suc_ForStckList(e)
{

var divForDetails = document.getElementById("stckListeDetails");

if (divForDetails==null)
{
    var el = document.createElement("div");
    el.setAttribute("id","stckListeDetails");
    document.body.appendChild(el);
    divForDetails = el;
}
     
 //RetDet();
 SetHTML("stckListeDetails",e.container);
 SetHTML("stckDetToolbarLeft",e.Tb1);
 SetHTML("stckDetToolbarRight",e.Tb2);
 SetHTML("stckDetPanelLeft",e.P1);
 SetHTML("stckDetPanelRight",e.P2);
 ShowModalBackground();
 divForDetails.style.display = "block";
 stckListeDetailsMode = true;
 NoWait();
}


function GetArtSub_sucl(e)
{
deselecttext();
 SetHTML("stckDetToolbarLeft",e.Tb1);
 SetHTML("stckDetToolbarRight",e.Tb2);
 SetHTML("stckDetPanelLeft",e.P1);
 SetHTML("stckDetPanelRight",e.P2);
 MarkId(car_id);
 MarkDetSub(e.id);
 NoWait();
}

function ADSRet()
{
 //SetHTML("pAd2",pads);
 //SetHTML("hd2",tads);
 
 MarkId(car_id);
 MarkDetSub(det_id);
 HideStckListeDetails();
}

function HideStckListeDetails()
{
 stckListeDetailsMode = false;
 var divForDetails = document.getElementById("stckListeDetails");
 HideModalBackground();
 if (divForDetails)
    divForDetails.style.display = "none";
}

function FindArt()
{
 
 ClearHistory();
 ClearCarAndArtLabel();
 current_car = null;
 //car_id = 0; na razie
  if ($get('faNr').value.length>1)
  {
    find_art=GetHTML("nf");
    var s=document.getElementById('faNr').value+'\t\ttrue\ttrue\ttrue\tfalse\tfalse\tfalse';
    Wait();
    CentroDigitalNETVB.CDK.FindArts(s, land, BGnr,bNkw,GetArtsFind_suc,ErrorHandler);
  }
  else
  {
  alert("Bitte geben Sie ein Suchkriterium ein.");
  }
}

function ErwArt()
{
}

function ClrArt()
{
 document.getElementById('faNr').value ="";
 document.getElementById('faNa').value ="";
}

function NoStar(e,object)
{
if (object.value.indexOf("*") ==0)
     object.value = object.value.substring(1, object.value.length);
}


function KeyFA(e,object)
{
 if(window.event)
 {
  if (e.keyCode==13)
  {
   FindArt();
   return false;
  }
 }
 else if(e.which)
 {
  if (e.keyCode==13)
  {
   FindArt();
   return false;
  }
 }
 return true;
}

function KeyNA(e,object)
{
 return KeyFA(e,object);
}

function GetWebshopArticleInfo()
{
 var cartImgId =  'cartAddImg_'+art_id;
    if ($get(cartImgId)) 
    {
        var imgID = 'WebShopImage_' + art_id;
        if ($get(imgID))
            {
                $get(imgID).src = "Images/iWebShopLoader.gif";
                CentroDigitalNETVB.WebShopProvider.GetArticleInfo(art_id ,loginDataObject ,land, BGnr, bNkw,false, GetWebshopArticleInfo_succeed,ErrorHandler)
            }
    }
    else
        alert("Pseudoartikel können nicht im Webshop angefragt werden.");
}

function GetDetWebshopArticleInfo()
{

if (det_id!=0)
{
 var cartImgId =  'cartAddImg_'+det_id;
    if ($get(cartImgId)) 
    {
        var imgID = 'WebShopImage_' + det_id;
        if ($get(imgID))
            {
                $get(imgID).src = "Images/iWebShopLoader.gif";
                
                CentroDigitalNETVB.WebShopProvider.GetArticleInfo(det_id ,loginDataObject ,land, BGnr, bNkw,true, GetWebshopArticleInfo_succeed,ErrorHandler)
            }
    }
    else
        alert("Pseudoartikel können nicht im Webshop angefragt werden.");
 }
}




function GetWebshopArticleInfo_succeed(e)
{
var i;
if (e.Status == true)
 {
  for (i in e.WebShopArticleList)
   {
    var id = "webshop_" + e.WebShopArticleList[i].ID;
    var id2 = "vk_" + e.WebShopArticleList[i].ID;
    if ($get(id))
        $get(id).innerHTML = e.WebShopArticleList[i].DivContent;
    if ($get(id2))
        $get(id2).innerHTML = e.WebShopArticleList[i].VK;
    } 
  }
else
  {
  alert('Es konnte keine Verbindung zum Webshop Ihres Großhändlers aufgebaut werden. Bitte überprüfen Sie Ihre Zugangsdaten.');
    //alert(e.StatusText);
  }
}


function GetWebshopArticleInfoNoWait_succeed(e)
{
GetWebshopArticleInfo_succeed(e);
ForceNoWait();
}

function GetWebshopAllArticleInfo()
{
if (!$get('pa')) {  ForceNoWait(); return false;}


ShowWaitIcon();
var object = new Array();
var trs = $get('pa').getElementsByTagName("tr");
var i=0;
var counter = 0;
for (i=0;i<trs.length;i++)
{
    if (trs[i].id)
        {
            var cartImgId =  'cartAddImg_'+trs[i].id;
            if ($get(cartImgId)) //czyli musi istnieć koszyk
            {
                 object[counter] = parseInt(trs[i].id);
                   counter++;
            }
        }
}
if (counter>0)
    CentroDigitalNETVB.WebShopProvider.GetArticlesInfo(object,loginDataObject,land, BGnr, bNkw, false, GetWebshopArticleInfoNoWait_succeed,ErrorHandler)
else
    ForceNoWait();
}


function GetDetWebshopAllArticleInfo()
{
if (!$get('stckTableList'))
       {
       ForceNoWait();
       return false;
       } 

ShowWaitIcon();
var object = new Array();
var trs = $get('stckTableList').getElementsByTagName("tr");
var i=0;
var counter = 0;
for (i=0;i<trs.length;i++)
{
    if (trs[i].id)
        {
            var cartImgId =  'cartAddImg_' + trs[i].id;
            if ($get(cartImgId)) //czyli musi istnieć koszyk
            {
                 object[counter] = trs[i].id;
                   counter++;
            }
        }
}
if (counter>0)
    CentroDigitalNETVB.WebShopProvider.GetArticlesInfo(object,loginDataObject,land, BGnr, bNkw, true, GetWebshopArticleInfoNoWait_succeed,ErrorHandler)
else
    ForceNoWait();
}



function ErrorHandler(e)
{
//if (true) alert(e.get_message() + e.get_stackTrace());
}

var histArray = new Array();


function AddToHistory()
{
//histArray = new Array();
//if (($get('navCar').innerHTML!='') &&($get('navTree').innerHTML!=''))
    {
        var histObject = new HistoryObject();
        histObject.CarName = $get('navCar').innerHTML;
        histObject.ArtName = $get('navTree').innerHTML;
        histObject.d =  $get('d').innerHTML;
        histObject.nf = $get('nf').innerHTML;
        histObject.ea = ea;
        histObject.va = va;
        if($get('faNr'))
            histObject.faNr_value = $get('faNr').value;
        histArray.push(histObject);
    }
}

function SetFromHistory()
{
ShowWaitIcon();
var histObject = new HistoryObject();

if (histArray.length >0)
    {
        histObject = histArray.pop();
        SetHTML("d",histObject.d);
        SetHTML("nf",histObject.nf);
        SetHTML("navCar",histObject.CarName);
        SetHTML("navTree",histObject.ArtName);
        if($get('faNr'))
            $get('faNr').value = histObject.faNr_value ;
        ea=histObject.ea;
        va=histObject.va;
        
    }
HideWaitIcon();    
}

 function HistoryObject()
 {    
    this.CarName="";
    this.ArtName="";
    this.nf="";
    this.d="";
    this.ea="";
    this.va="";
    this.faNr_value="";
}

function ClearHistory()
{
histArray = new Array();
}


function CheckWebshopUser()
{
    var user = $get("WebShopUserName").value;
    var pass = $get("WebShopUserPassword").value;
    CentroDigitalNETVB.WebShopProvider.CheckUserCredentials(loginDataObject,user,pass,CheckWebshopCredentials_succ,CheckWebshopCredentials_ERROR);
}


function CheckWebshopCredentials_succ(result)
{
    if ( result == false) 
        alert('Die Verbindung zum Webshop konnte nicht hergestellt werden. Bitte überprüfen Sie Ihre Zugangsdaten.');
    else
        alert('Die Verbindung zum Webshop wurde erfolgreich hergestellt.');    
}

function CheckWebshopCredentials_ERROR()
{

}
