/**
  * Ensure the required JS is included
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     if (($headBlock = $this->getLayout()->getBlock('head')) !== false) {
         $headBlock->addJs('fishpig/wordpress/update.js');
     }
     return parent::_prepareLayout();
 }
 /**
  * Add the JS
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     $this->setText(sprintf("\n\t\t\t<script type=\"text/javascript\">\n\t\t\t\t//<![CDATA[\t\t\t\t\n\t\t\t\t\t(function() {\n\t\t\t\t\t\tvar create = {\n\t\t\t\t\t\t\tgo: function() {\n\t\t\t\t\t\t\t\tthis.attr = \$('splash_attribute_id');\n\t\t\t\t\t\t\t\tthis.opt = \$('splash_option_id');\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif (!this.attr || !this.opt) {\n\t\t\t\t\t\t\t\t\tthrow 'Missing required input fields';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.name = \$('splash_display_name');\n\n\t\t\t\t\t\t\t\tthis.options = new Array();\n\t\t\t\t\t\t\t\tthis.onAttributeChange();\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.attr.observe('change', this.onAttributeChange.bindAsEventListener(this));\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.opt.observe('change', this.onOptionChange.bindAsEventListener(this));\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\thasOptions: function() {\n\t\t\t\t\t\t\t\treturn typeof this.options[this.attr.getValue()] !== 'undefined';\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tupdateOptions: function() {\n\t\t\t\t\t\t\t\tthis.opt.options = null;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tthis.opt.options[0] = new Option('%s', '');\n\n\t\t\t\t\t\t\t\tthis.options[this.attr.getValue()].each(function(elem, ind) {\n\t\t\t\t\t\t\t\t\tthis.opt.options[ind+1] = new Option(elem.label, elem.value);\n\t\t\t\t\t\t\t\t}.bind(this));\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetOptions: function() {\n\t\t\t\t\t\t\t\tnew Ajax.Request('%s?attribute=' + this.attr.getValue(), {\n\t\t\t\t\t\t\t\t\tonSuccess: function(transport) {\n\t\t\t\t\t\t\t\t\t\tvar json = transport.responseText.evalJSON();\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tif (json.error) {\n\t\t\t\t\t\t\t\t\t\t\tthrow json.error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tthis.options[this.attr.getValue()] = new Array();\n\n\t\t\t\t\t\t\t\t\t\tjson.options.each(function(elem, ind) {\n\t\t\t\t\t\t\t\t\t\t\tthis.options[this.attr.getValue()].push({'value': elem.value, 'label': elem.label});\n\t\t\t\t\t\t\t\t\t\t}.bind(this));\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tthis.updateOptions();\n\t\t\t\t\t\t\t\t\t}.bind(this)\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonAttributeChange: function() {\n\t\t\t\t\t\t\t\tif (this.hasOptions()) {\n\t\t\t\t\t\t\t\t\tthis.updateOptions();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthis.getOptions();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonOptionChange: function() {\n\t\t\t\t\t\t\t\tif (this.opt.getValue()) {\n\t\t\t\t\t\t\t\t\tif (this.name.getValue() === '') {\n\t\t\t\t\t\t\t\t\t\tthis.name.setValue(this.opt.options[this.opt.selectedIndex].label);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t\t\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn create.go();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\t\talert(e);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t//]]>\n\t\t\t</script>\n\t\t", Mage::helper('adminhtml')->__('-- Please Select --'), Mage::getModel('adminhtml/url')->getUrl('*/*/options')));
     return parent::_prepareLayout();
 }