// JavaScript Document

verFoto = function (foto) {
	var _foto = document.getElementById("fotodestaque");

	_foto.src = "/thumb.aspx?src=" + foto;
}

var timer = null;
var opcao = {
	iniciar: function() {
		var objBody = document.getElementsByTagName("body").item(0);
		var div = document.createElement("div");
			
		div.setAttribute('id','divfundo');		

		with (div.style) {
			//height = getPageSize()[1] + "px"; //"100%";
			
			if (navigator.appName.indexOf("MSIE 6") >= 0 )
				height = "100%";
			else
				height = document.documentElement.scrollHeight + "px";
				
			width = "100%";
			top = "0px";
			position = "absolute";
			backgroundColor = "#000";
			filter = "alpha(opacity=50)";
			opacity = ".5";
			zIndex = 0;
			visibility = "hidden";
		}

		objBody.appendChild(div);
	},
	
	indique_on: function() {
		var divop	= document.getElementById("divindique");
		var div		= document.getElementById("divfundo");
		
		with (divop.style) {
			zIndex = 1;
			left = ((getPageSize()[0] - divop.clientWidth) / 2) + "px";
			top = ((document.all) ? document.documentElement.scrollTop : window.pageYOffset) +
				((getPageSize()[3] - divop.clientHeight) / 2) + "px";
		}
		
		div.style.visibility = "visible";
		divop.style.visibility = "visible";

		return false;
	},
	
	indique_off: function() {
		var divop = document.getElementById("divindique");
		var div = document.getElementById("divfundo");
		
		div.style.visibility = "hidden";
		divop.style.visibility = "hidden";		

		return false;
	},

	interesse_on: function () {
		var div = document.getElementById("divfundo");
		var divop = document.getElementById("divinteresse")
		
		with (divop.style) {
			zIndex = 1;
			left = ((getPageSize()[0] - divop.clientWidth) / 2) + "px";
			top = ((document.all) ? document.documentElement.scrollTop : window.pageYOffset) +
				((getPageSize()[3] - divop.clientHeight) / 2) + "px";
		}
		
		div.style.visibility = "visible";
		divop.style.visibility = "visible";
		
		return false;
	},

	interesse_off: function() {
		var div = document.getElementById("divfundo");
		var divop = document.getElementById("divinteresse");
		
		div.style.visibility = "hidden";
		divop.style.visibility = "hidden";

		return false;
	},
	
	off: function() {
		var div = document.getElementById("divfundo");
		var divop1 = document.getElementById("divindique");
		var divop2 = document.getElementById("divinteresse");
		
		timer = setInterval("mesmoEmail('" + divop1.style.visibility + "');", 1000);
		
		div.style.visibility = "hidden";
		divop1.style.visibility = "hidden";
		divop2.style.visibility = "hidden";

		return false;
	}
}

mesmoEmail = function(indique) {
	var txtnome		= document.getElementById("txtnome");
	var txtemail	= document.getElementById("txtemail");
	var txtseunome	= document.getElementById("txtseunome");
	var txtseuemail	= document.getElementById("txtseuemail");
	
	try {
		if (indique == "visible") {
			txtnome.value = txtseunome.value;
			txtemail.value = txtseuemail.value;
		} else {
			txtseunome.value = txtnome.value;
			txtseuemail.value = txtemail.value;
		}
	} catch (e) {
		setTimeout("mesmoEmail(" + indique + ");", 1000);
	}
		
	 clearInterval(timer);
}

var fundo = setInterval("opcao.iniciar(); clearInterval(fundo);", 1000);


/* MAIS DETALHES ******************************************************************************/
validaIndique = function (obj) {
	var ret = true;
	var seuNome		= document.getElementById("txtseunome");
	var seuEmail	= document.getElementById("txtseuemail");
	var amigoNome	= document.getElementById("txtnomeamigo");
	var amigoSexo	= document.getElementsByName("rdosexo");
	var amigoEmail	= document.getElementById("txtemailamigo");
	var rdoSexo		= false;

	for (x=0; x<=amigoSexo.length-1; x++) {
		if (amigoSexo[x].checked)
			rdoSexo = true;
	}

	//Indicador
	if (seuNome.value == "") {
		alert("Preencha seu nome");
		seuNome.focus();
		ret = false;
	} else if (seuEmail.value == "") {
		alert("Preencha seu e-mail");
		seuEmail.focus()
		ret = false;
	} else if (!validarEmail(seuEmail)) {
		alert("Seu e-mail parece ser inválido, verifique se o digitou corretamente.");
		seuEmail.select();
		ret = false;
		
	//Indicado
	} else if (amigoNome.value == "") {
		alert("Preencha o nome da sua indicação");
		amigoNome.focus()
		ret = false;
	} else if (!rdoSexo) {
		alert("Escolha o sexo da sua indicação");
		ret = false;
	} else if (amigoEmail.value == "") {
		alert("Preencha o e-mail da sua indicação");
		amigoEmail.focus()
		ret = false;
	} else if (!validarEmail(amigoEmail)) {
		alert("O e-mail da sua indicação parece ser inválido, verifique se o digitou corretamente.");
		amigoEmail.select();
		ret = false;
	}
	
	if (ret) {
		obj.disabled = true;
		obj.value = "  aguarde  ";
		__doPostBack(obj.id,'');
	}
	
	return false;
}

validaInteresse = function(obj) {
	var ret		= true;
	var nome	= document.getElementById("txtnome");
	var email	= document.getElementById("txtemail");

	if (nome.value == "") {
		alert("Por favor preencha seu nome");
		ret = false;
	} else if (email.value == "") {
		alert("Por favor preencha seu e-mail");
		ret = false;
	} else if (!validarEmail(email)) {
		alert("O seu e-mail parece ser inválido, verifique se o digitou corretamente");
		ret = false;
	}

	if (ret) {
		obj.disabled = true;
		obj.value = "  aguarde  ";
		__doPostBack(obj.id,'');
	}
	
	return false;
}


/* CADASTRAR CLIENTES *************************************************************************/
validarEmail = function(obj) {
	var formRegExp = new RegExp("([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(.[a-zA-Z0-9_-]+)+");
	var str = (typeof(obj) == "object") ? obj.value : obj;

	var ok = str.match(formRegExp);
	
	if (ok) 
		return true;
	else
		return false;
}


/* OUTROS ************************************************************************************/
instTXT = function(obj) {
	if (obj.value == "separe os campos com vírgula") {
		obj.value = "";
		obj.style.color = "";
	} else if (obj.value == "") {
		obj.value = "separe os campos com vírgula";
		obj.style.color = "#999";
	}
}
