// JavaScript Document

function showHide(catID){
	var divID = document.getElementById('cat'+catID);
	if(divID.style.display=='none'){ divID.style.display = 'block'; document.getElementById('expCol'+catID).innerHTML = '&#9650;'; }
	else{ divID.style.display = 'none'; document.getElementById('expCol'+catID).innerHTML = 'v'; }
}

function sh(did){
	var divID = document.getElementById(did);
	if(divID.style.display=='block'){ divID.style.display = 'none'; }
	else{ divID.style.display = 'block'; }
}

function showRF(d){
	var otherDiv = 'question';
	if(d == 'question'){ otherDiv = 'options'; }
	
	var divID = document.getElementById('RF_'+d);
	var otherDiv = document.getElementById('RF_'+otherDiv);
	
	if(divID.style.display=='none'){ otherDiv.style.display = 'none'; divID.style.display = 'block'; }
	else{ divID.style.display = 'none'; otherDiv.style.display = 'block'; }
}


function callScript(js, request){
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = js+"?"+request;
	document.getElementsByTagName('head')[0].appendChild(script);
}

function fetchUsers(user, txtBox, userSelectDiv){
	if(user.length > 3){
		callScript('forums/includes/js/queries.php', 'user='+user+'&txtBox='+txtBox+'&userSelectDiv='+userSelectDiv);
	}
}

function selectUser(txtBox, userSelectDiv, user){
	document.getElementById(txtBox).value = user;
	document.getElementById(userSelectDiv).style.display = 'none';
	document.getElementById(userSelectDiv).innerHTML = '';
}

function postRatingIcon(imgObj, imgType, sPath){
	imgObj.src = sPath + "images/"+imgType+".gif";
}

function ratePost(post_id, userID, sid, action, sPath){
	callScript(sPath+'includes/js/userfunctions.php', 'p='+post_id+'&u='+userID+'&sid='+sid+'&action='+action);
}

function doSubscribe(action, topicID, sPath){
	callScript(sPath+'includes/js/userfunctions.php', 'sub='+action+'&t='+topicID);
}

function appreciateTopic(topicID, sPath){
	callScript(sPath+'includes/js/userfunctions.php', 'appreciate='+topicID);
}

function doTopicBookmark(isTopic, topicID, sPath){
	callScript(sPath+'includes/js/userfunctions.php', 'bookmark='+topicID+'&isTopic='+isTopic);
}

function doConfirm(msg, goto){
	if(confirm(msg)){ location.href=goto; }
}

function getAvatars(dir, sPath, pg){
	callScript(sPath+'includes/js/avatars.php', 'gallery='+dir+'&sPath='+sPath+'&pg='+pg);
}



function textCounter(field,cntfield,maxlimit) {
	field = document.getElementById(field);
	cntfield = document.getElementById(cntfield);
	if (field.value.length > maxlimit){ // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		field.scrollTop = field.scrollHeight;
	}
	else{
		// otherwise, update 'characters left' counter
		cntfield.innerHTML = maxlimit - field.value.length;
	}
}

function checkPref(f){
	var theField = f.replace('chk_', '');
	if(document.getElementById(f).checked){
		document.getElementById(theField).disabled = '';
		document.getElementById(theField).select();
	}
	else{
		document.getElementById(theField).value = '0';
		document.getElementById(theField).disabled = 'disabled';
	}
}
