function clearAll()
{
	$('group-title').value = '';
	$('group-content').value = '';
}

function switchGroupTabs()
{
	$('discussions-list').toggle();
	$('member-list').toggle();
	$('group-discussions-tab').toggleClassName('active');
	$('group-members-tab').toggleClassName('active');
	return false;
}

//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = '/images/new-design/group/false.jpg';
var imgTrue = '/images/new-design/group/true.jpg';
var ch = false;
//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
	
    replaceChecks();
}

function replaceChecks() {
	
    //get all the input fields on the page
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for(var i=0; i < inputs.length; i++) {

        //check if the input is a checkbox
        if(inputs[i].getAttribute('type') == 'checkbox') {
            
            //create a new image
            var img = document.createElement('img');
            
            //check if the checkbox is checked
            if(inputs[i].checked) {
                img.src = imgTrue;
            } else {
                img.src = imgFalse;
            }

            //set image ID and onclick action
            img.id = 'checkImage'+i;
            //set image
            img.onclick = new Function('checkChange('+i+')');
            //place image in front of the checkbox
            inputs[i].parentNode.insertBefore(img, inputs[i]);
            
            //hide the checkbox
            inputs[i].style.display='none';
        }
    }
}

//change the checkbox status and the replacement image
function checkChange(i, d) {
	if(d != 2) {
		if(inputs[i].checked) {
			inputs[i].checked = '';
			document.getElementById('checkImage'+i).src=imgFalse;
		} else {
			inputs[i].checked = 'checked';
			document.getElementById('checkImage'+i).src=imgTrue;
		}
	} else {
		if(ch) {
			inputs[i].checked = '';
			document.getElementById('checkImage'+i).src=imgFalse;
		} else {
			inputs[i].checked = 'checked';
			document.getElementById('checkImage'+i).src=imgTrue;
		}	
	}
}

function checkAll() {
	 for(var i=0; i < inputs.length; i++) {
		 checkChange(i,2);
	 }
	 ch = !ch;
}

//Event.observe(window, 'load', init);

function checkDiscussionForm()
{
	var errors = false;
	
	//ckec title
	if($('discussion-title').value == '') { 
		errors = true; 
		$('error-discussion-title').show(); 
	} else {
		$('error-discussion-title').hide();
	}
	
	//check content
	if($('discussion-content').value == '') { 
		errors = true; 
		$('error-discussion-content').show(); 
	} else {
		$('error-discussion-content').hide();
	}
	
	//check themes
	var totalChecked = 0;
	$('new_discussion-form').getElements().each(
		function(element)
		{
			if (element.type == 'checkbox') {
				if (element.checked) {
					totalChecked++;
				}
			}
		}
	);
	
	if (totalChecked == 0) {
		errors = true;
		$('error-discussion-keywords').show();
	} else {
		$('error-discussion-keywords').hide();
	}
	
	if(!errors)
	{
	   $('new_discussion-form').submit();
	}
}

function checkGroupForm()
{
	var errors = false;
	if($('group-title').value == '') { errors = true; $('error-title').show(); } else {$('error-title').hide();}
	if($('group-content').value == '') { errors = true; $('error-content').show(); } else {$('error-content').hide();}
	if($('group-image').value == '') { errors = true; $('error-image').show(); } else {$('error-image').hide();}
	
	if(!errors)
	{
		var timer = setTimeout(function() {
			
			if($('group-submit-btn')){
				//alert('group-submit-btn');
				$('group-submit-btn').click();
			}else {
				//alert("soumission après 1 seconde");
				$('group-form').submit();
			}
		}, 1000);
		
	}
	//alert('fin checkGroupForm');
	return false;
}

function checkGroupFields()
{
	var result = true;
	
	if($('group-title').value == '')
	{
        $('error-title').show();
        result = false;
	}else  { $('error-title').hide(); } 
	
	if($('group-content').value == '')
	{
        $('error-content').show();
        result = false;
	}else { $('error-content').hide(); }
	
	return result;
}

function clearForm() {   
    $('discussion-title').value = '';
    $('discussion-content').value = ''; 
    
}

function clearDiscussionCommentForm() {   
    $('Votre').value = '';
    
}

function checkCommentForm() { 
    if($('Votre').value == '') { 
        $('votreErrorMessage').show(); 
        return false;
    } else {
        return true;
    }
}

function showGroupEdit()
{
	$('group-title-div').hide();
	$('discussion').hide();
	
	$('group-title-field').show();
	$('group-content-field').show();
	$('group-submit-btn').show();
}

function toggleGroupEditMode()
{
	$('group-title-div').toggle();
	$('discussion').toggle();
	
	$('group-title-field').toggle();
	$('group-content-field').toggle();
	$('group-submit-btn').toggle();
	$('group-cancel-btn').toggle();
	
	$('group-edit-link').toggle();
}

function toggleEnSaviorPlus()
{
	$('green-box-title').toggleClassName('green_box_title');
	$('green-box-title').toggleClassName('green_box_title_active');
	$('green-box-content').toggle();
}




