function TdOver(obj, cor, cur) {
	if (!obj) return false;

	obj.bgColor = cor;
	if (obj.style) {
	 obj.style.cursor = (cur) ? cur : "default" ;
	} else {
	 obj.cursor = (cur) ? cur : "default" ;
	}
	
	return true;
}

function LimitTextArea(objDiv, objText, maxSize) {
    objText = document.all[objText];
    if (objText.value.length>maxSize) {
       objText.value = objText.value.substr(0,maxSize);
       texto = "(" + (maxSize-objText.value.length) + " caracteres)" ;
       WriteLayer(objDiv,texto)
       alert ("Você pode digitar somente " + maxSize + " caracteres.");
    }
    texto = "(" + (maxSize-objText.value.length) + " caracteres)" ;
    WriteLayer(objDiv,texto)
    return true;
}

function PesquisaVotar(m) {
    var obj = document.frmPesquisa;
    var url = "interativo/pesquisa/index.php?ID=" + obj.PesquisaID.value
    if (m == 'votar') {
        var checkID = "";
        for (i=0;i<obj.AlternativaID.length; i++) {
             if (obj.AlternativaID[i].checked)
                checkID = obj.AlternativaID[i].value;
        }
        if (checkID == "") {
           alert ("PESQUISA\nPor favor, selecione uma alternativa.")
           return false;
        }
        url += "&AID=" + checkID;
    }
    if (window.winPesquisa) window.winPesquisa.close();
    winPesquisa = window.open (url, 'winPesquisa', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=350,height=230');
    return false;
}

function WriteLayer(layer,texto) {
    if (document.getElementById(layer) ) {
        document.getElementById(layer).innerHTML = texto;
    } else if (document.all) {
        document.all[layer].innerHTML = texto;
    } else if (document.layers ) {
        document.layers[layer].document.open();
        document.layers[layer].document.write(texto);
        document.layers[layer].document.close();
    }
}

function SetDisplayLayer(layer,set) {
    obj = document.all[layer];
    if (obj)
       obj.style.display = set;
    return false;
}

function CustomHintShow(txt) {
   var vtop;
   var vleft;
   obj = document.all['CustomHint'];
   vleft=(event.clientX);
   vtop=(event.clientY+15)+document.body.scrollTop       ;
//   if ((vleft-parseInt(obj.style.width)) < document.body.clientWidth) vleft =  document.body.clientWidth - ;
   vleft = event.clientX-200;


   if (vleft<0) vleft = 5;


   obj.style.left = vleft + 'px';
   obj.style.top =  vtop + 'px';
   obj.innerHTML = '<table border=1 bordercolor=#808080 cellpadding="4" cellspacing="0" bgcolor=#FFFFC0><tr><td class=texto>' + txt + '</td></tr></table>';
   obj.style.display = '';
}

function CustomHintHide() {
    obj = document.all['CustomHint'];
    obj.style.display = 'none';
}


function swapImg(file, imgName) {
   var obj = document.all[imgName];
   if (obj) {
       obj.src = file;
   }
   return true;
}

function mSwapCor(src, cor, cursor) {
   if (src) {
      if (!cursor) cursor = 'default';
      src.style.cursor = cursor;
      src.bgColor = cor;
   }
}



//elimina espaços, tabs, quebras de linha e retornos de carro do ladoesquerdo
function LTrim(str) {
    return str.replace(/^\s*(\w|\W)/,"$1");
}
//elimina espaços, tabs, quebras de linha e retornos de carro do lado  direito
function RTrim(str) {
    return str.replace(/(\w|\W)\s*$/,"$1");
}

//elimina espaços, tabs, quebras de linha e retornos de carro dos dois lados
function Trim(str) {
    str = str.replace(/^\s*(\w|\W)/,"$1");
    str = str.replace(/(\w|\W)\s*$/,"$1");
    if (str == " ") str = "";
    return str;
}

// News
function postNews(acao) {
    var obj = document.all['frmNews'];
    if (obj) {
        if (obj.email.value == "" || obj.email.value == "Digite seu e-mail") {
            alert ("ERRO!\n" + 'Digite o e-mail.');
            obj.email.focus(); obj.email.select();
            return false;
        }
    }
    // Montando a strring
    return true;
}


function getMyObj(layerName) {
    //alert (document.getElelmentById);
    if (document.all) {
      if (document.all[layerName]) return document.all[layerName];
    } else if (document.layers) {
      if (document.layers[layerName]) return document.layers[layerName];
    } else if (document.getElementById ) {
       if (document.getElementById(layerName)) return document.getElementById(layerName);
	}

    return null;
}


function getMyObjOffsetW(obj) {
   if (!obj) return 0;
   return ((obj.offsetWidth)?obj.offsetWidth:obj.outerWidth);
}

function getMyObjOffsetH(obj) {
   if (!obj) return 0;
   return ((obj.offsetHeight)?obj.offsetHeight:obj.outerHeight);
}


function getMyObjW(obj) {
   if (!obj) return 0;
   return ((obj.clientWidth)?obj.clientWidth:obj.clientWidth);
}

function getMyObjH(obj) {
   if (!obj) return 0;
   return ((obj.clientHeight)?obj.clientHeight:obj.clientHeight);
}

function getMyObjLeft(obj) {
   if (!obj) return 0;
   return ((obj.style)?obj.style.left:obj.left);
}

function getMyObjTop(obj) {
   if (!obj) return 0;
   return ((obj.style)?obj.style.top:obj.top);
}

function getMyObjDisplay(obj) {
   if (!obj) return 0;
   return ((obj.style)?obj.style.display:obj.display);
}


function setMyObj(obj, prop, valor, debug) {
   if (!obj) return 0;
   if (obj.style) {
      comando = "obj.style."+prop+" = '" + valor + "'";
   } else {
      comando = "obj."+prop+" = '" + valor + "'";
   }
   if (debug == 1) alert (comando);
   return eval(comando);

}

function openNewWindow(link, w, h, s) {
  if (!w || w == '') w = 200;
  if (!h || h == '') h = 200;
  if (!s || s == '') s = 'no';
  
  //if (window.NewWindow) window.NewWindow.close();
  //NewWindow = window.open (link,'NewWindow','channelmode=no,directories=no,fullscreen=no,left=150,top=50,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width='+w+',height='+h+'');
  window.open (link,'NewWindow','channelmode=no,directories=no,fullscreen=no,left=150,top=50,location=no,menubar=no,resizable=no,scrollbars='+s+',status=no,titlebar=no,toolbar=no,width='+w+',height='+h+'');
  return false;
}

function openGaleria(link) {
  if (window.winGaleria) window.winGaleria.close();
  winGaleria = window.open (link, 'winGaleria', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=600,height=400');
  return false;
}

function HideShowDivs(obj, imgSrc, Ext) {
   setMyObj(getMyObj(obj), 'display',  (getMyObjDisplay(getMyObj(obj)) == "") ? 'none':'' );
   objImg = document.all['img' + obj];
   if (objImg) {
	  objImg.src = imgSrc + ((getMyObjDisplay(getMyObj(obj)) == "") ? 'Hide':'Show' ) + "." + Ext      
   };
   
   return false;
}


function openIndiquePortal() {
  if (window.winIndique) window.winIndique.close();
  winGaleria = window.open ("/interatividade/indique/", 'winIndique', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=240,height=240');
  return false;
}


function openWallpaper() {
  if (window.winWallpaper) window.winWallpaper.close();
  winWallpaper = window.open ("/wallpaper/download.php", 'winWallpaper', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=580,height=600');
  return false;
}


function  postComentario() {
    var obj = document.frmComentario;
    if (Trim(obj.comentNome.value) == "") {
        alert ("Por favor, digite o nome.");
        obj.comentNome.focus(true);
        return false;
    }
    if (Trim(obj.comentEmail.value) == "") {
        alert ("Por favor, digite o e-mail.");
        obj.comentEmail.focus(true);
        return false;
    }
    if (Trim(obj.comentTexto.value) == "") {
        alert ("Por favor, digite o texto.");
        obj.comentTexto.focus(true);
        return false;
    }
    return true;
}



function open_new_window(link, w, h,scroll,resizable, name,status) {
  if (!name) name= 'newWindow';
  if (!w || w == '') w = 200;
  if (!h || h == '') h = 200;
  if (!scroll || scroll == '') scroll = 'yes';
  if (!resizable || resizable == '') resizable = 'no';
  if (!status|| status == '') status= 'yes';
  if (scroll || scroll != '') w = w+20;

  //if (window.NewWindow) window.NewWindow.close();
  //alert (name);
  var name = window.open (link,name,'channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable='+resizable+',scrollbars='+ scroll + ',status='+status+',titlebar=no,toolbar=no,width='+w+',height='+h+'');
  var px1 = window.screenX;
  var px2 = window.screenX + window.outerWidth;
  var py1 = window.screenY;
  var py2 = window.screenY + window.outerHeight;
  if (py2>screen.height || px2>screen.width) {
      var x = (px2 - px1 - name.outerWidth) / 2;
      var y = (py2 - py1 - name.outerHeight) / 2;
      name.moveTo(x, y);
  }

  name.focus();

  return false;
}


