﻿

function WhatsNewItem(data){ 
        this.itemData = data.split("^");
        this.ProductId = function (){  return this.itemData[0]; };
        this.Name = function (){  return this.itemData[1]; };
        this.Description = function (){  return this.itemData[2]; };
        this.Price = function (){  return this.itemData[3]; };
        this.FileName = function (){  return this.itemData[4]; };
        this.ShortDesc = function (){  return this.itemData[5]; };
        
    }
    
  function LoadWhatsNew(dealerId){
 
        var whatsNewContainer = $get('whatsNew');
        whatsNewContainer.innerHTML = "<div style='color:gray;'><img src=\"images/ajax-loader.gif\"/>Loading....</div>";
        if(dealerId == null){dealerId = "";}
        BMW.Lifestyles.Web.Services.Products.WhatsNewItems(dealerId,CompleteLoadWhatsNew, FailedLoadWhatsNew);
      
    }
    
    function FailedLoadWhatsNew(result, eventArgs){
     var whatsNewContainer = $get('whatsNew');
    whatsNewContainer.innerHTML = "Currently No New Items Available.";
    }
    
    function CompleteLoadWhatsNew(result, eventArgs){
        var whatsNewHTMLData = "";
        var whatsNewContainer = $get('whatsNew');
        var whatNewTitle ="<h3><a href=\"ProductList.aspx?c=156\">What's New</a></h3>";
        var whatsNewFormat ="<div class=\"thumbContainer\"><a href=\"ProductDetail.aspx?p={0}\"><img class=\"ThumbnailImage\" onerror=\"ImageNotAvailable(this,'ImageNotAvailable.jpg','small');\" src=\"images/assets/small/{2}\" alt=\"\" width=\"54\" height=\"54\" border=\"0\" /></a>" +
                     "<div class=\"detailsContainer\"><div class=\"productText\"><a href=\"ProductDetail.aspx?p={0}\">{1}</a><br /></div>" +
			         "<div class=\"priceText\"><span class=\"price\"></span></div><div class=descText\">{4}</div></div></div>"
      
        if ( result.length == 0 ){
            whatsNewContainer.innerHTML = "Currently No New Items Available.";
        }
        else
        {
            whatsNewContainer.innerHTML = "";
            for(i=0; i < result.length; i++){
               var wni = new WhatsNewItem(result[i]);
                whatsNewHTMLData = whatsNewHTMLData + String.format(whatsNewFormat,wni.ProductId(),wni.Name(),wni.FileName(),wni.Price(),wni.ShortDesc());
            }
     
            whatsNewContainer.innerHTML = whatNewTitle + whatsNewHTMLData;
  
        }
    }


