/*
 * Author       : lozc
 * Generated on : 23-Nov-2009 03:27:07
 * Version      : 3.0
 */
application "Zyndafeed v0.02"
{
    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
                    {
                        // $Id$
                        // $Date$
                        // $Revision$
                        // $HeadURL$
                        // $Author$
                        logging = true;
                        input.welcome_display = (((((((("<table cellpadding='10' border='0'><tr><td style='background-color: #bcf;border:dashed 1px #63f;'") + " valign='top'><p style='color:#006'>") + "Zyndafeed lets you manage your <a href='http://www.syndafeed.com'>Syndafeed</a> <a href='http://www.syndafeed.com/display.php?id=0001&title=What%20You%20Get&newcnt=1'>real estate listings</a> with Zoho Creator.  ") + "<p style='color:#006'>To get started with Zyndafeed, <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'>Zyndafeed</h3><br/>") + "<h3 align='center'>v0.02</h3><p align='center'>pete at <a href='http://landofzohocreator.com'>LoZC</a></p></td>") + "</tr></table>";
                        if (logging  &&  (zoho.loginuser  !=  zoho.adminuser))
                        {
                            app = "Zyndafeed 0.02";
                            // 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.
                            // Your logging app's form on load {} action can store this string any way it wants.
                            // See http://landofzohocreator.com/2007/07/23/when-guests-arrive/ for an example.
                            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/69/hz9bB1yaH3MJ9Z2zAe2n9TQwYVJz0DCFB7Qf8AmRXS2CGSVnzze6CFYUft4tJbj679b971spE1RHFtevVHuMsn02BRu1xWxE4r8d//'>XML feed</a>.  Syndafeed can poll 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>, <em>Photo</em> and <em>Seller Info</em></li>") + "</ol></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."
            
            unique_id_display
            (
                type  =  plaintext
            )

            must  have  title
            (
                displayname  =  "Title"
                type  =  text
                tooltip  =  "Provide a title for this listing."
                on user input
                {
                    input.listing_label = input.unique_id + ":" + input.title;
                }
            )

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

            must  have  property_type
            (
                displayname  =  "Property Type"
                type  =  picklist
                values  =  {"Single Family",   "Condominium",   "Duplex",   "Land",   "Commercial",   "Townhome"}
                defaultvalue  =  "Single Family"
            )

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

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

            must  have  unique  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
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        hide listing_label;
                        hide status;
                        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;
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            ampsToReplaceTotal = (input.description).getOccurenceCount("&");
                            if (ampsToReplaceTotal  >  0)
                            {
                                raw = input.description;
                                processed = "";
                                for each j in Iterations  [iteration < ampsToReplaceTotal]
                                {
                                    pre = raw.getPrefix("&");
                                    post = raw.getSuffix("&");
                                    processed = processed + pre + "&";
                                    if ((post).getOccurenceCount("&")  >  0)
                                    {
                                        raw = post;
                                    }
                                    else
                                    {
                                        processed = processed + post;
                                    }
                                }
                                input.description = processed;
                            }
                            input.public_url = ((("http://creator.zoho.com/showForm.do?formLinkId=945&amp;link=true&amp;sharedBy=" + zoho.adminuser) + "&amp;unique_id=") + input.unique_id) + "&amp;privatelink=hDpKnhyUV4q4yKQAZW9zyjAT6KFwendkz969bpMXXJPguUUYJ7mymUW75hFMAXEpfRwEU3Z2TtwBtedbpUfJ3EpKJVS2fhkVhOZa";
                            input.public_link = ((("<a href='http://creator.zoho.com/showForm.do?formLinkId=945&link=true&sharedBy=" + zoho.adminuser) + "&unique_id=") + input.unique_id) + "&privatelink=hDpKnhyUV4q4yKQAZW9zyjAT6KFwendkz969bpMXXJPguUUYJ7mymUW75hFMAXEpfRwEU3Z2TtwBtedbpUfJ3EpKJVS2fhkVhOZa'>[public link]</a>";
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    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];
                            ampsToReplaceTotal = (input.description).getOccurenceCount("&");
                            if (ampsToReplaceTotal  >  0)
                            {
                                raw = input.description;
                                processed = "";
                                for each j in Iterations  [iteration < ampsToReplaceTotal]
                                {
                                    pre = raw.getPrefix("&");
                                    post = raw.getSuffix("&");
                                    processed = processed + pre + "&";
                                    if ((post).getOccurenceCount("&")  >  0)
                                    {
                                        raw = post;
                                    }
                                    else
                                    {
                                        processed = processed + post;
                                    }
                                }
                                input.description = processed;
                            }
                            input.public_url = ((("http://creator.zoho.com/showForm.do?formLinkId=608&amp;link=true&amp;sharedBy=" + zoho.adminuser) + "&amp;unique_id=") + e.unique_id) + "&amp;privatelink=D96EdYb4Zf7YCuvT5PBDQfPZEO5OA7A7dgh4tEsW268p6R44s1gUCvDUqbqG1CV0GeknRbMn3EytGP05ANUVjZPeJCChvuCKENBN";
                            input.public_link = ((("<a href='http://creator.zoho.com/showForm.do?formLinkId=608&link=true&sharedBy=" + zoho.adminuser) + "&unique_id=") + e.unique_id) + "&privatelink=D96EdYb4Zf7YCuvT5PBDQfPZEO5OA7A7dgh4tEsW268p6R44s1gUCvDUqbqG1CV0GeknRbMn3EytGP05ANUVjZPeJCChvuCKENBN'>[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  =  {"-Select-",   "ZYND2007002:kpolh",   "ZYND2007006:refaddafs",   "SYND200700001:THis is a test listing",   "SYND200700001:A test listing!",   "SYND200700005:A Nice Houses",   "SYND200700012:dfasafdsfdsafdasdafsadfs",   "SYND200700016:Perfect for the Modern Couple",   "SYND200700024:Beautiful Mountain Property on Creek",   "SYND200700042:1",   "SYND200700056:Ski Condo",   "SYND200700061:PHS - This is my first records"}
                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>Property Type</strong>:  " + e.property_type + "</li><li><strong>Price</strong>: " + e.price + "</li><li><strong>Description</strong>: " + e.description + "</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>Lot Width</strong>: ") + a.lot_length_width) + "</li><li><strong>Irregular Lot?</strong>: ") + a.irregular_lot) + "</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>Listing Status</strong>: " + s.listing_status + "</li><li><strong>Broker ID</strong>: " + s.broker_name + "</li><li><strong>Agent ID</strong>: " + s.agent_name + "</li><li><strong>MLS ID</strong>: " + s.mls_id + "</li></ul>";
                    }
                    show address;
                    show city;
                    show state;
                    show zip_code;
                    input.saved_display = buffer;
                }
            )

            saved_display
            (
                type  =  plaintext
            )

            must  have  address
            (
                displayname  =  "Address"
                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  unique_id
            (
                displayname  =  "Unique ID"
                type  =  text
                width  =  20
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        hide address;
                        hide city;
                        hide state;
                        hide zip_code;
                        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 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 a photo use form 4. Add a Photo</li>" + "<li>To add seller info use form 5. 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  =  {"-Select-",   "ZYND2007002:kpolh",   "ZYND2007006:refaddafs",   "SYND200700001:THis is a test listing",   "SYND200700001:A test listing!",   "SYND200700005:A Nice Houses",   "SYND200700012:dfasafdsfdsafdasdafsadfs",   "SYND200700016:Perfect for the Modern Couple",   "SYND200700024:Beautiful Mountain Property on Creek",   "SYND200700056:Ski Condo"}
                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>Property Type</strong>:  " + e.property_type + "</li><li><strong>Price</strong>: " + e.price + "</li><li><strong>Description</strong>: " + e.description + "</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>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>Listing Status</strong>: " + s.listing_status + "</li><li><strong>Broker ID</strong>: " + s.broker_name + "</li><li><strong>Agent ID</strong>: " + s.agent_name + "</li><li><strong>MLS ID</strong>: " + s.mls_id + "</li></ul>";
                    }
                    show lot_size;
                    show lot_length_width;
                    show bathrooms;
                    show bedrooms;
                    show square_feet;
                    show year_built;
                    show irregular_lot;
                    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
            )

            lot_length_width
            (
                displayname  =  "Lot Length Width"
                type  =  text
            )

            irregular_lot
            (
                displayname  =  "Irregular lot?"
                type  =  checkbox
                defaultvalue  =  false
            )

            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  =  "1"
            )

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

            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        hide lot_size;
                        hide lot_length_width;
                        hide bathrooms;
                        hide bedrooms;
                        hide square_feet;
                        hide year_built;
                        hide irregular_lot;
                        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;
                            hide lot_length_width;
                            hide irregular_lot;
                            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 a photo use form 4. Add a Photo</li>" + "<li>To add seller info use form 5. 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  Photos
        {
            displayname  =  "4. Add a Photo"
            success message  =  "Photo added."
            
            instructions
            (
                type  =  plaintext
                value = "<br>\n"
            )

            must  have  essentials_dropdown
            (
                displayname  =  "For which listing?"
                type  =  picklist
                values  =  {"-Select-",   "ZYND2007002:dsfasdffsadafdsadfs",   "ZYND2007002:kpolh",   "SYND200700001:THis is a test listing",   "SYND200700001:A test listing!",   "SYND200700005:A Nice Houses",   "SYND200700012:dfasafdsfdsafdasdafsadfs",   "SYND200700016:Perfect for the Modern Couple",   "SYND200700024:Beautiful Mountain Property on Creek",   "SYND200700056:Ski Condo"}
                on user input
                {
                    show photo;
                    e  =  Essentials  [listing_label == input.essentials_dropdown];
                    input.listing_id = e.unique_id;
                    buffer = "<p><strong>Essentials</strong>:</p><ul><li><strong>Property Type</strong>:  " + e.property_type + "</li><li><strong>Price</strong>: " + e.price + "</li><li><strong>Description</strong>: " + e.description + "</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>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>Lot Width</strong>: ") + a.lot_length_width) + "</li><li><strong>Irregular Lot?</strong>: ") + a.irregular_lot) + "</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>Listing Status</strong>: " + s.listing_status + "</li><li><strong>Broker ID</strong>: " + s.broker_name + "</li><li><strong>Agent ID</strong>: " + s.agent_name + "</li><li><strong>MLS ID</strong>: " + s.mls_id + "</li></ul>";
                    }
                    total_count = 0;
                    p_list = "";
                    for each p in Photos  [listing_id == input.listing_id]
                    {
                        p_list = (p_list + "<img width='175' height='175' src='/DownloadFile.do?filepath=/" + p.photo + "&sharedBy=" + zoho.adminuser) + "'/>";
                        total_count = (total_count  +  1);
                    }
                    if (total_count  >  0)
                    {
                        buffer = buffer + "<p><strong>Existing photos for this listing:</strong></p>" + p_list;
                    }
                    input.saved_display = buffer;
                }
            )

            saved_display
            (
                type  =  plaintext
            )

            must  have  photo
            (
                displayname  =  "Add Photo"
                type = upload file
            )

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

            image_display
            (
                type  =  formula
                value  =  ("<img height='175' width='175' src='http://creator.zoho.com/DownloadFile.do?filepath=/" + photo + "&sharedBy=" + zoho.adminuser) + "'/>"
            )

            must  have  listing_id
            (
                type  =  text
                width  =  20
            )

            actions
            {
                on add
                {
                    on load
                    {
                        essentials_dropdown:ui.add("-Select-");
                        hide listing_id;
                        hide photo;
                        total_records = 0;
                        for each e in Essentials
                        {
                            essentials_dropdown:ui.add(e.listing_label);
                            total_records = (total_records  +  1);
                        }
                        if (total_records  <  1)
                        {
                            hide essentials_dropdown;
                            input.saved_display = "<em>Please create at least one listing if you want to add photos.</em>";
                        }
                        else
                        {
                            input.instructions = "<em>A listing can have as many photos as you care to upload for it.  After adding photos be sure to republish your feed.</em>";
                        }
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            e  =  Essentials  [unique_id == input.listing_id];
                            e.status = "incomplete";
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    on load
                    {
                        hide listing_id;
                    }
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
                on delete
                {
                    on success
                    {
                        remaining_photos_total = 0;
                        for each p in Photos  [listing_id == input.listing_id]
                        {
                            remaining_photos_total = (remaining_photos_total  +  1);
                        }
                        if (remaining_photos_total  <  1)
                        {
                            e  =  Essentials  [unique_id == input.listing_id];
                            e.status = "incomplete";
                        }
                    }
                }
            }
        }

        form  Seller_Info
        {
            displayname  =  "5. Add Seller Info"
            success message  =  "Seller info added."
            
            must  have  essentials_dropdown
            (
                displayname  =  "For which listing?"
                type  =  picklist
                values  =  {"-Select-",   "ZYND2007002:kpolh",   "ZYND2007006:refaddafs",   "SYND200700001:THis is a test listing",   "SYND200700001:A test listing!",   "SYND200700005:A Nice Houses",   "SYND200700012:dfasafdsfdsafdasdafsadfs",   "SYND200700016:Perfect for the Modern Couple",   "SYND200700024:Beautiful Mountain Property on Creek"}
                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>Property Type</strong>:  " + e.property_type + "</li><li><strong>Price</strong>: " + e.price + "</li><li><strong>Description</strong>: " + e.description + "</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>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>Lot Width</strong>: ") + a.lot_length_width) + "</li><li><strong>Irregular Lot?</strong>: ") + a.irregular_lot) + "</li><li><strong>Bedrooms</strong>: ") + a.bedrooms) + "</li><li><strong>Bathrooms</strong>: ") + a.bathrooms) + "</li></ul>";
                    }
                    show mls_id;
                    show broker_name;
                    show agent_name;
                    show listing_status;
                    input.saved_display = buffer;
                }
            )

            saved_display
            (
                type  =  plaintext
            )

            must  have  listing_status
            (
                displayname  =  "Listing Status"
                type  =  picklist
                values  =  {"Active",   "Subject To Inspection",   "Pending",   "Sold"}
                defaultvalue  =  "Active"
            )

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

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

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

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

            actions
            {
                on add
                {
                    on load
                    {
                        hide unique_id;
                        hide mls_id;
                        hide agent_name;
                        hide broker_name;
                        hide listing_status;
                        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 mls_id;
                            hide listing_status;
                            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>" + "<li>To add a photo use form 4. Add a Photo</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>, <em>Photos</em>, and <em>Seller Info</em>.</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 "Listing ID"
                title as "Title"
                property_type as "Property Type"
                description as "Description"
                price as "Price $"
                status as "Status"
                public_link as "Detail Page"
            )
            options
            (
                display rows = 100
            )
        }

        list  Location
        {
            displayname = "2. Location"
            show  all  rows  from  Location 
            (
                unique_id as "Listing ID"
                address as "Address"
                city as "City"
                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 "Listing ID"
                lot_length_width as "Lot Width"
                irregular_lot as "Irregular Lot?"
                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  Photos
        {
            displayname = "4. Photos"
            show  all  rows  from  Photos 
            (
                listing_id as "Listing ID"
                image_display as "Photo"
                image_url as "URL"
            )
            options
            (
                display rows = 100
            )
        }

        list  Seller_Info
        {
            displayname = "5. Seller Info"
            show  all  rows  from  Seller_Info 
            (
                unique_id as "Listing ID"
                listing_status as "Status"
                broker_name as "Broker ID"
                agent_name as "Agent ID"
                mls_id as "MLS#"
            )
            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 Syndafeed real estate feed with the latest listings</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
            )

            must  have  listings_to_publish
            (
                displayname  =  "Listings to Publish"
                type  =  text
            )

            listings_ready
            (
                type  =  plaintext
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide listings_to_publish;
                        buffer = "";
                        total_count = 0;
                        lC = 0;
                        aC = 0;
                        pC = 0;
                        sC = 0;
                        for each e in Essentials  [(unique_id != "" && status == "incomplete")]
                        {
                            for each l in Location  [unique_id == e.unique_id]
                            {
                                lC = (lC  +  1);
                            }
                            for each a in Attributes  [unique_id == e.unique_id]
                            {
                                aC = (aC  +  1);
                            }
                            for each p in Photos  [listing_id == e.unique_id]
                            {
                                pC = (pC  +  1);
                            }
                            for each s in Seller_Info  [unique_id == e.unique_id]
                            {
                                sC = (sC  +  1);
                            }
                            items_ready = "";
                            if ((((lC  >  0)  &&  (aC  >  0))  &&  (pC  >  0))  &&  (sC  >  0))
                            {
                                total_count = (total_count  +  1);
                                items_ready = items_ready + "<li>" + e.listing_label + "</li>";
                            }
                        }
                        if (total_count  >  0)
                        {
                            input.listings_to_publish = "publish";
                            input.ready_instructions = "<em>The following listings are ready to to publish.  Click submit to update your Oodle feed.</em>";
                            input.listings_ready = "<ul>" + items_ready + "</ul>";
                        }
                        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 == "incomplete" || 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];
                                irregularLot = "";
                                if (a.irregular_lot)
                                {
                                    irregularLot = "Y";
                                }
                                dateString = input.Modified_Time.toString();
                                day = dateString.getPrefix("-");
                                monthYear = dateString.getSuffix("-");
                                month = monthYear.getPrefix("-");
                                yearTime = monthYear.getSuffix("-");
                                year = yearTime.getPrefix(" ");
                                time = yearTime.getSuffix(" ");
                                if (month  ==  "Jan")
                                {
                                    month = "01";
                                }
                                else if (month  ==  "Feb")
                                {
                                    month = "02";
                                }
                                else if (month  ==  "Feb")
                                {
                                    month = "02";
                                }
                                else if (month  ==  "Mar")
                                {
                                    month = "03";
                                }
                                else if (month  ==  "Apr")
                                {
                                    month = "04";
                                }
                                else if (month  ==  "May")
                                {
                                    month = "05";
                                }
                                else if (month  ==  "Jun")
                                {
                                    month = "06";
                                }
                                else if (month  ==  "Jul")
                                {
                                    month = "07";
                                }
                                else if (month  ==  "Aug")
                                {
                                    month = "08";
                                }
                                else if (month  ==  "Sep")
                                {
                                    month = "09";
                                }
                                else if (month  ==  "Oct")
                                {
                                    month = "10";
                                }
                                else if (month  ==  "Nov")
                                {
                                    month = "11";
                                }
                                else
                                {
                                    month = "12";
                                }
                                dateString = year + "-" + month + "-" + day + " " + time;
                                xml = xml + "<Listing><ListingId>" + e.unique_id + "</ListingId><StreetAddress>" + l.address + "</StreetAddress><City>" + l.city + "</City><Country>US</Country>" + "<StateProvince>" + l.state + "</StateProvince><PropertyType>" + e.property_type + "</PropertyType><PostalCode>" + l.zip_code + "</PostalCode><BrokerId>" + s.broker_name + "</BrokerId><AgentId>" + s.agent_name + "</AgentId><BathRooms>" + a.bathrooms + "</BathRooms><BedRooms>" + a.bedrooms + "</BedRooms><BrokerId>BuggyRocket</BrokerId>";
                                for each p in Photos  [listing_id == e.unique_id]
                                {
                                    xml = xml + "<PhotoURL>" + p.image_url + "</PhotoURL>";
                                }
                                xml = ((((((((((((((xml + "<ListingStatus>" + s.listing_status + "</ListingStatus><GMTLastModified>" + dateString + "</GMTLastModified><Currency>USD</Currency><DescriptionLang value='en'><Description><![CDATA[" + e.description + "]]></Description><Caption><![CDATA[" + e.title + "]]></Caption><DetailsURL>" + e.public_url + "</DetailsURL></DescriptionLang><LandArea>" + a.lot_size) + "</LandArea><PropertyId>") + s.mls_id) + "</PropertyId><Price>") + e.price) + "</Price>") + "<StructureArea>") + a.square_feet) + "</StructureArea><LotLengthWidth>") + a.lot_length_width) + "</LotLengthWidth><IrregularLot>") + irregularLot) + "</IrregularLot><YearBuilt>") + a.year_built) + "</YearBuilt></Listing>";
                                if (e.status  ==  "incomplete")
                                {
                                    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  unique_id
            (
                displayname  =  "Unique ID"
                type  =  number
                width  =  20
            )

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

            message_display
            (
                type  =  plaintext
                value = "<br>\n"
            )

            actions
            {
                on add
                {
                    on load
                    {
                        if (count(seed_unique_id[unique_id != 0])  >  0)
                        {
                            hide unique_id;
                            hide prefix;
                            input.message_display = "A Unique ID seed has been submitted.   If you wish to reset the starting values please either: " + "<ol> <li>Visit the View and delete the existing record, then recreate here with new values or </li>" + "<li>Update its existing values in the View using the <strong>Bulk Edit</strong> feature.</li></ol>";
                        }
                    }
                    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' encoding='UTF-8' ?>"
                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' encoding='UTF-8' ?>"
            )
            options
            (
                display rows = 100
            )
        }

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

                must  have  unique  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];
                        p  =  Photos  [listing_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>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>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>Agent</strong>:  ") + s.agent_name) + "</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=/") + p.photo) + "&sharedBy=") + zoho.adminuser) + "'/>") + "<p><strong>Description:</strong>  ") + e.description) + "</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"
                    )
                }
            }
        }

        form  Iterations
        {
            
            must  have  iteration
            (
                displayname  =  "Iteration"
                type  =  number
                width  =  20
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

    }

}
