function XS_Frame(sId, sTitle, oContent, jOptions)
{
    var sClass='class="XS_Frame" ';
    var sWidth="";
    var sHeight="";
    var sB = '';
    var sA = ''; 
    var nW = 0;
    
    if (jOptions!=null)
    {
        if(jOptions.myClass != null && jOptions.myClass!= 'undefined')
            sClass='class="' + jOptions.myClass + '" ';

        if(jOptions.width != null && jOptions.width!= 'undefined')
            sWidth = 'width:' + jOptions.width;
            
        if(jOptions.height != null && jOptions.height!= 'undefined')
            sHeight = 'height:' + jOptions.height;
        
        if(jOptions.onToggle != null && jOptions.onToggle!= 'undefined')
        {
            sA = '<a href="javascript:_XS_toggle(\'' + sId + '\')'; 
            if(jOptions.onToggle != 'on')
                sA += ';' + jOptions.onToggle; 
            sA += '"><img id="' + sId + '_img" value="U" src="/XS_Include/img/window/U.gif" border="0"/></a>';
            sB += sA;  
            nW += 15;
        }

        if(jOptions.onClose != null && jOptions.onClose != 'undefined')
        {
            var sX = '_X_' + sId + '()';
            sA = '<a href="javascript:function ' +  sX + '{ $(' + sId + ').hide(); ' 
            if(jOptions.onClose != 'on')
                sA += jOptions.onClose; 
            sA += '; }; ' + sX + ';"><img src="/XS_Include/img/window/X.gif" border="0" title="Cerrar"/></a>';
            sB += sA;  
            nW += 15;
        }    
    }            
    
    var sHtml = '<div style="padding:0;' + sWidth + ';" id="' + sId + '" ' + sClass + '>';
    if(sB != '')
    {
        sHtml = sHtml + '<table cellspacing="0" cellpadding="0" style="border:0; padding:0; width:100%;"><tr><th id="' + sId + '_title">' + sTitle + '</th><th align="right" width="' + nW + '">' + sB + '</th></tr></table>';
        sHtml = sHtml + '<div style="padding:5px;" id="' + sId + '_body" style="'+ sHeight +'; overflow:auto;"></div>';
    }    
    else
    {
        sHtml = sHtml + '<table cellspacing="0" cellpadding="0" style="border:0; padding:0; width:100%;"><tr><th id="' + sId + '_title">' + sTitle + '</th></tr></table>';
        sHtml = sHtml + '<div style="padding:5px;" id="' + sId + '_body" style="'+ sHeight +'; overflow:auto"></div>';
    }    
    sHtml += '</div>';
    
    var oDiv = document.createElement('div');
    oDiv.innerHTML = sHtml;
    if ( typeof(oContent)=='string' )
        oDiv.firstChild.childNodes[1].innerHTML = oContent    
    else    
        oDiv.firstChild.childNodes[1].appendChild(oContent);    

    return oDiv.innerHTML;    
}

function _XS_toggle(sId, oImg)
{
    var oTable = $(sId);
    //var oImg = oTable.rows[0].cells[1].firstChild.firstChild;
    
    oImg = $(sId + '_img');
    var sValue = oImg.getAttribute('value');
    if(sValue == 'U')
    {
        oImg.src="include/img/D.gif";
        oImg.setAttribute('value', 'D');
        $(sId + '_body').hide();
    }
    else
    {
        oImg.src="include/img/U.gif";
        oImg.setAttribute('value', 'U');
        $(sId + '_body').show();
    }

}

var _winNotes = null
function XS_Notes(cod_doc, cod_sec)
{
   var lClosed = true;
   document.body.style.cursor = 'wait';    
	  var sURL = '/SIAS/XS_Include/Notes/XS_Notes.asp?cod_doc=' + cod_doc + '&cod_sec=' + cod_sec;
	  var oWin = _winNotes; //$(_winNotes);
	  if( oWin != null)
	        lClosed = oWin.closed;
	  
	  if (lClosed)
	  {
          var iWidth  = 800;
          var iHeight = 520;	  
	      var iLeft   = (screen.width - iWidth) / 2
	      var iTop    = (screen.height - iHeight) / 2
	      _winNotes = window.open("" + sURL, "_notes", "toolbar=NO, menubar=NO, directories=NO, location=NO, titlebar=NO, status=NO, resizable=NO, scrollbars=yes, left=" + iLeft + ",top=" + iTop + ",width=" + iWidth + ",height=" + iHeight)
	   }
	   else
	   {
	       oWin.focus(); 
	   }    
	       
   document.body.style.cursor = 'default';    
     
}


var _winNotes = null
function XS_Help(cod_doc, cod_sec)
{
   var lClosed = true;
   document.body.style.cursor = 'wait';    
	  var sURL = '/SIAS/XS_Include/Notes/XS_Notes.asp?cod_doc=' + cod_doc + '&cod_sec=' + cod_sec;
	  var oWin = _winNotes; //$(_winNotes);
	  if( oWin != null)
	        lClosed = oWin.closed;
	  
	  if (lClosed)
	  {
          var iWidth  = 800;
          var iHeight = 520;	  
	      var iLeft   = (screen.width - iWidth) / 2
	      var iTop    = (screen.height - iHeight) / 2
	      _winNotes = window.open("" + sURL, "_notes", "toolbar=NO, menubar=NO, directories=NO, location=NO, titlebar=NO, status=NO, resizable=NO, scrollbars=yes, left=" + iLeft + ",top=" + iTop + ",width=" + iWidth + ",height=" + iHeight)
	   }
	   else
	   {
	       oWin.focus(); 
	   }    
	       
   document.body.style.cursor = 'default';    
     
}

//XS_createCollection( { id:'', padding:'2', frame:'0px #cccccc solid',  layout:'horizontal' | 'vertical', labelPos:'left' | 'top' 
//                list:[
//                    {type:'rut',  label:'RUT', size:'12', field:'sch_RUT'}, 
//                    {type:'text', label:'Apellido', size:'20', field:'sch_Apellido'}, 
//                    {type:'list', label:'Estado', field:'sch_Estado', list:'1=Activo,2=Inactivo'}, 
//                    {type:'button', id:'btnBuscaRubro', label:'Buscar', onClick:'javascript:RubroTexto_search()'},
//                     ]
//                   }) 

function XS_createCollection(jObject)
{

    jObject = Object.toJSON(jObject).evalJSON();

    if(jObject.LabelWidth==null || jObject.LabelWidth=='undefined')
        var sLar = ''
    else
        var sLar = jObject.LabelWidth;

    if(jObject.padding==null || jObject.padding=='undefined')
        var sPad = '2'
    else
        var sPad = jObject.padding;

        
    var oDiv = document.createElement('div');
    oDiv = $(oDiv)
    oDiv.setAttribute('id', jObject.id);
    if(jObject.padding!=null && jObject.padding!='undefined')
        oDiv.style.padding = jObject.padding;
    if(jObject.myClass!=null && jObject.myClass!='undefined')
        oDiv.addClassName(jObject.myClass);
    else
        oDiv.addClassName('XS_SecCollection');
        
    if(jObject.layout!=null && jObject.layout!='undefined')
        var sLayout = jObject.layout
    else
        var sLayout = 'horizontal';

    if(jObject.labelPos==null || jObject.labelPos=='undefined')
       jObject.labelPos = 'left';

    if(jObject.frame!=null && jObject.frame!='undefined')
        oDiv.style.border = jObject.frame;

    if(jObject.width!=null && jObject.width!='undefined')
        oDiv.style.width = jObject.width;
    var nTabIndex = 0;
    if (sLayout == 'vertical') 
    {
        var oTable = document.createElement('table');
        oTable.setAttribute('cellspacing',sPad);
        for(var i=0;i<jObject.list.length;i++)
        {
            var oTR = oTable.appendChild(document.createElement('tr'));
            var oTD = oTR.appendChild(document.createElement('td'));
            var oObj = XS_createControl(jObject.list[i], nTabIndex++);
            if(oObj.getAttribute('label')!=null)
            {
                if(sLar!='')
                    oTD.setAttribute("width",sLar)
                oTD.innerHTML = oObj.getAttribute('label');    
            }
            var oTD = oTR.appendChild(document.createElement('td'));
            Insertion.Bottom(oTD, oObj);
       }     
       Insertion.Bottom(oDiv, oTable);
    }
    else //Horizontal
    {
        var oTable = document.createElement('table');
        oTable.setAttribute('cellspacing', sPad);
        if(jObject.labelPos == 'top')
        {
                var oTR_L = oTable.appendChild(document.createElement('tr'));
                var oTR = oTable.appendChild(document.createElement('tr'));
                for(var i=0;i<jObject.list.length;i++)
                {
                    var oTD = oTR.appendChild(document.createElement('td'));
                        oTD.innerHTML = oObj.getAttribute('label');    

                    var oObj = XS_createControl(jObject.list[i], nTabIndex++);
                    var oTD = oTR.appendChild(document.createElement('td'));
                    Insertion.Bottom(oTD, oObj);
               }     
        }
        else
        { 
                var oTR = oTable.appendChild(document.createElement('tr'));
                for(var i=0;i<jObject.list.length;i++)
                {
                    var oObj = XS_createControl(jObject.list[i], nTabIndex++);
                    var oTD = oTR.appendChild(document.createElement('td'));
                    if(oObj.getAttribute('label')!=null && oObj.getAttribute('label')!='undefined')
                    {
                        oTD.innerHTML = oObj.getAttribute('label');    
                    }
                    var oTD = oTR.appendChild(document.createElement('td'));
                    Insertion.Bottom(oTD, oObj);
               }     
        }       
       Insertion.Bottom(oDiv, oTable);
    }    
    oDiv.innerHTML = oDiv.innerHTML ; 
    return oDiv
}


//XS_createView( { id:'', myClass:'', width:'',
//                list:[ 
//                    [
//                    {type:'rut',  label:'RUT', width:'12', field:'sch_RUT'}, 
//                    {type:'text', label:'Apellido', width:'20', field:'sch_Apellido'}, 
//                     ],
//                    [
//                    {type:'rut',  label:'RUT', width:'12', field:'sch_RUT'}, 
//                    {type:'text', label:'Apellido', width:'20', field:'sch_Apellido'}, 
//                     ]
//                   ]}) 

function XS_createView(jObject)
{

    jObject = Object.toJSON(jObject).evalJSON();

    var oDiv = document.createElement('div');
    oDiv = $(oDiv)
    oDiv.setAttribute('id', jObject.id);
    if(jObject.myClass!=null && jObject.myClass!='undefined')
        oDiv.addClassName(jObject.myClass);
    else
        oDiv.addClassName('XS_SecCollection');

//    if(jObject.frame!=null && jObject.frame!='undefined')
//        oDiv.style.border = jObject.frame;

//    if(jObject.width!=null && jObject.width!='undefined')
//        oDiv.style.width = jObject.width;
        
    var sTable = '<table cellspacing="0" cellpadding="0">';
    for(var nR=0;nR<jObject.list.length;nR++)
    {
        var sLabel = '';
        var sData = '';
        for(var i=0;i<jObject.list[nR].length;i++)
        {
            sLabel += '<span style="text-align:center; padding:2px; width:' + jObject.list[nR][i].width + '; font-weight:bold; background:#cccccc;">' + jObject.list[nR][i].label + '</span>'
            sData  += '<span id="' + jObject.list[nR][i].field + '" style="text-align:center; padding:2px; width:' + jObject.list[nR][i].width + '; border:1px #cccccc solid;">' + jObject.list[nR][i].value + '</span>'
        }     
        sTable += '<tr><td>' + sLabel + '</td></tr>';
        sTable += '<tr><td>' + sData + '</td></tr>';
    }   
    sTable += '</table>'
    oDiv.innerHTML = sTable; 
    return oDiv
}



/*
jObject = {type:'number', label:'Archivo', labelWidth:'150', field:'FILE', size:'', value:'', required:'R', minVal:'0',  maxVal:'10', eval:'')
jObject = {type:'list' , label:'Tipo de Documento', labelWidth:'150', field:'TIPO_DOC', value:'', required:'R', eval:'', list:"-1=Seleccione, PRE=Presentación, PRO=Propuesta, NOT=Noticia, ANT=Antecedente, OTR=Otros" }
jObject = {type:'file' , label:'Archivo', labelWidth:'150', field:'FILE', value:'', required:'R', eval:'',  size:'50', path:'c:\\', file_id:'11111', fileType:'*', minFiles:'1', maxFiles:'1', maxSize:'1000000' }
jObject = {type:'date' , label:'Fecha', labelWidth:'150', field:'fecha',  value:'01/01/2008', required:'R', min:'',  max:'', eval:''}
jObject = {type:'rut'  , label:'RUT', field:'RUT' , value:'', required:'O', eval:''} 
*/
function XS_createControl(jParam, nTabIndex)
{
    jObject = Object.toJSON(jParam).evalJSON();
    var obj = 'none'
    var sType = jObject.type.toLowerCase(); 

    switch(sType)
    {
    case 'text':
        var obj = XS_textEdit(jObject.label, jObject.field, jObject.mask, jObject.size, jObject.value, jObject.required, jObject.min, jObject.max, jObject.eval, jObject.align)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    
        
    case 'number':
        var obj = XS_numberEdit(jObject.label, jObject.field, jObject.size, jObject.format, jObject.value, jObject.required, jObject.minVal, jObject.maxVal, jObject.eval)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'percent':
        var obj = XS_percentEdit(jObject.label, jObject.field, jObject.value, jObject.required, jObject.eval)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    
        
    case 'list':
        var obj = XS_listEdit(jObject.label, jObject.field, jObject.value, jObject.required, jObject.list, jObject.eval)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'date':
        var obj = XS_dateEdit(jObject.label, jObject.field, jObject.mask, jObject.value, jObject.required, jObject.minVal, jObject.maxVal, jObject.eval)
        if(nTabIndex!=null)
        {
            var oInput = obj.rows[0].cells[0].firstChild;
            oInput.setAttribute('tabindex', nTabIndex);         
            var oInput = obj.rows[0].cells[1].firstChild;
            oInput.setAttribute('tabindex', nTabIndex);         
        }    
        break;    

    case 'email':
        var obj = XS_emailEdit(jObject.label, jObject.field, jObject.value, jObject.required, jObject.size, jObject.min, jObject.max, jObject.eval)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'rut':
        var obj = XS_rutEdit(jObject.label, jObject.field, jObject.value, jObject.required, jObject.eval)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'pop':
        if(jObject.code==null || jObject.code=='undefined')
        {
            alert(jObject.label + ' : le falta definir el campo "code"');
        }    
        var obj = XS_popEdit(jObject.label, jObject.field, jObject.value, jObject.code, jObject.required, jObject.size, jObject.pop, jObject.eval)
        if(nTabIndex!=null)
        {
            var oInput = obj.rows[0].cells[0].firstChild;
            oInput.setAttribute('tabindex', nTabIndex);         
            var oInput = obj.rows[0].cells[1].firstChild;
            oInput.setAttribute('tabindex', nTabIndex);         
        }    
        break;    

    case 'textarea':
        var obj = XS_textAreaEdit(jObject.label, jObject.field, jObject.value, jObject.rows, jObject.cols, jObject.required, jObject.min, jObject.max, jObject.eval)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'option':
        var obj = XS_optionEdit(jObject.label, jObject.field, jObject.value, jObject.format, jObject.required, jObject.list, jObject.eval)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'check':
//        var obj = XS_checkEdit(jObject.label, jObject.field, jObject.value, jObject.format, jObject.required, jObject.list, jObject.eval)
        var obj = XS_checkEdit(jObject.label, jObject.format, jObject.required, jObject.list);
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'checkbox':
        var obj = XS_checkBoxEdit(jObject.label, jObject.field, jObject.value, jObject.required, jObject.eval)
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'file':
//        var obj = XS_UpLoad(jObject.label, jObject.field, jObject.size, jObject.value, jObject.required, jObject.path, jObject.file_id, jObject.fileType, jObject.minFiles, jObject.maxFiles, jObject.maxSize, jObject.eval );       

                var oInput = document.createElement('input')
                oInput.setAttribute("label", jObject.label)    
                oInput.setAttribute("type", 'file')
                oInput.setAttribute("size", jObject.size)
                oInput.setAttribute("id", jObject.field)
                oInput.setAttribute("name", "f_"+jObject.field)
                oInput.setAttribute("prm", "XS_Field")
                if (jObject.value != null)
                    oInput.setAttribute("value", jObject.value)
                else
                    oInput.setAttribute("value", "");
                    
                if (jObject.required == 'R')
                    oInput.setAttribute("required", jObject.required)
                else
                    oInput.setAttribute("required",'');
                oInput.style.border="1px #cccccc solid"    
                oInput.style.font="normal 10px verdana,arial,serif";    
                
                if (jObject.eval == null || jObject.eval=='')
                    oInput.setAttribute("onBlur", 'this.style.background = "#ffffff"')
                else
                    oInput.setAttribute("onBlur", jObject.eval );
        
        obj = oInput
        if(nTabIndex!=null)
            obj.setAttribute('tabindex', nTabIndex);         
        break;    

    case 'label':
        var obj = document.createElement('span')
        obj.setAttribute('type','label')
        //obj.style.border="1px #cccccc solid"    
        obj.style.font="normal 10px verdana,arial,serif";    
        obj.style.background = '#eaeaea';
        obj.innerHTML = jObject.label;
        obj.innerHTML = obj.innerHTML ;    
        break;    
        
    case 'title':
        var obj = document.createElement('div')
        obj.setAttribute('type','title')
        obj.setAttribute('class','XS_SecSubTitle')
        obj.setAttribute('id', jObject.field)        
        obj.innerHTML = jObject.value;
        obj.innerHTML = obj.innerHTML ;    
        break;    
        
    case 'captcha':
        var obj = document.createElement('div')
        obj.setAttribute('type','captcha')
        var sTabla = '<table class="XS_Capcha" cellspacing="0" cellpadding="0" width="250">';
            if(jObject.label!=null)
                sTabla = sTabla + '<tr><td class="XS_listTitle">'+jObject.label+'</td></tr>';
            sTabla = sTabla + '<tr><td align="center"></td></tr>'        
            sTabla = sTabla + '<tr><td align="center"><img src="/XS_Include/Captcha/CAPTCHA_image.asp" id="CAPTCHA_ID" /></td></tr>'
            sTabla = sTabla + '<tr><td align="center"></td></tr>'        
            sTabla = sTabla + '<tr><td align="center"><input class="Input" name="captcha" id="' + jObject.field + '" size="10"/></td></tr>'
            sTabla = sTabla + '<tr><td align="center"><a href="javascript:XS_reloadCAPTCHA(' + jObject.field + ');" class="A">Nuevo Código</a></td></tr>'
            sTabla = sTabla + '<tr><td align="center"></td></tr></table>'        
        obj.innerHTML = sTabla;
        break;            
        
    case 'link':
        var obj = document.createElement('div')
        obj.setAttribute('type','link')
        obj.setAttribute('class','XS_Link')
        var sLink = '';
        if(jObject.icon+'' != 'undefined')
            sLink = '<img height="15" style="cursor:pointer" src="/Xs_include/Icons/icon_' + jObject.icon + '.gif" border="0" title="' + jObject.tip + '"/>'
        if(jObject.text+'' != 'undefined')
            sLink += jObject.text;
        obj.innerHTML = '<a onclick="' + jObject.url + '" target="' + jObject.target + '">' + sLink + '</a>';
        obj.innerHTML = obj.innerHTML ;
        break;    
        
    case 'button':
        var obj = document.createElement('div')
        obj.innerHTML = '<input type="button" class="boton" id="' + jObject.id + '" value="' + jObject.label + '" onClick="' + jObject.onClick + '" />';
        obj = obj.firstChild;
        break;

    case 'wait':
        var obj = document.createElement('div')
        if(jObject.label+''!='undefined')
            obj.innerHTML = '<span style="display:none" id="' + jObject.id + '"><img height="15" src="/Xs_include/Icons/icon_rotor.gif" border="0"/> ' + jObject.label + '</span>';
        else
            obj.innerHTML = '<span style="display:none" id="' + jObject.id + '"><img height="15" src="/Xs_include/Icons/icon_rotor.gif" border="0"/></span>';
        obj = obj.firstChild;
        break;

    }
    
    if (obj == 'none')
    {
        alert('XS_createControl: No se identificó el tipo de Control para\n' + Object.toJSON(jParam) )
    }
    else
    if (obj == null)
    {
        alert('XS_createControl: No se creó Control para\n' + Object.toJSON(jParam) )
    }
    return obj;    
}


function XS_reloadCAPTCHA(sId) 
{
    $(sId).value = '';
	document.getElementById('CAPTCHA_ID').src='/XS_Include/Captcha/CAPTCHA_image.asp?' + Math.random();
}    



function XS_verifyCAPTCHA( sCode)
{
  if(sCode=='')
     return false;  
  var sResult = '';
  var lRet = false;
  var peticion =  new Ajax.Request('/XS_Include/Captcha/CAPTCHA_Verify_Ajax.asp?securityCode='+ sCode + '&rnd=' + Math.random(),   
		  {     
			 method: 'post', 
			 postBody: 'securityCode='+sCode,
			 contentType: 'application/x-www-form-urlencoded',
			 asynchronous: false,
			 onComplete: function(transport)
	 		 {   
 				 if (transport.statusText == 'OK')
 				 {		 		
				      sResult = transport.responseText;		
				      if (sResult.substring(0,3) == 'OK=')		
				          return lRet=true;
				 }						 
				 else
				 {
				 	  alert(transport.statusText)		
				 }	
	 		 },     
	 		 onFailure: function()
	 		 { 
				alert('XS_verifyCAPTCHA: Error de conexión...') 
				return null;
	 		 }   
		  }
	);   	
	return lRet;
}


function XS_validateControl(obj)
{
    var sFormat = obj.getAttribute('format');
    var sMsg = '';
    if (sFormat != null)
    {    
        switch ( sFormat )
        {
           case 'text':
                sMsg = XS_textEdit_val(obj, '');
                break;
                
           case 'number':
                sMsg = XS_numberEdit_val(obj, '');
                break;

           case 'percent':
                sMsg = XS_numberEdit_val(obj, '');
                break;
                                                        
           case 'rut':
                var sMsg = XS_rutEdit_val(obj, 'box');
                break;

           case 'date':
                var sMsg = XS_dateEdit_val(obj, '');
                break;                                
                
           case 'email':
                var sMsg = XS_emailEdit_val(obj, '');
                break
           
           case 'textarea':
                var sMsg = XS_textAreaEdit_val(obj, '');
                break;

           case 'list':
                var sMsg = XS_listEdit_val(obj, '');
                break;                                

           case 'pop':
                var sMsg = XS_popEdit_val(obj, '');
                break;                                

           case 'check':
                alert('valid check')
                break;                                

           case 'option':
                alert('valid option')
                break;                                
        }    
    }    
    else
    {
        alert('XS_validateControl: Tipo de Campo no Reconocido, especifique atributo "format" para Field:' + obj.id)
    }            
    return sMsg;
}


function XS_jumpLoader(sFileType)
{
    var sApp = ''
    sApp = sApp + '<applet name="jumpLoaderApplet"'
	sApp = sApp + '    code="jmaster.jumploader.app.JumpLoaderApplet.class"'
	sApp = sApp + '    archive="http://127.0.0.1/XS_Include/jumploader_z.zip"'
	sApp = sApp + '    width="120"'
	sApp = sApp + '    height="35"'
	sApp = sApp + '    mayscript>'
    if (sFileType != '' && sFileType.toLowerCase() == 'image')	
	    sApp = sApp + ' 		<param name="uc_imageEditorEnabled" value="true"/>'
	else    
	    sApp = sApp + ' 		<param name="uc_imageEditorEnabled" value="false"/>';
	
	sApp = sApp + '		    <param name="uc_fileParameterName" value="UploadFile"/>'
	sApp = sApp + '		    <param name="uc_uploadUrl" value="http://127.0.0.1/XS_Include/asp/XS_UpLoad.asp"/>'
	sApp = sApp + '		    <param name="uc_maxFileLength" value="1024000"/>' 
	sApp = sApp + '		    <param name="uc_minFiles" value="1" />' 
	sApp = sApp + '		    <param name="uc_maxFiles" value="10" />'
    sApp = sApp + '         <param name="vc_useThumbs" value="true"/>'			
	sApp = sApp + '		    <param name="vc_mainViewFileTreeViewVisible" value="true"/>'
	sApp = sApp + '		    <param name="vc_mainViewFileListViewVisible" value="true"/>'
	sApp = sApp + '		    <param name="vc_mainViewFileListViewVisible" value="true"/>'
	sApp = sApp + '		    <param name="vc_uploadViewRetryActionVisible" value="true"/>'
	sApp = sApp + '		    <param name="ac_fireUploaderStatusChanged" value="true"/>'
    sApp = sApp + '         <param name="ac_mode" value="framed"/>'
    sApp = sApp + '</applet>'
    return sApp;

}



//Applet SUN para Upload de archivos
function XS_UpLoad( sLabel, sField, sSize, sValue, sRequired, sPath, sFileId, sFileType, nMinFiles, nMaxFiles, nMaxSize, sEval)
{
    var oDiv = document.createElement('div');
    oDiv.setAttribute("type", 'file')                       
    oDiv.setAttribute("label", sLabel)                       
    Insertion.Bottom(oDiv);

    var oInput = XS_createInput(sLabel, sField,  'file', 'text', sValue, 'P', sEval)
    oInput.setAttribute("size", sSize);
    Insertion.Bottom(oDiv, oInput );
    
    var sApp = XS_jumpLoader(sFileType)
    Insertion.Bottom(oDiv, sApp );
    oDiv.innerHTML = oDiv.innerHTML
    return oDiv;    
}


// Crea un objeto de tipo Input
function XS_createInput(sLabel, sField, sType, sFormat, sValue, sRequired, sEval)
{
    var oInput = document.createElement('input')
    oInput.setAttribute("label", sLabel)    
    oInput.setAttribute("type", sType)
    oInput.setAttribute("id", sField)
    oInput.setAttribute("name", "f_"+sField)
    oInput.setAttribute("prm", "XS_Field")
    oInput.setAttribute("format", sFormat)
    if (sValue != null)
        oInput.setAttribute("value", sValue)
    else
        oInput.setAttribute("value", "");
        
    if (sRequired == 'R')
        oInput.setAttribute("required", sRequired)
    else
    if (sRequired == 'P')
    {
        oInput.setAttribute("required", sRequired);
        oInput.setAttribute('readOnly', 'true');
        oInput.style.background = '#eaeaea';
    }
    else
        oInput.setAttribute("required",'');
    oInput.style.border="1px #cccccc solid"    
    oInput.style.font="normal 10px verdana,arial,serif";    
    if (sRequired != 'P')
        oInput.setAttribute("onFocus", 'this.style.background = "#ffffd9"');
    
    if (sEval == null || sEval=='')
        oInput.setAttribute("onBlur", 'this.style.background = "#ffffff"')
    else
        oInput.setAttribute("onBlur", sEval );
        
        
    return oInput
}


//Indica cuando un objeto de edición tiene error
function XS_editAlert(obj, sAlert, sMsg)
{
   if (sAlert == 'box' || sAlert == 'alert' )
   {
        if (sMsg == '')
        {        
            obj.style.border = "1px #cccccc solid";
            obj.style.background = "#ffffff";
        }    
        else
            obj.style.border = "1px red solid"
            

        if (sMsg != '')
        {
            obj.focus();
            if ( sAlert == 'alert')
                alert(sMsg);
        }    
   }
}

//Objeto Edición de texto
function XS_textEdit(sLabel, sField, sMask, nSize, sValue, sRequired, sMin, sMax, sEval, sAlign)
{
    var oInput = XS_createInput(sLabel, sField, "text", "text", sValue, sRequired, sEval);
    if(sAlign!=null)
        oInput.style.textAlign=sAlign;
    else
        oInput.style.textAlign="left";
    oInput.setAttribute("size", nSize);
    
    //Para verficación de largo de ingreso del texto
    if (sMin != null && sMin != '')
        oInput.setAttribute("min", sMin)        
    if (sMax != null && sMax != '')
        oInput.setAttribute("maxlength", sMax)                
        
    return oInput
}

function XS_textEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'XS_textEdit_val: No se identificó el objeto '; 
    var sRequired = obj.getAttribute('required');
    var nLar = obj.value.length;
    if ( nLar == 0)
    {
        if ( sRequired == 'R' )
        {
            sMsg = obj.getAttribute('label');
            if( sMsg=='')
                sMsg = 'Dato requerido';      
            else
                sMsg += ': Dato requerido';      
        }
    }
            
    var nPos = ValidaCaracter(obj.value, "',\",\\");
    if (nPos != -1)
    {
        sMsg = obj.value;
        sMsg = obj.getAttribute('label') + ': [ ' + sMsg.substr(nPos,1) + ' ] Caracter inválido';                                         
    }

    if (sMsg == '' && nLar > 0)
    {
        var sMin = obj.getAttribute('min')
        if (sMin != null && sMin != '')
            if (nLar < parseInt(sMin) )
                sMsg = obj.getAttribute('label') + ': El dato debe tener al menos ' + sMin + ' caracteres';

        var sMax = obj.getAttribute('max')
        if (sMax != null && sMax != '')
            if (nLar > parseInt(sMax) )
                sMsg = obj.getAttribute('label') + ': El dato debe tener máximo ' + sMax + ' caracteres';
    }    

    XS_editAlert(obj, sAlert, sMsg)
    return sMsg;
}


//Objeto Edición de texto
function XS_fileEdit(sLabel, sField, nSize, sValue, sRequired, sExtentions, sEval)
{
    var oInput = XS_createInput(sLabel, sField, "file", "text", sValue, sRequired, sEval);
    oInput.style.textAlign="left";
    oInput.setAttribute("size", nSize);
    oInput.setAttribute("extentions", sExtentions)        
    return oInput
}

function XS_fileEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'XS_fileEdit_val: No se identificó el objeto '; 
    var sRequired = obj.getAttribute('required');
    if ( obj.value.length == 0)
    {
        if ( sRequired == 'R' )
            sMsg = obj.getAttribute('label') + ': Dato requerido'; 
    }
            
    if (sMsg == '')
    {
        var nPos = ValidaCaracter(obj.value);
        if (nPos != -1)
        {
            sMsg = obj.value;
            sMsg = obj.getAttribute('label') + ': [ ' + sMsg.substr(nPos,1) + ' ] Caracter inválido';                                         
        }
    }

    if (sMsg == '')
    {
        var nLar = obj.value.length;
        var sMin = obj.getAttribute('min')
        if (sMin != null && sMin != '')
            if (nLar < parseInt(sMin) )
                sMsg = obj.getAttribute('label') + ': El dato debe tener al menos ' + sMin + ' caracteres';

        var sMax = obj.getAttribute('max')
        if (sMax != null && sMax != '')
            if (nLar > parseInt(sMax) )
                sMsg = obj.getAttribute('label') + ': El dato debe tener máximo ' + sMax + ' caracteres';
    }    

    XS_editAlert(obj, sAlert, sMsg)
    
    return sMsg;
}



//***********************

//Objeto de edición de rut
function XS_rutEdit(sLabel, sField, sValue, sRequired, sEval)
{
    var oInput = XS_createInput(sLabel, sField, "text", "rut", sValue, sRequired, sEval);
    oInput.style.textAlign="left";
    oInput.setAttribute("size", 12);
    return oInput
}   

function XS_rutEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'XS_rutEdit_val: No se identificó el objeto '; 
    var sRequired = obj.getAttribute('required');
    if ( obj.value.length == 0)
    {
        if ( sRequired == 'R' )
            sMsg = obj.getAttribute('label') + ': Dato requerido'; 
    }
    else
    if ( !_F_IsRut(obj) )
        sMsg = obj.getAttribute('label') + ': Rut inválido';
    XS_editAlert(obj, sAlert, sMsg)
    return sMsg;
}
//********************************



//Objeto de edición para text area
function XS_textAreaEdit(sLabel, sField, sValue, sRows, sCols, sRequired, sMin, sMax, sEval)
{
    var oDiv = document.createElement('div')    
    oDiv.innerHTML = '<textarea id=' + sField + ' name=f_' + sField + ' prm="XS_Field" rows=' + sRows + ' cols=' + sCols + ' class="Input" format="textarea" >'+sValue+'</textarea>'
    var oTextArea = oDiv.firstChild;
    
    oTextArea.setAttribute("label", sLabel);
    oTextArea.setAttribute("onFocus", 'this.style.background="#ffffd9"; this.style.border="1px #cccccc solid"');
    oTextArea.setAttribute("onBlur", 'this.style.background = "#ffffff"');
    
    
    //Para verficación de largo de ingreso del texto
    if (sMin != null && sMin != '')
        oTextArea.setAttribute("min", sMin)        
    if (sMax != null && sMax != '')
        oTextArea.setAttribute("max", sMax)                

    if (sRequired != null)
        oTextArea.setAttribute("required",sRequired)
    else
        oTextArea.setAttribute("required","");

    if (sEval != null)
        oTextArea.setAttribute("onBlur", sEval + '(this)')


    return oTextArea;
}

function XS_textAreaEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'No se identificó el objeto '; 
    var sRequired = obj.getAttribute('required');
    var sValue = obj.value;
    if ( sValue.length == 0)
    {
        if ( sRequired == 'R' )
        {
            sMsg = obj.getAttribute('label');
            if( sMsg=='')
                sMsg = 'Dato requerido';      
            else
                sMsg += ': Dato requerido';      
        }    
    }
            
    if (sMsg == '')
    {
        var nPos = ValidaCaracter(sValue, String.fromCharCode(10,13));
        if (nPos != -1)
        {
            sMsg = sValue;
            sMsg = obj.getAttribute('label') + ': [ ' + sMsg.substr(nPos,1) + ' ] Caracter inválido';                                         
        }
    }

    if (sMsg == '')
    {
        var nLar = sValue.length;
        var sMin = obj.getAttribute('min')
        if (sMin != null && sMin != '')
            if (nLar < parseInt(sMin) )
                sMsg = obj.getAttribute('label') + ': El dato debe tener al menos ' + sMin + ' caracteres';

        var sMax = obj.getAttribute('max')
        if (sMax != null && sMax != '')
            if (nLar > parseInt(sMax) )
                sMsg = obj.getAttribute('label') + ': El dato debe tener máximo ' + sMax + ' caracteres';
    }    

    XS_editAlert(obj, sAlert, sMsg)
    
    return sMsg;
}

//*******************************

//Objeto para edición de correos electrónicos
function XS_emailEdit(sLabel, sField, sValue, sRequired, nSize, sMin, sMax, sEval)
{
    var oInput = XS_createInput(sLabel, sField, "text", "email", sValue, sRequired, sEval);
    oInput.setAttribute("size", nSize);    
    return oInput;
}

function XS_emailEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'No se identificó el objeto '; 
    var sRequired = obj.getAttribute('required');
    if ( sRequired == 'R' )
    {
        if ( obj.value.length == 0)
            sMsg = obj.getAttribute('label') + ': Dato requerido'
        else
            if ( !ValidaCorreo(obj.value) )
                sMsg = obj.getAttribute('label') + ': Dato inválido'; 
    }
    else            
    {
        if ( obj.value.length != 0)
            if ( !ValidaCorreo(obj.value) )
                sMsg = obj.getAttribute('label') + ': Dato inválido'; 
    }         

    XS_editAlert(obj, sAlert, sMsg)
   
   return sMsg;
}
//*****************************



//Objeto de edición de numeros            
function XS_numberEdit(sLabel, sField, nSize, sMask, sValue, sRequired, nMinVal, nMaxVal, sEval)
{
    if(sEval == null && sMask != 'none')
        sEval = 'XS_numberEdit_format(this)';
        
    var oInput = XS_createInput(sLabel, sField, "text", "number", sValue, sRequired, sEval);
    oInput.style.textAlign="right";
    oInput.setAttribute("size", nSize);
    //Para verficación de rangos de ingreso
    if (nMinVal != null && nMinVal != '')
        oInput.setAttribute("min", nMinVal)        
    if (nMaxVal != null && nMaxVal != '')
        oInput.setAttribute("max", nMaxVal)                
 
    if (sMask != null && sMask != '')
        oInput.setAttribute("mask", sMask)        
    oInput.setAttribute('onkeypress', 'return _F_onlyNumbers(event)' );
    return oInput
}

function XS_numberEdit_format(obj)
{
    obj.value = Replace(obj.value,'.','');
    obj.value = FormatNumber(obj.value);
}

function XS_numberEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'No se identificó el objeto '; 
    var sRequired = obj.getAttribute('required');

    if ( obj.value.length == 0)
    {
        if ( sRequired == 'R' )
            sMsg = obj.getAttribute('label') + ': Dato requerido'; 
    }
            
    if (sMsg == '')
    {
        var sNum = Replace(obj.value,'.',''); 
        if ( SoloTipo(sNum, "9") )
        {
            var sMin = obj.getAttribute('min')
            if (sMin != null && sMin != '')
                if (parseFloat(sNum) < parseFloat(sMin) )
                    sMsg = "El valor no debe ser menor que " + sMin;

            var sMax = obj.getAttribute('max')
            if (sMax != null && sMax != '')
                if (parseFloat(sNum) > parseFloat(sMax) )
                    sMsg = "El valor no debe ser mayor que " + sMax
        }
        else
            sMsg = obj.getAttribute('label') + ': Dato inválido'; 
   }         
  
     XS_editAlert(obj, sAlert, sMsg)
  
   return sMsg;
}


//**************************

 
//Objeto de edición de porcentaje
function XS_percentEdit(sLabel, sField, sValue, sRequired, sEval)
{
    var oInput = XS_createInput(sLabel, sField, "text", "percent", sValue, sRequired, sEval);
    oInput.style.textAlign="center";
    oInput.setAttribute("size", 4);    
    oInput.setAttribute("min", 0)        
    oInput.setAttribute("max", 100)                
    return oInput;
}




//Objeto de edición para fecha con icono de calendario 
function XS_dateEdit(sLabel, sField, sMask, sValue, sRequired, nMinVal, nMaxVal, sEval) 
{ 

    if (sMask != null && sMask != '') 
    { 
        if(sEval == null) 
            sEval = '_F_InputDate(this,\'' + sMask + '\')'; 
    } 
    
    var oInput = XS_createInput(sLabel, sField, "text", "date", sValue, sRequired, sEval); 
    oInput.setAttribute("size", "12"); 
    

    var sCel = '<img style="cursor:pointer" id="c_' + sField + '" src=/XS_Include/Icons/icon_calendar.gif border=0 height=15 onClick="javascript:_F_Calendar(this, \'dd/mm/yyyy\');"/>' 

    //Para verficación de rangos de ingreso 
    if (nMinVal != null && nMinVal != '') 
        oInput.setAttribute("min", nMinVal)        
    if (nMaxVal != null && nMaxVal != '') 
        oInput.setAttribute("max", nMaxVal)                
  
    if (sMask != null && sMask != '') 
        oInput.setAttribute("mask", sMask)        
    else 
        oInput.setAttribute('readonly','true'); 
  
    var oDiv = document.createElement('div')    

    oDiv.innerHTML = '<table format="date" label="'+ sLabel +'" border="0" cellspacing="0" cellpadding="0"><tr><td></td><td>' + sCel + '</td></tr></table>';

    oDiv.firstChild.rows[0].cells[0].appendChild(oInput); 
    return oDiv.firstChild;   

}    


function _F_InputDate(sId, sMask)
{
    var obj = $(sId);
    var sText = obj.value;
    if(sText.length == 0)
        return 

    sText = Replace(sText,'-','/');
    sText = Replace(sText,'.','/');
    if(sText.indexOf('/') == -1)
    {
        sText = sText.substr(0,2) + '/' + sText.substr(2,2) + '/' + sText.substr(4,4)
    }
    var aText = sText.split('/');
    
    
    if(aText.length == 3)
    {
        if(aText[2].length<4)
        {
            if(aText[2].length<2)
               aText[2] = '200' + aText[2]; 
            else   
               aText[2] = '20' + aText[2]; 
        }      
        sText = XS_padNumber(aText[0],2,'0') + '/' + XS_padNumber(aText[1],2,'0') + '/' + aText[2];
     }   
               
    obj.value = sText;
    if(_F_IsDate(obj, sMask) )
    {
        obj.style.borderColor = '#cccccc'
    }
    else
    {
        obj.style.borderColor = 'red';
        obj.focus();
    }
}



function _F_Calendar(imgObj, format) 
{ 
    var inputField = imgObj.parentNode.parentNode.firstChild.firstChild; 
    inputField.style.background = "#ffffd9"; 
    displayCalendar(inputField, format, imgObj); 
} 




function XS_dateEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'XS_dateEdit: No se identificó el objeto '; 
        
    var sRequired = obj.getAttribute('required');
    if ( obj.value.length == 0)
    {
        if ( sRequired == 'R' )
            sMsg = obj.getAttribute('label') + ': Dato requerido'; 
    }
    else
    {
        obj.value = Replace(obj.value, '-', '/');
        if ( !_F_IsDate(obj,"dma") )
            sMsg = obj.getAttribute('label') + ': Fecha inválida';
    }
    XS_editAlert(obj, sAlert, sMsg)
    return sMsg;
} 
//**************************



//Objeto para seleccionar de una lista combo-box 
function XS_listEdit(sLabel, sField, sValue, sRequired, oList, sEval)
{
    var oSelect = document.createElement('select')				   
    oSelect.setAttribute("id", sField)                       
    oSelect.setAttribute("label", sLabel)                       
    oSelect.setAttribute("format", 'list')                       
    oSelect.setAttribute("name", "f_"+sField)
    oSelect.setAttribute("prm","XS_Field")

    if (sValue != null)
        XS_SetOption(oSelect, sValue);
        
    if (sRequired != null)
        oSelect.setAttribute("required",sRequired)
    else
        oSelect.setAttribute("required","");

    oSelect.setAttribute("onFocus", 'this.style.background = "#ffffd9"')
    oSelect.setAttribute("onBlur", 'this.style.background = "#ffffff";')
    if (sEval != null)
        oSelect.setAttribute("onChange", sEval)
    
    oSelect.setAttribute("class", "Input")
    if (oList.substring(0,7) != '{list:[') //Carga los elementos de la lista de string
    {
        var aList = oList.split(',')
        for( var i=0;i<aList.length;i++ )
        {
            sOpcion = aList[i]
            aOpcion = sOpcion.split('=')
            sCodigo = aOpcion[0]
            sValor = aOpcion[1]

            var oOption = document.createElement('option')
            oOption.setAttribute('value',sCodigo)
            if (sValue == sCodigo)
               oOption.setAttribute('selected','true')
            oOption.appendChild(document.createTextNode(sValor))
            oSelect.appendChild(oOption)    	                    
        }
    }
    else //Carga los elementos de un Arreglo de Objetos
    {
        oList = oList.evalJSON()
        for(var i=0;i<oList.list.length;i++)
        {
            if(oList.list[i].type=='grp')
            {
                var oOption = document.createElement('optgroup');	     
                oOption.setAttribute("label", oList.list[i].name )
                oOption.appendChild(document.createTextNode(oList.list[i].name))
                oSelect.appendChild(oOption)    	                    
            }            
            else
            if(oList.list[i].type=='itm')
            {
                var oOption = document.createElement('option')
                oOption.setAttribute('value', oList.list[i].code)
                if (oList.list[i].code == sValue)
                    oOption.setAttribute('selected','true')
                oOption.appendChild(document.createTextNode(oList.list[i].name))
                oSelect.appendChild(oOption)    	                    
            }
        }
    }
    return oSelect; 
}     


function XS_listEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'No se identificó el objeto '; 
    var sRequired = obj.getAttribute('required');
    var sValue = obj.value;
    if(sValue == null || sValue == '')
        var sValue = $(obj.getAttribute('id')).value;                                       
    
    if ( sValue == '-1' || sValue == '')
        if ( sRequired == 'R' )
            sMsg = obj.getAttribute('label') + ': Dato requerido'; 

    XS_editAlert(obj, sAlert, sMsg)
            
    return sMsg;
}

function XS_listEdit_code(obj)
{
    if (obj == null) 
        return 'No se identificó el objeto '; 
    var sCode = $(obj.getAttribute('id')).value;                                       
    return sCode;
}

function XS_listEdit_value(obj)
{
    if (obj == null) 
        return 'No se identificó el objeto '; 
    var sValue = '';        
    var sCode = obj.value;    
    for(var nI=0;nI<obj.childNodes.length;nI++)
    {
//        if (obj.childNodes[nI].getAttribute('selected') == true)
        if (obj.childNodes[nI].getAttribute('value') == sCode)
        {
            sValue = obj.childNodes[nI].innerHTML;
            break;
        }
    }    
    return sValue;
}

function XS_listSet_code(obj, sCode)
{
    if (obj == null) 
        return 'No se identificó el objeto '; 
    for(var nI=0;nI<obj.childNodes.length;nI++)
    {
        if (obj.childNodes[nI].getAttribute('value') == sCode)
        {
            obj.childNodes[nI].setAttribute('selected','true')
            obj.childNodes[nI].selected = true;
        }    
        else
            obj.childNodes[nI].removeAttribute('selected');
    }    
}
//*************************
   
   
//Objeto para seleccionar desde una ventana Pop-up
function XS_popEdit(sLabel, sField, sValue, sCode, sRequired, sSize, sPop, sEval)
{
    var aField = sField.split(':')
    if (aField.length > 1)
    {
        sFieldValue = aField[0];
        sFieldCode  = aField[1];
    }  
    else
    {
        alert('Definición del Campo incompleta para el objeto tipo Pop, ejemplo VALUE_FIELD:CODE_FIELD')
        return;
    }

    var oInput = XS_createInput(sLabel, sFieldValue, "text", "pop", sValue, sRequired, sEval);
    
    oInput.setAttribute('readonly','true')
    oInput.setAttribute('code', sCode)
    oInput.setAttribute('fieldCode', sFieldCode)
    oInput.setAttribute('size', sSize)

    sPop = Replace(sPop,'(','');
    sPop = Replace(sPop,')','');
    
    var sCel = "<a href=javascript:" + sPop + "('" + sFieldValue + "','" + sFieldCode + "','" + sValue + "','" + sCode + "')>"                        
    sCel = sCel + '<img src=/Files/Icons/icon_search.gif border=0 height=15/>' 
    sCel = sCel + '</a>'

//    var sCel = '<img src="/Files/Icons/icon_search.gif" border=0 height=15" onClick=javascript:' + sPop + '("' + sFieldValue + '","' + sFieldCode + '","' + sValue + '","' + sCode + '")/>' 

    var oDiv = document.createElement('div')    
    oDiv.innerHTML = '<table format="pop" label="' + sLabel + '" border="0" cellspacing="0" cellpadding="0"><tr><td></td><td>' + sCel + '</td></tr></table>';
    oDiv.firstChild.rows[0].cells[0].appendChild(oInput);
    
    return oDiv.firstChild;
}

function XS_popEdit_val(obj, sAlert)
{
    var sMsg = '';
    if (obj == null) 
        return 'No se identificó el objeto '; 
    var sRequired = obj.getAttribute('required');
    if ( obj.value.length == 0)
    {
        if ( sRequired == 'R' )
            sMsg = obj.getAttribute('label') + ': Dato requerido'; 
    }
    
    XS_editAlert(obj, sAlert, sMsg)
    return sMsg;
}
//*******************



//Objeto tabla para seleccionar un elemento de un panel de opciones
function XS_optionEdit(sLabel, sField, sValue, sLayout, sRequired, sList, sEval)
{
    var aList = sList.split(',')
    var ooTable = document.createElement('table')    
    ooTable.setAttribute("id", sField)
    ooTable.setAttribute("label", sLabel)
    ooTable.setAttribute("code", sValue)
    ooTable.setAttribute("format", "option")
    ooTable.setAttribute('cellspacing','0');
    ooTable.setAttribute('cellpadding','0');
    for(var i=0;i<aList.length;i++)
    {
        if (sLayout.toLowerCase() == 'vertical' || i == 0)
        {
            var ooTR = document.createElement('tr')
            ooTR.style.font="normal 10px verdana";    
            ooTable.appendChild(ooTR)
        }    

        var sOpcion = aList[i]
        var aOpcion = sOpcion.split('=')
        var sCodigo = aOpcion[0]
        var sValor = aOpcion[1]
        var sSelected = '';
        if ( sCodigo == sValue )
            sSelected = ' checked ';

        var ooTD = document.createElement('td');
            ooTD.setAttribute("valign","middle");
            ooTD.style.border = '0px #cccccc solid';
            ooTD.innerHTML = '<input style="border:0px #cccccc solid" id="' + sField + '" ' + sSelected + ' format="option" name="f_' + sField + '" value="' + sCodigo + '" type="radio" prm="XS_Field"> '       

        ooTR.appendChild(ooTD)       
        ooTD = document.createElement('td')                            
        ooTD.appendChild(document.createTextNode(sValor))    
        ooTR.appendChild(ooTD)                                   
    }
    
    var oDiv = document.createElement(oDiv)
    oDiv.appendChild(ooTable);
    oDiv.innerHTML = oDiv.innerHTML
    return oDiv.firstChild;
}

function XS_checkBoxEdit(sLabel, sField, sValue, sRequired, sEval )
{
    var oInput = XS_createInput(sLabel, sField,  'checkbox', 'check', sValue, sRequired, sEval)
    return oInput;
}

//Objeto tabla para marcar items de una lista
function XS_checkEdit(sLabel, sLayout, sRequired, aFields)
{
    var ooTable = document.createElement('table')    
    ooTable.setAttribute("label", sLabel)
    ooTable.setAttribute("format", "check")
    ooTable.setAttribute('cellspacing','3');
    ooTable.setAttribute('cellpadding','0');
    for(var i=0;i<aFields.length;i++)
    {
        var sCampo  = aFields[i].field;
        var sCodigo = aFields[i].code;
        var sValor  = aFields[i].value;
        var sChecked = '';        
        if ( sCodigo == sValor)
        {
            sChecked = ' checked="true" ';
        }
        if (sLayout.toLowerCase() == 'vertical' || i == 0)
        {
            var ooTR = document.createElement('tr')
            ooTR.style.font="normal 10px verdana";    
            ooTable.appendChild(ooTR)
        }    
        var ooTD = document.createElement('td')
            ooTD.innerHTML = '<input style="border:0px" id="' + sCampo + '" format="check" ' + sChecked + ' name="' + sCampo + '" value="' + sCodigo + '" type="checkbox" prm="XS_Field">'       
        var oInput = ooTD.firstChild;
        oInput.setAttribute("onFocus", 'this.style.background = "#ffffd9"')
        oInput.setAttribute("onBlur", 'this.style.background = "#ffffff"')

        ooTR.appendChild(ooTD)       
        ooTD = document.createElement('td')                            
        ooTD.appendChild(document.createTextNode(aFields[i].label))    
        ooTR.appendChild(ooTD)       
        ooTable.appendChild(ooTR)
    }
    return ooTable;
}

//Limpia una lista del tipo Select
function XS_listClear(obj)
{
    if(obj!=null)
    {
	    for(var i=obj.length;i>=0;i--)
  	    obj.options[i]=null;
  	}
}


function XS_image(sId, sSource, sWidth, sHeight, sTitle)
{
    var oDiv = document.createElement('div');
    oDiv.id = sId;
    
}



function XS_Button(jButton, nIdx)
{
    var jButton = Object.toJSON(jButton).evalJSON();
    if (jButton.icon!=null)
        var sIcon = '<img src="/XS_Include/butt/b_' + jButton.icon + '.gif" border="0" valign="middle"/>&#160;'
    else
        var sIcon = '';
    if (jButton.tip!=null)
        var sTip = ' title="' + jButton.tip + '"'
    else
        var sTip = '';
                
    if(nIdx!=null)
    {
        nIdx++
        var sTabIndex = 'tabindex=' + nIdx
    }    
    else
        var sTabIndex = '';
    if( jButton.display != null)
       var sVisible = 'display:'+ jButton.display + '; '
    else
       var sVisible =  '';
    if( jButton.width != null)
       var sWidth = 'width:'+ jButton.width + 'px; '
    else
       var sWidth = '';
    sName = '<span style="width:50px; text-align:center">' + jButton.value + '</span>';
    var sBot = '<span ' + sVisible + '" ' + sTip + ' id="' + jButton.id + '"  ><a id="' + jButton.id + '_a" ' + sTabIndex + ' class="XS_IconBoton" href="javascript:' + jButton.onClick + '">' + sIcon + sName + '</a></span>'; 
    return sBot;
}

function XS_buttonList(jButton, nTabIndex)
{
    if(nTabIndex!=null)
        var nIdx = nTabIndex
    else
        var nIdx = null
    
    var oButton = Object.toJSON(jButton).evalJSON();
    var sDiv = '<div style="padding-left:0px; margin:0px;">' 
    for(var nB=0;nB<oButton.length;nB++)
    {
        if (oButton[nB].icon!=null)
            var sIcon = '<img src="/XS_Include/butt/b_' + oButton[nB].icon + '.gif" border="0" valign="middle"/>&#160;'
        else
            var sIcon = '';
        if (oButton[nB].tip!=null)
            var sTip = ' title="' + oButton[nB].tip + '"'
        else
            var sTip = '';
                    
        if(nIdx!=null)
        {
            nIdx++
            var sTabIndex = 'tabindex=' + nIdx
        }    
        else
            var sTabIndex = '';
        if( oButton[nB].display != null)
        {
           var sVisible = 'display:'+ oButton[nB].display + '; '
        }    
        else
            var sVisible =  '';
        if( oButton[nB].width != null)
           var sWidth = 'width:'+ oButton[nB].width + 'px; '
        else
           var sWidth = '';
           
        var sFloat = ' float:left; '

        if(oButton[nB].onOk == null)
            var sJS = oButton[nB].onClick
        else
            if(oButton[nB].onCancel == null)
                var sJS = "XS_displayMessage('" + oButton[nB].message + "', 'Confirmar', [{value:'Ok', icon:'Ok', onClick:'XS_closeMessage();" + oButton[nB].onOk + "'} ] )"                
            else
                var sJS = "XS_displayMessage('" + oButton[nB].message + "', 'Confirmar', [{value:'Ok', icon:'Ok', onClick:'XS_closeMessage();" + oButton[nB].onOk + "'},  {value:'Cancel', icon:'Cancel', onClick:'XS_closeMessage();" + oButton[nB].onCancel + "'}] )"                
            
        var sBot = '<div style="padding:5px; ' + sFloat + sVisible + sWidth + '" ' + sTip + ' id="' + oButton[nB].id + '" ' + sVisible + ' ><a id="' + oButton[nB].id + '_a" ' + sTabIndex + ' class="XS_IconBoton" href="javascript:' + sJS + '">' + sIcon + oButton[nB].value + '</a></div>' 
        sDiv = sDiv + sBot;	            
    }	            
    sDiv = sDiv + '</div>'

    return sDiv;
}


function XS_Buttons(sId, jButton, nTabIndex, oSession)
{
    this.type = 'Buttons';
	this.id = sId;
	this.display = 'block';
	this.divButtons = document.createElement('DIV')
    this.divButtons.id = this.id + '_but'; 

    if(nTabIndex!=null)
        var nIdx = nTabIndex
    else
        var nIdx = null
    
    var oButton = Object.toJSON(jButton).evalJSON();
    var sDiv = '' 
    var sFloat = ' float:left; '
    var lBoton = false;
    for(var nB=0;nB<oButton.length;nB++)
    {
        lBoton = false;
        if ( oButton[nB].code != null && oButton.code != '' )
        {
            if ( oSession != null )
                lBoton = ( oSession.isRol( oButton[nB].code ) )
            else
            {
                alert('XS_Buttons: No hay objeto de sesión para validar el rol')
                return;
            }    
        }    
        else
            lBoton = true;
        
        if(lBoton == true)
        {   
                if (oButton[nB].icon!=null)
                    var sIcon = '<img src="/XS_Include/butt/b_' + oButton[nB].icon + '.gif" border="0" valign="middle"/>&#160;'
                else
                    var sIcon = '';
                if (oButton[nB].tip!=null)
                    var sTip = ' title="' + oButton[nB].tip + '"'
                else
                    var sTip = '';
                            
                if(nIdx!=null)
                {
                    nIdx++
                    var sTabIndex = 'tabindex=' + nIdx
                }    
                else
                    var sTabIndex = '';
                if( oButton[nB].display != null)
                {
                   var sVisible = 'display:'+ oButton[nB].display + '; '
                }    
                else
                    var sVisible =  '';
                if( oButton[nB].width != null)
                   var sWidth = 'width:'+ oButton[nB].width + 'px; '
                else
                   var sWidth = '';
                   
                if (nB == oButton.length-1)
                    sFloat = ' float:none; '
                    
                if(oButton[nB].onOk == null)
                    var sJS = oButton[nB].onClick
                else
                    if(oButton[nB].onCancel == null)
                        var sJS = "XS_displayMessage('" + oButton[nB].message + "', 'Confirmar', [{value:'Ok', icon:'Ok', onClick:'XS_closeMessage();" + oButton[nB].onOk + "'} ] )"                
                    else
                        var sJS = "XS_displayMessage('" + oButton[nB].message + "', 'Confirmar', [{value:'Ok', icon:'Ok', onClick:'XS_closeMessage();" + oButton[nB].onOk + "'},  {value:'Cancel', icon:'Cancel', onClick:'XS_closeMessage();" + oButton[nB].onCancel + "'}] )"                
                    
                var sBot = '<div style="padding:5px; ' + sFloat + sVisible + sWidth + '" ' + sTip + ' id="' + oButton[nB].id + '" ' + sVisible + ' ><a id="' + jButton.id + '_a" ' + sTabIndex + ' class="XS_IconBoton" href="javascript:' + sJS + '">' + sIcon + oButton[nB].value + '</a></div>' 
                sDiv = sDiv + sBot;	            
        }     
    } //for	            
    this.divButtons.innerHTML = sDiv + '<br/>';
    this.getContent = function()
                    {
                    return this.getContainer().innerHTML;
                    }   
	this.getContainer = function()
	    {
	        if($(this.id + '_but') == null)
	            return this.divButtons
	        else
	            return $(this.id + '_but');
	    }   
	         
    this.hide = function(aButtons)
    {
            $(this.getContainer()).hide();        
            this.display = 'none';
            if (aButtons == null)
            {
                var aButtons = this.getContainer().childNodes;
                var sId = '';
                for(var i=0;i<aButtons.length;i++)
                {
                    sId = $(aButtons[i].getAttribute('id') +'');
                    if(sId != null)
                        sId.hide();
                }            
            }            
            else
                for(var i=0;i<aButtons.length;i++)
                {
                    $(aButtons[i]).hide();                             
                }            
    }    
    
    this.show = function(aButtons)
    {
            $( this.getContainer()).show()                
            this.display = 'block';
            if (aButtons == null)
            {
                var aButtons = this.getContainer().childNodes;
                for(var i=0;i<aButtons.length;i++)
                {
                    sId = $(aButtons[i].getAttribute('id') +'');
                    if(sId != null)
                        sId.show();
                }            
            }            
            else
                for(var i=0;i<aButtons.length;i++)
                {
                    $(aButtons[i]).show();                             
                }            
    }    

    //Setea el javascript de ejecución para el botón
    this.setOnClick= function(sId, sOnClick)
    {
        var oA = $(sId + '_a');
        if (oA == null)
            alert('Botón ' + sId + ' no identificado')
        else
            oA.setAttribute('href', sOnClick);        
    }
    
    this.toogle= function(sButton)
        {
            var lDo = false;
            var aButtons = this.getContainer().childNodes;
            for(var i=0;i<aButtons.length;i++)
            {
                var oButton = aButtons[i]; 
                lDo = false;
                if (sButton!=null)
                {
                    if ( oButton.getAttribute('id').toUpperCase() == sButton.toUpperCase() )
                        lDo = true;
                }
                else
                    lDo = true;
                if(lDo)
                {
                    var oAttr = oButton.getAttribute('disabled')
                    if (oAttr == null || oAttr == false || oAttr == 'false')
                        var sDisabled = 'true'
                    else
                        var sDisabled = 'false'
                      
                    if ( sDisabled == 'false')
                    {
                        oButton.removeAttribute('disabled')
                        oButton.setAttribute('class', 'boton');                             
                    }    
                    else
                    {
                        oButton.setAttribute('disabled', 'true');                             
                        oButton.setAttribute('class', 'botonOff');                             
                    }    
                }
            }
        }

}
 

function XS_MenuTitle(sTitle)
{
    return '<li class="XS_Title">' + sTitle + '</li>'
}


function XS_Show(sId)
{
    var obj = $(sId);
    if(obj != null)
       obj.show(); 
}

function XS_Hide(sId)
{
    var obj = $(sId);
    if(obj != null)
       obj.hide(); 
}
