var lastHeight = 23;
function resizer(obj) {
	if (obj.value.length > 140) {
		obj.value = obj.value.substr(0,140);
	}
	
	var dummyDiv = document.getElementById("dummyDiv");    	
	dummyDiv.innerHTML = obj.value;
	
	newHeight = parseInt(obj.style.height.substr(0,obj.style.height.length-2));    	
	if (obj.value != "" && newHeight < 43) {				
		newHeight = 43;
		obj.style.height = newHeight.toString() + 'px';			
	} else if (obj.value == "" && newHeight > 23) {
		newHeight = 23;
		obj.style.height = newHeight.toString() + 'px';
	}
	    	
	if (dummyDiv.scrollHeight != lastHeight) {									    		
		newValue = newHeight+(dummyDiv.scrollHeight-lastHeight);
		if (newValue < 23) newValue = 23;
		obj.style.height=newValue.toString() + 'px';			
		lastHeight = dummyDiv.scrollHeight;						
	}			
}

function getElement(obj, tagName) {		
	for (c1 = 0; c1 < obj.childNodes.length; c1++) {			
		if (obj.childNodes[c1].tagName == 'DIV') {
			for (c2 = 0; c2 < obj.childNodes[c1].childNodes.length; c2++) {
				if (obj.childNodes[c1].childNodes[c2].tagName == tagName) {						
					return obj.childNodes[c1].childNodes[c2];
				}
			}
		}
	}
}

function BlockUser(confirmation, username, id) {
	if (confirm(confirmation)) {
		objScript = document.createElement('SCRIPT');
	    objScript.setAttribute("type", "text/javascript");
	    objScript.setAttribute("src", "/wall_blockuser.php?username=" + username);
	    
	    objDiv = document.getElementById('procesador');
    	objDiv.appendChild(objScript);
    	
    	wall = document.getElementById('wallContainer');
    	for (w = 0; w < wall.childNodes.length; w++) {
    		if (wall.childNodes[w].title == username) {
    			wall.childNodes[w].style.display='none';
    		}
    	}
    		    	
    	var block = document.getElementById("block").cloneNode(true);
    	block.id = 'block' + id;
    		    	
    	block_link = getElement(block, "A");
    	block_text = getElement(block, "SPAN");
    	
    	block_link.href = "javascript:UnBlockUser('" + username + "', '" + id + "');";
    	block_text.innerHTML = BlockText.replace("#USUARIO", username);
    	
    	block.style.display = '';	    	
    	wall.insertBefore(block,document.getElementById("feed" + id));
    	setTimeout("fadeout('block" + id + "')", 2000);
	}
}

function UnBlockUser(username, id) {
	objScript = document.createElement('SCRIPT');
    objScript.setAttribute("type", "text/javascript");
    objScript.setAttribute("src", "/wall_unblockuser.php?username=" + username);
    
    objDiv = document.getElementById('procesador');
	objDiv.appendChild(objScript);    	
	
	wall = document.getElementById('wallContainer');
	
	var block = document.getElementById('block' + id);
	wall.removeChild(block);
	
	for (w = 0; w < wall.childNodes.length; w++) {
		if (wall.childNodes[w].title == username) {
			wall.childNodes[w].style.display='';
		}
	}
}

function RemoveFeed(confirmation, id) {	  	
	if (confirm(confirmation)) {		  	  	
	  	objScript = document.createElement('SCRIPT');
	    objScript.setAttribute("type", "text/javascript");
	    objScript.setAttribute("src", "/wall_removefeed.php?id=" + id);
	    
	    objDiv = document.getElementById('procesador');
    	objDiv.appendChild(objScript);
    	
    	fadeout("feed"+ id);
	}
}

function MoreFeeds(id_start, username) {
	var seemore = document.getElementById("seemore");
	var seemore_loading = document.getElementById("seemore_loading");
	seemore.style.display='none';
	seemore_loading.style.display='';
	
	iframe = document.getElementById('adder');
	if (username != "") {
		iframe.src = '/wallprofile_morefeeds.php?id_start='+id_start+'&username='+username;
	} else {
		iframe.src = '/wall_morefeeds.php?id_start='+id_start;
	}
}

function fadeout(id) {			
	if (document.getElementById(id)) {
		var speed = 5;
		var timer = 0;
			
		for(i = 100; i >= 0; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
				
		obj = document.getElementById(id);	
		obj.style.overflow='hidden';
		objH = obj.scrollHeight
		var dif = (objH/100);	
		for (i = 80; i >= 0; i--) {					
			setTimeout("changeHeight(" + i*dif + ",'" + id + "')",(timer * speed));
			timer++;
		}	
	}
}
	
function changeOpac(opacity, id) {
	if (document.getElementById(id)) {
		var object = document.getElementById(id).style; 
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
}
	
function changeHeight(height, id) {		
	if (document.getElementById(id)) {
		obj = document.getElementById(id);		
		if (height > 1) {
			obj.style.height=parseInt(height) + 'px'; 		
		} else {
			if (id.substr(0,5) == 'block') {
				wall = document.getElementById('wallContainer');
				wall.removeChild(obj);
			} else {
				obj.style.display = 'none';
			}
		}
	}
}	

function Publishing() {
	var publishButton = document.getElementById("publishButton");
	var publishButton_loading = document.getElementById("publishButton_loading");
	publishButton.style.display='none';
	publishButton_loading.style.display='';
}

function CancelPublishing() {
	var publishButton = document.getElementById("publishButton");
	var publishButton_loading = document.getElementById("publishButton_loading");
	publishButton.style.display='';
	publishButton_loading.style.display='none';
}