﻿function NotificationUI(button,textBox)
{
    this.button=button;
    this.textBox=textBox;
}
NotificationUI.prototype.button=function(){return(this.button);}
NotificationUI.prototype.textBox=function(){return(this.textBox);}
NotificationUI.prototype.enable=function(){
    
    this.button.val("Remove");
    this.textBox.attr("readonly");
}
NotificationUI.prototype.disable=function(){
    this.button.val("Disable");
    this.textBox.removeAttr("readonly");
}

function Notifications(productId,dailyEmailUI,dailySmsUI,productEmailUI)
{
    this.productId=productId;
    this.dailyEmailUI=dailyEmailUI;
    this.dailySmsUI=dailySmsUI;
    this.productEmailUI=productEmailUI;
    
    this.addDailyEmailCallback=function(json){
        if(eval(json).active==true)
        {
            this.dailyEmailUI.enable();
        }
        else
        {
            this.dailyEmailUI.disable();
        }
    }
    this.addDailySmsCallback=function(json){
        if(eval(json).active==true)
        {
            this.dailySmsUI.enable();
        }
        else
        {
            this.dailySmsUI.disable();
        }
    }
    this.addProductEmail=function(json)
    {
        if(eval(json).active==true)
        {
            this.productEmailUI.enable();
        }
        else
        {
            this.productEmailUI.disable();
        }  
    }
}

Notifications.prototype.addDailyEmail=function(email)
{
    $.post("/Notification/addDailyEmail",{Email:email},this.addDailyEmailCallback,"json");
    
}
Notifications.prototype.addDailySms=function(sms)
{
    $.post("/Notification/addDailySms",{Sms:sms},this.addDailySmsCallback,"json");
}

Notifications.prototype.addProductEmail=function(email)
{
    $.post("/Notification/addProductEmail",{Email:email},this.addDailySmsCallback,"json");
}