function bool(val)
{
	if (val == '0') result = "Nee";
	else if (val == '1') result = "Ja";
	else result = "?";
	document.write(result);
}

function survey_score2text(score)
{
	/* convert survey score to text and print it */
	text = "";
	if (score < 1) text = "";
	else if (score < 3) text = "Slecht";
	else if (score < 5) text = "Matig";
	else if (score < 7) text = "Voldoende";
	else if (score < 9) text = "Goed";
	else if (score <= 10) text = "Zeer goed";
	document.write(text);
}

function showBookmarkLink()
{
	var url = "http://www.vergelijken.info/";
	var title = "Vergelijken.nl";

	if (window.external)
	{
		document.write(
		 '<a href="#"'+
		 ' onClick="window.external.AddFavorite(url,title);">'+
		 'Bookmark!</a>'
		 );
	}
	else
	{
		document.write("Bookmark! (CTRL-D)");
	}
}

function winopen(url, width, height) {
	if(!width) {
		width=450;
	}
	if(!height) {
		height=550;
	}

	window.open(url, "_blank","resizable=yes,menubar=no,titlebar=yes,toolbar=no,location=no,status=yes,scrollbars=yes,width=" + width + ",height=" + height);
}

function email(name, domain)
{
	// Email spambot remmer
	document.write("<a href='mailto:" + name + "@" + domain + "'>" + name + " AT " + domain + "</a>");
}

function pw_promo_popup() {
	url = "/pricewatch_promo_popup.php";
	width = 450; // width of window in pixels
	height = 210; // height of window in pixels
	delay = 3; // time in seconds before popup opens
	timer = setTimeout("winopen(url, width, height)", delay*1000);
}

function addslashes(str)
{
	str = str.replace(/\\/g,"\\\\");
	str = str.replace(/\'/g,"\\'");
	str = str.replace(/\"/g,"\\\"");
	return str;
}

function smiley(sign, name, h, w)
{
	//document.write("<td style=\"font-family: courier\" nowrap><img onclick=\"putStr(document.theForm.body, \' ", addslashes(sign), " \');\" src=\"/images/smilies/", name, ".gif\" width=", w, " height=", h, " align=left>");
	document.write("<td style=\"font-family: courier\" nowrap><img src=\"/images/smilies/", name, ".gif\" width=", w, " height=", h, " align=left>");
	document.write("&nbsp;&nbsp;", sign, "</td>");
}

/* message box editing functions */
function storeCursor(element)
{
	if ( typeof element.createTextRange != 'undefined' )
		element.cursorPos = document.selection.createRange().duplicate();
}

function det_replace(type, text)
{
	if (text != '')
	{
		switch (type)
		{
			case 'AND':
				text = text.replace(/(\w+)\s+/g, '$1 AND ');
				break;
			case 'OR':
				text = text.replace(/(\w+)\s+/g, '$1 OR ');
				break;
			case 'brackets':
				text = '('+text+')';
				break;
			case 'title':
				text = 'title:('+text+')';
				break;
			case 'start':
				text = 'start:('+text+')';
				break;
			default:
			text = type;
		}
	}
	else
	{
		switch (type)
		{
			case 'AND':
				text = ' AND ';
				break;
			case 'OR':
				text = ' OR ';
				break;
			case 'brackets':
				text = '()';
				break;
			case 'title':
				text = 'title:';
				break;
			case 'start':
				text = 'start:';
				break;
			default:
				text = type;
		}
	}
	return text;
}

function putStr(target, type )
{
	//var target = document.getElementById( 'messageBox' );

	if ( target != null )
	{
		if ( typeof target.cursorPos != 'undefined' )
		{
			var cursorPos = target.cursorPos;
			cursorPos.text = det_replace(type, cursorPos.text);
		}
		else if ( typeof target.selectionStart != 'undefined' )
		{
			var sStart = target.selectionStart;
			var sEnd = target.selectionEnd;
			var text = det_replace(type, target.value.substr(sStart, sEnd));
			target.value = target.value.substr(0, sStart) + text + target.value.substr(sEnd, target.value.length);
			var nStart = sStart == sEnd ? sStart + text.length : sStart;
			var nEnd = sStart + text.length;
			target.setSelectionRange(nStart, nEnd);
		}
		else
		{
			target.value += det_replace(type,'');
		}
		target.focus();
		storeCursor(target);
	}
}