var carga;

function bg_lista(){
	return "onMouseOver=\"style.backgroundColor=\'#FEDFA2\'\" onMouseOut=\"style.backgroundColor=\'#EFFFEF\'\"";
}

function copiar_campo(id1,id2){
	document.getElementById(id2).value = document.getElementById(id1).value
}

function on_mouse_over_popup(texto){
	return "onmouseover=\"return overlib(\'"+ texto +"\', TIMEOUT, 900);\" onblur=\"return nd();\" onmouseout=\"return nd();\" onclick=\"return nd();\"";
}

function carga_inicio(){
	if (carga){
		incluir_carga();
	}
}

function getcookie (name)

{

	var arg = name + "=";

	var alen = arg.length;

	var clen = document.cookie.length;

	var i = 0;

	while (i < clen)

	{

		var j = i + alen;

		if (document.cookie.substring(i, j) == arg)

		return getCookieVal(j);

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0)

		break;

	}

	return null;

}

function getCookieVal (offset) 

{

var endstr = document.cookie.indexOf (";", offset);

if (endstr == -1)

endstr = document.cookie.length;

return unescape(document.cookie.substring(offset, endstr));

}

function setcookie (name, value)

{

	var argv = setcookie.arguments;

	var argc = setcookie.arguments.length;

	var expires = (2 < argc) ? argv[2] : null;

	var path = (3 < argc) ? argv[3] : null;

	var domain = (4 < argc) ? argv[4] : null;

	var secure = (5 < argc) ? argv[5] : false;

	document.cookie = name + "=" + escape (value) +

	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

	((path == null) ? "" : ("; path=" + path)) +

	((domain == null) ? "" : ("; domain=" + domain)) +

	((secure == true) ? "; secure" : "");

}


function write_text(text,id)
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}

function popup(url,alto,ancho) {
	datewindow = window.open(url, 'popup', 'height='+alto+',width='+ancho+',top=150,left=150,scrollbars=yes,resizable=no,titlebar=no');
} 

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
	return true;
}      

function go(url) {
	alert(url);
	opener.location.href = url;
}

function cambiar_panel(id){
	
	show_hide(id, 'auto');
}

/***********************************************************************/
// SHOW HIDE PANEL
/***********************************************************************/

function format_money (num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	num = Math.floor(num/100).toString();
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num);
	}

function show_hide(id, show) {
	var itm = null;
	
		
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all){
		itm = document.all[id];
	} else if (document.layers){
		itm = document.layers[id];
	}
	
	if (!itm) {
		// do nothing
	}
	else if (itm.style) {
		
		if (show == 1){itm.style.display = "";}
		if (show == 0){itm.style.display = "none";}
		
		if (show == 'auto'){
			disp = itm.style.display;
			itm.style.display = "none";
			
			if (disp == "none"){
				itm.style.display = "";
			}
		}
		
	}else{
		itm.visibility = "show"; 
	}
}

/***********************************************************************/
// VALIDAR RUT
/***********************************************************************/
function validar_rut(form1){
	rut=form1.rut.value;
	
	if (rut == "1111111111"){
		rut = "0".concat(rut);
		alert("El RUT ingresado no es válido");
		return
	}
	
	switch (rut.length) {
  		case 9: rut = "0".concat(rut);break;
  		case 8: rut = "00".concat(rut);break;
    }
	
	
	var count=0;
	var count2=0;
	var factor=2;
	var suma=0;
	var sum=0;
	var digito=0;
		
	digito_a_verificar = rut.substring(10,9);
	
	if (digito_a_verificar == "k" || digito_a_verificar == "K"){
		digito_a_verificar = 10;
	}
	
	
	rut = rut.substring(8,0);
	
	count2=rut.length - 1;
	
	while(count < rut.length){
		sum = factor * (parseInt(rut.substr(count2,1))); 
		suma = suma + sum;
		sum=0;

		count = count + 1;
		count2 = count2 - 1;
		factor = factor + 1;

		if(factor > 7){
			factor=2; 
		} 
	}

	digito= 11 - (suma % 11)
	if(digito==11){
		digito=0;
	}

	if (digito_a_verificar != digito){
		alert("El RUT ingresado no es válido");
	}else{
		rut_ok = true;
	}
}