
contatoDo = function() {
	Ext.Ajax.request({
		url: 'ajaxContato',
		form: 'formcontato',
		method: 'POST',
		success: function(response, opts) {
			var obj = Ext.decode(response.responseText);
			if (!obj.success) {
				alert(obj.errors.reason);
				return;
			}
			window.location = 'contato_confirmado.html';
		},
		failure: function(response, opts) {
			alert('Não foi possível gravar suas informações. Por favor, entre em contato pelo telefone (11) 3474-1099.');
		}
	});
};

loginAcesso = function() {
	displayLoginEmp(false);
	var el = Ext.get("winlogin");
	if (el.isVisible()) {
		el.fadeOut({
		    endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
		    easing: 'easeOut',
		    duration: .5,
		    remove: false,
		    useDisplay: true
		});
		return;
	}
	var left = Ext.get("topacesso").getX() + Ext.get("topacesso").getWidth() - 260;
	var top = Ext.get("topacesso").getY() + Ext.get("topacesso").getHeight() + 11;
	el.setStyle({
		top: top + 'px',
		left: left + 'px'
	});
	el.fadeIn({
	    endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)	
	    easing: 'easeOut',
	    duration: .5
	});
	Ext.get("loginuserid").focus();

};

loginAcessoDo = function() {
	var loginID = Ext.getDom("loginuserid");
	if (!loginID.value || loginID.value=="") {
		alert("Por favor, preencha a identificação do usuário");
		Ext.get("loginuserid").focus();
		return;
	}
	var loginCheck = Ext.getDom("logincheckfun");
	if (loginCheck.checked) {
		alert("Opção para cadastro de funcionários não disponível no momento.");
		loginAcesso();
		return;
	} else {
		/* pesquisa login nas bases */
		displayWaiting(true);
		Ext.Ajax.request({
			url     : 'ajaxAcesso',
			params  : { act : 'chkuser', userid : loginID.value },
			method  : 'POST',
			success : function(response, opts) {
				displayWaiting(false);
				var obj = Ext.decode(response.responseText);
				if (!obj.rowcount || obj.rowcount<=0) {
					alert('Usuário não cadastrado.');
					return;
				}
				if (obj.rowcount==1) {
					//-- único usuário, redireciona para base encontrada
					var url = obj.lst[0].dburl;
					if (url) {
						//-- abre janela de login
						url += "/login/login.jsp?userID="+loginID.value;
			    		window.open(url ,'FatoRHweb','menubar=no, status=yes, location=no, toolbar=no, scrollbars=yes, resizable=yes');  		
			    		window.opener = 'Pay System FolhaWeb';
			    		loginAcesso();
					} else {
						alert('URL de acesso não encontrada. Por favor, entre em contato pelo telefone (11) 3474-1099.');
					}
				} else {
					loginAcesso();
					//-- seleciona base de dados a trabalhar
					var html = "<table width=100% border=0 cellspacing=0 cellpadding=2>";
					html += "<tbody>";
					for (var idx=0; idx<obj.rowcount; idx++) {
						var rec = obj.lst[idx];
						var dbdesc = rec.dbdesc;
						var dburl = rec.dburl + "/login/login.jsp?userID="+loginID.value;
						html += '<tr><td><a href="JavaScript:openFolha(\''+dburl+'\')">'+dbdesc+'</a></td></tr>';
					}
					html += "</table>";
					Ext.fly("winloginemptxt").update(html);
//					Ext.fly("winloginempbottom").select("div").update(html);
//					alert(html);
					displayLoginEmp(true);
				}
			},
			failure: function(response, opts) {
				displayWaiting(false);
				alert('Não foi possível validar informações de login. Por favor, entre em contato pelo telefone (11) 3474-1099.');
			}
		});
	}
};
openFolha = function(url) {
	window.open(url ,'FatoRHweb','menubar=no, status=yes, location=no, toolbar=no, scrollbars=yes, resizable=yes');  		
	window.opener = 'Pay System FolhaWeb';
	displayLoginEmp(false);
};

displayWaiting = function(display) {
	displayWinBack(display);
	var im = Ext.get("imgwaiting");
	if (display) {
		var left = (Ext.get(document.body).getWidth() - 300) / 2;
		var top = (Ext.get(document.body).getHeight() - 110) / 2;
		im.setStyle({ top: top + 'px', left: left + 'px' });
		im.show();
	} else {
		im.hide();
	}
};

displayWinBack = function(display) {
	var el = Ext.get("winback");
	if (display) {
		el.setWidth(Ext.get(document.body).getWidth());
		el.setHeight(Ext.get(document.body).getHeight());
		el.setOpacity(0.3);
		el.show();
	} else {
		el.hide();
	}
};

displayLoginEmp = function(display) {
	var el = Ext.get("winloginemp");
	if (display) {
		var left = (Ext.get(document.body).getWidth() - 500) / 2;
		var top = (Ext.get(document.body).getHeight() - 300) / 2;
		el.setStyle({
			top: top + 'px',
			left: left + 'px'
		});
		el.fadeIn({
		    endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)	
		    easing: 'easeOut',
		    duration: .5
		});
	} else {
		el.fadeOut({
		    endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
		    easing: 'easeOut',
		    duration: .5,
		    remove: false,
		    useDisplay: true
		});
	}
};

