
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by ----- filename.js -----
 */

/* ----- formsubmithelpers.js ----- */
function inputSubmitOnClick(event) {
    if (!event) var event = window.event; // IE compatibility

    if (hasClassName(this, 'submitting')) {
        return confirm(window.form_resubmit_message);
    } else {
        addClassName(this, 'submitting');
    }
    return true;
}

function registerSubmitHandler() {
    var nodes = cssQuery('input[type=submit]');
    for (var i=0; i<nodes.length; i++) {
        var node = nodes[i];
        if (!node.onclick) {
            node.onclick = inputSubmitOnClick;
        }
    }
}
registerPloneFunction(registerSubmitHandler);


/* ----- showProducts.js ----- */

function showProducts(list_id) {
    // show/hide products according to user selection.

    var all_products = cssQuery('.visibleProduct');

    for (var i=0; i < all_products.length; i++) {
        replaceClassName(all_products[i], 'visibleProduct', 
            'hiddenProduct', true);
    }

    var products = cssQuery('#' + list_id + ' > .hiddenProduct');

    for (var i=0; i < products.length; i++) {
        replaceClassName(products[i], 'hiddenProduct', 'visibleProduct', true);
    }


    // show/hide "more links"

    var all_more_links = cssQuery('.hiddenMore');

    for (var i=0; i<all_more_links.length; i++) {
        replaceClassName(all_more_links[i], 'hiddenMore', 'visibleMore', 
            true);
    }

    var more_link = document.getElementById(list_id+'-linkmore');

    if(more_link) {
        replaceClassName(more_link, 'visibleMore', 'hiddenMore', true);
    }

}



/* ----- flash2doc.js ----- */
function switchFlashToText() {
/*    document.getElementById('region-content').style.height='600px';*/
    setTimeout(function() {
                document.getElementById('flash_behind_text').className='hide_element';
                document.getElementById('text_behind_flash').className='show_element';
               }, 16000);
}


/* ----- forms.js ----- */
function cleanFields() {
    var msgs = ['Requisitos – formação, experiência, etc.',
                'Funções – tarefas, responsabilidades, etc.',
                'Condições – salário, regalias, tipo de contrato, etc.'];
    for(var i=0; i<document.getElementsByTagName('input').length; i++) {
        var input = document.getElementsByTagName('input')[i];
        if(input.alt == input.value && input.alt!='') {
            input.value='';
        }
    }
    for(var i=0; i<document.getElementsByTagName('textarea').length; i++) {
        var exist = 'false';
        var textarea = document.getElementsByTagName('textarea')[i];
        for(var j=0; j < msgs.length; j++) {
            if(textarea.value == msgs[j]) {
               exist = 'true';
            }
        }
        if(exist == 'true') {
            textarea.value='';
        }
    }
}

function resetFields() {
    for(var i=0; i<document.getElementsByTagName('input').length; i++) {
        var input = document.getElementsByTagName('input')[i];
        input.style.color='gray';
    }
    for(var i=0; i<document.getElementsByTagName('textarea').length; i++) {
        var textarea = document.getElementsByTagName('textarea')[i];
        textarea.style.color='gray';
    }
}


/* ----- ieupdate.js ----- */
function flashWithoutClickActivation(src, w, h) {
    document.write('<embed width="'+ w +'" height="'+ h +'" src="' + src+ '">');
}


/* ----- scroll.js ----- */
var clipTop = 0;
var clipWidth = 410;
var clipBottom = 410;
var topper = 144;
var lyrheight = 0;
var time,amount,theTime,theHeight,DHTML;


function getObj(name)
{
  if (document.getElementById)
  {
    this.obj = document.getElementById(name);
    if (this.obj) {
        this.style = document.getElementById(name).style;
    }
  }
  else if (document.all)
  {
    this.obj = document.all[name];
    this.style = document.all[name].style;
  }
  else if (document.layers)
  {
    this.obj = document.layers[name];
    this.style = document.layers[name];
  }
}


function init()
{
    DHTML = (document.getElementById || document.all || document.layers)
    if (!DHTML) return;
    var x = new getObj('scroll');
    if (document.layers)
    {
        lyrheight = x.style.clip.bottom;
        lyrheight += 20;
        x.style.clip.top = clipTop;
        x.style.clip.left = 0;
        x.style.clip.right = clipWidth;
        x.style.clip.bottom = clipBottom;
    }
    else if (document.getElementById || document.all)
    {
        lyrheight = x.obj.offsetHeight;
        x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
    }
    if (x.obj.offsetHeight<411) {
        document.getElementById('srcoll_arrows').style.display='none';
    } 
}

function scrollayer(layername,amt,tim)
{
    if (!DHTML) return;
    thelayer = new getObj(layername);
    if (!thelayer) return;
    amount = amt;
    theTime = tim;
    realscroll();
}

function realscroll()
{
    if (!DHTML) return;
    clipTop += amount;
    clipBottom += amount;
    topper -= amount;
    if (clipTop < 0 || clipBottom > lyrheight)
    {
        clipTop -= amount;
        clipBottom -= amount;
        topper += amount;
        return;
    }
    if (document.getElementById || document.all)
    {
        clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
        thelayer.style.clip = clipstring;
        thelayer.style.top = topper + 'px';
    }
    else if (document.layers)
    {
        thelayer.style.clip.top = clipTop;
        thelayer.style.clip.bottom = clipBottom;
        thelayer.style.top = topper;
    }
    time = setTimeout('realscroll()',theTime);
}

function stopscroll()
{
    if (time) clearTimeout(time);
}

/* *********** */

function setLyr(lyr)
{
    var elem = document.getElementById('portal-column-content');
    var x = document.getElementById(lyr);
    var coords = findPos(elem);
//    alert('TESTE: \nLeft: ' + coords[0] + '\nTop: ' + coords[1]);
    x.style.left = 205 + coords[0] + 'px';
}


function findPos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}


/* ----- increaseTextSize.js ----- */
function increaseTextSize(size, val) {
  if(size<250) {    
    document.getElementById(val).style.fontSize=size+"%";
    size+=5;
    setTimeout("increaseTextSize("+size+",'"+val+"')",15);
  }
}

