//Shows the publication details.
var visiblediv = null;
var txshopdiv = null;
var txshopiframe = null;

function moveVisibleDiv()
{
    //I hate Internet Explorer SO MUCH right now.
    //This could be done in two lines if they'd just do it the same way as Mozilla, et al.
    var winW;
    var winH;
    if(!window.innerWidth)
    {
        winW = document.body.offsetWidth;
        winH = document.body.offsetHeight;
    }
    else
    {
        winW = window.innerWidth;
        winH= window.innerHeight;
    }
    
    
    var dw = visiblediv.clientWidth;
    var dh = visiblediv.clientHeight;
    
    var l = (winW / 2) - (dw/2);
    var t = (winH / 4) - (dh/2);
    
    visiblediv.style.left = l;
    visiblediv.style.top = t;
}

function ShowPublicationDetails(pubID)
{
    var v = visiblediv;
    //Before we do much else, let's hide the visible publications div.
    HideVisiblePublicationsDiv();
    
    //Get the div.
    var d = document.getElementById("pub_details_div_" + pubID);
    
    if (v == d) return;
    
    //I hate Internet Explorer SO MUCH right now.
    //This could be done in two lines if they'd just do it the same way as Mozilla, et al.
    var winW;
    var winH;
    if(!window.innerWidth)
    {
        winW = document.body.offsetWidth;
        winH = document.body.offsetHeight;
    }
    else
    {
        winW = window.innerWidth;
        winH= window.innerHeight;
    }
    
    //Now, we need to compute the position of our div.
   
    d.style.display = "block";
    
    var dw = d.clientWidth;
    var dh = d.clientHeight;
    
    var l = (winW / 2) - (dw/2);
    var t = (winH / 4) - (dh/2);
    
    
    d.style.left = l;
    d.style.top = t;
    
    visiblediv = d;
    
    window.onresize = moveVisibleDiv;
}

function HideVisiblePublicationsDiv()
{
    if(visiblediv == null) return;
    
    
    visiblediv.style.display = "none";
    
    visiblediv = null;
}

function launchBuyPub(pubID)
{      
   var url = assembleTXShopURL(pubID);
   
   //var f = document.getElementById("txshopiframe");
   
   /*f.src = url;

   //Finally, make sure that the div is visible.
   showTXShopDiv();*/
   
   document.location = url;
}

//Generates the URL for the TXShop page for the given item.
function assembleTXShopURL(pubID)
{
    var baseurl = "http://utdirect.utexas.edu/txshop/item_details.WBX?cart_id=0EGBUREAU&dept_prefix=EG";
    
    var iid = "&item_id=" + pubID;
    
    return baseurl + iid; // + cid;
}

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function showTXShopDiv()
{
    //Make the store div visible.
    var z = document.getElementById("txshopdiv");
    
    z.style.visibility = "visible";
}

function hideTXShopDiv()
{
    //Make the store div visible.
    var z = document.getElementById("txshopdiv");
    
    z.style.visibility = "hidden";
}

function listItemMouseOver(pubID)
{
    var divID = "publicationlistdiv_" + pubID + "";
    var c = document.getElementById(divID);
    c.className = "publicationlistitemdiv_highlighted";
}

function listItemMouseOut(pubID)
{
    var divID = "publicationlistdiv_" + pubID + "";
    var c = document.getElementById(divID);
    var v = visiblediv;
    if(c != v)
    {
        c.className = "publicationlistitemdiv";
    }
}

//Does the resubmit action on the search form.
function resubmitForm(terms)
{
    f = document.getElementById("searchformhidden");
    
    hf = document.getElementById("sparams");
    
    hf.value = terms;
    
    f.submit();
}