/*
COPYRIGHT NOTICE - DO NOT REMOVE
MunchAway POS Integrated Online Ordering System for Restaurants
Designed by: Robert H. Johnson
Developed by: Team MunchAway, V2 Solutions, Inc.
Copyright 2007, Lone Tree Technology, Inc., all rights reserved.
Copyright 2008, LT2 Systems, Inc., all rights reserved.
Copyright 2009-2010, MunchAway, LLC., all rights reserved.
This file contains Confidential and Proprietary Information of MunchAway, LLC.
Using or copying this file or any portions of its contents without the expressed written consent of MunchAway LLC is strictly prohibited.
*/
//
// // Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function set_global_price_index(pi, start, count) {
	if (!confirm("Are you sure you want to change all of the price indexes to "+pi+"?")) return;
	for(var idx = start; idx <= count; idx++) {
		$('edititem'+idx+'[menuitem][price_index]_0').checked = (pi == '0');
		$('edititem'+idx+'[menuitem][price_index]_1').checked = (pi == '1');
		$('edititem'+idx+'[menuitem][price_index]_2').checked = (pi == '2');
		$('edititem'+idx+'[menuitem][price_index]_3').checked = (pi == '3');
	 }
}

function  showHidePortionPricing(use_mode)
{
	if(use_mode=="2")
	{
		Element.show('portion_pricing_div');
		if(document.getElementById('portion_pricing').value==1)
			Element.show('portion_pricing_percentage_div');
		else
			Element.hide('portion_pricing_percentage_div');
	}
	else
	{
		Element.hide('portion_pricing_div');
		Element.hide('portion_pricing_percentage_div');
	}

}

function  showHidePortionPricingForAdd(use_mode)
{
	if(use_mode=="2")
	{
		Element.show('add_form_portion_pricing_div');
		if(document.getElementById('add_form_portion_pricing').value==1)
			Element.show('add_form_portion_pricing_percentage_div');
		else
			Element.hide('add_form_portion_pricing_percentage_div');
	}
	else
	{
		Element.hide('add_form_portion_pricing_div');
		Element.hide('add_form_portion_pricing_percentage_div');
	}

}

function check_onload()
    {
        if($('holiday_closed').checked == true){
             $('timings').hide();
             $('holiday_open_time', 'holiday_earliest_order_time', 'holiday_latest_order_time','holiday_close_time').invoke('disable');
      }
      else
        {
             $('timings').show();
             $('holiday_open_time', 'holiday_earliest_order_time', 'holiday_latest_order_time','holiday_close_time').invoke('enable');
      }
    }

function uncheckLocation()
{
	var check_all = document.getElementById("check_all");
	check_all.checked = false;
}

function check_all_location()
{
	var check_all = document.getElementById("check_all");
	var location = document.getElementById("location[]");
	set = false;
	if(check_all.checked == true)
	set = true;
	for(var i=0; i<location.options.length; i++)
	 {
		location.options[i].selected = set;
     }

}

function updateLocation()
{
	new Ajax.Updater('location','/admin/order_reports/find_location',
					 {asynchronous:true,evalScripts:true,parameters:Form.serialize('filterForm')},
					 onLoad=Element.show('location'),
					 onComplete=Effect.SlideDown('location'));
}

function updateConsoleLocations()
{
	new Ajax.Updater('location','/admin/admin_users/update_console_locations',
					 {asynchronous:true,evalScripts:true,parameters:Form.Element.serialize('subscriber')},
					 onLoad=Element.show('location'),
					 onComplete=Effect.SlideDown('location'));
}
function updateFilterValue(object)
{
	if(object.value==' ')
	{
		document.filterFormName.submit();
	}
	else
	{
		new Ajax.Updater('filter','/admin/subscribers/find_search_value',
					 {asynchronous:true,evalScripts:true,parameters:Form.serialize('filterFormId')},
					 onLoad=Element.show('ajax_spinner'),
					 onComplete=Element.hide('ajax_spinner'));
	}
}

function submitForm(object)
{
	if(object.value!=' ')
	{
		document.filterFormName.submit();
	}
}

function enable_disable(){
	if (document.getElementById('group_by_modifier')){
	  if (document.getElementById('group_by_modifier').checked == true)
	  {
		document.getElementById('sb2').disabled=true;
		document.getElementById('sb3').disabled=true;
		document.getElementById('sb1').checked=true;
	  }
	  else
	  {
		document.getElementById('sb2').disabled=false;
		document.getElementById('sb3').disabled=false;
		}
	}
}

function set_all_descriptions_to_default(start, count) {
	if (!confirm("Are you sure you want to change all of the descriptions to their default values?")) return;

	for(var idx = start; idx <= count; idx++) {
		$('edititem'+idx+'[menuitem][menu_short_desc]').value = $('edititem'+idx+'_pos_long_desc').value;
	 }
}

function stripeTables() {
  $$("table.striped tr").each(function(tr, index) {
    if (! tr.hasClassName('nostripe')) {
      tr.addClassName((index % 2 == 0) ? "even" : "odd");
    }
  });
}
Event.onReady(function() {
  stripeTables();
});

Ajax.InPlaceBooleanEditor = Class.create();
Ajax.InPlaceBooleanEditor.defaultHighlightColor = "#FFFF99";
Ajax.InPlaceBooleanEditor.prototype = {
  initialize: function(element, url, options) {
    this.url = url;
    this.element = $(element);

    this.options = Object.extend({
      paramName: "value",
      okButton: true,
      okText: "ok",
      cancelLink: true,
      cancelText: "cancel",
      savingText: "Saving...",
      clickToEditText: "Click to edit",
      okText: "ok",
      rows: 1,
      onComplete: function(transport, element) {
        new Effect.Highlight(element, {startcolor: this.options.highlightcolor});
      },
      onFailure: function(transport) {
        alert("Error communicating with the server: " + transport.responseText.stripTags());
      },
      callback: function(form) {
        return Form.serialize(form);
      },
      handleLineBreaks: true,
      loadingText: 'Loading...',
      savingClassName: 'inplaceeditor-saving',
      loadingClassName: 'inplaceeditor-loading',
      formClassName: 'inplaceeditor-form',
      highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor,
      highlightendcolor: "#FFFFFF",
      externalControl: null,
      submitOnBlur: false,
      ajaxOptions: {},
      evalScripts: false
    }, options || {});

    if(!this.options.formId && this.element.id) {
      this.options.formId = this.element.id + "-inplaceeditor";
      if ($(this.options.formId)) {
        // there's already a form with that name, don't specify an id
        this.options.formId = null;
      }
    }

    if (this.options.externalControl) {
      this.options.externalControl = $(this.options.externalControl);
    }

    this.originalBackground = Element.getStyle(this.element, 'background-color');
    if (!this.originalBackground) {
      this.originalBackground = "transparent";
    }

    this.element.title = this.options.clickToEditText;

    this.onclickListener = this.enterEditMode.bindAsEventListener(this);
    this.mouseoverListener = this.enterHover.bindAsEventListener(this);
    this.mouseoutListener = this.leaveHover.bindAsEventListener(this);
    Event.observe(this.element, 'click', this.onclickListener);
    Event.observe(this.element, 'mouseover', this.mouseoverListener);
    Event.observe(this.element, 'mouseout', this.mouseoutListener);
    if (this.options.externalControl) {
      Event.observe(this.options.externalControl, 'click', this.onclickListener);
      Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener);
      Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener);
    }
  },
  enterEditMode: function(evt) {
    if (this.saving) return;
    if (this.editing) return;
    this.editing = true;
    this.onEnterEditMode();
    if (this.options.externalControl) {
      Element.hide(this.options.externalControl);
    }
    Element.hide(this.element);
    this.createForm();
    this.element.parentNode.insertBefore(this.form, this.element);
    if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField);
    // stop the event to avoid a page refresh in Safari
    if (evt) {
      Event.stop(evt);
    }
    return false;
  },
  createForm: function() {
    this.form = document.createElement("form");
    this.form.id = this.options.formId;
    Element.addClassName(this.form, this.options.formClassName)
    this.form.onsubmit = this.onSubmit.bind(this);

    this.createSelectField();

    if (this.options.okButton) {
      okButton = document.createElement("input");
      okButton.type = "submit";
      okButton.value = this.options.okText;
      okButton.className = 'editor_ok_button';
      this.form.appendChild(okButton);
    }

    if (this.options.cancelLink) {
      cancelLink = document.createElement("a");
      cancelLink.href = "#";
      cancelLink.appendChild(document.createTextNode(this.options.cancelText));
      cancelLink.onclick = this.onclickCancel.bind(this);
      cancelLink.className = 'editor_cancel';
      this.form.appendChild(cancelLink);
    }
  },
  hasHTMLLineBreaks: function(string) {
    if (!this.options.handleLineBreaks) return false;
    return string.match(/<br/i) || string.match(/<p>/i);
  },
  convertHTMLLineBreaks: function(string) {
    return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, "");
  },
  createSelectField: function() {
    var text;
    if(this.options.loadTextURL) {
      text = this.options.loadingText;
    } else {
      text = this.getText();
    }

    var obj = this;
	var txt1, txt2;

    var selectField = document.createElement("select");
	selectField.obj = this;
	selectField.name = this.options.paramName;
    selectField.className = 'editor_field';
	selectField.value = text;

	var optionYesField = document.createElement("option");
//	optionYesField.obj = this;
	optionYesField.value="Yes"
	txt1 = document.createTextNode("Yes");
	optionYesField.appendChild(txt1);

	var optionNoField = document.createElement("option");
//	optionNoField.obj = this;
	optionNoField.value="No"
	txt2 = document.createTextNode("No");
	optionNoField.appendChild(txt2);

	selectField.appendChild(optionYesField);
	selectField.appendChild(optionNoField);

	if (text == "Yes" || text == "true") {
		optionYesField.selected = true;
	} else {
		optionNoField.selected = true;
	}

	this.editField = selectField;

    if(this.options.loadTextURL) {
      this.loadExternalText();
    }
    this.form.appendChild(selectField);
  },
  getText: function() {
    return this.element.innerHTML;
  },
  loadExternalText: function() {
    Element.addClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = true;
    new Ajax.Request(
      this.options.loadTextURL,
      Object.extend({
        asynchronous: true,
        onComplete: this.onLoadedExternalText.bind(this)
      }, this.options.ajaxOptions)
    );
  },
  onLoadedExternalText: function(transport) {
    Element.removeClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = false;
    this.editField.value = transport.responseText.stripTags();
    Field.scrollFreeActivate(this.editField);
  },
  onclickCancel: function() {
    this.onComplete();
    this.leaveEditMode();
    return false;
  },
  onFailure: function(transport) {
    this.options.onFailure(transport);
    if (this.oldInnerHTML) {
      this.element.innerHTML = this.oldInnerHTML;
      this.oldInnerHTML = null;
    }
    return false;
  },
  onSubmit: function() {
    // onLoading resets these so we need to save them away for the Ajax call
    var form = this.form;
    var value = this.editField.value;

    // do this first, sometimes the ajax call returns before we get a chance to switch on Saving...
    // which means this will actually switch on Saving... *after* we've left edit mode causing Saving...
    // to be displayed indefinitely
    this.onLoading();

    if (this.options.evalScripts) {
      new Ajax.Request(
        this.url, Object.extend({
          parameters: this.options.callback(form, value),
          onComplete: this.onComplete.bind(this),
          onFailure: this.onFailure.bind(this),
          asynchronous:true,
          evalScripts:true
        }, this.options.ajaxOptions));
    } else  {
      new Ajax.Updater(
        { success: this.element,
          // don't update on failure (this could be an option)
          failure: null },
        this.url, Object.extend({
          parameters: this.options.callback(form, value),
          onComplete: this.onComplete.bind(this),
          onFailure: this.onFailure.bind(this)
        }, this.options.ajaxOptions));
    }
    // stop the event to avoid a page refresh in Safari
    if (arguments.length > 1) {
      Event.stop(arguments[0]);
    }
    return false;
  },
  onLoading: function() {
    this.saving = true;
    this.removeForm();
    this.leaveHover();
    this.showSaving();
  },
  showSaving: function() {
    this.oldInnerHTML = this.element.innerHTML;
    this.element.innerHTML = this.options.savingText;
    Element.addClassName(this.element, this.options.savingClassName);
    this.element.style.backgroundColor = this.originalBackground;
    Element.show(this.element);
  },
  removeForm: function() {
    if(this.form) {
      if (this.form.parentNode) Element.remove(this.form);
      this.form = null;
    }
  },
  enterHover: function() {
    if (this.saving) return;
    this.element.style.backgroundColor = this.options.highlightcolor;
    if (this.effect) {
      this.effect.cancel();
    }
    Element.addClassName(this.element, this.options.hoverClassName)
  },
  leaveHover: function() {
    if (this.options.backgroundColor) {
      this.element.style.backgroundColor = this.oldBackground;
    }
    Element.removeClassName(this.element, this.options.hoverClassName)
    if (this.saving) return;
    this.effect = new Effect.Highlight(this.element, {
      startcolor: this.options.highlightcolor,
      endcolor: this.options.highlightendcolor,
      restorecolor: this.originalBackground
    });
  },
  leaveEditMode: function() {
    Element.removeClassName(this.element, this.options.savingClassName);
    this.removeForm();
    this.leaveHover();
    this.element.style.backgroundColor = this.originalBackground;
    Element.show(this.element);
    if (this.options.externalControl) {
      Element.show(this.options.externalControl);
    }
    this.editing = false;
    this.saving = false;
    this.oldInnerHTML = null;
    this.onLeaveEditMode();
  },
  onComplete: function(transport) {
    this.leaveEditMode();
    this.options.onComplete.bind(this)(transport, this.element);
  },
  onEnterEditMode: function() {},
  onLeaveEditMode: function() {},
  dispose: function() {
    if (this.oldInnerHTML) {
      this.element.innerHTML = this.oldInnerHTML;
    }
    this.leaveEditMode();
    Event.stopObserving(this.element, 'click', this.onclickListener);
    Event.stopObserving(this.element, 'mouseover', this.mouseoverListener);
    Event.stopObserving(this.element, 'mouseout', this.mouseoutListener);
    if (this.options.externalControl) {
      Event.stopObserving(this.options.externalControl, 'click', this.onclickListener);
      Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener);
      Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener);
    }
  }
};


Ajax.InPlaceAssetEditor = Class.create();
// Ajax.InPlaceAssetEditor.defaultHighlightColor = "#FFFF99";
Ajax.InPlaceAssetEditor.prototype = {
  initialize: function(element, url, options) {
    this.url = url;
    this.element = $(element);

    this.options = Object.extend({
      paramName: "value",
      okButton: true,
      okText: "ok",
      cancelLink: true,
      cancelText: "cancel",
      savingText: "Saving...",
      clickToEditText: "Click to edit",
      okText: "ok",
      rows: 1,
      onComplete: function(transport, element) {
        new Effect.Highlight(element, {startcolor: this.options.highlightcolor});
      },
      onFailure: function(transport) {
        alert("Error communicating with the server: " + transport.responseText.stripTags());
      },
      callback: function(form) {
        return Form.serialize(form);
      },
      handleLineBreaks: true,
      loadingText: 'Loading...',
      savingClassName: 'inplaceeditor-saving',
      loadingClassName: 'inplaceeditor-loading',
      formClassName: 'inplaceeditor-form',
      highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor,
      highlightendcolor: "#FFFFFF",
      externalControl: null,
      submitOnBlur: false,
      ajaxOptions: {},
      evalScripts: false
    }, options || {});

    if(!this.options.formId && this.element.id) {
      this.options.formId = this.element.id + "-inplaceeditor";
      if ($(this.options.formId)) {
        // there's already a form with that name, don't specify an id
        this.options.formId = null;
      }
    }

    if (this.options.externalControl) {
      this.options.externalControl = $(this.options.externalControl);
    }

    this.originalBackground = Element.getStyle(this.element, 'background-color');
    if (!this.originalBackground) {
      this.originalBackground = "transparent";
    }

    this.element.title = this.options.clickToEditText;

    this.onclickListener = this.enterEditMode.bindAsEventListener(this);
    this.mouseoverListener = this.enterHover.bindAsEventListener(this);
    this.mouseoutListener = this.leaveHover.bindAsEventListener(this);
    Event.observe(this.element, 'click', this.onclickListener);
    Event.observe(this.element, 'mouseover', this.mouseoverListener);
    Event.observe(this.element, 'mouseout', this.mouseoutListener);
    if (this.options.externalControl) {
      Event.observe(this.options.externalControl, 'click', this.onclickListener);
      Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener);
      Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener);
    }
  },
  enterEditMode: function(evt) {
    if (this.saving) return;
    if (this.editing) return;
    this.editing = true;
    this.onEnterEditMode();
    if (this.options.externalControl) {
      Element.hide(this.options.externalControl);
    }
    Element.hide(this.element);
    this.createForm();
    this.element.parentNode.insertBefore(this.form, this.element);
    if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField);
    // stop the event to avoid a page refresh in Safari
    if (evt) {
      Event.stop(evt);
    }
    return false;
  },
  createForm: function() {
    this.form = document.createElement("form");
    this.form.id = this.options.formId;
    Element.addClassName(this.form, this.options.formClassName);
    this.form.onsubmit = this.onSubmit.bind(this);
	this.form.encoding = "multipart/form-data";
	this.form.method = "POST";

    this.createFileField();

    if (this.options.okButton) {
      okButton = document.createElement("input");
      okButton.type = "submit";
      okButton.value = this.options.okText;
      okButton.className = 'editor_ok_button';
      this.form.appendChild(okButton);
    }

    if (this.options.cancelLink) {
      cancelLink = document.createElement("a");
      cancelLink.href = "#";
      cancelLink.appendChild(document.createTextNode(this.options.cancelText));
      cancelLink.onclick = this.onclickCancel.bind(this);
      cancelLink.className = 'editor_cancel';
      this.form.appendChild(cancelLink);
    }
  },
  hasHTMLLineBreaks: function(string) {
    if (!this.options.handleLineBreaks) return false;
    return string.match(/<br/i) || string.match(/<p>/i);
  },
  convertHTMLLineBreaks: function(string) {
    return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, "");
  },
  createFileField: function() {
    var text;
    if(this.options.loadTextURL) {
      text = this.options.loadingText;
    } else {
      text = this.getText();
    }

    var obj = this;

    this.options.textarea = false;
    var textField = document.createElement("input");
    textField.obj = this;
    textField.type = "file";
    textField.name = this.options.paramName;
    textField.value = text;
    textField.style.backgroundColor = this.options.highlightcolor;
    textField.className = 'editor_field';
    var size = this.options.size || this.options.cols || 0;
    if (size != 0) textField.size = size;
    if (this.options.submitOnBlur)
      textField.onblur = this.onSubmit.bind(this);
    this.editField = textField;

    if(this.options.loadTextURL) {
      this.loadExternalText();
    }
    this.form.appendChild(this.editField);
  },
  getText: function() {
    return this.element.innerHTML;
  },
  loadExternalText: function() {
    Element.addClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = true;
    new Ajax.Request(
      this.options.loadTextURL,
      Object.extend({
        asynchronous: true,
        onComplete: this.onLoadedExternalText.bind(this)
      }, this.options.ajaxOptions)
    );
  },
  onLoadedExternalText: function(transport) {
    Element.removeClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = false;
    this.editField.value = transport.responseText.stripTags();
    Field.scrollFreeActivate(this.editField);
  },
  onclickCancel: function() {
    this.onComplete();
    this.leaveEditMode();
    return false;
  },
  onFailure: function(transport) {
    this.options.onFailure(transport);
    if (this.oldInnerHTML) {
      this.element.innerHTML = this.oldInnerHTML;
      this.oldInnerHTML = null;
    }
    return false;
  },
  onSubmit: function() {
    // onLoading resets these so we need to save them away for the Ajax call
    var form = this.form;
    var value = this.editField.value;

    // do this first, sometimes the ajax call returns before we get a chance to switch on Saving...
    // which means this will actually switch on Saving... *after* we've left edit mode causing Saving...
    // to be displayed indefinitely
    this.onLoading();

    var subform = document.createElement("form");
	// var subform = Form.new;
	subform.action = form.action;
	subform.target = form.target;
    subform.id = "asset_upload_form_id";
	subform.encoding = "multipart/form-data";
	subform.method = "POST"
	subform.name = "asset_upload_form"
    // Element.addClassName(subform, this.options.formClassName + "_subform")

	fileupload = document.createElement("input")
	fileupload.name = "assset_upload_file";
    fileupload.type = "file";
    fileupload.value = value;
	subform.appendChild(fileupload);

	// this.element.parentNode.insertBefore(this.form, this.element);

    subform.submit()

    // stop the event to avoid a page refresh in Safari
    if (arguments.length > 1) {
      Event.stop(arguments[0]);
    }
    return false;
  },
  onLoading: function() {
    this.saving = true;
    this.removeForm();
    this.leaveHover();
    this.showSaving();
  },
  showSaving: function() {
    this.oldInnerHTML = this.element.innerHTML;
    this.element.innerHTML = this.options.savingText;
    Element.addClassName(this.element, this.options.savingClassName);
    this.element.style.backgroundColor = this.originalBackground;
    Element.show(this.element);
  },
  removeForm: function() {
    if(this.form) {
      if (this.form.parentNode) Element.remove(this.form);
      this.form = null;
    }
  },
  enterHover: function() {
    if (this.saving) return;
    this.element.style.backgroundColor = this.options.highlightcolor;
    if (this.effect) {
      this.effect.cancel();
    }
    Element.addClassName(this.element, this.options.hoverClassName)
  },
  leaveHover: function() {
    if (this.options.backgroundColor) {
      this.element.style.backgroundColor = this.oldBackground;
    }
    Element.removeClassName(this.element, this.options.hoverClassName)
    if (this.saving) return;
    this.effect = new Effect.Highlight(this.element, {
      startcolor: this.options.highlightcolor,
      endcolor: this.options.highlightendcolor,
      restorecolor: this.originalBackground
    });
  },
  leaveEditMode: function() {
    Element.removeClassName(this.element, this.options.savingClassName);
    this.removeForm();
    this.leaveHover();
    this.element.style.backgroundColor = this.originalBackground;
    Element.show(this.element);
    if (this.options.externalControl) {
      Element.show(this.options.externalControl);
    }
    this.editing = false;
    this.saving = false;
    this.oldInnerHTML = null;
    this.onLeaveEditMode();
  },
  onComplete: function(transport) {
    this.leaveEditMode();
    this.options.onComplete.bind(this)(transport, this.element);
  },
  onEnterEditMode: function() {},
  onLeaveEditMode: function() {},
  dispose: function() {
    if (this.oldInnerHTML) {
      this.element.innerHTML = this.oldInnerHTML;
    }
    this.leaveEditMode();
    Event.stopObserving(this.element, 'click', this.onclickListener);
    Event.stopObserving(this.element, 'mouseover', this.mouseoverListener);
    Event.stopObserving(this.element, 'mouseout', this.mouseoutListener);
    if (this.options.externalControl) {
      Event.stopObserving(this.options.externalControl, 'click', this.onclickListener);
      Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener);
      Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener);
    }
  }
};

Ajax.InPlaceDateEditor = Class.create();
Object.extend(Ajax.InPlaceDateEditor.prototype, Ajax.InPlaceEditor.prototype);
Object.extend(Ajax.InPlaceDateEditor.prototype, {
  createEditField: function() {
    var text;
    if(this.options.loadTextURL) {
      text = this.options.loadingText;
    } else {
      text = this.getText();
    }

    var obj = this;

    if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) {
      this.options.textarea = false;
      var textField = document.createElement("input");
      textField.obj = this;
      textField.type = "text";
      textField.name = this.options.paramName;
      textField.value = text.slice(0,10);
      textField.style.backgroundColor = this.options.highlightcolor;
      textField.className = 'editor_field';
      var size = this.options.size || this.options.cols || 0;
      if (size != 0) textField.size = size;
      if (this.options.submitOnBlur)
        textField.onblur = this.onSubmit.bind(this);
      this.editField = textField;
    } else {
      this.options.textarea = true;
      var textArea = document.createElement("textarea");
      textArea.obj = this;
      textArea.name = this.options.paramName;
      textArea.value = this.convertHTMLLineBreaks(text);
      textArea.rows = this.options.rows;
      textArea.cols = this.options.cols || 40;
      textArea.className = 'editor_field';
      if (this.options.submitOnBlur)
        textArea.onblur = this.onSubmit.bind(this);
      this.editField = textArea;
    }

    if(this.options.loadTextURL) {
      this.loadExternalText();
    }
    this.form.appendChild(this.editField);
  },
  createSelectField: function() {
	    var text;
	    if(this.options.loadTextURL) {
	      text = this.options.loadingText;
	    } else {
	      text = this.getText();
	    }

	    var obj = this;
		var txt1, txt2;

	    var selectField = document.createElement("select");
		selectField.obj = this;
		selectField.name = this.options.paramName;
	    selectField.className = 'editor_field';
		selectField.value = text;

		var optionYesField = document.createElement("option");
	//	optionYesField.obj = this;
		optionYesField.value="Yes"
		txt1 = document.createTextNode("Yes");
		optionYesField.appendChild(txt1);

		var optionNoField = document.createElement("option");
	//	optionNoField.obj = this;
		optionNoField.value="No"
		txt2 = document.createTextNode("No");
		optionNoField.appendChild(txt2);

		selectField.appendChild(optionYesField);
		selectField.appendChild(optionNoField);

		if (text == "Yes" || text == "true") {
			optionYesField.selected = true;
		} else {
			optionNoField.selected = true;
		}

		this.editField = selectField;

	    if(this.options.loadTextURL) {
	      this.loadExternalText();
	    }
	    this.form.appendChild(selectField);
  },
  onSubmit: function() {
    // onLoading resets these so we need to save them away for the Ajax call
    var form = this.form;
    var value = this.editField.value;

    // do this first, sometimes the ajax call returns before we get a chance to switch on Saving...
    // which means this will actually switch on Saving... *after* we've left edit mode causing Saving...
    // to be displayed indefinitely
    this.onLoading();

    if (this.options.evalScripts) {
      new Ajax.Request(
        this.url, Object.extend({
          parameters: this.options.callback(form, value),
          onComplete: this.onComplete.bind(this),
          onFailure: this.onFailure.bind(this),
          asynchronous:true,
          evalScripts:true
        }, this.options.ajaxOptions));
    } else  {
      new Ajax.Updater(
        { success: this.element,
          // don't update on failure (this could be an option)
          failure: null },
        this.url, Object.extend({
          parameters: this.options.callback(form, value),
          onComplete: this.onComplete.bind(this),
          onFailure: this.onFailure.bind(this)
        }, this.options.ajaxOptions));
    }
    // stop the event to avoid a page refresh in Safari
    if (arguments.length > 1) {
      Event.stop(arguments[0]);
    }
    return false;
  }
});


// added for creating new location. for payment gateway integration

function change_merchant_id_display()
  {
    var vars = document.getElementById("merchant_id");
    display_val = vars.style.display;
    if(display_val == 'none')
      {
        vars.style.display = 'block';
      }
    else
      {
       vars.style.display = 'none';
      }
  }

function createDate()
	{
		var day = (document.getElementById('day')).value;
		var month = (document.getElementById('month')).value;
		var year = (document.getElementById('year')).value;
		var future_date =  day + "/" + month +"/"+ year;
//		alert(future_date);
	}
  /**
   * Used to hide and un hide div on subscriber edit/create pages
   */
 function showSubscriberDiv(div_name, checked){
    if(checked == true){
      $(div_name).style.display = "";
    }else{
      $(div_name).style.display = "none";
    }
  }