
/*
$(document).ready(function()
{
	var results = '';
	dcn = document.getElementsByTagName('*')
	for (i = 0; i < dcn.length; ++i)
	{
		if(dcn[i].nodeType != 1)
			continue;
		if(dcn[i].id == null)
			continue;
		if(dcn[i].id == '')
			continue;
		results = results + dcn[i].id + '\n';
	}
	alert(results);
});*/
//TRACK MOUSE POSITION
var globalMouseX;
var globalMouseY;
$(document).ready(function()
{
	$("body").mousemove(
		function(e)
		{
			globalMouseX = e.pageX;
			globalMouseY = e.pageY;
		}
	);
	var is_chrome = /chrome/.test( navigator.userAgent.toLowerCase() );	
	if (is_chrome) 
	{
		$(".table_lst td").each(
			function()
			{						
				var width = $(this).css("width");
				width = width.substring(0, width.length - 2);
				width = parseInt(width) + 12;
				$(this).css("width", width + 'px');
					
			}
		);	
		$(".table_frm td").each(
			function()
			{						
				var width = $(this).css("width");
				width = width.substring(0, width.length - 2);
				width = parseInt(width);
				
				var padleft = $(this).css("padding-left");
				padleft = padleft.substring(0, padleft.length - 2);
				var padright = $(this).css("padding-right");
				padright = padright.substring(0, padright.length - 2);
				var pad = parseInt(padleft) + parseInt(padright);
				//MISSING CELLPADDING?
				$(this).css("width", width + (pad + 2)*2 + 'px');
					
			}
		);	
	}
});




/*
function ie6resize()
{
	if($.browser.msie && parseInt($.browser.version) == 6)
	{		
		$("div[class^='blockbg']").each(
			function()
			{
				var width = $(this.parentNode).width();
				var pad = ($(this).css('right'));
				var pad = 2 * pad.substring(0,pad.length-2);
				$(this).css("width", width - pad + 'px');							
			
				var heightClass = false;
				if(($(this).hasClass('blockbgh1'))) 
					heightClass = true;			
				else if(($(this).hasClass('blockbgh2'))) 
					heightClass = true;				
				else if(($(this).hasClass('blockbgh3'))) 
					heightClass = true;				
				else if(($(this).hasClass('blockbgh4'))) 
					heightClass = true;				
				else if(($(this).hasClass('blockbgh5'))) 
					heightClass = true;				
				if (!heightClass) 
				{
					var height = $(this.parentNode).height();
					var pad = ($(this).css('top'));
					var pad = 2 * pad.substring(0, pad.length - 2);
					$(this).css("height", height - pad + 'px');
				}											
			}
		);		
	}
}
*/






function newColorPicker()
{
	alert('new');


}



/*
//FOOTER IE FIX
$(document).ready(function()
{
	if (!$.browser.msie )
		return;
	if(parseInt($.browser.version) != 6)
		return;
	$('#gtfooter').css('position', 'absolute');
	$('#gtfooter').css('bottom', 'auto');
	var scrollDistance	= document.documentElement.scrollTop;
	var windowHeight	= document.documentElement.offsetHeight;
	var footerHeight	= $('#gtfooter').height();
	$('#gtfooter').css('top', (windowHeight - footerHeight) + scrollDistance);
	$(window).scroll(function ()
	{
		var scrollDistance	= document.documentElement.scrollTop;
		var windowHeight	= document.documentElement.offsetHeight;
		var footerHeight	= $('#gtfooter').height();
		$('#gtfooter').css('top', (windowHeight - footerHeight) + scrollDistance);
	});
	$(window).resize(function ()
	{
		var scrollDistance	= document.documentElement.scrollTop;
		var windowHeight	= document.documentElement.offsetHeight;
		var footerHeight	= $('#gtfooter').height();
		$('#gtfooter').css('top', (windowHeight - footerHeight) + scrollDistance);
	});
});
*/
function getRadioValue(radioName)
{
	radios = document.getElementsByName(radioName);
	for (var i = 0; i < radios.length; i++)
		if (radios[i].checked)
			return radios[i].value;
	return null;
}
function createCookie(name,value,hours) {
	if (hours) {
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
//profile/edit.php
function populateDateWidget()
{
	year = document.getElementById("year");
	selectedYear = year.options[year.selectedIndex].value;
	if (selectedYear == "")
		return;
	month = document.getElementById("month");
	selectedMonth = month.options[month.selectedIndex].value;
	if (selectedMonth == "")
		return;
	day = document.getElementById("day");
	selectedDay = day.options[day.selectedIndex].value;
	dayinm = daysInMonth(selectedMonth, selectedYear);
	day.innerHTML = "";
	for (var i = 0; i <= dayinm; i++)
	{
		if (i == 0)
			day.options[i] = new Option('--' + "\u00A0", "");
		else if( i < 10)
			day.options[i] = new Option('0' + i + "\u00A0", i);
		else
			day.options[i] = new Option(i + "\u00A0", i);
		if (i == selectedDay)
			day.options[i].selected = true;
		if (i == dayinm && selectedDay >= dayinm)
			day.options[i].selected = true;
	}
}
function daysInMonth(month, year)
{
	var date = new Date(year, month, 0);
	return date.getDate();
}
//account/create/index.php
function populate(objForm,selectIndex) {
	e = document.getElementById("day");
	sel = e.selectedIndex;
	year = document.getElementById("year");
	month = document.getElementById("month");
	timeA = new Date(year.options[year.selectedIndex].text, month.options[month.selectedIndex].value,1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	for (var i = 0; i < e.length; i++)
	{
		e.options[0] = null;
	}
	for (var i = 0; i < daysInMonth; i++)
	{
		e.options[i] = new Option(i+1, i+1);
	}
	if(sel <=e.options.length)
	{
		e.options[sel].selected = true;
	}
	else
	{
		e.options[0].selected = true;
	}
}
//*****************************
//*****************************
function messageBoxConfirmSubmit(formName, msg)
{
	if(confirm(msg))
		document.getElementById(formName).submit();
}
//*****************************
//*****************************
function toggleVisibility(id1, id2)
{
	$('#' + id1).hide();
	$('#' + id2).show();
}
//*****************************
//*****************************
function showForm2(formElement)
{
	$('#' + formElement).show();
}
//*****************************
//*****************************
function hideForm(formElement)
{
	$('#' + formElement).hide();
}
//*****************************
//*****************************
$(document).ready(function()
{
	//IF JS ENABLED, DISABLE LOGIN LINK
	$("#header_dropdown_login_show").html("Log In");
	$("#header_dropdown_login_show").mouseover(function()
	{
		document.getElementById("header_dropdown_login_show").style.textDecoration = 'underline';
	});
	$("#header_dropdown_login_show").mouseout(function()
	{
		document.getElementById("header_dropdown_login_show").style.textDecoration = 'none';
	});
	//
	$('#header_dropdown_username').keyup(function(e)
	{
		if (e.keyCode == 13)
			document.getElementById('header_dropdown_login_form').submit();
	});
	$('#header_dropdown_password').keyup(function(e)
	{
		if (e.keyCode == 13)
			document.getElementById('header_dropdown_login_form').submit();
	});
});
var hdmLoaded = false;
//*****************************
//*****************************
function headerDDBuildMenu(ACCTID)
{
	if(hdmLoaded)
		return;
	hdmLoaded = true;
	try
	{
		$.ajax(
		{
			type:		"POST",
			url:		'/ajax_requests.php?rnd=' + Math.round(Math.random() * 10000000),
			processData:false,
			data:		'HEADERDROPDOWNMENU=&ACCTID=' + ACCTID,
			dataType:	'xml',
			success: function(resp_xml)
			{
				document.getElementById('header_dropdown_menu_fs').innerHTML = Base64.decode(resp_xml.getElementsByTagName('my_servers').item(0).firstChild.data);
				document.getElementById('header_dropdown_menu_mt').innerHTML = Base64.decode(resp_xml.getElementsByTagName('my_teams').item(0).firstChild.data);
				document.getElementById('private_messages_unread').innerHTML = Base64.decode(resp_xml.getElementsByTagName('private_messages_unread').item(0).firstChild.data);
			},
			error: function(resp_xml)
			{
				document.getElementById('header_dropdown_menu_fs').innerHTML = '<a href="http://www.gametracker.com/account/manage/my_servers.php"> View Servers </a>';
				document.getElementById('header_dropdown_menu_mt').innerHTML = '<a href="http://www.gametracker.com/account/manage/my_clans.php"> View Clans </a>';
			}
		});
	}
	catch (e)
	{
		document.getElementById('header_dropdown_menu_fs').innerHTML = '<a href="http://www.gametracker.com/account/manage/my_servers.php"> View Servers </a>';
		document.getElementById('header_dropdown_menu_mt').innerHTML = '<a href="http://www.gametracker.com/account/manage/my_clans.php"> View Clans </a>';
	}
}
//*****************************
//*****************************
function headerDDShow()
{
	if ($('#header_dropdown').css('display') == 'none')
	{
		$("#header_dropdown_menu_icon").attr('src', 'http://www.gametracker.com/images/global/header/header_button_ddup.gif');
		var offset = $("#header_dropdown_header").offset();
		$('#header_dropdown').css('top', offset.top+36);
		$('#header_dropdown').css('left', offset.left+3);
		$('#header_dropdown').slideDown('fast');
	}
	else
	{
		$("#header_dropdown_menu_icon").attr('src', 'http://www.gametracker.com/images/global/header/header_button_dddown.gif');
		$('#header_dropdown').slideUp('fast');
	}
}
function processTabClick(id)
{
	var ttab03 = document.getElementById('ttab_03');
	var ttab03block = document.getElementById('ttab_03block');
	if (id == 'ttab_01')
	{
		$('#ttab_01block').css('display', 'block');
		document.getElementById('ttab_01').className='ttab_on';
		$('#ttab_02block').css('display', 'none');
		document.getElementById('ttab_02').className='ttab_off';
		if (ttab03 != null)
			ttab03.className = 'ttab_off';
		if(ttab03block != null)
			ttab03block.style.display = 'none';
		return;
	}
	if (id == 'ttab_02')
	{
		$('#ttab_01block').css('display', 'none');
		document.getElementById('ttab_01').className='ttab_off';
		$('#ttab_02block').css('display', 'block');
		document.getElementById('ttab_02').className='ttab_on';
		if (ttab03 != null)
			ttab03.className = 'ttab_off';
		if(ttab03block != null)
			ttab03block.style.display = 'none';
		return;
	}
	if (id == 'ttab_03')
	{
		$('#ttab_01block').css('display', 'none');
		document.getElementById('ttab_01').className='ttab_off';
		$('#ttab_02block').css('display', 'none');
		document.getElementById('ttab_02').className='ttab_off';
		if (ttab03 != null)
			ttab03.className = 'ttab_on';
		if(ttab03block != null)
			ttab03block.style.display = 'block';
		return;
	}
}
/*
//*****************************
//*****************************
function navmenuShow(element, event, submenuid)
{
	submenu = document.getElementById('navmenu_plansub');
	if (submenu != null)
	{
		if(submenuid == 'navmenu_plansub')
			submenu.style.display = 'block';
		else
			submenu.style.display = 'none';
	}
	submenu = document.getElementById('navmenu_serversub');
	if (submenu != null)
	{
		if(submenuid == 'navmenu_serversub')
			submenu.style.display = 'block';
		else
			submenu.style.display = 'none';
	}
	submenu = document.getElementById('navmenu_clansub');
	if (submenu != null)
	{
		if(submenuid == 'navmenu_clansub')
			submenu.style.display = 'block';
		else
			submenu.style.display = 'none';
	}
	if ($.browser.msie )
		window.event.cancelBubble=true
	else
		event.stopPropagation();
}
*/
function stopPropagation(event)
{
	if ($.browser.msie)
		window.event.cancelBubble = true
	else
		event.stopPropagation();
}
//*****************************
//*****************************
function inputHintHide(element, event, hint)
{
	if(element.value == hint)
		element.value = "";
}
//*****************************
//*****************************
function hoverPopupShow(element, event, content)
{
	var popup = document.getElementById("HOVERPOPUP");
	if (popup == null)
	{
		//CREATE POPUP
		e = document.createElement("div");
		e.id = "HOVERPOPUP";
		e.style.display = "none";
		e.style.position = "absolute";
		e.style.zIndex = 1000;
		e.className = "popup";
		//INSERT POPUP INTO DOM
		n1 = document.body.firstChild;
		while (n1.nodeType != 1)
			n1 = n1.nextSibling;
		document.body.insertBefore(e, n1);
		popup = document.getElementById("HOVERPOPUP");
	}
	//DISPLAY
	if (popup.style.display == "none")
		popup.innerHTML = decodeURIComponent(unescape(content));
	popup.style.top = globalMouseY + 5 + "px";
	popup.style.left = globalMouseX + 5 + "px";
	popup.style.display = "block";
}
function hoverPopupHide()
{
	var popup = document.getElementById("HOVERPOPUP");
	if (popup != null)
		document.getElementById("HOVERPOPUP").style.display = "none";
}
//*****************************
//*****************************
function loginPopupShow(element)
{
	var popup = document.getElementById("LOGINPOPUP");
	if(popup == null)
	{
		//CREATE POPUP
		e = document.createElement("div");
		e.id = "LOGINPOPUP";
		e.style.display = "none";
		e.style.position = "absolute";
		e.style.top = "0px";
		e.style.left = "0px";
		e.style.zIndex = 1000;
		e.innerHTML = '\n\
			<table id="LOGINPOPUPWIDTH" width="1%" style="border-style:none; border-width:0px; border-spacing:0px 0px; border-collapse:collapse;">\n\
				<tr>\n\
					<td style="width:9px; height:40px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_TL.gif); background-repeat: no-repeat;">\n\
						<div style="width:9px; height:40px;">\n\
						</div>\n\
					</td>\n\
					<td valign="top" style="height:40px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_TM.gif); background-repeat: repeat-x;">\n\
						<table width="100%" style="height:36px;" >\n\
							<tr>\n\
								<td align="left">\n\
									<img src="/images/global/PopupGT/PopupGT_logo.gif" alt="GT" />\n\
								</td>\n\
								<td align="center">\n\
									<img src="/images/global/PopupGT/PopupGT_title.gif" alt="GameTracker" />\n\
								</td>\n\
								<td align="right">\n\
									<img id="LOGINPOPUPHIDE" style="cursor:pointer;" src="/images/global/PopupGT/PopupGT_close.gif" alt="Close" />\n\
								</td>\n\
							</tr>\n\
						</table>\n\
					</td>\n\
					<td style="width:9px; height:40px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_TR.gif); background-repeat: no-repeat;">\n\
						<div style="width:9px; height:40px;">\n\
						</div>\n\
					</td>\n\
				</tr>\n\
				<tr>\n\
					<td style="width:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_ML.gif); background-repeat: repeat-y;">\n\
					</td>\n\
					<td valign="center" style="background-color:#171B20;">\n\
						<div style="padding:10px; text-align:center;">\n\
							<form id="LOGINPOPUPFORM" method="POST">\n\
							<table align="center">\n\
								<tr>\n\
									<td align="right">\n\
										Username:&nbsp;&nbsp;\n\
									</td>\n\
									<td colspan="2">\n\
										<input id="LOGINPOPUPUSERNAME" type="text" class="text" style="width:140px;" name="username" value=""/>\n\
									</td>\n\
								</tr>\n\
								<tr>\n\
									<td align="right">\n\
										Password:&nbsp;&nbsp;\n\
									</td>\n\
									<td colspan="2">\n\
										<input id="LOGINPOPUPPASSWORD" type="password" class="text" style="width:140px;" name="password" value=""/>\n\
									</td>\n\
								</tr>\n\
								<tr>\n\
									<td align="left">\n\
										Remember&nbsp;Me:&nbsp;&nbsp;\n\
									</td>\n\
									<td align="left">\n\
										<input type="checkbox" name="cookieuser" value="1">\n\
									</td>\n\
									<td align="right">\n\
										<input type="image" class="button" name="loginfrompopup" value="submit" alt="Submit" src="/images/buttons/btn_login_sm.gif"/>\n\
									</td>\n\
								</tr>\n\
							</table>\n\
							</form>\n\
							<br/>\n\
							<a style="color:#fff200; text-decoration:none; cursor:pointer;" href="/account/create/">Need an account?</a> | <a style="color:#fff200; text-decoration:none; cursor:pointer;" href="/account/forgot_password/">Forgot Password?</a>\n\
						</div>\n\
					</td>\n\
					<td style="width:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_MR.gif); background-repeat: repeat-y;">\n\
					</td>\n\
				</tr>\n\
				<tr>\n\
					<td style="width:9px; height:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_BL.gif); background-repeat: no-repeat;">\n\
					</td>\n\
					<td style="height:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_BM.gif); background-repeat: repeat-x;">\n\
					</td>\n\
					<td style="width:9px; height:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_BR.gif); background-repeat: no-repeat;">\n\
					</td>\n\
				</tr>\n\
			</table>';
		//INSERT POPUP INTO DOM
		n1 = document.body.firstChild;
		while(n1.nodeType != 1)
			n1 = n1.nextSibling;
		document.body.insertBefore(e, n1);
		//BIND EVENTS TO POPUP
		$('#LOGINPOPUPHIDE').click(function(e)
		{
			document.getElementById("LOGINPOPUP").style.display = 'none';
		});
		$('#LOGINPOPUPPASSWORD').keyup(function(e)
		{
			if (e.keyCode == 13)
				document.getElementById('LOGINPOPUPFORM').submit();
		});
		$('#LOGINPOPUPUSERNAME').keyup(function(e)
		{
			if (e.keyCode == 13)
				document.getElementById('LOGINPOPUPFORM').submit();
		});
		popup = document.getElementById("LOGINPOPUP");
	}
	//POSITION
	var offset = $(element).offset();
	$('#LOGINPOPUP').css('top', offset.top);
	$('#LOGINPOPUP').css('left', offset.left);
	$('#LOGINPOPUP').css('display', 'block');
	$('#LOGINPOPUPUSERNAME').focus();
}
//*****************************
//*****************************
function GTPopupShow(element, content, halign, valign)
{
	var popup = document.getElementById("GTPOPUP");
	if (popup == null)
	{
		//CREATE POPUP
		e = document.createElement("div");
		e.id = "GTPOPUP";
		e.style.display = "none";
		e.style.position = "absolute";
		e.style.top = "0px";
		e.style.left = "0px";
		e.style.zIndex = 1000;
		e.style.color = "white";
		e.style.fontSize = "8pt";
		e.innerHTML = '\n\
			<table id="GTPOPUPWIDTH" width="1%" style="border-style:none; border-width:0px; border-spacing:0px 0px; border-collapse:collapse;">\n\
				<tr>\n\
					<td style="width:9px; height:40px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_TL.gif); background-repeat: no-repeat;">\n\
						&nbsp;&nbsp;&nbsp;\n\
					</td>\n\
					<td valign="top" style="height:40px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_TM.gif); background-repeat: repeat-x;">\n\
						<table width="100%" style="height:36px;" >\n\
							<tr>\n\
								<td align="left">\n\
									<img src="/images/global/PopupGT/PopupGT_logo.gif" alt="GT" />\n\
								</td>\n\
								<td align="center">\n\
									<img src="/images/global/PopupGT/PopupGT_title.gif" alt="GameTracker" />\n\
								</td>\n\
								<td align="right">\n\
									<img id="GTPOPUPCLOSE" style="cursor:pointer;" src="/images/global/PopupGT/PopupGT_close.gif" alt="Close" />\n\
								</td>\n\
							</tr>\n\
						</table>\n\
					</td>\n\
					<td style="width:9px; height:40px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_TR.gif); background-repeat: no-repeat;">\n\
						&nbsp;&nbsp;&nbsp;\n\
					</td>\n\
				</tr>\n\
				<tr>\n\
					<td style="width:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_ML.gif); background-repeat: repeat-y;">\n\
						&nbsp;\n\
					</td>\n\
					<td valign="center" style="background-color:#171B20;">\n\
						<div id="GTPOPUPCONTENT" style="padding:20px; text-align:center;">\n\
						</div>\n\
					</td>\n\
					<td style="width:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_MR.gif); background-repeat: repeat-y;">\n\
						&nbsp;\n\
					</td>\n\
				</tr>\n\
				<tr>\n\
					<td style="width:9px; height:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_BL.gif); background-repeat: no-repeat;">\n\
						&nbsp;\n\
					</td>\n\
					<td style="height:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_BM.gif); background-repeat: repeat-x;">\n\
						&nbsp;\n\
					</td>\n\
					<td style="width:9px; height:9px; overflow:hidden; padding:0px; margin:0px; background-image:url(/images/global/PopupGT/PopupGT_BR.gif); background-repeat: no-repeat;">\n\
						&nbsp;\n\
					</td>\n\
				</tr>\n\
			</table>';
		//INSERT POPUP INTO DOM
		n1 = document.body.firstChild;
		while(n1.nodeType != 1)
			n1 = n1.nextSibling;
		document.body.insertBefore(e, n1);
		//BIND EVENTS TO POPUP
		$("#GTPOPUPCLOSE").click(function(e)
		{
			$('#GTPOPUP').css('display', 'none');
		});
		popup = document.getElementById("GTPOPUP");
	}
	if (popup.style.display == "none")
		$('#GTPOPUPCONTENT').html(decodeURIComponent(content));
	//POSITION
	var offset = $(element).offset();
	$('#GTPOPUP').css('display', 'block');
	if (valign == 'top')
		$('#GTPOPUP').css('top', offset.top + $(element).height() - $('#GTPOPUPWIDTH').height());
	else if (valign == 'center')
		$('#GTPOPUP').css('top', offset.top + $(element).height() - ($('#GTPOPUPWIDTH').height()/2));
	else
		$('#GTPOPUP').css('top', offset.top);
	if (halign == 'left')
		$('#GTPOPUP').css('left', offset.left - $('#GTPOPUPWIDTH').width());
	else if (halign == 'center')
		$('#GTPOPUP').css('left', offset.left - ($('#GTPOPUPWIDTH').width()/2));
	else
		$('#GTPOPUP').css('left', offset.left + $(element).width());
};
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = {
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		//input = Base64._utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		//input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		//output = Base64._utf8_decode(output);
		return output;
	},
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}