var el=null;
function submitenter(myfield,e){
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13)
    {
        search();
        return false;
    }
    else
        return true;
}
function aTooltip(items, name){
    var str='';
    $(items).each(function(i){
        str = '<div class="gr-line tooltip" id="'+name+i+'" style="width:570px;"><div class="s1"><b>&nbsp;</b></div><div class="s2"><b><i>&nbsp;</i></b></div><div class="s3"><b>&nbsp;</b></div><div class="s4"><b>&nbsp;</b></div><div class="s5"><b>&nbsp;</b></div><div class="s6"><b>&nbsp;</b></div><div class="s7"><b>&nbsp;</b></div><div class="s8"><b>&nbsp;</b></div><div class="s9"><b>&nbsp;</b></div><div class="s10"><b>&nbsp;</b></div><div class="gr-line-content"><div class="tip-content"><div class="ar"><a href="javascript:;" class="red"><img src="/images/09_tip_close.gif" width="7" height="7" alt="" /></a></div>'
        +'<strong class="title">'+$(this).attr('title')+'</strong><br />'
        +'<div class="text" id="'+name+i+'_text"></div>'
        +'</div></div><div class="s10"><b>&nbsp;</b></div><div class="s9"><b>&nbsp;</b></div><div class="s8"><b>&nbsp;</b></div><div class="s7"><b>&nbsp;</b></div><div class="s6"><b>&nbsp;</b></div><div class="s5"><b>&nbsp;</b></div><div class="s4"><b>&nbsp;</b></div><div class="s3"><b>&nbsp;</b></div><div class="s2"><b><i>&nbsp;</i></b></div><div class="s1"><b>&nbsp;</b></div></div>';
        
        $("#alltool").append(str);
        var my_tooltip = $("#"+name+i);
        my_tooltip.find('.red').click(function(){
            my_tooltip.fadeOut(400);
            my_tooltip.removeClass('shown');
        });
        $(this).attr('href','javascript:;');
        $(this).removeAttr("title").click(function(kmouse){
            if(!my_tooltip.hasClass('shown')){
                $(".tooltip").each(function(){
                    $(this).fadeOut(200);
                    $(this).removeClass('shown');
                });
                if(my_tooltip.find('.text').html()==""){
                    title=my_tooltip.find('strong.title').html();
                    $.ajax({
                        url:"/glossary/word/",
                        type:"POST",
                        data:{
                            title:title                            
                        },
                        success:function(m){
                            id=my_tooltip.attr('id');
                            el=document.getElementById(id+'_text');
                            el.innerHTML=m;
                            my_tooltip.css({
                                display:"none"
                            }).fadeIn(400);
                            my_tooltip.addClass('shown');
//
                            l=kmouse.pageX-(my_tooltip.width()/2);
                            if(l<0){
                                l=20;
                            }
                            if((l+my_tooltip.width())>$(window).width()){
                                l=$(window).width()-(my_tooltip.width()+50);
                            }
                            t=kmouse.pageY-(20+my_tooltip.height());
                            my_tooltip.css({
                                left:l,
                                top:t
                            });
                        }
                    });
                }else{
                    my_tooltip.css({
                        display:"none"
                    }).fadeIn(400);
                    my_tooltip.addClass('shown');
                    l=kmouse.pageX-(my_tooltip.width()/2);
                    if(l<0){
                        l=20;
                    }
                    if((l+my_tooltip.width())>$(window).width()){
                        l=$(window).width()-(my_tooltip.width()+50);
                    }
                    t=kmouse.pageY-(40+my_tooltip.height());
                    my_tooltip.css({
                        left:l,
                        top:t
                    });
                }

            }
        });
    });
}
Array.prototype.has=function(v){
    for (i=0;i<this.length;i++){
    if (this[i]==v) return i;
    }
    return false;
}
