var xmlhttp;
var postId;
var container;
var template;
var loaderImage;

function setLoaderImage(imgObj){
	loaderImage = imgObj;
}

function pull(where,id,what){
	xmlhttp=null;
	container = where;
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open("GET","?post="+id+"&action="+what,true);
		xmlhttp.send(null);
	}
	else{
		alert("Your browser does not support XMLHTTP.");
	}
}

function pullother(where,fullurl){
	xmlhttp=null;
	container = where;
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open("GET",fullurl,true);
		xmlhttp.send(null);
	}
	else{
		alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change(){
	if (xmlhttp.readyState==4){
		if (xmlhttp.status==200){
			document.getElementById(container).innerHTML=xmlhttp.responseText;
	    }
		else{
			alert("Problem retrieving data:" + xmlhttp.statusText);
	    }
	}
	else{
		document.getElementById(container).innerHTML="<img src='"+loaderImage.src+"' alt=''/>";	
	}
}

function loadImg(imgUrl,whereat,fullurl){
	var img = new Image(); 
	if(window.addEventListener){
		img.addEventListener('load',function(){loadXMLDoc(whereat,fullurl);},true);
		img.src = imgUrl;
	}
	else{
		img.attachEvent('onload',function(){loadXMLDoc(whereat,fullurl);});
		img.src = imgUrl;
	}
}

function loadXMLDoc(where,url){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
	}
	else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.open("GET",url,false);
		xmlhttp.send();
	}
	document.getElementById(where).innerHTML=xmlhttp.responseText;
}

var displayStyle = 'inline';

function show(xname,pid,action){
	document.getElementById(xname).style.display=displayStyle;
	if(action == 'comments'){
		show("inner_"+xname);
		pull("inner_"+xname,pid,action);
	}
}
function hide(xname){
	document.getElementById(xname).style.display='none';
}

function select_option(option_id,select_id){
	document.getElementById(select_id).selectedIndex = option_id;
}