/*///////////////////////////////////////////////////*/
/*Desarrollado por:/*
/*Jacob Silva G./*
/*Analista Programador C. CIREN*/
/*Todos los derechos reservados - 2008*/
/*Script js Genericos Proyecto Ventas*/
/*////////////////////////////////////////////////////*/



// CambiaCSS: Cambia estilos CSS
//-------------------------------------------------------------------------------------------
function CambiaCSS(c,n,css)
{
	if(n == 1)
	{
		c.className = css;	
	}else{
			c.className = css;	
		 }
}

// VerDIV: Desoculta etiqueta DIV
//-------------------------------------------------------------------------------------------
function VerDIV(DivName, Display)
{
    
    if(Display=='show')
	{
		document.getElementById(DivName).style.display = 'block';
    	document.getElementById(DivName).style.visibility = 'visible';
	}
	else
	{
		document.getElementById(DivName).style.display = 'none';
    	document.getElementById(DivName).style.visibility = 'hidden';
	}
   
}

// VerDIV2: Desoculta etiqueta DIV
//-------------------------------------------------------------------------------------------
function VerDIV2(div)
{
	if (document.getElementById)
	{
          
		  dis = (document.getElementById(div).style.display == 'none') ? 'block' : 'none';
    	vista = (document.getElementById(div).style.visibility == 'visible') ? 'hidden' : 'visible';
    		
    	document.getElementById(div).style.display = dis;
    	document.getElementById(div).style.visibility = vista;
    }
   
}


// ControlDIV: Controla la visualizacion de etiqueta DIV atraves de un objeto
//-------------------------------------------------------------------------------------------
function ControlDIV(Obj,Div)
{
	
	val = Obj.value;
	
	if(val == 1)
		VerDIV(Div,'show');
	else
		VerDIV(Div,'');
}


// ControlDIV2: Controla la visualizacion de etiqueta DIV atraves de un valor
//-------------------------------------------------------------------------------------------
function ControlDIV2(Val,Div)
{
	if(Val == 1)
		VerDIV(Div,'show');
	else
		VerDIV(Div,'');
}


// MenuNav: Controla acciones sobre la pantalla
//-------------------------------------------------------------------------------------------
function MenuNav(nObj)
{
	
	switch(nObj)
	{
	  case 1 : { window.history.back();	break; }
	  case 2 : { window.history.go(1); break; }
	  case 3 : { location.reload();	break; }
	  case 4 : { location.href="logout.asp"; break; }
	  case 5 : { window.close(); break; }
	  case 6 : { ShowPopUp(2,"ayuda.htm",'ayuda',0,0,0,0,0,1,1,1034,550,328,13); break; }
	}

}

// ShowPopUp: Crea ventana PopUp
// Param = 1-> Switch 2-> Direccion 3-> Nombre Ventana 4-> Pantalla C.(0-1) 5-> Herramientas(0-1) 6-> Barra Dir.(0-1) 7-> Barra Est.(0-1) 8-> Barra Menu(0-1)
// Param = 9-> Scroll(0-1) 10-> Cambiar Tamaño(0-1) 11-> Ancho 12-> Alto 13-> Centrar Izq. 14-> Centrar Arriba
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ShowPopUp(Sw,Url,Name,Fullscreen,Toolbar,Location,Status,Menubar,Scrollbars,Resizable,Width,Height,Left,Top)
{
	
	if(Sw == 1)
	{
		var Opcion = "fullscreen="+Fullscreen+",toolbar="+Toolbar+",location="+Location+",statusbar="+Status+",directories=no,menubar="+Menubar+",scrollbars="+Scrollbars+",copyhistory=no";
			
	}
	else
	{
		var Opcion = "toolbar="+Toolbar+",location="+Location+",statusbar="+Status+",directories=no,menubar="+Menubar+",scrollbars="+Scrollbars+",copyhistory=no,resizable="+Resizable+",width="+Width+",height="+Height+",left="+Left+",top="+Top;
		
	}
	
	window.open(Url,Name,Opcion);
}

// EnabledControl: habilita todos los controles del form
// Param = 1-> Switch 2-> Cantidad de Elementos 
//-------------------------------------------------------------------------------------------
function EnabledControl(nSw,nC)
{

	var Obj;
	var nLength;
		
	if(nSw == 1)
	{
		Obj = document.forms[0].elements;
		nLength = Obj.length;
		for(var i=0;i<nLength;i++)
			Obj[i].disabled=false;
	}
	else if(nSw == 2)
	{
		Obj = document.forms[0].elements;
		nLength = nC+1;
		for(var i=0;i<nLength;i++)
			Obj[i].disabled=false;
	}
	else
	{
		Obj = document.forms[0].elements;
		nLength = Obj.length;
		for(var i=nC;i<nLength;i++)
			Obj[i].disabled=false;
	
	}
} 

// DisabledControl: deshabilita todos los controles del form
// Param = 1-> Switch 2-> Cantidad de Elementos 
//-------------------------------------------------------------------------------------------
function DisabledControl(nSw,nC)
{
	var Obj;
	var nLength;
		
	if(nSw == 1)
	{
		Obj = document.forms[0].elements;
		nLength = Obj.length;
		for(var i=0;i<nLength;i++)
			Obj[i].disabled=true;
	
	}
	else if(nSw == 2)
	{
		Obj = document.forms[0].elements;
		nLength = nC+1;
		for(var i=0;i<nLength;i++)
			Obj[i].disabled=true;
	}
	else
	{
			
		Obj = document.forms[0].elements;
		nLength = Obj.length;
		for(var i=nC;i<nLength;i++)
			Obj[i].disabled=true;
	}
	
} 



// Rut: Validador de rut de clientes
//-------------------------------------------------------------------------------------------
function revisarDigito( 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");
		//document.getElementById("aviso").innerHTML = "DEBE INGRESAR UN DIGITO VERIFICADOR VALIDO";
		//window.document.form1.rut.focus();		
		//window.document.form1.rut.select();		
		return false;	
	}	
	return true;
}

function revisarDigito2( crut )
{	
	largo = crut.length;	
	if ( largo < 2 )	
	{
		//document.getElementById("aviso").innerHTML = "DEBE INGRESAR EL RUT COMPLETO";
		alert("Debe ingresar el rut completo")		
		//window.document.form1.rut.focus();		
		//window.document.form1.rut.select();		
		return false;	
	}	
	if ( largo > 2 )		
		rut = crut.substring(0, largo - 1);	
	else		
		rut = crut.charAt(0);	
	dv = crut.charAt(largo-1);	
	revisarDigito( dv );	

	if ( rut == null || dv == null )
		return 0	

	var dvr = '0'	
	suma = 0	
	mul  = 2	

	for (i= rut.length -1 ; i >= 0; i--)	
	{	
		suma = suma + rut.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() )	
	{
		//document.getElementById("aviso").innerHTML = "EL RUT ES INCORRECTO";
		alert("EL rut es incorrecto");		
		//window.document.form1.rut.focus();		
		//window.document.form1.rut.select();		
		return false	
	}

	return true
}

function Rut(texto,objeto)
{	
	var tmpstr = "";	
	for ( i=0; i < texto.length ; i++ )		
		if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
			tmpstr = tmpstr + texto.charAt(i);	
	texto = tmpstr;	
	largo = texto.length;	

	if ( largo < 2 )	
	{		
		alert("Debe ingresar el RUT completamente.");
		//document.getElementById("aviso").innerHTML = "DEBE INGRESAR EL RUT COMPLETO";
		//window.document.form1.rut.focus();		
		//window.document.form1.rut.select();		
		return false;	
	}	

	for (i=0; i < largo ; i++ )	
	{			
		if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
 		{			
			//document.getElementById("aviso").innerHTML = "&nbsp;";
			alert("El valor ingresado no corresponde a un R.U.T valido");			
			//window.document.form1.rut.focus();			
			//window.document.form1.rut.select();			
			return false;		
		}	
	}	

	var invertido = "";	
	for ( i=(largo-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + texto.charAt(i);	
	var dtexto = "";	
	dtexto = dtexto + invertido.charAt(0);	
	dtexto = dtexto + '-';	
	cnt = 0;	

	for ( i=1,j=2; i<largo; i++,j++ )	
	{		
		//alert("i=[" + i + "] j=[" + j +"]" );		
		if ( cnt == 3 )		
		{			
			dtexto = dtexto + '.';			
			j++;			
			dtexto = dtexto + invertido.charAt(i);			
			cnt = 1;		
		}		
		else		
		{				
			dtexto = dtexto + invertido.charAt(i);			
			cnt++;		
		}	
	}	

	invertido = "";	
	for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + dtexto.charAt(i);	

	objeto.value = invertido.toUpperCase()		

	if ( revisarDigito2(texto) )		
		return true;	

	return false;
}

// ObjType: Verifica el tipo de elemento.
// Param = 1-> Switch 2-> Elemento 
//-------------------------------------------------------------------------------------------
function ObjType(nSw,Obj)
{
	var bF = false;
	
	switch(nSw)
	{
		case 1 : { 
					 if(Obj.type == "text")
						bF = true;	
					 
					 break;
				 }
			   
		case 2 : { 
	  			 	if(Obj.type == "radio")
				 		bF = true;	
	  			 
				 	break;
			   	 }
			   
		case 3 : { 
	  			 	if(Obj.type == "checkbox")
				 		bF = true;	
	  			 
				 	break;
			   	 }	
		
		case 4 : { 
	  			 	if(Obj.type == "select-one")
				 		bF = true;	
	  			 
				 	break;
			   	 }	
				 
				 
		case 5 : { 
	  			 	if(Obj.type == "textarea")
				 		bF = true;	
	  			 
				 	break;
			   	 }	
	
	}

	return bF;
}

// Valrequired: Valida campos de tipo requeridos.
// Param = 1-> Elemento 2-> Cantidad Minima 3-> Nombre Elemento form
//-------------------------------------------------------------------------------------------
function Valrequired(Obj,Lmin,Objname)
{
	 
	 nSw = true;
		
	 objvalue = Obj.value;
	 Minimo = Lmin;
	 MsgVacio = "Escriba en: "+Objname;
	 MsgMinimo = "Minimo "+Lmin+" caracteres en: "+Objname;
	 			
	if(!objvalue)
	{
		alert(MsgVacio);
		//Obj.value = "";
		Obj.focus();
			
		nSw = false;
	}else{
						
			if(objvalue.length < Minimo)
			{
				alert(MsgMinimo);
				//Obj.value = "";
				Obj.focus();
					
				nSw = false;
			}
			
		 }	

	
	if(nSw)
	{
		r = 1;
	}else{
			r = 0;
		 }

	return r;	

		 
}



// Valcaracter: Valida campos de tipo caracteres permitidos.
//-------------------------------------------------------------------------------------------
function Valcaracter(Obj,Lmin,Objname)
{
	 nSw = true;	
	 Incluir = /^[a-zA-z\s]+$/; 
	 r = 0; 
	 
	 objvalue = Obj.value;
	 Minimo = Lmin;
	 MsgVacio = "Escriba en campo: "+Objname;
	 MsgMinimo = "Escriba minimo "+Lmin+" caracteres en campo: "+Objname;
	 MsgCaracteres = "Escriba caracteres permitidos en campo: "+Objname;
			
	if(!objvalue)
	{
		alert(MsgVacio);
		//Obj.value = "";
		Obj.focus();
		nSw = false;
	}else{
						
			if(objvalue.length < Minimo)
			{
				alert(MsgMinimo);
				//Obj.value = "";
				Obj.focus();
				nSw = false;
				return false;
			}
			
			if(!Incluir.test(objvalue))
			{
				alert(MsgCaracteres);
				Obj.focus();
					
				nSw = false;
			}	
		 }	
		 

	if(nSw)
	{
		r = 1;
	}else{
			r = 0;
		 }

	return r;	

		 
}

// Valemail: Valida campos de tipo Email.
//-------------------------------------------------------------------------------------------
function Valemail(Obj,Lmin,Objname)
{
	 nSw = true;
	 Incluir = /^(.+\@.+\..+)$/;
	
	 objvalue = Obj.value;
	 Minimo = Lmin;
	 MsgVacio = "Escriba en campo: "+Objname;
	 MsgMinimo = "Escriba minimo "+Lmin+" caracteres en campo: "+Objname;
	 MsgCaracteres = "Escriba caracteres permitidos en campo: "+Objname;
				
	if(!objvalue)
	{
		alert(MsgVacio);
		//Obj.value = "";
		Obj.focus();
		nSw = false;
	}else{
			if(objvalue.length < Minimo)
			{
				alert(MsgMinimo);
				//Obj.value = "";
				Obj.focus();
				nSw = false;
				return false;
			}
			if(!Incluir.test(objvalue))
			{
				alert(MsgCaracteres);
				//Obj.value = "";
				Obj.focus();
				nSw = false;
			}	
		 }	

	if(nSw)
	{
		r = 1;
	}else{
			r = 0;
		 }

	return r;	

}

// ValFono: Valida campos de tipo Fonos.
//-------------------------------------------------------------------------------------------
function ValFono(Obj,Lmin,Objname)
{
	 
	 nSw = true;
	 
	 Incluir = /(^[0-9\s\+\-])+$/;
	
	 objvalue = Obj.value;
	 Minimo = Lmin;
	 MsgVacio = "Escriba en campo: "+Objname;
	 MsgMinimo = "Escriba minimo "+Lmin+" caracteres en campo: "+Objname;
	 MsgCaracteres = "Escriba caracteres permitidos en campo: "+Objname;
				
	if(objvalue == "")
	{
		alert(MsgVacio);
		//Obj.value = "";
		Obj.focus();
		nSw = false;
	}else{
			if(objvalue.length < Minimo)
			{
				alert(MsgMinimo);
				//Obj.value = "";
				Obj.focus();
				nSw = false;
				return false;
			}
			if(Incluir.test(objvalue))
			{
				alert(MsgCaracteres);
				//Obj.value = "";
				Obj.focus();
				nSw = false;
			}	
		 }	



	if(nSw)
	{
		r = 1;
	}else{
			r = 0;
		 }

	return r;	
}


// ValNumber: Valida campos de tipo numeros.
//-------------------------------------------------------------------------------------------
function ValNumber(Obj,Lmin,Objname,opt)
{
	 
	 nSw = true;
	 
	 Incluir = /^([0-9])*$/;
	
	 objvalue = Obj.value;
	 Minimo = Lmin;
	 MsgVacio = "Escriba en campo: "+Objname;
	 MsgMinimo = "Escriba minimo "+Lmin+" numeros en campo: "+Objname;
	 MsgCaracteres = "Escriba numeros permitidos en campo: "+Objname;
				
	if(objvalue == opt)
	{
		alert(MsgVacio);
		//Obj.value = "";
		Obj.focus();
		nSw = false;
	}else{
			if(objvalue.length < Minimo)
			{
				alert(MsgMinimo);
				//Obj.value = "";
				Obj.focus();
				nSw = false;
				return false;
			}
			if(!Incluir.test(objvalue))
			{
				alert(MsgCaracteres);
				//Obj.value = "";
				Obj.focus();
				nSw = false;
			}	
		 }	
		
		 
 	if(nSw)
	{
		r = 1;
	}else{
			r = 0;
		 }

	return r;		 
		 
}

// ValDate: Valida campos de tipo fecha.
//-------------------------------------------------------------------------------------------
function ValDate(Obj,Lmin,Objname)
{
	 
	 nSw = true;
	 
	 objvalue = Obj.value;
	 Minimo = Lmin;
	 MsgVacio = "Escriba en campo: "+Objname;
	 MsgMinimo = "Escriba minimo "+Lmin+" digitos en campo: "+Objname;
	 MsgCaracteres = "Escriba fecha valida en campo: "+Objname;
		
	var Fecha= new String(objvalue);   // Crea un string   
    var RealFecha= new Date();   	   // Para sacar la fecha de hoy   
    
    var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))   
    var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))   
    var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")))   
  
    
	if(objvalue == "")
	{
		alert(MsgVacio);
		//Obj.value = "";
		Obj.focus();
		nSw = false;
	}else{
			if(objvalue.length < Minimo)
			{
				alert(MsgMinimo);
				//Obj.value = "";
				Obj.focus();
				nSw = false;
				return false;
			}		
			
			if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900)
			{   
            	alert(MsgCaracteres+"\nERROR Ano mal ingresado.");
				//Obj.value = "";
				Obj.focus();
        		nSw = false;
				return false;
    		}   
   
			if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12)
			{   
				alert(MsgCaracteres+"\nERROR Mes mal ingresado.");
				//Obj.value = "";
				Obj.focus();
        		nSw = false;
				return false;
			}   
	
			if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31)
			{   
				alert(MsgCaracteres+"\nERROR Dia mal ingresado.");
				//Obj.value = "";
				Obj.focus();
        		nSw = false;
				return false;
			}   
			if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2)
			{   
				if (Mes==2 && Dia > 28 || Dia > 30)
				{   
					alert(MsgCaracteres);
					//Obj.value = "";
					Obj.focus();
					nSw = false;
				}   
			}
		}   			
			
	
	
	if(nSw)
	{
		r = 1;
	}else{
			r = 0;
		 }

	return r;
}

// Valalpha: Valida campos de tipo alphabeticos permitidos.
// Param = 1-> Elemento 2-> Cantidad Minima 3-> Nombre Elemento form
//-------------------------------------------------------------------------------------------
function Valalpha(Obj,Lmin,Objname)
{
	 
	 Incluir = /^[a-zA-z\s]+$/; 
	 sM = "";
		
	 objvalue = trim(Obj.value);
	 Minimo = Lmin;
	 MsgVacio = "Escriba en: "+Objname;
	 MsgMinimo = "Minimo "+Lmin+" letras en: "+Objname;
	 MsgCaracteres = "Letras no permitidas en: "+Objname;
			
	if(!objvalue)
	{
		sM = MsgVacio; //alert(MsgVacio);
		//Obj.value = "";
		if(!ObjType(4,Obj))
			Obj.focus();
			
		//return trim(sM);
	}else{
						
			if(objvalue.length < Minimo)
			{
				sM = MsgMinimo;  //alert(MsgMinimo);
				//Obj.value = "";
				if(!ObjType(4,Obj))
					Obj.focus();
					
				//return trim(sM);
			}
			
			if(!Incluir.test(objvalue))
			{
				sM = MsgCaracteres;  //alert(MsgCaracteres);
			//	Obj.value = "";
				if(!ObjType(4,Obj))
					Obj.focus();
					
				//return trim(sM);
			}	
			//Chkcaracter(Incluir,Obj,MsgCaracteres);
		 }	

	
	return trim(sM);	

		 
}

// Valalphanum: Valida campos de tipo alphanumericos permitidos.
// Param = 1-> Elemento 2-> Cantidad Minima 3-> Nombre Elemento form
//-------------------------------------------------------------------------------------------
function Valalphanum(Obj,Lmin,Objname)
{
	 
	 nSw = true;
	 Incluir = /^[a-zA-Z0-9]+$/; 
	 sM = "";
		
	 objvalue = trim(Obj.value);
	 Minimo = Lmin;
	 MsgVacio = "Escriba en: "+Objname;
	 MsgMinimo = "Minimo "+Lmin+" letras o numeros en: "+Objname;
	 MsgCaracteres = "Letras o numeros no permitidos en: "+Objname;
			
	if(!objvalue)
	{
		//sM = MsgVacio; 
		alert(MsgVacio);
		//Obj.value = "";
		if(!ObjType(4,Obj))
			Obj.focus();
		
		nSw = false;
		//return trim(sM);
	}else{
						
			if(objvalue.length < Minimo)
			{
				//sM = MsgMinimo;  
				alert(MsgMinimo);
				//Obj.value = "";
				if(!ObjType(4,Obj))
					Obj.focus();
					
				nSw = false;
				//return trim(sM);
			}
			
			if(!Incluir.test(objvalue))
			{
				//sM = MsgCaracteres;  
				alert(MsgCaracteres);
			//	Obj.value = "";
				if(!ObjType(4,Obj))
					Obj.focus();
					
				nSw = false;
				//return trim(sM);
			}	
			
		 }	

	
	if(nSw)
	{
		r = 1;
	}else{
			r = 0;
		 }

	return r;	

		 
}

// ValDoc: Permite validar extensiones de archivo.
// Param = 1-> Elemento 2-> Array Extensiones 3-> Nombre Elemento form
//-------------------------------------------------------------------------------------------
function ValDoc(Obj,sA,Objname)
{
	 
	 sM = ""; sExt = "";
	 nSw = false; 
	 objvalue = trim(Obj.value);
	 sArray   = sA.split(',');
	 MsgVacio = "Debe seleccionar en: "+Objname;
	 				
	if(objvalue.length==0)
	{
		sM = MsgVacio; //alert(MsgVacio);
		//Obj.value = "";
		if(!ObjType(4,Obj))
			Obj.focus();
		//return sM;
	}else{
			
			sExt = (objvalue.substring(objvalue.lastIndexOf("."))).toLowerCase(); 
			
			for (var i = 0; i < sArray.length; i++)
			{ 
         		x = sArray[i];
											
				if(x==sExt)
				{ 
         			nSw = true; 
         			break; 
				}
         	} 
			
			if(!nSw)
				sM = "Compruebe extension de archivo, permitidas ("+sArray.join()+") en: "+Objname;
       
		 }	

	
	return trim(sM);	
}




// ClearObj: Permite limpiar los valores de los elementos en la pagina.
// Param = 1->Nº Form 2-> Cantidad Indice 3-> Cantidad Elementos html
//-------------------------------------------------------------------------------------------
function ClearObj(nF,nI,nLong)
{
	oEleme = document.forms[nF].elements;
	
	if(!nLong)
		nlargo = oEleme.length;
	else
		nlargo = nLong;
		
	for(n=nI;n<nlargo;n++)	
	{
				
		if(ObjType(1,oEleme[n]))
			oEleme[n].value = "";	
				
		if(ObjType(2,oEleme[n]) || ObjType(3,oEleme[n]))
			oEleme[n].checked = false;
		
		if(ObjType(4,oEleme[n]))
			oEleme[n].value = 0;
			
		if(ObjType(5,oEleme[n]))
			oEleme[n].value = "";
		
	}	
		
}


// Confirma: Permite generar alerta de confirmación.
// Param = 1-> Mensaje
//-------------------------------------------------------------------------------------------
function Confirma(sMsn)
{
		if(!confirm(sMsn))
		{
			r = 0;
			return false;  
		} 
		else{
			  r = 1;
			}  
			
	return r;		
}


// Cutstring: Permite cortar una cadena de texto.
// Param = 1-> Switch 2-> Texto 3-> Nº Inicial 4-> Nº Fin
//-------------------------------------------------------------------------------------------
function Cutstring(nSw,sMsn,nI,nF)
{
	nLargo = sMsn.length;	
		
	switch(nSw)
	{
	  case 1 : {
		  			nIni = nI;
					nFin = nF;
					break; 
	   		   }
	  case 2 : {
		  			nIni = nI;
					nFin = nLargo - nF;
		   			break; 
		   	   }
	  case 3 : {
		  			nIni = nI;
					nFin = nLargo;
		   			break;
		   	   }
	  case 4 : { 
	  				sCadena = sMsn.charAt(nI - nF);	
	   				break;
			   }
	}
			if(nSw != 4)	
				sCadena = sMsn.substring(nIni,nFin);	
			
	return sCadena;		
}

// GenUpdate: Permite actualizar registros con transporte Ajax.
// Param = 1-> Switch 2-> Url 3-> Nº Opcion 4-> Campos 5-> Tabla 6-> Opciones 7-> Elemento html contenedor 8-> Elemento html 
//-------------------------------------------------------------------------------------------------------
function GenUpdate(nSw,sUrl,nOp,sCampo,sTable,sOption,sDiv,sInput)
{
	sParam = "?nSw="+nSw+"&nOp="+nOp+"&sCampo="+sCampo+"&sTable="+sTable+"&sOption="+sOption+"&sInput="+sInput; 
	sUrl = sUrl+sParam;
		
	new Ajax.Updater(sDiv,sUrl);
	
}


// ltrim: Permite eliminar espacios en blanco a la izquierda de una cadena.
// Param = 1-> Texto 
//-------------------------------------------------------------------------------------------
function ltrim(s) {
	return s.replace(/^\s+/, "");
}
// rtrim: Permite eliminar espacios en blanco a la derecha de una cadena.
// Param = 1-> Texto
//-------------------------------------------------------------------------------------------
function rtrim(s) {
	return s.replace(/\s+$/, "");
}
// trim: Permite eliminar espacios en blanco a la izquierda y derecha de una cadena.
// Param = 1-> Texto
//-------------------------------------------------------------------------------------------
function trim(s) {
	return rtrim(ltrim(s));
}



// ImpPagina: Permite levantar ventana de impresion.
// Param = 1-> Switch
//-------------------------------------------------------------------------------------------
function ImpPagina(nSw)
{
	
	if(nSw == 1)
	{
		if (window.print)
			window.print();
	  	else alert("No es posible imprimir, su navegador es incompatible con esta petición.");
	}
	else
	{
		if ((navigator.appName == "Netscape"))
			window.print() ; 
		else
		{
			var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
			document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(7, -1); WebBrowser1.outerHTML = "";
		}
	}
} 

// Fecha: Permite obtener fecha de sistema.
// Param = 1-> Estilo css
//-------------------------------------------------------------------------------------------
function Fecha(sStyle)
{
	
	var mydate=new Date()
	var year=mydate.getYear()
	
	if (year < 1000)
	year+=1900
	
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	
	if (daym<10)
	daym="0"+daym
	
	var dayarray=new Array("Domingo","Lunes","Martes","Mi&eacute;rcoles","Jueves","Viernes","S&aacute;bado")
	var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre")
	
	sA = dayarray[day]+",  "+daym+" de "+montharray[month]+" de "+year;
	
	sF = "<span class="+sStyle+">"+sA+"</span>";
	
	
	return document.write(sF);
}



// getWindowData: Permite obtener dimensiones de ventana.
//-------------------------------------------------------------------------------------------
function getWindowData()
{ 
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal; 
    if (typeof window.innerWidth != 'undefined')
	{ 
        widthViewport= window.innerWidth-17; 
        heightViewport= window.innerHeight-17; 
    }
	else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0)
	{ 
        widthViewport=document.documentElement.clientWidth; 
        heightViewport=document.documentElement.clientHeight; 
    }
	else
	{ 
        widthViewport= document.getElementsByTagName('body')[0].clientWidth; 
        heightViewport=document.getElementsByTagName('body')[0].clientHeight; 
    } 
    
	xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft); 
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop); 
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport); 
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport); 
    
	return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal]; 
} 



