function checkZoek(what, val) {
	if(what.value == val) {
		what.value = "";
	}
}
function unCheckZoek(what, wom) {
	if(what.value == "") {
		what.value = wom;
	}
}

function checkAll(w) {
	c = w.checked;
	frm = w.form;
	l = frm.elements.length;
	for(i=0;i<l;i++) {
		if(frm.elements[i].type == "checkbox") {
			frm.elements[i].checked = c;
		}
	}
}
function showHide(whoname) {
	who = document.getElementById(whoname);
	who.style.display = who.style.display == "none" ? "block" : "none";
}
function addRow(val, orig) {
    var found = false;
    var origElem = document.getElementById(orig);
    for(var i = 0; i < origElem.length; i++) {
        if(origElem.options[i].text == val) {
            origElem.selectedIndex = i;
            found = true;
        }
    }
    
	if(found == true) {
        return false;
    }
	
	regio = false;
	if(orig == "city_id") {
		rr = document.getElementById("regio_id");
		if(rr) {
			if(rr.selectedIndex == 0) {
				alert("Please insert a region");
				return false;
			}
			regio = rr[rr.selectedIndex].value;
		}
	}
	
    addElement(val, orig, regio);
}
var ajax;
var origElement;
var textValue;

function addElement(val, elem) {
    ajax = new sack();
    ajax.setVar('value', val);
    ajax.setVar('element', elem);
    ajax.setVar('regio', regio);
    ajax.requestFile = '/ajax/addElement.php';
    ajax.method = 'GET';
    ajax.onCompletion = optionLoaded;
    origElement = elem;
    textValue = val;
    ajax.runAJAX();
}

function optionLoaded() {
    eval('var returnValue = ' + ajax.response);
    var origElem = document.getElementById(origElement);

    var y=document.createElement('option');
    y.text = textValue;
    y.value = returnValue;
    try {
        origElem.add(y,null); // standards compliant
    } catch(ex) {
        origElem.add(y); // IE only
    }
    
    for(var i = 0; i < origElem.length; i++) {
        if(origElem.options[i].text == textValue) {
            origElem.selectedIndex = i;
        }
    }
}

