/**
* phpBB3 forum functions
*/

/**
* Window popup
*/
function popup(url, width, height, name)
{
	if (!name)
	{
		name = '_popup';
	}

	window.open(url.replace(/&amp;/g, '&'), name, 'height=' + height + ',resizable=yes,scrollbars=yes, width=' + width);
	return false;
}

/**
* Jump to page
*/
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
function jumpto() {
	var page = prompt(jump_page, on_page);

	if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) {
		var seo_page = (page - 1) * per_page;
		if ( base_url.indexOf('?') >= 0 ) {
			document.location.href = base_url.replace(/&amp;/g, '&') + '&start=' + seo_page;
		} else if ( seo_page > 0 ) {
			var seo_type1 = base_url.match(/\.[a-z0-9]+$/i);
			if (seo_type1 !== null) {
				document.location.href = base_url.replace(/\.[a-z0-9]+$/i, '') + seo_delim_start + seo_page + seo_type1;
			}
			var seo_type2 = base_url.match(/\/$/);
			if (seo_type2 !== null) {
				document.location.href = base_url + seo_static_pagination + seo_page + seo_ext_pagination;
			}
		} else {
			document.location.href = base_url;
		}
	}
}
// www.phpBB-SEO.com SEO TOOLKIT END

/**
* Mark/unmark checklist
* id = ID of parent container, name = name prefix, state = state [true/false]
*/
function marklist(id, name, state)
{
	var parent = document.getElementById(id);
	if (!parent)
	{
		eval('parent = document.' + id);
	}

	if (!parent)
	{
		return;
	}

	var rb = parent.getElementsByTagName('input');
	
	for (var r = 0; r < rb.length; r++)
	{	
		if (rb[r].name.substr(0, name.length) == name)
		{
			rb[r].checked = state;
		}
	}
}

/**
* Resize viewable area for attached image or topic review panel (possibly others to come)
* e = element
*/
function viewableArea(e, itself)
{
	if (!e) return;
	if (!itself)
	{
		e = e.parentNode;
	}
	
	if (!e.vaHeight)
	{
		// Store viewable area height before changing style to auto
		e.vaHeight = e.offsetHeight;
		e.vaMaxHeight = e.style.maxHeight;
		e.style.height = 'auto';
		e.style.maxHeight = 'none';
		e.style.overflow = 'visible';
	}
	else
	{
		// Restore viewable area height to the default
		e.style.height = e.vaHeight + 'px';
		e.style.overflow = 'auto';
		e.style.maxHeight = e.vaMaxHeight;
		e.vaHeight = false;
	}
}

/**
* Set display of page element
* s[-1,0,1] = hide,toggle display,show
*/
function dE(n, s)
{
	var e = document.getElementById(n);

	if (!s)
	{
		s = (e.style.display == '' || e.style.display == 'block') ? -1 : 1;
	}
	e.style.display = (s == 1) ? 'block' : 'none';
}

/**
* Alternate display of subPanels
*/
function subPanels(p)
{
	var i, e, t;

	if (typeof(p) == 'string')
	{
		show_panel = p;
	}

	for (i = 0; i < panels.length; i++)
	{
		e = document.getElementById(panels[i]);
		t = document.getElementById(panels[i] + '-tab');

		if (e)
		{
			if (panels[i] == show_panel)
			{
				e.style.display = 'block';
				if (t)
				{
					t.className = 'activetab';
				}
			}
			else
			{
				e.style.display = 'none';
				if (t)
				{
					t.className = '';
				}
			}
		}
	}
}

/**
* Call print preview
*/
function printPage()
{
	if (is_ie)
	{
		printPreview();
	}
	else
	{
		window.print();
	}
}

/**
* Show/hide groups of blocks
* c = CSS style name
* e = checkbox element
* t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles) 
*/
function displayBlocks(c, e, t)
{
	var s = (e.checked == true) ?  1 : -1;

	if (t)
	{
		s *= -1;
	}

	var divs = document.getElementsByTagName("DIV");

	for (var d = 0; d < divs.length; d++)
	{
		if (divs[d].className.indexOf(c) == 0)
		{
			divs[d].style.display = (s == 1) ? 'none' : 'block';
		}
	}
}

function selectCode(a)
{
	// Get ID of code block
	var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];

	// Not IE
	if (window.getSelection)
	{
		var s = window.getSelection();
		// Safari
		if (s.setBaseAndExtent)
		{
			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
		}
		// Firefox and Opera
		else
		{
			var r = document.createRange();
			r.selectNodeContents(e);
			s.removeAllRanges();
			s.addRange(r);
		}
	}
	// Some older browsers
	else if (document.getSelection)
	{
		var s = document.getSelection();
		var r = document.createRange();
		r.selectNodeContents(e);
		s.removeAllRanges();
		s.addRange(r);
	}
	// IE
	else if (document.selection)
	{
		var r = document.body.createTextRange();
		r.moveToElementText(e);
		r.select();
	}
}

/**
* Play quicktime file by determining it's width/height
* from the displayed rectangle area
*/
function play_qt_file(obj)
{
	var rectangle = obj.GetRectangle();

	if (rectangle)
	{
		rectangle = rectangle.split(',');
		var x1 = parseInt(rectangle[0]);
		var x2 = parseInt(rectangle[2]);
		var y1 = parseInt(rectangle[1]);
		var y2 = parseInt(rectangle[3]);

		var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
		var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
	}
	else
	{
		var width = 200;
		var height = 0;
	}

	obj.width = width;
	obj.height = height + 16;

	obj.SetControllerVisible(true);
	obj.Play();
}

function translate(language) {
	if(language != '')
		window.open( 'http://www.google.com/translate?author=JavaScriptBank.com&ie=UTF8&hl=vi&sl=vi&tl=' + language + '&u=' + window.location.href );
}
function translator(language, url) {
	window.open( 'http://www.google.com/translate?author=javascriptbank.com&ie=UTF8&hl=vi&sl=vi&tl=' + language + '&u=' + window.location.href );
}
var banners_top_array = new Array(
					new Array( 'http://www.dreamhost.com/images/rewards/468x60-b.gif', 'http://www.dreamhost.com/r.cgi?257033/signup|97USDD', 'DreamHost Web Hosting'),
					new Array( 'http://www.hostgator.com/affiliates/banners/468x60e.gif', 'http://secure.hostgator.com/cgi-bin/affiliates/clickthru.cgi?id=jsbank', 'HostGator Web Hosting' ),
					new Array( 'http://img.bluehost.com/468x60/bh_468x60_03.gif', 'http://www.bluehost.com/track/jsbank/CODE60', 'BlueHost Web Hosting' ),
					new Array( 'https://www.ixwebhosting.com/templates/ix/v2/images/banners/expert-468x60-feb-22.gif', 'https://www.ixwebhosting.com/templates/ix/v2/affiliate/clickthru.cgi?id=jsbank', 'IX Web Hosting' ),
					new Array( 'http://www.hostnine.com/affiliates/banners/host9_468_60_01_03.gif', 'http://www.hostnine.com/affiliates/idevaffiliate.php?id=762_3_1_11', 'H9 Web Hosting' ),
					new Array( 'http://www.clicksor.com/publisher/images/pub/468x60_1.gif', 'http://www.clicksor.com/pub/index.php?ref=100237', 'ClickSor Ads' ),
					new Array( 'http://files.adbrite.com/mb/images/468x60-2.gif', 'http://www.adbrite.com/mb/landing_both.php?spid=122393&afb=468x60-2', 'AdBrite Ads' )
						);
function banner_rotator()
{
	var total_banners = banners_top_array.length;
	var i = Math.floor(Math.random()*total_banners),
		j = Math.floor(Math.random()*total_banners);
	while( i == j )
	{
		j = Math.floor(Math.random()*total_banners);
	}
	document.getElementById('banner_rotator').innerHTML = '<a href="' + banners_top_array[i][1] + '" title="' + banners_top_array[i][2] + '" target="_blank"><img src="' + banners_top_array[i][0] + '" width="468" height="60" alt="' + banners_top_array[i][2] + '" /></a> <a href="' + banners_top_array[j][1] + '" title="' + banners_top_array[j][2] + '" target="_blank"><img src="' + banners_top_array[j][0] + '" width="468" height="60" alt="' + banners_top_array[j][2] + '" /></a>';
	window.setTimeout( "banner_rotator()", 20000 );
}

function safe_cert( name )
{
	var this_url = window.location.href;
	switch( name )
	{
		case 'mcafee':
			window.open( 'http://www.siteadvisor.com/sites/javascriptbank.com' );
			break;
		case 'norton':
			window.open( 'https://safeweb.norton.com/report/show?url=javascriptbank.com' );
			break;
		case 'drweb':
			window.open( 'http://online.us.drweb.com/result/?url=' + this_url );
			break;
		default: // google
			window.open( 'http://www.google.com/safebrowsing/diagnostic?site=' + this_url );
			break;
	}
}