
/**
 * @class Topic_Class
 * 
 * 
 * 
 * 
 * 
 */
Core.Topic_Class=function () {
    /**
     * Topic Code which is prd_code in DB
     */    
    this.TopicCode="";

    /**
     *  The json object reurned via webservices
     */
    this.Result;

    /**
     * Topic Types
     */
    this.TopicType="";

    /**
     * it is set to true if loaded and set to false otherwise.
     */
    this.Loaded=false;
}
/**
 * It registers the Topic_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) {Core.Topic_Class.registerClass('Core.Topic_Class'); }


/**
 * @class Core.TopicManager_Class
 *
 * 
 * 
 * 
 * @constructor 
 */

 Core.TopicManager_Class=function() {
   
    this.tempArrayLookUp=new Array();
    this.GetTopicProductsCodes= function (TopicCode, TopicType,FilterLevel)  {
      // _WebServiceAPI.GetTopicProductsCodes(TopicCode,TopicType,this.GetTopicProductsCodesOnComplete);
       _WebServiceAPI.GetTopicProductsCodes(TopicCode,TopicType,(FilterLevel=='1') ? this.GetTopicProductsCodesOnComplete: this.GetTopicParentProductsCodesOnComplete);
    
    }
    
    /**
     * This function will return all of the topic products filtered by the root category code.
     */
    this.GetTopicProductsCodesByRootCategory = function (TopicCode, TopicType, RootCategoryCode)
    {
        _WebServiceAPI.GetTopicProductsCodesByRootCategory(TopicCode, TopicType, RootCategoryCode, this.GetTopicProductsCodesByRootCategoryOnComplete);
    }
    
    /**
     * This function will handle the results of the GetTopicProductsCodesByRootCategory function
     */
    this.GetTopicProductsCodesByRootCategoryOnComplete = function (result)  
    {
         DoDefault();     
         if (result!=null) {
            if (AJAX_IS_TOPIC_PRODUCT_SLIDER_ON) 
            {
                 var constructedData=_TopicManager.GetConstruct(result);
                 // alert(constructedData);
                 if (constructedData==null || constructedData.length==0)
                 {
                    alert ("No results for this category.");
                 }
                 else 
                 {
                  _TopicManager.GetTopicProductsCodesOnComplete(constructedData);
                }
            }
            else 
            {
                _NavigatorManager.FilteredData=result;
                _NavigatorManager.DoMainFilterInitialization(MAIN_LAYER_PARENT_CONTAINS); 
            }
         }
         else 
         { 
            alert ("No results for this category.");
         }  
    }
    
    this.GetTopicProductsCodesOnComplete= function (result)  {
        DoDefault();
         if (result!=null) {
            _NavigatorManager.FilteredData=result;
            _NavigatorManager.DoFilterInitialization(VARIANT_LAYER_PARENT_CONTAINS);
         }
         else { 
            alert ("No Results for this Filter Combination.");
         }
    }
    
   
      this.GetConstruct=function (res) {
         var constructedData=new Array();
          for (var i = 0; i < res.length ; i++) {
              res[i]=res[i].replace(":","")
          }
          for (var i = 0; i < res.length ; i++) {
          
              for (var j = 0; j < this.tempArrayLookUp.length ; j++) {
                 
                   if (this.tempArrayLookUp[j].indexOf(res[i]) !=-1) {
                          var selectedvalue_array=this.tempArrayLookUp[j].split(":");
	                      res[i]=selectedvalue_array[0] + ":" +  res[i];
	                     // alert(res[i]);
                          break;
                   }
              }
          }
          for (var i = 0; i < res.length ; i++) {
             if (res[i].indexOf(":")!=-1) {
               constructedData[constructedData.length]=res[i];
             }
            
          }
         // alert(constructedData);
          return constructedData;
       }
    
    
   this.GetTopicParentProductsCodesOnComplete= function (result)  {
         DoDefault();
         
         if (result!=null) {
            if (AJAX_IS_TOPIC_PRODUCT_SLIDER_ON) {
                 var constructedData=_TopicManager.GetConstruct(result);
                 // alert(constructedData);
                 if (constructedData==null || constructedData.length==0) {
                    alert ("No Results for this Filter Combination.");
                 }
                 else {
                  //_TopicManager.GetTopicProductsCodesOnComplete(_TopicManager.GetConstruct(result));
                  _TopicManager.GetTopicProductsCodesOnComplete(constructedData);
         
                }
            }
            else {
                 _NavigatorManager.FilteredData=result;
                 _NavigatorManager.DoMainFilterInitialization(MAIN_LAYER_PARENT_CONTAINS); 
            }
         }
         else { 
         alert ("No Results for this Filter Combination.");
         }
   
   }
    
   this.GetTopicProductsCodesByTopicList=function(TopicList,TopicType,FilterLevel){
          try {
            _NavigatorManager.ClearFilter(); //clear prev filter
         }
         catch(e){
          //do nothing
         }
         if (typeof(TopicList)=='undefined' || TopicList=="") {return false;}
         if (TopicList.indexOf(',') ==-1){
                this.GetTopicProductsCodes(TopicList,TopicType,FilterLevel);
        }
        else {
              


                _WebServiceAPI.GetTopicProductsCodesByTopicList(TopicList,(FilterLevel=='1') ? this.GetTopicProductsCodesOnComplete: this.GetTopicParentProductsCodesOnComplete);
        }
   }
 
   
   /**
     * Saves a topic to customer profile. OnCompleteFuncName is not passed or is it empty, the control is passed
     * on this.SaveTopicOnComplete otherwise the custom call back function will be called.
     * @param {string} TopicCode 
     * @param {string} TopicType 
     * @param {object} OnCompleteFuncName (optional)
     */
   this.SaveTopic=function(TopicCode,TopicType,OnCompleteFuncName) {
      if (typeof(OnCompleteFuncName)=='undefined' || (OnCompleteFuncName=="")) {
	   _WebServiceAPI.TopicCustomerRatingRecord(CurrentCustomerID, TopicType, TopicCode, 'tips', 5, 'n/a', this.SaveTopicOnComplete);
	
	  }
	  else {
	 
	   _WebServiceAPI.TopicCustomerRatingRecord(CurrentCustomerID, TopicType, TopicCode, 'tips', 5, 'n/a',OnCompleteFuncName);
	
	  }
	
	}
	
  
   /**
     * On complete function when topic is saved.
     * @param {object} result
     */
    this.SaveTopicOnComplete=function(result) {
                DoDefault();
 		     if (result.ActivityStatus==true) {
                    alert("your topic has been saved");
		     }
   
     }
	
	 /**
     * removes a topic to customer profile. OnCompleteFuncName is not passed or is it empty, the control is passed
     * on this.RemoveFavTopicOnComplete otherwise the custom call back function will be called.
     * @param {string} TopicCode 
     * @param {string} TopicType 
     * @param {object} OnCompleteFuncName (optional)
     */
    this.RemoveFavTopic=function(TopicCode,TopicType,OnCompleteFuncName)  {
       if (typeof(OnCompleteFuncName)=='undefined' || (OnCompleteFuncName=="")) {
	   _WebServiceAPI.RemoveTopicFromFavorites(CurrentCustomerID, TopicCode, TopicType, this.RemoveFavTopicOnComplete);
	  
	   }
	   else {
	    _WebServiceAPI.RemoveTopicFromFavorites(CurrentCustomerID, TopicCode,TopicType, OnCompleteFuncName);
	  
	   }
	}
	
	 /**
     * On complete function when topic is removed.
     * @param {object} result
     */
	this.RemoveFavTopicOnComplete=function(result) {
	            DoDefault();
 		     if (result.ActivityStatus==true) {
                    alert("your topic has been removed");
		     }
	}
 
}

/**
 * It registers the  Core.TopicManager_Class using registerClass method of MS AJAX Library
 */
 if (IsTypeDefined) { Core.TopicManager_Class.registerClass('Core.TopicManager_Class'); }

