// JavaScript Document
var nav4 = window.Event ? true : false;

function ltrim(s) {return s.replace(/^\s+/, "");}
function rtrim(s) {return s.replace(/\s+$/, "");}
function Trim(sCadena) {return rtrim(ltrim(sCadena));}

function Salida(txt)
{
  if (Trim(txt.value) == '')
  {
   txt.value = txt.title;
   txt.style.color= '#b2b2b2';
   }
}

function Entrada(txt) 
{
  if (txt.value == txt.title)
  {
   txt.value = '';
   txt.style.color= '#000000';
  }
}

function Letras(evt) //ingreso exclusivamente de letras sin caracteres especiales :  onKeyPress="return Letras(event);"
{
	var key = nav4 ? evt.which : evt.keyCode;
	return (key == 13 ||  (key >= 65 && key <= 90) || (key >= 97 && key <= 122));
}

function Ruts(evt) //ingreso exclusivamente de Rut (numeros, guion y K k) :  onKeyPress="return Ruts(event);"
{
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || key == 45 || key == 75 || key == 107 || (key >= 48 && key <= 57));
}

function Tarjetas(evt) //ingreso exclusivamente de Rut (numeros, guion y K k) :  onKeyPress="return Ruts(event);"
{
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || key == 45 || (key >= 48 && key <= 57));
}

function Numeros(evt) //ingreso exclusivamente de numeros sin caracteres especiales :  onKeyPress="return Numeros(event);"
{
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));
}

function Palabras(evt) //ingreso exclusivamente de letras y espacios sin caracteres especiales:  onKeyPress="return Palabras(event);"
{
	var key = nav4 ? evt.which : evt.keyCode;
	return ( key == 32 || key == 13 ||  (key >= 65 && key <= 90) || (key >= 97 && key <= 122));
}

function GetCookie (name, InCookie) //obtencion de cookie
{ 
		var prop = name + "="; // propiedad buscada
		var plen = prop.length;
		var clen = InCookie.length;
		var i=0;
		if (clen>0) { // Cookie no vacío;
			i = InCookie.indexOf(prop,0); // aparición de la propiedad
			if (i!=-1) { // propiedad encontrada
				// Buscamos el valor correspondiente
				j = InCookie.indexOf(";",i+plen);
				if(j!=-1) // valor encontrado
					return unescape(InCookie.substring(i+plen,j));
				else //el último no lleva ";"
					return unescape(InCookie.substring(i+plen,clen));
			}
			else
				return "";
		}
		else
			return "";
}

function SetCookie (name, value) //modificacion de cookie
{ 
		// número de parámetros variable.
		var argv = SetCookie.arguments;
		var argc = SetCookie.arguments.length;
		// asociación de parámetros a los campos cookie.
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		// asignación de la propiedad tras la codificación URL
		document.cookie = name + "=" + escape(value) +
			((expires==null) ? "" : ("; expires=" + expires.toGMTString())) +
			((path==null) ? "" : (";path=" + path)) +
			((domain==null) ? "" : ("; domain=" + domain)) +
			((secure==true) ? "; secure" : "");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function getValue(obj,nivel) // obtiene  el valor de un  objeto , subiendo niveles o no (document.parents)
{	
	var valor ="";
	if(obj=='[object]')
		valor=obj.value;
	else
	{
		if((nivel==null)||(nivel=="undefined"))
			valor=document.getElementById(obj).value.toUpperCase();
		if(nivel==1)
			valor=window.parent.document.getElementById(obj).value.toUpperCase();
		if(nivel==2)
			valor=window.parent.parent.document.getElementById(obj).value.toUpperCase();			
		if(nivel==3)
			valor=window.parent.parent.parent.document.getElementById(obj).value.toUpperCase();			
	}
	
	return Trim(valor);
}
function GetCookie (name, InCookie) //obtencion de cookie
{ 
		var prop = name + "="; // propiedad buscada
		var plen = prop.length;
		var clen = InCookie.length;
		var i=0;
		if (clen>0) { // Cookie no vacío;
			i = InCookie.indexOf(prop,0); // aparición de la propiedad
			if (i!=-1) { // propiedad encontrada
				// Buscamos el valor correspondiente
				j = InCookie.indexOf(";",i+plen);
				if(j!=-1) // valor encontrado
					return unescape(InCookie.substring(i+plen,j));
				else //el último no lleva ";"
					return unescape(InCookie.substring(i+plen,clen));
			}
			else
				return "";
		}
		else
			return "";
}

function SetCookie (name, value) //modificacion de cookie
{ 
		// número de parámetros variable.
		var argv = SetCookie.arguments;
		var argc = SetCookie.arguments.length;
		// asociación de parámetros a los campos cookie.
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		// asignación de la propiedad tras la codificación URL
		document.cookie = name + "=" + escape(value) +
			((expires==null) ? "" : ("; expires=" + expires.toGMTString())) +
			((path==null) ? "" : (";path=" + path)) +
			((domain==null) ? "" : ("; domain=" + domain)) +
			((secure==true) ? "; secure" : "");
}
function mostrardiv(Obj)
{
  Obj.style.visibility ="visible";
}

function cerrardiv(Obj)
{
  Obj.style.visibility ="hidden";
}
function Hide(obj,nivel) //oculta un Objeto ,  subiendo niveles o no (document.parents)
{	
	if(obj=='[object]')
		obj.style.display="none";
	else
	{
		if((nivel==null)||(nivel=="undefined"))
			document.getElementById(obj).style.display="none";
		if(nivel==1)
			window.parent.document.getElementById(obj).style.display="none";
		if(nivel==2)
			window.parent.parent.document.getElementById(obj).style.display="none";			
		if(nivel==3)
			window.parent.parent.parent.document.getElementById(obj).style.display="none";			
	}	
}

function Show(obj,nivel) //Muestra un Objeto ,  subiendo niveles o no (document.parents)
{		
	if(obj=='[object]')
		obj.style.display="";
	else
	{
		if((nivel==null)||(nivel=="undefined"))
			document.getElementById(obj).style.display="";
		if(nivel==1)
			window.parent.document.getElementById(obj).style.display="";
		if(nivel==2)
			window.parent.parent.document.getElementById(obj).style.display="";			
		if(nivel==3)
			window.parent.parent.parent.document.getElementById(obj).style.display="";			
	}	
}



