
var obj;

function OpenWysiwygEditor( elementID )
{
	parameters = new String();
	parameters = "'resizable=no, toolbar=no, location=no, directories=no, status=no, menubar=no, copyhistory=no, width=570, height=360'";	
	var scherm = window.open('/birth/pages/body/WysiwygBody.jsp', 'Editor', parameters);		
	
	var obj = document.getElementById( elementID );	
}

function OpenAddImage()
{
	parameters = new String();
	parameters = "'resizable=no, toolbar=no, location=no, directories=no, status=no, menubar=no, copyhistory=no, width=250, height=350'";	
	var scherm = window.open('/birth/pages/body/imageAddBody.jsp', 'Select image', parameters);			
}

function SetSelectedText( elementID, func, image, keyframe, url)
{	
	var obj = getBackField('rte1');	

	if( !obj ) {
		throw "Element " + elementID + " not found!";
	}
		
	// Netscape, Mozilla, Firefox
	if(obj.contentWindow) {		
		
		var selection = obj.contentWindow.getSelection(); 		
		var selText = selection.getRangeAt(selection.rangeCount - 1).toString();
		var newText = '';
		
		selection.getRangeAt(selection.rangeCount - 1).deleteContents();		
		
		if(func == '1')
		{
			newText = '<strong>' + selText + '</strong>';
			selection.getRangeAt(selection.rangeCount - 1).insertNode(document.createTextNode(newText));		
					
			updateRTE('rte1');
		}
		if(func == '2')
		{
			newText = '<i>' + selText + '</i>';		
			selection.getRangeAt(selection.rangeCount - 1).insertNode(document.createTextNode(newText));		
					
			updateRTE('rte1');
		}	
		if(func == '3')
		{
			newText = '<u>' + selText + '</u>';
			selection.getRangeAt(selection.rangeCount - 1).insertNode(document.createTextNode(newText));		
					
			updateRTE('rte1');
		}	
		if(func == '4')
		{		
			newText = selText + '#articlepage/#';
			selection.getRangeAt(selection.rangeCount - 1).insertNode(document.createTextNode(newText));		
					
			updateRTE('rte1');					
		}
		if(func == '5')
		{						
			newText = selText + '#articleimage#' + image + '#/articleimage#';
			selection.getRangeAt(selection.rangeCount - 1).insertNode(document.createTextNode(newText));		
					
			updateRTE('rte1');					
		}
		if(func == '6')
		{								
			newText = selText + '#audiovisual#' + image + '#' + keyframe + '#' + url + '#/audiovisual#';
			selection.getRangeAt(selection.rangeCount - 1).insertNode(document.createTextNode(newText));		
					
			updateRTE('rte1');				
		}			
	}

	// Internet Explorer
	else
	{			
		rteFocus('rte1');   //makes sure input will arrive in wysiwyg editor
		obj.caretPos = obj.selection.createRange().duplicate();
		var txt = obj.caretPos.text;	
					
		if(func == '1')
		{
			obj.caretPos.text = '<strong>' + txt + '</strong>';
			updateRTE('rte1');							
		}
		if(func == '2')
		{
			obj.caretPos.text = '<i>' + txt + '</i>';
			updateRTE('rte1');				
		}	
		if(func == '3')
		{
			obj.caretPos.text = '<u>' + txt + '</u>';
			updateRTE('rte1');				
		}	
		if(func == '4')
		{
			obj.caretPos.text = txt + '#articlepage/#';
			updateRTE('rte1');				
		}
		if(func == '5')
		{			
			obj.caretPos.text = txt + '#articleimage#' + image + '#/articleimage#';					
			updateRTE('rte1');				
		}
		if(func == '6')
		{			
			obj.caretPos.text = txt + '#audiovisual#' + image + '#' + keyframe + '#' + url + '#/audiovisual#';					
			updateRTE('rte1');				
		}	
	}
}

function AddPage() 
{
	SetSelectedText('', '4', '', '', '');
}

function AddImage(imagename)
{
	SetSelectedText('', '5', imagename, '', '');
}

function AddAVImage(assetID, keyframe, url)
{
	if(keyframe == '')
	{
		keyframe = 'none';
	}
	SetSelectedText('', '6', assetID, keyframe, url);
}
