function activa(obj){
	existeObjeto(obj);
	document.getElementById(obj).style.display="";
}

function desactiva(obj){
	existeObjeto(obj);
	document.getElementById(obj).style.display="none";
}

function existeObjeto(objeto){
	a = document.getElementById(objeto)
	if(!a){alert("El objeto '"+objeto+"', probablemente no exista.\n Revise el ID que envia a la funcion.")}
}

function existeObjetoName(objeto){
	//alert(objeto)
	a = document.getElementsByName(objeto)
	if(!a){alert("El objeto '"+objeto+"', probablemente no exista.\n Revise el 'Name' que envia a la funcion.")}
}

function cambiaClase(objeto,clase) { 
	document.getElementById(objeto).className=clase; 
}

function validaCampoTexto(campo){ 
	existeObjeto(campo);
	//f = document.getElementById(campo)
	r = (document.getElementById(campo).value!='')? 0:1;
	cl = (r==1)? 'error':'campos';
	cambiaClase(campo,cl)
	return r;
}

function validaCampoList(campo) {
	// Esta funcion valida que si el primer registro(index=0) esta selecionado, devuelve error(return 1) y cambia la calse de campos a error (campos->error)
	existeObjeto(campo);
	obj = document.getElementById(campo);
	f = obj.selectedIndex
	//alert(obj+" : "+ obj.selectedIndex)
	r = (f>0)? 0:1;
	cl = (r==1)? 'error':'campos';
	cambiaClase(campo,cl)
	return r
}

function validaCamposEmail(em1,em2) {
	v1 = document.getElementById(em1).value;
	v2 = document.getElementById(em2).value;
	f = (v1==v2)? 0:1;
	g = (validaCampoEmail(em1)==0)? 0:1;
	h = (validaCampoEmail(em2)==0)? 0:1;
	cl = ((f+g+h)>=1) ? 'error':'campos';
	cambiaClase(em1,cl)
	cambiaClase(em2,cl)
	//alert(f+g+" "+v1+" "+v2)
	return f+g+h;
}

function validaCampoEmail(campo) {
	existeObjeto(campo);
	valor = document.getElementById(campo);
	r = (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor.value))? 0:1;
	cl = (r==1)? 'error':'campos';
	cambiaClase(campo,cl)
	return r
}

function validaCampoCheckbox(campo){
	existeObjeto(campo);
	obj = document.getElementById(campo);
	r=0
	if(obj.checked==false){r=1}
	return r
}

function validaCampoRadioButton(campo,idcelda){ 
	existeObjeto(idcelda);
	existeObjetoName(campo);
	obj = document.getElementsByName(campo);
	var i;
	var r=1;
	cla = "error"
	//alert(obj+ " : " +obj.length);
	for (i=0;i<obj.length;i++){ 
		//alert(campo + " : " + obj[i].checked+" : "+ obj+ " : " +obj.length);
		if (obj[i].checked) {
			r=0;
			cla = ""
			break; 
		}
	} 
	cambiaClase(idcelda,cla)
	return r;
}

function selecciona(elemt, valor){
	// Seleciona un elemento de una lista en base al valor enviado
	//Recibe el ID del elemento que afectará, y el valor del criterio de selección
	x = _$$(elemt);	i = -1;
	do { x.selectedIndex = i++ } while (x.value != valor)		
}

function IIF($cond, $vV , $vF) {
	if ($cond) {return $vV; }else {return $vF;} 
}

function iif($cond, $vV , $vF) {
	if ($cond) {return $vV; }else {return $vF;} 
}

function _$$(obj) {
	if (typeof obj == 'string') { 
		existeObjeto(obj); a = document.getElementById(obj);
	} else {
		alert("El valor recibido debe ser string...");}
	return a;
}

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 
