//Atribui valor a ser utilizado na paginação
function naveg( nav){
  window.document.form_naveg.btn_naveg.value=nav;
  window.document.form_naveg.submit();
};

function email(listId, thisEmail, thisName, mailingPath){
  mainWin = window.open( mailingPath+'admin/email.php?listID='+listId+'&action=add&enter='+thisEmail+'&name='+thisName,'','scrollbars=no,status=no,width=380,height=240,top=10,left=10');
};

//Submete um form, passando todos os seus elementos no Action definido
function novaJanela( frm, tag, width, height){
  var argumentos="";
  var nrElem = frm.elements.length;
  var count = 0;
  var concat='';
  var optionString;
  
  //
  while (count < nrElem){
    if( frm.elements[count].type != 'radio'){
      argumentos=argumentos+concat+frm.elements[count].name+'='+frm.elements[count].value;
      concat='&';
     }
     else{
       if ( frm.elements[count].checked=='1'){
         argumentos=argumentos+concat+frm.elements[count].name+'='+frm.elements[count].value;
           concat='&';
       }
    }
    count++;
  }
  optionString = ('width=' + width + ',height=' + height + ',top=10,left=10,status=no,menubar=no,resizable=no,scrollbars=yes');

  window.open(frm.action+"?"+argumentos, "", optionString);
}

//Para ver os resultados de sondagens anteriores
function verResultadosPoll( pollPath, width, height){
  optionString = ('width=' + width + ',height=' + height + ',top=10,left=10,status=no,menubar=no,resizable=no,scrollbars=no');

  window.open( pollPath+"pollVoteResult.php?from=ver_result", "", optionString);
}

function popper(thisUrl,thisWidth,thisHeight,thisTop,thisLeft)
{
var optionString,mainWin;
optionString = ('width=' + thisWidth + ',height=' + thisHeight + ',top=' + thisTop + ',left=' + thisLeft + ',status=no,menubar=no,resizable=no,scrollbars=no');
mainWin = window.open(thisUrl,"",optionString);
}

function popperScroll(thisUrl,thisWidth,thisHeight,thisTop,thisLeft)
{
var optionString,mainWin;
optionString = ('width=' + thisWidth + ',height=' + thisHeight + ',top=' + thisTop + ',left=' + thisLeft + ',status=no,menubar=no,resizable=no,scrollbars=yes');
mainWin = window.open(thisUrl,"",optionString);
}

//Conta o Nº de Caracteres em falta de uma mensagem SMS
var supportsKeys = false
var maxlength = 140;

function Init() {
  check();
}

function getLength(what) {
  if (what.value.length > maxlength) {
    what.value = what.value.substring(0,maxlength)
    charsleft = 0
  } else {
    charsleft = maxlength - what.value.length
  }
  document.forms[0].elements['charsleft'].value = charsleft
}

function check() {
  getLength(document.forms[0].elements['message'])
  if (!supportsKeys) timerID = setTimeout("check()",300)
}

function openOrcam(baseurl){
  popper(baseurl+'orcam_cdcards.php',330,560,10,10);
}

/**
 * The global array below will be used inside the "setPointer()" function
 */
var markedRow = new Array();


/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 * @param   object   the background color
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, thePointerColor, theNormalBgColor)
{
    var theCells = null;

    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    var currentColor = null;
    var newColor     = null;
    // Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
    }

    return true;
} // end of the 'setPointer()' function

