//***************************** COOKIES ***************************************//
//JGCookie.set("Key", "Value", 1); // Setamos (nome, valor, duracao)
//JGCookie.get("Key"); // Lemos (nome)
//JGCookie.unset("Key"); // Apagamos (nome)

var JGCookie = {
  date: new Date(),
  set: function(name, content, days) {
    var expires = "";
    if(days) {
	  this.date.setTime(this.date.getTime()+(days*24*60*60*1000));
      expires = this.date.toGMTString() + "; ";
	}
	document.cookie = name + "=" + content + "; " + expires + "path=/";
	return true;
  },
  get: function( name ) {
  	var nameE = name + "=";
	  var cookies = document.cookie.split(";");
  	for (var i = 0, Cookie; Cookie = cookies[i]; i++) {
  	  while(Cookie.charAt(0) == " ") {
  	  	Cookie = Cookie.substring(1,Cookie.length);
  	  }
  	  if(Cookie.indexOf(nameE) == 0) {
  	  	return Cookie.substring(nameE.length,Cookie.length);
  	  }
  	}
	  return false;
  },
  unset: function( name ) {
  	this.set(name, "", -1);
  	return true;
  }
}

if( !top.JGCookie.get("investLanguage") && !top.JGCookie.get("investCountry") ){
  top.JGCookie.set("investLanguage", "pt", 1095);
  top.JGCookie.set("investCountry", "br", 1095);
}

function mudaLinguagem(lang, country){
  top.JGCookie.set("investLanguage", lang, 1095);
  top.JGCookie.set("investCountry", country, 1095);
  top.self.location='../';
}

function eventAdder(objAttrib,handler,addFunction){
   if ((!document.all)&&(document.getElementById)){
       objAttrib.setAttribute(handler,addFunction);
   }
   //workaround for IE 5.x
   if ((document.all)&&(document.getElementById)){
       objAttrib[handler]=new Function(addFunction);
   }
}

function verificaAporte(id){
  var aporte = document.getElementById('APORTE_'+id);
  if(aporte.style.display == "none"){
    aporte.style.display = "inline";
  }
  else{
    aporte.style.display = "none";
  }
}

var numOpcao=0;
var numTbodyCompra=0;
var numTbodyVenda=0;
var numAcao=0;
var numTr=0;

function mascaraOptions(){
  var divOptions = document.getElementById("options"); //pega a div que iremos trabalhar
  	divOptions.style.width = "600px";
	divOptions.style.marginLeft ="auto";
	divOptions.style.marginRight ="auto";


  numOpcao++;
  numTbodyCompra++;
  numTbodyVenda++;

  //INICIO BR
    var br = document.createElement("br");
    br.setAttribute("id", "br_"+numOpcao);
  //FIM BR

  //INICIO DIV
    var div = document.createElement("div");
    div.setAttribute("id", "option_"+numOpcao);

    //INICIO TABELA1
      var table1 = document.createElement("table");
      table1.setAttribute("border", "0");
      table1.cellSpacing = 0;
      table1.setAttribute("align", "center");
      table1.setAttribute("width", "600px");
	  table1.style.marginRight ="70px";
      table1.setAttribute("id", "tbVenda_"+numOpcao);
      table1.setAttribute("name", "tbVenda_"+numOpcao);
	  table1.style.marginBottom ="5px";


      //INICIO THEAD1
        var thead1 = document.createElement("thead");
			thead1.style.color = "#245e94";
			thead1.style.textAlign ="center";
			thead1.style.fontSize =".9em";

          //INICIO TR1
            var tr1 = document.createElement("tr");

              //INICIO TD1
                var td1 = document.createElement("td");
                td1.setAttribute("align", "left");
                td1.colspan = 3;

                  //INICIO LABEL1
                    var label1 = document.createTextNode("Item");
                  //FIM LABEL1
                td1.appendChild(label1);
              //FIM TD1
            tr1.appendChild(td1);
          //FIM TR1

          //INICIO TR2
            var tr2 = document.createElement("tr");
            	tr2.style.backgroundColor = "#c4d6e4";

              //INICIO TD2
                var td2 = document.createElement("td");
				td2.setAttribute("class","textoItem");
                td2.colSpan = 3;
                td2.style.fontWeight = "bold";

                  //INICIO LABEL2
                    var label2 = document.createTextNode("Vender ");

                  //FIM LABEL2

                  //INICIO INPUT1
                    //var input1 = document.createElement("img");
					var input1 = document.createElement("input");
					input1.setAttribute("type", "button");
                    input1.setAttribute("class", "btns margem");
                    input1.setAttribute("value", "Add");
                    input1.setAttribute("align", "right");
                    eventAdder(input1,"onclick", "addRowOptionVenda('"+numTbodyVenda+"')");
                  //FIM INPUT1
                td2.appendChild(label2);
                td2.appendChild(input1);
              //FIM TD2
            tr2.appendChild(td2);
          //FIM TR2

          //INICIO TR3
            var tr3 = document.createElement("tr");
            tr3.style.backgroundColor = "#f0f0f0";


              //INICIO TD3
                var td3 = document.createElement("td");
                //td3.setAttribute("align", "center");
                td3.style.color = "#000000";
                td3.style.fontSize = ".8em";
                td3.style.fontWeight = "bold";
				td3.style.textAlign = "center";
				td3.style.padding = "3px";
				td3.style.borderBottomWidth ="1px";
				td3.style.borderColor ="#cccccc";
				td3.setAttribute("class", "textoValores");


                  //INICIO LABEL3
                    var label3 = document.createTextNode("Tipo de Investimento");
                  //FIM LABEL3
                td3.appendChild(label3);
              //FIM TD3
              //INICIO TD4
                var td4 = document.createElement("td");
                //td4.setAttribute("align", "center");
                td4.style.color = "#000000";
                td4.style.fontSize = ".8em";
                td4.style.fontWeight = "bold";
				td4.style.textAlign = "center";
				td4.setAttribute("class", "textoValores");

                  //INICIO LABEL4
                    var label4 = document.createTextNode("Investimento");
                  //FIM LABEL4
                td4.appendChild(label4);
              //FIM TD4
              //INICIO TD5
                var td5 = document.createElement("td");
                //td5.setAttribute("align", "center");
                td5.style.color = "#000000";
                td5.style.fontSize = ".8em";
                td5.style.fontWeight = "bold";
				td5.style.textAlign = "center";
				td5.setAttribute("class", "textoValores");

                  //INICIO LABEL5
                    var label5 = document.createTextNode("Valor");
                  //FIM LABEL5
                td5.appendChild(label5);
              //FIM TD9
            tr3.appendChild(td3);
            tr3.appendChild(td4);
            tr3.appendChild(td5);
          //FIM TR3
        thead1.appendChild(tr1);
        thead1.appendChild(tr2);
        thead1.appendChild(tr3);
      //FIM THEAD1

      //INICIO TBODY1
        var tbody1 = document.createElement("tbody");
        tbody1.setAttribute("id", "tbodyVenda_"+numTbodyVenda);

          //INICIO INPUT2
            var input2 = document.createElement("input");
            input2.setAttribute("type", "hidden");
            input2.setAttribute("name", "NUM_TABELA[]");
			input2.style.display ="block";
          //FIM INPUT2

          //INICIO INPUT7
            var input7 = document.createElement("input");
            input7.setAttribute("type", "hidden");
            input7.setAttribute("value", "0");
            input7.setAttribute("name", "NUM_ROWS_COMPRA[]");
            input7.setAttribute("id", "NUM_ROWS_COMPRA_"+numTbodyCompra);
          //FIM INPUT7

          //INICIO INPUT12
            var input12 = document.createElement("input");
            input12.setAttribute("type", "hidden");
            input12.setAttribute("value", "0");
            input12.setAttribute("name", "NUM_ROWS_VENDA[]");
            input12.setAttribute("id", "NUM_ROWS_VENDA_"+numTbodyVenda);
          //FIM INPUT12

      //FIM TBODY1
      table1.appendChild(input2);
      table1.appendChild(input7);
      table1.appendChild(input12);
      table1.appendChild(thead1);
      table1.appendChild(tbody1);
    //FIM TABELA1

    //INICIO TABELA2
      var table2 = document.createElement("table");
      table2.setAttribute("border", "0");
      table2.cellSpacing = 0;
      //table2.setAttribute("align", "center");
      table2.setAttribute("width", "600px");
	  table2.style.marginLeft ="auto";
	  table2.style.marginRight ="auto";
      table2.setAttribute("id", "tbCompra_"+numOpcao);
      table2.setAttribute("name", "tbCompra_"+numOpcao);

      //INICIO THEAD2
        var thead2 = document.createElement("thead");
			thead2.style.fontSize =".9em";


          //INICIO TR4
            var tr4 = document.createElement("tr");
            tr4.style.backgroundColor = "#c4d6e4";
			tr4.style.color = "#245e94";
			tr4.style.textAlign ="center";


              //INICIO TD6
                var td6 = document.createElement("td");
				td6.setAttribute("class","textoItem");
                td6.colSpan = 3;
                td6.style.fontWeight = "bold";

                  //INICIO LABEL6
                    var label6 = document.createTextNode("Comprar ");

                  //FIM LABEL6

                  //INICIO INPUT3
                    var input3 = document.createElement("input");
                    input3.setAttribute("type", "button");
					input3.setAttribute("class", "btns margem");
                    input3.setAttribute("value", "Add");
                    input3.setAttribute("align", "right");
                    eventAdder(input3,"onclick", "addRowOptionCompra('"+numTbodyCompra+"')");
                  //FIM INPUT3

				  //INICIO CHECKBOX1
                    var input10 = document.createElement("input");
                    input10.setAttribute("type", "checkbox");
					input10.setAttribute("class", "margem");
                    input10.setAttribute("value", "S");
                    eventAdder(input10,"onclick", "verificaAporte("+numTbodyCompra+")");
                  //FIM CHECKBOX1

                  //INICIO LABEL10
                    var label10 = document.createTextNode(" c/ aporte ?");
                  //FIM LABEL10

                  //INICIO INPUT11
                    var input11 = document.createElement("input");
                    input11.setAttribute("type", "text");
                    //input11.setAttribute("validation", "required");
                    input11.setAttribute("Label", "Aporte "+numTbodyCompra);
                    input11.setAttribute("name", "APORTE_"+numTbodyCompra);
                    input11.setAttribute("id", "APORTE_"+numTbodyCompra);
                    input11.setAttribute("size", "15");
					input11.style.display="none";
                  //FIM INPUT11
                td6.appendChild(label6);
                td6.appendChild(input3);
                td6.appendChild(input10);
                td6.appendChild(label10);
                td6.appendChild(input11);
              //FIM TD6
            tr4.appendChild(td6);
          //FIM TR4

          //INICIO TR5
            var tr5 = document.createElement("tr");
            tr5.style.backgroundColor = "#f0f0f0";


              //INICIO TD7
                var td7 = document.createElement("td");
                td7.setAttribute("align", "center");
                td7.style.fontSize = ".8em";
                td7.style.fontWeight = "bold";
				td7.style.color ="#000000"
				td7.setAttribute("class", "textoValores");


                  //INICIO LABEL7
                    var label7 = document.createTextNode("Tipo de Investimento");
                  //FIM LABEL7
                td7.appendChild(label7);
              //FIM TD7
              //INICIO TD8
                var td8 = document.createElement("td");
                td8.setAttribute("align", "center");
                td8.style.color = "#000000";
                td8.style.fontSize = ".8em";
                td8.style.fontWeight = "bold";
				td8.setAttribute("class", "textoValores");

                  //INICIO LABEL8
                    var label8 = document.createTextNode("Investimento");
                  //FIM LABEL8
                td8.appendChild(label8);
              //FIM TD8
              //INICIO TD9
                var td9 = document.createElement("td");
                td9.setAttribute("align", "center");
                td9.style.color = "#000000";
                td9.style.fontSize = ".8em";
                td9.style.fontWeight = "bold";
				td9.setAttribute("class", "textoValores");

                  //INICIO LABEL9
                    var label9 = document.createTextNode("Valor");
                  //FIM LABEL9
                td9.appendChild(label9);
              //FIM TD9
            tr5.appendChild(td7);
            tr5.appendChild(td8);
            tr5.appendChild(td9);
          //FIM TR5
        thead2.appendChild(tr4);
        thead2.appendChild(tr5);
      //FIM THEAD2

      //INICIO TBODY2
        var tbody2 = document.createElement("tbody");
        tbody2.setAttribute("id", "tbodyCompra_"+numTbodyCompra);


      //FIM TBODY2
      table2.appendChild(thead2);
      table2.appendChild(tbody2);
    //FIM TABELA2
  div.appendChild(table1);
  div.appendChild(table2);

  if(numOpcao != 1){
    //INICIO TABELA3
      var table3 = document.createElement("table");
      table3.setAttribute("align", "center");
      table3.setAttribute("width", "600px");
	  table3.style.textAlign ="center";

        //INICIO TBODY3
          var tbody3 = document.createElement("tbody");

            //INICIO TR6
              var tr6 = document.createElement("tr");

                //INICIO TD10
                  var td10 = document.createElement("td");
                  //td10.setAttribute("align", "center");
				  td10.style.textAlign ="center";

                    //INICIO INPUT4
                      var input4 = document.createElement("input");
                      input4.setAttribute("type", "button");
					  input4.setAttribute("class", "btns margem");
                      input4.setAttribute("value", "Remove Option");
                      eventAdder(input4,"onclick","removeOption('option_"+numOpcao+"', 'br_"+numOpcao+"')");

                    //FIM INPUT4
                  td10.appendChild(input4);
                //FIM TD10
              tr6.appendChild(td10);
            //FIM TR6
          tbody3.appendChild(tr6);
        //FIM TBODY3
      table3.appendChild(tbody3);
    //FIM TABELA3
  div.appendChild(table3);
  }
  //FIM DIV
  divOptions.appendChild(br);
  divOptions.appendChild(div);
  addRowOptionVenda(numTbodyVenda);
  addRowOptionCompra(numTbodyCompra);
}


function addRowOptionCompra(id){
  var numRowsCompra = document.getElementById("NUM_ROWS_COMPRA_"+id);
  numRowsCompra.value = parseInt(numRowsCompra.value) + 1;
  var tbody4 = document.getElementById("tbodyCompra_"+id);
  numAcao++;
  numTr++;

  //INICIO TR7
    var tr7 = document.createElement("tr");
    tr7.id = numTr;
    tr7.style.backgroundColor = "#f0f0f0";

      //INICIO TD11
        var td11 = document.createElement("td");
        td11.setAttribute("align", "center");

          //INICIO SELECT1
            var campoSelect1 = document.createElement("select");
            campoSelect1.setAttribute("name", "TIPO_OPCAO[]");
            campoSelect1.setAttribute("validation", "required");
            campoSelect1.setAttribute("label", "Tipo de Investimento");
            //eventAdder(campoSelect1,"onchange", "ajaxGet('../_actions/tipoPapel.php?letra='+this.options[this.selectedIndex].value, document.getElementById('papel_"+numAcao+"'),true);");

              var objOption1 = document.createElement("option");
              objOption1.text = " -- Investimento -- ";
              objOption1.value = 0;
              campoSelect1.options.add(objOption1);

              var objOption2 = document.createElement("option");
              objOption2.text = " Ações ";
              objOption2.value = 1;
              campoSelect1.options.add(objOption2);

              var objOption3 = document.createElement("option");
              objOption3.text = " Fundos ";
              objOption3.value = 2;
              campoSelect1.options.add(objOption3);

          //FIM SELECT1
        td11.appendChild(campoSelect1);
        
	      //INICIO SELECT2-a
    	var campoSelect2a = document.createElement("select");
        campoSelect2a.setAttribute("name", "LETRA[]");
        campoSelect2a.setAttribute("label", "Letra");
        eventAdder(campoSelect2a,"onchange", "ajaxGet('../_actions/tipoPapel.php?letra='+this.options[this.selectedIndex].value, document.getElementById('papel_"+numAcao+"'),true);");
	        var objOption4a = document.createElement("option");
            objOption4a.text = " - # - ";
            objOption4a.value = 0;
            campoSelect2a.options.add(objOption4a);
            
            var objOption41a = document.createElement("option");
            objOption41a.text = " - A - ";
            objOption41a.value = "A";
            campoSelect2a.options.add(objOption41a);
            
            var objOption41b = document.createElement("option");
            objOption41b.text = " - B - ";
            objOption41b.value = "B";
            campoSelect2a.options.add(objOption41b);
            
            var objOption41c = document.createElement("option");
            objOption41c.text = " - C - ";
            objOption41c.value = "C";
            campoSelect2a.options.add(objOption41c);
            
            var objOption41d = document.createElement("option");
            objOption41d.text = " - D - ";
            objOption41d.value = "D";
            campoSelect2a.options.add(objOption41d);
            
            var objOption41e = document.createElement("option");
            objOption41e.text = " - E - ";
            objOption41e.value = "E";
            campoSelect2a.options.add(objOption41e);
            
            var objOption41f = document.createElement("option");
            objOption41f.text = " - F - ";
            objOption41f.value = "F";
            campoSelect2a.options.add(objOption41f);
            
            var objOption41g = document.createElement("option");
            objOption41g.text = " - G - ";
            objOption41g.value = "G";
            campoSelect2a.options.add(objOption41g);
            
            var objOption41h = document.createElement("option");
            objOption41h.text = " - H - ";
            objOption41h.value = "H";
            campoSelect2a.options.add(objOption41h);
            
            var objOption41i = document.createElement("option");
            objOption41i.text = " - I - ";
            objOption41i.value = "I";
            campoSelect2a.options.add(objOption41i);
            
            var objOption41j = document.createElement("option");
            objOption41j.text = " - J - ";
            objOption41j.value = "J";
            campoSelect2a.options.add(objOption41j);
            
            var objOption41k = document.createElement("option");
            objOption41k.text = " - K - ";
            objOption41k.value = "K";
            campoSelect2a.options.add(objOption41k);
            
            var objOption41l = document.createElement("option");
            objOption41l.text = " - L - ";
            objOption41l.value = "L";
            campoSelect2a.options.add(objOption41l);
            
            var objOption41m = document.createElement("option");
            objOption41m.text = " - M - ";
            objOption41m.value = "M";
            campoSelect2a.options.add(objOption41m);
            
            var objOption41n = document.createElement("option");
            objOption41n.text = " - N - ";
            objOption41n.value = "N";
            campoSelect2a.options.add(objOption41n);
            
            var objOption41o = document.createElement("option");
            objOption41o.text = " - O - ";
            objOption41o.value = "O";
            campoSelect2a.options.add(objOption41o);
            
            var objOption41p = document.createElement("option");
            objOption41p.text = " - P - ";
            objOption41p.value = "P";
            campoSelect2a.options.add(objOption41p);
            
            var objOption41q = document.createElement("option");
            objOption41q.text = " - Q - ";
            objOption41q.value = "Q";
            campoSelect2a.options.add(objOption41q);
            
            var objOption41r = document.createElement("option");
            objOption41r.text = " - R - ";
            objOption41r.value = "R";
            campoSelect2a.options.add(objOption41r);
            
            var objOption41s = document.createElement("option");
            objOption41s.text = " - S - ";
            objOption41s.value = "S";
            campoSelect2a.options.add(objOption41s);
            
            var objOption41t = document.createElement("option");
            objOption41t.text = " - T - ";
            objOption41t.value = "T";
            campoSelect2a.options.add(objOption41t);
            
            var objOption41u = document.createElement("option");
            objOption41u.text = " - U - ";
            objOption41u.value = "U";
            campoSelect2a.options.add(objOption41u);
            
            var objOption41v = document.createElement("option");
            objOption41v.text = " - V - ";
            objOption41v.value = "V";
            campoSelect2a.options.add(objOption41v);
            
            var objOption41w = document.createElement("option");
            objOption41w.text = " - W - ";
            objOption41w.value = "W";
            campoSelect2a.options.add(objOption41w);
            
            var objOption41x = document.createElement("option");
            objOption41x.text = " - X - ";
            objOption41x.value = "X";
            campoSelect2a.options.add(objOption41x);
            
            var objOption41y = document.createElement("option");
            objOption41y.text = " - Y - ";
            objOption41y.value = "Y";
            campoSelect2a.options.add(objOption41y);
            
            var objOption41z = document.createElement("option");
            objOption41z.text = " - Z - ";
            objOption41z.value = "Z";
            campoSelect2a.options.add(objOption41z);

        //FIM SELECT2-a
            
            td11.appendChild(campoSelect2a);
      //FIM TD11
      //INICIO TD12
        var td12 = document.createElement("td");
        td12.setAttribute("align", "center");

          //INICIO DIV1
            var divPapel1 = document.createElement("div");
            divPapel1.setAttribute("id", "papel_"+numAcao);

              //INICIO SELECT2
                var campoSelect2 = document.createElement("select");
                campoSelect2.setAttribute("name", "PAPEL[]");
                campoSelect2.setAttribute("validation", "required");
                campoSelect2.setAttribute("label", "Papel");

                  var objOption4 = document.createElement("option");
                  objOption4.text = " -- Papel -- ";
                  objOption4.value = 0;
                  campoSelect2.options.add(objOption4);
              //FIM SELECT2
            divPapel1.appendChild(campoSelect2);
          //FIM DIV1
        td12.appendChild(divPapel1);
      //FIM TD12
      //INICIO TD13
        var td13 = document.createElement("td");
        td13.setAttribute("align", "center");

          //INICIO SELECT3
            var campoSelect3 = document.createElement("select");
            campoSelect3.setAttribute("name", "TIPO_QUANTIDADE[]");
            campoSelect3.setAttribute("validation", "");
            campoSelect3.setAttribute("label", "Tipo Quantidade");

              var objOption5 = document.createElement("option");
              objOption5.text = " Porc (%) ";
              objOption5.value = "(%)";
              campoSelect3.options.add(objOption5);

              var objOption6 = document.createElement("option");
              objOption6.text = " Cotas ";
              objOption6.value = "(Cotas)";
              campoSelect3.options.add(objOption6);

              var objOption7 = document.createElement("option");
              objOption7.text = " R$ ";
              objOption7.value = "(R$)";
              campoSelect3.options.add(objOption7);

              var objOption8 = document.createElement("option");
              objOption8.text = " US$ ";
              objOption8.value = "(US$)";
              campoSelect3.options.add(objOption8);
          //FIM SELECT3
          //INICIO INPUT5
            var input5 = document.createElement("input");
            input5.setAttribute("type", "text");
            input5.setAttribute("name", "VALOR[]");
            input5.setAttribute("size", "15");
            input5.setAttribute("validation", "required");
            input5.setAttribute("label", "Valor");
          //FIM INPUT5
          //INICIO INPUT6
            var input6 = document.createElement("input");
            input6.setAttribute("type", "button");
			input6.setAttribute("class", "btns margem");
            input6.setAttribute("value", "Remove");
            eventAdder(input6,"onclick", "removeRowOptionCompra('"+numTr+"', '"+id+"')");
          //FIM INPUT6
        td13.appendChild(campoSelect3);
        td13.appendChild(input5);
        td13.appendChild(input6);
      //FIM TD13
    tr7.appendChild(td11);
    tr7.appendChild(td12);
    tr7.appendChild(td13);
  //FIM TR7
  tbody4.appendChild(tr7);
}

function addRowOptionVenda(id){
  var numRowsVenda = document.getElementById("NUM_ROWS_VENDA_"+id);
  numRowsVenda.value = parseInt(numRowsVenda.value) + 1;
  var tbody5 = document.getElementById("tbodyVenda_"+id);
  numAcao++;
  numTr++;

  //INICIO TR8
    var tr8 = document.createElement("tr");
    tr8.id = numTr;
    tr8.style.backgroundColor = "#f0f0f0";

      //INICIO TD14
        var td14 = document.createElement("td");
        td14.setAttribute("align", "center");

          //INICIO SELECT4
            var campoSelect4 = document.createElement("select");
            campoSelect4.setAttribute("name", "TIPO_OPCAO[]");
            campoSelect4.setAttribute("validation", "required");
            campoSelect4.setAttribute("label", "Tipo de Investimento");
            //eventAdder(campoSelect4,"onchange", "ajaxGet('../_actions/tipoPapel.php?tpOpcao='+this.options[this.selectedIndex].value, document.getElementById('papel_"+numAcao+"'),true);");
            //FIM SELECT4
            td14.appendChild(campoSelect4);
            
              var objOption9 = document.createElement("option");
              objOption9.text = " -- Investimento -- ";
              objOption9.value = 0;
              campoSelect4.options.add(objOption9);

              var objOption10 = document.createElement("option");
              objOption10.text = " Ações ";
              objOption10.value = 1;
              campoSelect4.options.add(objOption10);

              var objOption11 = document.createElement("option");
              objOption11.text = " Fundos ";
              objOption11.value = 2;
              campoSelect4.options.add(objOption11);

    	      //INICIO SELECT4-a
          	var campoSelect4a = document.createElement("select");
              campoSelect4a.setAttribute("name", "LETRA[]");
              campoSelect4a.setAttribute("label", "Letra");
              eventAdder(campoSelect4a,"onchange", "ajaxGet('../_actions/tipoPapel.php?letra='+this.options[this.selectedIndex].value, document.getElementById('papel_"+numAcao+"'),true);");
      	        var objOption4a = document.createElement("option");
                  objOption4a.text = " - # - ";
                  objOption4a.value = 0;
                  campoSelect4a.options.add(objOption4a);
                  
                  var objOption41a = document.createElement("option");
                  objOption41a.text = " - A - ";
                  objOption41a.value = "A";
                  campoSelect4a.options.add(objOption41a);
                  
                  var objOption41b = document.createElement("option");
                  objOption41b.text = " - B - ";
                  objOption41b.value = "B";
                  campoSelect4a.options.add(objOption41b);
                  
                  var objOption41c = document.createElement("option");
                  objOption41c.text = " - C - ";
                  objOption41c.value = "C";
                  campoSelect4a.options.add(objOption41c);
                  
                  var objOption41d = document.createElement("option");
                  objOption41d.text = " - D - ";
                  objOption41d.value = "D";
                  campoSelect4a.options.add(objOption41d);
                  
                  var objOption41e = document.createElement("option");
                  objOption41e.text = " - E - ";
                  objOption41e.value = "E";
                  campoSelect4a.options.add(objOption41e);
                  
                  var objOption41f = document.createElement("option");
                  objOption41f.text = " - F - ";
                  objOption41f.value = "F";
                  campoSelect4a.options.add(objOption41f);
                  
                  var objOption41g = document.createElement("option");
                  objOption41g.text = " - G - ";
                  objOption41g.value = "G";
                  campoSelect4a.options.add(objOption41g);
                  
                  var objOption41h = document.createElement("option");
                  objOption41h.text = " - H - ";
                  objOption41h.value = "H";
                  campoSelect4a.options.add(objOption41h);
                  
                  var objOption41i = document.createElement("option");
                  objOption41i.text = " - I - ";
                  objOption41i.value = "I";
                  campoSelect4a.options.add(objOption41i);
                  
                  var objOption41j = document.createElement("option");
                  objOption41j.text = " - J - ";
                  objOption41j.value = "J";
                  campoSelect4a.options.add(objOption41j);
                  
                  var objOption41k = document.createElement("option");
                  objOption41k.text = " - K - ";
                  objOption41k.value = "K";
                  campoSelect4a.options.add(objOption41k);
                  
                  var objOption41l = document.createElement("option");
                  objOption41l.text = " - L - ";
                  objOption41l.value = "L";
                  campoSelect4a.options.add(objOption41l);
                  
                  var objOption41m = document.createElement("option");
                  objOption41m.text = " - M - ";
                  objOption41m.value = "M";
                  campoSelect4a.options.add(objOption41m);
                  
                  var objOption41n = document.createElement("option");
                  objOption41n.text = " - N - ";
                  objOption41n.value = "N";
                  campoSelect4a.options.add(objOption41n);
                  
                  var objOption41o = document.createElement("option");
                  objOption41o.text = " - O - ";
                  objOption41o.value = "O";
                  campoSelect4a.options.add(objOption41o);
                  
                  var objOption41p = document.createElement("option");
                  objOption41p.text = " - P - ";
                  objOption41p.value = "P";
                  campoSelect4a.options.add(objOption41p);
                  
                  var objOption41q = document.createElement("option");
                  objOption41q.text = " - Q - ";
                  objOption41q.value = "Q";
                  campoSelect4a.options.add(objOption41q);
                  
                  var objOption41r = document.createElement("option");
                  objOption41r.text = " - R - ";
                  objOption41r.value = "R";
                  campoSelect4a.options.add(objOption41r);
                  
                  var objOption41s = document.createElement("option");
                  objOption41s.text = " - S - ";
                  objOption41s.value = "S";
                  campoSelect4a.options.add(objOption41s);
                  
                  var objOption41t = document.createElement("option");
                  objOption41t.text = " - T - ";
                  objOption41t.value = "T";
                  campoSelect4a.options.add(objOption41t);
                  
                  var objOption41u = document.createElement("option");
                  objOption41u.text = " - U - ";
                  objOption41u.value = "U";
                  campoSelect4a.options.add(objOption41u);
                  
                  var objOption41v = document.createElement("option");
                  objOption41v.text = " - V - ";
                  objOption41v.value = "V";
                  campoSelect4a.options.add(objOption41v);
                  
                  var objOption41w = document.createElement("option");
                  objOption41w.text = " - W - ";
                  objOption41w.value = "W";
                  campoSelect4a.options.add(objOption41w);
                  
                  var objOption41x = document.createElement("option");
                  objOption41x.text = " - X - ";
                  objOption41x.value = "X";
                  campoSelect4a.options.add(objOption41x);
                  
                  var objOption41y = document.createElement("option");
                  objOption41y.text = " - Y - ";
                  objOption41y.value = "Y";
                  campoSelect4a.options.add(objOption41y);
                  
                  var objOption41z = document.createElement("option");
                  objOption41z.text = " - Z - ";
                  objOption41z.value = "Z";
                  campoSelect4a.options.add(objOption41z);

              //FIM SELECT4-a
        td14.appendChild(campoSelect4a);              
        
      //FIM TD14
      //INICIO TD15
        var td15 = document.createElement("td");
        td15.setAttribute("align", "center");

          //INICIO DIV2
            var divPapel2 = document.createElement("div");
            divPapel2.setAttribute("id", "papel_"+numAcao);

              //INICIO SELECT5
                var campoSelect5 = document.createElement("select");
                campoSelect5.setAttribute("name", "PAPEL[]");
                campoSelect5.setAttribute("validation", "required");
                campoSelect5.setAttribute("label", "Papel");

                  var objOption12 = document.createElement("option");
                  objOption12.text = " -- Papel -- ";
                  objOption12.value = 0;
                  campoSelect5.options.add(objOption12);
              //FIM SELECT5
            divPapel2.appendChild(campoSelect5);
          //FIM DIV2
        td15.appendChild(divPapel2);
      //FIM TD15
      //INICIO TD16
        var td16 = document.createElement("td");
        td16.setAttribute("align", "center");

          //INICIO SELECT6
            var campoSelect6 = document.createElement("select");
            campoSelect6.setAttribute("name", "TIPO_QUANTIDADE[]");
            campoSelect6.setAttribute("validation", "");
            campoSelect6.setAttribute("label", "Tipo Quantidade");

              var objOption13 = document.createElement("option");
              objOption13.text = " Porc (%) ";
              objOption13.value = "(%)";
              campoSelect6.options.add(objOption13);

              var objOption14 = document.createElement("option");
              objOption14.text = " Cotas ";
              objOption14.value = "(Cotas)";
              campoSelect6.options.add(objOption14);

              var objOption15 = document.createElement("option");
              objOption15.text = " R$ ";
              objOption15.value = "(R$)";
              campoSelect6.options.add(objOption15);

              var objOption16 = document.createElement("option");
              objOption16.text = " US$ ";
              objOption16.value = "(US$)";
              campoSelect6.options.add(objOption16);
          //FIM SELECT6
          //INICIO INPUT8
            var input8 = document.createElement("input");
            input8.setAttribute("type", "text");
            input8.setAttribute("name", "VALOR[]");
            input8.setAttribute("size", "15");
            input8.setAttribute("validation", "required");
            input8.setAttribute("label", "Valor");
          //FIM INPUT8
          //INICIO INPUT9
            var input9 = document.createElement("input");
            input9.setAttribute("type", "button");
			input9.setAttribute("class", "btns margem");
            input9.setAttribute("value", "Remove");
            eventAdder(input9,"onclick", "removeRowOptionVenda('"+numTr+"', '"+id+"')");
          //FIM INPUT9
          //INICIO INPUT10
            var input10 = document.createElement("input");
            input10.setAttribute("type", "hidden");
            input10.setAttribute("name", "NUM_ROW_"+id+"[]");
          //FIM INPUT10
        td16.appendChild(campoSelect6);
        td16.appendChild(input8);
        td16.appendChild(input9);
        td16.appendChild(input10);
      //FIM TD16
    tr8.appendChild(td14);
    tr8.appendChild(td15);
    tr8.appendChild(td16);
  //FIM TR7
  tbody5.appendChild(tr8);
}

function addOption(){
  var mascaraOpt = mascaraOptions();
}

function removeOption(id1, id2){
  var divOptions = document.getElementById("options");
  divOptions.removeChild(document.getElementById(id1));
  divOptions.removeChild(document.getElementById(id2));
}

function removeRowOptionCompra(id1, id2){
  var numRowsCompra = document.getElementById("NUM_ROWS_COMPRA_"+id2);
  numRowsCompra.value = parseInt(numRowsCompra.value) - 1;
  var tbody = document.getElementById(id1);
  tbody = tbody.parentNode;

  var tbody2 = tbody.parentNode;
  tbody2 = tbody2.previousSibling;
  tbody2 = tbody2.lastChild;

  var tr = document.getElementById(id1);
  if ( tbody2.hasChildNodes() ) {
    tbody.removeChild(document.getElementById(id1));
  }
  else{
    if( tbody.lastChild != tbody.firstChild ){
      tbody.removeChild(document.getElementById(id1));
    }
  }
}

function removeRowOptionVenda(id1, id2){
  var numRowsVenda = document.getElementById("NUM_ROWS_VENDA_"+id2);
  numRowsVenda.value = parseInt(numRowsVenda.value) - 1;
  var tbody = document.getElementById(id1);
  tbody = tbody.parentNode;

  var tbody2 = tbody.parentNode;
  tbody2 = tbody2.nextSibling;
  tbody2 = tbody2.lastChild;

  var tr = document.getElementById(id1);
  if ( tbody2.hasChildNodes() ) {
    tbody.removeChild(document.getElementById(id1));
  }
  else{
    if( tbody.lastChild != tbody.firstChild ){
      tbody.removeChild(document.getElementById(id1));
    }
  }
}


function votacaoStart() {
	addRowOptionCompra(id);
	addRowOptionVenda(id);
	addOption();
	removeOption(id1, id2);
	removeRowOptionCompra(id1, id2);
	removeRowOptionVenda(id1, id2);
}