// -----------------------------------------------------------------------------
//  INITIALISATION
// -----------------------------------------------------------------------------

Event.observe(window, 'load' ,   function() { setupSingleSubmitButton();});


function initUnloadMessage(){
  
  var func = function(event){
    if(event.keyCode == 116){  return; } // Skip F5 key
    window.onbeforeunload = function unloadMess() { return I18N.glp('warn.edit.contentlost'); } // Register unload message
    initKeyObs(false); // Unregister keypress listener
  }
  
  var initKeyObs = function(init){
    if (init){ Event.observe(document, 'keypress' , func); } 
    else    { Event.stopObserving(document, 'keypress' , func); }
  
    $A(window.frames).each(function(elm,idx){
      if (init){ Event.observe(elm.document, 'keypress' , func); } 
      else    { Event.stopObserving(elm.document, 'keypress' , func); }
    });
  };
  
  initKeyObs(true);
}

// ----------------------------------------------------------------------------
// Data Chooser 
// -----------------------------------------------------------------------------

function openDataChooser(window, ctxPath, form, widget, pos, jspPath, width, height){ // ctxPath must not end with '/', and jspPath must start with '/'
 var formName   = getFormName(window.document, form);
 var widgetPos  = getFormElementPos(form,widget)+pos;
 var chooser    = ctxPath+jspPath+"targetInput=document."+formName+".elements["+widgetPos+"].value&targetLabel=document."+formName+".elements["+(widgetPos-1)+"].value";
 popupWindow(chooser, 'DataChooser', width, height,'no','yes','yes',false);
}

// -----------------------------------------------------------------------------
// Date Chooser 
// -----------------------------------------------------------------------------

function openDateChooser(window, ctxPath, form, widget, pos, dateOnly, showWeek){ 
 var formName   = getFormName(window.document, form);
 var widgetPos   = getFormElementPos(form,widget)+pos;
 var fieldValue  = escape(form.elements[widgetPos].value);
 var targetInput = "document."+formName+".elements["+widgetPos+"].value";
 var chooser     = ctxPath+"/work/calendarPopup.jsp?showWeekNbr="+showWeek+"&dateOnly="+dateOnly+"&datetime="+fieldValue+"&targetInput="+targetInput;
 popupWindow(chooser, 'calendar', '300', dateOnly ? '320' : '320');
}

// -----------------------------------------------------------------------------
// Doc Chooser 
// -----------------------------------------------------------------------------

function openDocChooser(window, ctxPath, form, widget, pos, nbElt, id){ 
 var formName   = getFormName(window.document, form);
 var widgetPos  = getFormElementPos(form,widget) + pos;
 var chooser    = ctxPath+"/work/docChooser.jsp?form="+formName+"&nbElt="+nbElt+"&startElt="+(widgetPos-1);
 
 if (id){
  chooser   = chooser+"&id="+id;
 }
 Popup.popupWindow(chooser, 'DocChooser', 640, 600,'no','yes','yes',false);
}

// -----------------------------------------------------------------------------
// File Chooser 
// -----------------------------------------------------------------------------

function openFileChooser(window, ctxPath, path, form, widget, pos){ 
 var formName   = getFormName(window.document, form);
 var widgetPos  = getFormElementPos(form,widget)+pos;
 var chooser    = ctxPath+"/work/fileChooser.jsp?"+path+"targetInput="+formName+".elements["+widgetPos+"]&targetInputValue="+escape(form.elements[widgetPos].value);
 popupWindow(chooser, 'FileChooser', 700, 500,'no','yes','yes',false);
}

// -----------------------------------------------------------------------------
// Color Chooser 
// -----------------------------------------------------------------------------

function openColorChooser(window, ctxPath, form, widget, pos){ 
 var formName   = getFormName(window.document, form);
 var widgetPos  = getFormElementPos(form,widget)+pos;
 var chooser    = ctxPath+"/work/colorChooser.jsp?targetInput="+formName+".elements["+widgetPos+"]";
 popupWindow(chooser, 'ColorChooser', 235, 220,'no','no','yes',false);
}

// -----------------------------------------------------------------------------
// Query Chooser 
// -----------------------------------------------------------------------------

function openQueryChooser(window, ctxPath, form, widget, pos){ 
 var formName   = getFormName(window.document, form);
 var widgetPos  = getFormElementPos(form,widget)+pos;
 var chooser    = ctxPath+"/work/queryChooser.jsp?targetInput=document."+formName+".elements["+widgetPos+"].value&targetLabel=document."+formName+".elements["+(widgetPos-1)+"].value&qs="+escape(form.elements[widgetPos].value);
 popupWindow(chooser, 'QueryChooser', 800, 400,'no','yes','yes',false);
}

// -----------------------------------------------------------------------------
// Image Chooser
// -----------------------------------------------------------------------------

function openImageChooser(window, ctxPath, form, widget, pos){ 
 internalOpenImageChooser(window, ctxPath, form, widget, pos, false);
}
function openImagePubChooser(window, ctxPath, form, widget, pos){ 
 internalOpenImageChooser(window, ctxPath, form, widget, pos, true);
}

function internalOpenImageChooser(window, ctxPath, form, widget, pos, isPubChooser){ 
  var formName   = getFormName(window.document, form);
  var widgetPos  = getFormElementPos(form,widget)+pos;
  var chooser    = ctxPath + "/work/mediaBrowser.jsp?medias=image&jsFunc="
                  + (isPubChooser ? "MediaBrowser.insertPub" : "MediaBrowser.insertMedia")
                  + "&targetInput=document."+formName+".elements["+widgetPos+"]"
                  + (isPubChooser ? ("&targetLabel=document."+formName+".elements["+(widgetPos-1)+"]") : "");
 
  popupWindow(chooser, 'MediaBrowser', 930, 570,'no','no','no',false);
}

// -----------------------------------------------------------------------------
// Media Chooser 
// -----------------------------------------------------------------------------

function openMediaChooser(window, ctxPath, form, widget, pos){ 
 internalOpenMediaChooser(window, ctxPath, form, widget, pos, 'MediaBrowser.insertMedia');
}
function openMediaPubChooser(window, ctxPath, form, widget, pos){ 
 internalOpenMediaChooser(window, ctxPath, form, widget, pos, 'MediaBrowser.insertPub', true);
}
function internalOpenMediaChooser(window, ctxPath, form, widget, pos, jsfunc, label){ 
 var formName   = getFormName(window.document, form);
 var widgetPos  = getFormElementPos(form,widget)+pos;
 var chooser    = ctxPath + "/work/mediaBrowser.jsp?media=all&jsFunc="+jsfunc
                  + "&targetInput=document."+formName+".elements["+widgetPos+"]"
                  + (label ? ("&targetLabel=document."+formName+".elements["+(widgetPos-1)+"]") : "");
 popupWindow(chooser, 'MediaBrowser', 930, 570,'no','no','no',false);
}


// -----------------------------------------------------------------------------
// TEST SQLQuery
// -----------------------------------------------------------------------------


function testSQLQuery(window, ctxPath, form, widget, pos, title){
  var sqlQuery   = form.elements[getFormElementPos(form,widget)+pos];
	var dataSource = form.elements[getFormElementPos(form,widget+"DataSource")+pos];
	var maxRows    = form.elements[getFormElementPos(form,widget+"MaxRows")+pos];
	
	var chooser    = ctxPath+"/work/checkSQLQuery.jsp?";
	    chooser   += "dataSource=" +escape(dataSource.value);
	    chooser   += "&maxRows="   +escape(maxRows.value);
	    chooser   += "&sqlQuery="  +escape(sqlQuery.value);
	
	// alert("pos: "+pos+"\ndataSource "+dataSource.value + "\nmaxRows " + maxRows.value + "\nsqlQuery "+sqlQuery.value);
	popupWindow(chooser, title, 400, 600,'no','yes','yes',false);   
}


// -----------------------------------------------------------------------------
// Common jsFunc callback functions : Image and Media Chooser 
// -----------------------------------------------------------------------------

if (!window.MediaBrowser) {
  var MediaBrowser = new Object();
}

Object.extend(MediaBrowser,{
	
	/**
	 * @param fdId id of the FileDocument being inserted
	 * @param fdTitle title of the FileDocument being inserted
	 * @param fdMediaType media type of the FileDocument being inserted
	 *        ('image', 'video', 'audio', 'flash', 'other')
	 * @param fdUrl the relative url of the FileDocument being inserted
	 * @param targetInput the input in which to store the id or URL,
	 *        for example 'document.myForm.elements[12]'
	 * @param targetLabel the input in which to store the title
	 *        for example 'document.myForm.elements[13]'
	 */
	 
	insertPub: function(fdId, fdTitle, fdMediaType, fdUrl, targetInput, targetLabel) {
	  var evalScript = targetInput + ".value = '" + fdId + "';";
	  evalScript += targetLabel + ".value = '" + fdTitle + "';";
	  eval(evalScript);
	},
	
	insertMedia: function(fdId, fdTitle, fdMediaType, fdUrl, targetInput, targetLabel) {
	  var evalScript = targetInput + ".value = '" + fdUrl + "';";
	  eval(evalScript);
	}
	
});

    
// -----------------------------------------------------------------------------
// Wysiwyg
// -----------------------------------------------------------------------------

'JCMS.wysiwyg.TinyMceCB'.namespace({

  // --------------------------------------------------------------
  // onInit callback
  // All processed done here are made to make sure that we do not allow
  // form submit when content is not yet ready (which could submit partial on empty data).
    
  // Number of wysiwyg editor to be initialized for current page
  editorsNbr : 0,
  
  /**
   * Method invoked after each editor has been initialized properly (see onInit).
   */
  initInstanceCB : function (ed) {
    JCMS.wysiwyg.TinyMceCB.editorsNbr = JCMS.wysiwyg.TinyMceCB.editorsNbr - 1;
    JCMS.wysiwyg.TinyMceCB._checkWysiwygEditorInitialization(ed);
  },

  /**
   * This method should be called to check if all wysiwyg editors are completely ready.
   */
  _checkWysiwygEditorInitialization: function (ed) {
    if (ed) {
      JcmsLogger.debug('TinyMCE_JcmsPluginCB', '[', ed.id, '] [_checkWysiwyg] - editorsNbr:', JCMS.wysiwyg.TinyMceCB.editorsNbr);
    } else {
       JcmsLogger.debug('TinyMCE_JcmsPluginCB', '[_checkWysiwyg] - editorsNbr:', JCMS.wysiwyg.TinyMceCB.editorsNbr);
    }
    if (JCMS.wysiwyg.TinyMceCB.editorsNbr != 0) {
      return;
    }
    if (window.document.editForm && window.document.editForm.pageLoaded) {
      window.document.editForm.pageLoaded.value = 'true';
    }
  },
  
  /**
   * Count the number of editors on the page.
   * Used onload to initialized number of editors on page.
   */
  _countWysisygEditorOnPage : function() {
    JCMS.wysiwyg.TinyMceCB.editorsNbr += $$('TEXTAREA.formRichText').size();
    JCMS.wysiwyg.TinyMceCB._checkWysiwygEditorInitialization();
  }
});

Event.observe(window, 'load', JCMS.wysiwyg.TinyMceCB._countWysisygEditorOnPage);

// -----------------------------------------------------------------------------
// Duration Chooser 
// -----------------------------------------------------------------------------

function fillDurationField(window, form, widget, pos, resolution){
  var widgetPos  = getFormElementPos(form,widget)+pos;
	restrictToNumerics(form.elements[widgetPos+1]);
  form.elements[widgetPos].value = form.elements[widgetPos+1].value * form.elements[widgetPos+2].value / resolution;
}

// -----------------------------------------------------------------------------
// Fields 
// -----------------------------------------------------------------------------

function fillOpenerField(window, form, widget, pos, id, label){
  var widgetPos  = getFormElementPos(form,widget)+pos;
  form.elements[widgetPos].value   = id;
  form.elements[widgetPos-1].value = label;
  window.close();
}

function submitAddCount(window, form, widget, fullwidget, addCount, langCount, id){
  var elmCount = getFormElementCount(form, widget, id) / langCount;
  fullwidget.value = elmCount+addCount;
  simpleSubmitForm(window, form, "opRefresh", "Wait WYSIWYG");
}

function clearDefField(def, e1, e2, e3, e4) {
    if (e1 != null) {
      if (e1.options)
        e1.options[0].selected = true;
      else
        e1.value = def;
    }
    if (e2 != null) {
      if (e2.options)
        e2.options[0].selected = true;
      else
        e2.value = def;
    }
    if (e3 != null) {
      if (e3.options)
        e3.options[0].selected = true;
      else
        e3.value = def;
    }
    if (e4 != null) {
      if (e4.options)
        e4.options[0].selected = true;
      else
        e4.value = def;
    }
}


function moveFormElement(form, widget, relativepos, op, relfirst, id) {
  var array = form.elements;
  var first = getFormElementPos(form,widget,id)+relfirst;
  var last  = getFormElementLastPos(form, widget, true,id)+relfirst;
  var pos   = first + relativepos;

  // alert(id+': '+first+'->'+pos+'<-'+last);

  // Move Up
  if (op == "up") {
    if (pos > first) { 
      tmp = array[pos].value;
      array[pos].value = array[pos - 1].value;
      array[pos - 1].value = tmp;
    } else {
      tmp = array[first].value;
      for(i = first; i < last; i++) {
        array[i].value = array[i + 1].value;
      }
      array[last].value = tmp;
    }
  } 
  // Move Down
  else if (op == "down") {
    if (pos < last) {
      tmp = array[pos].value;
      array[pos].value = array[pos + 1].value;
      array[pos + 1].value = tmp;
    } else {
      tmp = array[last].value;
      for(i = last; i > first; i--) {
        array[i].value = array[i - 1].value;
      }
      array[first].value = tmp;
    }
  }
  // Remove Element
  else if (op == "remove") {
    for(i = pos; i < last; i++) {
      array[i].value = array[i + 1].value;
    }
    array[last].value = "";

  }
}

function move2FormElement(form, widget, relativepos, op, relfirst, id) {
  var array = form.elements;
  
  // Find position -1 because we locate the second field not the first one
  var first = getFormElementPos(form,widget,id) + relfirst;
  var last  = getFormElementLastPos(form, widget, false,id) + relfirst;
  var pos   = first + relativepos;

  // Move Up
  if (op == "up") {
    if (pos > first) {
      tmp1 = array[pos].value;
      tmp2 = array[pos+1].value;
      array[pos    ].value = array[pos - 2].value;
      array[pos + 1].value = array[pos - 1].value;
      array[pos - 2].value = tmp1;
      array[pos - 1].value = tmp2;
    } else {
      tmp1 = array[first].value;
      tmp2 = array[first+1].value;
      for(i = first; i < last; i+=2) {
        array[i  ].value = array[i + 2].value;
        array[i+1].value = array[i + 3].value;
      }
      array[last].value = tmp1;
      array[last+1].value = tmp2;
    }
  } 
  // Move Down
  else if (op == "down") {
    if (pos < last) {
      tmp1 = array[pos].value;
      tmp2 = array[pos+1].value;
      array[pos    ].value = array[pos + 2].value;
      array[pos + 1].value = array[pos + 3].value;
      array[pos + 2].value = tmp1;
      array[pos + 3].value = tmp2;
    } else {
      tmp1 = array[last    ].value;
      tmp2 = array[last + 1].value;
      for(i = last; i > first; i-=2) {
        array[i].value = array[i - 2].value;
        array[i+1].value = array[i - 1].value;
      }
      array[first    ].value = tmp1;
      array[first + 1].value = tmp2;
    }
  }
  // Remove Element
  else if (op == "remove") {
    for(i = pos; i < last; i+=2) {
      array[i].value   = array[i + 2].value;
      array[i+1].value = array[i + 3].value;
    }
    array[last].value = "";
    array[last+1].value = "";
  }
}

function move3FormElement(form, widget, relativepos, op, relfirst, id) {
  var array = form.elements;
  
  // Find position -1 because we locate the second field not the first one
  var first = getFormElementPos(form,widget,id) + relfirst;
  var last  = getFormElementLastPos(form, widget, false, id) + relfirst;
  var pos   = first + relativepos;

  // Move Up
  if (op == "up") {
    if (pos > first) {
      tmp1 = array[pos].value;
      tmp2 = array[pos+1].value;
      tmp3 = array[pos+2].value;
      array[pos    ].value = array[pos - 3].value;
      array[pos + 1].value = array[pos - 2].value;
      array[pos + 2].value = array[pos - 1].value;
      array[pos - 3].value = tmp1;
      array[pos - 2].value = tmp2;
      array[pos - 1].value = tmp3;
    } else {
      tmp1 = array[first].value;
      tmp2 = array[first+1].value;
      tmp3 = array[first+2].value;
      for(i = first; i < last; i+=3) {
        array[i  ].value = array[i + 3].value;
        array[i+1].value = array[i + 4].value;
        array[i+2].value = array[i + 5].value;
      }
      array[last].value = tmp1;
      array[last+1].value = tmp2;
      array[last+2].value = tmp3;
    }
  } 
  // Move Down
  else if (op == "down") {
    if (pos < last) {
      tmp1 = array[pos].value;
      tmp2 = array[pos+1].value;
      tmp3 = array[pos+2].value;
      array[pos    ].value = array[pos + 3].value;
      array[pos + 1].value = array[pos + 4].value;
      array[pos + 2].value = array[pos + 5].value;
      array[pos + 3].value = tmp1;
      array[pos + 4].value = tmp2;
      array[pos + 5].value = tmp3;
    } else {
      tmp1 = array[last    ].value;
      tmp2 = array[last + 1].value;
      tmp3 = array[last + 2].value;
      for(i = last; i > first; i-=3) {
        array[i].value = array[i - 3].value;
        array[i+1].value = array[i - 2].value;
        array[i+2].value = array[i - 1].value;
      }
      array[first    ].value = tmp1;
      array[first + 1].value = tmp2;
      array[first + 2].value = tmp3;
    }
  }
  // Remove Element
  else if (op == "remove") {
    for(i = pos; i < last; i+=3) {
      array[i].value   = array[i + 3].value;
      array[i+1].value = array[i + 4].value;
      array[i+2].value = array[i + 5].value;
    }
    array[last].value = "";
    array[last+1].value = "";
    array[last+2].value = "";
  }
}

// -----------------------------------------------------------------------------
// Form Element Access 
// -----------------------------------------------------------------------------

function getFormElementCount(form, name, id){
  // Get all elements
  var elms  = form.elements;
  var count = 0;
  
  // Count element
  for (var i = 0 ; i < elms.length ; i++){
    if (elms[i].name != name)
      continue;
      
    if (!id){
      count++;
      continue;
    }
    
    if ((elms[i].id == id) || (elms[i].id.indexOf(id) > -1)){ // very ugly
      count++;
    }
  }
  return count;
}

function getFormElementPos(form, name, id){
  // Get all elements
  var elms = form.elements;
 
  // Find out the (first) current element
  
  for (var i = 0 ; i < elms.length ; i++){
    if (elms[i].name != name) {
      continue;
    }      
    if (!id) {
      return i;
    }
    
    if ((elms[i].id == id) || (elms[i].id == id+'0') || (elms[i].id && elms[i].id.startsWith(id)) ){ // very ugly
      return i;
    }
  }
  return -1;
}

function getFormElementLastPos(form, name, first, id){
  // Get all elements
  var elms = form.elements;
 
  // Find out the (last) current element
  var last = -1;
  for (var i = 0 ; i < elms.length ; i++){

    if (elms[i].name != name){
      if (last > 0 && first)
        break;
      continue;
    }
      
    if (!id){
      last = i;
      continue;
    }
      
    if (elms[i].id.indexOf(id) > -1){
      last = i;
      continue;
    }
    
    if (last > 0 && first)
      break;
  }
  return last;
}

// -----------------------------------------------------------------------------
// Button 
// -----------------------------------------------------------------------------


function toggleSingleSubmitButton(evt, form, on){

	// check "this" is a form, otherwise, use given form
	if (this.elements) {
	  form = this;
	}

	// Enable/Disable all formButton
	var elements = $(form.elements);
	for (var i = 0 ; i < elements.length ; i++){
    var elm = $(elements[i]);

	  if (!on){
		  if (!elm.hasClassName("formButton")) { continue; }
		  elm.addClassName("disabledButton");
		  elm.oldclick = elm.onclick;
		  elm.onclick  = function(event){ return false; }
	  } else {
	    if (!elm.hasClassName("disabledButton")) { continue;  }
	    elm.removeClassName("disabledButton");
		  elm.onclick  = elm.oldclick;
		  elm.oldclick = null;
	  }
  }
  
  // Register/Unregister myself
  if (!on){
	  form.oldsubmit = form.onsubmit;
	  form.onsubmit  =  function(event){ return false; }
    window.onbeforeunload = null;	  // disable the warning msg put in doEditPubFooter.jsp
  }
  else{
	  form.onsubmit  =  form.oldsubmit;
	  form.oldsubmit = null;
  }
}

function setupSingleSubmitButton(off){
  
  // Register function
  try{
  var forms = document.forms;
  for (var i = 0 ; i < forms.length ; i++){
    var form = $(forms[i]);
    
    if (form.hasClassName("noSingleSubmitButton"))
      continue;
      
    if (off){
      toggleSingleSubmitButton(null, forms[i], true);
      continue;
    }
    
    var onsubmit = form.onsubmit;
    if (typeof onsubmit == 'function') {
      form.onsubmit = function(evt){
        toggleSingleSubmitButton(evt, this);
        return onsubmit(evt, this);
      };
    }
    else{
      form.onsubmit = toggleSingleSubmitButton;
    }
  }
  } catch(ex){ alert(ex); }
}

function restrictToNumerics(input) {
 var re = new RegExp("[^0-9]");
 var value = input.value;
 var cleaned = value.replace(re, "");
 input.value = cleaned;
}

// -----------------------------------------------------------------------------
// Form 
// -----------------------------------------------------------------------------

/**
 * form should be like: window.document.editForm
 */ 
function simpleSubmitForm(window, fullform, action, warn, anchorValue, actionValue) {
  
  if(fullform.pageLoaded && fullform.pageLoaded.value=='false') {
    alert(warn);
    return;
  }

  for (var i = 0; i < fullform.elements.length; i++) {
    if (fullform.elements[i].jcmsSubmitCallBack != null) {
      fullform.elements[i].jcmsSubmitCallBack(window, fullform, action, warn, anchorValue);
    }
  }

  if (anchorValue){
  	fullform.anchor.value = anchorValue;
  }
  
  if (action && fullform.action){
    fullform.action.name  = action;
    if (actionValue)
      fullform.action.value = actionValue;
  }
  
  if (fullform.onsubmit)
    fullform.onsubmit();
  fullform.submit();
}

function confirmSubmitForm(window, fullform, action, msg, warn, anchorValue, actionValue) {
  if (top.confirm(msg)) {
    simpleSubmitForm(window, fullform, action, warn, anchorValue, actionValue);
  }
}
function confirmSubmitFormLightBox(window, fullform, action, msg, warn, anchorValue, actionValue) {
  JCMS.window.Modal.confirm(msg, function(ok) {
    if (ok) {
      simpleSubmitForm(window, fullform, action, warn, anchorValue, actionValue);
    }
  });
}

function getFormName(document, form){
  if (document.all){
    if (form.attributes){
      if (form.attributes.getNamedItem){
      	return form.attributes.getNamedItem("NAME").value;
      }
      else{
      	if (form.attributes["name"])
      	  return form.attributes["name"];
      	else if (form.attributes["NAME"])
      	  return form.attributes["NAME"];
      	else
      	  return 'editForm';
      }
    }
    else{
    	return 'editForm';
    }
  }
  else{
    return form.getAttribute("NAME");
  }
}

// -----------------------------------------------------------------------------
// EditPubFooter: DEPRECATED Should be removed or replaced
// -----------------------------------------------------------------------------
	

	function submitForm(action, anchor, actionvalue) {  
	  simpleSubmitForm(window, window.document.editForm, action,'Error',anchor, actionvalue);
	}
	function confirmSubmit(msg, action, anchor, actionvalue) {
    confirmSubmitForm(window, window.document.editForm, action, msg, anchor, actionvalue)
	}
	function submitAction(action, value) {
	  simpleSubmitForm(window, window.document.editForm, action,'Error',null, value);
	}
	
	/* This function are no longer used in JCMS 5.5
		function removeField(element, anchor) {
		  element.value = "__remove__";
		  submitForm("opRefresh", anchor);
		}
		function removeSelectedIndex(element, anchor) {
		  element.options[element.selectedIndex].value = "__remove__";
		  submitForm("opRefresh", anchor);
		}
		function clearSelectedIndex(element) {
		  element.selectedIndex=0;
		}
		function validateListItem(action, list, pos) {
		  window.document.editForm.opItem.name = action;
		  window.document.editForm.opItem.value = list;
		  window.document.editForm.itemPos.value = pos;
		  submitForm("opRefresh", list);
		}
	*/

