var chatWindow;
		
function openChat(visid,action)
{
	if(!chatWindow || chatWindow.closed)
	{
		var url	= "index.php?pageID=194&visid=" + visid + "&action=" + action;
		chatWindow = window.open('','privatechat','height=450,width=720');
		if(chatWindow.location.href.indexOf('index.php') == -1)	chatWindow.location.replace(url);
		else chatWindow.changeAction(action, visid);
	} 
	else 
	{
		chatWindow.changeAction(action, visid);
	}
	if (!chatWindow.opener)	chatWindow.opener = self;
	chatWindow.focus();
}

function openChatNew(data)
{
	if(!chatWindow || chatWindow.closed) {
		var url	= "index.php?pageID=194&visid=" + data[0] + "&action=" + data[1];
		var windowSettings = 'height=' + data[3] + ',width=' + data[2];
		chatWindow = window.open('','privatechat',windowSettings);
		if(chatWindow.location.href.indexOf('index.php') == -1)	chatWindow.location.replace(url);
		else chatWindow.openRoom(data[0]); //calling flash function open room
	} else {
		chatWindow.openRoom(data[0]); //see aquarium.php
	}	
	if (!chatWindow.opener)	chatWindow.opener = self;
	chatWindow.focus();
}

function callChat(memberID,chatAction,chatWidth,chatHeight)
{
	var data = new Array(memberID,chatAction,chatWidth,chatHeight);
	openChatNew(data);
}

// create the prototype on the String object

String.prototype.trim = function() {

 // skip leading and trailing whitespace
 // and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

// Functies voor flessenpost
// check
function SelectCheckbox (inputObject)
{
	formObject = inputObject.form;
	if (formObject)
	{
		for (i=0;i<formObject.elements.length;i++)
		{
			element = formObject.elements[i];
			element.checked = inputObject.checked;
		}
	}
}

// flessenpost
function windowpopup(naamurl,breedte,hoogte,scrollbar)
{
	window.open(naamurl,"_blank","width=" + breedte + ", height=" + hoogte + ",scrollbars=" + scrollbar + "");
}

// flessenpost
function centerwindow (breedte, hoogte)
{
	var Ycor=((screen.height-hoogte)/2);
	var Xcor=((screen.width-breedte)/2);
	window.moveTo(Xcor, Ycor);
}


// functions inc
function ShowSmilies (fieldObject, fieldName)
{
	var smiliesObject = document.getElementById ('functionSmilies' + fieldName);
	if (smiliesObject)
	{
		smiliesObject.style.display = 'block';
	}
}

// functions inc
function HideSmilies (fieldName)
{
	var smiliesObject = document.getElementById ('functionSmilies' + fieldName);
	if (smiliesObject)
	{
		smiliesObject.style.display = 'none';
	}
}

// functions inc
function InsertText (fieldName, content)
{
	var textObject = document.getElementById (fieldName);
	if (textObject)
	{
		cursorPosition = GetCursorPosition (textObject);
		var firstPart = textObject.value.substring (0, cursorPosition);
		var secondPart = textObject.value.substring (cursorPosition, textObject.value.length);
		textObject.value = firstPart + content + secondPart;
	}
}

// functions inc
function ShowSmallProfile (fieldName)
{
	var smallProfileObject = document.getElementById ('functionSmallProfile' + fieldName);
	var smallProfileContainerObject = document.getElementById ('functionSmallProfileContainer' + fieldName);
	if (smallProfileObject && smallProfileContainerObject)
	{
		if (smallProfileObject.style.display == 'none')
		{
			smallProfileObject.style.display = 'block';
			smallProfileContainerObject.style.zIndex = 100;
		}
		else
		{
			smallProfileObject.style.display = 'none';
			smallProfileContainerObject.style.zIndex = 1;
		}
	}
}

// functions inc
function HideSmallProfile (fieldName)
{
	var smallProfileObject = document.getElementById ('functionSmallProfile' + fieldName);
	var smallProfileContainerObject = document.getElementById ('functionSmallProfileContainer' + fieldName);
	if (smallProfileObject && smallProfileContainerObject)
	{
		smallProfileObject.style.display = 'none';
		smallProfileContainerObject.style.zIndex = 1;
	}
}


// fb - twt labels
function labels (h, w, count) {
	var minheight = (count > 1) ? (count * 180) : 180;
	if (h <= minheight || w <= 1160) {
		$('#labelBar').hide();
	} else {
		if ($('#labelBar').is(':hidden')) {$('#labelBar').show()};
	};
}

function chatOverlay (argString) { // memberID, chatWidth, chatHeight, name, languageID ()
	ar = argString.toString();
	args = ar.split(',');
	var content = "";
	var styleH = "style=\"font-weight: bold; font-size: 11pt; margin-bottom: 12px;\"";
	switch (args[4]) {
		default:
			content = "<div " + styleH + ">Je hebt een chat-uitnodiging ontvangen van " + args[3] + ".</div><div>Wil je met deze persoon chatten?</div><div style=\"margin-top: 12px;\"><input type=\"button\" value=\"Ja, graag\" id=\"accept\" class=\"buttonmenu\" onclick=\"callChat(" + args[0] + ",'invited'," + args[1] + "," + args[2] + "); CloseOverlay();\" />&nbsp;<input type=\"button\" class=\"buttonmenu\" value=\"Nee, dank je\" id=\"deny\" onclick=\"CloseOverlay();\" /></div><div style=\"margin-top: 20px;\">Let op: de chat verschijnt in een pop-up-scherm. Je pop-up-blokker kan om acceptatie vragen.</div>";
			break;
		
	}
	$('#overlayContainer').show();
	$('#popupOverlayContainer').css({'position':'fixed'}).show();
	$('#popupContainer').html(content);
}

function tabFocus(tabNr,tabTotal,tabName,divContentName) {
	if(divContentName == "") divContentName = "divProfileText";
	if(tabName == "") tabName = "tab";
	for(i = 1; i <= tabTotal; i++) {
		if(i == tabNr) {
			document.getElementById(tabName + i).style.background='#FFFFFF';
			document.getElementById(divContentName + i).style.visibility = 'visible';
		} else {
			document.getElementById(tabName + i).style.background='#DEDEDE';
			document.getElementById(divContentName + i).style.visibility='hidden';
		}	
	}
	return false;
}
