function ampliar(id, pw, ph, base)
{
	if (pw > 760)
		pw = 760;
	if (ph > 570)
		ph = 570;

	w = (screen.width-30);
	w = pw+10 > w ? w : pw+10;
	h = (screen.height-30);
	h = ph+10 > h ? h : ph+10;
	
	janela = window.open('about:blank','pict_big','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,menubar=no,width='+(w)+',height='+(h)+',top='+(((screen.height-h)/2)-30)+',left='+(((screen.width-w)/2)-10))
	janela.document.write('<HTML><TITLE>Imagem ampliada</TITLE>');
	janela.document.write('<BODY style="margin: 0px; padding: 0px">');
	janela.document.write('<TABLE BORDER=0 cellpadding=0 cellspacing=0 width=100% height=100%><TR><TD width=100% height=100% align=center valign=middle>');
	janela.document.write('<A HREF="" onclick="window.close(); return false"><IMG id=pic ALT="Clique para fechar" SRC="' + base + 'ModuleHandlers/Content/picture.aspx?idContentPicture=' + (id) + '&w='+(janela.document.body.clientWidth-10)+'&h='+(janela.document.body.clientHeight-10)+'" BORDER=0 style="border: 1px solid gray"></a>');
	janela.document.write('</TD></TR></TABLE></BODY></HTML>');	
	
	janela.focus()
	
}
function textControlKeyPress(sender, tipo, base)
{
	if (event.keyCode == 13)
		calculaIMC(base);
		
	if (tipo == 'peso')
		return ((event.keyCode >= 48) && (event.keyCode <= 57));
	else if (tipo == 'altura')
	{
		result = (((event.keyCode >= 48) && (event.keyCode <= 57)) || (event.keyCode == 46) || (event.keyCode == 44));
		if ((result) && ((event.keyCode == 46) || (event.keyCode == 44)) && (((sender.value.indexOf('.') > -1) || (sender.value.indexOf(',') > -1))))
			result = false;
		if ((result) && ((event.keyCode == 46) || (event.keyCode == 44)) && (sender.value == ''))
			result = false;
		return result;
	}
	else
		return true;
}
function calculaIMC(base)
{
	peso = document.imc.txtPeso.value;
	altura = document.imc.txtAltura.value;
	altura = altura.replace(',', '.');
	
	if ((peso == '') || (parseFloat(peso) < 10) || (parseFloat(peso) > 500))
	{
		alert('Por favor informe seu peso corretamente.');
		document.imc.txtPeso.focus();
		document.imc.txtPeso.select();
		return;
	}
	
	if ((altura == '') || (parseFloat(altura) < 0.5) || (parseFloat(altura) > 3))
	{
		alert('Por favor informe sua altura corretamente.');
		document.imc.txtAltura.focus();
		document.imc.txtAltura.select();
		return;
	}

	window.frames['ifcontent'].location = base + 'imc.aspx?peso=' + (peso) + '&altura=' + (altura);
}

/* Controle das imagens animadas */

var outItens;
var automatic = 1;
var slideTime = 10000;
var speed = 100;
var changingImage = 0;
var outItemIndex = -1;
var newIndex = -1;
var changeStep = 0;
var changeDirection = 1;

function getel(id) {
    return document.getElementById(id);
}

function el(id) {
    return document.getElementById(id);
}

function matriz(n)  {
   this.length=n
   for (var i=0;i<n;i=i+1)  {
     this[i] = ''
   }
}

function addOutItem(idContent, idContentPicture)
{
	outItens.length++;
	outItens[outItens.length-1] = new matriz(3);
	outItens[outItens.length-1].idContent = idContent;
	outItens[outItens.length-1].idContentPicture = idContentPicture;
}

function initOutdor(picturesCount, auto, slide_time, slide_change_speed)
{
	automatic = auto;
	slideTime = slide_time;
	speed = slide_change_speed;
	
	outItens = new matriz(0);
}

function initOutdor2()
{
	setTimeout('loadPictures()', 100);
	setTimeout('changePicture(1, false)', 100);
}

function loadPictures()
{
	for (i=0; i<outItens.length; i++)
	{
		if (!(outItens[i].ok))
		{
			// verifica se a imagem anterior já foi carregada
			if ((i > 0) && !(outItens[i-1].img.complete))
			{
				setTimeout('loadPictures()', 100);
				break;
			}
			else
			{
				outItens[i].img = newImage(getSrc(outItens[i].idContentPicture));
				outItens[i].ok = 1;
			}
		}
	}
}

function changePicture(forward, byUser, destindex)
{
	if ((changingImage) && (byUser))
		return;

	if (byUser)
		automatic = 0;
		
	img = getel('outPicture');
	
	if (newIndex == outItemIndex)
	{
		newIndex = outItemIndex;
		if (forward)
		{
			newIndex++;
			if (newIndex >= outItens.length)
				newIndex = 0;
		}
		else if (typeof(destindex) != "undefined")
		{
			newIndex = destindex;
		}
		else
		{
			newIndex--;
			if (newIndex < 0)
				newIndex = outItens.length-1;
		}
	}
	
	if ((outItens[newIndex].ok) && (outItens[newIndex].img.complete))
	{
		changingImage = 0;
		
		if ((!byUser) && (outItemIndex > -1))
			slowChange(1);
		else
			show(newIndex);
		
		outItemIndex = newIndex;
		
		if (automatic)
			setTimeout('changeSlide()', slideTime);
	}
	else
	{
		img.src = "images/blank.gif";
		changingImage = 1;
		setTimeout('changePicture(' + (forward) + ', 0)', 100);
	}
}

function getSrc(id)
{
	return 'controles/foto.aspx?idContentPicture=' + id;
}

function slowChange(start)
{
	try
	{
		oDiv = getel('divSlide');
		oDiv.style.filter="blendTrans(duration=2)";
   		oDiv.filters.blendTrans.apply();
		oDiv.filters.blendTrans.play();
		show(newIndex);
	}
	catch(e)
	{
		show(newIndex);
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeSlide()
{
	if (automatic)
		changePicture(1, 0);
}

function show(index)
{
	getel('outPicture').src = getSrc(outItens[index].idContentPicture);
}

/* ------------------------------------- */

function escreve(s)
{
	document.write(s);
}


var menus = new arr(0);
nie = (navigator.appName.indexOf("Microsoft") == -1);
function arr(n)  {
   this.length=n
   for (var i=0;i<n;i=i+1)  {
     this[i] = ''
   }
}
/* 29/09/2008 */
function escreveFlash(id, src, width, height, align, salign, transparent, mozila, versao, onmouseover, onmouseout, style) {
    s = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + (versao) + ',0,0,0" width="' +
        (width) + '" height="' + (height) + '" id="' +
        id + '" ' + (align != '' ? 'align="' + align + '"' : '') +
        (onmouseover != '' ? ' onmouseover="' + onmouseover + '"' : '') +
        (onmouseout != '' ? ' onmouseout="' + onmouseout + '"' : '') +
        (typeof (style) != "undefined" ? ' style="' + style + '"' : '') +
        '><param name="quality" value="high" />' +
        (src != '' ? '<param name="movie" value="' + src + '" />' : '') +
        (salign != '' ? '<param name="salign" value="' + salign + '" />' : '') +
        (transparent ? '<param name="wmode" value="transparent" />' : '') +
        '<param name="menu" value="false" /><param name="scale" value="noscale" />';
    if (mozila)
        s += '<embed ' +
            (src != '' ? 'src="' + src + '" ' : '') +
            'loop="false" menu="false" quality="high" scale="noscale" width="' +
            (width) + '" height="' + (height) + '" name="' + id + '" ' +
            (align != '' ? 'align="' + align + '" ' : '') +
            (salign != '' ? 'salign="' + salign + '" ' : '') +
            (onmouseover != '' ? 'onmouseover="' + onmouseover + '" ' : '') +
            (onmouseout != '' ? 'onmouseout="' + onmouseout + '" ' : '') +
            (transparent ? 'wmode="transparent" ' : '') +
            'allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swliveconnect="true" />';
    s += '</object>';
    escreve(s);
}

function loadFlashWithPreload(id, src, preloadId, paramsStr) {
    preloaded = movieIsLoaded(mv(preloadId));
    loaded = movieIsLoaded(mv(id));

    if ((!loaded) && (preloaded)) {
        cmd = 'loadMovie(\'' + id + '\', \'' + src + '\', [' + paramsStr + '])';
        setTimeout(cmd, 1);
        setTimeout(cmd, 500);
    }

    paramsStr = paramsStr.replace(/\'/g, '\\\'');
    cmd = 'loadFlashWithPreload(\'' + id + '\', \'' + src + '\', \'' + preloadId + '\', \'' + paramsStr + '\')';

    if ((loaded) && (nie))
        setTimeout(cmd, 1000);
    else if (!loaded)
        setTimeout(cmd, 100);

}

function mv(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return document.all[movieName]
    } else {
        return document[movieName]
    }
}

function loadMovie(id, movie, params) {
    mv(id).LoadMovie(0, movie);
    for (p = 0; p < params.length; p += 2)
        mv(id).SetVariable(params[p], params[p + 1]);
}

function loadMovieWithDelay(id, movie, paramsStr) {
    cmd = 'loadMovie(\'' + id + '\', \'' + movie + '\', ' + paramsStr + ')';
    setTimeout(cmd, 500);
}

function movieIsLoaded(theMovie) {
    if (typeof (theMovie) != "undefined") {
        return ((typeof (theMovie.PercentLoaded) != "undefined") && (theMovie.PercentLoaded() == 100));
    } else {
        return false;
    }
}

function movieIsReady(theMovie) {
    return (typeof (theMovie.PercentLoaded) != "undefined");
}

function getAjax() {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType("text/html; charset=windows-1252");
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    if (!http_request) {
        alert('Desculpe, seu navegador é incompatível com este recurso.');
        return false;
    }
    return http_request;
}