  String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); }

  AjaxPro.onLoading = function(b)
  {
	var Load = document.getElementById("Loading").style;
	Load.visibility = b ? "visible" : "hidden";
  }

  function slide(Obj)
  {
	var wb = document.getElementById('WhiteBack');
	var obj = document.getElementById(Obj);
	var hd = document.getElementById('scrollPos');
    var FichaInc = document.getElementById("FichaInscricao");
    var EmailBorland = document.getElementById("MailBorland");
    var EmailCodeGear = document.getElementById("MailCodeGear");
    var EmailTreinamento = document.getElementById("MailTreinamento");
    var EmailProdutos = document.getElementById("MailProdutos");

    if (!wb)
    {
      wb = document.createElement("div");
      wb.id = 'WhiteBack';
      wb.style.visibility = 'hidden';
      document.body.insertBefore(wb, document.body.firstChild);
    }

	if(wb.style.visibility == 'hidden')
	{
	  wb.style.visibility = 'visible';
	  obj.style.visibility = 'visible';

	  hd.value = document.body.scrollTop;
	  document.body.scrollTop = 0;
	  document.body.style.overflow = "hidden";
	}
	else
	{
	  wb.style.visibility = 'hidden';
	  obj.style.visibility = 'hidden';

      if (FichaInc) FichaInc.style.visibility = 'hidden';
      if (EmailBorland) EmailBorland.style.visibility = 'hidden';
      if (EmailCodeGear) EmailCodeGear.style.visibility = 'hidden';
      if (EmailTreinamento) EmailTreinamento.style.visibility = 'hidden';
      if (EmailProdutos) EmailProdutos.style.visibility = 'hidden';

	  document.body.scrollTop = hd.value;
	  document.body.style.overflow = "auto";
	}
  }

  function getCurso(ID)
  {
	slide('PopUpCurso');

	var Calendario = document.getElementById("Calendario");
    Calendario.innerHTML = "";

	ucPopUpCurso.TucPopUpCurso.getCurso(ID, getCurso_callBack);
	ucPopUpCurso.TucPopUpCurso.getCalendario(ID, getCalendario_callBack);
  }

  function getCurso_callBack(response)
  {
	var Ds = response.value;

	var Titulo = document.getElementById("TituloCurso");
	var Objetivo = document.getElementById("Objetivo");
	var Carga = document.getElementById("Carga");
	var Pre = document.getElementById("Pre");
	var Conteudo = document.getElementById("Conteudo");
	var Inscricao = document.getElementById("Inscricao");

	if(Ds != null && typeof(Ds) == "object" && Ds.Tables != null && Ds.Tables[0].Rows != '')
	{
	  var Row = Ds.Tables[0].Rows[0];

	  Titulo.innerHTML = (Row.TITULO == null ? "NULO" : Row.TITULO);
	  Objetivo.innerHTML = (Row.RESUMO == null ? "" : Row.RESUMO);
	  Carga.innerHTML = (Row.CARGAHORARIA == null ? "" : Row.CARGAHORARIA + " hora(s)");
	  Pre.innerHTML = (Row.PREREQUISITOS == null ? "" : Row.PREREQUISITOS);
	  Conteudo.innerHTML = (Row.ARQ_CONTEUDO == null ? "" :
	  "<a href='datasheets/" + Row.ARQ_CONTEUDO + "' target='_blank'>Clique aqui</a> para ver o conteúdo programático");
	  Inscricao.innerHTML = (Row.ARQ_FICHAINSCRICAO == null? "" :
	  "Baixe <a href='datasheets/" + Row.ARQ_FICHAINSCRICAO + "' target='_blank'>aqui</a> a ficha de inscrição");
	}
  }

  function getCalendario_callBack(response)
  {
	var Ds = response.value;
	var Calendario = document.getElementById("Calendario");

	if(Ds != null && typeof(Ds) == "object" && Ds.Tables != null && Ds.Tables[0].Rows != '')
	{
	  var sCal = "";
	  for (i = 0; i < Ds.Tables[0].Rows.length; i++)
	  {
		var Row = Ds.Tables[0].Rows[i];

		sCal += "<a href='agendas/" + Row.ARQ_CALENDARIO + "' target='_blank'>" + (Row.TEXTOLINK == null? "" : Row.TEXTOLINK) + "</a><br />";
	  }
	  Calendario.innerHTML = sCal;
	}
  }

  function setMailing()
  {
	var Nome = document.getElementById("ucTop_ucPopUpMailing_txtNome").value;
    var Sobrenome = document.getElementById("ucTop_ucPopUpMailing_txtSobreNome").value;
	var EMail = document.getElementById("ucTop_ucPopUpMailing_txtEMail").value;
	var Empresa = document.getElementById("ucTop_ucPopUpMailing_txtEmpresa").value;
	var Telefone = document.getElementById("ucTop_ucPopUpMailing_txtTelefone").value;
	var Info = (document.getElementById("ucTop_ucPopUpMailing_chkInfo").checked == true ? "S" : "N");
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	var Msg = "";
	if (Nome.trim() == "") Msg += "-Nome; \n";
   	if (Sobrenome.trim() == "") Msg += "-Sobrenome; \n";
	if (EMail.trim() == "") Msg += "-EMail; \n";

	if (Msg != "")
	{
	  alert("Existem campos requeridos não preenchidos: \n" + Msg);
	  return false;
	}

	if (!EMail.match(emailRegEx))
	{
	  alert("Formato do e-mail incorreto!");
	  return false;
	}

	ucPopUpMailing.TucPopUpMailing.enviarCad(Nome, Sobrenome, EMail, Telefone, Empresa, Info, enviarMailing_callBack);
  }

  function enviarMailing_callBack(response)
  {
	var Nome = document.getElementById("ucTop_ucPopUpMailing_txtNome");
    var Sobrenome = document.getElementById("ucTop_ucPopUpMailing_txtSobreNome");
	var EMail = document.getElementById("ucTop_ucPopUpMailing_txtEMail");
	var Empresa = document.getElementById("ucTop_ucPopUpMailing_txtEmpresa");
	var Telefone = document.getElementById("ucTop_ucPopUpMailing_txtTelefone");

    Nome.value = "";
    Sobrenome.value = "";
    EMail.value = "";
    Empresa.value = "";
    Telefone.value = "";

    alert(response.value);
    slide("PopUpMailing");
  }

  function abreFC (Tipo, Texto)
  {
    var TituloTexto = document.getElementById("TituloTexto");
    var Assunto = document.getElementById("ucTop_ucPopUpFaleConosco_txtAssunto");
    var FichaInc = document.getElementById("FichaInscricao");
    var EmailBorland = document.getElementById("MailBorland");
    var EmailCodeGear = document.getElementById("MailCodeGear");
    var EmailTreinamento = document.getElementById("MailTreinamento");
    var EmailProdutos = document.getElementById("MailProdutos");

    if (Tipo == 1) TituloTexto.innerHTML = "Fale Conosco!";
    if (Tipo == 2) TituloTexto.innerHTML = "Informações de Produtos Borland?";
    if (Tipo == 3) TituloTexto.innerHTML = "Informações de Produtos Embarcadero?";
    if (Tipo == 4) TituloTexto.innerHTML = "Informações de Treinamentos?";
    if (Tipo == 5) TituloTexto.innerHTML = "Informações de Nossos Produtos?";

    if (Texto != null)
        Assunto.value = Texto;
    else
        Assunto.value = '';

    EmailBorland.style.visibility = (Tipo == 2 ? "visible" : "hidden");
    EmailBorland.style.position = (Tipo == 2 ? "relative" : "absolute");

    EmailCodeGear.style.visibility = (Tipo == 3 ? "visible" : "hidden");
    EmailCodeGear.style.position = (Tipo == 3 ? "relative" : "absolute");

    EmailTreinamento.style.visibility = (Tipo == 4 ? "visible" : "hidden");
    EmailTreinamento.style.position = (Tipo == 4 ? "relative" : "absolute");
    FichaInc.style.visibility = (Tipo == 4 ? "visible" : "hidden");

    EmailProdutos.style.visibility = (Tipo == 5 ? "visible" : "hidden");
    EmailProdutos.style.position = (Tipo == 5 ? "relative" : "absolute");

    slide("PopUpFaleConosco");
  }

  function abreMailing ()
  {
    var txtEMail = document.getElementById("ucTop_ucPopUpMailing_txtEMail");
    var EMail = document.getElementById("txtMailing").value;
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (!EMail.match(emailRegEx))
	{
	  alert("Formato do e-mail incorreto!");
	  return false;
	}

    txtEMail.value = EMail;

    slide("PopUpMailing");
  }

  function enviarContato()
  {
	var Nome = document.getElementById("ucTop_ucPopUpFaleConosco_txtNome").value;
	var EMail = document.getElementById("ucTop_ucPopUpFaleConosco_txtEMail").value;
	var Empresa = document.getElementById("ucTop_ucPopUpFaleConosco_txtEmpresa").value;
	var Telefone = document.getElementById("ucTop_ucPopUpFaleConosco_txtTelefone").value;
	var Assunto = document.getElementById("ucTop_ucPopUpFaleConosco_txtAssunto").value;
	var Texto = document.getElementById("ucTop_ucPopUpFaleConosco_txtTexto").value;
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var Titulo = document.getElementById("TituloTexto");

	var Msg = "";
	if (Nome.trim() == "") Msg += "-Nome; \n";
	if (EMail.trim() == "") Msg += "-EMail; \n";
	if (Telefone.trim() == "") Msg += "-Telfone; \n";
	if (Empresa.trim() == "") Msg += "-Empresa; \n";
	if (Assunto.trim() == "") Msg += "-Assunto; \n";
	if (Texto.trim() == "") Msg += "-Mensagem; \n";

	if (Msg != "")
	{
	  alert("Existem campos requeridos não preenchidos: \n" + Msg);
	  return false;
	}

	if (!EMail.match(emailRegEx))
	{
	  alert("Formato do e-mail incorreto!");
	  return false;
	}

    var Tipo = "";
    if (Titulo.innerHTML == "Fale Conosco!") Tipo = "1";
    if (Titulo.innerHTML == "Informações do Produto?") Tipo = "2";
    if (Titulo.innerHTML == "Informações do Treinamento?")  Tipo = "3";

	ucPopUpFaleConosco.TucPopUpFaleConosco.enviarContato(Nome, EMail, Telefone, Empresa, Assunto, Texto, Tipo, enviarContato_callBack);
  }

  function enviarContato_callBack(response)
  {
  	var Nome = document.getElementById("ucTop_ucPopUpFaleConosco_txtNome");
	var EMail = document.getElementById("ucTop_ucPopUpFaleConosco_txtEMail");
	var Telefone = document.getElementById("ucTop_ucPopUpFaleConosco_txtTelefone");
	var Empresa = document.getElementById("ucTop_ucPopUpFaleConosco_txtEmpresa");
	var Assunto = document.getElementById("ucTop_ucPopUpFaleConosco_txtAssunto");
	var Texto = document.getElementById("ucTop_ucPopUpFaleConosco_txtTexto");

    Nome.value = "";
    EMail.value = "";
    Telefone.value = "";
    Empresa.value = "";
    Assunto.value = "";
    Texto.value = "";

    alert(response.value);
    slide("PopUpFaleConosco");
  }

function showContent(obj)
{
	obj.style.overflow = 'visible';
}

function hideContent(obj)
{
	obj.style.overflow = 'hidden';
}

function openAndFocusWin(pagina) {
    var myWin = window.open(pagina,"popup","toolbar=no,copyhistory=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width=840,height=550,left=0, top=0");
    myWin.focus();
}

over = function()
{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i = 0; i < sfEls.length; i++)
	{
		sfEls[i].onmouseover = function()
		{
			this.className += " over";
		}
		sfEls[i].onmouseout = function()
		{
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}
if (window.attachEvent)
	window.attachEvent("onload", over);
