// Funciton to close/hide a box
function toggleBox(objDiv)
{
	var objBox = document.getElementById(objDiv);

	if (objBox.style.display == "none")
		objBox.style.display = "";
	else {
		objBox.style.display = "none";
	}

}

//Function to jump to another forum
function ForumJump(URL) {

	if (URL.options[URL.selectedIndex].value != "") self.location.href = URL.options[URL.selectedIndex].value;
	return true;
}

//Function to open pop up window
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}



//Function to open preview post window
function OpenPreviewWindow(targetPage, formName){

	now = new Date

	//Open the window first
   	openWin('','preview','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=680,height=400')

   	//Now submit form to the new window
   	formName.action = targetPage + "?ID=" + now.getTime();
	formName.target = "preview";
	formName.submit();
}

//Function to hide and show menu sub links
function menushowhide(objImage, id) {

	var objBox = document.getElementById(id)

	if (document.getElementById(id).style.display == "") {
		objBox.style.display = "none";
		objImage.style.filter = "gray()";

		SaveCookie(id, 'Hide');
	}
	else {
		objBox.style.display = "";
		objImage.style.filter = "";

		SaveCookie(id, 'Show');
	}
}

//Function show and hide column boxes
function showhide(id, imgPath) {
	var objBox = document.getElementById(id + '_full');
	var objContent = document.getElementById(id);
	var objImage = document.getElementById(id + '_image');

	var boxHeight = objContent.clientHeight;

	//Hide Box
	if (objContent.style.display=='') {
		if (objContent.clientHeight==0) {
			objContent.style.height='0px';
			boxHeight = objContent.clientHeight;
		}

		objContent.value = boxHeight;
		//objContent.style.MozOpacity="1";

		objContent.style.overflow = 'hidden';
		objContent.style.height = boxHeight;

		objImage.src = imgPath + 'module-max-arrow.gif';
		objBox.style.filter = 'gray()';

		closeBox(id, boxHeight);
		SaveCookie(id, 'Hide');
	//Show Box
	} else {
		boxHeight = objContent.value;
		if (boxHeight==0) boxHeight = objContent.clientHeight;

		objImage.src = imgPath + "module-min-arrow.gif";
		objBox.style.filter = '';
		//objContent.style.MozOpacity="0";

		if (boxHeight>=0) {
			objContent.style.overflow = "hidden";
			objContent.style.display='';
			objContent.style.height='1px';

			showBox(id, boxHeight);
		} else {
			objContent.style.overflow = 'visible';
			objContent.style.display='';
		}

		SaveCookie(id, 'Show');
		objContent.value = "";
	}
}

function closeBox(id, Height) {
	var objContent = document.getElementById(id);

	var boxHeight = objContent.style.height;
	boxHeight = parseInt(boxHeight.replace('px',''));
	boxHeight = boxHeight - 4 + parseInt((boxHeight - Height)/8);

	if (boxHeight<=0) boxHeight = 0;

	objContent.style.height = boxHeight+'px';
	//objContent.style.MozOpacity = (boxHeight/Height);

	if (boxHeight==0) {
		objContent.style.display='none';
	} else {
		var boxInterval = "closeBox('" + id + "','" + Height + "')";
		setTimeout(boxInterval, 10);
	}
}

function showBox(id, Height) {
	var objContent = document.getElementById(id);

	var boxHeight = objContent.style.height;
	boxHeight = parseInt(boxHeight.replace('px',''));
	boxHeight = boxHeight + 4 + parseInt((Height - boxHeight)/8);

	if (boxHeight>=Height) boxHeight = Height;

	objContent.style.height = boxHeight+'px';
	//if ((boxHeight/Height)!=0) objContent.style.MozOpacity= (boxHeight/Height);

	if (boxHeight!=Height) {
		var boxInterval = "showBox('" + id + "','" + Height + "')";
		setTimeout(boxInterval, 10);
	} else {
		objContent.style.overflow = "visible";
		objContent.style.height = "";
	}
}

function disableModule(id) {

	var closeModule = confirm('Are you sure you want to disable this box and not have it shown in the future?\n\nTo re-enable you have to click \' Reset Disabled Modules \' at the bottom of the Navigation Menu.');

	if (closeModule) {
		alert('The changes will take effect when you refresh your browser.');
		SaveCookie(id, 'Close');
	}

	return false;

}

function enableModule(id) {
	SaveCookie(id, 'Show');
}

//Function save cookie
function SaveCookie(name, value)
{
	var expiry = new Date();
	expiry.setTime (expiry.getTime() + (24 * 60 * 60 * 1000*365));

	document.cookie=name + "=" + escape(value) + "; expires=" + expiry + "; path=/";
}

//Function to check avatar image
function AvatarImage(objImage, newSize) {

	imgWidth = objImage.width;
	imgHeight = objImage.height;

	if (imgWidth > newSize) {
		objImage.width = newSize;
	}

	if (imgHeight > newSize) {
		objImage.height = newSize;
	}
}