function showAndHide(sElementToShow, sElementToHide){
    new Effect.Appear(sElementToShow);
    new Effect.Fade(sElementToHide);
}

/**
 * Change Input Text
 */
var Procommunity = Class.create();
Procommunity.changeVisibilityInputText = Class.create();
Procommunity.changeVisibilityInputText.prototype = {
    initialize: function(form, field, fieldSubmit, emptyText){
        this.form = $(form);
        this.buttonSubmit = $(fieldSubmit);
        this.field = $(field);
        this.emptyText = emptyText;
        
        Event.observe(this.form, 'submit', this.submit.bind(this));
        Event.observe(this.buttonSubmit, 'click', this.click.bind(this));
        Event.observe(this.field, 'focus', this.focus.bind(this));
        Event.observe(this.field, 'blur', this.blur.bind(this));
        this.blur();
    },
    
    submit: function(event){
        if (this.field.value == this.emptyText || this.field.value == '') {
            Event.stop(event);
            return false;
        }
        return true;
    },
    
    click: function(event){
        if (this.submit(event)) 
            this.form.submit();
    },
    
    focus: function(event){
        if (this.field.value == this.emptyText) {
            this.field.value = '';
        }
        
    },
    
    blur: function(event){
        if (this.field.value == '') {
            this.field.value = this.emptyText;
        }
    }
}


Procommunity.checkboxManageMark = Class.create();
Procommunity.checkboxManageMark.prototype = {

    initialize: function(sClassName, sSwitcher){
    	this.className = sClassName;
		this.switcher = $(sSwitcher);
		this.checkboxes = $A(document.getElementsByClassName(sClassName));
		Event.observe(this.switcher, 'click', this.click.bind(this));
	},
	
	click: function() {
		if (this.switcher.checked == '')
			this.unmark();
		else
			this.mark();
	},
	
	mark: function() {
		this.checkboxes.each(function(checkbox) {
			checkbox.checked = "checked";
		});
	},
	
	unmark: function() {
		this.checkboxes.each(function(checkbox) {
			checkbox.checked = "";
		});
	}
 };

Procommunity.submitForm= Class.create();
Procommunity.submitForm.prototype = {

    	initialize: function(sFormId, sLang){
			this.temp = 0;
			
			for (i=0; i<$(sFormId).elements.length; i++){
				if ($(sFormId).elements[i].checked) {
					this.temp = this.temp + 1;
				}
			}
			
			$(sFormId).onsubmit = function(){
				return true;
			}
		
			if(this.temp > 0) {
				$(sFormId).submit();
			} else {
				alert(sLang);
				return false;
			}
    	}
}

Procommunity.textAreaMax = Class.create();
Procommunity.textAreaMax.prototype = {

    initialize: function(oTextarea, iMax, oTextareaLengthHolder){
        this.textarea = $(oTextarea);
        this.max = iMax;
        this.textareaLengthHolder = $(oTextareaLengthHolder);
		this.textareaLengthHolder.value = iMax;
        Event.observe(this.textarea, 'keyup', this.keypress.bind(this));
        Event.observe(this.textarea, 'keydown', this.keypress.bind(this));
    },
    
    keypress: function(){
		if (this.textarea.value.length > this.max) 
            this.textarea.value = this.textarea.value.substring(0, this.max);
			
		this.textareaLengthHolder.value = this.max - this.textarea.value.length;
    }
}

function addPostParam(sParams, sParamName, sParamValue, sSeparator) {
	if(sParams.length > 0){
		sParams += "&";
	}
	return sParams + encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
};

function addURLParam(sURL, sParamName, sParamValue, bRewrite){
	if(typeof bRewrite != "undefined" && bRewrite == true){
		sURL += (sURL.lastIndexOf("/") == sURL.length ? "" : "/");
		sURL += encodeURIComponent(sParamName) + "/" + encodeURIComponent(sParamValue);
	} else {sURL += (sURL.indexOf("?") == -1 ? "?" : "&");
		sURL += encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
	}
	return sURL;
}
