
	/*
	+----------------------------------------------------------------
	|
	|	MJGUEST
	|	=============================================================
	|	Copyright (c) 2002-2005 Giacomo "mdsjack" Menni
	|	Terms of agreement and support at www.mdsjack.bo.it
	|
	+----------------------------------------------------------------
	|	[ INTERFACE MODULE ]
	|	Javascript global functions
	+----------------------------------------------------------------
	*/

function include(filename) // PHP include() emulation
{
	var js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', filename);
	js.setAttribute('defer', 'defer');
	document.getElementsByTagName('HEAD')[0].appendChild(js);
}

function trim(str) // PHP trim() emulation
{
	str = str.replace(/&nbsp;$/g, ' ');
	str = str.replace(/^\s*|\s*$/g, '');
	return str;
}

function base64_decode(input) // PHP base64_decode() emulation
{
	try {
		return atob(input);
		
	} catch (e) {
		
		var output = '';
		var keyStr =
			'ABCDEFGHIJKLMNOP' +
			'QRSTUVWXYZabcdef' +
			'ghijklmnopqrstuv' +
			'wxyz0123456789+/' +
			'=';
		
		var chr1, chr2, chr3 = '';
		var enc1, enc2, enc3, enc4 = '';
		var i = 0;
		
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
	
		do
		{
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = 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);
		
		chr1 = chr2 = chr3 = '';
		enc1 = enc2 = enc3 = enc4 = '';
	
		} while (i < input.length);
	
		return output;
	}
}

function getElementByInputType(type) // Get the first Input field of a certain Type
{
	if(document.getElementsByTagName)
		for(i=0; i<document.getElementsByTagName('INPUT').length; i++)
			if(document.getElementsByTagName('INPUT')[i].getAttribute('type') == type)
				return document.getElementsByTagName('INPUT')[i];
}

function addLoadEvent(func) // Copyright (c) Simon Willison, Yahoo co-worker and developer. <http://simon.incutio.com>
{
	var oldonload = window.onload;
	
	if (typeof window.onload != 'function')
		window.onload = func;
	else
		window.onload = function()
		{
			oldonload();
			func();
		}
}

function auto_selection(selectfield, value) // Automatically select an option if there is none by default
{
	
	if (selectfield.options[selectfield.selectedIndex].defaultSelected == true)
		return;
	
	for (id = 0; id < selectfield.options.length; id++)
	{
		if (selectfield.options[id].value == value)
		{
			selectfield.options[id].selected = true;
			break;
		}
	}
}

function force_selection(selectfield) // Keep selected the default-selected option or the given param value
{
	if (selectfield.options[selectfield.selectedIndex].defaultSelected == false)
	{
		for (id = 0; id < selectfield.options.length; id++)
		{
			if (selectfield.options[id].defaultSelected == true)
			{
				selectfield.options[id].selected = true;
				selectfield.blur();
				break;
			}
		}
	}
}

function confirm_check(field, message) // Ask user before checking a checkbox
{
	if (field.checked)
	{
		message += '\n\n' + say['confirm_proceed'];
		
		if (!confirm(message))
		{
			field.checked = false;
			field.blur();
		}
		else
		{
			field.checked = true;
			field.blur();
		}
	}
}

function progressbar(bar, runtime, redirect)
{
	var ProcessRunning;
	var loaded	= 0;
	var bar		= document.getElementById(bar).style;
	
	var load = function()
	{
		loaded++
		
		if(loaded >= 100)
		{
			bar.width = 'auto';
			self.location.href = redirect;
			clearInterval(ProcessRunning);
			return false;
		}
		
		bar.width = loaded + '%';
		
		return true;
	}
	
	ProcessRunning = setInterval(load, runtime * 10);
}

function surfto(url) // Open external link in a new window, if allowed
{
	if (url == 0)
		alert(say['urls_not_allowed']);
	else
	{
		link = window.open(url, 'external_window');
		link.focus();
	}
	
	return false;
}
/*
function visible(obj, gradient) // Object visibility
{
	if (gradient == 0)
		obj.style.display = 'none';
	
	else if(gradient)
	{
		obj.style.opacity = gradient/100;
		obj.style.filter = 'alpha(opacity=' + gradient + ')'
	}
}
*/

function go(where) // Jump to prev/next guestbook page
{
	location.href = where;	
}

function loadset(from, where) // Jump to prev/next guestbook page
{
	if(!from) void(0);
	
	else location.href = 'mjguest.php?do=read&from=' + from + '#' + where;	
}

function mailto(email) // Decode anti-spam filter and launch email client
{
	email	= base64_decode(email);
	email	= email.replace(/_DOT_/g, '\.');	// compatible with 5HP Series
	email	= email.replace(/_AT_/g,'\@');		// compatible with 5HP Series
	location.href = 'mailto:' + email;
}

function homepage(url) // Open and show the guest's homepage in a new window
{
	userhome = window.open(url, 'mjguest_user_webpage');
	userhome.focus();
}

function sendpager(chat, uin) // Launch the selected instant messenger and contact the user
{
	switch(chat)
	{
		case 'icq':
			location.href = 'http://www.icq.com/whitepages/cmd.php?uin=' + uin + '&action=message';
		break;
		case 'aim':
			location.href = 'aim:goim?screenname=' + uin + '';
		break;
		case 'yim':
			location.href = 'ymsgr:sendim?' + uin + '';
		break;
		case 'skp':
			location.href = 'skype:' + uin + '?chat';
		break;
		case 'msn':
			MsgrObj.classid = 'clsid:B69003B3-C55E-4B48-836C-BC5946FC3B28';
			window.onerror = function (msg, url, h)
			{
				if (msg.indexOf('8100031e') != '-1')
					return true;
				else
					return false;
			};
			
			if(MsgrObj.MyStatus == 1) return false;
			else MsgrObj.InstantMessage(uin);
		break;
	}
}

eval( base64_decode('dG9wLmRvY3VtZW50LnRpdGxlICs9ICgodG9wICE9IHNlbGYpID8gIiAtIEd1ZXN0Ym9vayIgOiAiIikgKyAiIChNSkdVRVNUIKkgd3d3Lm1kc2phY2suYm8uaXQpIjs=') );