<!--
/*======================================================================/*
// InstantForum.NET - Global JavaScript File							//
// (c) Ryan Healey © 2004 InstantASP Limited.							//
//																		//
// http://www.instantasp.co.uk/											//
// support@instantasp.co.uk												//
\*======================================================================*/

/* ----------------------------------------------------------- */
// Initialize menu constants					   
/* ----------------------------------------------------------- */

var mnu_active = false; // determines if a menu is active
var mnu_items = new Array(); // holds a collection of current active menus
var mnu_left = 0;
var mnu_right = 0;
var mnu_top = 0;
var mnu_bottom = 0;
var WinNum = 0; // init windows number

/* ----------------------------------------------------------- */
// Set-up document event handlers									   
/* ----------------------------------------------------------- */

if (ie4 || ie5 || opera) {
	document.onclick = if_hideAllMenusOnClick;
	document.onscroll = if_hideAllMenusOnClick;
	window.onresize = if_winResize;
}    
else if (ns6) { 
	document.addEventListener("mousedown", if_hideAllMenusOnClick, true);
	window.addEventListener("onresize", if_winResize, true);
} 
else if (ns4) {
	document.onmousedown = if_hideAllMenusOnClick;
	window.captureEvents(Event.MOUSEMOVE);
}

/* ----------------------------------------------------------- */
// Pre-load drop down menu images so they display correctly					   
/* ----------------------------------------------------------- */

function if_preLoad(strForumSkin) {

	arImageList = new Array ();
	var arImageSrc = new Array(strForumSkin + "misc_rating1.gif",
    strForumSkin + "misc_rating2.gif",
    strForumSkin + "misc_rating3.gif",
	strForumSkin + "misc_rating4.gif",
	strForumSkin + "misc_rating5.gif",
	strForumSkin + "button_go.gif");
	
	for (counter in arImageSrc) {
        arImageList[counter] = new Image();
        arImageList[counter].src = arImageSrc[counter];
    }
    
}

/* ----------------------------------------------------------- */
// Determine what object model we should use                   
/* ----------------------------------------------------------- */

function if_returnObjRef(objName) {

	var objReturn = '';
		if (ie5 || ns6)
		{
			objReturn = document.getElementById(objName);
			if (!objReturn) {
				objReturn = document.getElementById(if_findInASPNETControlTree(objName));
			}
		}
		else if (ie4 || opera)
		{
			objReturn = document.all[objName];
			if (!objReturn) {
				objReturn = document.all[if_findInASPNETControlTree(objName)];
			}
		}
		else if (ns4)
		{
			objReturn = document.layers[objName];
			if (!objReturn) {
				objReturn = document.layers[if_findInASPNETControlTree(objName)];
			}
		}

	return objReturn

}

/* ----------------------------------------------------------- */
// Open Menu on MouseOver Event
/* ----------------------------------------------------------- */

function if_openMenuMouseOver(caller_id, mnu_div_id, strForumSkin, mnu_width) {
	
	if (mnu_active) {if_openMenu(caller_id, mnu_div_id, strForumSkin, mnu_width);}
		
}

/* ----------------------------------------------------------- */
// Open Menu on MouseClick Event
/* ----------------------------------------------------------- */

function if_openMenu(caller_id, mnu_div_id, strForumSkin, mnu_width) {
		
		// determine if we can create elements dynamically
		
		if (!document.createElement) {return false;}
		
		// check to see if item is already within active menu array if so just quit and return false
				
		for (count = 0; count < mnu_items.length; count++)	{
			if (mnu_items[count] == mnu_div_id) {
				return false;
			}
		}
		
		// hide any menus that maybe open
		
		if_hideAllMenus();
		
		// add active menu to array and set active state to true
		
		mnu_items[mnu_items.length] = mnu_div_id;
		mnu_active = true;
		
		// create the div layer container for this menu
		
     	if_setDiv(mnu_div_id, strForumSkin, mnu_width);
     	
     	// get object references to div layer and div_layer that called this function
		
		var div_layer = if_returnObjRef(mnu_div_id);
     	var div_layer_caller = if_returnObjRef(caller_id);
     	
     	// set default offset for div layer from the caller div
     	
		var offsetTopDefault;
		offsetTopDefault = div_layer_caller.offsetHeight + 4;
		
		if ((ie4 || ie5) && !opera) {
			div_layer.filters.revealTrans.apply();
		}		
		
		// position div layer relative to the opening link
     	
     	div_layer.style.top = if_getAbsoluteOffsetTop(div_layer_caller) + offsetTopDefault;
     	div_layer.style.left = if_getAbsoluteOffsetLeft(div_layer_caller);   
     	
       	// get left, right, top and bottom co-ordinates for div layer
		
     	if (ie4 || ie5 || opera) { 
 			mnu_left = div_layer.style.posLeft;
			mnu_top = div_layer.style.posTop - offsetTopDefault; 
		}
		else if (ns6) {
			mnu_left = if_removePX(div_layer.style.left);
			mnu_top = if_removePX(div_layer.style.top);
		}
		
		mnu_right = parseInt(mnu_left) + parseInt(mnu_extent.x);			
		mnu_bottom = parseInt(mnu_top) + parseInt(mnu_extent.y);
		
		// attempt to keep menu on screen
			
		if (ie4 || ie5 || opera || ns6) { 
 			win_width = document.body.clientWidth;
			if (mnu_right > win_width)
			{div_layer.style.left = win_width - mnu_width - 10;}
		}
				
     	// play layer filter just before displaying   
     	
		if ((ie4 || ie5) && !opera) {div_layer.filters.revealTrans.play();}
		
		// hide select boxes
		
		if_toggleSelects('hidden')
		
		// finally display the menu
		
		div_layer.style.display = "";
		
}

/* ----------------------------------------------------------- */
// Hide all menus on click event of document
/* ----------------------------------------------------------- */

function if_hideAllMenusOnClick(event) {
	
	if (mnu_active) {
		
		// find the element that was clicked on.

		if (ie4 || ie5 || opera) {
			el = window.event.srcElement;
		}
		else {
			el = (event.target.tagName ? event.target : event.target.parentNode);
		}

		// if the element is not part of a menu, reset and clear the active button.

		if (if_getContainer(el, "DIV") == null) {
			if_hideAllMenus();
		}
	
	}
		
}

/* ----------------------------------------------------------- */
// Hide all active menus 
/* ----------------------------------------------------------- */

function if_hideAllMenus() {
	
	if (mnu_active) {	
		if_toggleSelects('visible');
		for (count = 0; count < mnu_items.length; count++)	{
			var div_layer = if_returnObjRef(mnu_items[count]);
			if (div_layer != null)	{
				div_layer.style.display = 'none';
				mnu_items[count] = '';
				mnu_active = false;
			}
		}			
	}
		
}

/* ----------------------------------------------------------- */
// Create div layer to hold menu
/* ----------------------------------------------------------- */

function if_setDiv(mnu_div_id, strForumSkin, mnu_width) {     

	// create div layer container to holder table
	
    var elemDiv = document.createElement('div');     	
    elemDiv.id = mnu_div_id;
    elemDiv.setAttribute('class','');
    elemDiv.style.position = 'absolute';       
    elemDiv.style.width = mnu_width;
    
    // if IE apply layer effects
    
    if ((ie4 || ie5) && !opera)	{
	elemDiv.style.filter += "progid:DXImageTransform.Microsoft.alpha(enabled=1,opacity=100)";
	elemDiv.style.filter += "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#AAAAAA,strength=2)";
	elemDiv.style.filter += "revealTrans(duration=0.2,transition=5)";}		
	
	// deteremine what table to apply as the innerHTML of the div layer container

	if (mnu_div_id == "if_menu_search") 
	{elemDiv.innerHTML = if_InitSearch(strForumSkin);}
	else if (mnu_div_id == "if_menu_recent_topics") 
	{elemDiv.innerHTML = if_InitRecentPosts();}
	else if (mnu_div_id == "if_control_panel") 
	{elemDiv.innerHTML = if_InitControlPanel();}
	else if (mnu_div_id == "if_forum_options") 
	{elemDiv.innerHTML = if_InitForumOptions();}
	else if (mnu_div_id == "if_forum_search") 
	{elemDiv.innerHTML = if_InitForumSearch(strForumSkin);}
	else if (mnu_div_id == "if_topic_options") 
	{elemDiv.innerHTML = if_InitTopicOptions();}
	else if (mnu_div_id == "if_topic_rating") 
	{elemDiv.innerHTML = if_InitTopicRating(strForumSkin);}
	else if (mnu_div_id.indexOf("if_author_name_") == 0) 
	{elemDiv.innerHTML = if_InitAuthorName(strForumSkin);}
	
	// add div layer to documents
	
	document.body.appendChild(elemDiv);    
	
	// get layer height now content has been added
	
	var mnu_height;
	
	if ((ie4 || ie5) || ns6)
		{mnu_height = elemDiv.offsetHeight;}
	else if (ns4)	
		{mnu_height = elemDiv.clip.height;}
	
	mnu_extent = {
		x : mnu_width,
		y : mnu_height
	};
		
	// finally hide the layer 
	
	elemDiv.style.display = "none";			
		
}

/* ----------------------------------------------------------- */
// Toggle display of forum group					           
/* ----------------------------------------------------------- */

function if_toggleDisplay(objName, strStylePath)
{

	obj = if_returnObjRef("if_obj_Group_" + objName);
	img = if_returnObjRef("if_obj_Image_" + objName);
	gft = if_returnObjRef("if_obj_Footer_" + objName);
	
	if (obj.style.display == "none" || gft.style.display == "none")
	{
		obj.style.display = "";
		gft.style.display = "";
		img.src = strStylePath + "misc_collapse.gif"
		if_update_cookie(objName, false);

	}
	else
	{
		obj.style.display = "none";
		gft.style.display = "none";
		img.src = strStylePath + "misc_expand.gif"
		if_update_cookie(objName, true);
	
	}
	return false;
}

/* ----------------------------------------------------------- */
// Save snapshot of forum groups into cookie		           
/* ----------------------------------------------------------- */

function if_update_cookie(objName, bolSave)
{
	var ckName = "InstantForum_Groups";
	var ckColl = if_get_cookie(ckName);		
	var arrLocTemp = new Array();
	
	if (ckColl != null) // if cookie exists
	{
		arrColl = ckColl.split(","); // split cookie into array
		
		for (i in arrColl) // loop array
		{
			/* if item does not match objName or is blank */
			if (arrColl[i] != objName && arrColl[i] != "") 
			{
				arrLocTemp[arrLocTemp.length] = arrColl[i];
			}
		}
	}

	if (bolSave) // if item is expanded save groupid to array
	{
		arrLocTemp[arrLocTemp.length] = objName;
	}

	if_set_cookie(ckName, arrLocTemp.join(",")); // save cookie
}

/* ----------------------------------------------------------- */
// Standard Cookie Functions                       	           
/* ----------------------------------------------------------- */

function if_set_cookie(name, value)
{
	expire = " expires=Wed, 1 Jan 2020 00:00:00 GMT;";
	document.cookie = name + "=" + value + "; path=/;" + expire;
}

/* ----------------------------------------------------------- */

function if_get_cookie(name)
{
	ckName = name + '=';
	ckPos  = document.cookie.indexOf(ckName);
	
	if ( ckPos != -1 )
	{
		ckStart = ckPos + ckName.length;
		ckEnd   = document.cookie.indexOf(";", ckStart);
		
		if (ckEnd == -1)
		{
			ckEnd = document.cookie.length;
		}
		
		return unescape( document.cookie.substring(ckStart, ckEnd) );
	}
	
	return null;
}

/* ---------------------------------------------------------------------------------------------- */  
// General Helper Functions
/* ---------------------------------------------------------------------------------------------- */

/* ----------------------------------------------------------- */  
// Get top location of menu link to position menu
/* ----------------------------------------------------------- */

function if_getAbsoluteOffsetTop(obj) {

	var top = obj.offsetTop;
	var parent = obj.offsetParent;
	while (parent != document.body) {
	top += parent.offsetTop;
	parent = parent.offsetParent;	}
	return top;
	
}

/* ----------------------------------------------------------- */
// Get left location of menu link to position menu
/* ----------------------------------------------------------- */

function if_getAbsoluteOffsetLeft(obj) {

	var left = obj.offsetLeft;
	var parent = obj.offsetParent;
	while (parent != document.body) {
	left += parent.offsetLeft;
	parent = parent.offsetParent;	}
	return left - 7;
	
}

/* ----------------------------------------------------------- */
// If we cannot immediatly find a tbody object to hide a table this 
// will loop though all tbodies and find the object regardless of any
// asp.net control tree identifiers - things like _ctl1_objectID
/* ----------------------------------------------------------- */

function if_findInASPNETControlTree(strObjectName) {
	
	var strObjectOutput;
		tbodies = document.getElementsByTagName("tbody");
		for (var i = 0; i < tbodies.length; i++)
		{
			if (tbodies[i].id.indexOf(strObjectName) > 0) {
			strObjectOutput = tbodies[i].id;
			}
		}
		
	return strObjectOutput;
	
}

/* ----------------------------------------------------------- */
// Starting with the given node, find the nearest containing element
// with the specified tag name.
/* ----------------------------------------------------------- */

function if_getContainer(node, tagName) {

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName)
      return node; node = node.parentNode;
  }

  return node;
}

/* ----------------------------------------------------------- */
// Hide select boxes when menus are expanded
/* ----------------------------------------------------------- */

function if_toggleSelects(state) {

	if (ie4 || ie5 || opera || ns6)	{
		selects = document.getElementsByTagName("select");
		for (var i = 0; i < selects.length; i++)
		{selects[i].style.visibility = state;}
	}

}

/* ----------------------------------------------------------- */
// This funtion removes the px chars from top and left 
// properties for NS6 browsers and returns a int
/* ----------------------------------------------------------- */

function if_removePX(strInput)	{
	var strOutput = 0;
	strOutput = strInput.substr(0, strInput.length -2);
	return strOutput;	
}

/* ----------------------------------------------------------- */
// This funtion removes any anchor points that maybe added to a 
// querystring value when getting the querystring values using javascript.
/* ----------------------------------------------------------- */

function if_removeBookmark(strInput)	{
	
	var strOutput;
	var bolBMFoundPos = strInput.indexOf("#");
	
	if (bolBMFoundPos > 0) 
	{strOutput = strInput.substring(0, bolBMFoundPos);}
	else
	{strOutput = strInput;}

	return strOutput;

}

/* ----------------------------------------------------------- */
// This function handles a window resize to ensure menus display correctly
/* ----------------------------------------------------------- */

function if_winResize() {

	if_hideAllMenus();

}

/* ----------------------------------------------------------- */
// Opens a window within the forums. Used for printtopic.aspx
/* ----------------------------------------------------------- */

function if_wOpen(Url, Width, Height, Scroll, ToolBar, Location, Status, MenuBar, Resizeable)	{	
	var String;
   	String =  "toolbar=" + ToolBar + ",location=" + Location 
   	String += ", directories=0,status=" + Status + ",menubar=" + MenuBar + ","
	String += "scrollbars=" + Scroll + ",resizable=" + Resizeable + ",copyhistory=0,";
   	String += ",width=";
   	String += Width;
   	String += ",height=";
   	String += Height;
   	WinPic = window.open(Url,WinNum++,String);	
}

/* ----------------------------------------------------------- */
// Forum logout confirmation
/* ----------------------------------------------------------- */

function if_logOut() {

	if (ie4 || ie5 || opera || ns6)	{
	
		ht = document.getElementsByTagName("body");
		ht[0].style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=55)";
		if (confirm('Are you sure you wish to logout?\n\nWhen you logout if you have choosen\nautomated login your cookie will be deleted.\n\nYou will need to login again to post to the forums.\n\nClick OK to confirm this action...'))
		{return true;}
		else
		{ht[0].style.filter = ""; return false;}
	}
	else {
		if (confirm('Are you sure you wish to logout?\n\nWhen you logout if you have choosen\nautomated login your cookie will be deleted.\n\nYou will need to login again to post to the forums.\n\nClick OK to confirm this action...'))
		{return true;}
		else
		{return false;}
	}
	
}

 
//-->

