var arrInput = new Array(0);
var arrInputValue = new Array(0);

function UbbCode(strCode, ptrForm, strAlert)
{
	strText = prompt(strAlert);

	strText = '[' + strCode + ']' + strText + '[/' + strCode + ']';
	InsertTextAtCursor(ptrForm, strText);
}

function UbbLinkCode(ptrForm)
{
	strUrl = prompt('Geeft het adres op.');
	strAlt = prompt('Geef de alternatieve tekst op.\nKlik op Annuleren om geen alternatieve tekst in te geven.');

	if((strAlt == null) || (strAlt == ''))
		strText = '[url]' + strUrl + '[/url]';

	else
		strText = '[url=\'' + strUrl + '\']' + strAlt + '[/url]';

	InsertTextAtCursor(ptrForm, strText);
}


function UbbImgCode(ptrForm)
{
	strImage = prompt('Geeft de lokatie van het plaatje.');
	iWidth = prompt('Geeft de breedte.\nKlik op annueren om de standaard breedte aan te houden.');
	iHeight = prompt('Geeft de hoogte.\nKlik op annueren om de standaard hoogte aan te houden.');
	strAlt = prompt('Geeft de alternatieve tekst op.\nKlik op annuleren om de standaard tekst aan te houden.');
	strText = '[img';

	if((iWidth != null) && (iWidth != ''))
		strText += ' width=' + iWidth;

	if((iHeight != null) && (iHeight != ''))
		strText += ' height=' + iHeight;

	if((strAlt != null) && (strAlt != ''))
		strText += ' alt=' + strAlt;

	strText += ']' + strImage + '[/img]';
	InsertTextAtCursor(ptrForm, strText);

}

function UbbTextCode(ptrForm)
{
	iSize = prompt('Geeft de groote van de tekst.\nKlik op annuleren om de standaard groote aan te houden.');
	strColor = prompt('Geeft de kleur van de tekst.\nKlik op annuleren om de standaard kleur aan te houden.');
	strPos = prompt('Geeft de positie (left, middle, right) van de tekst.\nKlik op annuleren om de standaard positie aan te houden.');
	strContent = prompt('Geeft de tekst op die opgemaakt moet worden.');

	if((strContent == null) || (strContent == ''))
		return ;

	strText = '';
	if((iSize != null) && (iSize != ''))
		strText += ' size=' + iSize;

	if((strColor != null) && (strColor != ''))
		strText += ' color=' + strColor;

	if((strPos != null) && (strPos != ''))
		strText += ' pos=' + strPos;

	if(strText == '')
		InsertTextAtCursor(strContent);

	else
	{
		strText = '[text' + strText + ']' + strContent + '[/text]';
		InsertTextAtCursor(ptrForm, strText);
	}

}

function UbbList(ptrForm)
{
	arrValues = new Array(0);
	strValue = '';

	bDone = 0;

	while(bDone == 0)
	{
		strTmp = prompt('Geef de volgende optie op (enter/annuleren voor afsluiten).');

		if((strTmp == '') || (strTmp == null))
			bDone = 1;

		else
			arrValues[arrValues.length] = strTmp;
	}

	if(arrValues.length > 0)
	{
		strValue += '[list]';

		for(i=0; i<arrValues.length; i++)
			strValue += '[li]' + arrValues[i] + '[/li]';

		strValue += '[/list]';
		InsertTextAtCursor(ptrForm, strValue);
	}
}

function InsertTextAtCursor(ptrForm, strText)
{
	if (document.selection)
	{
		ptrForm.focus();
		sel = document.selection.createRange();
		sel.text = strText;
	}
	//MOZILLA/NETSCAPE support
	else if((ptrForm.selectionStart) || (ptrForm.selectionStart == '0'))
	{
		var startPos = ptrForm.selectionStart;
		var endPos = ptrForm.selectionEnd;
		ptrForm.value = ptrForm.value.substring(0, startPos) + strText + ptrForm.value.substring(endPos, ptrForm.value.length);
		SetTextCursorPos(ptrForm, startPos + strText.length);
	}
	else
	{
		ptrForm.value += strText;
		SetTextCursorPos(ptrForm.value.length + strText.length);
	}
}

function SetTextCursorPos(ptrForm, iPos)
{
	if(ptrForm.createTextRange)
	{
		var range = ptrForm.createTextRange();
		range.move('character', iPos);
		range.select();
	}
	else if(ptrForm.selectionStart)
	{
		ptrForm.focus();
		ptrForm.setSelectionRange(iPos, iPos);
	}
}




function UbbSMilie(strSmilie, ptrForm)
{
	InsertTextAtCursor(ptrForm, strSmilie);
}




function addInput()
{
	if(arrInput.length < 10)
	{
		arrInput.push(arrInput.length);
		arrInputValue.push("");
		display();
	}
}

function display()
{
	document.getElementById('parah').innerHTML="";
	for (intI=0;intI<arrInput.length;intI++)
		document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);

}

function saveValue(intId,strValue)
{
	arrInputValue[intId]=strValue;
}

function strrpos(strText)
{

}

function addUbb(iId)
{
	for(i=arrInputValue[iId].length; i>=0; i--)
	{
		if(arrInputValue[iId][i] == '/')
		{
			i++;
			InsertTextAtCursor(document.myform.body, '{' + arrInputValue[iId].substr(i, (arrInputValue[iId].length - i)) + '}');
			i = -1;
		}
	}

}

function addUbb1(strCode)
{
	InsertTextAtCursor(document.myform.body, '{' + strCode + '}');
}

function createInput(id,value)
{
	return '<input type="file" name="attachements[]" id="test '+ id +'" value="' + value + '" onChange="javascript:saveValue(' + id + ',this.value)"/> <a href="javascript:addUbb(' + id + ')">Code</a><br/>';
}

function deleteInput()
{
	if (arrInput.length > 0)
	{
		arrInput.pop();
		arrInputValue.pop();
	}
	display();
}



function switch_div(from, other)
{
	obj_from = document.getElementById(from);
	obj_other = document.getElementById(other);
	
	if(obj_from != null)
	{
		if(obj_from.style.display == 'none')
		{
			obj_from.style.display = 'block';
		}
		else
		{
			obj_from.style.display = 'none';
		}
	}
	
	if(obj_other != null)
	{
		if(obj_other.innerHTML.substr(0, 1) == '+')
		{
			obj_other.innerHTML = '-' + obj_other.innerHTML.substr(1, obj_other.innerHTML.length - 1);
		}
		else
		{
			obj_other.innerHTML = '+' + obj_other.innerHTML.substr(1, obj_other.innerHTML.length - 1);
		}
	}
	
	return false;
}

function tooltip_find_pos_x(obj) 
{
	var curleft = 0;
	if (obj.offsetParent) 
	{
		while (obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	
	return curleft;
}



function tooltip_find_pos_y(obj) 
{
	var curtop = 0;
	if (obj.offsetParent) 
	{
		while (obj.offsetParent) 
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

function tooltip_show(tooltipId, parentId, posX, posY)
{
	it = document.getElementById(tooltipId);
	

	if ((it.style.top == '' || it.style.top == 0) && (it.style.left == '' || it.style.left == 0))
	{
		if(navigator.appName == 'Microsoft Internet Explorer')
		{
			it.style.width = it.offsetWidth + 'px';
			it.style.height = it.offsetHeight + 'px';
		}
		else
		{
			it.style.width = it.offsetWidth + 'px';
			it.style.height = (it.offsetHeight - 8) + 'px';
		}
	}
	
		img = document.getElementById(parentId.id); 
		
		// if tooltip is too wide, shift left to be within parent 
		if (posX + it.offsetWidth > img.offsetWidth)
		{
			posX = img.offsetWidth - it.offsetWidth;
		}
		
		if (posX < 0 )
		{
			posX = 0; 
		}
		
		
		x = tooltip_find_pos_x(img) + posX;
		y = tooltip_find_pos_y(img) + posY;
		
		x += 10;
		it.style.top = y + 'px';
		it.style.left = x + 'px';
	
	
	it.style.visibility = 'visible'; 
}

function tooltip_hide(id)
{
    it = document.getElementById(id); 
    it.style.visibility = 'hidden'; 
}

function change_profile_extended()
{
	obj = document.getElementById('extended');
	link = document.getElementById('profile_extended_link');

	if(obj != null)
	{
		if(obj.style.display == 'none')
		{
			obj.style.display = 'block';
			link.innerHTML = 'Simpel';
		}
		else
		{
			obj.style.display = 'none';
			link.innerHTML = 'Uitgebreid';
		}
	}
}