function wipeinput(item, defvalue)
{

}

function search_friend_st(tab)
{
    jQuery('#search_approved').hide();
    jQuery('#search_latest').hide();
    jQuery('#search_sentrequests').hide();
    jQuery('#search_recvrequests').hide();
//    jQuery('search_suggestions').hide();

    if (tab != 'suggestions')
    {
        jQuery('#search_' + tab).show();
    }
}

function selectfriend(uid)
{
    jQuery('#target_avatar').html(jQuery('#avatar_'+uid).html());
    jQuery('#user_id').value = uid;
    tagimage_change_friend();
}


function selectimagebyid(label)
{
    img = jQuery('#' + label);
    if (img.hasClass('selectedimage'))
    {
        img.removeClass('selectedimage');
        img.fadeTo('slow', 1);
    }
    else
    {
        img.addClass('selectedimage');
        img.fadeTo('slow', 0.7);
    }
}


function selectimage(img)
{
    if (img.hasClass('selectedimage'))
    {
        img.removeClass('selectedimage');
        img.fadeTo('slow', 1);
    }
    else
    {
        img.addClass('selectedimage');
        img.fadeTo('slow', 0.7);
    }
}


function tagimage_change_friend()
{
    jQuery('#textdiv').fadeTo('slow', 0.7);
    jQuery('#selfdiv').fadeTo('slow', 0.7);
    jQuery('#friendsdiv').fadeTo('slow', 1);
    jQuery('#friendsselectiondiv').fadeTo('slow', 1);

    jQuery('#self').attr('checked', false);
    jQuery('#text').val('');
}

function tagimage_change_self()
{
//    if( jQuery('#self').checked )
  //  {
        jQuery('#textdiv').fadeTo('slow', 0.7);
        jQuery('#selfdiv').fadeTo('slow', 1);
        jQuery('#friendsdiv').fadeTo('slow',0.7);
        jQuery('#friendsselectiondiv').fadeTo('slow', 0.7);
//    }
  //  else
//    {
  //      jQuery('#textdiv').fadeTo('slow', 1);
    //    jQuery('#selfdiv').fadeTo('slow', 0.5);
     //   jQuery('#friendsdiv').fadeTo('slow', 1);
     //   jQuery('#friendsselectiondiv').fadeTo('slow', 1);
//    }

    jQuery('#text').val('');
}

function tagimage_change_text()
{
    if (jQuery('#text').val().length > 0)
    {
        jQuery('#textdiv').fadeTo('slow', 1);
        jQuery('#selfdiv').fadeTo('slow', 0.7);
        jQuery('#friendsdiv').fadeTo('slow', 0.7);
        jQuery('#friendsselectiondiv').fadeTo('slow', 0.7);
    }
    else
    {
        jQuery('#textdiv').fadeTo('slow', 0.7);
        jQuery('#selfdiv').fadeTo('slow', 1);
        jQuery('#friendsdiv').fadeTo('slow', 1);
        jQuery('#friendsselectiondiv').fadeTo('slow', 1);
    }

    jQuery('#self').attr('checked', false);
}

function profile2_tab(section, tab)
{
    jQuery('#profile_information').hide();
    jQuery('#profile_general').hide();
    jQuery('#profile_profile').hide();
    jQuery('#profile_music').hide();

    jQuery('#profile_information_tab').removeClass('selected_profile_tab');
    jQuery('#profile_general_tab').removeClass('selected_profile_tab');
    jQuery('#profile_profile_tab').removeClass('selected_profile_tab');
    jQuery('#profile_music_tab').removeClass('selected_profile_tab');

    tab.addClass('selected_profile_tab');
    jQuery(section).show();

}

function json_moodupdate(input, json)
{
    var r= json;

//alert(input);
  //  if (!json){
        var r= eval('(' + input.responseText + ')');
   // }
 

    jQuery('#userhome_update_content').before(r.partial);
    jQuery('#mood_update').html(r.mood);
    jQuery('#mood_change').slideUp();

}

function json_updates(input, json)
{
    var r= json;

    if (!json){
        var r= eval('(' + input.responseText + ')');
    }

    jQuery('#updatestopbar #updatestopbarspan').html(r.updatescount);
    if (parseInt(r.updatescount) > 0 )
    {
	jQuery('#updatestopbar').addClass('statusbarred');
    }
    else
    {
	jQuery('#updatestopbar').removeClass('statusbarred');
    }


    jQuery('#notificationstopbar #notificationstopbarspan').html(r.notificationscount);
    if (parseInt(r.notificationscount) > 0 )
    {
	jQuery('#notificationstopbar').addClass('statusbarred');
    }
    else
    {
	jQuery('#notificationstopbar').removeClass('statusbarred');
    }

    jQuery('#online_friends_count').html(r.onlinecount);
}


function imagejson(input, json)
{
    var r= json;

    if (!json){
        var r= eval('(' + input.responseText + ')');
    }

jQuery('#backalbum').html(r.backalbum);
jQuery('#backalbums').html(r.backalbums);
jQuery('#backprofile').html(r.backprofile);
jQuery('#imgnum').html(r.imgnum);
jQuery('#imgdescription').html(r.imgdescription);
jQuery('#allnum').html(r.allnum);
jQuery('#toptitle').html(r.imgtitle);
//jQuery('#invitelink').html(r.invitelink)
jQuery('#invitelink a').attr('href', '/userinvite/index/type/6/id/' + r.imgid + '.html?height=420&width=680');
jQuery('#clublink').html(r.clublink);
jQuery('#albumlink').html(r.albumlink);
jQuery('#userlink').html(r.userlink);
jQuery('#imagetags').html(r.imagetags);
//jQuery('#imagetags a').attr('href', '/albumimages/addtag/id/' + r.imgid + '.html');
jQuery('#dwlink').attr('href', '/download_image/id/' + r.imgid + '.html');
jQuery('#imagetagsbottom').html(r.imagetagsbottom);
jQuery('#image_comments').html(r.image_comments);
jQuery('#editlink').html(r.editlink);
jQuery('#taglink a').attr('href', '/albumimages/addtag/id/'+ r.imgid + '.html');
jQuery('#innerimage').html(r.innerimage);
jQuery('div#imgtitle').html(r.imgtitle);

jQuery('#mainimage').attr('src', r.mainimage);
jQuery('#nextlink').html( r.nextlink);
jQuery('#prevlink').html( r.prevlink);
//jQuery('#imgid').val(r.imgid)


  //  jQuery('section').value = r.section;
   // $('mainimage').src = r.mainimage;
    //alert($('dwlink').href);
//    $('dwlink').href = $('dwlink').href.substring(0, $('dwlink').href.lastIndexOf('/')) + '/'+r.imgid+'.html';

//alert('imagejson');
    //document.location += '#' + r.histurl;
    //alert(document.location.sub('#', ''))
    //document.location = document.location.sub(/#.*/, '');
    //document.location += '#' + r.histurl;
  jQuery("#innerimage a[rel='history']").click(function(){
                        var hash = this.href;
                        hash = hash.replace(/^.*#/, '');
                        jQuery.historyLoad(hash);
                        return false;
                });

}

function okimage(con)
{
	$(con).innerHTML = '<img src="/images/ok.gif" alt="ok" /> OK';
}

function loading2(con)
{
//	$(con).setOpacity(0.5);
	jQuery('#' + con).fadeTo('slow', 0.5);
    //new Effect.Opacity(con, { from: 1.0, to: 0.5, duration: 0.1 });

}

function unloading(con)
{
	jQuery('#' + con).html('');
}
function unloading2(con)
{
//	$(con).setOpacity(1);
	jQuery('#' + con).fadeTo('slow', 1);
//	jQuery('#' + con).css('opacity', 1);
//alert('unloading2')
}

function loadingspan(con)
{
//	$(con).innerHTML = '<span class="loading"><img src="/images/loading.gif" alt="loading" /></span>';
	jQuery('#' + con).html('<span class="loading"><img src="/images/loading.gif" alt="loading" /></span>');
}

function loading(con)
{
	//$(con).innerHTML = '<div class="loading"><img src="/images/loading.gif" alt="loading" /></div>';
	//jQuery('#' + con).html('<div class="loading"><img src="/images/loading.gif" alt="loading" /></div>');
	jQuery('#' + con).html('<div class="loading"><img src="/images/loading.gif" alt="Зареждане..." /></div>');
}

function selectuser(id)
{
    if (jQuery('#' + id).hasClass('selected_invite_user'))
        jQuery('#' + id).removeClass('selected_invite_user');
    else
        jQuery('#' + id).addClass('selected_invite_user');

}

function toggleCheckBoxes(formName, src)   {
	jQuery('form#' + formName + ' input:checkbox').attr('checked', jQuery('#'+ src ).attr('checked'));
}

function update_friendlist(item)
{
    var friends = jQuery('#allfriends .invite_user');
    for(var i=0; i<friends.length; i++){
            if (item.value =="" )
            {
                friends[i].show();
            }
            else
            {
                var unames = friends[i].getElementsByClassName('username');
                for (var j=0; j< unames.length; j++)
                {
                    var un =  unames[j].innerHTML
                    if (un.toLowerCase().match(item.value.toLowerCase()))
                    {
                        friends[i].show();
                    }
                    else
                    {
                        friends[i].hide();
                    }
                }
            }
     }

}

function update_inviteslist(item)
{
    var friends = jQuery('#invite_friends .invite_user');
    for(var i=0; i<friends.length; i++){
            if (item.value =="" )
            {
                friends[i].show();
            }
            else
            {
                var unames = friends[i].getElementsByClassName('username');
                for (var j=0; j< unames.length; j++)
                {
                    var un =  unames[j].innerHTML
                    if (un.toLowerCase().match(item.value.toLowerCase()))
                    {
                        friends[i].show();
                    }
                    else
                    {
                        friends[i].hide();
                    }
                }
            }
     }

}

function approveimage(img)
{

    if (jQuery(img).hasClass('groupadminimagetoapprove'))
    {
        jQuery(img).removeClass('groupadminimagetoapprove');
    }
}

function wipenotifications()
{
alert('runwa')
    jQuery('notificationstopbarspan').html('0');
    jQuery('notificationstopbar').removeClass('statusbarred');
}

function wipeupdates()
{
    jQuery('updatestopbarspan').html('0');
    jQuery('updatestopbar').removeClass('statusbarred');
}

function decrementnotifications()
{
    var ncount = parseInt(jQuery('#notificationstopbarspan').html());
    if (ncount >0)
    {
        jQuery('#notificationstopbarspan').html(ncount -1); 
    }

    if (ncount == 1)
    {
        jQuery('#notificationstopbar').removeClass('statusbarred');
    }
}

function decrementupdates()
{
    var ncount = parseInt(jQuery('#updatestopbarspan').html());
    if (ncount >0)
    {
        jQuery('#updatestopbarspan').html( ncount -1); 
    }

    if (ncount == 1)
    {
        jQuery('updatestopbar').removeClass('statusbarred');
    }
}

function updatestab(tab)
{
	var targeturl = '';
	var targetid = '';
	var selectedtab = '';
	var updatetab  = tab;

	jQuery('#updatestopbar').removeClass('controltab_selected')
	jQuery('#notificationstopbar').removeClass('controltab_selected')
	jQuery('#updatestopbarlink').removeClass('controltab_selected')

	if (tab == 'fupdates')
	{
		jQuery('#notifications').hide();
		jQuery('#online_friends').hide();
		targetid = '#fupdates';
		targeturl = '/statusbar/friendupdates.html';
		selectedtab = '#updatestopbar';
	}
	if (tab == 'notifications')
	{
		jQuery('#fupdates').hide();
		jQuery('#online_friends').hide();
		targetid = '#notifications';
		targeturl = '/statusbar/notifications.html';
		selectedtab = '#notificationstopbar';
	}
	if (tab == 'online_friends')
	{
		jQuery('#fupdates').hide();
		jQuery('#notifications').hide();
		targetid = '#friends_container';
		targeturl = '/statusbar/onlinefriends.html';
		updatetab = '#friends_container';
		selectedtab = '#updatestopbarlink';
	}

	if (jQuery("#"+tab).css('display') == 'none') 
	{
		jQuery("#"+tab).css('display','block');
		jQuery(selectedtab).addClass('controltab_selected')

		jQuery.ajax({type:'POST',dataType:'html',success:function(data, textStatus){jQuery(targetid).html(data);},complete:function(XMLHttpRequest, textStatus){tb_init(targetid  + ' .thickbox ,#TB_ajaxContent  a.thickbox, #TB_ajaxContent area.thickbox,#TB_ajaxContent  input.thickbox')},url: targeturl}); 
	}
	else
	{
		jQuery("#"+tab).css('display','none');
	}

	jQuery('#se_input').val('Търси в приятели');
//	loading(updatetab);
}

function quizmanagetab(tab)
{
	jQuery('#management').hide();
	jQuery('#answers').hide();
	jQuery('#questions').hide();
	jQuery('#categories').hide();

	jQuery('#management_span').removeClass('quizselectedtab');
	jQuery('#answers_span').removeClass('quizselectedtab');
	jQuery('#questions_span').removeClass('quizselectedtab');
	jQuery('#categories_span').removeClass('quizselectedtab');

	jQuery('#' + tab).show();
	jQuery('#' + tab + '_span').addClass('quizselectedtab');
}

function scrollto(elid)
{
	 var caller = this;
                        //event.preventDefault();
                        var locationHref = window.location.href;
                        var elementClick = '#' + elid;

                        var destination = jQuery(elementClick).offset().top;
                        jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100, function() {
                                window.location.hash = elementClick;
                        });

}
