// JavaScript Document

var overacting = false;

function showHideFaqItem(faqId) {
	if (!overacting) {
		var element = $('faqsAnswer'+faqId);
		var scrollDiv = $('faqsScroll');
		overacting = true;
		if (element.style.display=='none') {
			Effect.BlindDown('faqsAnswer'+faqId,{duration: 0.1});
		}else{
			Effect.BlindUp('faqsAnswer'+faqId,{duration: 0.1});
		}
		setTimeout(function () { overacting = false;},100);
		setTimeout(function () {if(scrollDiv.scrollUpdate) scrollDiv.scrollUpdate();},110);
	}
}

/* BEGIN userRegisterForm */
function register_validate() {
    var userRegister;
	
	Validation.add('validate-username', 'Este campo tem de ter entre 6 e 32 caracteres.', {
		 minLength : 6, // value must be at least 6 characters
		 maxLength : 32 // value must be at least 6 characters
	});

	Validation.add('validate-password', 'Este campo tem de ter entre 6 e 64 caracteres e n&atilde;o pode ser igual ao nome de utilizador.', {
		 minLength : 6, // value must be at least 6 characters
		 maxLength : 64, // value must be at least 6 characters
		 notEqualToField : 'username' // value is not equal to the form element with this ID
	});
	
	Validation.add('validate-confirm-password', 'A password confirmada deve ser igual &aacute; introduzida.', {
		 equalToField : 'password' // value is equal to the form element with this ID
	});

	userRegister = new Validation('userRegister'); // OR new Validation(document.forms[0]);
	return userRegister.validate();
}
/* END userRegisterForm */

/* BEGIN recoverPasswordForm */
function recoverPassword_validate() {
    var recoverPasswordForm;
	
	recoverPasswordForm = new Validation('recoverPasswordForm'); // OR new Validation(document.forms[0]);
	return recoverPasswordForm.validate();
}
/* END recoverPasswordForm */

/* BEGIN recoverPasswordForm2 */
function recoverPassword2_validate() {
    var recoverPasswordForm;

	Validation.add('validate-password', 'Este campo tem de ter entre 6 e 64 caracteres.', {
		 minLength : 6, // value must be at least 6 characters
		 maxLength : 64 // value must be at least 6 characters
	});
	
	Validation.add('validate-confirm-password', 'A password confirmada deve ser igual &aacute; introduzida.', {
		 equalToField : 'pass' // value is equal to the form element with this ID
	});
	
	recoverPasswordForm = new Validation('recoverPasswordForm'); // OR new Validation(document.forms[0]);
	return recoverPasswordForm.validate();
}
/* END recoverPasswordForm2 */

/* BEGIN userEditForm */
function userEdit_validate() {
    var userEdit;
	
	Validation.add('validate-username', 'Este campo tem de ter entre 6 e 32 caracteres.', {
		 minLength : 6, // value must be at least 6 characters
		 maxLength : 32 // value must be at least 6 characters
	});

	userEdit = new Validation('userEdit'); // OR new Validation(document.forms[0]);
	return userEdit.validate();
}
/* END userEditForm */

/* BEGIN userEditPassForm */
function userEditPass_validate() {
    var userEdit;
	
	Validation.add('validate-password', 'Este campo tem de ter entre 6 e 64 caracteres.', {
		 minLength : 6, // value must be at least 6 characters
		 maxLength : 64 // value must be at least 6 characters
	});
	
	Validation.add('validate-confirm-password', 'A password confirmada deve ser igual &aacute; introduzida.', {
		 equalToField : 'password' // value is equal to the form element with this ID
	});

	userEdit = new Validation('userEditPass'); // OR new Validation(document.forms[0]);
	return userEdit.validate();
}
/* END userEditPassForm */

/* BEGIN contactForm */
function contactForm_validate() {
    var contactForm;
	
	contactForm = new Validation('contactForm'); // OR new Validation(document.forms[0]);
	return contactForm.validate();
}
/* END contactForm */

/* BEGIN showHideProductCat */
function showHideProductCat(catId) {
	if (!overacting) {
		var element = $('productCat'+catId);
		var typeItems = $('catTypeItems'+catId);
		overacting = true;
		//alert(element.style.overflow);
		if (parseInt(typeItems.value,10)!=0) {
			if (element.style.overflow != 'visible') {
				var topValue = parseInt(typeItems.value,10)*20+25;
				element.style.top = '-'+topValue+'px';
				element.style.overflow = 'visible';
			}else{
				element.style.top = '-21px';
				element.style.overflow = 'hidden';
			}
		}
		overacting = false;
	}
}
/* END showHideProductCat */

/* BEGIN hideProductCat */
function hideProductCat(catId) {
	if (!overacting) {
		var element = $('productCat'+catId);
		overacting = true;

		element.style.top = '-16px';
		element.style.overflow = 'hidden';
		overacting = false;
	}
}
/* END hideProductCat */

/* BEGIN pagination */
function updatePagination(actualIndex) {
	if (!overacting) {
		var paginationItems = parseInt($('paginationTotalItems').value,10);
		overacting = true;
		for (var i=1; i<=paginationItems; i++) {
			$('paginationItem'+i).className = 'none';
		}

		for (var i=actualIndex; i<actualIndex+3; i++) {
			if ($('paginationItem'+(i+1)))
				$('paginationItem'+(i+1)).className = 'selected';
		}
		overacting = false;
	}	
}
/* END pagination */