function populate_dropdown(field_id,options_array,selected_option_index){

	//Remove all of the current options in the select menu
	document.getElementById(field_id).length=0;

	//Populate the select element with values from the passed array
	for(var a=0;a<options_array.length;a++){
		//Separate the text from the value
		var text=options_array[a].split("=>")[0];
		var value=options_array[a].split("=>")[1];
		document.getElementById(field_id)[a]=new Option(text,value);
	}
	//Preselect the selected option
	document.getElementById(field_id).selectedIndex=selected_option_index;

}

function change_element_value(id,type,value){
	//Make sure that the element exists
	if( document.getElementById(id)!=null ){
		eval("document.getElementById('"+id+"')."+type+"='"+value+"'");
	}
}

function toggle_links(id){

	change_element_value(id,"className","selected");
	
	//Record the last selected link so that it can be undecorated
	if( typeof last_selected_link_id!="undefined" ){
		change_element_value(last_selected_link_id,"className","");
	}
	
	last_selected_link_id=id;

}

//Replace Characters
function replace_characters(text,findChars,replacementChars){
	newText="";
	for(r=0;r<text.length;r++){
		//Set char string to compare
		charString="";
		//starting at r, create charString to compare findChars with (according to number of chars)
		for(s=r;s<r+findChars.length&&s<text.length;s++){
			charString+=text.charAt(s);
		}
		//If the charString matches findChars
		if(charString==findChars){
			//add charString to nextText
			newText+=replacementChars;
			//and move on, starting at next unchecked char
			r=r+eval(findChars.length-1);
		}
		else{
			//Add letter to nextText
			newText+=text.charAt(r);
		}
	}
	return newText;
}

function validate_form(){
	//look at all of the form fields
	fields_to_validate=new Array("add|0,first_name","add|0,last_name","add|0,email_address","add|0,telephone_number");
	field_names=new Array("First Name","Last Name","Email Address","Telephone Number");	
	error_message="";
	there_are_errors=false;
	for(var a=0;a<fields_to_validate.length;a++){
		
		//Strip the excess spaces (before and after the value)
		field_value=replace_characters(document.getElementById(fields_to_validate[a]).value," ","");
		field_name=field_names[a];
		
		//Make sure that it isn't blank
		if(field_value==""){
			error_message+="\n- "+field_name;
			there_are_errors=true;
		}
	}
	
	//Check the resume file
	if( replace_characters(document.getElementById("add|0,resume_file").value," ","")!="" ){
		
		var valid_file_extensions=new Array("doc","rtf","txt");
		
		//File details
		var file_details=document.getElementById("add|0,resume_file").value.split(".");
		var file_extension=file_details[file_details.length-1];
		var valid_extension=false;
		
		//Determine the file extension
		for(var a=0;a<valid_file_extensions.length==true;a++){
		
			//Does the file's extension match one of the valid extensions?
			if( file_extension==valid_file_extensions[a] ){
				valid_extension=true;
			}
		
		}
		
		if( valid_extension==false ){
			there_are_errors=true;
			error_message+="\n- Resume file (invalid file type)";
		}
		
	}
	
	
	
	//error message heading
	if(there_are_errors==true){
		error_message="Please check the following fields:\t\n"+error_message+"\n";
	}
	//report the errors if there are any
	if(error_message!=""){
		alert(error_message);
		return false;
	}
	//Otherwise, do nothing
	
}