﻿var dlgGA;
function likePicture(id) {
    rpc2.startRequest(likePictureComplete, "There was a problem telling the system you liked this picture.  Please try again.  If the problem persists please let support know via the 'Feedback' link at the bottom of the page.", "/rpc/likepicture.ashx", "id=" + id);
}
function likePictureComplete(o) {
    alert(o.ReturnMessage);
}
function createGardenArea() {
    document.getElementById("GardenAreaID").value = "0";
    showGardenAreaPopup();
}
function showGardenAreaPopup() {
    if (!dlgGA) { // lazy initialize the dialog and only create it once
        document.getElementById("divGardenArea").style.display = "";

        dlgGA = new YAHOO.widget.Dialog("divGardenArea",
				{ width: 550,
				    fixedcenter: true,
				    draggable: true,
				    visible: false,
				    modal: true,
				    constraintoviewport: true,
				    zindex: 9001,
				    postmethod: '',
				    buttons: [{ text: "Save Garden Area", handler: saveGardenArea, isDefault: true}]
				});
        dlgGA.cfg.queueProperty("postmethod", "form");

        dlgGA.render(document.body);
    }
    dlgGA.show();
}
function editGardenArea(id) {
    rpc2.startRequest(editGardenAreaComplete, "There was a problem retrieving this garden area.  Please try again.  If the problem persists please let support know via the 'Feedback' link at the bottom of the page.", "/rpc/getgardenarea.ashx", "id=" + id);
}
function editGardenAreaComplete(ReturnData) {
    var o = YAHOO.lang.JSON.parse(ReturnData.Data);

    document.getElementById("txtDesc").value = o.Description;
    document.getElementById("txtName").value = o.Name;
    document.getElementById("txtLocation").value = o.Location;

    var drp = document.getElementById("drpSoilType");
    for (var y = 0; y < drp.options.length; y++) {
        if (drp.options[y].value == o.SoilType){
            drp.selectedIndex = y;
            break;
        }
    }

    drp = document.getElementById("drpHardinessZone");
    for (var y = 0; y < drp.options.length; y++) {
        if (drp.options[y].value == o.HardinessZone){
            drp.selectedIndex = y;
            break;
        }
    }

    drp = document.getElementById("drpSunlight");
    for (var y = 0; y < drp.options.length; y++) {
        if (drp.options[y].value == o.SunlightLevel) {
            drp.selectedIndex = y;
            break;
        }
    }
    document.getElementById("chkOutdoors").checked = o.Outdoors;
    document.getElementById("chkIsActive").checked = o.IsActive;
    document.getElementById("GardenAreaID").value = o.GardenAreaID;
    showGardenAreaPopup();
}
function saveGardenArea() {
    var ga = {};
    ga.Description = document.getElementById("txtDesc").value;
    ga.GardenAreaID = document.getElementById("GardenAreaID").value;
    var drp = document.getElementById("drpHardinessZone");
    ga.HardinessZone = drp.options[drp.selectedIndex].value;
    ga.Location = document.getElementById("txtLocation").value;
    ga.Name = document.getElementById("txtName").value;
    ga.Outdoors = document.getElementById("chkOutdoors").checked;
    drp = document.getElementById("drpSoilType");
    ga.SoilType = drp.options[drp.selectedIndex].value;
    drp = document.getElementById("drpSunlight");
    ga.SunlightLevel = drp.options[drp.selectedIndex].value;
    ga.IsActive = document.getElementById("chkIsActive").checked;
    rpc.startRequest(saveGardenAreaComplete, "There was a problem saving this Garden Area.  Please try again.  If the problem persists please let support know via the 'Feedback' link at the bottom of the page.", "/rpc/saveGardenArea.ashx", "ga=" + escape(YAHOO.AL.util.JSON.encode(ga)));
    dlgGA.hide();
}
function saveGardenAreaComplete(o) {
    alert("Your new Garden Area has been succesfully created.  Your screen will refresh and show this new Garden Area after you press 'OK'.");
    window.location.reload();
}
function changePic(imgPath, CommunityName, Width, Height, Subject, Notes, id, DisplayCommunityName) {
    var s = "<div class=\"caption\" style=\"height:" + Height + "px;width:" + Width + "px;\">";
    s += "<a href=\"/members/" + escape(CommunityName) + "/picture/" + id + ".aspx\"><img border=\"0\" src=\"" + imgPath + "\" /></a>";
    s += "<div class=\"captionbar\"><p>" + Subject + " (<a href=\"/members/" + CommunityName + "/default.aspx\">" + CommunityName + "</a>)<br><span class=\"Notes\">" + (Notes) + "</span> <span class=\"LikeThis\">";
    s += "<a href=\"javascript:likePicture(" + id + ")\">(I Like This Picture!)</a></span></div></p></div>";
    s += "</div>";
    document.getElementById("BigPic").innerHTML = s;
}

