//var base_url = "http://megan/abemo/index.php/";
var base_url = "http://www.abemo.org/index.php/";

function excluirRegistro(id,tipo)
{	
confirma = confirm('Tem certeza que deseja excluir este registro?');
	if(confirma)
	{
			location.href= base_url+tipo+'/excluir/'+id;
	}else{
			return false;
	}
}

function excluirNoticia(id,tipo)
{	
confirma = confirm('Tem certeza que deseja excluir este registro?');
	if(confirma)
	{
		location.href= base_url+tipo+'/excluir/'+id;
	}else{
			return false;
	}
}

function excluirCurriculo(id)
{	
confirma = confirm('Tem certeza que deseja excluir este registro?');
	if(confirma)
	{
		location.href= base_url+'curriculos/excluir/'+id;
	}else{
			return false;
	}
}

//////////////////////////////////////////////////////////
/////////////////funcao p/ jump menu//////////////////////
//////////////////////////////////////////////////////////
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

////////////////////////////////////////////////////////////
/////// funcao p/ abrir popup no centro do navegador ///////
////////////////////////////////////////////////////////////
function centerPopup(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll;
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}

///////////////////////////////////////////////////////
/////////////// função para as divs ///////////////////
///////////////////////////////////////////////////////

function MM_reloadPage(init){
	if (init==true) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)){
			document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
		}
	} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH){
		location.reload();
	}
}
MM_reloadPage(true);

////////////////////////////////////////////////////
/////// funcao p/ abrir o site em tela cheia ///////
////////////////////////////////////////////////////
function OpenMeFull(pagina){
	remote = window.open(pagina, 'janela_openFull', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=0,left=0');
	remote.resizeTo(window.screen.availWidth, window.screen.availHeight);
}


//////////////////////////////////////////////
//// função para digitar apenas números //////
//////////////////////////////////////////////
function bloqueia_alfa(e){
navegador = /msie/i.test(navigator.userAgent);
if (navegador)
	var tecla = event.keyCode;
else
	var tecla = e.which;
	if(tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else{
	if (tecla != 8) // backspace
		return false;
	else
		return true;    
	}
}

///////////////////////////////////////////////////////
/////// funções para formatar campos de valor /////////
///////////////////////////////////////////////////////
function Limpar(valor, validos){
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++){
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0){
			result += aux;
		}
	}
	return result;
}

function Formata(campo,tammax,teclapres,decimal){
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal

	if (tam < tammax && tecla != 8){
		tam = vr.length + 1;
	}

	if (tecla == 8){
		tam = tam - 1;
	}

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){

		if ( tam <= dec ){
			campo.value = vr;
		}

		if ( (tam > dec) && (tam <= 5) ){
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam );
		}
		
		if ( (tam >= 6) && (tam <= 8) ){
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ); 
		}

		if ( (tam >= 9) && (tam <= 11) ){
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam );
		}

		if ( (tam >= 12) && (tam <= 14) ){
			campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam );
		}
		
		if ( (tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam );
		}
	}
}


//////////////////////////////////////////////////////////
////////////////função para as divs///////////////////////
//////////////////////////////////////////////////////////

function MM_reloadPage(init){
	if (init==true) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)){
			document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
		}
	} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH){
		location.reload();
	}
}
MM_reloadPage(true);


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-->

$(document).ready(function(){
	//verifica se o e-mail já está cadastrado
	//var base_url = 'http://megan/abemo/';
	var base_url = 'http://www.abemo.org/';
	$('#login').change(function(){	
		$.ajax({
			type: "POST",
			url: 'verifica_login',
			data: "login="+$('#login').val(),
			dataType: "html",
			success: function(resp){	
									
									$("#loading_ajax").html("");
									if(resp == 0)
									{
										$("#loading_ajax").html("<img src=\""+base_url+"imgs/checked.gif\"/>").fadeIn('slow');
										$('input').removeAttr('disabled');
										$('#senha').focus();
									}
									else
									{
										$('input').removeAttr('disabled');
										$('#login').val('');
										$('#login').focus();
										$("#loading_ajax").html("<img src=\""+base_url+"imgs/unchecked.gif\"/>").fadeIn('slow');
									}

			},

			beforeSend: function(){
					$("#loading_ajax").html("<img src=\""+base_url+"imgs/loading.gif\"/>").fadeIn('slow');
					$('input').attr('disabled', true);
				}			
										  
		});
	});
	
	$('#login_alterar').change(function(){	
		$.ajax({
			type: "POST",
			url: '../verifica_login',
			data: "login="+$('#login_alterar').val(),
			dataType: "html",
			success: function(resp){	
									
									$("#loading_ajax").html("");
									if(resp == 0)
									{
										$("#loading_ajax").html("<img src=\""+base_url+"imgs/checked.gif\"/>").fadeIn('slow');
										$('input').removeAttr('disabled');
										$('#senha').focus();
									}
									else
									{
										$('input').removeAttr('disabled');
										$('#login_alterar').val('');
										$('#login_alterar').focus();
										$("#loading_ajax").html("<img src=\""+base_url+"imgs/unchecked.gif\"/>").fadeIn('slow');
									}

			},

			beforeSend: function(){
					$("#loading_ajax").html("<img src=\""+base_url+"imgs/loading.gif\"/>").fadeIn('slow');
					$('input').attr('disabled', true);
				}			
										  
		});
	});	
	
	$('#login_associado').change(function(){	
		$.ajax({
			type: "POST",
			url: 'seja_associado/verifica_login',
			data: "login="+$('#login_associado').val(),
			dataType: "html",
			success: function(resp){	
									
									$("#loading_ajax").html("");
									if(resp == 0)
									{
										$("#loading_ajax").html("<img src=\""+base_url+"imgs/checked.gif\"/>").fadeIn('slow');
										$('input').removeAttr('disabled');
										$('#senha').focus();
									}
									else
									{
										$('input').removeAttr('disabled');
										$('#login_associado').val('');
										$('#login_associado').focus();
										$("#loading_ajax").html("<img src=\""+base_url+"imgs/unchecked.gif\"/>").fadeIn('slow');
									}

			},

			beforeSend: function(){
					$("#loading_ajax").html("<img src=\""+base_url+"imgs/loading.gif\"/>").fadeIn('slow');
					$('input').attr('disabled', true);
				}			
										  
		});
	});	
});


