//MÁSCARA DE VALORES
//nput type="text" size="20" onkeypress="return mascara_valores(this, '99/99/9999', event);">
//RG:<input type="text" size="20" onkeypress="return mascara_valores(this, '99.999.999-9', event);">
//Telefone:<input type="text" size="20" onkeypress="return mascara_valores(this, '(99)9999-9999', event);">
//Código:<input type="text" size="20" onkeypress="return mascara_valores(this, '99-999', event);">

function mascara_valores(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); }
      else { // qualquer caracter...
        return true;
      }
    }
    else {
      return true;
    }
  }

function formataCep(e,src,mask) {
    if(window.event) { _TXT = e.keyCode; }
    else if(e.which) { _TXT = e.which; }
    if(_TXT > 47 && _TXT < 58) {
 var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
 if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); }
    return true; } else { if (_TXT != 8) { return false; }
 else { return true; }
    }
}

function set_convite_ref(ref){
	document.getElementById('convite_referencia').value = ref;

}


function set_n_paginas(n_paginas){
	document.getElementById('n_paginas_aux').value = n_paginas;
}

function soma_capa(capa, total_paginas){

	sobra = total_paginas - 4;

	//alert(sobra);
	//alert('Tota de páginas: '+document.getElementById('n_paginas_aux').value);
	//alert('paginas_total'+document.getElementById('paginas_total').value);
	if (sobra >= 0){
		document.getElementById('n_paginas_aux').value = sobra;

	}else{
		//alert('Número de páginas excedeu a quantidade de páginas padrão.')
		document.getElementById('verniz_local_capa').checked = false;
	}

}

function soma_uv_local(paginas_uv){

qtdade= document.getElementById('n_paginas_aux').value;
sobra = qtdade-paginas_uv;
//alert(sobra);
	if(sobra >=0){
			document.getElementById('n_paginas_aux').value = sobra;
	}else{
		alert('Número de páginas excedeu a quantidade de páginas padrão.')
	}


}


function mostra_alerta(rb) {
  if (rb ==1){
		document.getElementById('alerta').style.display = '';
	}else{
		document.getElementById('alerta').style.display = 'none';
	}
}


function numdias(mes,ano) {
   //mês ímpar menor que 8 ou mês par maior que 7 tem 31 dias
   if((mes<8 && mes%2==1) || (mes>7 && mes%2==0)) return 31;

   //se não for fevereiro, os outros meses que não os de cima têm 30 dias
   if(mes!=2) return 30;

   //ano bissexto é múltiplo de 4
   if(ano%4==0) return 29;
   return 28;
}

function somadias(data, dias) {
  data =data.split ('/');
  diafuturo=parseInt(data[0])+dias;
  mes=data[1];
  ano=parseInt(data[2]);
  while(diafuturo>numdias(mes,ano)) {
      diafuturo-=numdias(mes,ano);
      mes++;
      if(mes>12) {
          mes=1;
          ano++;
      }
  }

  if(diafuturo<10) diafuturo='0'+diafuturo;
  if(mes<10) mes='0'+mes;

document.getElementById('dt_entrega_servico').value=diafuturo+"/"+mes+"/"+ano;

}

function $(id){
	return document.getElementById(id);
}

function alerta(msg){
	alert(msg);
}

function data_extenso(){
		hoje = new Date();
        dia = hoje.getDate();
        dias = hoje.getDay();
        mes = hoje.getMonth();
        ano = hoje.getYear();
        if (dia < 10)
                dia = "0" + dia;
        if (ano <= 100){
                ano = "19" + ano;
		}
		else{
				ano = "2" + ano-100;
			}


        function CriaArray (n) {
	        this.length = n ;
		}
        NomeDia = new CriaArray(7);
	    NomeDia[0] = "Domingo";
        NomeDia[1] = "Segunda-feira";
        NomeDia[2] = "Terça-feira";
        NomeDia[3] = "Quarta-feira";
        NomeDia[4] = "Quinta-feira";
        NomeDia[5] = "Sexta-feira";
        NomeDia[6] = "Sábado";

        NomeMes = new CriaArray(12);
        NomeMes[0] = "Janeiro";
        NomeMes[1] = "Fevereiro";
        NomeMes[2] = "Março";
        NomeMes[3] = "Abril";
        NomeMes[4] = "Maio";
        NomeMes[5] = "Junho";
        NomeMes[6] = "Julho";
        NomeMes[7] = "Agosto";
        NomeMes[8] = "Setembro";
        NomeMes[9] = "Outubro";
        NomeMes[10] = "Novembro";
        NomeMes[11] = "Dezembro";

// function WriteDate() {
        //document.write ()
// -->

var ni = document.getElementById('divData');
var newdiv = document.createElement('div');
newdiv.innerHTML = "<font><b>" + NomeDia[dias] + ", " + dia + " de " + NomeMes[mes] + " de " + ano + " </b></font>";
ni.appendChild(newdiv);
}

function fechaRetorno(id){
	$('retorno'+id).style.display = 'none';
}

function salvarLink(id){
	var qtd = $('qtd'+id);
	var salvar = $('salvar'+id);

	$('salvar'+id).style.display = 'none';
	$('retorno'+id).style.display = 'block';
	carrega('produto_editar_ajax.php?acao=editar&id='+id+'&qtd='+qtd.value,'retorno'+id);

	setTimeout('fechaRetorno('+id+')', 2000);

}
function editarLink(id){
	var qtd = $('qtd'+id);
	var qtd_ = $('qtd_'+id);
	var editar = $('editar'+id);
	var salvar = $('salvar'+id);
	qtd.style.display = 'block';
	qtd_.style.display = 'none';
	salvar.style.display = 'block';
	editar.style.display = 'none';
}
function removeLink(id){
	carrega('produto_editar_ajax.php?acao=excluir&id='+id,'retorno'+id);
	$('linha'+id).style.display = 'none';
}


function addEvent(valor, valor2, valor3, valor4, numId)
{
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);

newdiv.innerHTML = "Nome:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+valor+"<br>Data:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+valor2+"<br>Endereço: "+valor3+"<br>Local:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "+valor4+"<br><br>";
ni.appendChild(newdiv);
}





function addEvent5(numId, valor, valor2, valor3, valor_bruto, id_item)
{
	var ni = document.getElementById('myDiv');
	var numi = document.getElementById('theValue');
	var num = (document.getElementById("theValue").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	if(valor_bruto!=''){
		valor4=valor3;
	}else{
		valor4=0;
	}

	if(id_item==99999 || id_item==99998){
		texto_convites = "onblur= \"calcula_convite("+num+", this.value, getElementById(\'valor_bruto["+num+"]\').value); somavalor2(this.value , getElementById(\'qtdade["+num+"]\').value,\'"+valor3+"\', getElementById(\'valor_total\').value, "+num+")\"";
	}else{
		texto_convites = "onblur= \"somavalor2(this.value , getElementById(\'qtdade["+num+"]\').value,\'"+valor3+"\', getElementById(\'valor_total\').value, "+num+")\"";
	}


	ni.appendChild(newdiv);

		newdiv.innerHTML = "<table><tr><td height='24'><input style='width:45px' name='item["+num+"]' type='text' class='box50' id='"+num+"' value='"+num+"' maxlength='100'></td><td><input style='width:400px' name='descricao["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"' maxlength='100'></td><td><input name='qtdade["+num+"]' type='hidden' id='qtdade["+num+"]' value='"+valor2+"'><input name='valor_bruto["+num+"]' type='hidden' id='valor_bruto["+num+"]' value='"+valor_bruto+"'><input style='width:100px' name='quantidade["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor2+"' maxlength='100' onblur= \"somavalor2(this.value , getElementById(\'qtdade["+num+"]\').value,\'"+valor3+"\', getElementById(\'valor_total\').value, "+num+")\"></td><td><input style='width:100px' name='valor["+num+"]' type='text' class='box50' id='valor["+num+"]' value='"+valor4+"' maxlength='100' onKeyPress=\"return MascaraMoeda(this, '.', ',' ,event)\" ><br></td></tr></table>";

}


function addEvent_extra(numId, valor, valor2, valor3, valor_bruto, valor5, id_item)
{
	var ni = document.getElementById('myDiv3');
	var numi = document.getElementById('theValue5');
	var num = (document.getElementById("theValue5").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div3";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	if(valor_bruto!=''){
		valor4=valor3;
	}else{
		valor4=0;
	}


	if(valor5 ==0){
		var aluno = 'checked';
	}else{
		var turma = 'checked';
	}


	texto_convites = "onblur= \"somavalor2(this.value , getElementById(\'qtdade["+num+"]\').value,\'"+valor3+"\', getElementById(\'valor_total\').value, "+num+")\"";


	ni.appendChild(newdiv);

		newdiv.innerHTML = "<table><tr><td height='24'><input style='width:45px' name='item_extra["+num+"]' type='text' class='box50' id='"+num+"' value='"+num+"' maxlength='100'></td><td><input style='width:300px' name='descricao_extra["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"' maxlength='100'>&nbsp;&nbsp;Aluno<input name='tipo_divisao["+num+"]' type='radio' id='"+num+"' "+aluno+" value='0'>&nbsp;Turma<input name='tipo_divisao["+num+"]' type='radio' "+turma+" id='"+num+"' value='1'></td><td><input name='qtdade_extra["+num+"]' type='hidden' id='qtdade_extra["+num+"]' value='0'></td><td><input name='qtdade_extra["+num+"]' type='hidden' id='qtdade_extra["+num+"]' value='"+valor2+"'><input name='valor_bruto_extra["+num+"]' type='hidden' id='valor_bruto_extra["+num+"]' value='"+valor_bruto+"'><input style='width:100px' name='quantidade_extra["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor2+"' maxlength='100' onblur= \"somavalor2(this.value , getElementById(\'qtdade_extra["+num+"]\').value,\'"+valor3+"\', getElementById(\'valor_total\').value, "+num+")\"></td><td><input style='width:100px' name='valor_extra["+num+"]' type='text' class='box50' id='valor_extra["+num+"]' value='"+valor4+"' maxlength='100' onKeyPress=\"return MascaraMoeda(this, '.', ',' ,event)\" ><a href=\"javascript:;\" onclick=\"removeEvent_extra(\'"+divIdName+"\')\">&nbsp;<img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";

}
function addEvent_extra_(numId, valor, valor2)
{
	var ni = document.getElementById('myDiv3');
	var numi = document.getElementById('theValue5');
	var num = (document.getElementById("theValue5").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div3";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);

	var valor = valor.split("- R$ ");

	newdiv.innerHTML = "<table><tr><td height='24'><input style='width:45px' name='item_extra["+num+"]' type='text' class='box50' id='"+num+"' value='"+num+"' maxlength='100'></td><td><input style='width:300px' name='descricao_extra["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor[0]+"' maxlength='100'>&nbsp;&nbsp;Aluno<input name='tipo_divisao["+num+"]' type='radio' id='"+num+"' value='0'>&nbsp;Turma<input name='tipo_divisao["+num+"]' type='radio' id='"+num+"' value='1'></td><td><input name='qtdade_extra["+num+"]' type='hidden' id='qtdade_extra["+num+"]' value='0'><input style='width:100px' name='quantidade_extra["+num+"]' type='text' class='box50' id='"+num+"' maxlength='100' onblur= \"somavalor(this.value , getElementById(\'qtdade_extra["+num+"]\').value, \'"+valor[1]+"\', getElementById(\'valor_total\').value, "+ num+")\"></td><td><input style='width:100px' name='valor_extra["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor[1]+"' maxlength='100'><a href=\"javascript:;\" addEvent_formar=\"removeEvent_extra(\'"+divIdName+"\')\">&nbsp;<img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";
	ni.appendChild(newdiv);
}

function removeEvent_extra(divNum)
{
var d = document.getElementById('myDiv3');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
//limita texto
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}




function addEvent_brindes(numId, valor, valor2, valor3, valor_bruto, id_item)
{
	var ni = document.getElementById('myDiv2');
	var numi = document.getElementById('theValue4');
	var num = (document.getElementById("theValue4").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div2";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	if(valor_bruto!=''){
		valor4=valor3;
	}else{
		valor4=0;
	}

	texto_convites = "onblur= \"somavalor2(this.value , getElementById(\'qtdade["+num+"]\').value,\'"+valor3+"\', getElementById(\'valor_total\').value, "+num+")\"";


	ni.appendChild(newdiv);

		newdiv.innerHTML = "<table><tr><td height='24'><input style='width:45px' name='item_brinde["+num+"]' type='text' class='box50' id='"+num+"' value='"+num+"' maxlength='100'></td><td><input style='width:400px' name='descricao_brinde["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"' maxlength='100'></td><td><input name='qtdade_brinde["+num+"]' type='hidden' id='qtdade_brinde["+num+"]' value='"+valor2+"'><input name='valor_bruto_brinde["+num+"]' type='hidden' id='valor_bruto_brinde["+num+"]' value='"+valor_bruto+"'><input style='width:100px' name='quantidade_brinde["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor2+"' maxlength='100' onblur= \"somavalor2(this.value , getElementById(\'qtdade_brinde["+num+"]\').value,\'"+valor3+"\', getElementById(\'valor_total\').value, "+num+")\"></td><td><input style='width:100px' name='valor_brinde["+num+"]' type='text' class='box50' id='valor_brinde["+num+"]' value='"+valor4+"' maxlength='100' onKeyPress=\"return MascaraMoeda(this, '.', ',' ,event)\" ><a href=\"javascript:;\" onclick=\"removeEvent_brinde(\'"+divIdName+"\')\">&nbsp;<img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";

}
function addEvent_brindes_(numId, valor, valor2)
{
	var ni = document.getElementById('myDiv2');
	var numi = document.getElementById('theValue4');
	var num = (document.getElementById("theValue4").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div2";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);


	var valor = valor.split("- R$ ");
	//var valor3 = 0;


	newdiv.innerHTML = "<table><tr><td height='24'><input style='width:45px' name='item_brinde["+num+"]' type='text' class='box50' id='"+num+"' value='"+num+"' maxlength='100'></td><td><input style='width:400px' name='descricao_brinde["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor[0]+"' maxlength='100'></td><td><input name='qtdade_brinde["+num+"]' type='hidden' id='qtdade_brinde["+num+"]' value='0'><input style='width:100px' name='quantidade_brinde["+num+"]' type='text' class='box50' id='"+num+"' maxlength='100' onblur= \"somavalor(this.value , getElementById(\'qtdade_brinde["+num+"]\').value, \'"+valor[1]+"\', getElementById(\'valor_total\').value, "+ num+")\"></td><td><input style='width:100px' name='valor_brinde["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor[1]+"' maxlength='100'><a href=\"javascript:;\" onclick=\"removeEvent_brinde(\'"+divIdName+"\')\">&nbsp;<img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";
	ni.appendChild(newdiv);
}

function removeEvent_brinde(divNum)
{
var d = document.getElementById('myDiv2');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
//limita texto
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}









function addEvent5_(numId, valor, valor2, valor3)
{
	var ni = document.getElementById('myDiv');
	var numi = document.getElementById('theValue');
	var num = (document.getElementById("theValue").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);

	newdiv.innerHTML = "<table><tr><td height='24'><input style='width:45px' name='item["+num+"]' type='text' class='box50' id='"+num+"' value='"+num+"' maxlength='100'></td><td><input style='width:400px' name='descricao["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"' maxlength='100'></td><td><input name='qtdade["+num+"]' type='hidden' id='qtdade["+num+"]' value='"+valor2+"'><input style='width:100px' name='quantidade["+num+"]' type='text' class='box50' id='quantidade["+num+"]' value='"+valor2+"' maxlength='100' onblur= \"somavalor2(this.value , getElementById(\'qtdade["+num+"]\').value,\'0,0', getElementById(\'valor_total\').value, "+num+")\"></td><td><input style='width:100px' name='valor["+num+"]' type='text' class='box50' id='"+num+"' maxlength='100' onblur=\"somavalor3(getElementById(\'quantidade["+num+"]\').value , getElementById(\'qtdade["+num+"]\').value,this.value, getElementById(\'valor_total\').value, "+num+")\" onKeyPress=\"return MascaraMoeda(this, '.', ',' ,event)\" ><br></td></tr></table>";
	ni.appendChild(newdiv);
}

function addEvent6(numId, valor, valor2)
{
	var ni = document.getElementById('myDiv');
	var numi = document.getElementById('theValue');
	var num = (document.getElementById("theValue").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);


	var valor = valor.split("- R$ ");


	newdiv.innerHTML = "<table><tr><td height='24'><input style='width:45px' name='item["+num+"]' type='text' class='box50' id='"+num+"' value='"+num+"' maxlength='100'></td><td><input style='width:400px' name='descricao["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor[0]+"' maxlength='100'></td><td><input name='qtdade["+num+"]' type='hidden' id='qtdade["+num+"]' value='0'><input style='width:100px' name='quantidade["+num+"]' type='text' class='box50' id='"+num+"' maxlength='100' onblur= \"somavalor(this.value , getElementById(\'qtdade["+num+"]\').value, \'"+valor[1]+"\', getElementById(\'valor_total\').value, "+ num+")\"></td><td><input style='width:100px' name='valor["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor[1]+"' maxlength='100'><a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">&nbsp;<img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";
	ni.appendChild(newdiv);
}

function addEvent_curso(numId, valor, valor2)
{
	if(numId != '0') {
		var ni = document.getElementById('myDiv');
		var numi = document.getElementById('theValue');
		var num = (document.getElementById("theValue").value -1)+ 2;
		numi.value = num;
		var divIdName = "my"+num+"Div";
		var newdiv = document.createElement('div');
		newdiv.setAttribute("id",divIdName);
	} else {
		alert('Selecione o curso');
	}


//	newdiv.innerHTML = "<table width='100%'><tr><td width=150><input style='width:150px' name='nome["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"'><input name='id_nome["+num+"]' type='hidden' id='id_nome["+num+"]' value='"+valor2+"'>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\"><img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";
	newdiv.innerHTML = "<table width='100%'><tr><td width=150><input style='width:150px' name='curso_nome["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"'><input name='curso["+num+"]' type='hidden' id='curso["+num+"]' value='"+valor2+"'>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\"><img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";
	ni.appendChild(newdiv);
}



function addEvent_formar(valor, valor2)
{
	var ni = document.getElementById('myDiv');
	var numi = document.getElementById('theValue');
	var num = (document.getElementById("theValue").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);


	newdiv.innerHTML = "<table width='100%' border=0><tr><td>Turma:</td><td align='right' width=150 class='testos'>&nbsp;</td><td>&nbsp;&nbsp;<input style='width:300px' name='formar["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor2+"'><input name='id_formar["+num+"]' type='hidden' id='id_formar["+num+"]' value='"+valor+"'>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\"><img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";
	ni.appendChild(newdiv);
}

function addEvent_formar_(valor, valor2, valor3)
{

	var ni = document.getElementById('myDiv');
	var numi = document.getElementById('theValue');
	var ini = document.getElementById('inicio');
	var num = (document.getElementById("theValue").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);

	<!-- alert(valor2) -->
	num.value = ini + 1;
	newdiv.innerHTML = "<table width='100%'><tr><td>Turma:</td><td align='right' class='testos'>&nbsp;</td><td>&nbsp;&nbsp;<input style='width:300px' name='formar["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor2+"'><input name='id_formar_novos["+num+"]' type='hidden' id='id_formar_novos["+num+"]' value='"+valor+"'>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\"><img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";	
	ni.appendChild(newdiv);
}


function addEvent_formar2(valor, valor2)
{
	var ni = document.getElementById('myDiv2');
	var numi = document.getElementById('theValue2');
//	var ini = document.getElementById('inicio');
	var num = (document.getElementById("theValue2").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div2";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);

	/*
	newdiv.innerHTML = "<table width='100%'><tr><td>Turma:</td><td align='right' class='testos'>&nbsp;</td><td>&nbsp;&nbsp;<input style='width:300px' name='formar["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"'><input name='id_formar["+num+"]' type='hidden' id='id_formar["+num+"]' value='"+valor2+"'>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"removeEvent2(\'"+divIdName+"\')\"><img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";
	ni.appendChild(newdiv);
	*/
//    num.value = ini;
//	newdiv.innerHTML = "<div class='inteligente' style='width:600px;'><span>Turma:</span><input name='formar["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"'><input name='id_formar_novos["+num+"]' type='hidden' id='id_formar_novos["+num+"]' value='"+valor2+"'><span style='display:block; float:right; margin:-23px 170px 0 0;'><a id='adiciona' href=\"javascript:;\" onclick=\"removeEvent2(\'"+divIdName+"\')\"><img src='img/excluir.gif' align='absmiddle'/></a></span></div>";
	newdiv.innerHTML = "<div class='inteligente' style='width:600px;'><span>Turma:</span><input name='formar["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"'><input name='id_formar_novos["+num+"]' type='hidden' id='id_formar_novos["+num+"]' value='"+valor2+"'><a id='adiciona' href=\"javascript:;\" onclick=\"mudouAlgo(); removeEvent2(\'"+divIdName+"\');\"><img src='img/excluir.gif' align='absmiddle'/></a></div>";
	ni.appendChild(newdiv);

}



function addEvent_contato(curso,nome, email, telefone1, telefone2, telefone3, valor2, id_usuario_cliente)
{
	var ni = document.getElementById('myDiv23');
	var numi = document.getElementById('theValue23');
	var num = (document.getElementById("theValue23").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div23";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
//newdiv.innerHTML = "<p>Curso: "+curso+"</p> Nome:<input type='text' name='nome_contato["+num+"]' id='nome_contato["+num+"]' style='width:310px' value='"+nome+"' />&nbsp;&nbsp;&nbsp;Email:<input type='text' name='email_contato["+num+"]' id='email_contato["+num+"]' style='width:310px' value='"+email+"'/>&nbsp;&nbsp; Res:&nbsp;&nbsp;<input type='text' name='telefone1_contato["+num+"]' id='telefone1_contato["+num+"]' style='width:190px; margin-left:5px;' value='"+telefone1+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" />&nbsp;&nbsp; Com:<input type='text' name='telefone2_contato["+num+"]' id='telefone2_contato["+num+"]' style='width:190px' value='"+telefone2+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" />&nbsp;&nbsp;&nbsp;&nbsp;Cel:<input type='text' name='telefone3_contato["+num+"]' id='telefone3_contato["+num+"]' style='width:205px' value='"+telefone3+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" /><br /><br>"
	newdiv.innerHTML = "<p>Curso: "+curso+"</p> Nome:<input type='text' name='nome_contato["+num+"]' id='nome_contato["+num+"]' style='width:310px' value='"+nome+"' />&nbsp;&nbsp;&nbsp;Email:<input type='text' name='email_contato["+num+"]' id='email_contato["+num+"]' style='width:310px' value='"+email+"'/>&nbsp;&nbsp; Res:&nbsp;&nbsp;<input type='text' name='telefone1_contato["+num+"]' id='telefone1_contato["+num+"]' style='width:190px; margin-left:5px;' value='"+telefone1+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" />&nbsp;&nbsp; Com:<input type='text' name='telefone2_contato["+num+"]' id='telefone2_contato["+num+"]' style='width:190px' value='"+telefone2+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" />&nbsp;&nbsp;&nbsp;&nbsp;Cel:<input type='text' name='telefone3_contato["+num+"]' id='telefone3_contato["+num+"]' style='width:205px' value='"+telefone3+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" /><input type='hidden' name='id_usuario_cliente["+num+"]' id='id_usuario_cliente["+num+"]' value='"+id_usuario_cliente+"'><br /><br>"
	ni.appendChild(newdiv);
}

function addEvent_Lista_contato(curso,nome, email, telefone1, telefone2, telefone3, idContato, idTurma)
{
	var ni = document.getElementById('myDiv3');
	var numi = document.getElementById('theValue3');
	var num = (document.getElementById("theValue3").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div3";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	var adicionaAgenda = '<a href="home.php?page=turma_vendedor_editar&idTurma='+idTurma+'&idContato='+idContato+'">&nbsp;&nbsp;&nbsp;[Add Agenda]</a>';

//newdiv.innerHTML = "<p>Curso: "+curso+"</p> Nome:<input type='text' name='nome_contato["+num+"]' id='nome_contato["+num+"]' style='width:310px' value='"+nome+"' />&nbsp;&nbsp;&nbsp;Email:<input type='text' name='email_contato["+num+"]' id='email_contato["+num+"]' style='width:310px' value='"+email+"'/>&nbsp;&nbsp; Res:&nbsp;&nbsp;<input type='text' name='telefone1_contato["+num+"]' id='telefone1_contato["+num+"]' style='width:190px; margin-left:5px;' value='"+telefone1+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" />&nbsp;&nbsp; Com:<input type='text' name='telefone2_contato["+num+"]' id='telefone2_contato["+num+"]' style='width:190px' value='"+telefone2+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" />&nbsp;&nbsp;&nbsp;&nbsp;Cel:<input type='text' name='telefone3_contato["+num+"]' id='telefone3_contato["+num+"]' style='width:205px' value='"+telefone3+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" /><br /><br>"
	newdiv.innerHTML = "<p>Curso: "+curso+"</p> Nome:<input type='text' name='1nome_contato["+num+"]' id='1nome_contato["+num+"]' style='width:310px' value='"+nome+"' disabled='disabled' />&nbsp;&nbsp;&nbsp;Email: <a href='mailto:"+email+"'>"+email+"</a>" + adicionaAgenda + "<br/> <input type='hidden' name='1email_contato["+num+"]' id='1email_contato["+num+"]' style='width:310px' value='"+email+"' disabled='disabled'/>&nbsp;&nbsp; Res:&nbsp;&nbsp;<input type='text' name='1telefone1_contato["+num+"]' id='1telefone1_contato["+num+"]' style='width:190px; margin-left:5px;' value='"+telefone1+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" disabled='disabled' />&nbsp;&nbsp; Com:<input type='text' name='1telefone2_contato["+num+"]' id='1telefone2_contato["+num+"]' style='width:190px' value='"+telefone2+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" disabled='disabled' />&nbsp;&nbsp;&nbsp;&nbsp;Cel:<input type='text' name='1telefone3_contato["+num+"]' id='1telefone3_contato["+num+"]' style='width:205px' value='"+telefone3+"' onkeypress=\"return mascara_valores(this, '(99) 9999-9999', event);\" maxlength=\"14\" disabled='disabled' /><input type='hidden' name='1id_usuario_cliente["+num+"]' id='1id_usuario_cliente["+num+"]' value='"+idContato+"'><br /><br>"
	//newdiv.innerHTML = "<p>Curso:"+curso+"</p><span>Nome:"+nome+" </span><span>Email:"+email+"</span><p>Res:"+telefone1+" </p><p>Com:"+telefone2+" </p><p>Cel:"+telefone3+"</p><input type='hidden' name='id_usuario_cliente["+num+"]' id='id_usuario_cliente["+num+"]' value='"+id_usuario_cliente+"'><br /><br>"
	ni.appendChild(newdiv);
}

function addEvent_historico(nome, valor2)
{
	var ni = document.getElementById('myDiv4');
	var numi = document.getElementById('theValue4');
	var num = (document.getElementById("theValue4").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div4";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);


newdiv.innerHTML = "<br><br><table border=0><tr><td width=500>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Descrição</td><td>&nbsp;&nbsp;&nbsp;&nbsp;Status</td></tr><tr><td width=450 valing=top><center><textarea name='historico["+num+"]' id='historico["+num+"]' cols='80' rows='5'>"+nome+"</textarea></td><td valign=top><select name='status["+num+"]' ><option label='AGENDAR REUNIÃO' value='5'>AGENDAR REUNIÃO</option><option label='ALPHA EDITORA' value='13'>ALPHA EDITORA</option><option label='ART PHOTO' value='20'>ART PHOTO</option><option label='ATELIER DO PAPEL' value='15'>ATELIER DO PAPEL</option><option label='CENTER DESIGN' value='9'>CENTER DESIGN</option><option label='CONVITERIA' value='17'>CONVITERIA</option><option label='CRIATIVA' value='10'>CRIATIVA</option><option label='G10' value='12'>G10</option><option label='GRÁFICA AGNUS' value='16'>GRÁFICA AGNUS</option><option label='GRÁFICA NATAL' value='11'>GRÁFICA NATAL</option><option label='GRAFICAS' value='18'>GRAFICAS</option><option label='I9 CONVITES' value='19'>I9 CONVITES</option><option label='ICONE DESIGN' value='23'>ICONE DESIGN</option><option label='LIGAR NOVAMENTE' value='22'>LIGAR NOVAMENTE</option><option label='NEGOCIANDO' value='7'>NEGOCIANDO</option><option label='REUNIÃO AGENDADA' value='6'>REUNIÃO AGENDADA</option><option label='SEM CONTATO' value='4'>SEM CONTATO</option><option label='SEM FORMATURA' value='21'>SEM FORMATURA</option><option label='STUDIO A4' value='14'>STUDIO A4</option></select></td></tr></table><br /><br /><br />"
	ni.appendChild(newdiv);
}


function addEvent_historico_(nome, valor2, valor3)
{
	var ni = document.getElementById('myDiv4');
	var numi = document.getElementById('theValue4');
	var num = (document.getElementById("theValue4").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div4";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);


newdiv.innerHTML = "<label style='width:650px'>"+nome+"</label><br /><br />"
	ni.appendChild(newdiv);
}



function addEvent_formar2_(valor, valor2)
{
	var ni = document.getElementById('myDiv2');
	var numi = document.getElementById('theValue2');
	var num = (document.getElementById("theValue2").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div2";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);


	newdiv.innerHTML = "<table width='100%'><tr><td>Turma:</td><td align='right' class='testos'>&nbsp;</td><td>&nbsp;&nbsp;<input style='width:300px' name='formar["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"'><input name='id_formar["+num+"]' type='hidden' id='id_formar["+num+"]' value='"+valor2+"'>&nbsp;&nbsp;<br></td></tr></table>";
	ni.appendChild(newdiv);
}



function addEvent_cidade(numId, valor, valor2)
{
	var ni = document.getElementById('myDiv2');
	var numi = document.getElementById('theValue2');
	var num = (document.getElementById("theValue2").value -1)+ 2;
	numi.value = num;
	var divIdName = "my"+num+"Div2";
	var newdiv = document.createElement('div2');
	newdiv.setAttribute("id",divIdName);


	newdiv.innerHTML = "<table width='100%'><tr><td>Cidade:</td><td align='right' class='testos'>&nbsp;</td><td>&nbsp;&nbsp;<input style='width:200px' name='cidade["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"'><input name='id_cidade["+num+"]' type='hidden' id='id_cidade["+num+"]' value='"+valor2+"'>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"removeEvent_cidade(\'"+divIdName+"\')\">&nbsp;<img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' style='margin:0px,0px,5px,0px;'  /></a><br></td></tr></table>";
	ni.appendChild(newdiv);
}

function removeEvent_cidade(divNum)
{
var d = document.getElementById('myDiv2');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
//limita texto
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}



function removeEvent2(divNum)
{
var d = document.getElementById('myDiv2');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
//limita texto
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}





function addEvent7(numId, valor, valor2, valor3)
{
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);

newdiv.innerHTML = "<table><tr><td height='24'><input style='width:45px' name='item["+num+"]' type='text' class='box50' id='"+num+"' value='"+num+"' maxlength='100' disabled='disabled'></td><td><input style='width:475px' name='descricao["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor+"' maxlength='100' disabled='disabled'></td><td><input style='width:100px' name='quantidade["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor2+"' maxlength='100' disabled='disabled'></td><td><input style='width:100px' name='valor["+num+"]' type='text' class='box50' id='"+num+"' value='"+valor3+"' maxlength='100' disabled='disabled'><br></td></tr></table>";
ni.appendChild(newdiv);
}


function removeEvent(divNum)
{
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
//limita texto
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function addEvent2_generico(valor,numId)
{
var ni = document.getElementById('myDiv2');
var numi = document.getElementById('theValue2');
var num = (document.getElementById("theValue2").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div2";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "* Nome:<input style='width:300px;text-transform:uppercase' name='nome_g["+numId+"]' type='text' id='"+num+"' value='"+valor+"' maxlength='100'><a href=\"javascript:;\" onclick=\"removeEvent2(\'"+divIdName+"\')\">&nbsp;<img src='img/excluir.gif' width='60' height='22' align='absmiddle' class='bt' /></a><br>";
ni.appendChild(newdiv);
}
function addEvent2_generico2(valor,numId)
{
var ni = document.getElementById('myDiv2');
var numi = document.getElementById('theValue2');
var num = (document.getElementById("theValue2").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div2";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "Nome:<input style='width:300px;text-transform:uppercase' name='nome' type='text' id='"+num+"' value='"+valor+"' maxlength='100'><br>";
ni.appendChild(newdiv);
}


function addEvent2(valor,numId)
{
var ni = document.getElementById('myDiv2');
var numi = document.getElementById('theValue2');
var num = (document.getElementById("theValue2").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div2";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "Nome:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+valor+"<br>";
ni.appendChild(newdiv);
}



function addEvent3(valor,numId)
{
var ni = document.getElementById('myDiv3');
var numi = document.getElementById('theValue3');
var num = (document.getElementById("theValue3").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div3";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "Nome:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+valor+"<br>";
ni.appendChild(newdiv);
}





function emailValido( value ) {
return(/^([\w\.\-])+\@(([\w\-])+\.)+([\w ]{2,4})$/.test(value))
}

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}



function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
//mostra ou esconde a tag
function mostraEsconde(id){
	var elemento = document.getElementById(id);
	if(elemento.style.display == 'none'){
		elemento.style.display = 'block';
	} else {
		elemento.style.display = 'none';
	}

}

function ativaDesativa(id,qual){
	var elemento = document.getElementById(id);
	if(qual == 1){
		elemento.disabled = false;
	} else {
		elemento.disabled = true;
	}

}
//retorna a extensao do arquivo em maiuscula
	function getExt(file){
		return (file.substring(file.length-3,file.length)).toUpperCase();
	}

//========================================
	//Valida o formulario retornando true/false
	function validateArquivoMaling(){

		var form = document.form2;
		var focoElement = null;
		var array_erro = new Array();
		//Reinica as cores das bordas
		form.arquivo.style.borderColor      = '';
		//Verificação dos campos obrigatorios
		//Nome
		if(form.arquivo.value == ''){
			array_erro.push('Selecione um arquivo.');
			if(focoElement == null)
				focoElement = form.arquivo;
		}

		//Arquivo
		if(!form.separacao[0].checked && !form.separacao[1].checked){
			array_erro.push('Selecione o modo de separação dos emails no arquivo.');
		}

		//Arquivo
		if(form.arquivo.value != ''){
			var ext = getExt(form.arquivo.value);
			if(ext != 'CSV' && ext != 'TXT'){
				array_erro.push('Formato de arquivo inválido para inportação (Somente csv e txt)');
				form.arquivo.style.borderColor = 'red';
				if(focoElement == null)
					focoElement = form.arquivo;
			}
		}


		var numErros = array_erro.length;
		if(numErros > 0){
			var str = 'Foram encontrados os seguintes erros:\n';
			for(i = 0; i < numErros; i++){
				str += '\n - ' + array_erro[i];
			}
			alert(str);
			focoElement.focus();
			return false;
		} else {

				form.action ='usuarios_newsletter_usuarios_cadastro_lote_arquivo.php';
			return true;
		}
	} // Fim validate()

//========================================

function excluirEmailMarketing(id){
	if(confirm('Excluir este Email Marketing ?'))
		document.location.href = 'emarketing_excluir.php?id=' + id;
}

function visualizarEmailMarketing(id){
	var width  = 618;
	var height = 500;
	var left   = screen.Width / 2 - width / 2;
	var top    = screen.Height / 2 - height / 2;
	window.open('emarketing_visualizar.php?id='+id,'','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=yes,status=yes');
}

function excluirCampanhas(id){
	if(confirm('Excluir esta Campanha ?'))
		document.location.href = 'campanhas_excluir.php?id=' + id;
}


function getIndexByValue(selectObj,val){
	var n = -1;
	for(i=0; i<selectObj.options.length; i++)
		if (selectObj.options[i].value == val)
			n = i;

	return n;
}

function validaNoticia(){
		var form = document.form1;
		var focoElement = null;
		var array_erro = new Array();

		//Reinica as cores das bordas
		form.titulo.style.borderColor  = '';
		form.chamada.style.borderColor = '';
		form.texto.style.borderColor   = '';
		form.imagem1.style.borderColor = '';
		form.desc1.style.borderColor   = '';
		//Verificação dos campos obrigatorios
		//titulo
		if(form.titulo.value == ''){
			array_erro.push('Título não preenchido');
//			form.titulo.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.titulo;
		}
		//Chamada
		if(form.chamada.value == ''){
			array_erro.push('Chamada não preenchido');
//			form.chamada.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.chamada;
		}
		//texto
		if(form.texto.value == ''){
			array_erro.push('Texto não preenchido');
//			form.texto.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.texto;
		}
		//imagem1
		if(form.imagem1.value != '' && form.desc1.value == ''){
			array_erro.push('Descrição 1 não preenchida');
//			form.desc1.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.desc1;
		}

		var numErros = array_erro.length;
		if(numErros > 0){
			var str = 'Foram encontrados os seguintes erros:\n';
			for(i = 0; i < numErros; i++){
				str += '\n - ' + array_erro[i];
			}
			alert(str);
			focoElement.focus();
			return false;
		} else {
			return true;
		}
	} // Fim validate()

function filtraGrupos (doc){
	if (doc.form1.categoria.selectedIndex > 0){
		temp = '^'+doc.form1.categoria.options[doc.form1.categoria.selectedIndex].value+'FIM';
		myfilter.set(temp);
		showHide('grupoTR','show');
	}
	else{
		doc.form1.grupo.selectedIndex = 0;
		showHide('grupoTR','hide');
	}
}
function showHide(id, param){
	var elemento = document.getElementById(id);
	if(param == 'show'){
		elemento.style.display = 'inline';
	} else {
		elemento.style.display = 'none';
	}

}


function SelecionaGrupo(form, submitForm){
if (form.grupo.options[form.grupo.selectedIndex].value != ''){
	var temp = form.grupo.options[form.grupo.selectedIndex].value.split("FIM");
//	if(confirm('Selecionar o grupo ' + form.grupo.options[form.grupo.selectedIndex].text + '?')){
	form.idgrupo.value = temp[1];
	form.nomegrupo.value = form.categoria.options[form.categoria.selectedIndex].text + ' -> '+form.grupo.options[form.grupo.selectedIndex].text;
	if (submitForm)
			form.submit();
//	}
}
else
	alert ('Selecione o Grupo.');
}



//para ajax
function setDeleta(autent) {
   if (autent == 'sim'){
	   alert('Foto excluida!!');
   }else{
	   alert('A foto não pode ser excluida!!');
   }
}

function getDeleta(foto) {  //função que recebe os valores
		if(confirm('Excluir esta imagem? ')){
			x_deletaFoto(foto, setDeleta);
			document.getElementById('desc1').value = "";
		}
}
//----------
function abreImagem(file,w,h){
	var width  = parseInt(w);
	var height = parseInt(h);
	var left   = screen.width / 2 - width / 2;
	var top    = screen.height / 2 - height / 2;
	window.open('zoom.php?file='+file+'&width='+w+'&height='+h,'','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=no,status=yes')
}

//----------
function abrePopup(file,w,h){
	var width  = parseInt(w);
	var height = parseInt(h);
	var left   = screen.width / 2 - width / 2;
	var top    = screen.height / 2 - height / 2;
	window.open(file,'','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=no,status=yes')
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function excluirGrupoUsuario(id,nome){
	if((id == 0) || (id == 1) || (id == 2)){
		alert('Não é possível excluir o grupo ' + nome);
	} else {
		if(confirm('Excluir o grupo: ' + nome + '?'))
			document.location.href = 'usuarios_newsletter_grupos_excluir.php?id=' + id;
	}
}

function copyStringTo(item,str){
	var element = document.getElementById(item);
	element.value += str;
	element.focus();
}

function excluirGrupoRepresentantes(id,nome){
	if((id == 0)){
		alert('Não é possível excluir o grupo ' + nome);
	} else {
		if(confirm('Excluir o grupo: ' + nome + '?'))
			document.location.href = 'representantes_grupos_excluir.php?id=' + id;
	}
}

function excluirAlbum(id,nome){
	if(confirm('Excluir o álbum: ' + nome + '?\n\nAtenção: Todas as fotos também serão excluídas.'))
		document.location.href = 'album_excluir.php?id=' + id;
}

function excluirNewsletter(id){
	if(confirm('Excluir a newsletter?'))
		document.location.href = 'newsletter_excluir.php?id=' + id;
}

function visualizarNewsletter(id){
	var width  = 700;
	var height = 500;
	var left   = screen.Width / 2 - width / 2;
	var top    = screen.Height / 2 - height / 2;
	window.open('newsletter_visualizar.php?id='+id,'','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=yes,status=yes');
}

function selectCheckBox(theBoxes,value){
	var qtd = theBoxes.length;
	if(qtd){
		for(i = 0 ; i < qtd; i++){
			theBoxes[i].checked = value;
		}
	} else {
		theBoxes.checked = value;
	}
}

function selectOptions(comboID,value){
	var combo = document.getElementById(comboID);
	var numOptions = combo.options.length;
	for(var i = 0; i < numOptions; i++){
		combo.options[i].selected = value;
	}

}

function selectCheckBox2(name,value){
	var element = document.getElementsByName(name);
	var qtd = element.length;
	if(qtd){
		for(i = 0 ; i < qtd; i++){
			element[i].checked = value;
		}
	} else {
		element.checked = value;
	}
}

function checkTheBox(theBox){
	theBox.checked = !theBox.checked;
}

function confirmar(texto){
	if(confirm(texto))
		return true
	else
		return false
}

function confirmarLink(texto,url){
	if(confirm(texto))
		document.location.href=url;
}

function lembreteSenha(){
	window.open('usuarios_senha.php','','width=320,height=100');
}

function grabFocus(item){
	item.focus();
}

function janelaSelecaoGrupo(submitForm){
	var width  = 300;
	var height = 170;
	var left   = screen.Width / 2 - width / 2;
	var top    = screen.Height / 2 - height / 2;
	window.open('produto_cadastro_selecionar_grupo.php?submitForm='+submitForm,'PLATTSELGRUPO','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=no,status=yes');
}

function selecionarGrupo(id,nome,submitForm){

	if(confirm('Selecionar o grupo ' + nome + '?')){
		self.opener.form1.idgrupo.value = id;
		self.opener.form1.nomegrupo.value = nome;
		if(submitForm == 'true')
			self.opener.form1.submit();
		self.close();

	}

}

function showHideItem(id){
	var elemento = document.getElementById(id);
	if(elemento.style.display == 'none'){
		elemento.style.display = 'inline';
	} else {
		elemento.style.display = 'none';
	}

}


	function moveItem(qtd){
		var index = document.form1.produtos.selectedIndex;
		if(index != -1){
			var total = document.form1.produtos.length;
			var target = index + qtd;
			if(target > -1 && target < total){
				var aux = new Option(document.form1.produtos.options[index].text,document.form1.produtos.options[index].value);
				document.form1.produtos.options[index].text = document.form1.produtos.options[target].text;
				document.form1.produtos.options[index].value = document.form1.produtos.options[target].value;
				document.form1.produtos.options[target].text = aux.text;
				document.form1.produtos.options[target].value = aux.value;
				document.form1.produtos.options[target].selected = true;
			} else {
				alert("Ação inválida.");
			}
		} else {
			alert("Nenhum item selecionado.");
		}
	}

	function salvarOrdenacao(){
		if(confirmar('Salvar alterações?')){
			var total = document.getElementById('produtos').length;
			document.getElementById('listaID').value = implode(';;',document.getElementById('produtos').options);
			document.getElementById('form1').submit();
		}
	}

	/**
	 * implode: pega todos os elementos do array pieces e junta em uma string utilizado glue como separador
	 * @param glue: String separadora dos elementos
	 * @param pieces: array com os elementos a serem concatenados
	 */
function implode(glue,pieces){
		var str = "";
		var numPieces = pieces.length;
		for(var i = 0; i < (numPieces-1); i++){
			str += pieces[i].value + glue;
		}
		str += pieces[i].value;
		return str;
}

function banner(id,tipo,w,h){
	var width  = w;
	var height = h;
	var left   = screen.Width / 2 - width / 2;
	//var top    = screen.Height / 2 - height / 2;
	var top = 120;
	window.open('banner_visualizar.php?id='+id+'&tipo='+tipo+'&w='+w+'&h='+h,'','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=no,status=no');
}

function promocao(id,tipo,w,h){
	var width  = w;
	var height = h;
	var left   = screen.Width / 2 - width / 2;
	//var top    = screen.Height / 2 - height / 2;
	var top = 120;
	window.open('promocao_visualizar.php?id='+id+'&tipo='+tipo+'&w='+w+'&h='+h,'','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=no,status=no');
}


function enviar(pagina,valor){

 document.form1.opcao.value = valor;
 document.form1.action = pagina;
 document.form1.submit();

}

function irpara(pagina){

 //document.form1.method="get";
 document.form1.action = pagina;
 document.form1.submit();
 }

 function verificaAcesso(acesso){
	var acesso = acesso;
	if(acesso == 1){
		document.form1.method = "post";
		document.form1.submit();

	}
	else{
		alert("Usuário sem permissão.");
		document.form1.method = "get";
		document.form1.submit();
	}
}

//formatacao de numeros de moedas
function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}

	//Formata número tipo moeda usando o evento onKeyDown
	//chamada: texto1: <input type="text" name="texto" size="20" onKeydown="Formata(this,20,event,2)">

function Formata(campo,tammax,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 )
		{ tam = tam - 1 ; }

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{

		if ( tam <= dec )
		{ campo.value = vr ; }

		if ( (tam > dec) && (tam <= 5) ){
		campo.value = vr.substr( 0, tam - 2 ) + "." + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 6) && (tam <= 8) ){
		campo.value = vr.substr( 0, tam - 5 ) + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
		}
		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
		}
		if ( (tam >= 12) && (tam <= 14) ){
			campo.value = vr.substr( 0, tam - 11 ) + vr.substr( tam - 11, 3 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ;
		}
		if ( (tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + vr.substr( tam - 14, 3 ) + vr.substr( tam - 11, 3 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - 2, tam ) ;
		}
	}
}

function calcula_parcela(n_parcelas, entrada, total){

	total = total.replace(".","");
	total = total.replace(",",".");
	total = parseFloat(total);


	entrada = entrada.replace(".","");
	entrada = entrada.replace(",",".");
	entrada = parseFloat(entrada);

	valor = (parseFloat((total - entrada)/n_parcelas));

	//valor = valor.toFixed(2);
	//valor_total = parseFloat(entrada + valor);
	//valor = valor.replace(".",",");
	valor = format_money(valor);

	document.getElementById('valor_parcelas').value=valor;

}

function format_money(values) {
var values = new String(values);
if (values.indexOf(".") != -1) {
  var split_zero = values.split(".");
  if (split_zero[1].length == 1) { var extra_zero = (split_zero[1] + "0");
  } else if (split_zero[1].length > 2) { var extra_zero = split_zero[1].substr(0, 2);
  } else { var extra_zero = split_zero[1]; }
  var texts_nbrs = split_zero[0];
} else { var texts_nbrs = values, extra_zero = "00"; }
var sum_rplc = 0, all_number = "", len_number = texts_nbrs.length;
for (var i = 1; i < Math.ceil((len_number / 3)); i++) {
  all_number  += ("." + texts_nbrs.substr((len_number - 3), len_number));
  var sum_rplc = (sum_rplc + 3);
}
var str_nbrs  = texts_nbrs.substr(0, (len_number - sum_rplc));
var sum_shows = (str_nbrs + all_number + "," + extra_zero);
return sum_shows;
}



function calcula_desconto(desconto, total){
	total = total.replace(".","");
	//total = total.replace(",",".");
	total = parseFloat(total);

	desconto = desconto.replace(".","");
	//desconto = desconto.replace(",",".");
	desconto = parseFloat(desconto);
	valor = parseFloat(total - desconto);
	valor = format_money(valor);
	total = format_money(total);


	document.getElementById('valor_liquido').value=total;
	document.getElementById('valor_total').value=valor;

	document.getElementById('entrada').value=valor;
	document.getElementById('n_parcelas').value=0;
	document.getElementById('valor_parcelas').value=0;


}



function calcula_convite(num, quantidade, total){

	total = total.replace(".","");
	total = total.replace(",",".");
	total = parseFloat(total);

	valor = (parseFloat(total / quantidade));
	valor = valor.toFixed(2);
	valor = valor.replace(".",",");
	alert(valor);

	document.getElementById('valor['+num+']').value=valor;

}


function somavalor(quantidade_nova, quantidade_antiga, valor_unid, total, num){

	total = total.replace(".","");
	total = total.replace(",",".");
	total = parseFloat(total);

	valor_unid = valor_unid.replace(".","");
	valor_unid = valor_unid.replace(",",".");
	valor_unid = parseFloat(valor_unid);

	total = parseFloat(total - (quantidade_antiga * valor_unid));
	valor = parseFloat(total + (quantidade_nova * valor_unid));

	//valor = valor.toFixed(2);
	//valor = valor.replace(".",",");


	valor = format_money(valor);

	document.getElementById('valor_total').value=valor;
	document.getElementById('valor_liquido').value=valor;
	document.getElementById('qtdade['+num+']').value=quantidade_nova;
	//calcula_parcela(document.getElementById('n_parcelas').value, document.getElementById('entrada').value, valor);
}


function somavalor2(quantidade_nova, quantidade_antiga, valor_unid, total, num){

	total = total.replace(".","");
	total = total.replace(",",".");
	total = parseFloat(total);

	valor_unid = valor_unid.replace(".","");
	valor_unid = valor_unid.replace(",",".");
	valor_unid = parseFloat(valor_unid);

		total = parseFloat(total - (quantidade_antiga * valor_unid));
		valor = parseFloat(total + (quantidade_nova * valor_unid));

	//valor = valor.toFixed(2);
	//valor = valor.replace(".",",");

	valor = format_money(valor);

	//alert("Quantidade: "+quantidade_nova+" Valor Unidade: "+valor_unid+" Total: "+total);

	document.getElementById('valor_total').value=valor;
	document.getElementById('valor_liquido').value=valor;
	document.getElementById('qtdade['+num+']').value=quantidade_nova;
	//calcula_parcela(document.getElementById('n_parcelas').value, document.getElementById('entrada').value, valor);

}


function somavalor3(quantidade_nova, quantidade_antiga, valor_unid, total, num){

//quantidade_antiga = Aqui não é usado

	total = total.replace(".","");
	total = total.replace(",",".");
	total = parseFloat(total);

	valor_unid = valor_unid.replace(".","");
	valor_unid = valor_unid.replace(",",".");
	valor_unid = parseFloat(valor_unid);

	valor = parseFloat(total + (quantidade_nova * valor_unid));

	//valor = valor.toFixed(2);
	//valor = valor.replace(".",",");

	valor = format_money(valor);

	document.getElementById('valor_total').value=valor;
	document.getElementById('valor_liquido').value=valor;
	document.getElementById('qtdade['+num+']').value=quantidade_nova;

	document.getElementById('entrada').value=valor;
	document.getElementById('n_parcelas').value=0;
	document.getElementById('valor_parcelas').value=0;

}

//pega o emial preenchido e preenche o login
function preenche_login(email){
	document.getElementById('login').value=email;
}



function calcula_acrescimo_semi(porcentagem, valor_convite_atual, qtdade){


	valor_convite_atual = valor_convite_atual.replace(".","");
	valor_convite_atual = valor_convite_atual.replace(",",".");
	valor_convite_atual = parseFloat(valor_convite_atual);

	valor_novo = ((porcentagem/100)* valor_convite_atual) + valor_convite_atual;
	//alert('Valor atual '+valor_convite_atual);
	//alert(valor_novo);
	total = document.getElementById('valor_total').value;
	total = total.replace(".","");
	total = total.replace(",",".");
	total = parseFloat(total);

	valor = ((qtdade * valor_novo)+total)-(valor_convite_atual * qtdade);

	valor_novo = format_money(valor_novo);
	valor = format_money(valor);


	document.getElementById('valor_total').value=valor;
	document.getElementById('valor_liquido').value=valor;
	document.getElementById('valor[1]').value=valor_novo;

}

function calcula_acrescimo_luxo(porcentagem, valor_convite_atual, qtdade){


	valor_convite_atual = valor_convite_atual.replace(".","");
	valor_convite_atual = valor_convite_atual.replace(",",".");
	valor_convite_atual = parseFloat(valor_convite_atual);

	valor_novo = ((porcentagem/100)* valor_convite_atual) + valor_convite_atual;
	total = document.getElementById('valor_total').value;
	total = total.replace(".","");
	total = total.replace(",",".");
	total = parseFloat(total);

	valor = ((qtdade * valor_novo)+total)-(valor_convite_atual * qtdade);

	valor_novo = format_money(valor_novo);
	valor = format_money(valor);


	document.getElementById('valor_total').value=valor;
	document.getElementById('valor_liquido').value=valor;
	document.getElementById('valor[2]').value=valor_novo;

}
