function ConfirmDeleteChecked(formDelete, langQuestionTwo, langQuestionOne)
{
	var nrBoxes = 0;
	var nrSelected = 0;

	for (var i = 0; i < formDelete.length; i++)
	{
		var element = formDelete.elements[i];
		if (element.type == 'checkbox' && element.value == '1')
//		if (element.type == 'checkbox' && element.name == 'postId[]')
		{
			nrBoxes++;
			if (element.checked)
				nrSelected++;
		}
	}

	if (nrSelected == 0)
	{
		alert(langDelInstr);
		return false;
	}

	if (nrSelected == 1)
	{
		if (langQuestionOne == '')
			langQuestionOne = langQuestionTwo.replace('%d', '');
		return confirm(langQuestionOne);
	}

	return confirm(langQuestionTwo.replace('%d', nrSelected));
}

function SelectAll(thisCheckbox)
{
	if (thisCheckbox.checked)
	{
		for (var i = 0; i < thisCheckbox.form.length; i++)
		{
			var element = thisCheckbox.form.elements[i];
			if (element.type == 'checkbox' && element.value == '1')
				element.checked = true;
		}
	}
	else
	{
		for (var i = 0; i < thisCheckbox.form.length; i++)
		{
			var element = thisCheckbox.form.elements[i];
			if (element.type == 'checkbox' && element.value == '1')
				element.checked = false;
		}
	}
}

function PreviewBeforeUpload(strImgId, objFileinput, strOriginal)
{
	// most browsers are too paranoid for this to work. but it works in MSIE.

	// try 3 different methods for maximum compatibility
	var imageobject = false;
	if (document.getElementById) // modern standard
		imageobject = document.getElementById(strImgId);
	else if (document.all) // older microsoft internet explorer
		imageobject = document.all[strImgId];
	else if (document.images)
		imageobject = document.images[strImgId];

	if (imageobject && objFileinput)
	{
		if (objFileinput.value)
			imageobject.src = objFileinput.value;
		else if (strOriginal)
			imageobject.src = strOriginal;
	}
}

String.prototype.trim=function()
{
    return this.replace(/^\s*|\s*$/g,'');
}

function InsertText(text)
{
	// thanks to David Mårtensson @ gamer.se
	if (document.composeform.message.createTextRange)
	{
		document.composeform.message.focus();
		document.selection.createRange().duplicate().text = text;
	}
	else
	{
		document.composeform.message.value += text;
		document.composeform.message.focus();
	}
}

function QuoteText(postId)
{
	if (document.getElementById)
	{
		var username = document.getElementById('a'+postId).firstChild.nodeValue;

		var text = getSel();
		if (!text)
		{
			var temp = document.getElementById('p'+postId);
			if (temp.innerText)
				text = temp.innerText;
			else if (temp.innerHTML) // this feels more error-prone... i'm not sure what must be replaced
			{
				text = temp.innerHTML.replace(/<br>\n?/gi, "\n").replace(/<[^>]*>/gi, '').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
				// replace(/<\/?[a-z]+>/gi, '')
//				alert ('before:'+temp.innerHTML + '\n\nafter:' + text);
			}
		}

		if (text)
			document.composeform.message.value += '<quote author="' + username + '">' + text.trim() + '</quote>';
	}
	return false;
}

// Thanks to Peter-Paul Koch
// http://www.quirksmode.org/js/selected.html
function getSel()
{
	var txt = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
	}
	return txt.toString(); // otherwise mozilla returns an Object
}
