
function bg(s, z) {

	if (!z) z = '1';

	var el = document.getElementById('bgcover');

	var display = 'none';
	var hideTrouble = false;
	var bodyoverflow = 'scroll';

	if (s) {
		var bodyoverflow = 'hidden';
		display = 'inline';
		var hideTrouble = true;
	}

	hideTroubleElements(hideTrouble);

	document.body.style.overflow = bodyoverflow;

	el.style.display = display;
	el.style.zIndex = z;

}

function content(title, html, ww, wh, z, bgz, right) {

	elcontent = document.getElementById('content');
	eltitle = document.getElementById('content-title');
	elright = document.getElementById('content-right');
	elinner = document.getElementById('content-inner');

	if (title && html) {

		window.scrollTo(0,0);

		bg(1, bgz);

		bgzoff = '';
		if (bgz) bgzoff = 1;

		sw = document.body.offsetWidth;
		sh = document.body.offsetHeight;

		if (!z) z = '1';
		if (!ww) ww = 550;
		if (!wh) wh = 300;

		ww = parseInt(ww);
		wh = parseInt(wh);

		mw = ww + 50;
		mh = wh + 70;

		if (sw < mw) {
			ww = sw - 50;
		}
		if (sh < mh) {
			wh = sh - 70;
		}

		vm = wh / 2;
		hm = ww / 2;

		vm = vm + 20;
		hm = hm + 5;

		elcontent.style.zIndex = z;
		elcontent.style.width = ww + 'px';
		elcontent.style.height = wh + 'px';
		elcontent.style.margin = '-' + vm + 'px 0 0 -' + hm + 'px';

		if (!right) {
			closefunc = 'content()';
			right = '<a href="javascript:' + closefunc + '" onFocus="this.blur()" onMouseOver="return hideStatus()"><img src=http://www.mypersonality.info/images/modal-close.png width=25 height=25 alt="Close" border=0></a>';
		}
		eltitle.innerHTML = title;
		elright.innerHTML = right;
		elinner.innerHTML = '<div style="padding:12 12 12 12">' + html + '</div>';

		elinner.style.width = ww + 'px';
		elinner.style.height = wh + 'px';
		setTimeout("elinner.style.overflow = 'auto'", 1000);

		elcontent.style.display='block';

	}

	else {

		onoff = 0;
		if (bgz) onoff = 1;

		elcontent.style.display='none';
		bg(onoff, bgz);
		loading(0);
		eltitle.innerHTML = '';
		elinner.innerHTML = '';
		elright.innerHTML = '';
		elinner.style.overflow = 'hidden';

	}

}

document.onkeyup = keyCheck;       
function keyCheck(e) {

	var KeyID = (window.event) ? event.keyCode : e.keyCode;

	// close modal on (esc)
	if (KeyID == 27) content();

}

function hideTroubleElements(hide) {
	var s = 'visible';
	if (hide == true) s = 'hidden';
	if (navigator.appName.indexOf("MSIE")) {
		for (i = 0; i < document.forms.length; i++) {
			for (i2 = 0; i2 < document.forms[i].length; i2++) {
				if (document.forms[i].elements[i2].options) {
					document.forms[i].elements[i2].style.visibility = s;
				}
			}
		}
	}
}


function loading(on) {

	el = document.getElementById('loading');

	if (el) {

		if (on) {
	
			var html = '<div><img src=/images/ajax-loader.gif><br>Loading</div>';
			var ww = 90;
			var wh = 60;
		
			window.scrollTo(0,0);
		
			bg(1);
		
			sw = document.body.offsetWidth;
			sh = document.body.offsetHeight;
		
			z = '1';
		
			mw = ww + 50;
			mh = wh + 70;
		
			if (sw < mw) {
				ww = sw - 50;
			}
			if (sh < mh) {
				wh = sh - 70;
			}
		
			vm = wh / 2;
			hm = ww / 2;
		
			vm = vm + 10;
			hm = hm + 5;
		
			el.style.zIndex = z;
			el.style.width = ww + 'px';
			el.style.height = wh + 'px';
			el.style.margin = '-' + vm + 'px 0 0 -' + hm + 'px';
		
			el.innerHTML = '<div style="padding:14 14 14 10">' + html + '</div>';
		
			el.style.display='block';
	
		}
	
		else {
	
			el.style.display='none';
			bg(0);
	
		}

	}

}