//---------------------- Zuletzt gesehene Artikel ---------------------------- //
    var Zeit = new Date();
    var Jetzt = Zeit.getTime();

function GetCookie(name){
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var tCookie=document.cookie;
  var i = 0;
  while (i < clen) 
  {
    var j = i + alen;
    if(tCookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = tCookie.indexOf(" ", i) + 1;
    if (i == 0) 
      break; 
  }
  return "";

}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)            
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

var LastViewIDs ="";
function LastView(ID, Pic, PicDestBrand, StyleName, PriceNew, NewSale, ColorNumber, ProductTemplate){
		
	arrPieces = new Array(ID, Pic, PicDestBrand, StyleName, PriceNew, NewSale, ColorNumber, ProductTemplate);
	arrLastViewIds = new Array();
  
  if(document.referrer.indexOf('search.esprit.de') <0) {
  	urlParam = "";
  	try{
  		urlParam = parent.location.search;
  	}catch(e){ }

    if(urlParam.indexOf("noLV") < 0) {                       							// Wenn Detailansicht nicht aus "Zuletzt gesehen" aufgerufen wurde

			strLastViewValue = parent.parent.parent.FrameBasket.GetCookie('LastView');

			if(strLastViewValue) {
				if(strLastViewValue.length < 4000) {

					arrLastViewIds = strLastViewValue.split('|');

					if(!in_array(arrLastViewIds, ID, 0, ColorNumber, 6, '$')) {						
						if(arrLastViewIds.length >= 18) {
							arrLastViewIds.shift();
						}
						arrLastViewIds[arrLastViewIds.length] = arrPieces.join('$');
					
						strLastViewValue = arrLastViewIds.join('|');
					}
				}
			} else {
				
				arrLastViewIds[arrLastViewIds.length] = arrPieces.join('$');
				
				strLastViewValue = arrLastViewIds.join('|');
			}
			Zeit.setTime(Jetzt + (3600000*8));																								// Expire-Zeitpunkt festlegen

      parent.parent.parent.FrameBasket.SetCookie('LastView', strLastViewValue, Zeit);   // Cookie schreiben	


      if(parent.parent.parent.FrameBasket.GetCookie('LastView')) {											// Wenn Cookie existiert
        LastViewIDs = parent.parent.parent.FrameBasket.GetCookie('LastView');       		// Cookie in Variable speichern
        LastIDs = LastViewIDs.split('|');                               								// ausplitten nach Artikel

        if(LastIDs.length >= 19) {                                       	 							// wenn 3 oder mehr Artikel im Cookie
          if(LastViewIDs.indexOf(ID+"$"+Pic+"$"+PicDestBrand+"$"+StyleName+"$"+PriceNew+"$"+NewSale+"$"+ColorNumber+"$"+ProductTemplate) <0){       // Wenn Artikel noch nicht in "Zuletzt gesehen"
            LastViewIDs = LastIDs[1] +"|"+ LastIDs[2]
                  +"|"+ LastIDs[3] +"|"+ LastIDs[4]
                  +"|"+ LastIDs[5] +"|"+ LastIDs[6]
                  +"|"+ LastIDs[7] +"|"+ LastIDs[8]     
                  +"|"+ LastIDs[9] +"|"+ LastIDs[10]
                  +"|"+ LastIDs[11] +"|"+ LastIDs[12]
                  +"|"+ LastIDs[13] +"|"+ LastIDs[14]
                  +"|"+ LastIDs[15] +"|"+ LastIDs[16]
                  +"|"+ LastIDs[17] +"|"+ LastIDs[18];
            LastViewIDs +="|"+ID+"$"+Pic+"$"+PicDestBrand+"$"+StyleName+"$"+PriceNew+"$"+NewSale+"$"+ColorNumber+"$"+ProductTemplate;                 // Artikel hinzufügen
          } else{
            LastViewIDs = LastViewIDs;
          }
        } else {
          if(LastViewIDs.indexOf(ID+"$"+Pic+"$"+PicDestBrand+"$"+StyleName+"$"+PriceNew+"$"+NewSale+"$"+ColorNumber+"$"+ProductTemplate) <0){        // Wenn Artikel noch nicht in "Zuletzt gesehen"
            LastViewIDs += "|"+ID+"$"+Pic+"$"+PicDestBrand+"$"+StyleName+"$"+PriceNew+"$"+NewSale+"$"+ColorNumber+"$"+ProductTemplate;                 // Artikel hinzufügen
          }
        }
      } else {
        LastViewIDs += ID+"$"+Pic+"$"+PicDestBrand+"$"+StyleName+"$"+PriceNew+"$"+NewSale+"$"+ColorNumber+"$"+ProductTemplate;                 // Artikel hinzufügen
      }
      
      try{
      	parent.parent.parent.FrameStart.FrameMainNavi.ShowMerkliste();
      }catch(e){      	
      
      }
    }
  }
} 

  function isInLastView(intId) {
  
    if(parent.parent.parent.FrameBasket.GetCookie('LastView')){		                          // Wenn Cookie existiert

      arrLastIDs = parent.parent.parent.FrameBasket.GetCookie('LastView').split('|');        // aufsplitten nach Artikel

      if(arrLastIDs.length > 0) {
        for(r=0;r<arrLastIDs.length;++r) {
          arrElements = arrLastIDs[r].split('$');
          if(arrElements[0] == intId) {
            return 1;  
          }
        }
      }
    }
    return 0;
  }
  
  function in_array(arrHaystack, strNeedleOne, intFieldOne, strNeedleTwo, intFieldTwo, strSplit) {
  	
  	if(intFieldOne == undefined) {
  		intFieldOne = 0;
  	}
  	
  	if(intFieldTwo == undefined) {
  		intFieldTwo = 0;
  	}
  	
  	if(strSplit == undefined) {
  		strSplit = '';
  	}
  	
  	for(var h=0;h<arrHaystack.length;++h) {
  		if(strSplit != '') {
  			arrElements = arrHaystack[h].split(strSplit);

  			if(arrElements[intFieldOne] == strNeedleOne && arrElements[intFieldTwo] == strNeedleTwo) {
					return true;
				}
  		} else {
				if(arrHaystack[h][intFieldOne] == strNeedleOne && arrHaystack[h][intFieldTwo] == strNeedleTwo) {
					return true;
				}
			}
		}
  	return false;
 	}