// JavaScript Document

var url = "ObtemDescricao.php?id="; // The server-side script
var url2 = "AdicionaNome.php?codnome="; // The server-side script
var url3= "RemoveNome.php?codnome="; // The server-side script
var url4 = "gerarnomes.php"; // The server-side script
var url5 = "recomendasite.php?nomerecomenda="; // The server-side script
var url6 = "contato.php?nomesugestao="; // The server-side script
var url7 = "gerarnomes2.php"; // The server-side script
var url8 = "mostralayer.php"; // The server-side script

var accao="";
var descricao="";
var escolhas="";
var inicio="";
function handleHttpResponse() {   
if (http.readyState == 4) {
	  if(http.status==200) {
		  var results=http.responseText;
		  	if (inicio==""){
			  document.getElementById('glideDiv').innerHTML = escolhas + results;
			} else if (inicio=="gerarnomes") {
			  document.getElementById('gerarnomes').innerHTML = results;
			} else if (inicio=="gerarnomes2") {
			  document.getElementById('gerarnomes').innerHTML = results;
			  seg(4);
			} else if (inicio=="recomendar") {
			  document.getElementById('recomenda').innerHTML = results;
			}
				
				
	  	}
	  }
}
       
function requestCustomerInfo() {     
	var sId = document.getElementById("txtcodnome").value;
	var sId2 = document.getElementById("txtcodseleccao").value;
	http.open("GET", url + escape(sId) + "&codseleccao=" + escape(sId2) + "&t="+((new Date()).valueOf()), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}
function adicionaNome() {     
	var sId = document.getElementById("txtcodnome").value;
	var sId2 = document.getElementById("txtcodseleccao").value;
	http.open("GET", url2 + escape(sId) + "&codseleccao=" + escape(sId2) + "&t="+((new Date()).valueOf()), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}
function removeNome() {     
	var sId = document.getElementById("txtcodnome").value;
	var sId2 = document.getElementById("txtcodseleccao").value;
	http.open("GET", url3 + escape(sId) + "&codseleccao=" + escape(sId2) + "&t="+((new Date()).valueOf()), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}
function gerarnomes() {     
	inicio="gerarnomes";
	http.open("GET", url4 + "?t="+((new Date()).valueOf()), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
	setTimeout('gerarnomes()',2000);
}
function gerarnomes2() {     
	inicio="gerarnomes2";
	http.open("GET", url7 + "?t="+((new Date()).valueOf()), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
	setTimeout('gerarnomes2()',4000);
}

function recomendar() {  
	inicio="recomendar";

	var nomerecomenda = document.getElementById("nomerecomenda").value;
	var emailrecomenda = document.getElementById("emailrecomenda").value;
	var nomedestinatariorecomenda = document.getElementById("nomedestinatariorecomenda").value;
	var emaildestinatariorecomenda = document.getElementById("emaildestinatariorecomenda").value;
	var mensagemrecomenda = document.getElementById("mensagemrecomenda").value;
	
	http.open("GET", url5 + escape(nomerecomenda) + "&emailrecomenda=" + escape(emailrecomenda) + "&nomedestinatariorecomenda=" + escape(nomedestinatariorecomenda) + "&emaildestinatariorecomenda=" + escape(emaildestinatariorecomenda) + "&mensagemrecomenda=" + escape(mensagemrecomenda) + "&t="+((new Date()).valueOf()), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function contato() {  
	inicio="recomendar";

	var nomesugestao = document.getElementById("nomesugestao").value;
	var emailsugestao = document.getElementById("emailsugestao").value;
	var assuntosugestao = document.getElementById("assuntosugestao").value;
	var mensagemsugestao = document.getElementById("mensagemsugestao").value;
	
	http.open("GET", url6 + escape(nomesugestao) + "&emailsugestao=" + escape(emailsugestao) + "&assuntosugestao=" + escape(assuntosugestao) + "&mensagemsugestao=" + escape(mensagemsugestao) + "&t="+((new Date()).valueOf()), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function getHTTPObject() {
  var xmlhttp;

  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
   
}
  return xmlhttp;

 
}
var http = getHTTPObject(); // We create the HTTP Object


/****************/
function mD(codnome, codseleccao){
document.getElementById('txtcodnome').value=codnome;
document.getElementById('txtcodseleccao').value=codseleccao;
accao="descricao";
requestCustomerInfo();	
}

function iAN(codnome, codseleccao, ID){
	
document.getElementById('txtcodnome').value=codnome;
document.getElementById('txtcodseleccao').value=codseleccao;


	if (document.getElementById(ID).checked==true){
		accao="adiciona";
		adicionaNome();	
	} else {
		removeNome();
		accao="remove";
		
	}
}

function initStatLyr() {
  // args: id, left, top, w, h, duration of glide to location onscroll, acceleration factor
  // acceleration factor should be -1 to 1. -1 is full deceleration
	var statLyr = new Glider("glideDiv",775,30,null,null,900,-1);
  statLyr.show();
}

function initStatLyrNew() {
  // args: id, left, top, w, h, duration of glide to location onscroll, acceleration factor
  // acceleration factor should be -1 to 1. -1 is full deceleration
	var statLyr = new Glider("glideDiv",600,250,null,null,900,-1);
  statLyr.show();
}
function initStatLyrNomes() {
  // args: id, left, top, w, h, duration of glide to location onscroll, acceleration factor
  // acceleration factor should be -1 to 1. -1 is full deceleration
	var statLyr = new Glider("glideDiv",755,30,null,null,900,-1);
  statLyr.show();
}
