// Função para abrir o Popup da Página

function popup_imagem(pag,largura,altura,barra)
{var Wnd = window.open(pag,"Janela","toolbar=no,location=no,directories=no,scrollbars=yes,resizable=no,copyhistory=no,width="+largura+ ",height="+altura+ ",status=no,left=1, top=1");
	 Wnd.focus();
}

function popup() {
w = 778;
h = 560;
posH = (screen.height - h) / 2;
posW = (screen.width - w) / 2;
window.open('principal.php','MoreiraOrtence','width='+w+',height='+h+',top='+posH+',left='+posW);
}


// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004

function correctPNG() {
	var img;
	var imgName;
	var imgID;
	var imgClass;
	var imgTitle;
	var strNewHTML;
	for ( var i = 0; i < document.images.length; i++ ) {
		img = document.images[i];
		imgName = img.src.toUpperCase();
		if ( imgName.substring(imgName.length-3, imgName.length ) == "PNG") {
			imgID = (img.id) ? "id='" + img.id + "' " : "";
			imgClass = (img.className) ? "class='" + img.className + "' " : "";
			imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText 
			if ( img.align == "left" )
				imgStyle = "float:left;" + imgStyle;
			if ( img.align == "right" )
				imgStyle = "float:right;" + imgStyle;
			if ( img.parentElement.href )
				imgStyle = "cursor:hand;" + imgStyle;
			strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML;
			i = i - 1;
		} //if
	} //Fim do for
}

function AlteraAcompanhe( campo_selecionado ) {
	url = 'acompanhe.php?id=' + campo_selecionado.value;
	location=(url);
}

//Funcao para validacao de e-mail
function valida_email( email ) {
	//Expressao Regular utilizada para validar o endereco de email
	var ExpReg = /^[a-zA-Z0-9_\.-]{2,}@([A-Za-z0-9_-]{2,}\.)+[A-Za-z]{2,4}$/;
	if ( !ExpReg.test(email) ) {
		return false;
	}
	return true;
}

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

function F(s) {
	return document.getElementById(s).value;
}

//Validacao de Contato
function valida_contato() {
	if ( $('nome').value == "" ) {
		alert("O campo NOME é obrigatório!");
		$('nome').focus();
		return false;
	}

	if ( $('email').value == "" ) {
		alert("O campo E-MAIL é obrigatório!");
		$('email').focus();
		return false;
	}

	if ( $('email').value != "" ) {
		if ( !valida_email( $('email').value ) ) {
			alert("Seu E-MAIL não é válido!");
			$('email').focus();
			return false;
		}
	}
	
	if ( $('cliente_mo_s').checked == true ) {
		if ( F('nome_proprietario') == "" ) {
			alert("O campo NOME DO PROPRIETÁRIO é obrigatório!");
			$('nome_proprietario').focus();
			return false;
		}
		if ( F('empreendimento') == "" ) {
			alert("O campo EMPREENDIMENTO é obrigatório!");
			$('empreendimento').focus();
			return false;
		}
		if ( F('edificio') == "" ) {
			alert("O campo EDIFÍCIO é obrigatório!");
			$('edificio').focus();
			return false;
		}
		if ( F('apartamento') == "" ) {
			alert("O campo APARTAMENTO é obrigatório!");
			$('apartamento').focus();
			return false;
		}
	}

	if ( $('mensagem').value == "" ) {
		alert("O campo MENSAGEM é obrigatório!");
		$('mensagem').focus();
		return false;
	}
	return true;
}

//Validacao de Indicacao
function valida_indique() {
	if ( $('seunome').value == "" ) {
		alert("O campo Seu Nome é obrigatório!");
		$('seunome').focus();
		return false;
	}

	if ( $('seuemail').value == "" ) {
		alert("O campo Seu E-mail é obrigatório!");
		$('seuemail').focus();
		return false;
	}

	if ( $('seuemail').value != "" ) {
		if ( !valida_email( $('seuemail').value ) ) {
			alert("Seu E-mail não é válido!");
			$('seuemail').focus();
			return false;
		}
	}
	
	if ( $('nomeamigo').value == "" ) {
		alert("O campo Nome do Amigo(a) é obrigatório!");
		$('nomeamigo').focus();
		return false;
	}

	if ( $('emailamigo').value == "" ) {
		alert("O campo E-mail do Amigo(a) é obrigatório!");
		$('emailamigo').focus();
		return false;
	}

	if ( $('emailamigo').value != "" ) {
		if ( !valida_email( $('emailamigo').value ) ) {
			alert("O campo E-mail do Amigo(a) não é válido!");
			$('emailamigo').focus();
			return false;
		}
	}

	if ( $('comentario').value == "" ) {
		alert("O campo Comentário é obrigatório!");
		$('comentario').focus();
		return false;
	}
	return true;
}

function valida_data() {
	var date = $('data').value;
	var array_data = new Array;
	//vetor que contem o dia o mes e o ano
	array_data = date.split("/");
	erro = false;
	//Valido se a data esta no formato dd/mm/yyyy
	if ( date.search("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}") == -1 )
		erro = true;
	//Valido os meses que nao tem 31 dias com execao de fevereiro
	if ( ( ( array_data[1] == 4 ) || ( array_data[1] == 6 ) || ( array_data[1] == 9 ) || ( array_data[1] == 11 ) ) && ( array_data[0] > 30 ) )
		erro = true;
	//Valido o mes de fevereiro
	if ( array_data[1] == 2 ) {
		//Valido ano que nao e bissexto
		if ( ( array_data[0] > 28 ) && ( ( array_data[2] % 4 ) != 0 ) )
			erro = true;
		//Valido ano bissexto
		if ( ( array_data[0] > 29 ) && ( ( array_data[2] % 4 ) == 0 ) )
			erro = true;
	}
	if ( erro ) {
		alert("Data Inválida");
		$('data').focus();
	}
}

function amplia_imagem( imagem, title, desc ) {
	PositionX = 0;
	PositionY = 0;
	window.open('imagem.php?imagem=' + imagem + '&title=' + title + '&desc=' + desc, '', 'resizable=1,scrollbars=no,width=100,height=100,left='+PositionX+',top='+PositionY);
}

window.attachEvent("onload", correctPNG);