function goUser(id) { document.location.href = 'user.php?id=' + id; }
function goLoc(url) { document.location.href = url; return true; }
var mom = null
var fields = new Array('r_pic','pic','m_pic', 'v_pic');
function mumbledumble(id, hide, type) {
	if(typeof(mumbledisplay) !== 'boolean' || mumbledisplay !== true) {
		type = fields[type];
		window.clearTimeout(mom);
		pic = id.substr(0, 36);
		mid = id.substr(36);
		if(!hide) {
			document.getElementById(type + ':' + mid).style.display = 'none';
		} else {
			document.getElementById(type + ':' + mid).style.display = '';
			document.getElementById(type + ':' + mid).childNodes[0].childNodes[0].childNodes[0].src = './user_img/' + pic.substr(34, 2) + '/' + pic.substr(0, 34) + '.jpg';
		}
	}
}
function dumblemumble(id, type) { mom = window.setTimeout('mumbledumble(\''+id+'\', 1, '+type+')', 500); }
function trim(str) {
	return str.replace(/^\s*|\s*$/g,"");
}

function fixlimit(obj, id) {
	if(obj.value.length > lim) {
		obj.value = obj.value.substr(0, lim);
	}
	document.getElementById(id).innerHTML = lim - parseInt(obj.value.length);
}

function makeGb(id, more, w) {
	if(!more) more = '';
	if(!w) w = '476';
	ref = window.open('user_gb_write.php?id=' + id + more, 'GB_' + id, 'left='+((screen.availWidth - w)/2)+',top='+((screen.availHeight - 310)/2)+', resizable=0, status=no, width=' + w + ', height=310');
	ref.focus();
}
function makeChat(id) {
	ref = (window.opener)?window.opener.parent.comhead:parent.window.comhead;
	if(ref.popupArr['C_' + id] == null || ref.popupArr['C_' + id].closed) {
		ref.popupArr['C_' + id] = window.open('user_chat.php?id=' + id, 'C_' + id, 'left='+((screen.availWidth - 476)/2)+',top='+((screen.availHeight - 425)/2)+', resizable=0, status=no, width=476, height=425, location=yes');
		ref.popupArr['C_' + id].focus();
	} else
		ref.popupArr['C_' + id].focus();
}

function makePop(url, name, w, h, c, extra, opt) {
	if(!c) c = false;
	if(!extra) opt = 'resizable=0, status=no, ';
	if(!extra) extra = '';
	if(!w) w = 500;
	if(!h) h = 400;
	if(c) {
		l = (screen.availWidth - w)/2;
		t = (screen.availHeight - h)/2;
		opt = opt + 'left='+l+',top='+t+', ';
	}

	ref = window.open(url, name, opt + 'width='+w+', height='+h+extra);
	ref.focus();
}
function makeSmall(url) {
	makePop(url, '', 476, 310, 1, ',scrollbars=0', 'resizable=0, status=0, ');
	return false;
}
function makeBig(url) {
	makePop(url, '', 666, 520, 1, ',scrollbars=0', 'resizable=1, status=1, ');
	return false;
}
function fixRel() {
	if(parent.comhead && parent.comhead.gotHead) {
		if(parent.comhead.gotView) {
			parent.comhead.gotView = false;
			fetchRel();
		} else {
			parent.comhead.gotView = true;
			fetchRel();
		}
	}
}

function fetchRel() {
	str = '<table cellspacing="0" style="width: 160px;">';
	if(parent.comhead && parent.comhead.gotHead) {
		var array = parent.comhead.gotRel;
		if(parent.comhead.gotView) {
			if(array.length > 0) {
				for(i = 0; i < array.length; i++) {
					d = i + 1;
					var mS = array[i].substr(0, 32); // m
					var pS = array[i].substr(32, 2); // p
					var dS = array[i].substr(32 + 2, 2); // d
					var iC = array[i].substr(32 + 4, 2); // d
					var aL = new Number(array[i].substr(32 + 4 + 2, 2));
					var aS = array[i].substr(32 + 4 + 2 + 2, aL);
					var iS = array[i].substr(32 + 4 + 2 + 2 + aL, 3);
					var bB = array[i].substr(32 + 4 + 2 + 2 + aL + 3, 1);
					if(iC > 1) iC = '<img src="./_img/' + parseInt(iC) + '.gif" height="7" />&nbsp;'; else iC = '';
					if(bB == 1) iC = '<img src="./_img/icon_birth.gif" height="12" alt="Fyller år idag!" style="margin: 0 2px -1px 0;" />' + iC;
					str = str + ('<tr onmouseover="dumblemumble(\'' + mS + pS + dS + d + '\', 0, 0);" onmouseout="mumbledumble(\'' + mS + pS + dS + d + '\', 0, 0);"><td class="pdg_l spac"><div style="overflow: hidden; width: 150px;"><nobr><a href="user.php?id=' + mS + '" class="on bld" target="commain">' + unescape(aS) + '</a> ' + iS + '&nbsp;' + iC + '<a class="cur" onclick="makeGb(\'' + mS + '\');" title="Skriv GB-inlägg"><img src="_img/link_gb.gif" height="12" style="margin-bottom: -1px;"></a><a class="cur" onclick="makeChat(\'' + mS + '\');" title="Öppna privatchat"><img src="_img/link_cha.gif" height="12" style="margin: 0 0 -1px 3px;"></a></nobr></div></td></tr>');
					str = str + ('<tr id="r_pic:' + d + '" style="display: none;"><td colspan="2" style="padding-left: 5px;"><a><img onerror="this.parentNode.parentNode.id = \'xxx\'; this.parentNode.parentNode.style.display = \'none\';"></a></td></tr>');
					if(i > 8) {
						str = str + '<tr><td colspan="2" class="pdg_l spac">Endast de 10 första visas...</td></tr>';
						break;
					}
				}
			} else {
				str = str + ('<tr><td class="pdg_l spac">Inga vänner online.</td></tr>');
			}
		}
	} else {
		str = str + ('<tr><td class="pdg_l spac">Inga vänner online.</td></tr>');
	}
	str = str + '</table>';
	document.getElementById('RelCount').innerHTML = (parent.comhead && parent.comhead.gotRelC)?parent.comhead.gotRelC:0;
	document.getElementById('RelList').innerHTML = str;
}

function toggleInp(obj, text, blur_text) {
	if(text.length > 0 && obj.value == text) obj.value = '';
	else if(blur_text.length > 0 && obj.value == text) obj.value = blur_text;
}
