function hideElements(test) {
	var i=0;
	while(i<test.length) {
		$(test[i]).hide();
		i++;
	}
}

function showElements(test) {
	var i=0;
	while(i<test.length) {
		$(test[i]).show();
		i++;
	}
}

//Check for address
function checkForAddress() {
	elZipcode	= $('postalcode');
	elNumber	= $('houseno');
	elStreet	= $('street');
	elCity		= $('city');
	// Have the street and city filled in by getAddress-function
	if ((elZipcode.getValue() != '') && (elNumber.getValue() != '')) {
		getAddress(elZipcode, elNumber, elStreet, elCity);
	}
}

//Fill the education_level SELECT
function setEducationLevels(educationlevelID, educationcityID) {
    if(educationcityID == '') {
        educationcityID = $('education_city').getValue();
    }
    retrieveEducationLevels(educationcityID, $('education_level'), educationlevelID);
}

//Fill the education_institute SELECT
function setEducationInstitutes(educationinstituteID, educationlevelID, educationcityID) {
    if(educationcityID == '') {
        educationcityID = $('education_city').getValue();
    }    
    if(educationlevelID == '') {
        educationlevelID = $('education_level').getValue();
    }
    retrieveEducationInstitutes(educationlevelID, educationcityID, $('education_institute'), educationinstituteID);
}

//Fill the education_category SELECT
function setEducationCategories(educationcategoryID, educationinstituteID, educationlevelID, educationcityID) {
    if(educationcityID == '') {
        educationcityID = $('education_city').getValue();
    }    
    if(educationlevelID == '') {
        educationlevelID = $('education_level').getValue();
    }   
    if(educationinstituteID == '') {
        educationinstituteID = $('education_institute').getValue();
    }
    retrieveEducationCategories(educationinstituteID, educationlevelID, educationcityID, $('education_category'), educationcategoryID);
}

//Fill the education SELECT
function setEducations(educationID, educationcategoryID, educationinstituteID, educationlevelID, educationcityID) {
    if(educationcityID == '') {
        educationcityID = $('education_city').getValue();
    }    
    if(educationlevelID == '') {
        educationlevelID = $('education_level').getValue();
    }
    if(educationinstituteID == '') {
        educationinstituteID = $('education_institute').getValue();
    }
    if(educationcategoryID == '') {
        educationcategoryID = $('education_category').getValue();
    }
    retrieveEducations(educationcategoryID, educationinstituteID, educationlevelID, educationcityID, $('education'), educationID);
}

// Verify if IT study was chosen, if so, show IT checkboxes
function testITcheckboxes(educationID) {
	if (in_array(educationID, arrayEducationsIT) && !showITstuff) {
		$('programming_knowledge_tr').show();
		$('database_knowledge_tr').show();
		$('developing_method_tr').show();
		$('software_knowledge_tr').show();
		retrieveProgrammingLanguages($('programming_knowledge'), programmingLanguageIDs);
		retrieveDatabaseLanguages($('database_knowledge'), databaseLanguageIDs);
		retrieveDevelopMethods($('developing_method'), developMethodIDs);
		retrieveVariousSoftware($('software_knowledge'), variousSoftwareIDs);
		showITstuff=true;
	}
	else if (!in_array(educationID, arrayEducationsIT) && showITstuff) {
		removeElements($('programming_knowledge'));
		removeElements($('database_knowledge'));
		removeElements($('developing_method'));
		removeElements($('software_knowledge'));
		showITstuff=false;
		$('programming_knowledge_tr').hide();
		$('database_knowledge_tr').hide();
		$('developing_method_tr').hide();
		$('software_knowledge_tr').hide();
	}		
}

//Checks an array(haystack) for the presence of 1 item(needle)
function in_array(needle, haystack) {
    var found = false;
    for (key in haystack) {
        if (haystack[key] == needle) {
            found = true;
            break;
        }
    }
    return found;
}

//Collapse or Expand a workdirectory
function toggleThis(event, workdirectionID, strImageLoc) {
	elTR = $('wd'+workdirectionID);
	elIMG= $('img'+workdirectionID);

	if(elTR.visible()) {
		elTR.hide();
		elIMG.writeAttribute({'src':strImageLoc+'/expand.gif'});
	}
	else {
		elTR.show();
		elIMG.writeAttribute({'src':strImageLoc+'/collapse.gif'});
	}
}

function countWDs(event) {
	amount = 0;
	for (i=0; i<functions.length; i++) {
		if ($('cbFunction'+functions[i]).checked==true) {
			amount+=1;
		}
	}
	if (amount==1)
		$('amountCheckedWDs').update(amount+' functie geselecteerd');
	else
		$('amountCheckedWDs').update(amount+' functies geselecteerd');
}

//Retrieve the workdirections
function getWorkDirections(workDirectionIDs, strImageLoc) {
	retrieveWorkDirections($('work_directions'), workDirectionIDs, strImageLoc);
}

//Collapse the workdirection
function collapseWorkDirections() {
	wdIDs = workdirectionIDs.slice();
	while (wdID = wdIDs.pop()) {
		if ($('wd'+wdID).visible()) {
			toggleThis(this, wdID, strImageLoc);
		}
	}
}