
/*
   corelibs.js
   ----------
   
   Librerias de usuo com?n.
   
   Versi?n    : 1.0
   Fecha      : 01 de Septiembre de 2003
   Empresa    : CoreSystems S.A
   Modificado : Por Rodrigo  Rojas D., 29 de Septiembre de 2003
   Modificado : 27/12/2004.  Dagoberto Henriquez A.
   
   
/*-    Obtiene la posicion de la fila segun el Id  -*/
function getRowPosition(Tabla,IdRow)
{
        for (i=1;i<Tabla.rows.length;i++)
                if (Tabla.rows[i].id==IdRow)
                       return i;

return 0;
}



function isNumeric(x) {
    var numbers=".0123456789";
    // is x a String or a character?
    if(x.length>1) {
      // remove negative sign
      x=Math.abs(x)+"";
      for(j=0;j<x.length;j++) {
        // call isNumeric recursively for each character
        number=isNumeric(x.substring(j,j+1));
        if(!number) return number;
      }
      return number;
    }
    else {
      // if x is number return true
      if(numbers.indexOf(x)>=0) return true;
      return false;
    }
  }


/*Elimina todo el contenido de la tabla meno los headers*/
function clearTablas(Tabla){

while (Tabla.rows.length >1)
	Tabla.deleteRow ()
} 

function abreAdjuntos() {
    if (num==null || num==undefined){
       return;
    }

    var sUrl = urlRedirect + "PAG_WORKFLOWADJUNTOS&num="+num;

    // Calcula el espacio disponible de acuerdo al tamano.
    var winWidth = 450;
    var winHeight = 360;
    var winTop = ((window.screen.availHeight-winHeight) / 2);
    var winLeft = ((window.screen.availWidth-winWidth) / 2);
    var winProperties = "toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+winWidth+",height="+winHeight+",left="+winLeft+",top="+winTop;

    // Abre la ventana solicitada
    window.open(sUrl,"Archivos_Adjuntos",winProperties);
}

function abreHistorial() {
    if (num==null || num==undefined){
			return;
		}

    var sUrl = urlRedirect + "PAG_WORKFLOWHISTORIAL&num="+num;

    // Calcula el espacio disponible de acuerdo al tamano.
    var winWidth = 750;
    var winHeight = 300;
    var winTop = ((window.screen.availHeight-winHeight) / 2);
    var winLeft = ((window.screen.availWidth-winWidth) / 2);
    var winProperties = "toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+winWidth+",height="+winHeight+",left="+winLeft+",top="+winTop;

    // Abre la ventana solicitada
    window.open(sUrl,"Historial",winProperties);
}

function abreBusqueda() {
    var sUrl = urlRedirect + "PAG_WORKFLOWBUSQUEDA";

    // Calcula el espacio disponible de acuerdo al tamano.
    var winWidth = (window.screen.width*0.95);
    var winHeight = (window.screen.height*0.85);
    var winTop = ((window.screen.availHeight-winHeight) / 2);
    var winLeft = ((window.screen.availWidth-winWidth) / 2);
    var winProperties = "toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+winWidth+",height="+winHeight+",left="+winLeft+",top="+winTop;

    // Abre la ventana solicitada
    window.open(sUrl,"Busqueda",winProperties);
}

function allVariablesToUpperCase(){

var inputs  = window.document.getElementsByTagName("INPUT");
var textareas = window.document.getElementsByTagName("TEXTAREA");
/*Habilitar inputs*/

for (var i=0; i < inputs.length; i++){
if (inputs[ i ].type.toUpperCase()=="TEXT")
	inputs[ i ].value = formatText(inputs[ i ].value);
}
/*Habilitar textarea*/
for (var i=0; i < textareas.length; i++)
if (textareas[ i ].type.toUpperCase()=="TEXTAREA")
	textareas[ i ].value = formatText(textareas[ i ].value);	
	
}

function abreObservaciones() {
    if (num==null || num==undefined){
       return;
    }
    var sUrl = urlRedirect + "PAG_WORKFLOWOBSERVACIONES&num="+num;
    var aParams = new Array();
    aParams[0] = num;
    aParams[1] = user;

    // Calcula el espacio disponible de acuerdo al tamano.
    var winWidth = 450;
    var winHeight = 560;
    //var winTop = ((document.body.offsetHeight-winHeight) / 2);
    var winTop = ((window.screen.availHeight-winHeight) / 2);
    var winLeft = ((window.screen.availWidth-winWidth) / 2);
    var winProperties = "toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+winWidth+",height="+winHeight+",left="+winLeft+",top="+winTop;

    // Abre la ventana solicitada
    sNewObs = window.open(sUrl,"Archivos_Adjuntos",winProperties);
}

function abreReemplazo(){
    var sUrl = urlRedirect + "PAG_WORKFLOWREEMPLAZO";              

    // Calcula el espacio disponible de acuerdo al tamano.
    var winWidth = (window.screen.width*0.95);
    var winHeight = (window.screen.height*0.85);
    var winTop = ((window.screen.availHeight-winHeight) / 2);
    var winLeft = ((window.screen.availWidth-winWidth) / 2);
    var winProperties = "toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+winWidth+",height="+winHeight+",left="+winLeft+",top="+winTop;

    // Abre la ventana solicitada
    sNewObs = window.open(sUrl,"Reemplazo",winProperties);
}

function mail(){
    var sUrl = urlRedirect + "PAG_PERSONALIZAMAIL";
    var aParams = new Array();
    aParams[0] = user; 

    // Calcula el espacio disponible de acuerdo al tamano.
    var winWidth = 315;
    var winHeight = 180;
    var winTop = ((window.screen.availHeight-winHeight) / 2);
    var winLeft = ((window.screen.availWidth-winWidth) / 2);
    var winProperties = "toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+winWidth+",height="+winHeight+",left="+winLeft+",top="+winTop;

    // Abre la ventana solicitada
    sNewObs = window.open(sUrl,"BancoFalabella",winProperties);
}

function fLimpiaInput(sId){
  // Limpia campos INPUT de tipo Text
  var aInput = document.getElementsByTagName("INPUT");
  for(i = 0; i < aInput.length; i++){
    if(aInput[i].type == "text" && aInput[i].id.indexOf(sId) != -1) {
      aInput[i].value = "";
    }  
  }
}

function fLimpiaSelect(sId){
  // Limpia Campos de Tipo Text
  var aSelect = document.getElementsByTagName("SELECT");
  for(i = 0; i < aSelect.length; i++){
    if (aSelect[i].id.indexOf(sId) != -1) {
      aSelect[i].value = "-1";
    }
  }  
}

function fDisabledDiv(){
  // Deshabilita campos DIV
  var aDiv = document.getElementsByTagName("DIV");
  for(i = 0; i < aDiv.length; i++){
    aDiv[i].style.display = 'none';
  }  
}

function fEnabledDiv(){
  // Habilita compos DIV
  var aDiv = document.getElementsByTagName("DIV");
  for(i = 0; i < aDiv.length; i++){
    aDiv[i].style.display = 'inline';
  }  
}

function fAddOption(oSelect, sTxt){
  var oOption = window.document.createElement("OPTION");
  oSelect.options.add( oOption );
  oOption.value = sTxt;
  oOption.innerHTML = sTxt;
}

function fSelectDia(objLstDia){
  oSelect = objLstDia;
  for(var iPos = 1; iPos <= 31; iPos++){
    var oOption = window.document.createElement("OPTION");
    oSelect.options.add( oOption );
    oOption.value = iPos;
    oOption.innerHTML = iPos;
  }
}

function fSelectMes(objLstMes, bSelected){
//  var dFecha = new Date();
//  var dMes = dFecha.getMonth() + 1;
  oSelect = objLstMes;
  for(var iPos = 1; iPos <= 12; iPos++){
    var oOption = window.document.createElement("OPTION");
    oSelect.options.add( oOption );
    oOption.value = iPos;
//    if(iPos == dMes+1 && bSelected == true){ oOption.selected = true; }
    oOption.innerHTML = longMonth(iPos);
  }
}

function fSelectAno(objLstAno, bSelected){
//  var dFecha = new Date();
//  var dAno = dFecha.getFullYear();
  oSelect = objLstAno; 
  for(var iPos = 2000; iPos <= 2010; iPos++){
    var oOption = window.document.createElement("OPTION");
    oSelect.options.add( oOption );
    oOption.value = iPos;
//    if(iPos == dAno && bSelected == true){ oOption.selected = true; }
    oOption.innerHTML = iPos;
  }
}

function fNombreMes(nMes){
switch (nMes){
    case 1:
      sMes = "Enero";
      break;
    case 2:
      sMes = "Febrero";
      break;
    case 3:
      sMes = "Marzo";
      break;
    case 4:
      sMes = "Abril";
      break;
    case 5:
      sMes = "Mayo";
      break;
    case 6:
      sMes = "Junio";
      break;
    case 7:
      sMes = "Julio";
      break;
    case 8:
      sMes = "Agosto";
      break;
    case 9:
      sMes = "Septiembre";
      break;
    case 10:
      sMes = "Octubre";
      break;
    case 11:
      sMes = "Noviembre";
      break;
    case 12:
      sMes = "Diciembre";
      break;
    default:
      sMes = "";
      break;
  }
  return sMes;
}

var StrConcat = "";
function agregaEnter(){
        if (event.keyCode == 13){
                StrConcat = window.document.getElementById("descripcion");
                StrConcat.value = StrConcat.value + "@";
                alert( StrConcat.value );
                
        }
}




function trim(str)
{
s = str.replace(/^(\s)*/, '');
s = s.replace(/(\s)*$/, '');
return s;
}

function noKeyValid(fld,e)
{
	if (fld.readOnly) return false;
	var i = j = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

}
function onlyNumbersAndLine(fld,e)
{
	if (fld.readOnly) return false;
	fld.style.textTransform ='uppercase';
	var i = j = 0;
    	var strCheck = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-abcdefghijklmnopqrstuvwxyz';
	var strCheckMin  = '-';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

}

function onlyNumbersAndOthers(fld,e)
{
	fld.style.textTransform ='uppercase';
	if (fld.readOnly) return false;
	var i = j = 0;
    	var strCheck = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-,.abcdefghijklmnopqrstuvwxyz';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function noMailCharValid(fld,e)
{
	fld.style.textTransform ='uppercase';
	if (fld.readOnly) return false;
	var i = j = 0;
    	var strCheck = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-@_abcdefghijklmnopqrstuvwxyz??,';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}


function onlyNumbers(fld,e)
{	
	fld.style.textTransform ='uppercase';
	if (fld.readOnly) return false;
	var i = j = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

}

function onlyPrecio(fld,e)
{	
	fld.style.textTransform ='uppercase';
	if (fld.readOnly) return false;
	var i = j = 0;
	var strCheck = '0123456789zxcvbnmasdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP,.+-() ';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

}

function onlyNumbersAndDv(fld,e)
{	
	if (fld.readOnly) return false;
	fld.style.textTransform ='uppercase';
	var i = j = 0;
	var strCheck = '1234567890kK';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function onlyTelefonos(fld,e)
{
	if (fld.readOnly) return false;
	var i = j = 0;
	var strCheck = '0123456789()- ';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

}
function noCharContactoValid (fld,e)
{	
	if (fld.readOnly) return false;
	fld.style.textTransform ='uppercase';
	var i = j = 0;
	var strCheck = '.ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-@_ abcdefghijklmnopqrstuvwxyz??#-,??';
	//var strCheck = 'zxcvbn?masdfghjklqwertyuiopZXCVBNMASDFGHJKL?QWERTYUIOP1234567890!\"?$%&/()=??;:_,.-{}[]+*><|@#~????? ??';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 209) whichCode=241;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	
	if (whichCode==8364 || whichCode==38 || whichCode==37 ||  whichCode==35 || whichCode==62 || whichCode==60 || whichCode==124)
		return false;
	/*if (strCheck.indexOf(key) == -1 && whichCode!=241 && whichCode==8364){
		 return false;  // Not a valid key
	}*/
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function noCharDireccionValid (fld,e)
{	
	if (fld.readOnly) return false;
	fld.style.textTransform ='uppercase';
	var i = j = 0;
	var strCheck = '.ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-@_ abcdefghijklmnopqrstuvwxyz??#-,??';
	//var strCheck = 'zxcvbn?masdfghjklqwertyuiopZXCVBNMASDFGHJKL?QWERTYUIOP1234567890!\"?$%&/()=??;:_,.-{}[]+*><|@#~????? ??';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 209) whichCode=241;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 

	if (whichCode==8364 || whichCode==38 || whichCode==37 || whichCode==62 || whichCode==60 || whichCode==124)
		return false;
	/*if (strCheck.indexOf(key) == -1 && whichCode!=241 && whichCode==8364){
		 return false;  // Not a valid key
	}*/
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function noCharValid(fld,e)
{	
	if (fld.readOnly) return false;
	fld.style.textTransform ='uppercase';
	var i = j = 0;
	var strCheck = '.ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-@_ abcdefghijklmnopqrstuvwxyz??#-,??';
	//var strCheck = 'zxcvbn?masdfghjklqwertyuiopZXCVBNMASDFGHJKL?QWERTYUIOP1234567890!\"?$%&/()=??;:_,.-{}[]+*><|@#~????? ??';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 209) whichCode=241;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 
	
	if (whichCode==8364 || whichCode==37 || whichCode==124)
		return false;
	/*if (strCheck.indexOf(key) == -1 && whichCode!=241 && whichCode==8364){
		 return false;  // Not a valid key
	}*/
	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function noKey(fld,e)
{	
  return false;
	if (fld.readOnly) return false;
	fld.style.textTransform ='uppercase';
	var i = j = 0;
	var strCheck = 'A';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode); 

	len = fld.value.length;
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
}

function replace(originalString,searchText,replaceText) { 
  try {        
    var strLength = originalString.length; 
    var txtLength = searchText.length; 
    if ((strLength == 0) || (txtLength == 0)) { 
      return originalString; 
    } 
    var i = originalString.indexOf(searchText); 
    if ((!i) && (searchText != originalString.substring(0,txtLength))) { 
      return originalString; 
    } 
    if (i == -1) { 
      return originalString; 
    } 
    var newstr = originalString.substring(0,i) + replaceText; 
    if (i+txtLength < strLength) { 
      newstr += replace(originalString.substring(i+txtLength,strLength),searchText,replaceText); 
    } 
    return newstr;
  } 
  catch(e){
    return originalString;
  }
}

function prepareFormatDate(str)
{
	var tbdate = new Array();
	str.value=trim(str.value);
	if (str.value!=""){
		if (!isDate(str.value)){
			alert("Formato de fecha Incorrecto.\nPruebe: dd/mm/aaaa.");
			str.value="";
			return false;
			}
		tbdate = str.value.split("/");
		if (tbdate[0].length<2) str.value='0'+tbdate[0]; else str.value=tbdate[0]
		if (tbdate[1].length<2) str.value=str.value+'/0'+tbdate[1]; else str.value=str.value+'/'+tbdate[1]	
		if (tbdate[2].length==1) str.value=str.value+'/200'+tbdate[2]; 
		else if (tbdate[2].length==2) str.value=str.value+'/20'+tbdate[2]; 
		else if (tbdate[2].length==3) str.value=str.value+'/2'+tbdate[2]; 
		else str.value=str.value+'/'+tbdate[2];
	
	}
		

}
function decode(str)
{
var rstr
rstr=replace(str,'&quot;','"');
rstr=replace(str,"&gt;",">");
rstr=replace(rstr,"&lt;","<");	
rstr=replace(rstr,"&amp;","&");
rstr=replace(rstr,"&AMP;","&");

return rstr;	
}
function transformAmp(str)
{
var rstr
rstr=replace(str,"&amp;","&");
rstr=replace(rstr,"&AMP;","&");
rstr=replace(rstr,"&","&amp;");
rstr=replace(rstr,">","&gt;");
rstr=replace(rstr,"<","&lt;");
rstr=replace(rstr,'"','&quot;');


	
return rstr;
}
function formatText(str)
{
str=trim(str);
str=str.toUpperCase();
return str;
}

function isEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor.value)){
    return (true)
  } else {
    valor.value="";
    return (false);
  }
}




function isDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{1,4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) return false;

month = matchArray[3]; // parse date into variables
day = matchArray[1];
year = matchArray[5];

if (month < 1 || month > 12) return false;
if (day < 1 || day > 31) return false;
if ((month==4 || month==6 || month==9 || month==11) && day==31)return false;
if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day > 29 || (day==29 && !isleap)) return false;
}
return true; // fecha es valida
}

/********************************/
/* Resultado Casos Relacionados */
/********************************/

function get_xslCasosRelacionados() {

  var sRetorno = new String();
   
  sRetorno = "<?xml version=\"1.0\"?>";
  sRetorno += "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">";

	sRetorno += "<xsl:template match=\"/\">";
	sRetorno += " <xsl:apply-templates/>";
	sRetorno += "</xsl:template>";

  sRetorno += "<xsl:template match=\"SQL\">";

	sRetorno += "<TABLE border='1' width='100%' cellpadding='0' cellspacing='0' id=\"casosrelacionados\">";
  sRetorno += "  <xsl:for-each select=\"SQLTITLE/COLS\">";
  sRetorno += "    <TR>";
  sRetorno += "        <TD class='congral_titlecell' nowrap='true'>&#160;<a class='lk1' href=\"javascript:void(0);\" onclick=\"eliminarCasos();\"><B>Eliminar</B></a>&#160;</TD>";
  sRetorno += "      <xsl:for-each select=\"COL\">";
  sRetorno += "        <TD class='congral_titlecell' nowrap='true'>&#160;<B><xsl:value-of select=\"DATA\"/></B>&#160;</TD>";
  sRetorno += "      </xsl:for-each>";
  sRetorno += "    </TR>";
  sRetorno += "	</xsl:for-each>";

	sRetorno += "	<xsl:for-each select=\"SQLOUTPUT/RECORD\">";
  sRetorno += "    <TR ondblclick=\"abreFormulario(this);\">";
  sRetorno += "      <TD class='congral_datacellcenter' nowrap='true'><input type='checkbox' value='' /></TD>";
  sRetorno += "      <xsl:for-each select=\"COL\">";
  sRetorno += "        <TD class='congral_datacell' nowrap='true' style='cursor: hand'>&#160;<xsl:value-of select=\"DATA\"/>&#160;</TD>";
  sRetorno += "      </xsl:for-each>";
  sRetorno += "    </TR>";
	sRetorno += "	</xsl:for-each>";
	sRetorno += "</TABLE>";
	sRetorno += "</xsl:template>";
  sRetorno += "</xsl:stylesheet>";
  
  return sRetorno;
}

/**********************/
/* Toolbar Escritorio */
/**********************/

function get_xslToolBarEscritorio()  //Funcion nueva : Por Rodrigo Rojas 24/09/2003
{
   var sRetorno = new String();
   
  /* sRetorno += "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">";
   sRetorno += "<xsl:output method=\"html\" indent=\"yes\" omit-xml-declaration=\"yes\"/>";

   // Raiz del documento
   sRetorno += "<xsl:template match=\"/\">";
   sRetorno +=     "<xsl:apply-templates/>";
   sRetorno += "</xsl:template>";

   // Inicio del proceso de Work Tray
   sRetorno += "<xsl:template match=\"WORKTRAY\">";




   // Toolbar para opciones de la lista*/
   sRetorno +=    "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
   sRetorno +=       "<tr>";
   sRetorno +=       "<td>";
   
   
   sRetorno +=       "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
   sRetorno +=         "<tr>";
   sRetorno +=          "<td onclick=\"WorkShiftMode(" + this.id + ", 0)\"><img alt=\"Ordenar\" src=\"" + this.imagebaseurl + "/general/orden1.gif\" style=\"cursor:hand\"/></td>";
   sRetorno +=          "<td onclick=\"WorkShiftMode(" + this.id + ", 1)\"><img alt=\"Agrupar\" src=\"" + this.imagebaseurl + "/general/agrupar1.gif\" style=\"cursor:hand\"/></td>";
   sRetorno +=          "<td onclick=\"WorkShiftMode(" + this.id + ", 2)\"><img alt=\"Autofiltro\" src=\"" + this.imagebaseurl + "/general/filtro1.gif\" style=\"cursor:hand\"/></td>";
   sRetorno +=          "<td><select name=\"lstTipoTramite\" id=\"lstTipoTramite\" onchange=\"fChangeTipoFrm(this)\"></select></td>";


   sRetorno +=         "</tr>";
   sRetorno +=        "</table>";
   
   sRetorno +=         "</td>";
   sRetorno +=         "<td align=\"right\">";
   
   sRetorno +=       "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
   sRetorno +=         "<tr>";
   if (showBtnHist) 
   {
       //sRetorno +=      "<td onclick=\"abreFormObservaciones();\" id=\"btnHistorial\"><img alt=\"Observaciones\" src=\"" + this.imagebaseurl + "/general/observaciones1.gif\" style=\"cursor:hand\"/></td>";	   
       //sRetorno +=      "<td onclick=\"abreFormAdjuntos();\" id=\"btnHistorial\"><img alt=\"Archivos Adjuntos\" src=\"" + this.imagebaseurl + "/general/adjunto1.gif\" style=\"cursor:hand\"/></td>";

       sRetorno +=      "<td onclick=\"\" id=\"btnConPendientes\"><img alt=\"Consultas Pendientes\" src=\"" + this.imagebaseurl + "/general/consultas.gif\" style=\"cursor:hand\"/></td>";
       sRetorno +=      "<td onclick=\"\" id=\"btnCasRelacionados\"><img alt=\"Casos Relacionados\" src=\"" + this.imagebaseurl + "/general/casos.gif\" style=\"cursor:hand\"/></td>";
       sRetorno +=      "<td onclick=\"\" id=\"btnHisTramitacion\"><img alt=\"Historial Tramitacion\" src=\"" + this.imagebaseurl + "/general/tramitacion.gif\" style=\"cursor:hand\"/></td>";
       
       if ( oBusqueda.value == "false" ) {
        //sRetorno +=      "<td onclick=\"abreBusqueda();\" id=\"btnBusqueda\"><img alt=\"Busqueda de Casos\" src=\"" + this.imagebaseurl + "/general/buscador1.gif\" style=\"cursor:hand\"/></td>";

        sRetorno +=      "<td onclick=\"abreConsultaGeneral();\" id=\"btnBusqueda\"><img alt=\"Busqueda General\" src=\"" + this.imagebaseurl + "/general/buscador1.gif\" style=\"cursor:hand\"/></td>";
				sRetorno +=      "<td onclick=\"abreHistorial();\" id=\"btnHistorial\"><img alt=\"Historial\" src=\"" + this.imagebaseurl + "/general/historial1.gif\" style=\"cursor:hand\"/></td>";	   
			}
   }
   sRetorno +=         "</tr>";
   sRetorno +=        "</table>";

   sRetorno +=        "</td>";
   sRetorno +=       "</tr>";
   sRetorno +=    "</table>";
  
  /* sRetorno += "</xsl:template>";
   sRetorno += "</xsl:stylesheet>";*/
   // Fin Toolbar para opciones de la lista*/
   
   return sRetorno;
}


function emailCheck (emailStr) {

if (emailStr.value==""){
	return true;
}
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat = new RegExp("^"+ word + "(\\." + word +")*$")
var strmail = emailStr.value;

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

var matchArray=strmail.match(emailPat)

if (matchArray==null) {
	alert("El email ingresado es correcto");
      emailStr.value="";

	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    alert("El usuario del email es incorrecto.");
    emailStr.value="";
    return false
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("El servidor de su correo de su email es incorrecto.");
    emailStr.value="";	
    return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("La direccion de email es incorrecta")
   emailStr.value="";
   return false
}

return true;
}


function formatRut(rut){
  var str=rut.value;
  if (str.indexOf('-')!=-1){
      str=replace(str,'-','');
  }

  if (str.indexOf('.')!=-1){
      str=replace(str,'.','');
  }  
  var largo = str.length;
  var digito = str.charAt(largo-1);


  str=str.substring(0,largo-1);
  str  = formatMiles(str);
  if (str=="0")
    rut.value="";
  else  
    rut.value=str+"-"+digito

}

function validaRUT(rut)
{
  var tmpstr = "";

  var strrut=rut.value
  if (strrut.indexOf('-')!=-1){
    
    strrut=replace(strrut,'-','');
  }
  if (strrut.indexOf('.')!=-1){
    strrut = replace(strrut,'.','');
  }
  for ( i=0; i < strrut.length ; i++ )   //>
    if ( strrut.charAt(i) != ' ' && strrut.charAt(i) != '.' && strrut.charAt(i) != '-' )
      tmpstr = tmpstr + strrut.charAt(i);
  strrut = tmpstr;
  largo = strrut.length;

  tmpstr = "";
  for ( i=0; strrut.charAt(i) == '0' ; i++ );
  for (; i < strrut.length ; i++ )   //>
     tmpstr = tmpstr + strrut.charAt(i);
  strrut = tmpstr;
  largo = strrut.length;

  if ( largo < 2 )    //>
  {
    alert("Debe ingresar el rut completo.");
    return false;
  }
  for (i=0; i < largo ; i++ )   //>
  {
    if( (strrut.charAt(i) != '0') && (strrut.charAt(i) != '1') && (strrut.charAt(i) !='2') && (strrut.charAt(i) != '3') && (strrut.charAt(i) != '4') && (strrut.charAt(i) !='5') && (strrut.charAt(i) != '6') && (strrut.charAt(i) != '7') && (strrut.charAt(i) != '8') && (strrut.charAt(i) != '9') && (strrut.charAt(i) !='k') && (strrut.charAt(i) != 'K'))
    {
      alert("El valor ingresado no corresponde a un R.U.T valido.");
      return false;
    }
  }

  largo = strrut.length;
  digito = strrut.charAt(largo-1);
  str=strrut.substring(0,largo-1);
  if(!validaDV(str,digito)){
    rut.focus();
    return false;
  }  

  
  return true;
}
function validaDV(str,dig)
{
  dv = dig
  if(!validaCDV(dv))
     return false;
  if(str == null || dv == null){
      return false;
  }
  var dvr = '0';
  suma = 0;
  mul  = 2;
  for (i= str.length -1 ; i >= 0; i--){
    suma = suma + str.charAt(i) * mul;
    if(mul == 7){
      mul = 2;
    }
    else{
      mul++;
    }
  }
  res = suma % 11;
  if (res==1){
    dvr = 'k';
  }
  else{
    if(res==0){
      dvr = '0';
    }
    else{
      dvi = 11-res;
      dvr = dvi + "";
    }
  }
  if(dvr != dv.toLowerCase()){
    alert("El RUT ingresado no es v\u00E1lido.");
    return false;
  }
  return true;
}
function validaCDV(dvr)
{
  dv = dvr + "";
  if(dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K'){
    alert("Debe ingresar un digito verificador valido.");
    return false;
  }
  return true;
}
