/*
Funciones auxiliares para prototipos
v0.2 | 2006-01-15
Nelson Rodríguez-Peña A.
nelson@webstudio.cl
*/

// Permite mosrtar un elemento utilizando el atributo display
function ui_showElement(objId) { //v1.0
	var obj = document.getElementById(objId);
	if (obj.style) {
		obj.style.display='block';
	}
}
// Permite ocultar un elemento utilizando el atributo display
function ui_hideElement(objId) { //v1.0
	var obj = document.getElementById(objId);
	if (obj.style) {
		obj.style.display='none';
	}
}

function focusElement( elId ) {
	o = document.getElementById( elId );
	if ( o ) {
		o.focus();
	}
}

function setInputText( objId, text ) {
	o = document.getElementById( objId );
	if ( o ) {
		o.value=text;
	}
}

function cambiarValorCuentas(  ) {
	s = document.getElementById('cuenta-origen');
	t = document.getElementById('saldo-cuenta-origen');
	t2 = document.getElementById('saldo-cuenta-origen2');
	sg = document.getElementById('saldo-cuenta-sobregiro');
	if ( s && t && t2 ) {
		switch (s.selectedIndex) {
			case 1:
				t.innerHTML='91.642';
				t2.innerHTML='1.141.642';
				if (sg) { sg.innerHTML='1.050.000'; }
				break;
			case 2:
				t.innerHTML='433.000';
				t2.innerHTML='1.483.000';
				if (sg) { sg.innerHTML='1.050.000'; }
				break;
			default:
				t.innerHTML='0';
				t2.innerHTML='0';
				if (sg) { sg.innerHTML='0'; }
		}
	}
}

function alertDisabled() {
	disabled();
}

function disabled() {
	alert('Esta función no está habilitada, por favor continúe.');		
}

function goto( url ) {
	document.location=url;
	return false;
}

function goback() {
	history.back();	
}

var _uf = 17950;

function pesoToUF( pesos ) {
	num = pesos / _uf;
	return num.toFixed(2);
}

function UFToPeso( uf ) {
	num = uf*_uf;
	return num.toFixed(2);
}


function filterNumber( myfield, e, dec ) {
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
	(key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}


function ge( id ) {
	return document.getElementById( id );
}

function openWindow(uri, options) {
	if (!options) {
		winOpts = "toolbar=1,scrollbars=1,resizable=1,menubar=1,status=1,location=1,personalbar=1";
	} else {
        winOpts = options;
	}
	winObj = window.open(uri, "newWin", winOpts);
    if (winObj == null || typeof(winObj) == "undefined") {
		alert("Popup bloqueado!");
		return false;
	} else {
		return true;
	}
}


function ayuda(anchor) {
	openWindow('ayuda.htm#'+anchor, 'toolbar=1,scrollbars=1,resizable=0,menubar=1,status=0,location=0,personalbar=0,width=350,height=400');
}


function alternarEstado( id ) {
	var st = document.getElementById( id+'-st' );
	var ic = document.getElementById( id+'-ic' );
	var lb = document.getElementById( id+'-lb' );
		//alert(st.innerHTML);
		//alert(ic);
		//alert(lb);
//	if ( st & ic & lb ) {
		//alert('ok');
		if ( st.innerHTML=='activo' ) {
			st.innerHTML='inactivo';
			st.className='stat-inactivo';
			ic.src='images/accept.png';
			lb.innerHTML='activar';
		} else {
			st.innerHTML='activo';
			st.className='stat-activo';
			ic.src='images/cancel.png';
			lb.innerHTML='desactivar';
		}

//	}

}


function uiDisableFormElement(elementName) {
	obj = document.getElementById(elementName);
	if (obj) {
		obj.disabled = true;
	}
}

function uiEnableFormElement(elementName) {
	obj = document.getElementById(elementName);
	if (obj) {
		obj.disabled = false;
	}
}

function uiSwitchDisableFormElement(elementID) {
	obj = document.getElementById(elementID);
	if (obj) {
		obj.disabled = !obj.disabled;
	}
}

function switchDisplay( elementID ) {
	o = document.getElementById( elementID );
	if ( o ) {
		if ( o.style.display == 'none' ) {
			o.style.display = '';
		} else {
			o.style.display = 'none';
		}
	}
}

// No limpia items anteriormente destacados
function hiliteCurrent( itemId ) {
	o = document.getElementById( itemId );
	if ( o ) {
		o.className = 'current';
	}
}


function getFirstWord( str ) {
	re = /^\S*/ig;
	result = re.exec(str);
	if ( result ) {
		return result[0];
	} else {
		return '';
	}
}
