function h(e){
	if(!document.getElementById(e)){return false;}
	document.getElementById(e).style.display="none";
	return true;
}

function s(e){
	if(!document.getElementById(e)){return false;}
	document.getElementById(e).style.display="block";
	return true;
}

function sh(e){
	if(!document.getElementById(e)){return false;}
	e=document.getElementById(e);
	if(!e.style.display){e.style.display="none";}
	e.style.display=(e.style.display=="none")?"block":"none";
	return true;
}

// Obsolete en XML
function email(mail,anchor){
	mail=mail.replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
	//alert(mail);
	//alert(e);
	if(!anchor){
		document.write("<a href=\"mailto:"+mail+"\">"+mail+"</a>");
	}else{
		document.write("<a href=\"mailto:"+mail+"\">"+anchor+"</a>");
	}
}

function emailReplace(){
	
	var el=YAHOO.util.Dom.getElementsByClassName("emailReplace","span");
	for(i=0;i<el.length;i++){
		var em=el[i].innerHTML;
		em=em.replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
		em='<a href="mailto:'+em+'">'+em+'</a>';
		el[i].innerHTML=em;
	}
	
}

function collapse(e){
	var y=e.parentNode;
	if(YAHOO.util.Dom.hasClass(y,"collapsed")){
		var h=y.rosgoH;
		var t=(h/500);
		var eBox=new YAHOO.util.Anim(y,{height:{to:h}},t,YAHOO.util.Easing.easeOut);
		eBox.onComplete.subscribe(function(){YAHOO.util.Dom.removeClass(y,"collapsed");y.style.height="";});
		eBox.animate();
	}else{
		var h=y.offsetHeight;y.rosgoH=h;
		y.style.height=h+"px";
		var t=(h/500);
		var cBox=new YAHOO.util.Anim(y,{height:{from:h,to:40}},t,YAHOO.util.Easing.easeOut);
		YAHOO.util.Dom.addClass(y,"collapsed");
		cBox.animate();
	}
}

function collapseAll(){

	var f=document.getElementsByTagName("legend");
	if(O.collapsed==true){
		for(i=0;i<f.length;i++){
			if(!YAHOO.util.Dom.hasClass(f[i].parentNode.parentNode,"box-in-box")){
				if(YAHOO.util.Dom.hasClass(f[i].parentNode,"collapsed")){collapse(f[i]);}
			}
		}
		O.collapsed=false;
	}else{
		for(i=0;i<f.length;i++){
			if(!YAHOO.util.Dom.hasClass(f[i].parentNode.parentNode,"box-in-box")){
				if(!YAHOO.util.Dom.hasClass(f[i].parentNode,"collapsed")){collapse(f[i]);}
			}
		}
		O.collapsed=true;
	}
	
}

function openFrame(u){
		
		var y=window.scrollY+30;
		document.getElementById("w_iframe").src=u;
		YAHOO.util.Dom.setXY("window",[-10,y]);
		var oFr=new YAHOO.util.Anim("window",{height:{from:0,to:80,unit:"%"},width:{from:0,to:90,unit:"%"},left:{from:-10,to:35}},.3,YAHOO.util.Easing.easeOut);
		oFr.animate();
		return false;
	
}

function closeFrame(){
	
		var cFr=new YAHOO.util.Anim("window",{height:{from:80,to:0,unit:"%"},left:{from:35,to:-10},width:{from:90,to:0,unit:"%"}},.3,YAHOO.util.Easing.easeOut);
		cFr.animate();
		return false;
	
}

function openBrowser(local){
	if(local){u=document.getElementById("documentLocalUrl").value;if(u==""){u="http://www.doku-mento.com/";}}
	else{u=document.getElementById("documentUrl").value;}
	if(u!=""){
	//document.getElementById("w_ctrl").innerHTML="<a href=\"#\" onclick=\"return pickUrl();\">Seleccione este documento</a> | <a href=\"#\" onclick=\"return closeFrame();\">Cerrar esta ventana</a>";
		if(local){document.getElementById("w_ctrl").innerHTML="<a href=\"#\" onclick=\"return pickUrl('documentLocalUrl');\">Seleccione este documento</a> | <a href=\"#\" onclick=\"return closeFrame();\">Cerrar esta ventana</a>";}
		else{document.getElementById("w_ctrl").innerHTML="<a href=\"#\" onclick=\"return closeFrame();\">Cerrar esta ventana</a>";}
		return openFrame(u);
	}
	return false;
}

function pickUrl(id){
	document.getElementById(id).value=document.getElementById("w_iframe").contentDocument.location.href;
	A_getDocument("",document.getElementById("w_iframe").contentDocument.location.href);
	return closeFrame();
}

function setProgressBar(id,pc){
	
	var w=document.getElementById(id).offsetWidth;
	w=Math.ceil(pc*w);
	if(O.sPBf==0){var sPB=new YAHOO.util.Anim(id,{left:{from:0,to:w}},.3,YAHOO.util.Easing.easeOut);}
	else{var sPB=new YAHOO.util.Anim(id,{left:{to:w}},.3,YAHOO.util.Easing.easeOut);}
	sPB.animate();
	O.sPBf=w;
	
}

/* A */

function xhr(){var a=null;if(window.XMLHttpRequest)try{a=new XMLHttpRequest}catch(c){}else if(window.ActiveXObject)for(var d=0,b;b=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"][d++];)try{a=new ActiveXObject(b);break}catch(c){}return a;}

function pull(u){var a=xhr();if(a){a.open("GET",u);var at=0;a.onreadystatechange=function(){if(a.readyState==4){var c=0;if(a.status==200)try{eval(a.responseText);c=1}catch(d){}}};at=1;a.send(null);}}

function A_similar1(){
	
	var t=document.getElementById("inputLabTitle").value;
	var xc="/es/a/sim1/?s="+encodeURIComponent(t);
	pull(xc);
	return false;

}

function A_similar2(){
	
	var t=document.getElementById("inputDocTitle").value;
	var xc="/es/a/sim2/?s="+encodeURIComponent(t);
	pull(xc);
	return false;

}

function A_getDocument(id,url){

	var xc="/es/a/getDocument/?id="+encodeURIComponent(id)+"&url="+encodeURIComponent(url);
	pull(xc);
	return false;

}

function A_findTags(){
	
	var title,desc;
	if(document.getElementById("inputLabTitle")){title=document.getElementById("inputLabTitle").value;}
	if(document.getElementById("inputLabDesc")){desc=document.getElementById("inputLabDesc").value;}
	if(document.getElementById("inputDocTitle")){title=document.getElementById("inputDocTitle").value;}
	if(document.getElementById("inputDocDesc")){desc=document.getElementById("inputDocDesc").value;}
	var t=title+" "+desc;
	var xc="/es/a/suggestTags/?s="+encodeURIComponent(t);
	pull(xc);
	return false;

}

function A_checkUsername(){

	var t=document.getElementById("inputUserName").value;
	var xc="/es/a/userNameTaken/?s="+encodeURIComponent(t);
	pull(xc);
	return false;

}

function A_signIn(){

	var un=document.getElementById("signInUserName").value;
	var up=document.getElementById("signInUserPassword").value;
	var xc="/es/a/signIn/?u="+encodeURIComponent(un)+"&p="+encodeURIComponent(up);
	pull(xc);
	return false;

}

function A_logout(){

	var xc="/es/a/logout/";
	pull(xc);
	return false;

}

function A_uploadProgress(token){
	
	var xc="/es/a/uploadProgress/?token="+token;
	pull(xc);
	return false;
	
}

function A_checkNewDocForm(){
	document.getElementById("inputDocContent").value=tinyMCE.getInstanceById("inputDocContent").getBody().innerHTML;
	//alert(document.getElementById("inputDocContent").value);return false;
	var mode;
	if(document.getElementById("new_doc_on_my_computer").style.display=="block"){mode="upload";}
	else if(document.getElementById("new_doc_on_the_site").style.display=="block"){mode="localUrl";}
	else if(document.getElementById("new_doc_on_the_internet").style.display=="block"){mode="webUrl";}
	else if(document.getElementById("new_doc_by_copy_paste").style.display=="block"){mode="text";}
	document.getElementById("inputDocMode").value=mode;
	var fN=function callBack(o){eval(o.responseText);};
	var callback={success:fN};
	YAHOO.util.Connect.setForm("newDocForm",false);
	YAHOO.util.Connect.asyncRequest("POST","/es/a/checkDocForm/?justCheck=1",callback);
	return false;
	
}

function A_goNewDocForm(){
	
	var fN=function callBack(o){
		clearTimeout(to);
		setProgressBar("uploadProgressBar",1);
		eval(o.responseText);
	}
	var callback={success:fN,upload:fN};
	YAHOO.util.Connect.setForm("newDocForm",true);
	YAHOO.util.Connect.asyncRequest("POST","/es/a/checkDocForm/",callback);
	var token=document.getElementById("progress_key").value;
	O.sPBf=0;
	document.getElementById("uploadProgress").style.display="block";
	setProgressBar("uploadProgressBar",0);
	var to=setInterval("A_uploadProgress('"+token+"')",800);
	return false;
	
}




/* */
/*******************************/
/*******************************/

var O=new Object;
O.sPBf=0;
YAHOO.util.Event.onDOMReady(function(){
	var f=document.getElementsByTagName("legend");
	for(i=0;i<f.length;i++){f[i].onclick=function(e){collapse(this);};}
	emailReplace();
}
);

