// Easychange JavaScript library
// Rich Gray
// 23/05/2003 18:57

function pop(pop_url,win_name,w,h,sc) {
    var l = (screen.width  ? (screen.width - w) / 2 : 0);
    var t = (screen.height ? (screen.height - h) / 2 : 0);
    window.open(pop_url,win_name,'width='+w+',left='+l+',height='+h+',top='+t+(sc ? ',scrollbars=yes,resizable=yes' : '')+',location=no,status=no,toolbar=no');
}

function focusFrm() {
    if (document.forms && document.forms.length > 0) {
        var elems = document.forms[0].elements;
        for (i=0;i<elems.length;i++) {
            var e = elems[i];
            if (e.type && e.type == 'text') {
                try {
                    e.focus();
                }
                catch(err) {
                    continue;
                }
                break;
            }
        }
    }
}

function addEvent(elem,event_type,func,usecapture) {
    if (elem.addEventListener) {
        elem.addEventListener(event_type,func,usecapture);
        return true;
    }
    else if (elem.attachEvent) {
        var retcode = elem.attachEvent('on'+event_type,func);
        return retcode;
    }
    else {
        elem['on'+event_type] = func;
    }
}

// Load tooltips
$(document).ready(function() {

    $('a[id^=tt_]').each(function(i) {
        
        var uri  = this.href;
        var mtch = this.id.match(/tt_(\S+)/)
                        
        if (mtch != null) {
            var k = mtch[1];
            
            // Set up click handler
            $('#tti_'+k).click(function() {
                pop(uri,'info_pop',400,400,true);
                return false;
            });
            
            // DIsabled for now because JS content panels distort the X,Y positioning
            // so the tooltip is below the viewport... :(
            /* ***** 
            // Tell tooltip to go get content via AJAX
            if ($().simpletip) {
                var mtch2 = this.href.match(/&l=([a-z]+)&/);
                
                $('#tt_'+k).simpletip({ 
                    content: '',
                    position: 'bottom', 
                    showEffect: 'custom', 
                    showCustom: function() {
                      $(this).css({
                         fontSize: '12px',
                         display: 'block'
                      })
                      .animate({
                         fontSize: '15px'
                      },400)
                    },
                    position: 'right',
                    onBeforeShow: function() { 
                        this.load('ajax.php',{'a': 'ip','raw': 1,'lang': mtch2[1],'k': k}); 
                    } 
                });               
            }
            * *****/
        }
    });
    
});
