function popDiaGinecologista(){
    window.open(root+'site/inc/templates/pop_ginecologista.php','Popup','width=363px,height=500px');
} 

function zoom(tmp_src,tmp_w,tmp_h){
    if(tmp_w == null || tmp_h == null) {
	tmp_w = 500;
	tmp_h = 306;
    }
    var p = new Popup(tmp_w,tmp_h);
    p.overflow = 'hidden';
    p.position = "fixed";
    p.open(root+'site/inc/structure/zoom.php?src='+tmp_src);
}

function setaPadding(id,propriedade,valor){
    estilo = document.getElementById(id).style;

    if(propriedade == "padding-top")
    {
	estilo.paddingTop = valor;
    }
    else if(propriedade == "padding-right")
    {
	estilo.paddingRight = valor;
    }
    else if(propriedade == "padding-bottom")
    {
	estilo.paddingBottom = valor;
    }
    else if(propriedade == "padding-left")
    {
	estilo.paddingLeft = valor;
    }
}

Array.prototype.isIn = function(element) {
    for(var i=0; i<this.length;i++) {
	if(this[i] == element) {
	    return true;
	}
    }
    return false;
};
Array.prototype.doEach = function(func) {
    for(var i=0; i<this.length;i++) {
	func(this[i]);
    }
};
segundasPartes = [];
function showQuadroSegundaParte(idelemento) {
    for(var i=0; i<segundasPartes.length; i++) {
	if(segundasPartes[i].isIn(idelemento)) {
	    segundasPartes[i].doEach(showQuadro);
	} else {
	    segundasPartes[i].doEach(function(id){
		document.getElementById(id).style.display = 'none';
	    });
	}
    }
}

function showconteudos (i) {
    if (document.getElementById('conteudo'+i+'').style.display == 'none'){
	document.getElementById('conteudo'+i+'').style.display = '';
    }else{
	document.getElementById('conteudo'+i+'').style.display = 'none';
    }
	
}

function showQuadro(idelemento) {
    var elemento = document.getElementById(idelemento);

    if (elemento.style.display == '') {
	elemento.style.display = 'none';
    } else {
	elemento.style.display = '';
    }
}
function escondeContinua()
{
    document.getElementById('spanContinua').style.display = 'none';
}
function swapI(obj,focus){
    if(focus){
	if(obj.value == obj.attributes["label"].value){
	    obj.value = "";
	}
    } else {
	if(obj.value.trim() == ""){
	    obj.value = obj.attributes["label"].value;
	}
    }
}
function swapP(obj,focus){
    if(focus){
	var pass = document.getElementById(obj.attributes["parent"].value);
	if(pass){
	    obj.innerHTML = "";
	    pass.focus();
	}
    } else {
	if(obj.value == ""){
	    var div = document.getElementById("div"+obj.id);
	    if(div){
		div.innerHTML = obj.attributes["label"].value;
	    }
	}
    }
}

function alterarBannerTopo() {
    document.getElementById('div_bannertopo_'+banneratual).style.display = 'none';
    banneratual++;
    if (banneratual > bannertotal) {
	banneratual = 1;
    }
    document.getElementById('div_bannertopo_'+banneratual).style.display = '';
}
function passaCampo(id){
    if(id == "metro"){
	document.getElementById('centimetro').focus();
    }
    if(id == "centimetro" && document.getElementById(id).value.length == 2){
	document.getElementById('peso').focus();
    }
}

function calculaImc(){
    if(document.getElementById('peso').value == "")
	peso = 0;
    else
	peso = document.getElementById('peso').value;

    altura = (document.getElementById('metro').value+document.getElementById('centimetro').value)/100;
    imc = peso/ (altura*altura);
    imc = imc.toFixed(1).toString().replace(".",",");

    peso_min = Math.round(18.6*(altura*altura));
    peso_max = Math.round(24.6*(altura*altura));

    document.getElementById('resultadoimc').innerHTML = imc;
    document.getElementById('resultadomin').innerHTML = peso_min+" Kg";
    document.getElementById('resultadomax').innerHTML = peso_max+" Kg";
}
window.leiaMais = [];

function getFirstNotText(boxElement) {
    var children = boxElement.childNodes;
    for(var k=0; k<children.length;k++) {
	if(children[k] && children[k].nodeType && children[k].nodeType == 1) {
	    return children[k];
	}
    }
    return undefined;
}

function showLeiaMais(arr_leiaMais) {
    return function() {
	var displayDetails = (arr_leiaMais['isOpen']?'none':'block');
	var leiaMaisText =  (arr_leiaMais['isOpen']?'Leia mais...':'Fecha detalhes...');

	var forShow = arr_leiaMais['others'];
	for(var i=0; i<forShow.length; i++) {
	    forShow[i].style.display = displayDetails;
	}
	if(isIE) {
	    arr_leiaMais['leiamais'].innerText = leiaMaisText;
	} else {
	    arr_leiaMais['leiamais'].innerHTML = leiaMaisText;
	}
	arr_leiaMais['isOpen'] = !arr_leiaMais['isOpen'];
    }
}

window.onload = function() {

    var divs = document.getElementsByTagName('div');
    for(var i=0; i<divs.length; i++) {
	if(divs[i].getAttribute('name') && divs[i].getAttribute('name') == 'conteudoLeiaMais') {

	    var first = undefined;
	    var second = undefined;
	    var others = [];
	    var conteudo = divs[i];
	    var children = conteudo.childNodes;

	    for(var j=0; j<children.length; j++) {
		if(children[j].tagName && children[j].tagName.toLowerCase() == 'p' && !first) {
		    var firstChild = getFirstNotText(children[j]);

		    if(firstChild && firstChild.tagName &&
			(firstChild.tagName.toLowerCase() == 'strong' || firstChild.tagName.toLowerCase() == 'b')) {
			continue;
		    }
		    first = children[j];

		    first.style.display = '';
		} else if(children[j].tagName || children[j].style) {
		    if(first && !second) {
			second = children[j];
		    }
		    children[j].style.display = 'none';
		    others.push(children[j]);
		}
	    }

	    conteudo.style.display = '';
	    // adding the element Leia Mais..
	    if(second) {
		var arr_leiaMais = [];
		arr_leiaMais['first'] = first;
		arr_leiaMais['others'] = others;
		arr_leiaMais['isOpen'] = false;
		var leiaMais = document.createElement('p');
		leiaMais.style.display = 'block';
		leiaMais.className = 'continua';
		leiaMais.appendChild(document.createTextNode('Leia mais...'));
		first.appendChild(leiaMais);

		arr_leiaMais['leiamais'] = leiaMais;
		leiaMais.onclick = showLeiaMais(arr_leiaMais);
		//;
		window.leiaMais.push(arr_leiaMais);
	    }
	}
    }
};

