﻿function DealsOfTheWeekBase()
{
  
  this.DealsOfTheWeek = new Array();
  
  //------------------------------------------------------------------
    this.ReturnDealsOftheWeek = function()
    {
       //loop thru the dow array
       //set the coupon status based on Pods array and user restrictions   
       for (var i=0; i< this.DealsOfTheWeek.length;i++)
       {
         
         if(this.DealsOfTheWeek[i].dowCoupons.length > 0)
         {
            for (var j=0; j< this.DealsOfTheWeek[i].dowCoupons.length; j++)
            {
              SetProgramCpnStatusAndURL(this.DealsOfTheWeek[i].dowCoupons[j]);         
            }
         }    
       }   
       
       return this.DealsOfTheWeek;
    }

}


function FeaturedProgramsBase()
{
  
  this.FeaturedPrograms = new Array();
  
  //------------------------------------------------------------------
   this.ReturnFeaturedPrograms = function ()
    {
       //loop thru the featured programs array
       //set the coupon status based on Pods array and user restrictions   
       for (var i=0; i< this.FeaturedPrograms .length;i++)
       {
         if(this.FeaturedPrograms [i].ProgramCoupons.length > 0)
         {
            for (var j=0; j< this.FeaturedPrograms[i].ProgramCoupons.length; j++)
            {
              SetProgramCpnStatusAndURL(this.FeaturedPrograms[i].ProgramCoupons[j]);         
            }
         }    
       } 
       
       return this.FeaturedPrograms; 
    }

}
//featured program 
function FeaturedProgram(programText,ProgramAdditionalText,ProgramImgURL,ProgramPillowImgURL,ProgramCoupons)
{
  this.programText= programText;
  this.ProgramAdditionalText= ProgramAdditionalText;
  this.ProgramImgURL = ProgramImgURL;
  this.ProgramPillowImgURL = ProgramPillowImgURL;
  this.ProgramCoupons = ProgramCoupons;
  
}
// deal of the week 
function DealOfTheWeek(dowText,dowAdditionalText,dowImgURL,dowPillowImgURL,dowCoupons)
{
  this.dowText = dowText;
  this.dowAdditionalText = dowAdditionalText;
  this.dowImgURL = dowImgURL;
  this.dowPillowImgURL = dowPillowImgURL;
  this.dowCoupons = dowCoupons;
}

// Program Coupon 
function ProgramCoupon(couponID,Status,couponImgURL,prgmCpnDesc)
{
  this.couponID = couponID;
  this.Status = Status;
  this.couponImgURL = couponImgURL;
  this.prgmCpnDesc = prgmCpnDesc;
}




function GetProgramRestrictionForCpn (cid)
    {

       for(var x=0;x<ci_restrxArr.length;x++)
       {
          var rObj = ci_restrxArr[x];
          if(rObj.id == cid) return rObj;
       }
            
       return null;
    }

//--------------------------------------------------------------
function SetProgramCpnStatusAndURL(prgmCpnObj)
{
    var Status = 1;
    var availCpn= 0;
    var cpnObj = GetProgramRestrictionForCpn(prgmCpnObj.couponID);
    //check if coupon was printed by device
     if(typeof(cpnObj) != "undefined" && cpnObj !=null && cpnObj.printed == 1)
     {
       Status = 2;
     }   
    
    // check if coupon exists in pods array  
    if(typeof(ci_pods) != "undefined" && ci_pods != null)
     { 
       
        for(var i=0;i<ci_pods.length;i++)
        {
           if(prgmCpnObj.couponID == ci_pods[i].id) 
            {
              if (prgmCpnObj.couponImgURL == "")
              {
                prgmCpnObj.couponImgURL = ci_pods[i].imgURL;
              }
              availCpn = 1; 
              break;
            }    
        }
     
     }
     
    // find in targetted pods if not found in main pods
    if(availCpn == 0)
    { 
     if( typeof(ci_geoTargettedPods) != "undefined" && ci_geoTargettedPods != null)
       {   
           for(var i=0;i<ci_geoTargettedPods.length;i++)
           { 
               if(prgmCpnObj.couponID == ci_geoTargettedPods[i].id) 
                 {
                   availCpn = 1; 
                   break;
                 } 
            }
        }
     }
     // ProgramCoupon not found  
     if(availCpn == 0)
     {
      Status = 3;
     }
     
     prgmCpnObj.Status= Status;
}


