function populateSelectJSON(selectId,json,keepFirstEntry) {
    keepFirstEntry=(keepFirstEntry == undefined?true:keepFirstEntry);

	if (json){
        /* delete options */
        resetSelect(selectId,keepFirstEntry);
        /* add options */
        for (id in json) {
            if (isNaN(parseInt(id)) && id != ' ') {
                    continue;
            }
            var o=document.createElement("OPTION");
            o.innerHTML=json[id];

            /* special empty case */
            if (id == ' ') {
                id=''; /* php's json_encode does not support empty strings  - so we fix it here */
            }
            o.setAttribute('value',id)
            $(selectId).appendChild(o);
        }
	}
}

function resetSelect(selectId,keepFirstEntry) {
    keepFirstEntry=(keepFirstEntry == undefined?true:keepFirstEntry);
    var startIndex=(keepFirstEntry?1:0);
    while ($(selectId).options.length > startIndex) {
        $(selectId).options[startIndex]=null;
    }
}

