// JavaScript Document
 
// "site" object is create on the page's domready event
var Site = {
    // Add general site initialization functions here

    start: function() {

        
        Site.setupCalendarPopups();
        Site.setupPanelAutocomplete();

    },

    
    // Set up the delete confirmation dialog boxes
    setupCalendarPopups: function() {

        var aElemDelete = $$('a.showcal');  // Get all a tags with a 'delete' class

        // For each of these links
        aElemDelete.each(function(elemDelete) {

            // Store the href
            var sHref = elemDelete.get('href');

            // Clear the href
            elemDelete.set('href', '');

            // Add a click event to the element             
            elemDelete.addEvent('click', function(e) {
                e.stop();

                var eCal = $(sHref);
                eCal.set('styles', {
                    'display': 'block'
                });

            });


        }); // End  aElemDelete.each(function(elemDelete) {


    } // End  setupCalendarPopups: function() {

    ,

    // Set up autocomplete form for the panel
    setupPanelAutocomplete: function() {


        var sPanelNumFieldId = "ctl00_ContentPlaceHolder1_txtPanelNumber";
        var sPanelDescFieldId = "ctl00_ContentPlaceHolder1_txtPanelDescription";

        var aElemPanels = $(sPanelNumFieldId);  // Get the control where the user enters the panel number

        if (aElemPanels) {

            new Autocompleter.Request.JSON(aElemPanels, '../handlers/panelnumbers.ashx', {
                'postVar': 'search',
                'indicatorClass': 'autocompleter-loading'
            });

            var aElemChoices = $('autocompleter-choices');  // Get all a tags with a 'delete' class

            // If the choices textfield is clicked, update the description field
            aElemChoices.addEvent("click", function() {

                var jsonRequest = new Request.JSON({ url: "../handlers/paneldesc.ashx", onComplete: function(jsonObj) {

                    if (jsonObj != null) {
                        $(sPanelDescFieldId).set("value", jsonObj.desc[0]);
                    }
                }
                }).post({ 'search': aElemPanels.get("value") });

            });

            // If panels textfield is changed, update  the description field
            aElemPanels.addEvent("keydown", function() {

                var jsonRequest = new Request.JSON({ url: "../handlers/paneldesc.ashx", onComplete: function(jsonObj) {

                    if (jsonObj != null) {
                        $('ctl00_ContentPlaceHolder1_txtPanelDescription').set("value", jsonObj.desc[0]);
                    }
                }
                }).post({ 'search': aElemPanels.get("value") });

            });


        }



    } // End  setupPanelAutocomplete: function() {




} // End site
 
// Activate the site function on domready
window.addEvent('domready', Site.start);
 
 
// Handle market add popup
var newwindow;

function openPopup(url) {

     newwindow = window.open(url, "mywindow", "location=1,status=1,scrollbars=1,toolbars=1,width=600,height=500,resizable=1");
 
    if (window.focus) { newwindow.focus() }
}

 