/*======================================================================*\
|| #################################################################### ||
|| #  				  Imperial Bulletin Board v1.x                    # ||
|| # ---------------------------------------------------------------- # ||
|| #  For license, version and changelog questions or concerns,       # ||
|| #  navigate to the docs/ folder or visit the forums at the		  # ||
|| #  website, http://www.imperialbb.com/forums. with your questions. # ||
|| # ---------------------------------------------------------------- # ||
|| # Name: js_global.js                                               # ||
|| # ---------------------------------------------------------------- # ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| # ---------------------------------------------------------------- # ||
|| #################################################################### ||
\*======================================================================*/

// ==============================
// Declare IBB if not already declared, else leave it.
// ==============================
if ( typeof IBB == 'undefined' )
{
	var IBB = { };
}

IBB.namespace = function ( )
{
	var args = arguments;
	var curr_pos = null;
	var i, j, ns_array;
	for (i=0; i<args.length; i++)
	{
		curr_pos = IBB;
		ns_array = args[i].split(".");
		for ( j = ( ns_array[0] == "IBB") ? 1 : 0; j<ns_array.length; j++ )
		{
			curr_pos[ ns_array[ j ] ] = curr_pos[ ns_array[ j ] ] || { };
			curr_pos = curr_pos[ ns_array[ j ] ];
		}
	}
	return true;
};

IBB.init = function ( )
{
	this.namespace ( 'init', 'general' );
	var ua = navigator.userAgent.toLowerCase ( );
	this['is_opera']  = ( ( ua.indexOf ( 'opera' ) != -1 ) );
	//this['is_saf']  = ( ( ua.indexOf ( 'applewebkit' ) != -1 ) || ( navigator.vendor == 'Apple Computer, Inc.' ) );
	this['is_saf'] 	  = ( ( ( ua.indexOf ( 'applewebkit' ) != -1 ) || ( ua.indexOf ( 'safari' ) != -1 ) ) || 
					    ( ( ua.indexOf ( 'konqueror' ) != -1 ) || ( ua.indexOf ( 'khtml' ) != -1 ) ) );
	this['is_webtv']  = ( ( ua.indexOf ( 'webtv' ) != -1 ) );
	this['is_ie']     = ( ( ua.indexOf ( 'msie' ) != -1 ) && ( !this.is_opera ) && ( !this.is_saf ) && ( !this.is_webtv ) );
	this['is_ie4']    = ( ( this.is_ie ) && ( ua.indexOf ( 'msie 4.' )  != -1 ) );
	this['is_ie5'] 	  = ( ( this.is_ie ) && ( ua.indexOf ( 'msie 5.' )  != -1 ) );
	this['is_ie6'] 	  = ( ( this.is_ie ) && ( ua.indexOf ( 'msie 6.' )  != -1 ) );
	this['is_ie7'] 	  = ( ( this.is_ie ) && ( ua.indexOf ( 'msie 7.' )  != -1 ) );
	this['is_moz']    = ( ( navigator.product == 'Gecko' ) && ( !this.is_saf ) );
	//this['is_kon']  = ( ua.indexOf ( 'konqueror' ) != -1 );
	this['is_ns']     = ( ( ua.indexOf ( 'compatible' ) == -1 ) && ( ua.indexOf ( 'mozilla' ) != -1 ) && ( !this.is_opera ) && ( !this.is_webtv ) && ( !this.is_saf ) );
	this['is_ns4']    = ( ( this.is_ns ) && ( parseInt ( navigator.appBVersion ) == 4 ) );
	this['is_mac']    = ( ( ua.indexOf ( 'mac' ) != -1 ) || ( navigator.vendor == 'Apple Computer, Inc.' ) );
	this['is_win'] 	  = ( ( ua.indexOf ( 'win' ) != -1 ) || ( ua.indexOf ( '16bit' ) !=- 1 ) );
	this['is_ps3'] 	  = ( ( ua.indexOf ( 'playstation 3' ) != -1 ) );
	this['cursor']    = ( ( this.is_ie ) ? 'hand' : 'pointer' );
	var ibblang  	  = ( ( typeof ( ibblang ) == 'undefined' ) ? new Array ( ) : ibblang );
	// fix freaking array push and array shift for IE 5+
	if ( typeof ( Array.prototype.push ) === 'undefined' )
	{
		Array.prototype.push = function ( )
		{
			var len = this.length;	
			var n 	= arguments.length;
			for ( var i = 0; i < n; i++ ) 
			{
				this[ len+i ] = arguments[ i ];
			}
			return this.length;
		}
	}
	if ( typeof ( Array.prototype.shift ) === 'undefined' )
	{
		Array.prototype.shift = function ( )
		{
			for ( var i = 0, b = this[0], l = this.length-1; i < l; i++ )
			{
				this[ i ] = this[ i+1 ];
			}
			this.length--;
			return b;
		}
	}
};
IBB.init ( );

IBB.general.cancel_bubble = function ( obj, ext )
{
	if ( ext !== false )
	{
		ext = true;
	}
	if ( !obj || IBB.is_ie )
	{
		if ( ext == true )
		{
			window.event.returnValue = false;
		}
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		obj.stopPropagation ( );
		if ( ext == true )
		{
			obj.preventDefault ( );
		}
		return obj;
	}
}

IBB.general.cancel_bubble_all = function( obj )
{
	return IBB.general.cancel_bubble ( obj, true );
}

IBB.general.cancel_bubble_one = function ( obj )
{
	return IBB.general.cancel_bubble ( obj, false );
}

IBB.general.add_load_event = function ( func ) 
{
	var oldonload = window.onload;
	if ( typeof ( window.onload ) != 'function' )
	{
		window.onload = func;
	}
	else
	{
		window.onload = function ( )
		{
			if ( oldonload )
			{
				oldonload ( );
			};
			func ( );
		};
	}
}		

IBB.general.offset_left = function ( obj )
{
	var curleft = 0;
	if ( obj.offsetParent )
	{
		while ( obj.offsetParent )
		{
			curleft += obj.offsetLeft;
			obj      = obj.offsetParent;
		}
	}
	else if ( obj.x )
	{
		curleft += obj.x;
	}
	return curleft;
}

IBB.general.offset_top = function ( obj )
{
	var curtop = 0;
	if ( obj.offsetParent )
	{
		while ( obj.offsetParent )
		{ 
			curtop += obj.offsetTop;
			obj     = obj.offsetParent;
		}
	}
	else if ( obj.y )
	{
		curtop += obj.y;
	}
	return curtop;
}

IBB.general.fetch_position = function ( e )
{
	if ( !( e = $ ( e ) ) ) 
	{
		return false;
	}
	var top 	= e.offsetTop;
	var left 	= e.offsetLeft;
	var width 	= e.offsetWidth;
	var height 	= e.offsetHeight;
	while ( e = e.offsetParent )
	{
		if ( e.style.position == 'absolute' || e.style.position == 'relative' || ( e.style.overflow != 'visible' && e.style.overflow != '' ) ) 
		{
			break;
		}
		top  += e.offsetTop;
		left += e.offsetLeft;
	}
	return { 
		top	 	: top, 
		left	: left, 
		width	: width, 
		height	: height
	};
}

IBB.general.fetch_body = function ( )
{
	var dBody = null;
	if ( !dBody ) 
	{
		dBody = IBB.general.ifelse ( ( document.compatMode && document.compatMode.indexOf ( 'CSS' ) > -1 ), document.documentElement, document.body );
		//dBody = ( document.compatMode && document.compatMode.indexOf ( 'CSS' ) > -1 ) ? document.documentElement : document.body;
	}
	return dBody;
}

IBB.general.fetch_scroll_x = function ( ) 
{
	return ( window.pageXOffset || window.scrollX || IBB.general.fetch_body ( ).scrollLeft || 0 );
}

IBB.general.fetch_scroll_y = function ( )
{
	return ( window.pageYOffset || window.scrollY || IBB.general.fetch_body ( ).scrollTop || 0 );
}

IBB.general.fetch_body_width = function ( ) 
{
	return ( self.innerWidth || IBB.general.fetch_body ( ).clientWidth || 0 );
}

IBB.general.fetch_body_height = function ( ) 
{
	return ( self.innerHeight || IBB.general.fetch_body ( ).clientHeight || 0 );
}

IBB.general.fetch_obj = function ( 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;
}

IBB.general.fetch_tags = function ( obj, tag )
{
	if ( typeof ( obj.getElementsByTagName ) != 'undefined' )
	{
		return obj.getElementsByTagName ( tag );
	}
	else if ( obj.all && obj.all.tags )
	{
		return obj.all.tags ( tag );
	}
	else
	{
		return null;
	}
}

IBB.general.fetch_tag = function ( tag )
{
	if ( document.getElementsByTagName )
	{
		return document.getElementsByTagName ( tag );
	}
	else if (document.all && document.all.tags)
	{
		return document.all.tags ( tag );
	}
	else
	{
		return null;
	}
}

IBB.general.add_shadow = function ( con, div )
{
	var objone = IBB.general.fetch_obj ( div );
	var objtwo = IBB.general.fetch_obj ( con );
	if ( IBB.is_ie )
	{
		objtwo.className      = 'shadow-ie';
		objtwo.style.width    = objone.offsetWidth+1+'px';
		objtwo.style.height   = objone.offsetHeight+1+'px';
	}
	else
	{
		objtwo.className      = 'shadow-moz';
		objtwo.style.width    = objone.offsetWidth+1+'px';
		objtwo.style.height   = objone.offsetHeight+1+'px';
	}
}

IBB.general.include_js_file = function ( file, did )
{
	var dodoc = IBB.general.ifelse ( typeof ( did ) != 'undefined', $ ( did ), $ ( 'head' ).item ( 0 ) );
	var dojs  = document.createElement ( 'script' );
	dojs.setAttribute ( 'language', 'javascript' );
	dojs.setAttribute ( 'type', 'text/javascript' );
	dojs.setAttribute ( 'src', file );
	dodoc.appendChild ( dojs );
	return false;
}

IBB.general.location_jump = function ( url, full, type )
{
	url = url.replace ( /&amp;/g, '&' );
	switch ( type )
	{
		case 'win':
			window.location.href = IBB.general.ifelse ( full == 'true', root_path+url, url );
		break;

		case 'doc':
		default:
			document.location.href = IBB.general.ifelse ( full == 'true', root_path+url, url );
		break;
	}
}

IBB.general.trim = function( text )
{
	if( typeof(text) == 'undefined' )
	{
		return '';
	}
	text = text.replace(/^\s+/, '');
	return text.replace(/\s+$/, '');
}

IBB.general.in_array = function( needle, haystack )
{
	if ( ! haystack.length )
	{
		return false;
	}
	for ( var i = 0 ; i < haystack.length ; i++)
	{
		if ( haystack[i] === needle )
		{
			return true;
		}
	}
	return false;
}

IBB.general.array_pop = function ( a, b )
{
	if(typeof a != 'object' || !a.length)
	{
		return null;
	}
	else
	{
		var response = a[a.length - 1];
		a.length--;
		return response;
	}
}

IBB.general.array_push = function (a, value)
{
	a[a.length] = value;
	return a.length;
}

IBB.general.array_stack_size = function ( ary ) 
{
	for ( i = 0 ; i < ary.length; i++ ) 
	{
		if ( ( ary[ i ] == '' ) || ( ary[ i ] == null ) || ( typeof ( ary ) == 'undefined' ) ) 
		{
			return i;
		}
	}
	return ary.length;
}

IBB.general.array_push_stack = function ( ary, val ) 
{
	arysize = IBB.general.array_stack_size ( ary );
	ary[ arysize ] = val;
}

IBB.general.array_pop_stack = function ( ary ) 
{
	arysize = IBB.general.array_stack_size ( ary );
	val = ary[ arysize-1 ];
	delete ary[ arysize-1 ];
	return val;
}

IBB.general.htmlspecialchars = function( text )
{
	text = text.replace( /</g, '&lt;' );
	text = text.replace( />/g, '&gt;' );
	text = text.replace( /"/g, '&quot;' );
	return text;
}

IBB.general.un_htmlspecialchars = function( text )
{
	text = text.replace( /&lt;/g  , '<' );
	text = text.replace( /&gt;/g  , '>' );
	text = text.replace( /&quot;/g, '"' );	
	return text;
}

IBB.general.encodeurl = function ( text )
{
	text = escape(text.toString()).replace(/\+/g, '%2B');
	var matches = text.match(/(%([0-9A-F]{2}))/gi);
	if (matches)
	{
		for (var matchid = 0; matchid < matches.length; matchid++)
		{
			var code = matches[matchid].substring(1,3);
			if (parseInt(code, 16) >= 128) 
			{
				text = text.replace(matches[matchid], '%u00' + code);
			}
		}
	}
	text = text.replace('%25', '%u0025');
	return text;
}

// //output = IBB.general.sprintf ( IBB.ibblang['chosen_mday'], chosen_mday );
IBB.general.sprintf = function ( )
{
	var ret = arguments[ 0 ];
	if ( ret )
	{
		var reg = /%(-)?(\d+)?\.?(\d+)?(\w)/g;
		var i = 0;
		var l = 0;
		var arr = Array ( );
		while ( arr = reg.exec ( ret ) )
		{
			if ( ++i > arguments.length ) 
			{	
				return null;
			}
			var tmp = '';
			if ( arr[ 4 ] == 'f' )
			{
				if ( arr[ 3 ] )	
				{
					tmp = arguments[ i ].toFixed ( arr[ 3 ] );
				}
			}
			else 
			{
				tmp = arguments[ i ].toString ( );
			}
			if ( ( l = Number ( arr[ 2 ] )-tmp.length ) > 0 )
			{
				tmp = IBB.general.ifelse ( arr[ 1 ], tmp+new Array ( l+1 ).join ( '   ' ), new Array ( l+1 ).join ( '   ' )+tmp );
				//tmp = arr[ 1 ] ? tmp+new Array ( l+1 ).join ( '   ' ) : new Array ( l+1 ).join ( '   ' )+tmp;
			}
			ret = ret.replace ( arr[ 0 ], tmp );
		}
		return ret;
	}
	else
	{
		return null;
	}
}

IBB.general.nocache_url = function ( url )
{
	var sep    = ( -1 < url.indexOf ( '?' ) ) ? '&' : '?';
	var mydate = new Date ( );
	var newurl = url+sep+'__='+mydate.getTime ( );
	return newurl;
}

IBB.general.lang_build_string = function ( )
{
	if ( ! arguments.length || ! arguments )
	{
		return;
	}
	var string = arguments[0];
	for( var i = 1 ; i < arguments.length ; i++ )
	{
		var match  = new RegExp('<%' + i + '>', 'gi');
		string = string.replace( match, arguments[i] );
	}
	return string;
}

IBB.general.hide_element = function ( itm )
{
	if(!itm)
	{
		return;
	}
	itm.style.display = "none";
}

IBB.general.show_element = function ( itm )
{
	if(!itm)
	{
		return;
	}
	itm.style.display = "";
}

IBB.general.show_stuff = function ( elm, dt, vt )
{
	if ( !( elm = $ ( elm ) ) ) 
	{
		return false;
	}
	elm.style.display 	 = IBB.general.ifelse ( !dtype, 'block', dt );
	elm.style.visibility = IBB.general.ifelse ( !vtype, 'visible', vt );
}

IBB.general.hide_stuff = function ( elm )
{
	IBB.general.show_stuff ( elm, 'none', 'hidden' );
}

IBB.general.toggle_view = function ( id )
{
	if(!id)
	{
		return;
	}
	if(itm = IBB.general.fetch_obj(id))
	{
		if(itm.style.display == "none")
		{
				IBB.general.show_element(itm);
		}
		else
		{
			IBB.general.hide_element(itm);
		}
	}
}

IBB.general.add_class = function ( elm, obj )
{
	if ( elm )
	{
		if ( elm.className != "" )
		{
			elm.className += " "+obj;
		}
		else
		{
			elm.className = obj;
		}
	}
}

IBB.general.remove_class = function ( elm, obj )
{
	if ( elm.className == elm.className.replace ( " ", "-" ) )
	{
		elm.className = elm.className.replace ( obj, "" );
	}
	else
	{
		elm.className = elm.className.replace(" "+obj, "");
	}
}

IBB.general.fetch_by_class_name = function ( elm, str, cls )
{
	var aryelms = ( str == '*' && document.all ) ? document.all : IBB.general.fetch_tag ( elm );
	var aryretelms = new Array ( );
	cls = cls.replace(/\-/g, "\\-");
	var regexp = new RegExp ( "(^|\\s)"+cls+"(\\s|$)" );
	var oelm = '';
	for ( var i = 0; i < aryelms.length; i++ )
	{
		oelm = aryelms[ i ];
		if ( regexp.test ( oelm.className ) )
		{
			aryretelms.push ( oelm );
		}
	}
	return aryretelms;
}

IBB.general.change_class = function ( id, cl )
{
	var objid = IBB.general.fetch_obj ( id );
	if ( objid )
	{
		objid.className = cl;
	}
}

IBB.general.disable_button = function ( id, msg )
{
	var button = IBB.general.fetch_obj ( id );
	if ( button != undefined )
	{
		if ( msg != undefined )
		{
			button.value = msg;
		}
		button.disabled = true;
	}
}

IBB.general.expand_visual_check = function ( id )
{
	var a = IBB.general.fetch_obj(id);
	if(a.style.display == '')
	{
		a.style.display = 'none';
	}
	else
	{
		a.style.display = '';
	}
}

IBB.general.check_boxes = function ( form_name, element_name, is_checked )
{
	var chkboxes = document.forms[ form_name ].elements[ element_name ];
	var count 	 = chkboxes.length;
	if ( count )
	{
		for ( var i = 0; i < count; i++ )
		{
			chkboxes[ i ].checked = is_checked;
		}
	}
	else
	{
		chkboxes.checked = is_checked;
	}
	return true;
}

IBB.general.resize_textarea = function ( to, id, type )
{
	var textarea = IBB.general.fetch_obj(id);
	if ( type == true )
	{
		textarea.style.width = parseInt ( textarea.offsetWidth )+( to < 0 ? -100 : 100 )+"px";
	}
	textarea.style.height = parseInt ( textarea.offsetHeight )+( to < 0 ? -100 : 100 )+"px";
	return false;
}

IBB.general.add_emoticon = function ( text )
{
	document.new_topic.body.value  += text;
	document.new_topic.body.focus();
}

IBB.general.add_window_emoticon = function ( text ) 
{
	top.opener.document.new_topic.body.value  += text;
	top.opener.document.new_topic.body.focus();
}

IBB.general.add_bbcode = function ( text,attrib )
{
	if(attrib != undefined)
    {
		attrib = "=" + attrib;
	}
	else
	{
		attrib = "";
	}
	document.new_topic.body.value += "[" + text + attrib + "]Text[/" + text + "]";
	document.new_topic.body.focus();
}

IBB.general.set_selection_range = function ( input, selbeg, selend ) 
{
	if ( input.IBB.general.set_selection_range )
	//if ( input.set_selection_range )
	{
		input.focus ( );
		input.IBB.general.set_selection_range ( selbeg, selend );
	}
	else if ( input.createTextRange ) 
	{
		var range = input.createTextRange ( );
		range.collapse ( true );
		range.moveEnd ( 'character', selend );
		range.moveStart ( 'character', selbeg );
		range.select ( );
	}
}

IBB.general.replace_selection = function ( input, repstr )
{
	if ( input.IBB.general.set_selection_range )
	//if ( input.set_selection_range )
	{
		var selbeg  = input.selbeg;
		var selend  = input.selend;
		input.value = input.value.substring ( 0, selbeg )+repstr+input.value.substring ( selend );
		if ( selbeg != selend )
		{
			IBB.general.set_selection_range ( input, selbeg, selbeg+repstr.length );
		}
		else
		{
			IBB.general.set_selection_range ( input, selbeg+repstr.length, selbeg+repstr.length );
		}
	}
	else if ( document.selection ) 
	{
		var range = document.selection.createRange ( );
		if ( range.parentElement ( ) == input ) 
		{
			var iscollapsed = range.text == '';
			range.text = repstr;
			if ( !iscollapsed )  
			{
				range.moveStart ( 'character', -repstr.length );
				range.select ( );
			}
		}
	}
}

// This and the above two functions allow us to use tab within textareas
// once they are put into play
//<textarea name="content" id="content" wrap="on" onKeyDown="return IBB.general.catch_tab ( this, event );"></textarea>
IBB.general.catch_tab = function ( item, e )
{
	if ( IBB.is_moz )
	{
		c = e.which;
	}
	else
	{
		c = e.keyCode;
	}
	if ( c == 9 )
	{
		IBB.general.replace_selection ( item, String.fromCharCode ( 9 ) );
		setTimeout ( "IBB.general.fetch_obj ( '"+item.id+"' ).focus ( );",0 );
		return false;
	}
}

IBB.general.template_select = function ( value )
{
	if ( value > 0 )
	{
		document.template_selector.submit ( );
	}
}

IBB.general.language_select = function ( value )
{
	if ( value > 0 )
	{
		document.language_selector.submit ( );
	}
}

IBB.general.jumpbox_select = function ( obj )
{
	var url = '';
	choosebox = obj.options[ obj.selectedIndex ].value;
	if ( choosebox != 0 )
	{
		if ( choosebox > 0 )
		{
			url = 'view_forum.php?fid='+choosebox;
		}
		else
		{
			switch ( choosebox )
			{
				case '-1':
					url = 'usercp.php';
				break;
				
				case '-2':
					url = 'pm.php';
				break;
				
				case '-3':
					url = 'search.php';
				break;
				
				default:
				case '-4':
					url = index_url;
				break;
			}
		}
		IBB.general.location_jump ( url, 'true', 'doc' );
	}
}

IBB.general.check_all = function ( form, elem, type ) 
{
	var checkname = document.form.elem;
	for ( i = 0; i < checkname.length; i++ )
	{
		checkname[ i ].checked = type.checked ? true : false;
	}
}

IBB.general.change_table_selection = function (action, prefix)
{
	var select_box = IBB.general.fetch_obj('table_select');
	for(var i = 0; i < select_box.length; i++)
	{
		if(action == 'do')
		{
			document.table_selection.table_select[i].selected = true;
		}
		else if(action == 'undo')
		{
			document.table_selection.table_select[i].selected = false;
		}
	}
}

IBB.general.popup_window = function ( u, n, w, h )
{
	var d = new Date ( );
	var s = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=1, resizable=1';
	s = s+IBB.general.ifelse ( typeof ( w ) !== 'undefined', ', width='+w, ', width=400' );
	s = s+IBB.general.ifelse ( typeof ( h ) !== 'undefined', ', height='+h, ', height=400' );
	n = IBB.general.ifelse ( typeof ( n ) !== 'undefined', n, d.getTime ( ) );
	var w = window.open ( u.replace( '&amp;', '&' ), n, s );
	w.focus ( );
	return false;
}

IBB.general.confirm_action = function ( url, msg, lone, ltwo )
{
	if ( msg == null )
	{
		if ( lone == null || typeof ( lone ) == 'undefined' )
		{
			msg = 'Please Confirm:\nIs it ok to proceed ?';
		}
		else
		{
			msg = lone;
		}
	}
	url = IBB.general.ifelse ( ( url != null || typeof ( url ) !== 'undefined' ), url.replace( '&amp;', '&' ), '' );
	if ( confirm ( msg ) )
	{
		IBB.general.location_jump ( url, 'false', 'win' );
	}
	else
	{
		if ( ltwo == null || typeof ( ltwo ) == 'undefined' )
		{
			ltwo = 'Please Confirm:\nIs it ok to proceed ?';
		}
		alert ( ltwo );
		return false;
	} 
}

IBB.general.refresh_captcha = function ( )
{
	var rand = Math.floor ( Math.random ( ) * 1000000 );
	IBB.general.fetch_obj ( 'captcha_img' ).src = 'misc.php?func=captcha&nocache=' + rand;
}

IBB.general.blur_anchors = function ( )
{
	var a = IBB.general.fetch_tag ( "a" );
	for ( var i = 0; i < a.length; i++ )
	{
		a[i].onfocus = function ( )
		{
			this.blur ( )
		};
	}
}

IBB.general.ifelse = function ( one, two, thr )
{
	return ( ( one ) ? two : thr );
}

IBB.general.multi_paginate = function ( url, tp, pp, lang )
{
	var pages 	 = 1;
	var currpage = 1;	
	var showpage = 1;
	if ( tp%pp == 0 ) 
	{
		pages = tp/pp;
	}
	else 
	{
		pages = Math.ceil ( tp/pp );
	}
	var msg = lang+' '+pages;
	if ( currpg > 0 ) 
	{
		currpage = ( currpg/pp )-1;
	}
	if ( currpage < pages )
	{
		showpage = currpage + 1;
	}
	else 
	{
		showpage = currpage - 1;
	}
	var start 	 = '';
	var userpage = window.prompt ( msg, showpage );
	if ( userpage > 0 )
	{
		if ( userpage < 1 ) 
		{
			userpage = 1;
		}
		if ( userpage > pages ) 
		{
			userpage = pages;
		}
		if ( userpage == 1 ) 
		{
			start = 0;
		}
		else 
		{
			start = ( userpage-1 )*pp;
		}
		url = url+'&pg='+start;
		IBB.general.location_jump ( url, 'false', 'win' );
	}
}

function $( )
{
	var elm = Array ( );
	var len = arguments.length;
	if ( len == 1 )
	{
		elm = IBB.general.fetch_obj ( arguments[ 0 ] );
	}
	else 
	{
		for ( var i = 0; i < len; i++ )
		{
			elm.push ( IBB.general.fetch_obj ( arguments[ i ] ) );
		}
	}
	return elm;
}

/*======================================================================*\
|| #################################################################### ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| #################################################################### ||
\*======================================================================*/