function show_iframe(url)
{
    url = escape(url);
    document.location.href = "?type=iframe&url=" + url;
    return false;
}


function helppopup(e, id, txt)
{
	{
		var w = 300;
		var h = 400;
		var x = (e.screenX + 16);
		var y = (e.screenY + 16);
		var win = window.open('', 'help_popup', 'left='+x+',top='+y+',width='+w+',height='+h+',menubar=no,toolbar=no,resizable,scrollbars');
		win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n');
		win.document.write('<html xmlns="http://www.w3.org/1999/xhtml">\n');
		win.document.write('<head>\n');
		win.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\n');
		win.document.write('<title>Helpvenster ' + id + '</title>\n');
		win.document.write('<link rel="stylesheet" href="/stylesheet/help.css">\n');
		win.document.write('</head><body>\n');
		win.document.write(txt);
		win.document.write('<div style="text-align:center; padding-top: 10px; padding-bottom: 5px;"><input type=button value="Sluit dit scherm" onclick="javascript:window.close();" /></div>\n');
		win.document.write('</body></html>\n');
		win.document.close();
		win.focus();
	}

	return false;
}


function smmore(ctrl, setval)
{
	// actrl is the link that was clicked to influence this control,
	// we extract the ctrlname from the parent span
	var parent_span = ctrl.parentNode;
	var sel_ctrl    = parent_span.getElementsByTagName('select')[0];
	var ctrlname    = sel_ctrl.name;

	var smctrl = parent_span.parentNode;
	var allSpans = smctrl.getElementsByTagName('span');
	var firstspan = null;
	var maxid = 0;
	var minid = null;
	for (var i = 0; i < allSpans.length; i++)
	{
		var id = allSpans[i].id;
		if (minid == null || id < minid)
		{
			firstspan = allSpans[i];
			minid = id;
		}

		if (id.match(/^\d+$/) && id > maxid)
		{
			maxid = id;
		}
	}

	if (!firstspan)
		return false;

	// Clone the first complete entry (span)
	var newspan = firstspan.cloneNode(true);

	newspan.id = parseInt(maxid) + 1;
	var newsel = newspan.getElementsByTagName('select')[0];

	if (setval)
		smsetval(newsel, setval);	// Preselect given value
	else
		newsel.selectedIndex = 0;	// Unselect
	newspan.style.paddingTop = 8;

	// Hide +, Show -

	var links = newspan.getElementsByTagName('a');
	for (var i = 0; i < links.length; i++)
	{
		if (links[i].id == 'more')
			links[i].style.display = 'none';
		else
			if (links[i].id == 'less')
				links[i].style.display = 'inline';
	}

	// Insertion point depends on more...
	var more = document.getElementById('more' + ctrlname);
	smctrl.insertBefore(newspan, more);

	smmakelastplusvisible(smctrl);

	return false;
}


function smmakelastplusvisible(ctrl)
{
	var allSpans = ctrl.getElementsByTagName('span');
	var lastplus = null;
	var maxid = null;
	for (var k = 0; k < allSpans.length; k++)
	{
		var currentSpan = allSpans[k];
		var allLinks = currentSpan.getElementsByTagName('a');
		for (var i = 0; i < allLinks.length; i++)
		{
			var link = allLinks[i];
			if (link.id == 'more')
			{
				if (maxid == null || currentSpan.id > maxid)
				{
					maxid = currentSpan.id;
				}
				lastplus = link;

				link.style.display = 'none';
			}
		}
	}
		
	lastplus.style.display = 'inline';
}


function smsetval(selctrl, val)
{
	var o = selctrl.options;
	for (i = 0; i < o.length; i++)
	{
		if (o[i].value == val)
		{
			selctrl.selectedIndex = i;
			return;
		}
	}
}


function removeElt(node)
{
	if (node)
    {
        for (var i = 0; i < node.childNodes.length; i++)
		{
            removeElt(node.childNodes[i]);
		}

        node.parentNode.removeChild(node);
    }
}


function smless(ctrl)
{
	// actrl is the link that was clicked to influence this control,
	// we extract the ctrlname from the parent span
	var parent_span = ctrl.parentNode;
	var smctrl = parent_span.parentNode;

	var allSpans = smctrl.getElementsByTagName('span');
	var count = allSpans.length / 2;

	if (count > 1)
	{	
		// Destroy a row, including the children
		removeElt(parent_span);
	}
	else
	{
		// Instead of removing, min clears the selection if it is the last one left
		var sel_ctrl = smctrl.getElementsByTagName('select')[0];
		if (sel_ctrl)
			sel_ctrl.selectedIndex = -1;	
	}

	smmakelastplusvisible(smctrl);
	
	return false;
}


function sminit(varargs)
{
	var argv = sminit.arguments;
	var argc = argv.length;
	if (argc > 0)
	{
		var ctrlname = argv[0];

		// Find the first select control from the id smfs<fieldname>
		var firstSelectCtrl = document.getElementById('smfs' + ctrlname);
		if (argc > 1)
		{
			var firstval = argv[1];
			smsetval(firstSelectCtrl, firstval);
			// For any other values, we create a new select control
			if (argc > 2)
			{
				for (var i = 2; i < argc; i++)
				{
					if (argv[i].length && argv[i] != 0)
						smmore(firstSelectCtrl, argv[i]);
				}
			}
		}
	}
}


// with this test document.cookie.indexOf( name + "=" );


function GetCookie( name, subname ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var cookie = FindCookie(a_all_cookies, name);
	if (cookie && subname) {
		return FindCookie(cookie, subname);
	}
	return cookie;
}

function FindCookie (a_all_cookies, check_name) 
{
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}


// Start value to collect active banners for omniture
var UsedBannerposities = '';


function testIfNiceSearchUrl(f, stammap) {
	if (!f)
		f = document.forms[0];

	var niceOpts = [ 'provincie','vakgebied' ];	

    var chosen = new Object();
    var filled = 0;
    for (var i = 0; i < f.elements.length; i++) {
        var elt = f.elements[i];

		var setval = undefined;
        if (elt.type == 'hidden') {
            // Ignored
        } else if (elt.type == 'select-one') {
            if (elt.value != "" && !(elt.name=='periode' && elt.value=='0')) {
				setval = elt.options[elt.selectedIndex].value;
            }
        } else if (elt.type == 'text') {
            if (elt.value != "") {
                setval = elt.value;
            }
        } else if (elt.type == 'select-multiple') {
            // We don't handle multiple select's yet
            return true;
        } else if (elt.type == 'checkbox') {
            if (elt.checked) {
				setval = elt.value;
			}
        }

		if (typeof setval != "undefined") {
			if (!chosen[elt.name]) {
				chosen[elt.name] = new Array();
               	filled++;
			}
			chosen[elt.name].push(setval);
		}
    }

    var niceUrl = '/vacatures/';
    for (var i = 0; i < niceOpts.length; i++) {
        var key = niceOpts[i];
        var arr = chosen[key];
        if (typeof arr != "undefined" && typeof arr[0] != "undefined" && arr.length == 1) {
            delete chosen[key];
            filled--;
            niceUrl += urlEncode(stammap[key][arr[0]]) + "/";
        } else if (filled > 0) {
            // We miss a portion for a complete nice url
            return true;
        }
    }

    if (filled > 0)
        return true;

    document.location.href = niceUrl;



	return false;	


}

function urlEncode(v) {
    v = v.toLowerCase();
    v = stripVowelAccent(v);
    v = v.replace(/\s/g, '-');
    v = v.replace(/[\/\.']/g, '-');
    v = v.replace(/[()\+]/g, '');
	v = v.replace(/-+/g, '-');
    v =  escape(v);
    return v;
}


// The french way
function stripVowelAccent(str)
{
var s=str;

var rExps=[ /[\xC0-\xC2]/g, /[\xE0-\xE2]/g,
/[\xC8-\xCA]/g, /[\xE8-\xEB]/g,
/[\xCC-\xCE]/g, /[\xEC-\xEE]/g,
/[\xD2-\xD4]/g, /[\xF2-\xF4]/g,
/[\xD9-\xDB]/g, /[\xF9-\xFB]/g ];
var eExps=[ /%C[0-2]/g, /%E[0-2]/g,
/%C[8-A]/g, /%E[8-B]/g,
/%C[C-E]/g, /%E[C-E]/g,
/%D[2-4]/g, /%F[2-4]/g,
/%D[9-B]/g, /%F[9-B]/g ];

var repChar=['A','a','E','e','I','i','O','o','U','u'];

for(var i=0; i<rExps.length; i++)
s=s.replace(rExps[i],repChar[i]);
s=s.replace(eExps[i],repChar[i]);

return s;
}


function trackPageview(code) {
	if (pageTracker)
		pageTracker._trackPageview(code);
}
