// JavaScript Document
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
function hoverEdit(obj, divImage){
	try{
		image =	document.getElementById(divImage); 
		image.style.display="";
		obj.style.background = '#F2FBFF';
	 
	}catch(e){
		alert(e);
	}
}

function outEdit(obj, divImage){
	try{
		image =	document.getElementById(divImage); 
		image.style.display="none"; 
		obj.style.background = '#ffffff';
	}catch(e){
		alert(e);
	}
}
function valid(divMensaje, divContenedor){
	objMensaje = document.getElementById(divMensaje);
	objContenedor = document.getElementById(divContenedor);
	if (objMensaje.innerHTML.indexOf("Error")<0){
		$('#'+divMensaje).fadeOut(2500,function() {
			objMensaje.innerHTML = "";
		  });
	 }
}
function guardar(obj, objContenct, divMensaje){
	try{
		objC = document.getElementById(objContenct);
		objCache = document.getElementById('cache');
		valor = obj.value;
		valorCache = objCache.value;
		id = obj.name;
		objC.innerHTML = valor;
		if (valorCache!=valor){
			ajax_loadContent(divMensaje,"../../users/update_page.php?id="+id+"&v="+valor,"Enviando..." ,"none", "valid('"+divMensaje+"','"+objContenct+"')");
		}
	}catch(e){
		alert('On blur Guardar:'+e);
	}
}
function edit(objName,id, divMensaje){
	$('#'+divMensaje).fadeIn('slow');
	obj = $("#"+objName);
	text='text'+objName;
	textObj=document.getElementById(text);
	if(textObj==null){
		obj.innerHTML='<textarea style="border:#09C  solid 1px;width:400px;	font-family: Tahoma, Geneva, sans-serif; font-size: 14px; color: #000;" id="'+text+'" name="'+id+'" onblur="guardar(this,\''+objName+'\',\''+divMensaje+'\')">'+obj.text()+'</textarea><input id="cache" name="cache" type="hidden" value="'+obj.text()+'"/>';
		textObj=document.getElementById(text);textObj.focus();
			$(document).ready(function(){			
				$('textarea').elastic();
			});
 	}else{
		textObj.focus();
	}
}

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
function es(obj,tipo){
 	if(tipo=='u'){
		if (obj.value==""){
			obj.value="Usuario";
			obj.style.fontStyle="italic";	
			obj.style.color="#CCC";			
		}
	}else if(tipo=='c'){
		if (obj.value==""){
			obj.value="Contraseņa";
			obj.style.fontStyle="italic";	
			obj.style.color="#CCC";
		}
	}
}

function de(obj){
	if (obj.value=="Usuario" || obj.value=="Contraseņa"){
		obj.value="";
		obj.style.fontStyle="normal";
		obj.style.color="#000";
	}	
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
function hover(obj){
	try{
		obj.style.background = '#F2FBFF';
	}catch(e){
		alert(e);
	}
}
function out(obj){
	try{
		 
		obj.style.background = '#ffffff';
	 
	}catch(e){
		alert(e);
	}
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
function bgImageColorOver(obj, nivel){
	try{
		ns='';
		if(nivel==1){
			ns='../';
		}else if(nivel==2){
			ns='../../';
		}
		obj.style.backgroundImage = 'url('+ns+'images/barras/gradientAmarillo.jpg)' ;
	}catch(e){
		alert(e);
	}
}
function bgImageColorOut(obj){
	try{
		 
		obj.style.backgroundImage = '';
	 
	}catch(e){
		alert(e);
	}
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
function textCounter(field, countfield, maxlimit) {
	try{
		if (field.value.length > maxlimit) {// if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
		}else{
			countfield.value = maxlimit - field.value.length;
		}
	}catch (ex){
		alert(ex);
	}
}