<!--//

function clearText(obj){
	
	if (obj.value == obj.title){
		obj.value = ''
	}
	else if(obj.value == ''){
		obj.value = obj.title;
	}
}
function public_volunteer_registration(){
	var myForm = document.register;
	myForm.submit();

}

function show_shift(task_id){
	if ($("#task_"+task_id).is(":hidden")) {
		$("#task_"+task_id).slideDown("slow");
	} else {
		$("#task_"+task_id).slideUp("slow");
	}

}
function check_wavier(obj){
	
	if (document.getElementById('waiver').checked == true){
		window.location = obj.href;
	}else if( document.getElementById('waiver').value == 'agree_hidden'){
		window.location = obj.href;
	}else{
		alert('You need to agree to the waiver and liability'); 
	}
}
function register_shift(task_id){
	var error = '';
	var myForm = document.getElementById('task_form_id_'+task_id);
	var shift_id = new Array();
	var count = 0; 
	
	myElements = myForm.elements["shift_id[]"];
	
	if (typeof myElements.length == 'undefined') {
		if (myElements.checked == true) {
			shift_id[0] = myElements.value;
		}
	} else {
		for (var i = 0; i < myElements.length; i++) {
			if (myElements[i].checked == true) {
				shift_id[count] = myElements[i].value;
				count++;
			}
		}
	}
	
	if (typeof myForm.comment != 'undefined') {
		if (myForm.comment.title == myForm.comment.value) {
			comment = '';
		}
		else {
			comment = myForm.comment.value;
		}
	}else{
		comment = '';
	}
	
	if (typeof myForm.question != 'undefined') {
		if (myForm.question.title == myForm.question.value) {
			question = '';
		}
		else {
			question = myForm.question.value;
		}
	}else{
		question = '';
	}

	if (error == '') {
		$.post('/includes/ajax/shifts', {
			method_type: 	'register',
			'shift_id[]': 	shift_id,
			charity_id:		myForm.charity_id.value,	
			comment: 		comment,
			question: 		question
		}, function(data){
			if (data != '') {
				if (data == 'not_available') {
					alert('this shift is not available');
				} else if (data == 'true') {
						myForm.submit();
				}else{
					alert(data);	
				}
			}
		});
		
	}
}

function show_shift_details(shift_id){
	if ($("#details_"+shift_id).is(":hidden")) {
		$("#details_"+shift_id).slideDown("slow");
	} else {
		$("#details_"+shift_id).slideUp("slow");
	}
}

function select_all_box(obj, form_id, check_box_name){
	var myForm = document.getElementById(form_id);
	var myElements = myForm.elements[check_box_name];
	if (obj.checked == true){
		
		for (var i = 0; i < myElements.length; i++){
			myElements[i].checked = true;
		}
	}
	else{
		for (var i = 0; i < myElements.length; i++){
			myElements[i].checked = false;
		}
	}
}

function register_group_shift(form_id){
	var error = '';
	var myForm = document.getElementById(form_id);
	var shift_id;
	var shift_count_id = '';
	var volunteer_id_array = new Array();
	var count = 0; 
	
	if (typeof myForm.shift_id.length == 'undefined'){
		if (myForm.shift_id.checked == false){
			error = 'Your shift must be selected\n';
		}
	}else{
		error = 'Your shift must be selected\n'
		for (var i =  0; i < myForm.shift_id.length; i++){
			if (myForm.shift_id[i].checked == true){
				shift_count_id =  myForm.shift_id[i].value;
				error = '';
				break;
			}
		}
	}

	myElements = myForm.elements["volunteer_id[]"];
	if (typeof myElements != 'undefined'){ 
		if (typeof myElements.length == 'number'){
			
			for (var i = 0; i < myElements.length; i++){
				if (myElements[i].checked == true){
					volunteer_id_array[count] = (myElements[i].value);
					count++;
				}
			}
		}else if(myElements.checked == true){
			volunteer_id_array[0] = myElements.value;
		}
		
		if (volunteer_id_array.length == 0){
			error += 'You must select a volunteer\n';
		}
		
		if(shift_count_id != ''){
			var counter = document.getElementById("shift_count_"+shift_count_id).value;
			if (counter < volunteer_id_array.length){
				error += 'You have more members than available slots. Please choose ' + counter + ' members to fill the shift.';
			}
		}
		if (document.getElementById('waiver').checked == true){
			
		}
		else if (document.getElementById('waiver').value == 'agree_hidden'){
			
		}else{
			error += 'You need to agree to the waiver and liability';
		}
	}else{
		error += 'You do not have any available members in your group';
	}
	if (error == ''){
		myForm.submit();
	}else{
		alert(error);
	}
}

function remove_vol_shift(vol_shift_id, redir){
	if (vol_shift_id != '') {
		$.post('/includes/ajax/shifts', {
			method_type: 'remove',
			redir: redir,
			vol_shift_id: vol_shift_id
		}, function(data){
			if (data != '') {
				if (data != 'true') {
					if (data.result == 'true'){
						$("#vol_shift_"+ vol_shift_id).hide();
						if (data.waiver == 'true'){
							window.location = data.redir;
						}
					}
				}
			}
		},'json'); // end .$post
	}

}
function password_check(form_id){
	var myForm = document.getElementById(form_id);
	var error = '';
	
	if (myForm.password.value.length < 4){
		
		error += ' - password needs to be at least 4 character or more\n';

	}
	if (myForm.password.value != myForm.confirm_password.value){
		error += ' - password does not match with verify password\n';
	}
	if (error == ''){
		myForm.submit();
	}else{
		var error_header = 'The following error occured:\n';
		alert(error_header + error);
	}
}
function check_in(obj){
	var shift_vol_id = '';
	if (obj.checked == true){
		shift_vol_id = obj.value;
		$.post('/includes/ajax/checkin', {
			method_type: 		'checkin',
			shift_vol_id:		shift_vol_id
			}, function(data){
			if (data != '') {
				if (data == 'true') {
					$("#hide_"+ shift_vol_id).hide();
				}
			}
		}); // end .$post
	}
}
function check_out(obj){
	var shift_vol_id = '';
	if (obj.checked == true){
		shift_vol_id = obj.value;
		
		$.post('/includes/ajax/checkin', {
			method_type: 		'checkout',
			shift_vol_id:		shift_vol_id
			}, function(data){
			if (data != '') {
				if (data.result == 'true') {
					obj.disabled = true;
					$('#checkout_'+shift_vol_id).html(data.checkout_date);
				}
			}
		},'json'); // end .$post
	}
}
function remove_check_in(obj){
	var shift_vol_id = '';
	if (obj.checked == true){
		shift_vol_id = obj.value;
		if (confirm('Are you sure you want to remove from check in?')){
			$.post('/includes/ajax/checkin', {
				method_type: 		'remove_checkin',
				shift_vol_id:		shift_vol_id
				}, function(data){
				if (data != '') {
					if (data == 'true') {
						$("#hide_"+ shift_vol_id).hide();
					}
				}
			}); // end .$post
		}
		else{
			obj.checked = false;
		}
	}
	
}
function filter_shift_date(value){
	if (value == 'by_date'){
		document.getElementById('show_day').style.display = "none";
		document.getElementById('show_date').style.display = "inline";
	}else if (value == 'by_day'){
		document.getElementById('show_date').style.display = "none";
		document.getElementById('show_day').style.display = "inline";
	}else{
		document.getElementById('show_date').style.display = "none";
		document.getElementById('show_day').style.display = "none";
	}
}
function remove_tag_shift(shift_id, volunteer_id){
	if (shift_id != '' && volunteer_id != ''){
		$.post('/includes/ajax/shifts', {
			method_type: 	'remove_shift_tag',
			volunteer_id:	volunteer_id,
			shift_id:		shift_id
			}, function(data){
			if (data != '') {
				if (data == 'true') {
					$('#blind_tag_shift'+shift_id).hide();
				}
			}
		}); // end .$post
	}
}

function update_charity(shift_id){
	var id = "charity_id_"+shift_id;
	var charity_id = document.getElementById(id).value;
	$.post('/includes/ajax/volunteers', {
			method_type: 	'update_charity',
			charity_id:		charity_id,
			shift_id:		shift_id
			}, function(data){
			if (data != '') {
				if (data == 'true') {
					alert("Charity Updated Successfully.");
				}
				else {alert("Charity Update Failed."); }
			}
		}); // end .$post
	
}

function decision(message, url){
    if(confirm(message)) location.href = url;
}
	function confirm_shifts(shift_id)
	{
		if (confirmBox('Are you sure you want to confirm this shift?'))
		{
			$.post('/includes/ajax/shifts', {
				shift_id: 		shift_id,
				method_type: 	'confirm_shifts'
			}, function(data){
				if (data == 'true'){
					$('#hide_unconfirmed_' + shift_id).slideUp();
				}
			}); // end .$post
		}
	}
function confirmBox(message){
		var myMessage = confirm(message)
		return myMessage;
	}
	
function delete_volunteers(volunteer_id){
		if(confirmBox("Are you sure you want to delete this volunteer? This cannot be undone.")){
		
			if (volunteer_id != ""){
				$.post('/includes/ajax/volunteers', {
				method_type: 			'delete_vol',
				volunteer_id:			volunteer_id
				},
				function(data){
					if (data !=''){
							if (!$("#blind_" + volunteer_id).is(":hidden")) {
								$("#blind_" + volunteer_id).hide();
							}
					}
				}); // end .$post
			}
		}
	}
//-->
