function P_checkClick(ev) {
  if(P_setupPopUp ) {
    P_Link="";
//    if( document.layers ) { P_Link = ev.targetv.toString().toLowerCase(); }
    if( document.layers ) { P_Link = "" }
    else if( document.all ) {
      P_myElement = window.event.srcElement;
      while(P_myElement.tagName.toLowerCase() != "a" && 
            P_myElement.tagName.toLowerCase() != "area" && 
            P_myElement.tagName.toLowerCase() != "body" && 
            P_myElement.tagName.toLowerCase() != "input") {
        P_myElement = P_myElement.parentElement;
      }
      P_tag = P_myElement.tagName.toLowerCase();
      if( P_tag=="a" || P_tag=="area" ) { P_Link = P_myElement.href; }
      else if( P_tag=="input" ) { P_setupPopUp = false; }
    }
    
    P_Link = P_Link.toLowerCase();
    if( P_Link != "") {
      if(P_Link.indexOf("audible") > 0 || 
         P_Link.indexOf("linkthis") > 0 || 
         P_Link.indexOf("addtobasket") > 0 || 
         P_Link.indexOf("addtowishlist") > 0) {
        P_setupPopUp = false;
      }
      else { P_setupPopUp = true; }
    }
    if( document.layers ) {
      routeEvent( ev );
      return true;
    }
  }
}

function addToWishList(a) {
  document.basketForm.action = the_cgiinfo + '/store/wishList.jsp';
  document.basketForm.addToList.value=a;
  document.basketForm.previousPageLink.value=self.location.href;
  document.basketForm.addtobasket.value='no';
  document.basketForm.submit();
}

function show10GreatList() {
  window.open(the_myserver + the_cgiinfo + '/promo/10greatBarker.jsp?' + the_linkstring, 'help','resizable=no,toolbar=no,location=no,menubar=no,scrollbars=no,status=no,width=327,height=570');
}

function addToBasketAmazon(a) {
  document.basketForm.action= the_cgiinfo + "/store/amazonBasket.jsp";
  document.basketForm.productID.value=a;
  document.basketForm.previousPageLink.value=self.location.href;
  document.basketForm.addtobasket.value='yes';
  document.basketForm.submit();
}

function linkMe(a,b,c) {
  var matchMe = /^buy/;
  if(a.match(matchMe))
    linkThis('/store/buy.jsp','&notUsed='+a);
  else if(c == addtobasket) {
    var new_string= the_cgiinfo + '/store/homepage.jsp?' + the_linkstring + '&contentOID='+b+'&addtobasket=yes&uniqueKey='+uniqueKey;
    self.location.href=new_string;
  }
  else if(a == 'product') {
    var new_string= the_cgiinfo + '/store/product.jsp?' + the_linkstring + '&uniqueKey='+uniqueKey;
    if((b.indexOf('_') > 0) || (b.indexOf('-') > 0))
      new_string+='&productID='+b;
    else
      new_string+='&contentOID='+b;
    self.location.href=new_string;
  }
  else if(a == 'freeStuff2') {
    self.location.href= the_cgiinfo + '/store/freeStuff.jsp?' + the_linkstring + '&Type=freeStuff2&uniqueKey='+uniqueKey;
  }
  else if(a == 'freeStuff') {
    self.location.href= the_cgiinfo + '/store/freeStuff.jsp?' + the_linkstring + '&Type=freeStuff1&uniqueKey='+uniqueKey;
  }
  else {
    if(a)
    link_url+='&displayType='+a;
    if(b) {
      if((b.indexOf('_') > 0) || (b.indexOf('-') > 0))
      link_url+='&productID='+b;
      else if (c == subcategory)
      link_url+=c+b;
      else
      link_url+='&contentOID='+b;
    }
    if(c == addtobasket) { 
      link_url+=c;
    }
    self.location.href=link_url;
  }
}

function pushLink(a,b) {
  linkMe('product',a);
}

function popUp(a,b,c) {
  window.open(a,b,c);
}

function popUpJSP(a,b) {
  if(b == null) 
    b = '';
  window.open(the_myserver + the_cgiinfo +a+'?' + the_linkstring + b,'help','resizable=yes,toolbar=yes,location=no,menubar=yes,scrollbars=yes,status=yes,width=500,height=400');
}

function popUpPR(a) {
  window.open(a,'help','resizable=yes,toolbar=yes,location=no,menubar=yes,scrollbars=yes,status=yes,width=500,height=400');
}

function setAudio(a) {
  myListeningPreference = a;
}

function deleteFromCart(a) {
  document.removeCart.deleteOID.value = a;
  document.removeCart.submit();
}

function buildItemList() {
  document.itemListForm.previousPageLink.value = self.location.href;
  document.itemListForm.uniqueKey.value = uniqueKey;
  document.itemListForm.itemList.value = "";
  limit = document.itemListForm.maxitemlist.value;
  limit++;
  for(i=1;i<limit;i++) {
    tempChecked = eval("document.itemListForm.itemList"+i+".checked");
    tempValue = eval("document.itemListForm.itemList"+i+".value");
    if(tempChecked) {
      document.itemListForm.itemList.value += tempValue + ',';
    }
  }
  document.itemListForm.BV_SessionID.value = the_sessionId;
  document.itemListForm.BV_EngineID.value = the_engineId;
  document.itemListForm.submit();
  return false
}

function categoryLink() {
  var parIndex = document.freeOffers.categoryLinkCategory[document.freeOffers.categoryLinkCategory.selectedIndex].value;
  if(parIndex != 'select') {
    linkThis('/store/product.jsp',browseSelectArray[parIndex]);
  }
}

function linkCategory() {
  P_setupPopUp = false;
  var pageArray = new Array(
    '', '/store/category.jsp', '/store/category.jsp', '/store/category.jsp', '/store/category.jsp', 
    '/store/category.jsp', '/store/category.jsp', '/store/category.jsp', '/store/category.jsp', 
    '/store/category.jsp', '/store/category.jsp', '/store/category.jsp', '/store/category.jsp',
    '/store/category.jsp', '/store/category.jsp', '/store/category.jsp', '/store/category.jsp',
    '/store/category.jsp', '/store/category.jsp', '/store/category.jsp', '/store/category.jsp',
    '/store/category.jsp', '/store/sitePage.jsp'
  );
  var attrArray = new Array(
   '', '&categoryName=Fiction&categoryDisplayName=Fiction',
   '&categoryName=Nonfiction&categoryDisplayName=Nonfiction',
   '&categoryName=Business&categoryDisplayName=Business',
   '&categoryName=InformationAge&categoryDisplayName=Information+Age',
   '&categoryName=Science&categoryDisplayName=Science',
   '&categoryName=ForeignLanguage&categoryDisplayName=Foreign+Language',
   '&categoryName=Spirituality&categoryDisplayName=Spirituality',
   '&categoryName=Kids&categoryDisplayName=Kids',
   '&categoryName=Comedy&categoryDisplayName=Comedy',
   '&categoryName=History&categoryDisplayName=History',
   '&categoryName=Mystery&categoryDisplayName=Mystery',
   '&categoryName=GreatTalkers&categoryDisplayName=Great+Talkers',
   '&categoryName=DramaPoetry&categoryDisplayName=Drama+and+Poetry',
   '&categoryName=SelfDevelopment&categoryDisplayName=Self+Development',
   '&categoryName=ArtsLeisure&categoryDisplayName=Arts+and+Leisure',
   '&categoryName=News&categoryDisplayName=News',
   '&categoryName=Newspapers&categoryDisplayName=Newspapers',
   '&categoryName=Magazines&categoryDisplayName=Magazines',
   '&categoryName=Radio&categoryDisplayName=Radio',
   '&categoryName=Speeches&categoryDisplayName=Speeches+And+Lectures',
   '&categoryName=Audiobooks&categoryDisplayName=Audiobooks',
   '&Type=RHAU'
 );
 var selectedAttr = document.categoryMovement.moveCat.options[document.categoryMovement.moveCat.selectedIndex].value;
 if(selectedAttr == 0)
  return false;
  else {
    linkThis(pageArray[selectedAttr],attrArray[selectedAttr]);
  }
  return true;
}

if( document.layers ) {
  window.captureEvents( Event.CLICK );
  window.onClick = P_checkClick;
}

if( document.all ) { document.onclick = P_checkClick; }
