nie = (navigator.appName.indexOf("Microsoft") == -1);

function getel(doc, id)
{
    return doc.getElementById(id);
}

function el(id)
{
    return getel(document, id);
}

function escreve(s)
{
	document.write(s);
}

function adjust1()
{
    if (el('k0'))
        el('k0').style.display = 'none';
    if (el('k1'))
        el('k1').style.display = 'none';
    if (el('k2'))
        el('k2').style.display = 'none';
    if (el('lr'))
        el('lr').style.display = 'none'
}

function arr(n)  {
   this.length=n
   for (var i=0;i<n;i=i+1)  {
     this[i] = ''
   }
}

function element_top(el)
{
	var et = 0
	while (el)
	{
		et += el.offsetTop
		el = el.offsetParent
	}
	return et
}

function element_left(el)
{
	var et = 0
	while (el)
	{
		et += el.offsetLeft
		el = el.offsetParent
	}
	return et
}

/* 19/05/2008 */
function escreveFlash(id, src, width, height, align, salign, transparent, mozila, versao, onmouseover, onmouseout)
{
    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 + '"' : '') +
        '><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 if (document[movieName])
        return document[movieName]
    else
        return el(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") && (theMovie != null)) {
	return ((typeof(theMovie.PercentLoaded) != "undefined") && (theMovie.PercentLoaded() == 100));
  } else {
    return false;
  }
}

function movieIsReady (theMovie) {
	return (typeof(theMovie.PercentLoaded) != "undefined");
}

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 newImage(arg) {
	if (document.images) {  
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function imprime() {
    window.focus();
	setTimeout("window.print()", 500);
}

var ie5=document.all && !window.opera
var lastHeight = 0;
var autoHeight = 1;
var autoHSet = 0;
function adjustIFrameSize () 
{
    if (!el('ct'))
        return;
        
	iframeElement = getel(window.parent.document, 'ifcontent');
	iframeWindow = window.parent.frames[name];
	if (nie)
	{
        iframeElement.style.height = '';
    }
    h = 0;
    hMin = 0;
    h = el('ct').offsetHeight;

    hMin = 300;
    h = h > hMin ? h : hMin;

    if (el('sidebar-wrapper') && el('fBuscaInt')) {
        hMin = el('sidebar-wrapper').offsetHeight + 80;
        h = h > hMin ? h : hMin;
    }

    lastHeight = h;
	
	iframeElement.style.height = (h) +'px';

	if ((autoHeight) && (!autoHSet))
	{
	    autoHSet = 1;
	    setTimeout('autoH()', 500);
	}
}

function autoH()
{
    h = el('ct').offsetHeight;
    hMin = 300;
    h = h > hMin ? h : hMin;

    if (el('sidebar-wrapper') && el('fBuscaInt')) {
        hMin = el('sidebar-wrapper').offsetHeight + 80;
        h = h > hMin ? h : hMin;
    }

	if (h != lastHeight)
	{
        scrollPos = window.parent.document.documentElement.scrollTop;
		adjustIFrameSize();
	    window.parent.document.documentElement.scrollTop = scrollPos;
	}
    setTimeout('autoH()', 500);
}

var elementosFonte = '';
function fonte(aumenta)
{
    // default
    dif = Number(readCookie('fontSize'));
    
    els = elementosFonte.split(',');

    for (i=0; i<els.length; i++)
    {
        df = el(els[i]);
        if (!df)
            continue;
	    def = Number(df.getAttribute('default-font', 0));
	    if (aumenta > -1)
	    {
    	    size = Number(df.style.fontSize.substr(0, df.style.fontSize.length-2));
    	    dif = size - def;
    	}
    	else
    	{
            dif = Number(readCookie('fontSize'));
    	    size = def+dif;
        }
        //alert(els[i] + ' default: ' + (def) + ' atual: ' + (size));
        
	    if (aumenta > -1)
	    {
	        if ((dif <= 0) && !aumenta)
	        {
		        alert(fonteMinTxt);
		        return;
	        }
	        if ((dif >= 4) && aumenta)
	        {
		        alert(fonteMaxTxt);
		        return;
	        }
	        if (aumenta)
		        size++;
	        else
		        size--;
		}
		
		dif = size-def;

	    df.style.fontSize = (size) + "px";
	}
	
    var expire = new Date();
    expire.setTime(new Date().getTime() + 3600000*24*5000);
    document.cookie = 'fontSize'+"="+escape((dif) + '')+ ";expires="+expire.toGMTString();
    
    adjustIFrameSize();
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function indica()
{
	ifc = window.parent.frames['ifcontent'];
	iurl = 'indique.aspx?1=1';
	if (ifc)
	{
	    if (ifc.idcontent != 0)
		    iurl += '&idContent=' + (ifc.idcontent);
	    if (ifc.idcontentsection != 0)
		    iurl += '&idContentSection=' + (ifc.idcontentsection);
	    ifc.location = htmlbase + iurl;
	}
	else
	    window.location = iurl;
}

function abreGaleria(id, idContentPicture)
{
	janela = window.open(htmlbase + 'galeria.aspx?idContent=' + (id) + (typeof(idContentPicture) != 'undefined' ? '&idContentPicture=' + (idContentPicture) : ""),'galeria','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,menubar=no,width=611,height=477,top='+((screen.height-477)/2)+',left='+((screen.width-611)/2));
	janela.focus();
	return false;
}

function busca(ifc)
{
    s = 'busca.aspx?p=' + document.forms['fbusca'].p.value;
    abre(s, ifc);
}

function cadastraNews(ifc)
{
    s = 'maillist.aspx?email=' + document.forms['fnews'].email.value;
    abre(s, ifc);
}

function abre(url, ifc)
{
    if (ifc)
        window.parent.frames['ifcontent'].location = url;
    else
        window.location = 'padrao.aspx?' + url;
}


function amplia2(id, pw, ph, text)
{
    wp = window.parent;
    wpd = wp.document;
    ov = getel(wpd, 'overlay');
    amp = getel(wpd, 'ampliacao');
    ampi = getel(wpd, 'ampliInner');
    img = getel(wpd, 'imgAmpliar2');
    txt = getel(wpd, 'ampliText');
    
    ampi.style.width = (pw+12) + 'px';
    ov.style.height = (wpd.documentElement.scrollHeight) + 'px';
    img.src = wp.htmlbase + 'images/blank.gif';
    txt.style.display = (text != '' ? 'block' : 'none');
    txt.innerHTML = text;

    th = wpd.documentElement.clientHeight;
    th = ((th - ph - 12 - 18 - 3) / 2) - 20;
    if (th < 0)
        th = 0;
    th = th + window.parent.document.documentElement.scrollTop;
    ampi.style.marginTop = (th) + 'px';
    
    ov.style.display = 'block';
    amp.style.display = 'block';

    img.src = wp.htmlbase + 'ModuleHandlers/Content/picture.aspx?idContentPicture=' +
        (id) + '&w=' + (pw) + '&h=' + (ph);
}

function fechaAmpliar2()
{
    wp = window.parent;
    wpd = wp.document;
    img = getel(wpd, 'imgAmpliar2');
    txt = getel(wpd, 'ampliText');
    ov = getel(wpd, 'overlay');
    amp = getel(wpd, 'ampliacao');
   
    ov.style.display = 'none';
    amp.style.display = 'none';
    img.src = '';
    txt.innerHTML = '';
}


// *********************************************************************************************************************

activeHint = 0;
activeMenu = 0;

function abreMenu(e, id) {
    window.isOverButton = id;
    window.isOverMenu = 0;
    showmenu(e, eval('ms' + id), id);
}
function fechaMenu(id, subitens) {
    if (id == window.isOverButton) {
        window.isOverButton = 0;
        delayhidemenu();
    }
}

var defaultMenuWidth = 120;

var ie5 = document.all && !window.opera
var ns6 = document.getElementById

// já escrito. problema de posicionamento
dsm = ie5 ? document.all.divSubMenu : document.getElementById("divSubMenu")

function iecompattest() {
    return (document.compatMode && document.compatMode.indexOf("CSS") != -1) ? document.documentElement : document.body
}

function showmenu(e, which, id) {
    hidemenu();
    mv('m' + id).SetVariable('hideOver', 'no');
    mv('m' + id).SetVariable('isOverSub', 'yes');
    activeMenu = id;
    src = ie5 ? e.srcElement : e.target;
    if (!document.all && !document.getElementById)
        return
    clearhidemenu()
    menuobj = ie5 ? document.all.divSubMenu : document.getElementById("divSubMenu")
    menuobj.innerHTML = '<table id=tbMenu border=0 cellpadding=0 cellspacing=0>' + which + '</table>';
    menuobj.style.width = (getel(document, 'tbMenu').offsetWidth > defaultMenuWidth ? getel(document, 'tbMenu').offsetWidth : defaultMenuWidth) + "px";
    getel(document, 'tbMenu').style.width = menuobj.style.width;

    //menuobj.style.width=defaultMenuWidth;
    menuobj.contentwidth = menuobj.offsetWidth
    menuobj.contentheight = menuobj.offsetHeight

    menuobj.style.top = element_top(src) - 0 + "px";
    menuobj.style.left = element_left(src) + 137 + "px";

    menuobj.style.visibility = "visible"
    return false
}

function contains_ns6(a, b) {
    while (b.parentNode)
        if ((b = b.parentNode) == a)
        return true;
    return false;
}

function hidemenu() {
    if (window.menuobj) {
        menuobj.style.visibility = "hidden"
        ho = getel(document, 'hint' + (activeMenu));
        mv('m' + activeMenu).SetVariable('isOverSub', 'no');
        mv('m' + activeMenu).SetVariable('hideOver', 'yes');
        if (ho)
            ho.style.visibility = 'hidden';
    }
}

function dynamichide(e) {
    if (!window.isOverButton) {
        if (ie5 && !menuobj.contains(e.toElement))
            hidemenu()
        else if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))
            hidemenu()
    }
}

function delayhidemenu() {
    if (!window.isOverMenu)
        window.delayhide = setTimeout("hidemenu()", 500)
}

function clearhidemenu() {
    if (window.delayhide)
        clearTimeout(delayhide)
}

function changeHint(id, show) {
    if (show) {
        activeHint = id;
        clearTimeout('showHint()');
        setTimeout('showHint()', 300);
    }
}

if (ie5 || ns6)
    document.onclick = hidemenu

/* ----------------------------------------------- */

var bannerIndex = -1;
var allBannersCreated = 0;
var bannerAutoChangeDelay = 4000;
var loadAllBannersIndex = 1;
function loadBanners() {

    if (banners.length == 0)
        return;

    criaBanner(banners[0], 'banner0');
    if (banners.length > 1)
        setTimeout('loadAllBanners()', 500);

    trocaBanner(1, 1, -1);
}

function criaBanner(html, id) {
    el('banner').innerHTML += html;
}

function loadAllBanners() {
    if (bannerIsLoaded('banner0') || nie) {
        criaBanner(banners[loadAllBannersIndex], 'banner' + (loadAllBannersIndex));
        if (loadAllBannersIndex < banners.length - 1) {
            loadAllBannersIndex++;
            setTimeout('loadAllBanners()', 100);
        }
        else
            allBannersCreated = 1;
    }
    else
        setTimeout('loadAllBanners()', 500);
}


function bannerIsLoaded(id) {
    if ((el(id).tagName == 'EMBED') || (el(id).tagName == 'OBJECT'))
        return movieIsLoaded(mv(id));
    else if (el(id).tagName == 'IMG')
        return el(id).complete;
}

var oldBannerIndex;
function trocaBanner(avanca, fast, novoIndice) {

    if ((!allBannersCreated) && (bannerIndex != -1))
        return;

    oldBannerIndex = bannerIndex;

    if (avanca > -1) {
        if (avanca)
            bannerIndex++;
        else
            bannerIndex--;

        if (bannerIndex == -1)
            bannerIndex = banners.length - 1;
        else if (bannerIndex >= banners.length)
            bannerIndex = 0;
    }
    else if (novoIndice > -1) {
        bannerIndex = novoIndice;
    }

    if (bannerIndex > -1) {
        if (!bannerIsLoaded('banner' + (bannerIndex)) && (oldBannerIndex > -1)) {
            el('divbanner' + (oldBannerIndex)).style.display = 'none';
        }
    }

    mostraBanner(fast);
}

function avancaBanner(avanca) {
    trocaBanner(avanca, 0, -1);
}

function vaiParaBanner(indice) {
    if (bannerIndex > -1) {
        if (bannerIndex != indice) {
            trocaBanner(-1, 0, indice);
            return false;
        } else {
            return true;
        }
    }
    else {
        return false;
    }
}

var timeoutid;
function mostraBanner(fast) {
    if (bannerIsLoaded('banner' + (bannerIndex))) {
        if ((!nie) && (!fast)) {
            oDiv = el('banner');
            oDiv.style.filter = "blendTrans(duration=1.0)";
            oDiv.filters.blendTrans.apply();
            oDiv.filters.blendTrans.play();
        }
        if (oldBannerIndex > -1)
            el('divbanner' + (oldBannerIndex)).style.display = 'none';
        el('divbanner' + (bannerIndex)).style.display = 'block';
        if (timeoutid)
            clearTimeout(timeoutid);
        timeoutid = setTimeout('trocaBanner(1, 0, -1)', bannerAutoChangeDelay);
    }
    else {
        if (nie) {
            if (oldBannerIndex > -1)
                el('divbanner' + (oldBannerIndex)).style.display = 'none';
            el('divbanner' + (bannerIndex)).style.display = 'block';
            timeoutid = setTimeout('trocaBanner(1, 0, -1)', bannerAutoChangeDelay);
        }
        else
            setTimeout('mostraBanner(' + (fast) + ')', 100);
    }
}

/* ----------------------------------------------- */

var estiloAtivo = '';
var idiomaAtivo = '';
function mainAdjust(estilo, idioma) {

    if ((estilo != estiloAtivo) || (idioma != idiomaAtivo)) {

        main = estilo == 'index';
        
        divContent = el('content');
        divOW = el('outdoor-wrapper');
        img1 = el('imgCab1');
        img2 = el('imgCab2');
        a2 = el('aCab2');

        divOW.style.height = main ? '194px' : '118px';
        divOW.style.borderBottom = main ? '4px solid white' : '3px solid white';
        divContent.style.backgroundImage = 'url(' + (main ? 'images/bg_content.gif' : 'images/bg_content_interna.gif') + ')';

        a2.href = '';
        if (main) {
            img1.src = 'images/cab/index/outdoor_' + idioma + '.jpg';
            img2.style.display = 'none';
        }
        else {
            img1.src = 'images/cab/' + estilo + '/outdoor_' + idioma + '.jpg';
            img2.src = 'images/cab/' + estilo + '/logo_' + estilo + '_' + idioma + '.jpg';
            img2.style.display = 'block';
            if (estilo == 'airzap')
                a2.href = 'home.aspx';
            else
                a2.href = 'lista.aspx?id=' + estilo;
        }

        el('header-wrapper').style.backgroundImage = 'url(images/cab/' + estilo + '/bg_header_' + estilo + '.jpg)';

        cor = '#0d5cc9';
        if (estilo == 'dentalair')
            cor = '#a4c7e1';
        else if (estilo == 'dryzap')
            cor = '#7ec3e4';
        else if (estilo == 'hobbyzap')
            cor = '#d77c38';
        else if (estilo == 'industrial')
            cor = '#abc8e0';
        else if (estilo == 'profizap')
            cor = '#fdc111';

        el('outdoor-wrapper').style.backgroundColor = cor;

        if (el('portugues'))
            el('portugues').style.backgroundImage = 'url(images/cab/' + estilo + '/flag_portugues_' + estilo + '.gif)';
        if (el('english'))
            el('english').style.backgroundImage = 'url(images/cab/' + estilo + '/flag_english_' + estilo + '.gif)';
        if (el('espanol'))
            el('espanol').style.backgroundImage = 'url(images/cab/' + estilo + '/flag_espanol_' + estilo + '.gif)';

        el('home').style.backgroundColor = main ? '' : '#c4c4c4';

        img1.style.display = 'block';

        estiloAtivo = estilo;
        idiomaAtivo = idioma;
    }
    
}