// JavaScript Document

function changeInputType(oldElm, iType, iValue, blankValue, noFocus)
{
	if(!oldElm || !oldElm.parentNode || (iType.length<4) || !document.getElementById || !document.createElement) return;
	var newElm = document.createElement('input');
	newElm.type = iType;
	//alert("old " + oldElm.type);
	//alert("new " + newElm.type);
	if(oldElm.name) newElm.name = oldElm.name;
	if(oldElm.id) newElm.id = oldElm.id;
	if(oldElm.className) newElm.className = oldElm.className;
	if(oldElm.size) newElm.size = oldElm.size;
	if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
	if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
	if(oldElm.style.width) newElm.style.width = oldElm.style.width;
	if(oldElm.style.height) newElm.style.height = oldElm.style.height;
	if(oldElm.style.lineHeight) newElm.style.lineHeight = oldElm.style.lineHeight;
	newElm.onfocus = function(){return function(){
	if(this.hasFocus) return;
	var newElm = changeInputType(this,'password',iValue,
	  (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
	if(newElm) newElm.hasFocus=true;
	}}();
	newElm.onblur = function(){return function(){
	if(this.hasFocus)
	if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
	  changeInputType(this,'text',iValue,false,true);
	}
	}}();
	// hasFocus is to prevent a loop where onfocus is triggered over and over again
	newElm.hasFocus=false;
	oldElm.parentNode.replaceChild(newElm,oldElm);
	if(!blankValue) newElm.value = iValue;
	if(!noFocus || typeof(noFocus)=='undefined') {
	window.tempElm = newElm;
	setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
	}
	//alert("oldElm type " + oldElm.type);
	return newElm;
}

function muestra(clase)
{
	// alert($("."+clase).css('display'));
	if ($("."+clase).css('display') == 'block')
		$("."+clase).css('display','none');
	else
		$("."+clase).css('display','block');
}

function ganaFoco(val,input)
{
	if (input.value == val) input.value = '';
	$("#nube").css('visibility','visible');
	$("#nube").css('z-index','1000');
}

function pierdeFoco(val,input)
{
	if (input.value == '')
	{
		input.value = val;
	}
}

function ganaFocoRef(val,input)
{
	if (input.value == val) input.value = '';
}
function pierdeFocoRef(val,input)
{
	if (input.value == '')
	{
		input.value = val;
	}
}

function cierraNube()
{
	$("#nube").css('visibility','hidden');
}

function recargar(txt){
	/// Aqui podemos enviarle alguna variable a nuestro script PHP
	var variable_post=txt;
	
	/// Invocamos a nuestro script PHP
	$.post("filtro.php",{ texto: variable_post },function(data)
	{
		/// Ponemos la respuesta de nuestro script en el párrafo recargado 
		$("#nube").html(data);
	});
}


