//seleciona o 'radio' clicado
//insere o valor do radio em um campo hidden

function customRadio(nome,valor,total,id) {
	for (i=1;i<=total;i++) {
		$(nome+i).className = '' ;
	}
	$(nome+valor).className = 'selected' ;
	$(nome).value = valor ;
	document.cartaoForm.id.value = id;
}

function changeCartao(cartaoId,id) {
	document.cartao_desc.action = "cartao.php?cartao=" + cartaoId +"&id=" +id;
	document.cartao_desc.submit();
}
function visualizarCartao() {
	document.cartao_desc.visualizar.value = 1;
	document.cartao_desc.submit();
}

function enviarCartao() {
	//verifica campos
	ok = verifica();
	if (ok) {
		//esconde os botões de visualizar/modificar/enviar
		if($("modificar")){$("modificar").style.display = "none";}
		if($("ver")){$("ver").style.display = "none";}
		$("enviar").href = "#";
		
		//ajax
		var postString = "id=" + document.getElementById("id").value;
		postString += "&nome_de=" + document.getElementById("nome_de").value;
		postString += "&email_de=" + escape(document.getElementById("email_de").value);
		postString += "&nome_para=" + escape(document.getElementById("nome_para").value);
		postString += "&email_para=" + escape(document.getElementById("email_para").value);
		postString += "&msg=" + escape(document.getElementById("msg").value);
		
		//loading
		$("cartao_campo").innerHTML = '<div id="enviando_email"><img src="images/cartao_enviando.gif" /><br /><img src="images/indicator_medium.gif" /></div>';			
		
		new ajax('cartao_send.php', {postBody: postString, update: $('cartao_campo')});		
	}
	
}

function verifica(){
	
	if ($("nome_de").value == ""){
		alert("Informe o seu Nome!");
		$("nome_de").focus();
		return (false);
	}
	if ($("email_de").value == ""){
		alert("Informe o seu Email!");
		$("email_de").focus();
		return (false);
	}
	if ($("nome_para").value == ""){
		alert("Informe o Nome de quem irá receber o cartão!");
		$("nome_para").focus();
		return (false);
	}
	if ($("email_para").value == ""){
		alert("Informe o Email de quem irá receber o cartão!");
		$("email_para").focus();
		return (false);
	}
	if ($("msg").value == ""){
		alert("Informe a Mensagem do cartão!");
		$("msg").focus();
		return (false);
	}		

	return (true) ;

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}