//ALTERACOES OK NO PORTAL

//Vars
var d = new Date();

//Construtor do objeto portal
function Portal() {};

//Função static que retorna hora, minuto e segundo
Portal.getTime = function() {
    var d = new Date();
    return d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
}

//Função que faz form com abas
Portal.prototype.doTabbedForm = function() {
    var j = 0;
    var k = arguments.length;
    var t = "<div id='tabs'><ul id='ultabs'>";
	
    for (a = 0; a < k; a++) {
		t += "<li><a href='#fragment-" + a + "'><span>" + arguments[a] + "</span></a></li>";	
    }
	
    t += "</ul></div>";
	
    jQuery(t).insertAfter("p.description");

    jQuery("#ultabs li").each(function(i){	
        jQuery('#tabs').append("<div id='fragment-" + i + "'></div>");
    });
    
    jQuery(".ctrl-holder").each(function(){
        if (jQuery(this).prev().is('.lfr-webform')) {
            if (jQuery(this).prev().text() == 'tesoura') {
                jQuery(this).prev().remove();
                jQuery("#fragment-" + j).append(jQuery("<br /><a id='my-text-link-" + j +"'>Pr&oacute;xima &raquo;</a>"));
                j++;
            } else {
                jQuery("#fragment-" + j).append(jQuery(this).prev());
            }
        }
        jQuery("#fragment-" + j).append(jQuery(this));
    });

    jQuery("#fragment-" + j).append(jQuery(".button-holder"));

    jQuery("a[id*='my-text-link-']").each(function() { 
        jQuery(this).click(function() {
            jQuery("#tabs").tabs('select', jQuery("#tabs").tabs('option', 'selected') + 1);
            return false;
        });
    });
	
	//Recurso Técnico Emergencial para o caso de paragrafos em sequencia.
	//Esse codigo: jQuery(".ctrl-holder").each(function(){ nao esta pegando os itens
	//quando o each tem mais de um seletor ex:("p,.ctrl-holder") 
	jQuery("label:contains('invisivel')").parent().css("display","none")
}

//Eventos
jQuery(document).ready(

	/*
	This function gets loaded when all the HTML, not including the portlets, is
	loaded.
	*/

	function() {
		//Propriedades static do objeto portal
		Portal.fullUserName = jQuery("#user-greeting>span").text();
		Portal.userDate = d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear();
		Portal.userBeginSessionTimeStamp = Portal.getTime();		
	}
);

Liferay.Portlet.ready(

	/*
	This function gets loaded after each and every portlet on the page.

	portletId: the current portlet's id
	jQueryObj: the jQuery wrapped object of the current portlet
	*/

	function(portletId, jQueryObj) {
	}
);

jQuery(document).last(

	/*
	This function gets loaded when everything, including the portlets, is on
	the page.
	*/

	function() {
	}
);