/*
 * Author       : lozc
 * Generated on : 23-Nov-2009 05:08:48
 * Version      : 3.0
 */
application "Zoodle"
{
    type = public
    allow html = true
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section Main
    {
        form  Welcome
        {
            
            welcome_display
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    on load
                    {
                        input.welcome_display = (((((((((("<table cellpadding='10' border='0'><tr><td style='background-color: #bcf;border:dashed 1px #63f;'") + " valign='top'><p style='color:#006'>") + "Zoodle lets you manage your <a href='http://www.oodle.com'>Oodle</a> <a href='http://www.oodle.com/info/upload/real_estate_feed_doc.html'>real estate feed</a> with Zoho Creator.  ") + "Oodle's site says:  <em>When you have a feed that") + " is ready, or if you have any questions about providing us with a feed, send us an <a href='mailto:feed@oodle.com'>email</a></em>.</p>") + "<p style='color:#006'>To get started with Zoodle, <strong>Create</strong> some listings and <strong>Publish</strong> them.") + "  Your latest feed is always available at the URL linked to in the <strong>Feed</strong> area.</p>") + "</td>") + "<td valign='top'><h3 align='center'><img src='/DownloadFile.do?filepath=/1195244089042_zoodle.png&sharedBy=lozc'/></h3><br/>") + "<h3 align='center'>v0.19</h3><p align='center'>pete at <a href='http://landofzohocreator.com'>LoZC</a></p></td>") + "</tr></table>";
                        if (zoho.loginuser  !=  zoho.adminuser)
                        {
                            app = "Zoodle";
                            // REPLACE value with name of this application.
                            frm = "Welcome";
                            // REPLACE value with the name of this form.
                            usr = zoho.loginuser;
                            // The username of the current ZC user.
                            tst = zoho.currenttime.toLong();
                            // A timestamp of the current time.
                            log_entry = "Entry String : " + "App" + "|" + app + "*" + "Form" + "|" + frm + "*" + "User" + "|" + usr + "*" + "Time" + "|" + tst;
                            sendmail
                            (
                                To       :  "lozc-376@forms.zohocreator.com" 
                                From     :  zoho.adminuserid 
                                Subject  :  "Log Entry" 
                                Message  :  log_entry 
                            )
                        }
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Feed
        {
            
            feed_display
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    on load
                    {
                        input.feed_display = "<p style='color:#006'>This page links to your current " + "<a href='http://creator.zoho.com/lozc/tsv/32/235td4eOB47D6RfJMmRVE7HJdDU4hxhWTAEn44sKKEgv3v1RtNtweHf9bpSJfPH0DBzNmkhhwq2k6vp2jPggRmU8RqeZCsS0Qv0C/'>XML feed</a>.  Oodle can visit it to receive your latest updates.</p>";
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

    }

    section Create
    {
        form  create_help
        {
            displayname  =  "Help"
            
            help_display
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    on load
                    {
                        input.help_display = (((((("<table cellpadding='10' border='0'><tr><td style='background-color: #bcf;border:dashed 1px #63f;'") + " valign='top'><h3 style='color:#006' align='center'>Create listings</h3><p style='color:#006'><ol style='color:#006'><li>Add <em>New</em> listings</li>") + "<li>Complete them by filling out <em>Location</em>, <em>Attribute</em>, and <em>Seller Info</em></li>") + "</ol></td>") + "<td valign='top'><h3 align='center'><img src='/DownloadFile.do?filepath=/1195244089042_zoodle.png&sharedBy=lozc'/></h3><br/>") + "</td>") + "</tr></table>";
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Essentials
        {
            displayname  =  "1. New"
            success message  =  "Essential info added."
            
            column
            {
                unique_id_display
                (
                    type  =  plaintext
                )

                must  have  title
                (
                    displayname  =  "Title"
                    type  =  text
                    on user input
                    {
                        input.listing_label = input.unique_id + ":" + input.title;
                    }
                )

                must  have  price
                (
                    displayname  =  "Price $"
                    type  =  USD
                    width  =  20
                )

                must  have  description
                (
                    displayname  =  "Description"
                    type  =  textarea
                )

                must  have  condition
                (
                    displayname  =  "Condition"
                    type  =  picklist
                    values  =  {"pre-construction",   "new",   "existing"}
                )

                must  have  listing_expires
                (
                    displayname  =  "Listing Expires"
                    type  =  datetime
                )

                must  have  status
                (
                    displayname  =  "Status"
                    type  =  radiobuttons
                    values  =  {"incomplete",   "ready",   "published"}
                    defaultvalue  =  "incomplete"
                )

            }
            column
            {
                must  have  photo_1
                (
                    displayname  =  "Photo 1"
                    type = upload file
                )

                must  have  photo_1_cap
                (
                    displayname  =  "Caption"
                    type  =  text
                )

                photo_bar_1
                (
                    type  =  plaintext
                )

                photo_2
                (
                    displayname  =  "Photo 2"
                    type = upload file
                )

                photo_2_cap
                (
                    displayname  =  "Caption"
                    type  =  text
                )

                photo_bar_2
                (
                    type  =  plaintext
                )

                photo_3
                (
                    displayname  =  "Photo 3"
                    type = upload file
                )

                photo_3_cap
                (
                    displayname  =  "Caption"
                    type  =  text
                )

                photos_display
                (
                    displayname  =  "Photos Display"
                    type  =  textarea
                )

                captions_display
                (
                    displayname  =  "Captions Display"
                    type  =  textarea
                )

                must  have  unique_id
                (
                    displayname  =  "Unique ID"
                    type  =  text
                    width  =  20
                )

                must  have  listing_label
                (
                    displayname  =  "Label"
                    type  =  text
                )

                public_link
                (
                    displayname  =  "Public Link"
                    type  =  text
                )

                public_url
                (
                    displayname  =  "Public URL"
                    type  =  text
                )

                image_url
                (
                    type  =  formula
                    value  =  "http://creator.zoho.com/DownloadFile.do?filepath=/" + photo_1 + "&amp;sharedBy=" + zoho.adminuser
                )

            }
            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        hide listing_label;
                        hide status;
                        hide photos_display;
                        hide captions_display;
                        hide public_link;
                        hide public_url;
                        uid  =  seed_unique_id  [unique_id != 0];
                        current_uid = (uid.unique_id  +  1);
                        uid.unique_id = current_uid;
                        input.unique_id_display = "<p><em>Unique ID for this listing will be <strong>" + uid.prefix + current_uid + "</strong></em></p>";
                        input.unique_id = uid.prefix + current_uid;
                        input.photo_bar_1 = "<h3>_____</h3>";
                        input.photo_bar_2 = "<h3>_____</h3>";
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            e  =  Essentials  [ID == input.ID];
                            p_buffer = ("<img width='50' height='50' src='/DownloadFile.do?filepath=/" + e.photo_1 + "&sharedBy=" + zoho.adminuser) + "'/>";
                            c_buffer = e.photo_1_cap + "<br/>";
                            if (e.photo_2  !=  "")
                            {
                                p_buffer = (p_buffer + "<img width='50' height='50' src='/DownloadFile.do?filepath=/" + e.photo_2 + "&sharedBy=" + zoho.adminuser) + "'/>";
                            }
                            if (e.photo_3  !=  "")
                            {
                                p_buffer = (p_buffer + "<img width='50' height='50' src='/DownloadFile.do?filepath=/" + e.photo_3 + "&sharedBy=" + zoho.adminuser) + "'/>";
                            }
                            if (e.photo_2_cap  !=  "")
                            {
                                c_buffer = c_buffer + e.photo_2_cap + "<br/>";
                            }
                            if (e.photo_3_cap  !=  "")
                            {
                                c_buffer = c_buffer + e.photo_3_cap;
                            }
                            input.photos_display = p_buffer;
                            input.captions_display = c_buffer;
                            input.public_url = ((("http://creator.zoho.com/showForm.do?formLinkId=375&amp;link=true&amp;sharedBy=" + zoho.adminuser) + "&amp;unique_id=") + e.unique_id) + "&amp;privatelink=8MaPCqGewjtkSDnnTr6zfgMkyVB0JYVN3Yvn4wxCkr1FWJteO7RvOEyAWm9vp0NSw9k85WtFbykSXfO8SxqAyOTbOV1GyW7XJvE7";
                            input.public_link = ((("<a href='http://creator.zoho.com/showForm.do?formLinkId=375&amp;link=true&amp;sharedBy=" + zoho.adminuser) + "&amp;unique_id=") + e.unique_id) + "&amp;privatelink=P8MaPCqGewjtkSDnnTr6zfgMkyVB0JYVN3Yvn4wxCkr1FWJteO7RvOEyAWm9vp0NSw9k85WtFbykSXfO8SxqAyOTbOV1GyW7XJvE7'>[public link]</a>";
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    on load
                    {
                        hide captions_display;
                        hide photos_display;
                        hide unique_id;
                    }
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                        on validate
                        {
                            e  =  Essentials  [ID == input.ID];
                            if (input.ID  !=  e.ID)
                            {
                                alert "The unique ID cannot be edited.";
                                cancel submit;
                            }
                        }
                        on success
                        {
                            e  =  Essentials  [ID == input.ID];
                            p_buffer = ("<img width='50' height='50' src='/DownloadFile.do?filepath=/" + e.photo_1 + "&sharedBy=" + zoho.adminuser) + "'/>";
                            c_buffer = e.photo_1_cap + "<br/>";
                            if (e.photo_2  !=  "")
                            {
                                p_buffer = (p_buffer + "<img width='50' height='50' src='/DownloadFile.do?filepath=/" + e.photo_2 + "&sharedBy=" + zoho.adminuser) + "'/>";
                            }
                            if (e.photo_3  !=  "")
                            {
                                p_buffer = (p_buffer + "<img width='50' height='50' src='/DownloadFile.do?filepath=/" + e.photo_3 + "&sharedBy=" + zoho.adminuser) + "'/>";
                            }
                            if (e.photo_2_cap  !=  "")
                            {
                                c_buffer = c_buffer + e.photo_2_cap + "<br/>";
                            }
                            if (e.photo_3_cap  !=  "")
                            {
                                c_buffer = c_buffer + e.photo_3_cap;
                            }
                            input.photos_display = p_buffer;
                            input.captions_display = c_buffer;
                            input.public_url = ((("http://creator.zoho.com/showForm.do?formLinkId=375&amp;link=true&amp;sharedBy=" + zoho.adminuser) + "&amp;unique_id=") + e.unique_id) + "&amp;privatelink=8MaPCqGewjtkSDnnTr6zfgMkyVB0JYVN3Yvn4wxCkr1FWJteO7RvOEyAWm9vp0NSw9k85WtFbykSXfO8SxqAyOTbOV1GyW7XJvE7";
                            input.public_link = ((("<a href='http://creator.zoho.com/showForm.do?formLinkId=375&amp;link=true&amp;sharedBy=" + zoho.adminuser) + "&amp;unique_id=") + e.unique_id) + "&amp;privatelink=P8MaPCqGewjtkSDnnTr6zfgMkyVB0JYVN3Yvn4wxCkr1FWJteO7RvOEyAWm9vp0NSw9k85WtFbykSXfO8SxqAyOTbOV1GyW7XJvE7'>[public link]</a>";
                        }
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Location
        {
            displayname  =  "2. Add Location"
            success message  =  "Location info added."
            
            must  have  essentials_dropdown
            (
                displayname  =  "For which listing?"
                type  =  picklist
                values  =  {"Option 1",   "Option 2",   "Option 3",   "Current",   "BRRE200702:Perfect for the Modern Couple!",   "BRRE2007001:Perfect for the Modern Couple!",   "BRRE2007019:Colorado Luxury Home",   "BRRE2007038:joe",   "BRRE2007066:Jeff",   "BRRE2007070:test helloworld",   "BRRE2007086:1",   "BRRE2007091:Test",   "BRRE2007114:Canon a460"}
                on user input
                {
                    e  =  Essentials  [listing_label == input.essentials_dropdown];
                    input.unique_id = e.unique_id;
                    buffer = "<p><strong>Essentials</strong>:</p><ul><li><strong>Description</strong>: " + e.description + "</li><li><strong>Condition</strong>: " + e.condition + "</li><li><strong>Price</strong>: " + e.price + "</li><li><strong>Expires</strong>: " + e.listing_expires + "</li></ul>";
                    for each a in Attributes  [unique_id == e.unique_id]
                    {
                        buffer = (((((buffer + "<p><strong>Attributes</strong>:</p><ul><li><strong>Year Built</strong>: " + a.year_built + "</li><li><strong>Square Ft</strong>: " + a.square_feet + "</li><li><strong>Lot Size</strong>: " + a.lot_size) + "</li><li><strong>Bedrooms</strong>: ") + a.bedrooms) + "</li><li><strong>Bathrooms</strong>: ") + a.bathrooms) + "</li></ul>";
                    }
                    for each s in Seller_Info  [unique_id == e.unique_id]
                    {
                        buffer = buffer + "<p><strong>Seller Info</strong>:</p><ul><li><strong>Agent name</strong>: " + s.agent_name + "</li><li><strong>MLS ID</strong>: " + s.mls_id + "</li><li><strong>Seller type</strong>: " + s.seller_type + "</li></ul>";
                    }
                    input.saved_display = buffer;
                }
            )

            saved_display
            (
                type  =  plaintext
            )

            must  have  address
            (
                displayname  =  "Address"
                type  =  text
            )

            neighborhood
            (
                displayname  =  "Neighborhood"
                type  =  text
            )

            must  have  city
            (
                displayname  =  "City"
                type  =  text
            )

            must  have  state
            (
                displayname  =  "State"
                type  =  picklist
                values  =  {"AL",   "AK",   "AS",   "AZ",   "AR",   "CA",   "CO",   "CT",   "DE",   "DC",   "FM",   "FL",   "GA",   "GU",   "HI",   "ID",   "IL",   "IN",   "IA",   "KS",   "KY",   "LA",   "ME",   "MH",   "MD",   "MA",   "MI",   "MN",   "MS",   "MO",   "MT",   "NE",   "NV",   "NH",   "NJ",   "NM",   "NY",   "NC",   "ND",   "MP",   "OH",   "OK",   "OR",   "PW",   "PA",   "PR",   "RI",   "SC",   "SD",   "TN",   "TX",   "UT",   "VT",   "VI",   "VA",   "WA",   "WV",   "WI",   "WY"}
                defaultvalue  =  "AL"
            )

            must  have  zip_code
            (
                displayname  =  "Zip Code"
                type  =  text
            )

            must  have  unique_id
            (
                displayname  =  "Unique ID"
                type  =  text
                width  =  20
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        essentials_dropdown:ui.add("-Select-");
                        total_records = 0;
                        for each e in Essentials
                        {
                            if ((count(Location[unique_id == e.unique_id])  ==  0)  &&  (e.status  ==  "incomplete"))
                            {
                                essentials_dropdown:ui.add(e.listing_label);
                                total_records = (total_records  +  1);
                            }
                        }
                        if (total_records  ==  0)
                        {
                            hide essentials_dropdown;
                            hide address;
                            hide neighborhood;
                            hide state;
                            hide city;
                            hide zip_code;
                            input.saved_display = "<em>No listings are in need of location info.<ul><li>To add a new listing use form 1. New</li>" + "<li>To add attribute info use form 3. Add Attributes</li>" + "<li>To add seller info use form 4. Add Seller Info</li></ul></em>";
                        }
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    on load
                    {
                        hide unique_id;
                        hide essentials_dropdown;
                        essentials_dropdown:ui.add("Current");
                    }
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                        on validate
                        {
                            l  =  Location  [ID == input.ID];
                            if (input.ID  !=  l.ID)
                            {
                                alert "The unique ID cannot be edited.";
                                cancel submit;
                            }
                        }
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Attributes
        {
            displayname  =  "3. Add Attributes"
            success message  =  "Attributes info added."
            
            must  have  essentials_dropdown
            (
                displayname  =  "For which listing?"
                type  =  picklist
                values  =  {"Option 1",   "Option 2",   "Option 3",   "BRRE2007001:Perfect for the Modern Couple!",   "BRRE2007019:Colorado Luxury Home",   "BRRE2007038:joe",   "BRRE2007066:Jeff",   "BRRE2007070:test helloworld",   "BRRE2007086:1",   "BRRE2007091:Test",   "BRRE2007114:Canon a460"}
                on user input
                {
                    e  =  Essentials  [listing_label == input.essentials_dropdown];
                    input.unique_id = e.unique_id;
                    buffer = "<p><strong>Essentials</strong>:</p><ul><li><strong>Description</strong>: " + e.description + "</li><li><strong>Condition</strong>: " + e.condition + "</li><li><strong>Price</strong>: " + e.price + "</li><li><strong>Expires</strong>: " + e.listing_expires + "</ul>";
                    for each l in Location  [unique_id == e.unique_id]
                    {
                        buffer = buffer + "<p><strong>Location Info</strong>:</p><ul><li><strong>Address</strong>: " + l.address + "</li><li><strong>Neighborhood</strong>: " + l.neighborhood + "</li><li><strong>City</strong>: " + l.city + "</li><li><strong>State</strong>: " + l.state + "</li><li><strong>Zip Code</strong>: " + l.zip_code + "</li></ul>";
                    }
                    for each s in Seller_Info  [unique_id == e.unique_id]
                    {
                        buffer = buffer + "<p><strong>Seller Info</strong>:</p><ul><li><strong>Agent name</strong>: " + s.agent_name + "</li><li><strong>MLS ID</strong>: " + s.mls_id + "</li><li><strong>Seller type</strong>: " + s.seller_type + "</li></ul>";
                    }
                    input.saved_display = buffer;
                }
            )

            saved_display
            (
                type  =  plaintext
            )

            must  have  year_built
            (
                displayname  =  "Year Built"
                type  =  number
                width  =  20
            )

            must  have  square_feet
            (
                displayname  =  "Square Feet"
                type  =  decimal
                width  =  20
            )

            must  have  lot_size
            (
                displayname  =  "Lot Size"
                type  =  text
                width  =  20
            )

            must  have  bedrooms
            (
                displayname  =  "Bedrooms"
                type  =  picklist
                values  =  {"1",   "2",   "3",   "4",   "5",   "6",   "7",   "8",   "9",   "10",   "11",   "12",   "14",   "15",   "16",   "17",   "18",   "19",   "20"}
                defaultvalue  =  "1"
            )

            must  have  bathrooms
            (
                displayname  =  "Bathrooms"
                type  =  picklist
                values  =  {".5",   ".75",   "1",   "1.5",   "1.75",   "2",   "2.5",   "2.75",   "3",   "3.5",   "3.75",   "4",   "4.5",   "4.75",   "5"}
                defaultvalue  =  ".5"
            )

            must  have  unique_id
            (
                displayname  =  "Unique ID"
                type  =  text
                width  =  20
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        essentials_dropdown:ui.add("-Select-");
                        total_records = 0;
                        for each e in Essentials
                        {
                            if ((count(Attributes[unique_id == e.unique_id])  ==  0)  &&  (e.status  ==  "incomplete"))
                            {
                                essentials_dropdown:ui.add(e.listing_label);
                                total_records = (total_records  +  1);
                            }
                        }
                        if (total_records  ==  0)
                        {
                            hide essentials_dropdown;
                            hide bathrooms;
                            hide bedrooms;
                            hide lot_size;
                            hide square_feet;
                            hide year_built;
                            input.saved_display = "<em>No listings are in need of attribute info.<ul><li>To add a new listing use form 1. New</li>" + "<li>To add location info use form 2. Add Location</li>" + "<li>To add seller info use form 4. Add Seller Info</li></ul></em>";
                        }
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    on load
                    {
                        hide unique_id;
                        hide essentials_dropdown;
                        essentials_dropdown:ui.add("Current");
                    }
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                        on validate
                        {
                            a  =  Attributes  [ID == input.ID];
                            if (input.ID  !=  a.ID)
                            {
                                alert "The unique ID cannot be edited.";
                                cancel submit;
                            }
                        }
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Seller_Info
        {
            displayname  =  "4. Add Seller Info"
            success message  =  "Seller info added."
            
            must  have  essentials_dropdown
            (
                displayname  =  "For which listing?"
                type  =  picklist
                values  =  {"Option 1",   "Option 2",   "Option 3",   "BRRE2007001:Perfect for the Modern Couple!",   "BRRE2007019:Colorado Luxury Home",   "BRRE2007038:joe",   "BRRE2007066:Jeff",   "BRRE2007070:test helloworld",   "BRRE2007086:1",   "BRRE2007114:Canon a460"}
                on user input
                {
                    e  =  Essentials  [listing_label == input.essentials_dropdown];
                    input.unique_id = e.unique_id;
                    buffer = "<p><strong>Essentials</strong>:</p><ul><li><strong>Description</strong>: " + e.description + "</li><li><strong>Condition</strong>: " + e.condition + "</li><li><strong>Price</strong>: " + e.price + "</li><li><strong>Expires</strong>: " + e.listing_expires + "</li></ul>";
                    for each l in Location  [unique_id == e.unique_id]
                    {
                        buffer = buffer + "<p><strong>Location Info</strong>:</p><ul><li><strong>Address</strong>: " + l.address + "</li><li><strong>Neighborhood</strong>: " + l.neighborhood + "</li><li><strong>City</strong>: " + l.city + "</li><li><strong>State</strong>: " + l.state + "</li><li><strong>Zip Code</strong>: " + l.zip_code + "</li></ul>";
                    }
                    for each a in Attributes  [unique_id == e.unique_id]
                    {
                        buffer = (((((buffer + "<p><strong>Attribute Info</strong>:</p><ul><li><strong>Year Built</strong>: " + a.year_built + "</li><li><strong>Square Ft</strong>: " + a.square_feet + "</li><li><strong>Lot Size</strong>: " + a.lot_size) + "</li><li><strong>Bedrooms</strong>: ") + a.bedrooms) + "</li><li><strong>Bathrooms</strong>: ") + a.bathrooms) + "</li></ul>";
                    }
                    input.saved_display = buffer;
                }
            )

            saved_display
            (
                type  =  plaintext
            )

            must  have  agent_name
            (
                displayname  =  "Agent Name"
                type  =  text
            )

            must  have  agent_email
            (
                displayname  =  "Agent Email"
                type  =  email
            )

            must  have  broker_name
            (
                displayname  =  "Broker Name"
                type  =  text
            )

            mls_id
            (
                displayname  =  "MLS#"
                type  =  text
            )

            must  have  seller_type
            (
                displayname  =  "Seller Type"
                type  =  picklist
                values  =  {"agent",   "broker",   "builder",   "by owner",   "foreclosure"}
                defaultvalue  =  "agent"
            )

            must  have  unique_id
            (
                displayname  =  "Unique ID"
                type  =  text
                width  =  20
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        essentials_dropdown:ui.add("-Select-");
                        total_records = 0;
                        for each e in Essentials
                        {
                            if ((count(Seller_Info[unique_id == e.unique_id])  ==  0)  &&  (e.status  ==  "incomplete"))
                            {
                                essentials_dropdown:ui.add(e.listing_label);
                                total_records = (total_records  +  1);
                            }
                        }
                        if (total_records  ==  0)
                        {
                            hide essentials_dropdown;
                            hide agent_name;
                            hide agent_email;
                            hide broker_name;
                            hide mls_id;
                            hide seller_type;
                            input.saved_display = "<em>No listings are in need of seller info.<ul><li>To add a new listing use form 1. New</li>" + "<li>To add location info use form 2. Add Location</li>" + "<li>To add attribute info use form 3. Add Attributes</li></ul></em>";
                        }
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    on load
                    {
                        hide unique_id;
                        hide essentials_dropdown;
                        essentials_dropdown:ui.add("Current");
                    }
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                        on validate
                        {
                            s  =  Seller_Info  [ID == input.ID];
                            if (input.ID  !=  s.ID)
                            {
                                alert "The unique ID cannot be edited.";
                                cancel submit;
                            }
                        }
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

    }

    section View
    {
        form  view_help
        {
            displayname  =  "Help"
            
            help_display
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    on load
                    {
                        input.help_display = ((((("<table cellpadding='10' border='0'><tr><td style='background-color: #bcf;border:dashed 1px #63f;'") + " valign='top'><h3 style='color:#006' align='center'>View listings</h3><p style='color:#006'>Access listing details by browsing <em>Main</em>,") + " <em>Location</em>, <em>Attributes</em>, and <em>Seller Info</em>.</p>") + "</td>") + "<td valign='top'><p align='center'><img src='/DownloadFile.do?filepath=/1195244089042_zoodle.png&sharedBy=lozc'/></p></td>") + "</tr></table>";
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Main
        {
            displayname = "1. Main"
            show  all  rows  from  Essentials 
            (
                unique_id as "Unique ID"
                title as "Title"
                description as "Description"
                price as "Price $"
                condition as "Condition"
                listing_expires as "Listing Expires"
                status as "Status"
                photos_display as "Photos Display"
                captions_display as "Captions Display"
                public_link as "Detail Page"
            )
            options
            (
                display rows = 100
            )
        }

        list  Location
        {
            displayname = "2. Location"
            show  all  rows  from  Location 
            (
                unique_id as "Unique ID"
                address as "Address"
                city as "City"
                neighborhood as "Neighborhood"
                state as "State"
                zip_code as "Zip Code"
            )
            options
            (
                display rows = 100
            )
        }

        list  Attributes
        {
            displayname = "3. Attributes"
            show  all  rows  from  Attributes 
            (
                unique_id as "Unique ID"
                year_built as "Year Built"
                square_feet as "Square Feet"
                lot_size as "Lot Size"
                bedrooms as "Bedrooms"
                bathrooms as "Bathrooms"
            )
            options
            (
                display rows = 100
            )
        }

        list  Seller_Info
        {
            displayname = "4. Seller Info"
            show  all  rows  from  Seller_Info 
            (
                unique_id as "Unique ID"
                agent_name as "Agent Name"
                broker_name as "Broker Name"
                mls_id as "MLS#"
                seller_type as "Seller Type"
            )
            options
            (
                display rows = 100
            )
        }

    }

    section Publish
    {
        form  publish_help
        {
            displayname  =  "Help"
            
            help_display
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    on load
                    {
                        input.help_display = (((((("<table cellpadding='10' border='0'><tr><td style='background-color: #bcf;border:dashed 1px #63f;' valign='top'>") + "<h3 style='color:#006' align='center'>Publish listings</h3><p style='color:#006'>") + "Update your Oodle real estate feed with the latest listings</p>") + "</td>") + "<td valign='top'><p align='center'><img src='/DownloadFile.do?filepath=/1195244089042_zoodle.png&sharedBy=lozc'/></p>") + "</td>") + "</tr></table>";
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        form  Publish
        {
            success message  =  "Updated Oodle XML feed."
            
            ready_instructions
            (
                type  =  plaintext
            )

            noop
            (
                displayname  =  "NOOP"
                type  =  checkbox
                defaultvalue  =  false
            )

            listings_ready
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide noop;
                        buffer = "";
                        total_count = 0;
                        for each e in Essentials  [(unique_id != "" && (status == "incomplete" || status == "ready"))]
                        {
                            lC = count(Location[unique_id == e.unique_id]);
                            aC = count(Attributes[unique_id == e.unique_id]);
                            sC = count(Seller_Info[unique_id == e.unique_id]);
                            if (((lC  >  0)  &&  (aC  >  0))  &&  (sC  >  0))
                            {
                                total_count = (total_count  +  1);
                                if (total_count  ==  1)
                                {
                                    input.ready_instructions = "<em>The following listings are ready to to publish.  Click submit to update your Oodle feed.</em>";
                                    buffer = "<ul>";
                                }
                                buffer = buffer + "<li>" + e.listing_label + "</li>";
                                if (e.status  ==  "incomplete")
                                {
                                    e.status = "ready";
                                }
                                if (total_count  ==  1)
                                {
                                    buffer = buffer + "</ul>";
                                }
                            }
                        }
                        if (total_count  >  0)
                        {
                            input.listings_ready = buffer;
                        }
                        else
                        {
                            input.ready_instructions = "<em>At least one listing must be ready if you want to publish. </em>";
                        }
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            xml = "<listings>";
                            for each e in Essentials  [(status == "ready" || status == "published")]
                            {
                                this_id = e.unique_id;
                                l  =  Location  [unique_id == this_id];
                                a  =  Attributes  [unique_id == this_id];
                                s  =  Seller_Info  [unique_id == this_id];
                                xml = ((((((((((((((((((xml + "<listing><category>Homes For Sale</category><id>" + e.unique_id + "</id><title>" + e.title + "</title><url>" + e.public_url + "</url><address>" + l.address + "</address><city>" + l.city + "</city><country>US</country><neighborhood>") + l.neighborhood) + "</neighborhood><state>") + l.state) + "</state><zip_code>") + l.zip_code) + "</zip_code><agent>") + s.agent_name) + "</agent><bathrooms>") + a.bathrooms) + "</bathrooms><bedrooms>") + a.bedrooms) + "</bedrooms><broker>") + s.broker_name) + "</broker><condition>") + e.condition) + "</condition><create_time>") + zoho.currenttime) + "</create_time>";
                                xml = ((((((((((((xml + "<currency>USD</currency><description>" + e.description + "</description><expire_time>" + e.listing_expires + "</expire_time><image_url>" + e.image_url + "</image_url><lot_size>") + a.lot_size) + "</lot_size><mls_id>") + s.mls_id) + "</mls_id><price>") + e.price) + "</price><seller_type>") + s.seller_type) + "</seller_type><square_feet>") + a.square_feet) + "</square_feet><year_built>") + a.year_built) + "</year_built></listing>";
                                if (e.status  ==  "ready")
                                {
                                    e.status = "published";
                                }
                            }
                            xml = xml + "</listings>";
                            cx  =  Custom_XML  [ID != 0];
                            cx.xml_blob = xml;
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

    }

    section ADMIN
    {
        displayname = "__ADMIN"
        hide = true
        form  seed_unique_id
        {
            displayname  =  "Seed Unique ID"
            success message  =  "Unique ID Seeded."
            
            must  have  unique_id
            (
                displayname  =  "Unique ID"
                type  =  number
                width  =  20
            )

            prefix
            (
                displayname  =  "Prefix (optional)"
                type  =  text
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on validate
                        {
                            if (count(seed_unique_id[unique_id != 0])  >  0)
                            {
                                alert (("The seed record already exists.   If you wish to reset the starting values please either: ") + "<br/> <strong>(1)</strong> Delete the existing record and recreate it with new values or ") + "<br/><strong>(2)</strong> Update its existing values in the View using the <strong>Bulk Edit</strong> feature.";
                                cancel submit;
                            }
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Seed_Unique_ID
        {
            displayname = "Seed Unique ID"
            show  all  rows  from  seed_unique_id 
            (
                unique_id as "Unique ID"
            )
            options
            (
                display rows = 100
            )
        }

        form  Custom_XML
        {
            displayname  =  "Custom XML"
            success message  =  "Custom XML updated."
            
            xml_blob
            (
                displayname  =  "<?xml version=\"1.0\" ?>"
                type  =  textarea
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on validate
                        {
                            if (count(Custom_XML[ID != 0])  >  0)
                            {
                                cx  =  Custom_XML  [ID != 0];
                                cx.xml_blob = input.xml_blob;
                                cancel submit;
                            }
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Custom_XML_View
        {
            displayname = "Custom XML View"
            show  all  rows  from  Custom_XML 
            (
                xml_blob as "<?xml version='1.0' ?>"
            )
            options
            (
                display rows = 100
            )
        }

        form  Detail_page
        {
            displayname  =  "Detail page"
            success message  =  "Message sent to agent."
            
            column
            {
                detail_left
                (
                    type  =  plaintext
                )

                must  have  unique_id
                (
                    displayname  =  "Unique ID"
                    type  =  text
                    width  =  20
                )

            }
            column
            {
                detail_right
                (
                    type  =  plaintext
                )

            }
            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        e  =  Essentials  [unique_id == input.unique_id];
                        l  =  Location  [unique_id == input.unique_id];
                        a  =  Attributes  [unique_id == input.unique_id];
                        s  =  Seller_Info  [unique_id == input.unique_id];
                        left_buffer = (((((((((((((((((((((((((((((((((((((((((((((((((((((((("<div style='background-color: #fff;border:solid 1px #63f;padding:10px;'><img src='http://creator.zoho.com/DownloadFile.do?filepath=/1195329979516_extender.png&sharedBy=lozc'/>") + "<h3 style='color:#006' align='center'>Details</h3>") + "<ul><li><strong>Year Built</strong>:  ") + a.year_built) + "</li>") + "<li><strong>Condition</strong>:  ") + e.condition) + "</li>") + "<li><strong>Square Feet</strong>:  ") + a.square_feet) + "</li>") + "<li><strong>Lot Size</strong>:  ") + a.lot_size) + "</li>") + "<li><strong>Bedrooms</strong>:  ") + a.bedrooms) + "</li>") + "<li><strong>Bathrooms</strong>:  ") + a.bathrooms) + "</li>") + "<li><strong>Price</strong>:  ") + e.price) + "</li>") + "<li><strong>Address</strong>:  ") + l.address) + "</li>") + "<li><strong>Neighborhood</strong>:  ") + l.neighborhood) + "</li>") + "<li><strong>City</strong>:  ") + l.city) + "</li>") + "<li><strong>State</strong>:  ") + l.state) + "</li>") + "<li><strong>Zip</strong>:  ") + l.zip_code) + "</li>") + "<li><strong>Listing Posted</strong>:") + s.Added_Time) + "</li>") + "<li><strong>Listing Expires</strong>:  ") + e.listing_expires) + "</li>") + "<li><strong>Agent</strong>:  ") + s.agent_name) + "</li>") + "<li><strong>Broker</strong>:  ") + s.broker_name) + "</li>") + "<li><strong>Seller Type</strong>:  ") + s.seller_type) + "</li>") + "<li><strong>MLS #</strong>:  ") + s.mls_id) + "</li>") + "</ul></div>";
                        // ##>
                        right_buffer = ((((((((((((("<div style='background-color: #fff;border:solid 1px #63f;padding:10px;'") + " valign='top'><h2 style='color:#006' align='center'>") + e.title) + " </h3>") + "<img src='/DownloadFile.do?filepath=/") + e.photo_1) + "&sharedBy=") + zoho.adminuser) + "'/><p align='center'>") + e.photo_1_cap) + "</p>") + "<p><strong>Description:</strong>  ") + e.description) + "</p>";
                        if (e.photo_2  !=  "")
                        {
                            right_buffer = right_buffer + "<p><strong>More Photos:</strong></p>";
                            right_buffer = (right_buffer + "<img src='/DownloadFile.do?filepath=/" + e.photo_2 + "&sharedBy=" + zoho.adminuser) + "'/>";
                        }
                        if (e.photo_2_cap  !=  "")
                        {
                            right_buffer = right_buffer + "<p align='center'>" + e.photo_2_cap + "</p>";
                        }
                        if (e.photo_3  !=  "")
                        {
                            right_buffer = (right_buffer + "<img src='/DownloadFile.do?filepath=/" + e.photo_3 + "&sharedBy=" + zoho.adminuser) + "'/>";
                        }
                        if (e.photo_3_cap  !=  "")
                        {
                            right_buffer = right_buffer + "<p align='center'>" + e.photo_3_cap + "</p>";
                        }
                        left_buffer = left_buffer + "</div>";
                        input.detail_left = left_buffer;
                        input.detail_right = right_buffer;
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on validate
                        {
                            cancel submit;
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

    }

}
