// JavaScript Document
String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
function addRowToTable(element, rows, textNodes)
{
	var tbl = document.getElementById(element);
	var content = tbl.rows[1].cells[1].innerHTML.trim();
	if(content == "-")
	{
		textNode = textNodes.split("|");
		for(i=0; i<textNode.length; i++)
		{
			tbl.rows[1].cells[i].innerHTML = textNode[i];
		}
		return;
	}
	
	var lastRow = tbl.rows.length;
	// if there's no header row in the table, then iteration = lastRow + 1
	var row = tbl.insertRow(lastRow);
	var cell = new Array(rows);
	textNode = textNodes.split("|");
	
	for(i=0; i<rows; i++)
	{
		cell[i] = row.insertCell(i);
		cell[i].innerHTML = textNode[i];
	}
}
function pegalinha(obj, element)
{
  tabela = document.getElementById(element);
  celula = obj.parentNode;
  linha = celula.parentNode;
  
  return (linha.nrChildren());
  for (var i=0;i<tabela.rows.length;i++)
  {
    if (linha == tabela.rows[i])
      return( i );
  }
}
function removeRowFromTable(row, element)
{
  var tbl = document.getElementById(element);
  alert(row);
  tbl.deleteRow(row);
}
function removeLastRowFromTable(element)
{
  var tbl = document.getElementById(element);
  var lastRow = tbl.rows.length;
  if (lastRow > 2) 
  	tbl.deleteRow(lastRow - 1);
}
function getMultiple(ob) 
{
	var arSelected = new Array(); 

	while (ob.selectedIndex != -1) 
	{ 
		arSelected.push(ob.options[ob.selectedIndex].value); 
		ob.options[ob.selectedIndex].selected = false; 
	} // You can use the arSelected array for further processing. 
	return arSelected;
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
window.onload = init;
function init() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}
function getXY(e) {
	var pos =  new Array();
 	pos[0] = (window.Event) ? e.pageX : event.clientX;
	pos[1] = (window.Event) ? e.pageY : event.clientY;

  return pos;
}
function popFloat(fName, src)
{
	var caretPos = document.selection.createRange();

	alert(caretPos.boundingTop +" : " +caretPos.boundingLeft);
	fName.src = src;
	fName.style.visibility = 'visible';	
	fName.style.padding = pos[0];
//	document.getElementById(fName).style.padding-left = pos[1];
}
function detectItem(originalArray, itemToDetect) {
	var j = 0;
	alert(originalArray.length);
	while (j < originalArray.length) {
		if (originalArray[j].value == itemToDetect) {
			return true;
		} else { j++; alert(originalArray[j].value + " - " + itemToDetect)}
	}
	return false;
}
function abreUpload(opener)
{
	switch(opener)
	{
		case("banner"):
			window.open('uploadBanner.php?tipo='+document.getElementById('tipo').value,'upload','width=300,height=100');
			break;
		default:
			window.open('upload.php','upload','width=300,height=100');
			break;
	}
}
function formataCampo(campo,tipo){
	if(tipo=="cep"){
		var configuracao = new Array(2,6);
		var caracteres = new Array(".", "-");
	}
	if(tipo=="data"){
		var configuracao = new Array(2,5);
		var caracteres = new Array("/","/");
	}
	if(tipo=="hora"){
		var configuracao = new Array(0,2);
		var caracteres = new Array("",":");
	}
	if(tipo=="cnpj"){
		var configuracao = new Array(2,6,10,14);
		var caracteres = new Array(".",".","/","-");
	}
	if(tipo=="cpf"){
		var configuracao = new Array(3,7,11);
		var caracteres = new Array(".", ".","-");
	}
	/////////Executa a configuração
	for(i = 0; i < configuracao.length; i++){
		if(campo.value.length==configuracao[i]){
			campo.value = campo.value+caracteres[i];
		}//if
	}// for
}
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
}
function mOvr(src,clrOver) {
	src.bgColor = clrOver;
}
function mOut(src,clrIn) {
	src.bgColor = clrIn;
}
function buscaSubMacro(id)
{
	x_carregaWK_subMenu(id, montaSubMacro);
}
function buscaSubDocumentos(path)
{
	x_carregaWK_subDocumentos(path, montaSubDocumentos)	
}
function carregaPaginas(id)
{
	x_carregaddlPagina(id, montaPaginas);	
}
function buscaSubMacroCapa(id)
{
	x_carregaWK_subMenuCapa(id, montaSubMacro);
}
function montaSubMacro(html)
{
	document.getElementById('divMacros').innerHTML=html;
}
function montaSubDocumentos(html)
{
	document.getElementById('divDocumentos').innerHTML=html;
}
function montaPaginas(html)
{
	document.getElementById('divPaginas').innerHTML=html;
}