﻿// JScript File
function showhide(obj)
{
    var objid = '#'+obj;
    if($(objid)!=null)
    {
        if($(objid).css("display") == 'none')
        {
            show(obj);
        }
        else
        {
            hide(obj);
        }
    }
    return false;
}
function hide(obj) 
{
    var objid = '#'+obj;
    if($(objid)!=null)
    {
        $(objid).hide();
    }
    return false;
}
function show(obj) 
{
    var objid = '#'+obj;
    if($(objid)!=null)
    {
        $(objid).show();
        if(/MSIE (\d+\.\d+);/.test(navigator.userAgent) && $(objid)[0].tagName == "TR")
        {
            $(objid).css("display","block");
        }
    }
    return false;
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

function expandAll(list)
{
 for (var i=0; i<list.length; i++)
{
    show(list[i]);
}
return false;
}
function collapseAll(list)
{
 for (var i=0; i<list.length; i++)
{
    hide(list[i]);
}
return false;
}

function toggleAll(trlist,imglist)
{
 for (var i=0; i<trlist.length; i++)
{
    toggleTRVis(trlist[i],imglist[i]);
}
return false;
}
function expandAll(trlist,imglist)
{
 for (var i=0; i<trlist.length; i++)
{
    setTRVis(trlist[i],imglist[i],true);
}
return false;
}
function collapseAll(trlist,imglist)
{
 for (var i=0; i<trlist.length; i++)
{
    setTRVis(trlist[i],imglist[i],false);
}
return false;
}


        //master: id of div element that contains the information about master data

        //details: id of div element wrapping the details grid

        function showhidejq(master,detail)

        { 

            //First child of master div is the image

            var src = $(master).children()[0].src;

            //Switch image from (+) to (-) or vice versa.

            if(src.endsWith("plus.png"))

               src = src.replace('plus.png','minus.png');

           else

               src = src.replace('minus.png','plus.png');

           

           //Set new image

           $(master).children()[0].src = src;

           

           //Toggle expand/collapse                   

           $(detail).slideToggle("normal");             

       }


function swap(box1id, box2id)
{
    var temp = $(box1id).val();
    $(box1id).val($(box2id).val());
    $(box2id).val(temp);
    return false;
}



function searchyt(artistbox, titlebox)
{
    //http://uk.youtube.com/results?search_query=jahranimo+move&search_type=&aq=f
    var yturl = "http://www.youtube.com/results?search_query="+escape($(artistbox).val())+"+"+escape($(titlebox).val())+"&search_type=&aq=f";
    window.open(yturl,"bmmyt","");
    return false;
}

function searchlastfm(artistbox, titlebox)
{
    //http://www.last.fm/search?q=
    var lastfmurl = "http://www.last.fm/search?q="+encodeURIComponent($(artistbox).val())+"+"+encodeURIComponent($(titlebox).val());
    window.open(lastfmurl,"bmmlastfm","");
    return false;
}

function searchgoogle(artistbox, titlebox)
{
    //http://www.google.co.uk/search?q=
    var googleurl = "http://www.google.com/search?q="+encodeURIComponent($(artistbox).val())+"+"+encodeURIComponent($(titlebox).val());
    window.open(googleurl,"bmmgoogle","");
    return false;
}
function searchdeezer(artistbox, titlebox)
{
    //http://www.deezer.com/#music/result/all/title%20artist
    var deezerurl = "http://www.deezer.com/#music/result/all/"+encodeURIComponent($(artistbox).val())+"%20"+encodeURIComponent($(titlebox).val());
    window.open(deezerurl,"bmmdeezer","");
    return false;
}


function m(user, host) 
{
    window.location.href="mailto:"+user+"@"+host+"?subject=";
    return false;
}
function m(user, host, subject)
{
    window.location.href="mailto:"+user+"@"+host+"?subject="+subject;
    return false;
}


function togglePanelVis(panelId, imgId) 
{
    $(panelId).slideToggle();
    var $img = $(imgId);
   var src = $img.attr('src');
   var newsrc = src.indexOf('expand')>=0 ? src.replace('expand','collapse') : src.replace('collapse','expand');
   $img.attr('src',newsrc);
}
function toggleTRVis(trId, imgId) 
{
    showhide(trId);
    var $img = $('#'+imgId);
   var src = $img.attr('src');
   var newsrc = src.indexOf('expand')>=0 ? src.replace('expand','collapse') : src.replace('collapse','expand');
   $img.attr('src',newsrc);
}
function setTRVis(trId, imgId, vis) 
{
if(vis)show(trId);else hide(trId);
    var $img = $('#'+imgId);
   var src = $img.attr('src');
   var newsrc = vis ? src.replace('expand','collapse') : src.replace('collapse','expand');
   $img.attr('src',newsrc);
}


function expandAll(tableid)
{
$("tr", $(tableid)).filter(".extendedinfo").each(function() 
                { 
                    show($(this).attr("id"));
                });
                return false;
                }
function collapseAll(tableid)
{
$("tr", $(tableid)).filter(".extendedinfo").each(function() 
                { 
                    hide($(this).attr("id"));
                });
                return false;
}

// onload login positioning
// fuck i hate this, but it works...
$(document).ready(function(){$("#login").hide();});
$(window).load(positionLogin);

function positionLogin() {
var el = $("#login");
var el2 = $("#breadcrumb");
var pos = el2.position();
var leftpos = pos.left+el2.width()-el.width()-19;
el.css({ left: leftpos });
}

var resizeTimer = null;
$(window).bind('resize', function() {
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(positionLogin, 100);
});

function clickonenter(e, cmd)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

    if(key==13) {
    eval(cmd);
        //$(btnid).focus();
    }
}