// JavaScript Document

function showMenu(iObj){
	iState = document.getElementById(iObj).style;
	iState.display = "block";
	//if(iState.display=="none" || iState.display==""){
	//    iState.display = "block";
   // }else{	
	//    iState.display = "none";
   // }
}

function hideMenu(iObj){
	iState = document.getElementById(iObj).style;
	iState.display = "none";
}

function showMsg(iObj){
	iState = document.getElementById(iObj).style;
	iState.display = "block";
}

function hideMsg(iObj){
	iState = document.getElementById(iObj).style;
	iState.display = "none";
}
	

function toggleDetail(iTarget){
	if(document.getElementById(iTarget).style.display=='none' || document.getElementById(iTarget).style.display==''){
		document.getElementById(iTarget).style.display = 'block';
	}else{
		document.getElementById(iTarget).style.display = 'none';
	}
}


function ajaxRequest(iParams,iURL,iTarget){
	document.getElementById(iTarget).innerHTML = "Loading...";
	var xmlhttp;
	if (window.XMLHttpRequest){          // code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else if (window.ActiveXObject){     // code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		alert("Your browser does not support XMLHTTP!");
	}
	
	xmlhttp.open("POST",iURL,true);
	//http.open("POST", "/_includes/cart.php", true);
	
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", iParams.length);
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
		  document.getElementById(iTarget).innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.send(encodeURI(iParams));	
}

function init(iCat,iID){
	if(iID==0){
		setAllCategory();
	}else{
		setForum(iCat,iID);	
	}
}

function setForum(iCat,iID){
	var params = "";
	document.getElementById("threadListArea").style.display = 'block';
	var target = "/forum/services/getThreads.php?id="+iCat+"&start=0";
	ajaxRequest(params,target,"threadListArea");
	document.getElementById("categoryDetail").style.display = 'block';
	var target2 = "/forum/services/getSnippits.php?catSub=catSub"+iCat;
	ajaxRequest(params,target2,"categoryDetail");
	document.getElementById("categoryList").style.display = 'none';
	
	document.getElementById("postsList").style.display = 'block';
	var target3 = "/forum/services/getPosts.php?id="+iID;
	ajaxRequest(params,target3,"postsList");
}

function showPosts(id,iStart){
	var params = "";
	document.getElementById("postsList").style.display = 'block';
	var target = "/forum/services/getPosts.php?id="+id+"&start="+iStart;
	ajaxRequest(params,target,"postsList");
}

function showThreads(id,iStart){
	var params = "";
	var target = "/forum/services/getThreads.php?id="+id+"&start="+iStart;
	//document.getElementById("threadListArea").innerHTML = "Updating...";
	ajaxRequest(params,target,"threadListArea");
}

function setCategory(id){
	var params = "";
	document.getElementById("threadListArea").style.display = 'block';
	var target = "/forum/services/getThreads.php?id="+id+"&start=0";
	ajaxRequest(params,target,"threadListArea");
	document.getElementById("categoryDetail").style.display = 'block';
	var target2 = "/forum/services/getSnippits.php?catSub=catSub"+id;
	ajaxRequest(params,target2,"categoryDetail");
	document.getElementById("categoryList").style.display = 'none';
	
	document.getElementById("postsList").style.display = 'block';
	var target3 = "/forum/services/getPosts.php?id="+id;
	ajaxRequest(params,target3,"postsList");
}
function setAllCategory(){
	var params = "";
	document.getElementById("categoryList").style.display = 'block';
	var target2 = "/forum/services/getSnippits.php?catSub=catSubFull";
	ajaxRequest(params,target2,"categoryList");
	document.getElementById("threadListArea").style.display = 'none';
	document.getElementById("categoryDetail").style.display = 'none';
	
	document.getElementById("postsList").style.display = 'block';
	var target3 = "/forum/services/getPosts.php?id=0";
	ajaxRequest(params,target3,"postsList");
}

function setEventForum(iThreadID,iTarget){
	var params = "";
	var target = "/forum/services/getPosts.php?id="+iThreadID;
	ajaxRequest(params,target,iTarget);
}








