/*readyState:
0 = não inicializado           1 = carregando      2 = carregado    3 = modo interativo     4 = completado
*/

var tempHTML2;
var req;
var req2;
var parametros = new Array();
var primeiraVez = true;

var htmlCarregando = "<br><table width=\"154\" height=\"36\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"divCarregando\"><tr><td width=\"34\" height=\"36\" align=\"right\"><img alt=\"\" src=\"images/carregando.gif\" width=\"18\" height=\"18\"></td><td width=\"10\" align=\"center\" class=\"fonte21\">&nbsp;</td><td width=\"110\" align=\"left\" class=\"fonte21\" style=\"font-size:15px;\">carregando...</td></tr></table>";

var strBug = "<script type=\"text/javascript\" language=\"javascript\">";

//carregaPagina = onnavigate("carregaPagina", function(url) {
function carregaPagina(url) {
	makeHistory(url);
	okk = false;
	try {
		//verifica se tem alguma funcao concatenada com a url
		if(url.indexOf("{")!=-1) {			
			funcao = url.substring(url.indexOf("{")+1, url.length);
			if(funcao.indexOf("!")!=-1) {				
				par = funcao.substring(funcao.indexOf("!")+1, funcao.length);
				par = par.split("&");
				funcao = funcao.substring(0, funcao.indexOf("!"));
				temParametro = true;
			} else {
				temParametro = false;
			}
			url = url.substring(0, url.indexOf("{"));
			if(funcao=="paginaProduto") {
				okk = true;	
			} else {
				okk = false;		
			}	
			temFuncao = true;
		} else {
			temFuncao = false;			
		}
				
		if(url == "") {
			alert("?????");
			return;
		}
		
		//cria o objeto de requisição
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			// Internet Explorer Windows
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		//req.async = false;
		
		if(req) {
			req.onreadystatechange = function() {			
				lugarACarregar = document.getElementById("corpo");
				if(req.readyState == 4) {
					if(okk) {
						window.setTimeout(recarregaPagProd, 1000, par[0]);
					}
					tempHTML2 = req.responseText;
					if(lugarACarregar!=null) {
						
						//lugarACarregar.innerHTML = req.responseText;
						if(req.responseText.substring(0, strBug.length)!=strBug) {
							lugarACarregar.innerHTML = req.responseText;	
						} else {
							carregaPagina(url);
							return ;
						}
						
						if(temFuncao) {
							if(temParametro) {								
								funcao = funcao + "(";
								for(i=0;i<par.length-1;i++) {
									funcao = funcao + "'" + par[i] + "', ";
								}
								funcao = funcao + "'" + par[i] + "'";							
								funcao = funcao + ");";
							} else {
								funcao = funcao + "();";
							}							
							eval(funcao);
						}						
						switch(url) {							
							case "home.html": {
								desmarcarMenu(true);
								break;
							}							
							case "empresa.html": {
								itemMenuId = 1;
								marcarMenu(1);
								break;
							}
							case "produtos.html": {
								itemMenuId = 2;
								marcarMenu(2);
								break;
							}
							case "fonoaudiologia.html": {
								itemMenuId = 3;
								marcarMenu(3);								
								if(abaFono!=null) {
									abaClicar(abaFono, true);
								} else {
									abaClicar(0);
								}								
								break;	
							}
							case "fisioterapia.html": {
								itemMenuId = 4;
								marcarMenu(4);
								break;
							}
							case "emDesenvolvimento.html": {
								itemMenuId = 5;
								marcarMenu(5);
								break;
							}							
							case "downloads.html": {
								itemMenuId = 7;
								marcarMenu(7);							
								carregarPaginaEm("listaDownloads.html", "divFormDown");
								break;
							}		
							case "controleL.html": {
								itemMenuId = 13;
								marcarMenu(13);													
								//carregarPaginaEm("listaDownloads.html", "divFormDown");
								carregarControleL();
								break;
							}	
							case "cadastro.html": {
								if(!temFuncao) {									
									interesseId = 0;
								}								
								primeiroClique = true;
								itemMenuId = 8;
								marcarMenu(8);	
								break;
							}
							case "cadastroDesenv.html": {
								primeiroClique = true;
								itemMenuId = 8;
								marcarMenu(8);	
								break;
							}
							case "atualizacoes.html": {
								itemMenuId = 6;
								marcarMenu(6);
								//atualizarF							
								montaCheckProd2(3, "marcarCheckAtual", "tdCheck");
								//carregarPaginaEm("atualizaTodos.html", "corpoAtual");
								break;
							}
							case "representantes.html": {
								itemMenuId = 9;
								marcarMenu(9);
								break;
							}
							case "suporte.html": {
								itemMenuId = 10;
								marcarMenu(10);
								montaCheckProd2(3, "marcarCheck", "tdProduto");
								break;
							}						
							case "contato.html": {
								marcarMenu(11);
								itemMenuId = 11;
								break;
							}
							case "artigosPublicacoes.html": {
								itemMenuId = 12;
								marcarMenu(12);
								break;
							}
							case "faqs.html": {
								marcarMenu(10);
								itemMenuId = 10;
								break;
							}
							case "audiReport.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(0);
								break;	
							}
							case "fonoView.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(1);
								break;	
							}
							case "avalie.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(2);
								break;	
							}
							case "pedroNaCasa.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(3);
								break;	
							}
							case "desafioFonemas.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(4);
								break;	
							}
							case "voiceReport.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(5);
								break;	
							}
							case "fonoTools.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(6);
								break;	
							}
							case "voxGames.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(7);
								break;	
							}
							case "fonoFlex.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(8);
								break;	
							}
							case "voxMetria.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(9);
								break;	
							}
							case "fonospeak.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(10);								
								break;	
							}
							case "fisiMetrix.html": {
								marcarMenu(4);
								itemMenuId = 4;
								carregaPagProd(12);								
								break;	
							}
							case "earMix.html": {								
								//window.location.href = "#earMix.html";
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(15);								
								break;	
							}
							case "pedroParque.html": {								
								//window.location.href = "#earMix.html";
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(16);								
								break;	
							}
							case "motrisis.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(17);								
								break;	
							}
							case "vocalgrama.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(18);								
								break;	
							}
							case "andreaPureAudioUSB.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(19);								
								break;	
							}
							case "memoTraining.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(22);								
								break;	
							}	
							case "triAudi.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(23);								
								break;	
							}
						}						
						scrollTo(0,0);		
						document.title = "CTS Informática - Softwares para Fonoaudiologia e Fisioterapia";
					}
				} else if(req.readyState > 4) {
					alert("erro: " + req.readyState);
				} else if(req.readyState==1 && lugarACarregar!=null) {
					//lugarACarregar.innerHTML = htmlCarregando;	
					if(htmlCarregando.substring(0, strBug.length)!=strBug) {
						lugarACarregar.innerHTML = htmlCarregando;	
					} else {
						carregaPagina(url);
						return ;
					}
				} 				
			}
			req.open("GET", url, true);
			req.send(null);
		}
	} catch(e) {
		alert("Erro ao carregar a pagina!\n\nMotivo: " + e);		
	}
}
//});

function carregaPaginaAncora(url, ancora) {
  try {
	  if(url == "") {
    	return;
	  }
	  if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	  // Internet Explorer Windows
	  } else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  //req.async = false;
	  
	  if(req) {
		req.onreadystatechange = function() {
			var lugarACarregar = document.getElementById("corpo");
			if(req.readyState == 4) {
				
				//lugarACarregar.innerHTML = req.responseText;
				if(req.responseText.substring(0, strBug.length)!=strBug) {
					lugarACarregar.innerHTML = req.responseText;	
				} else {
					carregaPaginaAncora(url, ancora);
					return ;
				}
				
				gotoAncora(ancora);
				//ajustarTela();				
			} else if(req.readyState > 4) {
				alert("erro: " + req.readyState);
			} else {
				if(req.readyState == 1) {
					//lugarACarregar.innerHTML = htmlCarregando;
					if(htmlCarregando.substring(0, strBug.length)!=strBug) {
						lugarACarregar.innerHTML = htmlCarregando;	
					} else {
						carregaPaginaAncora(url, ancora);
						return ;
					}
				}
			}			
		}
		req.open("GET", url, true);
		req.send(null);
	  }
	} catch(e) {
		alert("Erro ao carregar a pagina!\n\nMotivo: " + e);		
	}
}

function carregarPaginaEm(url, idLugar) {	
	var parameters = null;

	if(url.indexOf("?")>-1) {
		var tempUrl = url.substring(url.indexOf("?")+1, url.length);
		if(tempUrl.indexOf("=")>-1) {
			parameters = tempUrl;
		}
	}

	try {	
	
		if(url.indexOf("{")!=-1) {			
			funcao = url.substring(url.indexOf("{")+1, url.length);
			if(funcao.indexOf("!")!=-1) {
				par = funcao.substring(funcao.indexOf("!")+1, funcao.length);
				par = par.split("&");
				funcao = funcao.substring(0, funcao.indexOf("!"));
				temParametro = true;
			} else {
				temParametro = false;
			}
			url = url.substring(0, url.indexOf("{"));
			temFuncao = true;
		} else {
			temFuncao = false;
		}
		
		if(url == "") {
			alert("?????");
			return;
		}
	
		if(idLugar=="") {
			return;
		} else {
			var lugarACarregar = document.getElementById(idLugar);	
		}		
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			// Internet Explorer Windows
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		//req.async = false;
		if(req) {	
			req.onreadystatechange = function() {
				if(req.readyState == 4) {					
					//lugarACarregar.innerHTML = req.responseText;	
					if(req.responseText.substring(0, strBug.length)!=strBug) {
						lugarACarregar.innerHTML = req.responseText;	
					} else {
						carregarPaginaEm(url, idLugar);
						return ;
					}
					
					if(temFuncao) {	
						if(temParametro) {
							funcao = funcao + "(";
							for(i=0;i<par.length-1;i++) {
								funcao = funcao + "'" + par[i] + "', ";
							}
							funcao = funcao + "'" + par[i] + "'";							
							funcao = funcao + ");";
						} else {
							funcao = funcao + "();";
						}						
						eval(funcao);						
					}		
					
					switch(url) {
						case "fonoaudiologia.html": {
							alert("fonoaudiologia em");
							if(abaFono!=null) {
								abaClicar(abaFono);
								carregarProdutos(abaFono);
							} else {
								abaClicar(0);
							}
							break;
						}
						case "listaDownloads.html": {
							primeiroClique = true;	
							break;
						}
						case "comprarProdutos.html": {
							preparaCompra();
							break;
						}
						case "popUpProdutos.html": {
							montaComboProdutos();
							break;
						}
						case "audiReport.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(0);
							break;	
						}
						case "fonoView.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(1);
							break;	
						}
						case "avalie.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(2);
							break;
						}
						case "pedroNaCasa.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(3);
							break;
						}
						case "desafioFonemas.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(4);
							break;
						}
						case "voiceReport.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(5);
							break;
						}
						case "fonoTools.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(6);
							break;	
						}
						case "voxGames.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(7);
							break;	
						}
						case "fonoFlex.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(8);
							break;	
						}
						case "voxMetria.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(9);
							break;	
						}
						case "fonospeak.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(10);
							break;	
						}
						case "fisiMetrix.html": {
							marcarMenu(4);
							itemMenuId = 4;
							carregaPagProd(12);								
							break;	
						}
						case "earMix.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(15);								
							break;	
						}
						case "pedroParque.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(16);								
							break;	
						}
						case "motrisis.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(17);								
							break;	
						}
						case "vocalgrama.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(18);								
							break;	
						}
						case "andreaPureAudioUSB.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(19);								
							break;	
						}
						case "memoTraining.html": {
							marcarMenu(3);
							itemMenuId = 3;
							carregaPagProd(22);								
							break;	
						}	
						case "triAudi.html": {
								marcarMenu(3);
								itemMenuId = 3;
								carregaPagProd(23);								
								break;	
							}
					}	
					//ajustarTela();
				} else if(req.readyState > 4) {
					alert("erro: " + req.readyState);
				} else {
					if(req.readyState == 1) {
						//lugarACarregar.innerHTML = htmlCarregando;
						if(htmlCarregando.substring(0, strBug.length)!=strBug) {
							lugarACarregar.innerHTML = htmlCarregando;	
						} else {
							carregarPaginaEm(url, idLugar);							
							return ;
						}
					}
				}
			}
			req.open("GET", url, true);
			if(parameters!=null) {			
				req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				req.setRequestHeader("Content-length", parameters.length);
				req.setRequestHeader("Connection", "close");
				req.send(parameters);
			} else {
				req.send(null);		
			}
		}

	} catch(e) {
		alert("Erro ao carregar a pagina!\n\nMotivo: " + e);		
	}
}

function carregarPaginaDadosEm(url, idLugar) {
  	try {		
		urlPag = url.substring(0, url.indexOf("*"));
		
		if(idLugar=="") {
			return;
		} else {
			var lugarACarregar = document.getElementById(idLugar);	
		}
		
		if (url == "") {
			return;
		}
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			// Internet Explorer Windows
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		//req.async = false;
		if(req) {	
			req.onreadystatechange = function() {	
				if(req.readyState == 4) {					
					
					novoHTML = req.responseText;
					
					tempParam = url.substring(url.indexOf("*")+1, url.length);					
					cont = 0;
					parametros = new Array();
					
					while(tempParam.indexOf("&")!=-1) {
						parametros[cont] = tempParam.substring(0, tempParam.indexOf("&"));
						tempParam = tempParam.substring(tempParam.indexOf("&")+1, tempParam.length);
						cont++;					
					}
					parametros[cont] = tempParam;
					
					for(i=0;i<parametros.length;i++) {
						novoHTML = novoHTML.replace("!!"+(i+1)+"!!", parametros[i]);
					}
							
					lugarACarregar.innerHTML = novoHTML;					
					
					if(urlPag=="popUpProdutos.html") {
						montaComboProdutos(Number(parametros[0])+1);
					}					
					
				} else if(req.readyState > 4) {
					alert("erro: " + req.readyState);
				} else {
					if(req.readyState==1) {
						lugarACarregar.innerHTML = htmlCarregando;
					}
				}
			}
			req.open("GET", urlPag, true);
			req.send(null);
		}

	} catch(e) {
		alert("Erro ao carregar a pagina!\n\nMotivo: " + e);		
	}
}

function carregaDados(url) {
  	try {		
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			// Internet Explorer Windows
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		//req.async = false;
		if(req) {	
			req.onreadystatechange = function() {	
				if(req.readyState == 4) {
					novoHTML = req.responseText;
					return novoHTML;					
				} else if(req.readyState > 4) {
					alert("erro: " + req.readyState);
				}
			}
			req.open("GET", urlPag, true);
			req.send(null);
		}

	} catch(e) {
		alert("Erro ao carregar a pagina!\n\nMotivo: " + e);		
	}
}

var http_request = false;

function makePOSTRequest(url, idLocal, parameters) {
	
	http_request = false;	
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			   http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	//http_request.async = false;
	if (!http_request) {
		alert('Não foi possível criar uma instância de XMLHTTP');
		return false;
	}  
  	http_request.onreadystatechange = function() {
		if(http_request.readyState==4) {
			document.getElementById(idLocal).innerHTML = http_request.responseText;
		}
	}	
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function getFormSuporte(obj, idLocal) {
  var poststr = "nome=" + encodeURI(document.getElementById("campoNome").value);
  poststr += "&email=" + encodeURI(document.getElementById("campoEmail").value);
  poststr += "&telefone=" + encodeURI(document.getElementById("campoTelefone").value);
  poststr += "&produtos=" + encodeURI(document.getElementById("campoProdutos").value);
  poststr += "&questao=" + encodeURI(document.getElementById("campoQuestao").value);

  makePOSTRequest('enviaEmailSuporte.php', idLocal, poststr);
  document.getElementById("divGeral2").innerHTML = "&nbsp;";
}

function getFormDownload(obj, idLocal) {
  var poststr = "nome=" + encodeURI(document.getElementById("campoNome").value);
  poststr += "&profissao=" + encodeURI(document.getElementById("campoProfissao").value);
  poststr += "&endereco=" + encodeURI(document.getElementById("campoEndereco").value);
  poststr += "&cidade=" + encodeURI(document.getElementById("campoCidade").value);
  poststr += "&estado=" + encodeURI(document.getElementById("campoEstado").value);
  poststr += "&cep=" + encodeURI(document.getElementById("campoCEP").value);
  poststr += "&pais=" + encodeURI(document.getElementById("campoPais").value);
  poststr += "&telefone=" + encodeURI(document.getElementById("campoTelefone").value);
  poststr += "&email=" + encodeURI(document.getElementById("campoEmail").value);
  poststr += "&nomeDownload=" + encodeURI(document.getElementById("campoDownload").value);
  poststr += "&downloadId=" + encodeURI(document.getElementById("campoDownloadId").value);

  makePOSTRequest('enviaEmailDownload.php', idLocal, poststr);
  document.getElementById("divGeral2").innerHTML = "&nbsp;";
}

function getFormCadastro(obj, idLocal) {
  var poststr = "nome=" + encodeURI(document.getElementById("campoNome").value);
  poststr += "&endereco=" + encodeURI(document.getElementById("campoEndereco").value);
  poststr += "&bairro=" + encodeURI(document.getElementById("campoBairro").value);
  poststr += "&cidade=" + encodeURI(document.getElementById("campoCidade").value);
  poststr += "&estado=" + encodeURI(document.getElementById("campoEstado").value);
  poststr += "&cep=" + encodeURI(document.getElementById("campoCEP").value);
  poststr += "&pais=" + encodeURI(document.getElementById("campoPais").value);
  poststr += "&telefoneR=" + encodeURI(document.getElementById("campoTelefoneR").value);
  poststr += "&telefoneC=" + encodeURI(document.getElementById("campoTelefoneC").value);
  poststr += "&fax=" + encodeURI(document.getElementById("campoFax").value);
  poststr += "&email=" + encodeURI(document.getElementById("campoEmail").value);
  poststr += "&interesse=" + encodeURI(document.getElementById("campoInteresse").value);
  poststr += "&produtos=" + encodeURI(document.getElementById("campoProdutos").value);
  poststr += "&sugestao=" + encodeURI(document.getElementById("campoSugestao").value);
 
  makePOSTRequest('enviaEmailCadastro.php', idLocal, poststr);
  document.getElementById("divGeral2").innerHTML = "&nbsp;";
}

function getFormCompra(obj, idLocal) {
	var poststr = "nome=" + encodeURI(document.getElementById("campoNome").value);
	poststr += "&rg=" + encodeURI(document.getElementById("campoRg").value);
	poststr += "&endereco=" + encodeURI(document.getElementById("campoEndereco").value);
	poststr += "&nro=" + encodeURI(document.getElementById("campoNro").value);
	poststr += "&complemento=" + encodeURI(document.getElementById("campoComplemento").value);
	poststr += "&bairro=" + encodeURI(document.getElementById("campoBairro").value);
	poststr += "&cidade=" + encodeURI(document.getElementById("campoCidade").value);
	poststr += "&estado=" + encodeURI(document.getElementById("campoEstado").value);
	poststr += "&cep=" + encodeURI(document.getElementById("campoCEP").value);
	poststr += "&pais=" + encodeURI(document.getElementById("campoPais").value);
	poststr += "&telefoneR=" + encodeURI(document.getElementById("campoTelefoneR").value);
	poststr += "&telefoneC=" + encodeURI(document.getElementById("campoTelefoneC").value);
	poststr += "&celular=" + encodeURI(document.getElementById("campoCelular").value);
	poststr += "&email=" + encodeURI(document.getElementById("campoEmail").value);
	poststr += "&compraAtr=" + (document.getElementById("campoCompraAtr").value);
	poststr += "&params=" + (document.getElementById("campoParams").value);
	poststr += "&pessoaClinica=" + encodeURI(document.getElementById("campoPessoaClinica").value);
	poststr += "&CpfCgc=" + encodeURI(document.getElementById("campoCpfCgc").value);  
	poststr += "&valorDeposito=" + encodeURI(document.getElementById("campoValorDeposito").value);	
	poststr += "&compraAtrCTS=" + encodeURI(document.getElementById("campoPPC").value);
	poststr += "&codVer=" + encodeURI(document.getElementById("campoCodVer").value);
	poststr += "&nroPedido=" + encodeURI(document.getElementById("campoNroPedido").value);	
	
	//poststr += "&detalhes=" + encodeURI(document.getElementById("campoDetalhes").value);  
	//poststr += "&strFinal=" + encodeURI(document.getElementById("campoStrFinal").value);  
	makePOSTRequest("enviaEmailCompra.php", idLocal, poststr);
	document.getElementById("divGeral2").innerHTML = "&nbsp;";
}

function getFormAssinaAudiReport(obj, idLocal) {
  var poststr = "nome=" + encodeURI(document.getElementById("campoNome").value);
  poststr += "&rg=" + encodeURI(document.getElementById("campoRg").value);  
  poststr += "&endereco=" + encodeURI(document.getElementById("campoEndereco").value);
  poststr += "&nro=" + encodeURI(document.getElementById("campoNro").value);
  poststr += "&complemento=" + encodeURI(document.getElementById("campoComplemento").value);
  poststr += "&bairro=" + encodeURI(document.getElementById("campoBairro").value);
  poststr += "&cidade=" + encodeURI(document.getElementById("campoCidade").value);
  poststr += "&estado=" + encodeURI(document.getElementById("campoEstado").value);
  poststr += "&cep=" + encodeURI(document.getElementById("campoCEP").value);
  poststr += "&pais=" + encodeURI(document.getElementById("campoPais").value);
  poststr += "&telefoneR=" + encodeURI(document.getElementById("campoTelefoneR").value);
  poststr += "&telefoneC=" + encodeURI(document.getElementById("campoTelefoneC").value);
  poststr += "&celular=" + encodeURI(document.getElementById("campoCelular").value);
  poststr += "&email=" + encodeURI(document.getElementById("campoEmail").value);
  poststr += "&compraAtr=" + encodeURI(document.getElementById("campoCompraAtr").value);
  poststr += "&pessoaClinica=" + encodeURI(document.getElementById("campoPessoaClinica").value);
  poststr += "&CpfCgc=" + encodeURI(document.getElementById("campoCpfCgc").value);
  poststr += "&pagAudiR=" + encodeURI(pagAudiR);
  poststr += "&agencia=" + encodeURI(document.getElementById("campoAgencia").value);
  poststr += "&conta=" + encodeURI(document.getElementById("campoConta").value);
  poststr += "&titular=" + encodeURI(document.getElementById("campoTitular").value);  
  poststr += "&nroPedido=" + encodeURI(document.getElementById("campoNroPedido").value);		
  poststr += "&valor=" + encodeURI(document.getElementById("campoValor").value);
  poststr += "&pagAudiR=" + encodeURI(document.getElementById("campoPagAudiR").value);
  
  makePOSTRequest('enviaEmailAssinaAudiReport.php', idLocal, poststr);
  document.getElementById("divGeral2").innerHTML = "&nbsp;";
}

function calcularFrete(cepOrigem, cepDestino, peso, destinoId) {

	document.getElementById(destinoId).innerHTML = "calculando...";	
	
	if (window.XMLHttpRequest) {
		reqC = new XMLHttpRequest();
		// Internet Explorer Windows
	} else if (window.ActiveXObject) {
		reqC = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	reqC.open("POST", "calcularFrete.php", true );
    reqC.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    reqC.send("cepOrigem="+cepOrigem+"&cepDestino="+cepDestino);

    reqC.onreadystatechange = function() { 
       if(reqC.readyState == 4 && reqC.status==200) {
			html = reqC.responseText;
			if(html.indexOf("Valor do Servi&ccedil;o")!=-1) {
				html = 	html.substring(html.indexOf("Valor do Servi&ccedil;o"), html.indexOf("Valor do Servi&ccedil;o")+200);				
				if(html.indexOf("R$")!=-1) {
					html = html.substring(html.indexOf("R$"), html.length);
					valor = html.substring(html.indexOf("R$")+3, html.indexOf("<"));
					if(valor!=null || valor!="") {
						valorFrete = Number(valor.replace(",", "."));
						document.getElementById(destinoId).innerHTML = "R$ " + valor;
						if(arrCestaCompras.length>0) {
							calcularValores();
						}
					} else {
						document.getElementById(destinoId).innerHTML = "CEP não encontrado.";
					}
				}
			}						
        } else {
			document.getElementById(destinoId).innerHTML = "calculando...";
		}
    }
}