
//************************************************ Internas
function OpenCenteredWindow(url,name,opts, w, h) {
var tp = null, lf = null;

	if (screen != null) {
	   tp = screen.height;
	   if (tp != null) {
			tp = (tp - h) / 2; 
	   }
	   lf = screen.width;
	   if (lf != null) {
			lf = (lf - w) / 2; 
	   }
	   
	}
			 
	if (lf != null) {
		opts = opts + ',left=' + new Number(lf).toString();
	}
		
	if (tp != null) {
		opts = opts +  ',top=' + new Number(tp).toString();
	}	
	
	window.open (url, name, opts);
	
	return false;
} 

function ShowAlert(obj, name) {
	alert('O campo ' + name + ' é obrigatório');
	obj.focus();	
}

function ValidateUsuario(doc) {
var obj, obj2;  

// Nome
obj = doc.getElementById('txtNome');
if ((obj != null)  && (obj.value == '')) {
	ShowAlert (obj, 'Nome');
	return false;	
}

// Email
obj = doc.getElementById('txtEmail');
if (obj != null)  {
	if (obj.value == '') {
		ShowAlert (obj, 'E-mail');	
		return false
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value)))	{	
		alert('E-mail inválido');
		obj.focus();	
		return false;
	}
}

// DDD & Telefone
obj = doc.getElementById('txtDDD');
obj2 = doc.getElementById('txtTelefone');
if (obj != null)  {
	if (obj.value != '') {
		if (!(/^(\d{2,4})$/.test(obj.value)))	{		
			alert('DDD inválido');
			obj.focus();	
			return false;
		}
		if ((obj2 != null) && (obj2.value == '')) {
			ShowAlert (obj2, 'Telefone');	
			return false		
		}
	}
}

if (obj2 != null)  {
	if (obj2.value != '') {
		if (!(/^([^01789]\d{1,3}|[789]\d{2,3})(\-)?\d{4}$/.test(obj2.value)))	{	
			alert('Telefone inválido');
			obj2.focus();	
			return false;
		}
		if ((obj != null) && (obj.value == '')) {
			ShowAlert (obj, 'DDD');	
			return false		
		}
	}
}

// Assunto
obj = doc.getElementById('cboAssunto');
if (obj != null)  {
	if (obj.options[obj.selectedIndex].value == '') {
			alert('Escolha um assunto');
			obj.focus();	
			return false;
	}
}

// Mensagem
obj = doc.getElementById('txtMsg');
if (obj != null)  {
	if (obj.value == '') {
		ShowAlert (obj, 'Mensagem');	
		return false
	}
}

return true;
}

//************************************************ Acionadas das páginas
function fncSubmeterFrmEmail (doc) {
var opts;

	if (!ValidateUsuario(doc)) {
		return false;
	}
	
	opts = 'width=400,height=300,location=no,' +
			 'menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';

	OpenCenteredWindow ('about:blank', '_newsletter', opts, 400, 250);
	
	return true;
}
