function NewsBlockInfo(url, info)
{
    this.id = (new Date()).getTime()+"_"+Math.random();
    this.url = url;
    this.info = info;

    var This = this;

    this.dialog = new dijit.Dialog({'content':''});

    var s = "<div style='direction:rtl'>";

    if (info.id)
    {
        s += "<h1>עדכון פריט</h1>"
    } 
    else 
    {
        s += "<h1>פריט חדש</h1>"
    }

    s += "<table><tr>";
    s += "<td>כותרת:</td><td><input type='text' id='"+this.id+"_new_name' /></td>";
    s += "</tr><tr>";
    s += "<td>תיאור:</td><td><textarea rows=6 id='"+this.id+"_new_desc' style='width:400px'></textarea></td>";
    s += "</tr><tr>";
    s += "<td>לינק:</td><td><input type='text' id='"+this.id+"_new_link' /></td>";
    s += "</tr><tr>";
    s += "<td>תמונה:</td><td><input type='text' id='"+this.id+"_new_image' /></td>";
    s += "</tr><tr>";
    s += "</tr></table>";
    s += "<div style='width:100%;text-align:center'><div id='"+this.id+"_done'></div><div id='"+this.id+"_del'></div></div><br/><br/>";

    s += "</div>";
    this.dialog.attr("content", s);

    if (info.id)
    {
        this.getField("new_name").value = info.title;
        this.getField("new_desc").value = info.description;
        this.getField("new_link").value = info.link ? info.link : "";
        this.getField("new_image").value = info.image ? info.image : "";

        this.delButton = new dojox.form.BusyButton({
            id: this.id+"_del_1",
            busyLabel: "אנא המתן...",
            style: "",
            label: "מחק",
            timeout: 60*60*1000,
        },
        this.id+"_del");
        dojo.connect(this.delButton, "onClick", function() {This.del();});
    }

    this.button = new dojox.form.BusyButton({
        id: this.id+"_done_1",
        busyLabel: "אנא המתן...",
        style: "",
        label: "שמור",
        timeout: 60*60*1000,
    },
    this.id+"_done");
    dojo.connect(this.button, "onClick", function() {This.save();});

    this.dialog.show();
}

NewsBlockInfo.prototype.getField = function(field)
{
    var name = this.id+"_"+field;
    return dojo.byId(name);
}

NewsBlockInfo.prototype.getFieldValue = function(field)
{
    value = this.getField(field).value.replace(/^\s*/, "").replace(/\s*$/, "");
    return value;
}

NewsBlockInfo.prototype.getFieldAndValidate = function(field)
{
    var name = this.id+"_"+field;
    var value = this.getFieldValue(field);

    if (value.length == 0)
    {
        dojo.byId(name).style.border = "2px solid red";
    }
    
    return value;
}

NewsBlockInfo.prototype.save = function()
{
    var title = this.getFieldAndValidate("new_name");
    var description = this.getFieldAndValidate("new_desc");
    var link = this.getFieldValue("new_link");
    var image = this.getFieldValue("new_image");

    if ((title.length == 0) || (description.length == 0))
    {
        this.button.cancel();
        return;
    }

    this.info.title = title;
    this.info.description = description;
    if (link.length > 0)
    {
        this.info.link = link;
    } else
    {
        delete this.info.link;
    }
    if (image.length > 0)
    {
        this.info.image = image;
    } else
    {
        delete this.info.image;
    }

    var This = this;
    post(this.url, this.info, function(param, result) { This.saveDone(result); }, null);
}

NewsBlockInfo.prototype.saveDone = function(result)
{
    if (result.error)
    {
        alert("שגיאה בעת שמירה!");
        this.button.cancel();
        return;
    }

    if (this.callback) {
        this.callback();
    } else {
        this.dialog.hide();
    }
}

NewsBlockInfo.prototype.hide = function()
{
    this.dialog.hide();
}

NewsBlockInfo.prototype.del = function()
{
    var This = this;
    del(this.url + "?id=" + this.info.id, function(param, result) {This.delDone(result); }, null);
}

NewsBlockInfo.prototype.delDone = function(result)
{
    if (result.error)
    {
        alert("שגיאה בעת מחיקה!");
        this.delButton.cancel();
        return;
    }

    if (this.callback) {
        this.callback();
    } else {
        this.dialog.hide();
    }
}

