var lastInput = 0;
	
function addAttachementInput()
{
	parent = document.getElementById('attachement_parent');
	
	divId = 'attachement_input_' + lastInput;
	newDiv = document.createElement('div');
	newDiv.setAttribute('id', divId);
	newDiv.innerHTML = '<input type="file" name="attachement[]"/> <a href="#" onclick="removeAttachementInput(\'' + divId + '\'); return false;">remove</a>';
	
	parent.appendChild(newDiv);
	lastInput++;
	
	
}

function removeAttachementInput(divId)
{
	parent = document.getElementById('attachement_parent');
	parent.removeChild(document.getElementById(divId));
}

function removeDiv(divId)
{
	parent = document.getElementById('attachment_anotherparent');
	parent.removeChild(document.getElementById(divId));
}

function removeAttachement(id)
{
	divId = 'existing_attachement_' + id;
	doHttpRequest('/attachement/remove/id:' + id, function(content) { if(content == 'ok'){ removeDiv(divId); } else { alert(content); } });
}

/*
function copyToClipboard(s)
{
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", s);
	}
	else
	{
		// You have to sign the code to enable this or allow the action in about:config by changing
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);	   
	}
}*/


function insertTextAtCursor(strText)
{
	ptrForm = document.getElementById('body');
	
	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 doHttpRequest(page, func)
{
	var xmlhttp;
	
	try
	{
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');   
	}
	catch (e) 
	{
		try 
		{
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');    
		}
		catch (e2) 
		{
			try 
			{  
				xmlhttp = new XMLHttpRequest();     
			}
			catch (e3) 
			{  
				xmlhttp = false;   
			}
		}
	}
	
	xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if(typeof func == 'function') { func(xmlhttp.responseText); } } };
	xmlhttp.open('GET', page,  true); 
	xmlhttp.send(null); 

}