function Initialize() {
	var req;
									
	try{
    	req=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
	    try{
	        req=new ActiveXObject("Microsoft.XMLHTTP");
	    }catch(oc){
	        req=null;
	    }
	}
	if(!req&&typeof XMLHttpRequest!="undefined"){
    	req = new XMLHttpRequest();
	}
	return req;
}

function loginByAjax(ajaxURL, divRetorno) {
		req = Initialize();
		
		email = document.getElementById("txtLoginEmail").value;
		senha = document.getElementById("txtLoginSenha").value;
		/* ajusta url */
		parametros = "email="+email+"&senha="+senha;
		
		//alert(ajaxURL);
		
		if(req!=null){
			req.onreadystatechange = function (){
					switch(req.readyState){
					    case 4:
					    //alert(req.responseText);
			    		if (req.status == 200){
	  	            if( req.responseText == "-1" ) {
	  	            	alert("Login ou senha inválidos!");
	  	            }else {
	  	            	//document.location.href = document.location.href;
	  	            	document.location.reload();
	  	            }				  	            
	  	        }else{
	  	            document.getElementById(divRetorno).innerHTML = "Houve um problema na requisição dos dados : " + req.statusText;
	  	        }
				  }
		 }
					
		 req.open("POST", ajaxURL, true);
		 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		 req.setRequestHeader("Content-length", parametros.length);
		 req.setRequestHeader("Connection", "close");
		 req.send(parametros);
	  }
}

function logoutByAjax(ajaxURL, divRetorno) {
	
		req = Initialize();
		
//		alert(ajaxURL);
		
		 req.open("GET", ajaxURL, true);
		if(req!=null){
			req.onreadystatechange = function (){
					switch(req.readyState){
					  case 4:
			    		if (req.status == 200){
			    			if( req.responseText == "0" ) {
	  	            document.location.reload();
	  	          } else {
	  	            alert("Erro no logout!");
	  	          }
	  	        }else{
	  	            document.getElementById(divRetorno).innerHTML = "Houve um problema na requisição dos dados : " + req.statusText;
	  	        }
				  }
		 }
		 req.send(null);
	  }
}

function verificaEmailCadastradoByAjax(emailUsuario) {
						req = Initialize();
						ajaxURL = "verificaEmailUsuario.php?emailUsuario="+emailUsuario;
						
						if(req!=null){
							req.onreadystatechange = function (){
								if(req.readyState == 4){
									if (req.status == 200){
										if( req.responseText == "1" ) {
											alert('Este email já foi cadastrado!');
											
											document.write(false);
											
										}else{
											req.send(false);
											
										} 	            	
									}else {
										document.getElementById(divRetorno).innerHTML = "Houve um problema na requisição dos dados : " + req.statusText;
									}
								}
							}
							req.open("GET", ajaxURL, true);
							req.send(null);
						} 
				}
	
