
var config_url_root;
var config_url_root;

if (location.host != "telecomvergelijker"){ config_url_root = "http://www.telecomvergelijker.nl";}
else config_url_root = "http://telecomvergelijker";

var config_url_dpimage = config_url_root + "/dpimage";

function u1(url, title)
{
	// Absolute internal URL. URL may not start with /
	document.write("<a href=\"",config_url_root, "/", url,"\">", title, "</a>");
}

function u2(url, title)
{
	// Relative URL, with respect to current dir
	document.write("<a href=\"",url,"\">", title, "</a>");
}

function u3(url, title)
{
	// Absolute external URL. Must start with http://
	document.write("<a href=\"",url,"\" target=\"_blank\">", title, "</a>");
}

function i1(id, w, h)
{
	// image with specified original id
	image_url = config_url_root + "/dpimage/dpimage.php?action=get_image&image_id=" + id;
	if (typeof w != "undefined") { image_url = image_url+ "&image_width=" + w; }
	if (typeof h != "undefined") { image_url = image_url+ "&image_height=" + h; }
	result = "<img src=\"" + image_url + "\" border=1>";
	document.write(result);
}

function bool(val)
{
	if (val == '0') result = "<img src='images/icons/no.gif'>";
	else if (val == '1') result = "<img src='images/icons/yes.gif'>";
	else result = "<img src='images/icons/unknown.gif'>";
	document.write(result);
}

function link_dpimage()
{
	// insert link to search in image library
	document.write("<a href='" + config_url_dpimage + "/' target=_blank>Zoek afbeeldingen</a>");
}

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

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 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);
	*/

	var rating = score;
	var width = 55;
	var height = width / 5;

	if (rating < 1) {
		image_id = 6754;
	} else if (rating < 3) {
		image_id = 6755;
	} else if (rating < 5) {
		image_id = 6756;
	} else if (rating < 7) {
		image_id = 6757;
	} else if (rating < 9) {
		image_id = 6758;
	} else {
		image_id = 6759;
	}

	// document.write("<img src=\"/image/?action=get_image&image_id=" + image_id + "&image_width=" + width + "&image_height=" + height + "\" width=" + width + "height=" + height + ">" );
	document.write("<img src=\"/images/survey/" + image_id + "_55x11.png\" width=55 height=11>");
}

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);
	}
}