var newWidth;

function init_resize(classname, element, nw) {
  newWidth = parseInt(nw);
  var s = document.getElementsByTagName(element);
  for (var i=0; i<s.length; i++) {
    if (s[i].className==classname) {
      var imgs = s[i].getElementsByTagName("img");
      for (var j=0; j<imgs.length; j++) {
        imgs[j].onload = auto_resize;
      }
    }
  }
}

function auto_resize() {
  if (parseInt(this.width) > newWidth) {
  	this.org_width = this.width;
  	this.org_height = this.height;  	
    this.width = newWidth;
    this.style.cursor = "pointer";
    this.style.border = "1px dotted red";
    this.onclick = img_onclick;
  }
  this.onload = null;
}

function img_onclick() {
	window.open("forum.viewimage.php?image=" + this.src, null, "height=" + (this.org_height + 10) + ",width=" + (this.org_width + 10) + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}

var http_request = new Array();

function collapseuinfo (uid, pid, ext) {
	var nl = pid;
	var img = document.getElementById("img_fs_" + pid);
    // http_request[nl] = false;
	
    if (http_request[nl]) {
    	var alias_table = document.getElementById("fs_" + pid).style;
    	if (alias_table.display == 'none') {
    		alias_table.display = 'block';
    		//document.getElementById("fs_" + pid).innerHTML = http_request[nl].responseText;
    		img.src = "images/forum_fs" + ext + "_open.gif";
    	}
    	else {
    		img.src = "images/forum_fs" + ext + "_closed.gif";
    		alias_table.display = 'none';
    	}
    }
    else {
    	img.src = "images/forum_fs" + ext + "_open.gif";
    	
		if (window.XMLHttpRequest) {
		    http_request[nl] = new XMLHttpRequest();
		    if (http_request[nl].overrideMimeType) {
		        http_request[nl].overrideMimeType('text/xml');
		    }
		} else if (window.ActiveXObject) {
		    try {
		        http_request[nl] = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (e) {
		        try {
		            http_request[nl] = new ActiveXObject("Microsoft.XMLHTTP");
		        } catch (e) {}
		    }
		}
		
		if (!http_request[nl])
		    return false;
		
		http_request[nl].onreadystatechange = function() { placeMenu(nl, pid); }
		http_request[nl].open('GET', 'forum.uinfo.php?userid=' + uid, true);
		http_request[nl].send(null);
    }
}

function placeMenu (nl, pid) {
	if (http_request[nl].readyState == 4) {
		if (http_request[nl].status == 200) {
			document.getElementById("fs_" + pid).style.display = 'block';
			document.getElementById("fs_" + pid).innerHTML = http_request[nl].responseText;
	    }
	}
}
