<?xml version="1.0"?>
<dynaForm type="xmlform" labelWidth="250px" width="95%" enableTemplate="1">
  <title type="title" colWidth="200" showInTable="0">
    <en><![CDATA[Department Information]]></en>
  </title>
  <DEP_UID type="hidden" showInTable="0"/>
  <DEP_PARENT type="hidden" showInTable="0"/>
  <DEP_TITLE type="text" colWidth="200" size="30" maxlength="64" required="1">
    <en><![CDATA[Department Name]]></en>
  </DEP_TITLE>
  <BTN_CANCEL type="button" onclick="cancel();">
    <en><![CDATA[Cancel]]></en>
  </BTN_CANCEL>
  <button type="button" onclick="return validateLocalFields(this.form);" showInTable="0">
    <en><![CDATA[Save]]></en>
  </button>
  <JS type="javascript" replacetags="1"><![CDATA[
	document.onkeypress=function(e){
var esIE=(document.all);
var esNS=(document.layers);
tecla=(esIE) ? event.keyCode : e.which;
if(tecla==13){
	return false;
  }
}

//getField('DEP_TITLE').value ='';
var sGroupname;
sGroupname = document.forms[0].elements['form[DEP_TITLE]'].value;
var verifyDptoname = function()
{ 
  document.forms[0].elements['form[DEP_TITLE]'].disabled = true;
  document.forms[0].elements['form[button]'].disabled = true;    
  
  var newvar =(typeof(this.value)=="undefined" )?getField('DEP_TITLE').value:this.value;
  
  var oRPC = new leimnud.module.rpc.xmlhttp({
    url    :'departments_Ajax',
    async  : false,
    method :'POST',
    args   :'action=verifyDptoname&sOriginalGroupname=' + sGroupname + '&sGroupname=' + encodeURIComponent(newvar)});
  oRPC.make();
  var sResponse = oRPC.xmlhttp.responseText; 
  document.forms[0].elements['form[DEP_TITLE]'].disabled = false;
  if (sResponse == '1')
  {
    new leimnud.module.app.alert().make({
	    label: G_STRINGS.ID_MSJ_DEPTO
  	});
    document.forms[0].elements['form[DEP_TITLE]'].focus();
  }
  else
  { 
  	getField('button').disabled= false;
  }
};
  
leimnud.event.add(document.forms[0].elements['form[DEP_TITLE]'],'change',verifyDptoname);  

var validateLocalFields = function(oForm){
//oAux1 = oForm.elements['form[DEP_TITLE]'];
 var oAux1 =getField('DEP_TITLE');

	if (oAux1.value == '')
	{
		new leimnud.module.app.alert().make({
	    label:G_STRINGS.DBCONNECTIONS_ALERT
  	});
		oAux1.focus();
		bContinue = false;
		return false;
	} else {
		savedepto( oForm );
  }

};

function cancel(){
    currentPopupWindow.remove();
}
]]></JS>
</dynaForm>
