/*
*	Coordinadora de Son Bruc i Ruma
*  	common.js
*/

var acr;

function initNewsSection(nnews){
	acr = new acord();
	for(x = 0; x < nnews; x++){
		acordx = document.getElementById('nw' + x);
		acordx.style.height = acordx.offsetHeight + 'px';
		acordx.style.display = 'none';
	}
}

function showField(value){
	document.getElementById('pentity').className = (value == 1) ? "vest dis" : "ndis";
}

function checkForm(frm){
	
	if(frm.accept.checked){
		tosubmit = true;	
	}else{
		remarkBox();
		tosubmit = false;
	}
	
	return tosubmit;
}

function remarkBox(){
	document.getElementById('acceptbox').className = "noaccept";
	setTimeout("document.getElementById('acceptbox').className = 'accept'", 500);
	setTimeout("document.getElementById('acceptbox').className = 'noaccept'", 1000);
	setTimeout("document.getElementById('acceptbox').className = 'accept'", 1500);
	setTimeout("document.getElementById('acceptbox').className = 'noaccept'", 2000);	
	setTimeout("document.getElementById('acceptbox').className = 'accept'", 2500);
}

function showBodyNew(atag, ncon){
	var nw = document.getElementById(ncon);	
	if(atag.innerHTML != "Amagar"){
		acr.active(ncon);
 		atag.innerHTML = "Amagar";
	}else{
		acr.active(ncon);
		atag.innerHTML = "Mostrar";
	}
}

acord = function(){ 
	this.steps = 12;
	this.duration = 600;
	this.stepCounter = 0;
	this.sizec = null;
	this.sizeo = null;
	this.stepGrow = null;
	this.interval = this.duration / this.steps;
	this.panc = null;
	this.grows = false;	

	acord.prototype.active = function (idac){
		this.panc = document.getElementById(idac);
		if(this.panc.style.display == 'none'){
			this.sizec = 0;
			this.sizeo = parseInt(this.panc.style.height);
			this.panc.style.height = 0 + 'px';
			this.panc.style.display = 'block';
			this.stepGrow = this.sizeo / this.steps;	
			this.grows = true;
		}else{
			clientHeight = this.panc.offsetHeight;
			this.sizeo = clientHeight;
			this.sizec = clientHeight;
			this.panc.style.height = this.sizec + 'px';
			this.panc.style.display = 'block';
			this.stepGrow = this.sizeo / this.steps;
			this.grows = false;
		}
		this.stepAnimation();
	}
	
	acord.prototype.stepAnimation = function (){
		++this.stepCounter;
		this.animate();
		(this.stepCounter >= this.steps) ? this.terminated() : this.start();
	}
	
	acord.prototype.start = function (){
		var self = this;
		setTimeout(function() { self.stepAnimation(); }, this.interval);
	}
	
	acord.prototype.downArrow = function(){ }
	
	acord.prototype.animate = function (){
		this.sizec = this.grows ? (this.sizec + this.stepGrow) : (this.sizec - this.stepGrow);		
		this.panc.style.height = this.sizec + "px";
	}
	
	acord.prototype.terminated = function(){
		if(!this.grows) this.panc.style.display = "none";
		this.panc.style.height = this.sizeo + 'px';
		this.stepCounter = 0;
	}
} 
