function show_hide_rating(){
	if(document.getElementById('rating_info').style.visibility == 'hidden'){
		document.getElementById('rating_info').style.display = 'block';
		document.getElementById('rating_info').style.visibility = 'visible';
		document.getElementById('rating_link').className = 'selected';
	}else{
		document.getElementById('rating_info').style.visibility = 'hidden';
		document.getElementById('rating_link').className = '';
	}
}


function PageLoaded(){
	setTimeout('labelTest()', 1000);
}

function labelTest(){
	show_hide_label(document.getElementById('username'), 1);
	show_hide_label(document.getElementById('password'), 1);
}


function show_hide_label(formElement, action){
	if(action){ // show label
		if(formElement != null){
			if(formElement.value == ''){
				document.getElementById(formElement.name+'_label').style.visibility = 'visible';
			}else{
				document.getElementById(formElement.name+'_label').style.visibility = 'hidden';
			}
		}
	}else{ // hide label
		document.getElementById(formElement.name+'_label').style.visibility = 'hidden';
	}

}

function change_adventures(){
	alert('Changing adventures.');
}

function change_charities(){

	var ajax_args = new Object();
	ajax_args['adventure_id'] = $F('adventure_id');

  _clear_select_list('charity_id');

  new Ajax.Request('intranet/ajax/form/update_charities.php',   {

		parameters: ajax_args,
		method:'post',
		onSuccess: function(transport){

			var response = transport.responseText || "no response text";
			// alert(response);

			commands = response.evalJSON(true);

			for(var key in commands) {
				eval(commands[key]);
			}

		},
		
		onFailure: function(){
			alert('Something went wrong...')
		}

	});

}

function _clear_select_list(element){

	try{

		document.getElementById(element).length = 0;
		return true;

	}catch(e){
		return false;
	}

}

function add_option(element, text, value){

	oOption = document.createElement('option');
	oOption.text = text;
	oOption.value = value;

	document.getElementById(element).options.add(oOption);

}

function view_departure(charity_id, adventure_id, departure_id){
	window.location.href = 'adventure-details.php?charity_id='+charity_id+'&adventure_id='+adventure_id+'&departure_id='+departure_id;
}

