/********************************************************
*			General Javascript Functions				*
********************************************************/

function switchid(id, plus){
	if(	document.getElementById(id).style.display == 'none')
	{
		showdiv(id);
		document.getElementById(plus).innerHTML="-";
		
	}
	else
	{
		hidediv(id);
		document.getElementById(plus).innerHTML="+";
		
	}	
	/*hideallids();
	showdiv(id);*/
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<furs.length;i++){
		hidediv(furs[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}



/********************************************************
*			AJAX Specific Javascript Functions			*
********************************************************/

function ajaxObject(url, callbackFunction, my) {
	var that=this;      
	this.updating = false;
	this.abort = function() {
		if (that.updating) {
			that.updating=false;
			that.AJAX.abort();
			that.AJAX=null;
		}
	}
	this.update = function(passData,postMethod) { 
		if (that.updating) { 
			return false; 
		}
		that.AJAX = null;                          
		if (window.XMLHttpRequest) {              
			that.AJAX=new XMLHttpRequest();              
		} 
		else {                                  
			that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		} 
		
		if (that.AJAX==null) {                             
			return false;                               
		} 
		else {
			that.AJAX.onreadystatechange = function() {  
				if (that.AJAX.readyState==4) {             
					that.updating=false;                
					that.callback(my, that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
					that.AJAX=null;                                         
				}                                                      
			}                                                        
			that.updating = new Date();                              
			if (/post/i.test(postMethod)) {
				var uri=urlCall+'?'+that.updating.getTime();
				that.AJAX.open("POST", uri, true);
				that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				that.AJAX.setRequestHeader("Content-Length", passData.length);
				that.AJAX.send(passData);
			} 
			else {
				var uri=urlCall+'?'+passData+'$amp;timestamp='+(that.updating.getTime()); 
				that.AJAX.open("GET", uri, true);                             
				that.AJAX.send(null);                                         
			}              
			return true;                                             
		}                                                                           
	}
	var urlCall = url;        
	this.callback = callbackFunction || function () { };
}

function showPost (my, responseText, responseStatus) {
	if ( responseStatus == 200 || responseStatus == 304 ) // success
	{
		/*var maindiv = document.getElementById("post-title");
		maindiv.innerHTML=responseText;*/
		document.getElementById("content"+my).innerHTML=responseText;
	}
	else 
		document.getElementById("content"+my).innerHTML='Error loading post';
}

function remPost (my, responseText, responseStatus) {
	if ( responseStatus == 200 || responseStatus == 304 ) // success
	{
		/*var maindiv = document.getElementById("post-title");
		maindiv.innerHTML=responseText;*/
		document.getElementById("content"+my).innerHTML=responseText;
	}
	else 
		document.getElementById("content"+my).innerHTML='Error loading post';
}


function showResult (my, responseText, responseStatus) {
	if ( responseStatus == 200 || responseStatus == 304 ) // success
	{
		/*var maindiv = document.getElementById("post-title");
		maindiv.innerHTML=responseText;*/
		document.getElementById("feed-result").innerHTML=responseText;
	}
	else 
		document.getElementById("feed-result").innerHTML='Error loading feed';
}

function msg ()
{
	document.getElementById("feed-result").innerHTML='K????????? ??? Feed...';
}

function initAjax(type, data)
{
	/*if (type == "post") {
		var symbol = document.getElementById(data).innerHTML;
		document.getElementById("content"+data).innerHTML= 'Updating...';
		
		if (symbol == '+') {
			var shpost = new ajaxObject('./ajax/ajax.php', showPost, data);
			shpost.update ('post='+data, 'POST');
		}
		else {
			-var rmpost = new ajaxObject('./ajax/ajax.php', remPost, data);
			rmpost.update ('rmpost='+data, 'POST');-
			switchid ('thepost'+data);
		}
	}*/
	if (type == "post" && data != "") {
		//var symbol = document.getElementById(data).innerHTML;
		document.getElementById("content"+data).innerHTML= 'Updating...';
		
		var shpost = new ajaxObject('./ajax/ajax.php', showPost, data);
		shpost.update ('post='+data, 'POST');
	}
	/*else if (type == "post" && data == "") {
		switchid ('thepost'+data);
	}*/
	else if (type == "rempost") {
		switchid ('thepost'+data, data);
	}
	else if (type == "chfeed") {
		document.getElementById("feed-result").innerHTML= 'Checking...';
		var temp = document.getElementById("url-feed").value;
		var result = new ajaxObject('./ajax/ajax.php', showResult, data);
		result.update ('chfeed='+temp, 'POST');
	}
}
