function fontstyle(style) {
	//document.getElementById('editorContent').setActive();
	document.execCommand(style,false,null);
}

function commandlocation(type) {
	if (type == 'createlink') {
		URL = prompt('Geef de locatie van de webpagina', 'http://');
		insertLink(type,URL);
	} else if(type == 'insertvideo') {
		popupLarge('afbeeldingpopup.php?insertType=youtube', 'Video');
	} else if(type == 'insertimage') {
		popupLarge('afbeeldingpopup.php?insertType=afbeelding', 'Afbeeldingen');
	}
}

function insertLink(type,URL) {
	document.execCommand(type,false,URL);
}

function insertVideo(icon,id) {
	icon = icon + '?videocode=' + id;
	document.execCommand('insertimage',false,icon);
}

function removeformat() {
	if (confirm("Are you sure you want to remove all markup?")){
 		fontstyle('removeformat');
	} else{
		return false;
	}
}

var div1 = true;
function switchModus(fieldName) {
	if(div1 == true) {
		document.getElementById(fieldName + '_editor_text_field').style.display = 'none';
		document.getElementById(fieldName + '_editor_html_field').style.display = 'block';
		document.getElementById(fieldName + '_editor_textarea').value  = document.getElementById(fieldName + '_editor_contents').innerHTML;
		div1 = false;
	} else {
		document.getElementById(fieldName + '_editor_text_field').style.display = 'block';
		document.getElementById(fieldName + '_editor_html_field').style.display = 'none';
		document.getElementById(fieldName + '_editor_contents').innerHTML = document.getElementById(fieldName + '_editor_textarea').value;
		div1 = true;
	}
}


function addTags(Tag,fTag,fieldName)
{
  var obj = document.getElementById(fieldName + '_editor_textarea');

  obj.focus();

  if (document.selection && document.selection.createRange)  // Internet Explorer
  {
sel = document.selection.createRange();
if (sel.parentElement() == obj)  sel.text = Tag + sel.text + fTag;
  }

  else if (typeof(obj) != "undefined")  // Firefox
  {
var longueur = parseInt(obj.value.length);
var selStart = obj.selectionStart;
var selEnd = obj.selectionEnd;

obj.value = obj.value.substring(0,selStart) + Tag + obj.value.substring(selStart,selEnd) + fTag + obj.value.substring(selEnd,longueur);
  }

  else obj.value += Tag + fTag;

  obj.focus();
}



// get content from page and add it to hidden field "thecode"
function prepare2save(formName,fieldName){
	if(document.getElementById(fieldName + '_editor_html_field').style.display == 'block') {
		document.getElementById(fieldName).value = document.getElementById(fieldName + '_editor_textarea').value;
	} else {
		document.getElementById(fieldName).value = document.getElementById(fieldName + '_editor_contents').innerHTML;
	}
	document.forms[formName].submit();
}

function popupLarge(url,winName,width,height) {
	W = 500;	//default width
	H = 480; //default height
	X = screen.width/2-W/2; //default Xpos (is now centered)
	Y = screen.height/2-H/2; //default Ypos (is now centered)

	winprops = 'height='+H+',width='+W+',top='+Y+',left='+X+',scrollbars=yes';
	win = window.open(url, winName, winprops);
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}
