//<!--

function verwijdertekst(uithetveld){
	if (uithetveld.defaultValue==uithetveld.value)
		uithetveld.value = ""
	}

//anti-spam mail weergeven
function mailkelink(voor,dom){
	var meel = 'mail';
	document.write('<a href="' + meel);
	document.write('to:' + voor);
	document.write('@');
	document.write(dom + '">');
	document.write(voor);
	document.write('@');
	document.write(dom + '</a>');
	}

function mailke(voor,dom,tekst){
	var meel = 'mail';
	document.write('<a href="' + meel);
	document.write('to:' + voor);
	document.write('@');
	document.write(dom + '">');
	document.write(tekst);
	document.write('</a>');
	}

function printmailke(voor,dom){
	document.write(voor);
	document.write('@');
	document.write(dom);
	}
	
	
// tagOpen en Sluiten in een textarea

var clientPC = navigator.userAgent.toLowerCase();
var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1) && (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1));
var is_safari = ((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1));

function insertTags(tagOpen, tagClose, sampleText, formulier) {
	
	if (formulier == 'sms') {
		var txtarea = document.sms.bericht;
	}
	if (formulier == 'mailing') {
		var txtarea = document.nieuwsbrief.boodschap;
	}
	// IE
	if(document.selection  && !is_gecko) {
		var theSelection = document.selection.createRange().text;
		if(!theSelection) { theSelection=sampleText;}
		txtarea.focus();
		if(theSelection.charAt(theSelection.length - 1) == " "){ // eindspatie weglaten als er een is
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
 		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		var scrollTop=txtarea.scrollTop;
		var myText = (txtarea.value).substring(startPos, endPos);
		if(!myText) { myText=sampleText;}
		if(myText.charAt(myText.length - 1) == " "){ // eindspatie
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		} else {
			subst = tagOpen + myText + tagClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst +
		  txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();

		var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
		txtarea.selectionStart=cPos;
		txtarea.selectionEnd=cPos;
		txtarea.scrollTop=scrollTop;

	// Alle andere
	} else {
		var copy_alertText=alertText;
		var re1=new RegExp("\\$1","g");
		var re2=new RegExp("\\$2","g");
		copy_alertText=copy_alertText.replace(re1,sampleText);
		copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose);
		var text;
		if (sampleText) {
			text=prompt(copy_alertText);
		} else {
			text="";
		}
		if(!text) { text=sampleText;}
		text=tagOpen+text+tagClose;
		document.infoform.infobox.value=text;
		// in Safari veroorzaakt dit scrollen
		if(!is_safari) {
			txtarea.focus();
		}
		noOverwrite=true;
	}
	// reposition cursor indien mogelijk
	if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}


function addtext(veld,text) 
{ 
    document.nieuws.elements[veld].value += " "+text+" "; 
    document.nieuws.elements[veld].focus(); 
}


function textCounter(field, countfield, maxlimit) { 
	var vreemdetekens = telvreemdetekens(field.value);
	var totkarakters = field.value.length + vreemdetekens;
	if (totkarakters > maxlimit) // if too long...trim it! 
		field.value = field.value.substring(0, maxlimit-vreemdetekens); 
	// otherwise, update 'characters left' counter 
	else 
		countfield.value = maxlimit - totkarakters; 
} 

function checkAll(theElement, nummer) {
     var theForm = theElement.form, z = 0;
     while (z<theForm.length) {
        if (theForm[z].id == nummer){
            theForm[z].checked = theElement.checked;
        }
        z++;
     }
}

function substr_count(string,substring,start,length) {
	var c = 0;
	if(start) { string = string.substr(start); }
	if(length) { string = string.substr(0,length); }
	for (var i=0;i<string.length;i++) {
		if(substring == string.substr(i,substring.length))
		c++;
	}
	return c;
}

function telvreemdetekens(bericht) {
	var vreemdetekens = 0;

	vreemdetekens += substr_count(bericht,'[');
	vreemdetekens += substr_count(bericht,'\\');
	vreemdetekens += substr_count(bericht,']');
	vreemdetekens += substr_count(bericht,'^');
	vreemdetekens += substr_count(bericht,'{');
	vreemdetekens += substr_count(bericht,'|');
	vreemdetekens += substr_count(bericht,'}');
	vreemdetekens += substr_count(bericht,'~');
	vreemdetekens += substr_count(bericht,'\u20ac'); // € symbol
	
	return vreemdetekens;
}


function textCounter2(field, countfield, messagefield, maxlimit) { 
	var vreemdetekens = telvreemdetekens(field.value);
	var totkarakters = field.value.length + vreemdetekens;
	if (totkarakters > maxlimit) // if too long...trim it! 
		field.value = field.value.substring(0, maxlimit-vreemdetekens); 
	// otherwise, update 'characters left' counter 
	else {
		var totberichten = 0, maxlimittemp = 0;

		if (totkarakters > 459) {
			totberichten = 4;
			maxlimittemp = 459;
		}
		if (totkarakters <= 459) {
			totberichten = 3;
			maxlimittemp = 459;
		}
		if (totkarakters <= 306) {
			totberichten = 2;
			maxlimittemp = 306;
		}
		if (totkarakters <= 160) {
			totberichten = 1;
			maxlimittemp = 160;
		}
		
		messagefield.value = totberichten;
		countfield.value = maxlimittemp - totkarakters; 
	}
}

//-->



