﻿var gSearchIndex = 'Books'; // Used by Browse
var gBrowseLevel = 0;
var searchHistory =new Array;
var gXsl = new Array;
var currentBrowse = 'b1';

function Clear(strDiv){
    document.getElementById(strDiv).innerHTML = "";
}

function Browse(strHistory, iPage, strParam){
    AddSomethingToDo(strParam + 'itemPage=' + iPage, 'amazonSearch.xml', 'itemSearch', 'searchResults');
}

function AddSearchHistory(strHTML, iCurrentlyDoing){
    // Adds a menu item for the history box
    var iPage = searchHistory.length;
    searchHistory[iPage]=strHTML;
    //document.getElementById('searchHistory').innerHTML += "<div class='hist' onmousemove='ShowCaption(" + iCurrentlyDoing + ")' onmouseout='Hide(\"captionDiv\")' onclick='ShowHist("+iPage+")'>"+(iPage+1)+"</div>";
    document.getElementById('searchHistory').innerHTML += "<a href='javascript:void(0)' onmousemove='ShowCaption(" + iCurrentlyDoing + ")' onmouseout='Hide(\"captionDiv\")' onclick='ShowHist("+iPage+")'>["+(iPage+1)+"]</a>";
}

function ShowHist(id){
   document.getElementById('searchResults').innerHTML = searchHistory[id];
}

function InitXslFF() {
   gXsl[0] = document.implementation.createDocument("","xsl",null); gXsl[0].load('xml/amazonSearch.xml');
   gXsl[1] = document.implementation.createDocument("","xsl",null); gXsl[1].load('xml/amazonItemDetails.xml');
   gXsl[2] = document.implementation.createDocument("","xsl",null); gXsl[2].load('xml/amazonItemSmall.xml');
   gXsl[3] = document.implementation.createDocument("","xsl",null); gXsl[3].load('xml/yProducts.xml');
   gXsl[4] = document.implementation.createDocument("","xsl",null); gXsl[4].load('xml/amazonCartCreate.xml');
   gXsl[5] = document.implementation.createDocument("","xsl",null); gXsl[5].load('xml/technoratiSearch.xml');   
   gXsl[6] = document.implementation.createDocument("","xsl",null); gXsl[6].load('xml/amazonBrowseNode.xml');      
   gXsl[7] = document.implementation.createDocument("","xsl",null); gXsl[7].load('xml/rsstohtml.xml');      
   gXsl[8] = document.implementation.createDocument("","xsl",null); gXsl[8].load('xml/amazonCartGet.xml');      
   gXsl[9] = document.implementation.createDocument("","xsl",null); gXsl[9].load('xml/ebaySearch.xml');      
   gXsl[10] = document.implementation.createDocument("","xsl",null); gXsl[10].load('xml/yNews.xml');     
   gXsl[11] = document.implementation.createDocument("","xsl",null); gXsl[11].load('xml/yMovies.xml');     
   gXsl[12] = document.implementation.createDocument("","xsl",null); gXsl[12].load('xml/yImages.xml');
   gXsl[13] = document.implementation.createDocument("","xsl",null); gXsl[13].load('xml/flickr.xml');
   gXsl[14] = document.implementation.createDocument("","xsl",null); gXsl[14].load('xml/yAudioArtist.xml');
   gXsl[15] = document.implementation.createDocument("","xsl",null); gXsl[15].load('xml/ayeHtml.xml');
   gXsl[16] = document.implementation.createDocument("","xsl",null); gXsl[16].load('xml/eBayItemSmall.xml');
   gXsl[17] = document.implementation.createDocument("","xsl",null); gXsl[17].load('xml/amazonTopNew.xml');
   gXsl[18] = document.implementation.createDocument("","xsl",null); gXsl[18].load('xml/youtube.xml');
}

function InitXslIE() {    
   gXsl[0] = new ActiveXObject("Msxml2.DomDocument"); gXsl[0].load('xml/amazonSearch.xml');
   gXsl[1] = new ActiveXObject("Msxml2.DomDocument"); gXsl[1].load('xml/amazonItemDetails.xml'); 
   gXsl[2] = new ActiveXObject("Msxml2.DomDocument"); gXsl[2].load('xml/amazonItemSmall.xml');
   gXsl[3] = new ActiveXObject("Msxml2.DomDocument"); gXsl[3].load('xml/yProducts.xml');
   gXsl[4] = new ActiveXObject("Msxml2.DOMDocument.3.0");gXsl[4].load('xml/amazonCartCreate.xml');
   gXsl[5] = new ActiveXObject("Msxml2.DomDocument"); gXsl[5].load('xml/technoratiSearch.xml');   
   gXsl[6] = new ActiveXObject("MSXML2.FreeThreadedDOMDocument"); gXsl[6].load('xml/amazonBrowseNode.xml'); 
   gXsl[7] = new ActiveXObject("Msxml2.DomDocument"); gXsl[7].load('xml/rsstohtml.xml');   
   gXsl[8] = new ActiveXObject("Msxml2.DomDocument"); gXsl[8].load('xml/amazonCartGet.xml');   
   gXsl[9] = new ActiveXObject("Msxml2.DomDocument"); gXsl[9].load('xml/ebaySearch.xml');   
   gXsl[10] = new ActiveXObject("Msxml2.DomDocument"); gXsl[10].load('xml/yNews.xml');   
   gXsl[11] = new ActiveXObject("Msxml2.DomDocument"); gXsl[11].load('xml/yMovies.xml');   
   gXsl[12] = new ActiveXObject("Msxml2.DomDocument"); gXsl[12].load('xml/yImages.xml');   
   gXsl[13] = new ActiveXObject("Msxml2.DomDocument"); gXsl[13].load('xml/flickr.xml');   
   gXsl[14] = new ActiveXObject("Msxml2.DomDocument"); gXsl[14].load('xml/yAudioArtist.xml');   
   gXsl[15] = new ActiveXObject("Msxml2.DomDocument"); gXsl[15].load('xml/ayeHtml.xml');   
   gXsl[16] = new ActiveXObject("Msxml2.DomDocument"); gXsl[16].load('xml/eBayItemSmall.xml');   
   gXsl[17] = new ActiveXObject("Msxml2.DomDocument"); gXsl[17].load('xml/amazonTopNew.xml');   
   gXsl[18] = new ActiveXObject("Msxml2.DomDocument"); gXsl[18].load('xml/youtube.xml');      
}

function AZTopNew(strBrowseNode){ 
    AddSomethingNewToDo('Amazon Top Sellers & New Releases', "", "", 'Operation=BrowseNodeLookup&BrowseNodeId='+ strBrowseNode+'&ResponseGroup=TopSellers,NewReleases',  17, 'app', 'similar');
}
function AZTop(strBrowseNode){ 
    AddSomethingNewToDo('Amazon Top Sellers', "", "", 'Operation=BrowseNodeLookup&BrowseNodeId='+ strBrowseNode+'&ResponseGroup=TopSellers',  17, 'app', 'similar');
}
function AZNew(strBrowseNode){ 
    AddSomethingNewToDo('Amazon New Releases', "", "", 'Operation=BrowseNodeLookup&BrowseNodeId='+ strBrowseNode+'&ResponseGroup=NewReleases',  17, 'app', 'similar');
}

function AZItemLookup(strASIN) {
   AddSomethingNewToDo('Amazon Item Lookup: ' + strASIN, "", "", 'Operation=ItemLookup&ResponseGroup=Large&ItemId=' + strASIN ,  1, 'app', 'searchResults');
}

function AS(iPage, strIndex) {
   AddSomethingNewToDo('Amazon Search:' + GCK(), iPage, strIndex, 'Operation=ItemSearch&ResponseGroup=Medium&Keywords=' + GCK(), 0, 'app', 'searchResults');
}

function ES(iPage, strIndex) {
   AddSomethingNewToDo('Ebay Search:' + GCK(), 0, '', GCK(), 9, 'e', 'searchResults');
}

function EB() {
   AddSomethingNewToDo('Ebay Search:' + GCK(), 0, '', GCK(), 16, 'e', 'similar');
}

function EK(strKeyWord) {
   AddSomethingNewToDo('Ebay Search:' + strKeyWord, 0, '', strKeyWord, 9, 'e', 'searchResults');
}

function AYE(iPage){
    AddSomethingNewToDo('AMZN+YHOO+EBAY:' + GCK(), 0, '', GCK(), 15, 'j', 'searchResults');
}

function EI(strKeyword){
   AddSomethingNewToDo('Ebay Search:' + strKeyword, 0, '', strKeyword, 9, 'e', 'searchResults');
}

function GI(){
    var dd = document.getElementById('ddSearchIndex');
    return dd.options[dd.selectedIndex].value;    
}

function ShowCaption( iIndex ){
    // Shows the Caption on a mouse-over for a history number thingy.
    ShowHtmlCaption(theQueueCaptions[iIndex]);    
}

function ShowHtmlCaption(strHtml){
    document.getElementById('captionDiv').style.left = 10 + tempX + 'px';
    document.getElementById('captionDiv').style.top = 10+ tempY+ 'px';  
    document.getElementById('captionDiv').innerHTML = strHtml;
    document.getElementById('captionDiv').style.visibility = 'visible';    
}

function Hide(strDiv){
    document.getElementById(strDiv).style.visibility = 'hidden';    
}
function Show(strDiv){
    document.getElementById(strDiv).style.visibility = 'visible';    
}
function ShowBrowse(){
    document.getElementById('amazonBrowse').style.visibility = 'visible';    
}

function AddBrowseToDo(strNodeId, iLevel){
    gBrowseLevel = iLevel;
    AddSomethingNewToDo('Amazon Browse: ' + gSearchIndex, 1, gSearchIndex, 'Operation=BrowseNodeLookup&BrowseNodeId=' + strNodeId + '&Sort=salesrank', 6, 'app', 'browse' + gBrowseLevel);
    // clean up existing select boxes
    var i=gBrowseLevel +1;
    while ( i < 11) {
     Clear('browse' + i);
     i++;
     }
}

function BeginBrowse(strIndex, strNodeId, obj){
    //Hide('amazonBrowse');
//    Clear('browse1');Clear('browse2');Clear('browse3');Clear('browse4');Clear('browse5');Clear('browse6');Clear('browse7');
    document.getElementById(currentBrowse).style.background='';    
    currentBrowse=obj;
    document.getElementById(currentBrowse).style.background='#BFD9F9';
        
    document.getElementById('browseContainer').style.visibility='visible';
    document.getElementById('browseContainer').style.height='75px';
    gSearchIndex = strIndex;    
    AddBrowseToDo(strNodeId, 1);
}