    var error = 0;

    var eventClickJL;

	

	function setSearch(){

		

	}

	

	



	

    function login(page){

        $("#loginSubmitBtn").attr('href','');

        var pos = $("#boxLogin").position();

        createLoading('loginLoad',(pos.top+20)+'px',(pos.left+330)+'px');

        user = $("#txtuser").val();

        pwd  = URLEncode($("#txtpwd").val());

	

        $.ajax({

            type: "POST",

            url: "/user.php",

            timeout:10000,

            data: "user="+user+"&pwd="+pwd,

            success: function(msg){

                $("#loginSubmitBtn").attr('href','javascript:login();');

                removeElement('#loginLoad');

                result = new Function("return " + msg)();

                if (result.AUTH == 'false') {                    

                    $("#boxMESSAGE").text(result.MESSAGE);

                    showBoxMSG()

                } else {

                    $("#boxLogin").animate({opacity:0}, 500,function(){

                        $("#boxLogin").html(result.MESSAGE);

                        $("#boxLogin").animate({opacity:1}, 500);

                        if (page) {

                            window.loadValues() 

                        }

                    });

                }

            },

            error: function(request, errorType, errorThrown){

                removeElement('#loginLoad');

                $("#boxMESSAGE").text("Error, please try again");

                $("#loginSubmitBtn").attr('href','javascript:login();');

                showBoxMSG();                

            }

        });

    }

    

    function createNewGroup() {

        if (checkLogin()) {

            window.location = "/createGroup.php"

        }

    }

    

    function checkLogin(){

        if (!getCookie('AUTHLogin')) {                    

            $("#boxMESSAGE").text("Por favor, primeiro clique em 'Conectar com o Twitter.' ");

            showBoxMSG();

            return false;

        }else{

            return true;

        }

    }



   $(window).scroll(function(){

		$("#boxMESSAGE").css('top',$(window).scrollTop()+'px')

   })



    function showBoxMSG(){

        $("#boxMESSAGE").css('top',$(window).scrollTop()+'px')

        $("#boxMESSAGE").slideDown(function(){

            setTimeout(function(){

                $("#boxMESSAGE").slideUp(function(){

                    $("#boxMESSAGE").text("");

                });

            },3000)

        });

    }    

    

    $(document).ready(function(){

		

		

		$("#qStr").focus(function(){

            if ($("#qStr").val() == "Find a Nest..."){

                   $("#qStr").val("")

            }

		});

		

		$("#qStr").blur(function(){

            if ($("#qStr").val() == ""){

                   $("#qStr").val("Find a Nest...")

            }

		});



		

       

        $("#txtuser").blur(function(){

            if ($("#txtuser").val() == ""){

                $("#txtuser").val("Twitter Login")

            }

        });

        $("#txtpwd").focus(function(){

            if ($("#txtpwd").val() == "123456789"){

                   $("#txtpwd").val("")

            }

        });

        $("#txtpwd").blur(function(){

            if ($("#txtpwd").val() == ""){

                $("#txtpwd").val("123456789")

            }

        });

        $("#txtuser").focus(function(){

            if ($("#txtuser").val() == "Twitter Login"){

                   $("#txtuser").val("")

            }

        });

        user = $("#txtuser").val();

        

        $("#footerContact").hover(function(){

            $(this).find("#footerBoxContact").slideDown();

        },function(){

            $(this).find("#footerBoxContact").slideUp();

        });

        

        $("#boxInfoLogin").hover(function(){

            $("#boxInfoLoginText").fadeIn();

        },function(){

            $("#boxInfoLoginText").fadeOut();

        })

		

		

		$("#img_powered").hover(function(){

			$(this).attr('src','/image/powered_twitter_over.png');

		},function(){

			$(this).attr('src','/image/powered_twitter.png');

		});

		

        

    });

    

    

    function createLoading(idName, top, left){

        var imgLoad = $('<img />').attr('src', 'http://twinester.mtv.uol.com.br/image/load-arrow.gif');

        imgLoad.attr('id', idName);

        imgLoad.css('position','absolute');

        imgLoad.css('top',top);

        imgLoad.css('left',left);

        $('body').append(imgLoad);

    }



    function getCookie(c_name){

        if (document.cookie.length>0){

            c_start=document.cookie.indexOf(c_name + "=");

            if (c_start!=-1){

                c_start=c_start + c_name.length+1;

                c_end=document.cookie.indexOf(";",c_start);

                if (c_end==-1) c_end=document.cookie.length;

                return unescape(document.cookie.substring(c_start,c_end));

            }

        }

        return "";

    }

    

	



    

    function removeElement(idName){

        $(idName).animate({opacity:0}, 250, function(){

            $(this).remove();

        });

    }

    

    function requestGroupRemove(nest,nestID){

        if (checkLogin()) {

            $.ajax({

                url: "/removeRequest.php",

                data: "nest="+nest,

                type: "POST",

                success: function(msg){

                    $("#"+nestID+" .btnSentRequest").fadeOut($("#"+nestID).find("#btnGroup-fncJoin").fadeIn());

                }

            })

        }

    }



    function joinGroup(nest){

        if (checkLogin()) {

            $.ajax({

                url: "/joinGroup.php",

                data: "nest="+nest,

                type: "POST",

                success: function(msg){

                    result = new Function("return " + msg)();

                    if (result.AUTH == 'true') {                        

                        var addUser = $("<div></div>").attr('class', 'infoBlockPerson');

                        $(addUser).html(result.HTML);

                        $(addUser).css("opacity",0);

                        $(addUser).attr("id",result.USERID);

                        $(addUser).insertAfter('#owner');

                        $(addUser).animate({opacity:1},1000);

                        $("#btnGroup-fncJoin").fadeOut($("#btnGroup-fncLeft").fadeIn());

                        

                        $("#"+result.NEST+" #count-members").html(result.COUNT+" members")

                    }else{

						if (result.REQUEST == "true") {

							$("#"+nest).find("#btnGroup-fncJoin").fadeOut($("#"+nest+" a[class='btnSentRequest']").fadeIn());

						}

                        $("#boxMESSAGE").text(result.MESSAGE);

                        showBoxMSG();

                    }

                }

            });

        }

    }



    function leftGroup(nest, _myDel){

        if (checkLogin()) {

            $.ajax({

                url: "/leftGroup.php",

                data: "nest="+nest,

                type: "POST",

                success: function(msg){

                    result = new Function("return " + msg)();

                    if (result.AUTH == 'true') {                        

                        $("#boxMESSAGE").text("ok... you left his nest");

                        if (_myDel == true) {

                            $("#"+nest).animate({opacity:0.01},1000,function(){

                                $("#"+nest).remove();

                            });

                        }else{

                            if (session == "M02") {

                                $("#"+result.NEST+" #count-members").html(result.COUNT+" members");

                                $("#btnGroup-fncLeft").fadeOut($("#btnGroup-fncJoin").fadeIn())

                                        groupMembers(nest,1,true);

                            }else{

                                if ($("#"+result.USERID).length > 0){

                                    $("#btnGroup-fncLeft").fadeOut($("#btnGroup-fncJoin").fadeIn());

                                    $("#"+result.USERID).fadeOut();

                                    $("#"+result.NEST+" #count-members").html(result.COUNT+" members");                                        

                                }else{

                                    alert("02");

                                    $("#"+result.NEST+" #count-members").html(result.COUNT+" members");

                                    $("#btnGroup-fncLeft").fadeOut($("#btnGroup-fncJoin").fadeIn());

                                    groupMembers(nest,1,true);

                                }

                            }

                        }

                    }else{

                        $("#boxMESSAGE").text(result.MESSAGE);

                        showBoxMSG();

                    }

                }

            });

        } 

    }

    

    

    function findPos(elemen){

        var obj = document.getElementById(elemen);

        var posX = obj.offsetLeft;var posY = obj.offsetTop;

        while(obj.parentNode){

            posX=posX+obj.parentNode.offsetLeft;

            posY=posY+obj.parentNode.offsetTop;

                if(obj==document.getElementsByTagName('body')[0]){

                break

            }else{

                obj=obj.parentNode;

            }

        }

        return new Function("return {'left':'"+ posX +"','top':'"+ posY +"'}")();

    }

    

    

    

function URLEncode(STREncore) {

	var SAFECHARS = "0123456789" +	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()";

	var HEX = "0123456789ABCDEF";

	var plaintext = STREncore;

	var encoded = "";

	for (var i = 0; i < plaintext.length; i++ ) {

		var ch = plaintext.charAt(i);

	    if (ch == " ") {

		    encoded += "+";				// x-www-urlencoded, rather than %20

		} else if (SAFECHARS.indexOf(ch) != -1) {

		    encoded += ch;

		} else {

		    var charCode = ch.charCodeAt(0);

			if (charCode > 255) {

			    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +"(URL encoding only supports 8-bit characters.)\n" +"A space (+) will be substituted." );

				encoded += "+";

			} else {

				encoded += "%";

				encoded += HEX.charAt((charCode >> 4) & 0xF);

				encoded += HEX.charAt(charCode & 0xF);

			}

		}

	}

	return encoded;

};

    

    

    		function leftGroupIndex(nest,idNest){

		    if (checkLogin()) {

		        $.ajax({

		            url: "/leftGroup.php",

		            data: "nest="+nest,

		            type: "POST",

		            success: function(msg){

		                result = new Function("return " + msg)();

		                if (result.AUTH == 'true') {

							if (result.PRIVATE == 'false') {

								var classGroupLeft = 'btnLeftGroup';

								var classGroupJoin = 'btnJoinGroup';

							}else{

								var classGroupLeft = 'btnLeftPGroup';

								var classGroupJoin = 'btnJoinPGroup';

							}

                            if (!idNest){

                                idNest  = nest;

                            }

							$("#"+idNest+" div.members").html(result.COUNT + ' members');

	                        $("#"+idNest+" a[class='" + classGroupLeft + "']").fadeOut($("#"+idNest+" a[class='" + classGroupJoin + "']").fadeIn());

	                    }else{

							$("#boxMESSAGE").text(result.MESSAGE);

							showBoxMSG();

						}

					}

				}); 

			}

		}

		

    

    



    /*function JoinGroupIndex(nest, idNest){

        if (checkLogin()) {

            $.ajax({

                url: "http://www.obadio.com/twitter/joinGroup.php",

                data: "nest="+nest,

                type: "POST",

                success: function(msg){

					//alert(msg);

					if (!idNest) {

                        idNest = nest;

                    }

                    result = new Function("return " + msg)();

					if (result.AUTH == 'true'){

						if (idNest) {

							if (result.PRIVATE == 'false') {

								var i=0;

								//alert(result.LIST[i][1])

								var intervalo = window.setInterval(function(){

									var getID  = $("#receiver_nests #G" + result.LIST[i][0]);

									var getPOS = result.LIST[i][1];

									//alert($($("#receiver_nests .infoBlock").get(getPOS)).index());

									var prev   = $(getID.prev());

									var next   = $(getID.next());					

									var length =  $("#receiver_nests .infoBlock").size();

									///alert(length);

									var objDiv =  $($("#receiver_nests .infoBlock").get(getPOS));

									if ((getPOS >= 0) && (getPOS < (length-1))){

										if (objDiv.attr("id") == next.attr("id")) {

											getID.clone(true).css("display","none").insertAfter(objDiv).fadeIn();

										}else{

											getID.clone(true).css("display","none").insertBefore(objDiv).fadeIn();

										}

										getID.fadeOut().remove();

									}else if (getPOS == (length-1)){

										getID.clone(true).css("display","none").insertAfter(objDiv).fadeIn();

										getID.fadeOut().remove();						

									}

										i++;

									if (i > 4){

										clearInterval(intervalo);	

									}

								},500);

								var classGroupLeft = 'btnLeftGroup';

								var classGroupJoin = 'btnJoinGroup';

							}else{

								var classGroupLeft = 'btnLeftPGroup';

								var classGroupJoin = 'btnJoinPGroup';

							}

						}else{

                            if (result.PRIVATE == 'false') {

                                var classGroupLeft = 'btnLeftGroup';

								var classGroupJoin = 'btnJoinGroup';

                            }else{

								var classGroupLeft = 'btnLeftPGroup';

								var classGroupJoin = 'btnJoinPGroup';

                            }

                            idNest = nest;

                        }

						$("#"+idNest+" div.members").html(result.COUNT + ' members');

						$("#"+idNest+" a[class='" + classGroupJoin + "']").fadeOut($("#"+idNest+" a[class='" + classGroupLeft + "']").fadeIn());

                    }else{

						if (result.REQUEST == "true") {

							$("#"+idNest).find("#btnGroup-fncJoin").fadeOut($("#"+idNest+" a[class='btnSentRequest']").fadeIn());

						}

                        $("#boxMESSAGE").text(result.MESSAGE);

                        showBoxMSG();

                    }

                }

            });

        } 

    }*/

    

    

    function JoinGroupIndex(nest, idNest){

        if (checkLogin()) {

            $.ajax({

                url: "/joinGroup.php",

                data: "nest="+nest,

                type: "POST",

                success: function(msg){

					//alert(msg);

					if (!idNest) {

                        idNest = nest;

                    }

                    result = new Function("return " + msg)();

					if (result.AUTH == 'true'){

						if (idNest) {

							if (result.PRIVATE == 'false') {

								var i=0;

								//alert(result.LIST[i][1])

								var classGroupLeft = 'btnLeftGroup';

								var classGroupJoin = 'btnJoinGroup';

							}else{

								var classGroupLeft = 'btnLeftPGroup';

								var classGroupJoin = 'btnJoinPGroup';

							}

						}else{

                            if (result.PRIVATE == 'false') {

                                var classGroupLeft = 'btnLeftGroup';

								var classGroupJoin = 'btnJoinGroup';

                            }else{

								var classGroupLeft = 'btnLeftPGroup';

								var classGroupJoin = 'btnJoinPGroup';

                            }

                            idNest = nest;

                        }

						$("#"+idNest+" div.members").html(result.COUNT + ' members');

						$("#"+idNest+" a[class='" + classGroupJoin + "']").fadeOut($("#"+idNest+" a[class='" + classGroupLeft + "']").fadeIn());

                    }else{

						if (result.REQUEST == "true") {

							$("#"+idNest).find("#btnGroup-fncJoin").fadeOut($("#"+idNest+" a[class='btnSentRequest']").fadeIn());

						}

                        $("#boxMESSAGE").text(result.MESSAGE);

                        showBoxMSG();

                    }

                }

            });

        } 

    }

    

    