$(function(){
    // ---v- Unobtrusive popup Windows
    $('a.newwin').click(function(){
        cls = $(this).attr('class');
        url = $(this).attr('href');
        w   = ((cls.match(/w:(\d+)/)||[])[1]) || 300;
        h   = ((cls.match(/h:(\d+)/)||[])[1]) || 215;
        // Available param values:
        // toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=400
        parm = "width="+w+",height="+h+",scrollbars=1,resizable=1";
        window.open(url,'InfoWindow',parm).focus();
        return false;
    });
// ---^-
    $('#profsmallpic a').click(function(){
        $('#profbigpic img').attr("src",this.href);
        return false;
    });

// ---v- FAQ/MailFAQ pages: number answers, add "Back to top" links
    var toTop = '<a href="#top" class="ttp">Back to Top</a>';
    if (thispg('faq')) {
        var faqs = document.getElementsByTagName('dl');
        var flen = faqs.length;
        for(var i=0;i<flen;i++){
            if(faqs[i].className=='faqa'){
                var dtel = faqs[i].getElementsByTagName('dt');
                var ddel = faqs[i].getElementsByTagName('dd');
                var dtln = dtel.length;
                for(var n=0;n<dtln;n++){
                    dtel[n].innerHTML = 1+n+'. '+dtel[n].innerHTML;
                    ddel[n].innerHTML = ddel[n].innerHTML+toTop;
                }
            }
        }
    }
// ---^-

    $('#regpages a').not('.newwin').each(function(i){
        $(this).click(function(){
            return confirm("Are you sure you want to leave this page?\n If yes, all data entered will be lost!");
        });
    });
    $('a').focus(function() {
        this.blur();
    });
    if (jQuery.browser.msie)
  {
    try
    {
      document.execCommand("BackgroundImageCache",false,true);
    } catch(err){}
  }
});

// Check page name
function thispg(pg){
    var page = pg+'.html';
    return (window.location.href.indexOf(page)!=-1)?true:false;
}
