//------------------------------------------
// Invision Power Board v2.0
// Global JS File
// (c) 2003 Invision Power Services, Inc.
//
// http://www.invisionboard.com
//------------------------------------------

//==========================================
// Set up
//==========================================

// Sniffer based on http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var uagent    = navigator.userAgent.toLowerCase();
var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var is_ie     = ( (uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) && (!is_webtv) );
var is_ie4    = ( (is_ie) && (uagent.indexOf("msie 4.") != -1) );
var is_moz    = (navigator.product == 'Gecko');
var is_ns     = ( (uagent.indexOf('compatible') == -1) && (uagent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari) );
var is_ns4    = ( (is_ns) && (parseInt(navigator.appVersion) == 4) );
var is_opera  = (uagent.indexOf('opera') != -1);
var is_kon    = (uagent.indexOf('konqueror') != -1);
var is_webtv  = (uagent.indexOf('webtv') != -1);

var is_win    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
var is_mac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var ua_vers   = parseInt(navigator.appVersion);


//==========================================
// Pop up MyAssistant window
//==========================================

function buddy_pop()
{
	window.open( ipb_var_base_url + 'act=buddy','BrowserBuddy','width=250,height=500,resizable=yes,scrollbars=yes');
}

//==========================================
// Pop up chat window
//==========================================

function chat_pop(cw,ch)
{
	window.open( ipb_var_base_url + 'act=chat&pop=1','Chat','width='+cw+',height='+ch+',resizable=yes,scrollbars=yes');
}

//==========================================
// Multi Page jumps
//==========================================

function multi_page_jump( url_bit, total_posts, per_page )
{
	pages = 1;
	cur_st = ipb_var_st;
	cur_page  = 1;
	
	if ( total_posts % per_page == 0 )
	{
		pages = total_posts / per_page;
	}
	else
	{
		pages = Math.ceil( total_posts / per_page );
	}
	
	msg = ipb_lang_tpl_q1 + " " + pages;
	
	if ( cur_st > 0 )
	{
		cur_page = cur_st / per_page; cur_page = cur_page -1;
	}
	
	show_page = 1;
	
	if ( cur_page < pages )
	{
		show_page = cur_page + 1;
	}
	
	if ( cur_page >= pages )
	{
		show_page = cur_page - 1;
	}
 	else
 	{
 		show_page = cur_page + 1;
 	}
 	
	userPage = prompt( msg, show_page );
	
	if ( userPage > 0  )
	{
		if ( userPage < 1 )     {    userPage = 1;  }
		if ( userPage > pages ) { userPage = pages; }
		if ( userPage == 1 )    {     start = 0;    }
		else { start = (userPage - 1) * per_page; }
	
		window.location = url_bit + "&st=" + start;
	}
}


//==========================================
// Get element by id
//==========================================

function my_getbyid(id)
{
	itm = null;
	
	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	
	return itm;
}


//==========================================
// Set DIV ID to hide
//==========================================

function my_hide_div(itm)
{
	if ( ! itm ) return;
	
	itm.style.display = "none";
}

//==========================================
// Set DIV ID to show
//==========================================

function my_show_div(itm)
{
	if ( ! itm ) return;
	
	itm.style.display = "";
}



//==========================================
// locationjump
//==========================================

function locationjump(url)
{
	window.location = ipb_var_base_url + url;
}


//==========================================
// pop up window
//==========================================

function PopUp(url, name, width,height,center,resize,scroll,posleft,postop)
{
	showx = "";
	showy = "";
	
	if (posleft != 0) { X = posleft }
	if (postop  != 0) { Y = postop  }
	
	if (!scroll) { scroll = 1 }
	if (!resize) { resize = 1 }
	
	if ((parseInt (navigator.appVersion) >= 4 ) && (center))
	{
		X = (screen.width  - width ) / 2;
		Y = (screen.height - height) / 2;
	}
	
	if ( X > 0 )
	{
		showx = ',left='+X;
	}
	
	if ( Y > 0 )
	{
		showy = ',top='+Y;
	}
	
	if (scroll != 0) { scroll = 1 }
	
	var Win = window.open( url, name, 'width='+width+',height='+height+ showx + showy + ',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
}


/***********************************************
* D2-Topic Preview Hover  --  Created By Dean
* Website:  http://www.dscripting.com
***********************************************/

var ns5 = (document.getElementById && navigator.userAgent.indexOf('Gecko') > -1) ? true: false;
var ie5 = (document.getElementById && navigator.userAgent.indexOf('MSIE') > -1) ? true : false;
var ie4 = (!document.getElementById && document.all) ? true : false;

if (!ie4 && !ie5 && !ns5)
{
	event = "nope"
}


var offset_x = 10;
var offset_y = 30; 
var pre_main;
var pretime_1, pretime_2;
var pre_show = false;
var cur_x, cur_y;

function initiate()
{
	if (!ie4 && !ie5 && !ns5)
	{
		return;
	}

	pre_main = my_getbyid('preview_main');
	if (pre_main)
	{
		document.onmousemove = set_preview;
	}
}

window.onload = initiate;

function do_preview(num, evnt)
{
	if (!pre_main)
	{
		return;
	}

	if (pretime_1){clearTimeout(pretime_1);}
	if (pretime_2){clearTimeout(pretime_2);}
	pre_show = true;

	if (ie4 || ie5 || ns5)
	{
		var temp = my_getbyid('preview_'+num);
		var th = temp.innerHTML;
		var wd = (th.length > 100) ? 350 : th.length+25;
		var html = "<div class='statfenster' style='width:"+wd+"px'><table align='center' width='100%' cellspacing='0' cellpdding='3'><tr><td align='center' class='stat_bg'>";
		html += temp.innerHTML;
		html += "</td></tr></table></div>";
	 	pre_main.innerHTML = html;
		my_show_div(pre_main);
	}

	pretime_1 = setTimeout("my_show_div(pre_main)", 10);
}

function set_preview(e)
{
	cur_x = (ns5) ? e.pageX : event.x+tbody().scrollLeft;
	cur_y = (ns5) ? e.pageY : event.y+tbody().scrollTop;
	var redge = ((ie4 || ie5) && !window.opera) ? tbody().clientWidth-event.clientX-offset_x : window.innerWidth-e.clientX-offset_x-20;
	var bedge = ((ie4 || ie5) && !window.opera) ? tbody().clientHeight-event.clientY-offset_y : window.innerHeight-e.clientY-offset_y-20;
	var ledge = (offset_x < 0) ? offset_x*(-1) : -1000;

	if (redge < pre_main.offsetWidth)
	{
		pre_main.style.left = (ie4 || ie5) ? tbody().scrollLeft+event.clientX-pre_main.offsetWidth+"px" : window.pageXOffset+e.clientX-pre_main.offsetWidth+"px";
	}
	else if (cur_x < ledge)
	{
		pre_main.style.left = "5px";
	}
	else
	{
		pre_main.style.left = cur_x+offset_x+"px";
	}

	if (bedge < pre_main.offsetHeight)
	{
		pre_main.style.top = (ie4 || ie5) ? tbody().scrollTop+event.clientY-pre_main.offsetHeight-offset_y+"px" : window.pageYOffset+e.clientY-pre_main.offsetHeight-offset_y+"px";
	}
	else
	{
		pre_main.style.top = cur_y+offset_y+"px";
	}
}

function hide_preview()
{
	if (!pre_main)
	{
		return;
	}

	pretime_2 = setTimeout("my_hide_div(pre_main)", 10);
	pre_show = false;
}
function tbody()
{
	return (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
}