function get_top_left(width, height){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
	  		winW = window.innerWidth;
	  		winH = window.innerHeight;
	 		winL = window.screenX;
	 		winT = window.screenY;
	 	}else{
	 	//if (navigator.appName.indexOf("Microsoft")!=-1) {
	  		winW = document.body.offsetWidth;
	  		winH = document.body.offsetHeight;
	  		winL = window.screenLeft;
	  		winT = window.screenTop;
	 	}
	}
	
	var scroll = 0;
	var l = winL + winW/2 - width/2;
	var t = winT + winH/2 - height/2;
	
	
  	if(screen.width <= width){
  		width=screen.width;
  	}
  	if(screen.height <= height){
  		height=screen.height;
 	 	var t = 0;
  		var scroll = 1;
  	}
	return Array(t,l);
}

/* generic window opener */
function openwin(uri,title,w,h){
	if(w){wwidth = w;}else{	wwidth = 380;}
	if(h){wheight = h; }else{ wheight = 380;}
	xy = get_top_left(wwidth, wheight);
	wleft = xy[1];
	wtop = xy[0];
	wnd = window.open(uri, title, "width="+wwidth+", height="+wheight+", left="+wleft+", top="+wtop+", toolbar=no, location=no, scrollbars=yes, status=no, menubar=no, resizable=no, directories=no");
}


/* set cookie */
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

/* get cookie */
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/* delete cookie */
function deleteCookie( name, path, domain ) {
	if ( getCookie(name) ) 
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}




/* toolbox */
var text_sizes		= [12, 14, 16];
var line_heights	= [1.4, 1.5, 1.6];

var def_text_size = 0;
var def_line_height = 0;


function change_line_height() {
	current_lh = getCookie('line_height');
	if (!current_lh) current_lh = 0;
	current_lh ++;
	if (current_lh == line_heights.length) current_lh = 0;
	if (current_lh != 0) {
		setCookie('line_height', current_lh);
	} else {
		deleteCookie('line_height');
		current_lh = def_line_height;
	}
	if (document.getElementById('content')) {
		document.getElementById('content').style.lineHeight = line_heights[current_lh] + "em";
	} else {
		document.getElementById('mainblock').style.lineHeight = line_heights[current_lh] + "em";
	}
}

function change_text_size() {
	current_ts = getCookie('text_size');
	if (!current_ts) current_ts = 0;
	current_ts ++;
	if (current_ts == text_sizes.length) current_ts = 0;
	if (current_ts != 0) {
		setCookie('text_size', current_ts);
	} else {
		deleteCookie('text_size');
		current_ts = def_text_size;
	}
	if (document.getElementById('content')) {
		document.getElementById('content').style.fontSize = text_sizes[current_ts] + 'px';
	} else {
		document.getElementById('mainblock').style.fontSize = text_sizes[current_ts] + 'px';
	}
}

function init_text_properties() {
	current_text_size = getCookie('text_size');
	current_line_height = getCookie('line_height');
	
	if (current_text_size) {
		document.getElementById('content').style.fontSize = text_sizes[current_text_size] + "px";
	}	
	if (current_line_height) {
		document.getElementById('content').style.lineHeight = line_heights[current_line_height] + "em";
	}
	
}




function xLoadMinimalFlash(width, height, moviePath, bgcolor) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id="flashAnimation" align="middle">\n');
	document.write('\t<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('\t<param name="movie" value="' + moviePath + '" />\n');
	document.write('\t<param name="menu" value="false"/>\n');
	document.write('\t<param name="quality" value="high" />\n');
	if (bgcolor == 'transparent') {
		document.write('\t<param name="wmode" value="' + bgcolor + '" />\n');
	} else {
		document.write('\t<param name="bgcolor" value="' + bgcolor + '" />\n');
	}
	document.write('\t<param name="width" value="' + width + '" />\n');
	document.write('\t<param name="height" value="' + height + '" />\n');
	if (bgcolor == 'transparent') {
		document.write('\t<embed src="' + moviePath + '" menu="false" quality="high" wmode="' + bgcolor + '" width="' + width + '" height="' + height + '" name="flashAnimation" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');	
	} else {
		document.write('\t<embed src="' + moviePath + '" menu="false" quality="high" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" name="flashAnimation" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
	}
	document.write('</object>\n');
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function reposition(w, h) {
	var page_sizes = getPageSize();
	var page_scroll = getPageScroll();
	
	/* shade */
	var backg = document.getElementById('popover_background');
	backg.style.width = '100%';
	backg.style.height = page_sizes[1] + 'px';
	
	
	/*content*/
	var popover = document.getElementById('popover');
	popover.style.width = w + 'px';	
	popover.style.height = h + 'px';
	
	var pos_x = (page_sizes[0] - w - 20) / 2;
	var pos_y = page_scroll[1] + ((page_sizes[3] - 35 - h) / 2);
	
	popover.style.top = (pos_y < 0) ? "0px" : pos_y + "px";
	popover.style.left = (pos_x < 0) ? "0px" : pos_x + "px";
	
}

function popover_open() {

	var page_sizes = getPageSize();
	var page_scroll = getPageScroll();
	
	w = 600;
	h = 458;
	
	var backg = document.getElementById('popover_background');
	var popover = document.getElementById('popover');
	
	var banner = document.getElementById('pikaboo');
	banner.style.display = 'none';
	
	reposition(w,h);

	backg.style.display   = 'block';
	
	var ifr = document.getElementById('avb');
	ifr.src = "avatarbuilder.php";
	ifr.style.width = w + 'px';
	ifr.style.height = h + 'px';
	
	popover.style.display = 'block';
	
	window.onresize = function() {
		reposition(w, h);
	}

	backg.onclick = function() {
		popover_close();
		window.onresize = function(){}
	}

	reposition(w, h);
	
	
	
}

function write_swf(filename,id,width,height,extra) {
	document.write('<object type="application/x-shockwave-flash" data="'+filename+(id!=null?'?cid='+id:'')+'" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+filename+(id!=null?'?cid='+id:'')+'" />');
	
	document.write('<param name="quality" value="autohigh" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="kupon" value="false" />');
	

	for (i in extra) {
			document.write('<param name="'+extra[i][0]+'" value="'+extra[i][1]+'" />');
	}
	document.write('</object>');
}


/* FAQ display answer toggle */

function toggle_display(id) {
	var element_ID = "answer_"+id;
	if(document.getElementById(element_ID).style.display == "block") {
		document.getElementById(element_ID).style.display = "none";
	} else {
		document.getElementById(element_ID).style.display = "block";
	}
}


