            var contextMenuClick = function(action, el, pos) {
            	/*
                alert(
			        'Action: ' + action + '\n\n' +
			        'Element ID: ' + $(el).attr('id') + '\n\n' +
			        'UserId: ' + $(el).attr('userid') + '\n\n' +
			        'MessageId: ' + $(el).attr('messageid') + '\n\n'
			        );*/
                
                var ie = action.indexOf("#", action);
                if (ie > 0){//Mean that IE and to action added link!
                	action = action.substr(ie+1);
                }
                
                if(action == "1" || action == "2" || action == "3"){
                  document.location.replace(root_domain+"/manage_msg/?id="+$(el).attr('messageid')+"&reply="+action);
                  return;
                }
                
                
                if(action == "provideTestimonial"){
                	if($(el).attr('username') != null){
                		document.location.replace(root_domain+"/compose_testimonial/"+$(el).attr('username'));
                  	}else{
                  		document.location.replace(root_domain+"/compose_testimonial/"+$(el).attr('userid'));
                  	}
                    return;
                  }
                
                if(action == "directZazam"){
                	if($(el).attr('username') != null){
                		document.location.replace(root_domain+"/direct_zazam_offer/"+$(el).attr('username'));
                  	}else{
                  		document.location.replace(root_domain+"/direct_zazam_offer/"+$(el).attr('userid'));
                  	}
                    return;
                  }
                
                if(action == "zazamIt"){
                    document.location.replace(root_domain+"/zazam_item/?id="+$(el).attr('messageid'));
                    return;
                  }
                
                if(action == "reportSpam"){
                	if ($(el).attr('thetab') != null)
                      document.location.replace(root_domain+"/rspam/"+$(el).attr('messageid')+"/"+$(el).attr('thetab'));
                	 else
                	  document.location.replace(root_domain+"/rspam/"+$(el).attr('messageid')+"/");	
                    return;
                  }
                if(action == "notSpam"){
                    document.location.replace(root_domain+"/rspam/"+$(el).attr('messageid')+'/back'+"/"+$(el).attr('thetab'));
                    return;
                  }
                
                if(action == "zazammed"){
                	if($(el).attr('username') != null){
                		document.location.replace(root_domain+"/profile/"+$(el).attr('username')+"/?z_id="+$(el).attr('messageid')+"&done=1");
                  	}else{
                  		document.location.replace(root_domain+"/profile/"+$(el).attr('userid')+"/?z_id="+$(el).attr('messageid')+"&done=1");
                  	}
                    return;
                  }
                	
                if(action == "assignGroup"){
                    //alert("Group! Cool! The zazam is " + $(el).attr('messageid'));
                    document.location.replace(root_domain+"/agroup/"+$(el).attr('messageid'));
                    return;
                  }
                if(action == "reply"){
                    document.location.replace(root_domain+"/responsereply/?id="+$(el).attr('messageid'));
                    return;
                  }
                
                if(action == "delete"){
                    document.location.replace(root_domain+"/manage_msg/?id="+$(el).attr('messageid')+"&delete=2");
                    return;
                  }
                
                if(action == "setFavorites"){
                    document.location.replace(root_domain+"/manage_zazam/?id="+$(el).attr('messageid')+"&favorite="+$(el).attr('userid'));
                    return;
                  }
                
                if(action == "edit"){
                    document.location.replace(root_domain+"/profile/"+$(el).attr('userid')+"/?z_id="+$(el).attr('messageid'));
                    return;
                  }
                
                if(action == "remove"){
                    document.location.replace(root_domain+"/delete/?id="+$(el).attr('messageid'));
                    return;
                  }
                
                if(action == "repost"){
                    document.location.replace(root_domain+"/repost/?id="+$(el).attr('messageid'));
                    return;
                  }
                
                if(action == "blockUser"){
                	if($(el).attr('username') != null){
                	  //alert(root_domain+"/profile/"+$(el).attr('username')+"/block");
                      document.location.replace(root_domain+"/profile/"+$(el).attr('username')+"/block");
                	}else{
                	  //alert(root_domain+"/profile/"+$(el).attr('userid')+"/block");
                	  document.location.replace(root_domain+"/profile/"+$(el).attr('userid')+"/block");
                	}
                    return;
                  }
                if(action == "unblockUser"){
                	if($(el).attr('username') != null)
                      document.location.replace(root_domain+"/profile/"+$(el).attr('username')+"/unblock");
                	 else
                  	  document.location.replace(root_domain+"/profile/"+$(el).attr('userid')+"/unblock");
                    return;
                  }
                
                if(action == "askQuestion"){
                	if($(el).attr('username') != null)
                      document.location.replace(root_domain+"/direct_message/"+$(el).attr('username'));
                	 else
                	  document.location.replace(root_domain+"/direct_message/"+$(el).attr('userid'));
                    return;
                  }
                
                if(action == "followUser"){
                	if ($(el).attr('username') != '')
                     document.location.replace(root_domain+"/profile/"+$(el).attr('username')+"/follow");
                	else
                	 document.location.replace(root_domain+"/profile/"+$(el).attr('userid')+"/follow");
                    return;
                  }
                
                if(action == "addFriend"){
                	if ($(el).attr('username') != '')
                     document.location.replace(root_domain+"/profile/"+$(el).attr('username')+"/addfriend");
                	else
                	 document.location.replace(root_domain+"/profile/"+$(el).attr('userid')+"/addfriend");
                    return;
                  }
                
                if(action == "unfollowUser"){
                	if ($(el).attr('username') != '')
                      document.location.replace(root_domain+"/profile/"+$(el).attr('username')+"/leave");
                	else
                	  document.location.replace(root_domain+"/profile/"+$(el).attr('userid')+"/leave");
                    return;
                  }
                
                if(action == "deFriend"){
                	if ($(el).attr('username') != '')
                     document.location.replace(root_domain+"/profile/"+$(el).attr('username')+"/remove");
                	else
                	 document.location.replace(root_domain+"/profile/"+$(el).attr('userid')+"/remove");
                    return;
                  }
                
                if(action == "forward"){
                	 document.location.replace(root_domain+"/forwardmsg/"+$(el).attr('messageid'));
                    return;
                  }

                
            };

            
            $(document).ready(function() {
                $("a[rel=contextMenu]").each(function() {
                    $(this).contextMenu({ menu: ($(this).attr('id') + "Menu") }, contextMenuClick);
                });
            });

   function load_group_members(group_id){}
    
$(document).ready(function(){
    $("#note").keyup(function(){
        $("#additional_note").empty().append($(this).val());
    });
    
    $("#choose_photo").hide();
    $("#upload").addClass("current");

    $("#upload").click(function(){
        $("#choose_photo").hide();
        $("#upload_photo").fadeIn("slow");
        $(this).addClass("current");
        $("#photo_set").removeClass("current");
        return false;
    });

    $("#photo_set").click(function(){
        $("#upload_photo").hide();
        $("#choose_photo").fadeIn("slow");
        $(this).addClass("current");
        $("#upload").removeClass("current");
        return false;
    });

    $("img.avatar.choose").click(function(){
        $("img.avatar.choose").removeClass("chosen");
        $(this).addClass("chosen");
        $("#chosen_photo").val($(this).attr("alt"));
        return false;
    });

    $("#old_zazam").keyup(function(){
        var chars;
        if(typeof message_max_length == "undefined") message_max_length = 71;
        chars = message_max_length - $(this).val().length;
        if (chars == 1 || chars < 1) {
        	$(this).val($(this).val().substr(0, message_max_length-1));
        	$("#old_left").html(0);
        } else {
        	$("#old_left").html((chars-1));
        }
    });
    
    $("#new_zazam").keyup(function(){
        var chars;
        if(typeof message_max_length == "undefined") message_max_length = 71;
        chars = message_max_length - $(this).val().length;
        if (chars == 1 || chars < 1) {
        	$(this).val($(this).val().substr(0, message_max_length-1));
        	$("#new_left").html(0);
        } else {
        	$("#new_left").html((chars-1));
        }
    });
    
    $("#new_testimonial").keyup(function(){
        var chars;
        if(typeof message_max_length == "undefined") message_max_length = 141;
        chars = message_max_length - $(this).val().length;
        if (chars == 1 || chars < 1) {
        	$(this).val($(this).val().substr(0, message_max_length-1));
        	$("#new_testimonial_left").html(0);
        } else {
        	$("#new_testimonial_left").html((chars-1));
        }
    });
    
    
    $("#bio, #interests").keyup(function(){
        var chars;
        chars = 200 - $(this).val().length;
        if(chars == 0 || chars < 0) $(this).val($(this).val().substr(0, 199));
    });
    $("#country").change(function(){
      // alert($("#location").options);
    }); 

    

//latest message tooltip
    var winH = $("body").height();
    if(winH < window.innerHeight) winH = window.innerHeight;
    var winW = window.innerWidth;
    var tooltip_w, tooltip_h;
    function eventMouseX(e, w) {
        if (e.pageX) xval = e.pageX;
        //if(xval + w > winW) xval = winW - w - 30;
        return xval;
    }
    function eventMouseY(e, h) {
        if (e.pageY) yval = e.pageY;
        //if(yval + h > winH) yval = winH - h - 30;
        return yval;
    }
    $("body").mousemove(function(e){
        var mouse_x = eventMouseX(e, 200)-100;
        var mouse_y = eventMouseY(e, tooltip_h)+10;
        $("#last_msg_tooltip").css({
            left: mouse_x + 'px',
            top: mouse_y + 'px'
        });
        tooltip_h = $("#last_msg_tooltip").height;
    });
    $(".show_msg_tooltip").hover(function(){
    	if(($(this).attr("src")).indexOf("_group") > -1){//group
          var sorce_name = "group";     		
    	}else{
    	  var sorce_name = "user";
    	}
        var markup = $.ajax({
            type: "GET",
            url: "ajax/user_last_message.php",
            data: sorce_name+"=" + escape($(this).attr("alt")),
            async: false
        }).responseText;
        $("body").append("<div id='last_msg_tooltip'><strong>" + $(this).attr("alt") + "</strong>: " + markup + "</div>");
    }, function(){
        $("#last_msg_tooltip").remove();
    });
    $(".show_msg_tooltip").mouseout(function(){
        $("#last_msg_tooltip").remove();
    });

    function recent_popular_enable(){
    }

//favorites ajax stuff

    function enable_add(){}

    function enable_del(){}

//scripts to copy and paste
    $("#paste_code").click(function(){
        this.select();
    });
    $("#js_my_status").click(function(){
        this.select();
    });
    $("#js_my_friends").click(function(){
        this.select();
    });

//notification mode setting
    $("#notify_mode1").click(function(){
        set_notify_mode($(this).val());
    });
    $("#notify_mode2").click(function(){
        set_notify_mode($(this).val());
    });
    $("#notify_mode3").click(function(){
        set_notify_mode($(this).val());
    });
    $("#notify_mode4").click(function(){
        set_notify_mode($(this).val());
    });

//message notification
    $("#notify_direct1").click(function(){
        set_msg_notification($(this).val());
    });
    $("#notify_direct2").click(function(){
        set_msg_notification($(this).val());
    });

//autoselect of api key
    $("#api_key").click(function(){
        this.select();
    });

//autofill of the mail address in the invite page
    $("#check_user").val("@hotmail.com");
    $("#check_type").change(function(){
        $("#check_user").val("@"+ $(this).val() +".com");
    });

//password for account deletion
    $("#del_pass_form").hide();
    $("#del_pass").click(function(){
        $(this).hide();
        $("#del_pass_form").show();
    });


// ==========================
// tabs in user's profile
// ==========================

// opening the right tab
    switch($("#current_tab").val()){
        case "group_messages":
            $("#profile_my_msg").addClass("current");
            $("#profile_my_msg").siblings("a").removeClass("current");
            $("#tab_content").html("<p>Loading...</p>");
            var stuff = $.ajax({
                    type: "GET",
                url: "ajax/messages_group.php",
                data: 'group_id=' + $("#current_group").val(),
                async: false
            }).responseText;
            $("#tab_content").html(stuff).fadeIn("slow");
            //enable_mine();
            //enable_add();
            //enable_del();
            break;
        case "mine":
            $("#profile_my_msg").addClass("current");
            $("#profile_my_msg").siblings("a").removeClass("current");
            $("#tab_content").html("<p>Loading...</p>");
/*            var stuff = $.ajax({
                type: "GET",
                url: "ajax/messages_mine.php",
                data: "stuff=" + $("#profile_my_msg").attr("rel"),
                async: false
            }).responseText;*/
            var rr = $.ajax({
                type: "GET",
                url: "ajax/messages_mine.php",
                data: "stuff=" + $("#profile_my_msg").attr("rel"),
                async: true,
                success: function(stuff){
	                $("#tab_content").html(stuff).fadeIn("slow");
	                enable_mine();
	                enable_add();
	                enable_del();
	                //alert("I'll do this!");
	                $("a[rel=contextMenu]").each(function() {
	                    $(this).contextMenu({ menu: ($(this).attr('id') + "Menu") }, contextMenuClick);
	                });
            	},
            	error: function(err){
	                $("#tab_content").html("This website is temporarily unavailable. Please check back later.").fadeIn("slow");
            	}
            });
            
/*            $("#tab_content").html(stuff).fadeIn("slow");
            enable_mine();
            enable_add();
            enable_del();
            //alert("I'll do this!");
            $("a[rel=contextMenu]").each(function() {
                $(this).contextMenu({ menu: ($(this).attr('id') + "Menu") }, contextMenuClick);
            });
*/            
            
            break;
        case "with_friends":
            $("#profile_friends").addClass("current");
            $("#profile_friends").siblings("a").removeClass("current");
            $("#tab_content").html("<p>Loading...</p>");
            var stuff = $.ajax({
                type: "GET",
                url: "ajax/messages_with_friends.php",
                data: "stuff=" + $("#profile_friends").attr("rel"),
                async: false
            }).responseText;
            $("#tab_content").html(stuff).fadeIn("slow");
            enable_add();
            enable_del();
            enable_friends();
            break;
        case "replys":
            $("#profile_replys").addClass("current");
            $("#profile_replys").siblings("a").removeClass("current");
            $("#tab_content").html("<p>Loading...</p>");
            var stuff = $.ajax({
                type: "GET",
                url: "ajax/messages_replys.php",
                data: "stuff=" + $("#profile_replys").attr("rel"),
                async: false
            }).responseText;
            $("#tab_content").html(stuff).fadeIn("slow");
            enable_add();
            enable_del();
            enable_replys();
            break;
        case "customize":
            $("#profile_customize").addClass("current");
            $("#profile_customize").siblings("a").removeClass("current");
            var stuff = $.ajax({
                type: "GET",
                url: "ajax/profile_customize.php",
                data: "user=" + $("#current_user").val(),
                async: false
            }).responseText;
            $("#tab_content").html(stuff).fadeIn("slow");
            enable_customize();
            break;
        default:
            $("#profile_my_msg").addClass("current");
            $("#profile_my_msg").siblings("a").removeClass("current");
            $("#tab_content").html("<p>Loading...</p>");
            var stuff = $.ajax({
                type: "GET",
                url: "ajax/messages_mine.php",//dddddddddddddddd
                data: "stuff=" + $("#profile_my_msg").attr("rel"),
                async: false
            }).responseText;
            $("#tab_content").html(stuff).fadeIn("slow");
            enable_mine();
            enable_add();
            enable_del();
            //alert("I'll do this!");
            $("a[rel=contextMenu]").each(function() {
                $(this).contextMenu({ menu: ($(this).attr('id') + "Menu") }, contextMenuClick);
            });
            break;
    }
// when user clicks on a tab...
    $("#profile_my_msg").click(function(){
        $(this).addClass("current");
        $(this).siblings("a").removeClass("current");
        $("#tab_content").html("<p>Loading...</p>");
        var stuff = $.ajax({
            type: "GET",
            url: "ajax/messages_mine.php",
            data: "stuff=" + $(this).attr("rel"),
            async: false
        }).responseText;
        $("#tab_content").html(stuff).fadeIn("slow");
        enable_mine();
        //alert("I'll do this!");
        $("a[rel=contextMenu]").each(function() {
            $(this).contextMenu({ menu: ($(this).attr('id') + "Menu") }, contextMenuClick);
        });
        return false;
    });

    $("#profile_friends").click(function(){
        $(this).addClass("current");
        $(this).siblings("a").removeClass("current");
        $("#tab_content").html("<p>Loading...</p>");
        var stuff = $.ajax({
            type: "GET",
            url: "ajax/messages_with_friends.php",
            data: "stuff=" + $(this).attr("rel"),
            async: false
        }).responseText;
        $("#tab_content").html(stuff).fadeIn("slow");
        enable_add();
        enable_del();
        enable_friends();
        return false;
    });
    $("#profile_replys").click(function(){
        $(this).addClass("current");
        $(this).siblings("a").removeClass("current");
        $("#tab_content").html("<p>Loading...</p>");
        var stuff = $.ajax({
            type: "GET",
            url: "ajax/messages_replys.php",
            data: "stuff=" + $(this).attr("rel"),
            async: false
        }).responseText;
        $("#tab_content").html(stuff).fadeIn("slow");
        enable_add();
        enable_del();
        enable_replys();
        return false;
    });
    $("#profile_customize").click(function(){
        $(this).addClass("current");
        $(this).siblings("a").removeClass("current");
        var stuff = $.ajax({
            type: "GET",
            url: "ajax/profile_customize.php",
            data: "user=" + $(this).attr("rel"),
            async: false
        }).responseText;
        $("#tab_content").html(stuff).fadeIn("slow");
        enable_customize();
        return false;
    });

// pagination enable
    function enable_mine(){
        $("a.pagination.mine").click(function(){
            $("#tab_content").empty().html("<p>Loading...</p>");
            var stuff = $.ajax({
                type: "GET",
                url: "ajax/messages_mine.php",
                data: "stuff=" + $(this).attr("rel"),
                async: false
            }).responseText;
            $("#tab_content").hide().empty().html(stuff).fadeIn("slow");
            enable_mine();
            //alert("I'll do this!");
            $("a[rel=contextMenu]").each(function() {
                $(this).contextMenu({ menu: ($(this).attr('id') + "Menu") }, contextMenuClick);
            });
            return false;
        });
    }

    function enable_friends(){
        $("a.pagination.friends").click(function(){
            $("#tab_content").empty().html("<p>Loading...</p>");
            var stuff = $.ajax({
                type: "GET",
                url: "ajax/messages_with_friends.php",
                data: "stuff=" + $(this).attr("rel"),
                async: false
            }).responseText;
            $("#tab_content").html(stuff).fadeIn("slow");
            enable_add();
            enable_del();
            enable_friends();
            return false;
        });
    }

    function enable_replys(){
        $("a.pagination.replys").click(function(){
            $("#tab_content").empty().html("<p>Loading...</p>");
            var stuff = $.ajax({
                type: "GET",
                url: "ajax/messages_replys.php",
                data: "stuff=" + $(this).attr("rel"),
                async: false
            }).responseText;
            $("#tab_content").hide().empty().html(stuff).fadeIn("slow");
            enable_add();
            enable_del();
            enable_replys();
            return false;
        });
    }

    //color picker stuff

    function add_picker(current_element){
        var move_picker = true;
        current_element.parent().prepend("<div id='colorpicker'><div id='wheel'></div><a id='cmClose' href='#'>Apply color</a></div>");
        $("#wheel").farbtastic(current_element);
        $("#colorpicker").show();
        current_element.parent().click(function(e){
            var mouse_x = eventMouseX(e, 200)-100;
            var mouse_y = eventMouseY(e, $("#colorpicker").height())+10;
            if(move_picker == true){
                $("#colorpicker").css({
                    left: mouse_x + 'px',
                    top: mouse_y + 'px'
                });
                move_picker = false;
            }
        });
        $("#cmClose").click(function(){
            if(current_element.val().substr(0, 1) == "#") current_element.val(current_element.val().substr(1));
            current_element.css("background", "#"+current_element.val());
            switch(current_element.attr("id")){
                case "back_color":
                    $("html").css("background-color", "#" + current_element.val());
                    break;
                case "side_fill_color":
                    $(".side_stuff").css("background", "#" + current_element.val());
                    break;
                case "side_border_color":
                    $(".decorative_bar").css("background", "#"+current_element.val());
                    break;
                case "text_color":
                    $("*, h1, h2, h3, h4, #footer, #copyright").not("a").css("color", "#"+current_element.val());
                    break;
                case "link_color":
                    $("a, a:visited, #footer a, #footer a:visited, .side_middle a, .side_middle a:visited, .username, .username:visited").css("color", "#"+current_element.val());
                    $("input.submit").css("background-color", "#"+current_element.val());
                    break;
                case "top_area_color":
                    $("#profile_header").css("background", "#" + current_element.val());
                    break;
            }
            $(this).parent().remove();
            return false;
        });
        return false;
    }

    var current_element;
    $("#colorpicker").hide();
    if($("#current_tab").val() != "customize") enable_customize();

    function bglib_enable(){
        $("#backs").hide();
        $(".back_lib").click(function(){
            var x = false;
            if(x==false){
                $("#backs").show("slow");
                x = true;
            } else {
                $("#backs").fadeOut("slow");
                x = false;
            }
            return false;
        });
        $("a.bglib_link").click(function(){
            $("a.bglib_link").not($(this)).children("img").removeClass("bglib_pic_current").addClass("bglib_pic");
            $(this).children("img").removeClass("bglib_pic").addClass("bglib_pic_current");
            $("#background_name").val($(this).attr("rel"));
            $("#use_image").attr("checked", "checked");
            return false;
        });
    }

    function enable_customize(){
        bglib_enable();
        $("#sticker_color").css("background", "#"+$("#sticker_color").val());
        $("#sticker_color").click(function(){add_picker($(this));});

        $("#back_color").css("background", "#"+$("#back_color").val());
        $("#back_color").click(function(){add_picker($(this));});

        $("#text_color").css("background", "#"+$("#text_color").val());
        $("#text_color").click(function(){add_picker($(this));});

        $("#link_color").css("background", "#"+$("#link_color").val());
        $("#link_color").click(function(){add_picker($(this));});

        $("#bubble_fill_color").css("background", "#"+$("#bubble_fill_color").val());
        $("#bubble_fill_color").click(function(){add_picker($(this));});

        $("#bubble_text_color").css("background", "#"+$("#bubble_text_color").val());
        $("#bubble_text_color").click(function(){add_picker($(this));});

        $("#side_border_color").css("background", "#"+$("#side_border_color").val());
        $("#side_border_color").click(function(){add_picker($(this));});

        $("#side_fill_color").css("background", "#"+$("#side_fill_color").val());
        $("#side_fill_color").click(function(){add_picker($(this));});

        $("#top_area_color").css("background", "#"+$("#top_area_color").val());
        $("#top_area_color").click(function(){add_picker($(this));});
    }

//invitations check all and uncheck all
    $("#check_all").click(function(){
        $("table input").attr("checked", "checked");
        return false;
    });
    $("#uncheck_all").click(function(){
        $("table input").removeAttr("checked");
        return false;
    });

//blocking confirmation
    $(".block_user").click(function(){
        return confirm("Are you sure you want to block this user? He will not be able to read your updates or add you as a friend.");
    });
    

    
    /*
    $("#gr_keywords").click(function(){
        if($(this).val() == "Keywords" ){
        	$(this).val("");
        }
        document.getElementsByName("gr_keywords")[0].style.color="black";
        document.getElementsByName("gr_keywords")[0].style.fontStyle="";
        document.getElementsByName("gr_keywords")[0].style.border="1px solid #5C8DB5";
        document.getElementsByName("gr_keywords")[0].style.backgroundColor="rgb(240, 247, 249)";
    });
    
    $("#gr_keywords").blur(function(){
        if($(this).val() == ""){
          $(this).val("Keywords");
          document.getElementsByName("gr_keywords")[0].style.color="gray";
          document.getElementsByName("gr_keywords")[0].style.fontStyle="italic";
        }
    	document.getElementsByName("gr_keywords")[0].style.border="1px solid gray";
    	document.getElementsByName("gr_keywords")[0].style.backgroundColor="white";
    });*/
    
    /*
    $("#a_zip").focus(function(){
        if($(this).val() == "Zip code or City, State" ){
        	$(this).val("");
        }
        /*document.getElementsByName("zip")[0]*//* this.style.color="black";
        /*document.getElementsByName("zip")[0]*//* this.style.fontStyle="";
        /*document.getElementsByName("zip")[0]*//* this.style.border="1px solid #5C8DB5";
        /*document.getElementsByName("zip")[0]*//* this.style.backgroundColor="rgb(240, 247, 249)";
    });*/
    
    /*
    $("#a_zip").blur(function(){
        if($(this).val() == ""){
          $(this).val("Zip code or City, State");
          /*document.getElementsByName("zip")[0]*/ /*this.style.color="gray";
          /*document.getElementsByName("zip")[0]*/ /*this.style.fontStyle="italic";
	    /*document.getElementsByName("zip")[0]*/ /*this.style.border="1px solid gray";
        }
    	/*document.getElementsByName("zip")[0]*/ /*this.style.backgroundColor="white";
    });*/
    /*
    $("#lzip").focus(function(){
        if($(this).val() == "Zip code or City, State" ){
        	$(this).val("");
        }
        /*document.getElementsByName("zip")[0]*//* this.style.color="black";
        /*document.getElementsByName("zip")[0]*//* this.style.fontStyle="";
        //document.getElementsByName("zip")[0].style.border="1px solid #5C8DB5";
        //document.getElementsByName("zip")[0].style.backgroundColor="rgb(240, 247, 249)";
    });*/
    /*
    $("#lzip").blur(function(){
        if($(this).val() == ""){
          $(this).val("Zip code or City, State");
          /*document.getElementsByName("zip")[0]*//* this.style.color="gray";
          /*document.getElementsByName("zip")[0]*//* this.style.fontStyle="italic";
        }
    	//document.getElementsByName("zip")[0].style.border="1px solid gray";
    	//document.getElementsByName("zip")[0].style.backgroundColor="white";
    });*/
    /*
    $("#zip").focus(function(){
        if($(this).val() == "Zip code or City, State" ){
        	$(this).val("");
        }
        /*document.getElementsByName("zip")[0]*//* this.style.color="black";
        /*document.getElementsByName("zip")[0]*//* this.style.fontStyle="";
        //document.getElementsByName("zip")[0].style.border="1px solid #5C8DB5";
        //document.getElementsByName("zip")[0].style.backgroundColor="rgb(240, 247, 249)";
    });*/
    
    /*
    $("#zip").blur(function(){
        if($(this).val() == ""){
          $(this).val("Zip code or City, State");
          /*document.getElementsByName("zip")[0]*/ /*this.style.color="gray";
          /*document.getElementsByName("zip")[0]*/ /*this.style.fontStyle="italic";
        }
    	//document.getElementsByName("zip")[0].style.border="1px solid gray";
    	//document.getElementsByName("zip")[0].style.backgroundColor="white";
    });*/
    
    /*
    $("#gr_zip").focus(function(){
        if($(this).val() == "Zip code or City, State" ){
        	$(this).val("");
        }
        /*document.getElementsByName("zip")[0] this.style.color="black";
        /*document.getElementsByName("zip")[0] this.style.fontStyle="";
        //document.getElementsByName("zip")[0].style.border="1px solid #5C8DB5";
        //document.getElementsByName("zip")[0].style.backgroundColor="rgb(240, 247, 249)";
    });
    
    $("#gr_zip").blur(function(){
        if($(this).val() == ""){
          $(this).val("Zip code or City, State");
          /*document.getElementsByName("zip")[0] this.style.color="gray";
          /*document.getElementsByName("zip")[0] this.style.fontStyle="italic";
        }
    	//document.getElementsByName("zip")[0].style.border="1px solid gray";
    	//document.getElementsByName("zip")[0].style.backgroundColor="white";
    });*/
    
    
    $("#search_words").click(function(){
        if($(this).val() == "What kind of stuff do you want?" || $(this).val() == "Product or service you offer!" || $(this).val() == "Name or zazam alias" || $(this).val() == "Interest or specific group" ){
        	$(this).val("");
        }
        document.getElementsByName("search_words")[0].style.color="black";
        document.getElementsByName("search_words")[0].style.fontStyle="";
        //document.getElementsByName("search_words")[0].style.border="1px solid #5C8DB5";
        //document.getElementsByName("search_words")[0].style.backgroundColor="rgb(240, 247, 249)";
    });
    
    $("#search_words").blur(function(){
        if($(this).val() == ""){
        	
        	if (document.getElementsByName("search_for")[0].value == "1"){
              if (document.getElementsByName("search_type")[0].value == "2"){
              	$(this).val("Product or service you offer!");
               }else{
        	     $(this).val("What kind of stuff do you want?");
              	}
        	 }else{
               if (document.getElementsByName("search_for")[0].value == "2"){
        	    $(this).val("Name or zazam alias"); 
               }else{
            	$(this).val("Interest or specific group");    
               }
           	}
        	
        	document.getElementsByName("search_words")[0].style.color="#CCCCCC";
        	document.getElementsByName("search_words")[0].style.fontStyle="";
        }
    	//document.getElementsByName("search_words")[0].style.border="1px solid gray";
    	//document.getElementsByName("search_words")[0].style.backgroundColor="white";
    });
    /*
    $("#old_zazam").click(function(){
        if($(this).val() == "Product or Service You Are Offering"){
        	$(this).val("");
        }
        document.getElementsByName("old_zazam")[0].style.color="black";
        document.getElementsByName("old_zazam")[0].style.fontStyle="";
        document.getElementsByName("old_zazam")[0].style.border="1px solid #5C8DB5";
        document.getElementsByName("old_zazam")[0].style.backgroundColor="rgb(240, 247, 249)";
    });
    
    $("#old_zazam").blur(function(){
        if($(this).val() == ""){
        	$(this).val("Product or Service You Are Offering");
        	document.getElementsByName("old_zazam")[0].style.color="gray";
        	document.getElementsByName("old_zazam")[0].style.fontStyle="italic";
        }
    	document.getElementsByName("old_zazam")[0].style.border="1px solid gray";
    	document.getElementsByName("old_zazam")[0].style.backgroundColor="white";
    });
    
    $("#new_zazam").click(function(){
        if($(this).val() == "Cash, Products or Services You Want in Exchange"){
        	$(this).val("");
        }
        document.getElementsByName("new_zazam")[0].style.color="black";
        document.getElementsByName("new_zazam")[0].style.fontStyle="";
        document.getElementsByName("new_zazam")[0].style.border="1px solid #5C8DB5";
        document.getElementsByName("new_zazam")[0].style.backgroundColor="rgb(240, 247, 249)";
    });
    
    $("#new_zazam").blur(function(){
        if($(this).val() == ""){
        	$(this).val("Cash, Products or Services You Want in Exchange");
        	document.getElementsByName("new_zazam")[0].style.color="gray";
        	document.getElementsByName("new_zazam")[0].style.fontStyle="italic";
        }

        document.getElementsByName("new_zazam")[0].style.border="1px solid gray";
        document.getElementsByName("new_zazam")[0].style.backgroundColor="white";

    });*/
    

//sms credit paypal form
    if($("#item_name").val() != "") $("#item_name").parent().submit();
});



function check_length(){

	var obj_old = document.getElementsByName('old_zazam')[0];
	var obj_new = document.getElementsByName('new_zazam')[0];
	
   if (document.getElementsByName('subgroupid')[0].value == 0){
	 alert('Please select a group first');
	 return false;
   }
	
   if (document.getElementsByName('whos_direct_zazam')[0] != null){
	   if (document.getElementsByName('whos_direct_zazam')[0].value == 0){
		alert('Please select someone with who do you want to try a Direct Zazam first');
		return false;
	   }
    }

   
   if (obj_old.value.length > 70){
    alert('Item to offer contains more then 70 symbols');
    return false;
   }
   if (obj_new.value.length > 70){
	alert('Item you want contains more then 70 symbols');
    return false;
   }
   
   
   if (obj_old.value.length == 0 || obj_old.value == "Product or Service You Are Offering"){
	 if (obj_new.value.length == 0 || obj_new.value == "Cash, Products or Services You Want in Exchange"){
	  alert('Please complete a zazam entry by telling us what your offering and what you want in return.');
	  return false;
	 }
   }
   
   if (obj_old.value.length == 0 || obj_old.value == "Product or Service You Are Offering"){
	    alert('Please tell us what you are offering');
	    return false;
	   }
	   
   if (obj_new.value.length == 0 || obj_new.value == "Cash, Products or Services You Want in Exchange"){
		alert('Please tell us what you may want');
	    return false;
	   }
   
   

 return true;
}

function show_upload_imagebox(){
 if (document.getElementById('zazam_img_cnt').style.display == "none"){
  document.getElementById('zazam_img_cnt').style.display="block";
 }else{
  document.getElementById('zazam_img_cnt').style.display="none";
  document.getElementsByName('zazam_img')[0].value="";
 }
}

function delete_zazam_img(){
	el = document.getElementById("old_img_cnt");
	el.parentNode.removeChild(el);
}

function change_group_trend(type){
	var padding = new Array(92, 290);
	document.getElementById("pointer_group_header").style.cssText="padding-left:"+padding[type-1]+"px;";
	document.getElementById("gr_strend").value=type;
}

var looking_withowt_radius = 1;
function change_group_for_local(){

	if (document.getElementById("gr_local_link").innerHTML=="standard"){
	 document.getElementById("gr_local_link").innerHTML="local";
	 document.getElementById('lcl_grsearch_cnt').style.display="none";
	 looking_withowt_radius = 1;
	 //document.getElementById("gr_slocal").value=0;
	 document.getElementById('gr_keywords').style.width="420px";
	}else{
	  document.getElementById("gr_local_link").innerHTML="standard";
	  document.getElementById('lcl_grsearch_cnt').style.display="";
	  //document.getElementById("gr_slocal").value=1;
	  document.getElementById('gr_keywords').style.width="170px";
	  looking_withowt_radius = 0;
	 }

}


function change_search_trend(type){
	var padding = new Array(92, 290);
	document.getElementById("pointer_main_header").style.cssText="padding-left:"+padding[type-1]+"px;";

	var inp_obj=document.getElementById("search_words");
	/*
	if (inp_obj.value == 'Product or service you offer!' || inp_obj.value == 'Product or service you want!'){	
        if (type == "2"){
        	inp_obj.value = 'Product or service you offer!';
         }else{
        	inp_obj.value = 'Product or service you want!';
         }
  	 }*/
	
	
    if (type == "2"){
    	if (document.getElementsByName("search_type")[0].value!=3 && document.getElementsByName("search_type")[0].value!=4)
    	 document.getElementsByName("search_type")[0].value=2;
    	document.getElementsByName("search_items")[0].value="wanted";
        if (document.getElementsByName("a_search_items")[0] != null)
       	 document.getElementsByName("a_search_items")[0].value="wanted";
     }else{
    	if (document.getElementsByName("search_type")[0].value!=3 && document.getElementsByName("search_type")[0].value!=4)
    	 document.getElementsByName("search_type")[0].value=1;
    	
    	document.getElementsByName("search_items")[0].value="aviable";
        if (document.getElementsByName("a_search_items")[0] != null)
    	 document.getElementsByName("a_search_items")[0].value="aviable";
     }
}


function change_search_type(type){
	
	if (type == 1){
		 document.getElementById('search_words').style.width="295px";
	   //document.getElementById('search_caption').innerHTML="Search what people are...";
	  if (document.getElementById('4_cnt') != null){
	    document.getElementById('3_cnt').style.cssText="display:none";
	    document.getElementById('4_cnt').style.cssText="display:none";
	    document.getElementById('1_cnt').style.cssText="";
	   }else{
		 document.getElementById('2_cnt').style.cssText=""; 
		 document.getElementById('1_cnt').style.cssText="display:none";
	   }
	  
	  
	  
	  if (document.getElementById("pointer_main_header").style.cssText='padding-left:92px;'){
	   document.getElementsByName("search_type")[0].value=1;
   	   document.getElementsByName("search_items")[0].value="aviable"; 
   	   if (document.getElementsByName("a_search_items")[1] != null)
   	    document.getElementsByName("a_search_items")[1].value="aviable";
	  }else{
	   document.getElementsByName("search_type")[0].value=2;
   	   document.getElementsByName("search_items")[0].value="wanted"; 
   	   if (document.getElementsByName("a_search_items")[1] != null)
	    document.getElementsByName("a_search_items")[1].value="wanted";
	  }
	 }else{
	   document.getElementById('search_words').style.width="410px"; 
	 }
	
	if (type == 4){
		//document.getElementById('search_caption').innerHTML="Advanced search for what people are...";
	    if (document.getElementById('4_cnt') != null){
		 document.getElementById('1_cnt').style.cssText="display:none";
		 document.getElementById('3_cnt').style.cssText="display:none";
		 document.getElementById('4_cnt').style.cssText="";
	    }
		document.getElementById('home_page').style.cssText="display:none";
		document.getElementById('not_adv_search_cnt').style.cssText="display:none";
		document.getElementById('adv_search_cnt').style.cssText="";
		document.getElementById('main_header_menu').style.cssText="height:400px";
		document.getElementsByName("search_type")[0].value=4;
	 return;
	}else{
		if (type==3){
			//document.getElementById('search_caption').innerHTML="Search locally what people are...";
		  if (document.getElementById('4_cnt') != null){
			document.getElementById('1_cnt').style.cssText="display:none";
			document.getElementById('3_cnt').style.cssText="";
			document.getElementById('4_cnt').style.cssText="display:none";
		   }else{
			 document.getElementById('2_cnt').style.cssText="display:none"; 
			 document.getElementById('1_cnt').style.cssText="";
			}
		  
		   document.getElementsByName("search_type")[0].value=3;
		}
		
		if (document.getElementById('home_page') != null){
		 document.getElementById('home_page').style.cssText="";
		 document.getElementById('not_adv_search_cnt').style.cssText="";
		 document.getElementById('adv_search_cnt').style.cssText="display:none";
		 document.getElementById('main_header_menu').style.cssText="height:96px";
		}
	}
	//alert(document.getElementsByName("search_for")[0].value);
	
	if(type == 3 && document.getElementsByName("search_for")[0].value == "2"){
	  //type 3 mean we are looking for group, but 2 that we are in pople part, neen be 3 too.
	   document.getElementsByName("search_for")[0].value = "3";
	}
	
	
	if (type == 3 && document.getElementsByName("search_for")[0].value == "1" && document.getElementById('local_search_radius_cnt') != null){
	 document.getElementById('local_search_radius_cnt').style.cssText="";
	 document.getElementById('local_search_items_cnt').style.cssText="";
	 //document.getElementById('search_words').style.cssText="font-style:italic; color:gray; width:410px";
	 if (document.getElementById('main_header_other_page') != null){
	  document.getElementById('main_header_other_page').style.height="95px"; 
	 }
	}else{
	  if (document.getElementById('local_search_radius_cnt') != null){
	   document.getElementById('local_search_radius_cnt').style.cssText="display:none";  
	   document.getElementById('local_search_items_cnt').style.cssText="display:none";  
	   //document.getElementById('search_words').style.cssText="font-style:italic; color:gray;";
	   if (document.getElementById('main_header_other_page') != null){
		 document.getElementById('main_header_other_page').style.height="75px"; 
	   }
	  }
	}

}

function change_search_for(type){
	if(type == 1 || type == 11  || type == 111){
	 document.getElementById("links_search_zazam").style.cssText="";
	 document.getElementById("links_search_people").style.cssText="display:none";
	 document.getElementById("links_search_group").style.cssText="display:none";
	  
	 document.getElementById("links2_search_zazam").style.cssText="display:none";
	 document.getElementById("links3_search_zazam").style.cssText="display:none";
	 document.getElementById("links2_search_people").style.cssText="";
	 
	 
	  if(type == 11){
		  document.getElementsByName("search_for")[0].value=1;
		 change_search_type(2);
	   }else if(type == 111){
		   document.getElementsByName("search_for")[0].value=1;
		 change_search_type(3);
	   }else{
		 document.getElementsByName("search_for")[0].value=1;
		 change_search_type(1);
	   }
		type=1;
	}else{
		
		//hide for local search sytuation
		  if (document.getElementById('local_search_radius_cnt') != null){
			   document.getElementById('local_search_radius_cnt').style.cssText="display:none";  
			   document.getElementById('local_search_items_cnt').style.cssText="display:none";  
			   //document.getElementById('search_words').style.cssText="font-style:italic; color:gray;";
			   if (document.getElementById('main_header_other_page') != null){
				 document.getElementById('main_header_other_page').style.height="75px"; 
			   }
			  }
		
	  document.getElementById("links_search_people").style.cssText="";
	  document.getElementById("links_search_zazam").style.cssText="display:none";
	  document.getElementById("links2_search_people").style.cssText="display:none";
	  document.getElementById("links2_search_zazam").style.cssText="";
	  if(type == 3){
		  //document.getElementById("pointer_main_header").style.cssText="padding-left:272px;";
		  //document.getElementsByName("search_type")[0].value=3;
		  document.getElementsByName("search_for")[0].value=3;
		  document.getElementById("links2_search_zazam").style.cssText="display:none";
		  document.getElementById("links3_search_zazam").style.cssText="";
		  document.getElementById("links_search_group").style.cssText="";
		  document.getElementById("links_search_people").style.cssText="display:none";
		  document.getElementById("links_search_zazam").style.cssText="display:none";
		  change_search_type(3);
	   }else{
		  // document.getElementById("pointer_main_header").style.cssText="padding-left:92px;";
		   document.getElementById("links3_search_zazam").style.cssText="display:none";
		   document.getElementById("links_search_group").style.cssText="display:none";
		   document.getElementById("links_search_people").style.cssText="";
		   document.getElementById("links_search_zazam").style.cssText="display:none";
	    }
	 // document.getElementById('search_caption').innerHTML="Search...";
	}
	
    if(document.getElementsByName("search_words")[0].value == "Product or service you want!" || document.getElementsByName("search_words")[0].value == "Name or zazam alias" || document.getElementsByName("search_words")[0].value == "Interest or specific group"){
    	if (type == 1){
    	  document.getElementsByName("search_words")[0].value = "Product or service you want!";
    	}else{
          if (type == 2){
     	     document.getElementsByName("search_words")[0].value = "Name or zazam alias";
            }else{
         	 document.getElementsByName("search_words")[0].value = "Interest or specific group";
            }
    	}
    }
    
    if(type != 1){
      document.getElementsByName("search_for")[0].value=type;
     }
} 

var locations_object;

var check_adress_form_link="check_adress_form_link";
var the_form="mainsearchform";
function get_long_lat(zip, form_name){

	the_form = form_name;
	if (document.getElementById(zip).value == '' || document.getElementById(zip).value =='Zip code or City, State'){
	 document.getElementById(the_form).submit();
	 return true;
	}

	if (the_form == 'groupsearchform' && looking_withowt_radius==1){
		//mean we are locking without radius
		document.getElementById(zip).value = '';
		document.getElementById(the_form).submit();
		return true;
	}
	
	var adv_true = false;
	
	if (document.getElementById("a_localize") != null && document.getElementById("a_localize").value == 'wanted'){
		adv_true = true;	
	 }
	
	if (the_form != 'groupsearchform' && (document.getElementsByName("search_type")[0].value == "1" || document.getElementsByName("search_type")[0].value == "2")){
		//mean we are locking without radius
		document.getElementById(the_form).submit();
		return true;
	}
	
	if (the_form != 'groupsearchform' && (document.getElementsByName("search_for")[0].value == "1" && document.getElementsByName("search_type")[0].value != "3" && (document.getElementsByName("search_type")[0].value == "4" && adv_true == true))){
		//mean we are locking without radius
		document.getElementById(the_form).submit();
		return true;
	}
	
	if (the_form != 'groupsearchform' && (document.getElementsByName("search_for")[0].value == "2" || document.getElementsByName("search_for")[0].value == "3")){
		//mean we are locking without radius
		document.getElementById(the_form).submit();
		return true;
	}
	

	geocoder = new GClientGeocoder();
	//"1600 Amphitheatre Pky, Mountain View, CA";
	var send_string = document.getElementById(zip).value;
	if(send_string == ""){
		alert("Please, fill address");
		//return false;
	}

	//return false;
	check_adress_form_link = "get_long_lat_link";
	geocoder.getLocations(send_string, addAddressToMap);
return false;
}

function check_adress(){
	geocoder = new GClientGeocoder();
	//"1600 Amphitheatre Pky, Mountain View, CA";
	var send_string = document.getElementsByName("zipcode")[0].value;
	if(send_string == ""){
		alert("Please, fill address");
		return;
	}
	
	geocoder.getLocations(send_string, addAddressToMap);

}

function addAddressToMap(response){
	
	locations_object=response;
	if (response.Status.code != "200"){
		alert("Address not found...");
		return;
	}
	send_url = 'f=1';
	
	if (response.Placemark[0] == null){
		alert("Error in check zip code!");
		return;
	}
	
	if (response.Placemark[1] == null){//We have only one point, doesn't need display form, just send correct data
		
		if(check_adress_form_link != 'get_long_lat_link'){
		  add_to_form_correct_location(0);
		 }else{
		  add_to_form_correct_long_lat(0);
		 }
		
		return;
	}
	
	var adress, lat, lon, pcode, send_url;
	for(var c=0; response.Placemark[c] != null; c++){
		
	  place = response.Placemark[c];
	  adress=place.address;
	  lat=place.Point.coordinates[0];
	  lon=place.Point.coordinates[1];
	  
	  place = place.AddressDetails.Country.AdministrativeArea;
	  if(place != null && place.SubAdministrativeArea != null && place.SubAdministrativeArea.Locality != null){
	    if (place.SubAdministrativeArea.Locality.PostalCode != null){
		  zipobj=place.SubAdministrativeArea.Locality.PostalCode;
	     }else if (place.SubAdministrativeArea.Locality.DependentLocality != null && place.SubAdministrativeArea.Locality.DependentLocality.PostalCode != null){
	       zipobj=place.SubAdministrativeArea.Locality.DependentLocality.PostalCode;
	      }else{
	    	  zipobj='';
	      }
		  pcode=(zipobj != "" && zipobj.PostalCodeNumber != null)?zipobj.PostalCodeNumber:'';
	   }else{
		 if(place != null && place.SubAdministrativeArea != null && place.SubAdministrativeArea.DependentLocality != null){
			 pcode=place.SubAdministrativeArea.DependentLocality.PostalCode.PostalCodeNumber;
		  }else{
			pcode='';
		   }
		 }

	
	send_url=send_url+'&a'+c+'='+encodeURIComponent(adress)+'&lat'+c+'='+encodeURIComponent(lat)+'&long'+c+'='+encodeURIComponent(lon)+'&pcode'+c+'='+encodeURIComponent(pcode);
   }

	var only_long='';
	if(check_adress_form_link != 'check_adress_form_link'){
	 only_long='&longonly=1';
	}
	var send_string = document.getElementById(check_adress_form_link).href + "?" + send_url + only_long;
    document.getElementById(check_adress_form_link).href = send_string;
    $('#'+check_adress_form_link).click();
}


function add_to_form_correct_long_lat(c){
	  place = locations_object.Placemark[c];
	  document.getElementsByName('correct_lat')[0].value = place.Point.coordinates[1];
	  document.getElementsByName('correct_long')[0].value = place.Point.coordinates[0];
	  
	  if (the_form == 'groupsearchform'){
	    document.getElementsByName('correct_lat')[1].value = place.Point.coordinates[1];
	    document.getElementsByName('correct_long')[1].value = place.Point.coordinates[0];
	    document.getElementById('search_tp_cnt').innerHTML='<input type="hidden" value="3" name="gr_search"><input type="hidden" value="3" name="search_type"><input type="hidden" value="1" name="search_for">';
	   }
	  
	  document.getElementById(the_form).submit();
	}


function add_to_form_correct_location(c){
  place = locations_object.Placemark[c];
  
  /***/
  var AdministrativeAreaName, SubAdministrativeAreaName;
  
  AdministrativeAreaName='';
  SubAdministrativeAreaName='';
  
  if (place != null && place.AddressDetails != null && place.AddressDetails.Country != null && place.AddressDetails.Country.AdministrativeArea != null)
   AdministrativeAreaName=place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
  
  if (place != null && place.AddressDetails != null && place.AddressDetails.Country != null && place.AddressDetails.Country.AdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea != null)
   SubAdministrativeAreaName = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName;
  /***/
  if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality != null){
   if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode != null){
	 zipobj=place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode;
    }else if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.DependentLocality != null && place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.DependentLocality.PostalCode != null){
	  zipobj=place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.DependentLocality.PostalCode;
     }else{
      zipobj='';
     }
   pcode=(zipobj != "" && zipobj.PostalCodeNumber != null)?zipobj.PostalCodeNumber:'';
  }else{
	 if(place != null && place.SubAdministrativeArea != null && place.SubAdministrativeArea.DependentLocality != null){
	   pcode=place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.DependentLocality.PostalCode.PostalCodeNumber;
	  }else{
	    pcode='';
	   }
  }

  
  document.getElementsByName('correct_adress')[0].value = place.address;
  document.getElementsByName('correct_lat')[0].value = place.Point.coordinates[1];
  document.getElementsByName('correct_long')[0].value = place.Point.coordinates[0];
  
  if (document.getElementsByName('correct_lat')[1] != null){
    document.getElementsByName('correct_lat')[1].value = place.Point.coordinates[1];
    document.getElementsByName('correct_long')[1].value = place.Point.coordinates[0];
   }
  
  document.getElementsByName('correct_pcode')[0].value = pcode;
  document.getElementsByName('AdministrativeAreaName')[0].value = AdministrativeAreaName;
  document.getElementsByName('SubAdministrativeAreaName')[0].value = SubAdministrativeAreaName;
  //alert("It's time to submit!");
  document.getElementById("mainform").submit();
}

function send_submit(type, id){
 document.getElementById('submit_cnt_'+id).innerHTML = '<input type="submit" name="'+type+'" id="send_submit_'+id+'">';
 document.getElementById('send_submit_'+id).click();
}

function check_if_not_empty(element, message){
  if(document.getElementsByName(element)[0].value != ''){
    return true;
  }else{
	alert(message);
	return false;
  }
}

function close_facebox(){
	  jQuery(document).trigger("close.facebox");
	}

function redirect_me(where){
  document.location.replace(root_domain+'/'+where);
}

function change_status(id){
 document.getElementById("ch_st_links_cnt_"+id).style.display = "";
 document.getElementById("st_cnt_"+id).style.display = "none";
}



function select_messages(type){
	
  switch (type){
  
   case 1:{//all
    for (c=0; document.getElementById("m_"+c) != null; c++){
	  document.getElementById("m_"+c).checked = true;
     }
    };break;
    
   case 2:{//read
	for (c=0; document.getElementById("m_"+c) != null; c++){
		document.getElementById("m_"+c).checked = (document.getElementById("m_"+c).value == 3)
	  }
	 };break;
	 
   case 3:{//replied
	for (c=0; document.getElementById("m_"+c) != null; c++){
		document.getElementById("m_"+c).checked = (document.getElementById("m_"+c).value == 4)
	  }
	 };break;
	 
   case 4:{//none
		for (c=0; document.getElementById("m_"+c) != null; c++){
		   document.getElementById("m_"+c).checked = false;
		  }
		 };break;
  }
 }

function select_all_display_settings(){
   if (document.getElementById("show_z_all").checked == true){
	 document.getElementById("show_z_friends").checked = true;
	 document.getElementById("show_z_following").checked = true;
	 document.getElementById("show_z_followers").checked = true;
	 document.getElementById("show_z_local").checked = true;
	 document.getElementById("show_z_groups").checked = true;
    }
 }

function select_zazam_form(type){
  if (type == 1){
	 document.getElementById('old_zazam').style.display = "";
	 document.getElementById('new_zazam').style.display = "";	
	 //document.getElementById('old_zazam').value="Product or Service You Are Offering";
	 //document.getElementById('new_zazam').value="Cash, Products or Services You Want in Exchange";
	 document.getElementById('cnt_for_old').style.display = "";
	 document.getElementById('cnt_for_new').style.display = "";	
	 document.getElementById('form_zazam_type_img').src = root_domain + '/grafika/form_postzazam.png';
	 document.getElementById('form_left_arrow').style.cssText="padding-top:0px";
     //document.getElementsByName("old_zazam")[0].style.color="gray";
     //document.getElementsByName("old_zazam")[0].style.fontStyle="italic";
     //document.getElementsByName("new_zazam")[0].style.color="gray";
     //document.getElementsByName("new_zazam")[0].style.fontStyle="italic";
     document.getElementById('main_form').action = root_domain + "/profile/" + current_user+"/zazamview";
  }
  if (type == 2){
	 document.getElementById('old_zazam').style.display = "";
	 document.getElementById('new_zazam').style.display = "none";	
	 //document.getElementById('old_zazam').value="Product or Service You Are Offering";
	 //document.getElementById('new_zazam').value="Make Offer";
	 document.getElementById('cnt_for_old').style.display = "";
	 document.getElementById('cnt_for_new').style.display = "none";	
	 document.getElementById('form_zazam_type_img').src = root_domain + '/grafika/form_makeoffer.png';
	 document.getElementById('form_left_arrow').style.cssText="padding-top:22px";
     //document.getElementsByName("old_zazam")[0].style.color="gray";
     //document.getElementsByName("old_zazam")[0].style.fontStyle="italic";
     document.getElementById('main_form').action = root_domain + "/profile/" + current_user+"/offerlists";
  }
  if (type == 3){
	 document.getElementById('old_zazam').style.display = "none";
	 document.getElementById('new_zazam').style.display = "";	 
	 //document.getElementById('old_zazam').value="What You Want";
	 //document.getElementById('new_zazam').value="Cash, Products or Services You Want in Exchange";
	 document.getElementById('cnt_for_old').style.display = "none";
	 document.getElementById('cnt_for_new').style.display = "";	
	 document.getElementById('form_zazam_type_img').src = root_domain + '/grafika/form_makewanted.png';
	 document.getElementById('form_left_arrow').style.cssText="padding-top:48px";
     //document.getElementsByName("new_zazam")[0].style.color="gray";
     //document.getElementsByName("new_zazam")[0].style.fontStyle="italic";
     document.getElementById('main_form').action = root_domain + "/profile/" + current_user+"/wantedlists";
	}
}

function change_search_type_new(forwhat){
	if(forwhat == 'people'){
		  document.getElementById('group_search_butt_cnt').style.display="none";
		  document.getElementById('search_people_cpt_cnt').style.display="";
		  document.getElementById('people_search_butt_cnt').style.display="";
		  document.getElementById('search_group_cpt_cnt').style.display="none";
		  document.getElementById('search_caption_cnt').innerHTML = "Who are you trying to find?";
		  document.getElementsByName('search_for_group')[0].name="search_for_people";
	}else{
	     document.getElementById('group_search_butt_cnt').style.display="";
	     document.getElementById('search_people_cpt_cnt').style.display="none";
	     document.getElementById('people_search_butt_cnt').style.display="none";
	     document.getElementById('search_group_cpt_cnt').style.display="";
	     document.getElementById('search_caption_cnt').innerHTML = "What are you interested in?";
	     document.getElementsByName('search_for_people')[0].name="search_for_group";
	 }
}

function get_subgroups(){
	//alert(document.getElementById('groupid').value);
	document.getElementById('subgroup_cnt').innerHTML = 'Loading...';
	var options = {
			   target: "#subgroup_cnt",
			    url: root_domain+'/ajax/get_subgroups.php?group_id='+document.getElementById('groupid').value,
			    success: function() {
	             //map.closeInfoWindow();
			    }
			  };
	 $("#subgroup_cnt").ajaxSubmit(options);
	 
}

function inputOnFocus(input, emptyText) { 
    if(input == null) return false; 
    if(input.value == emptyText) { 
        input.value = ""; 
    } 
    input.style.color = "#000000"; 
    input.style.fontStyle = ""; 

} 

function inputOnBlur(input, emptyText) { 
    if(input != null && input.value == "") { 
        input.value = emptyText; 
        input.style.color = "gray"; 
        input.style.fontStyle = "italic"; 
    } 
}
