/* 

  $Revision: #3 $
  
  Copyright (c) 2006 Amazon.com, Inc.  All rights reserved.

  This component contain javascript functions related to Product Detail Section in detail
  page.
  
  The function present in this component are :

  function changeDetailPageTab(imgIndex, tabCount) : This function is changing images dynamically 
  in tab section.

  function suppressImageTab(tabCount) : This function is suppressing the Image Tab, if there is no Large Image 
  available in product directory for selected ASIN

  function changeSeeMoreInfoImage(imgIndex, tabCount) : This function is collapsing the link " See more information"
  if all the information available fits within the tab section.

  function printTab() : This function is doing browser print in tab pop up

  function openDetailPageTab() : This function create the dynamic URL by adding arguments in string query
  and open product detail section tab pop up

*/
  function setTabFocus(e, tabName) {
    var key;
    if (window.event) key = e.keyCode;
    if (e.which) key = e.which;
    if (key != 13) return;
    changeDetailPageTab(tabName);
  }

function openDetailTabPopup(url) {
       
    window_handle = window.open(url,'ProductDetail',"location=0,menubar=0,resizable=no,height=550,width=600,scrollbars=yes,left=220,screenX=220,top=70,screenY=70"
                              );
    if( window_handle ){
        window_handle.focus();
    }
  } 
 
 





function promotionDetailsPopup(mylink, choice) {

  if (! window.focus) return true;
  var href;
  if (typeof(mylink) == 'string')
    href=mylink;
  else
    href=mylink.href;
    
  href+='?choice='+choice;
  window.open(href, 'OfferDetailsPopUp', 'location=0,menubar=0,resizable=no,height=600,width=295,scrollbars=yes,left=220,screenX=220,top=70,screenY=70');
  return false;
}


function openHolidayPopUp() {
  var h;
  h = window.open('/gp/redirect.html?location=http://www.target.com/gp/browse.html?node=3003591', '', 'location=0,menubar=0,resizable=no,width=579,height=510,scrollbars=yes,left=20,screenX=20,top=20,screenY=20');
  if( h ){
      h.focus();
  }
}




/******************************************************************************************************/

 function changeDetailPageTab1(tabName) {

    for (var i in tabArray1) {
    
      var tabObj = tabArray1[i];
      
      if (tabObj == null)
        continue;
        
      // set the tab image to 'on' or 'off'
      var tab = document.getElementById('tab_' + tabObj.name);
      if (tab != null){
        tab.type = "image";
        if (tabObj.name == tabName)
          tab.src = tabObj.onImg;
        else
          tab.src = tabObj.offImg;
      }
      // show this tab, hide all others
      var div = document.getElementById('div_' + tabObj.name);
      if (div != null)
        if (tabObj.name == tabName) 
          div.style.display = "block";
        else
          div.style.display = "none";
      // Turn the accessibility images off.
       var div2 = document.getElementById('access_' + tabObj.name);
       if (div2 != null) 
          div2.style.display = "none";
  
    } // foreach tab

    // remeber which tab is selected
    selectedDetailTabName = tabName;
   
    // Handle accessibility text.
    var access = document.getElementById('ddiv');
    var text = "There are " + tabArray.length + " buttons in the Next Model section, to make the tab readable click it and navigate past the buttons. The currently selected tab is " + tabName + ".";
    access.innerHTML = text;
 
    // hide or display the "see more info" link
    var moreInfoLink = document.getElementById('moreInfoLink');
    if (moreInfoLink != null) {
      if (tabObj.enableMoreInfoLink)
        moreInfoLink.style.display = "block";
      else
        moreInfoLink.style.display = "none";
    }
    

  }



/*****************************************************************************************************/

function change_img(source)
{
	if(document.all)
	 {
	  var obj=document.all.mainimg;
	 }
	 
	else if(document.getElementById)
	 {
		 var obj=document.getElementById('mainimg');
	 }
	 
	obj.src=source;
}




  var selectedDetailTabName;
  function changeDetailPageTab(tabName) {
    for (var i in tabArray) {
      var tabObj = tabArray[i];
      if (tabObj == null)
        continue;
      // set the tab image to 'on' or 'off'
      var tab = document.getElementById('tab_' + tabObj.name);
      if (tab != null){
        tab.type = "image";
        if (tabObj.name == tabName)
          tab.src = tabObj.onImg;
        else
          tab.src = tabObj.offImg;
      }
      // show this tab, hide all others
      var div = document.getElementById('div_' + tabObj.name);
      if (div != null)
        if (tabObj.name == tabName) 
          div.style.display = "block";
        else
          div.style.display = "none";
      // Turn the accessibility images off.
       var div2 = document.getElementById('access_' + tabObj.name);
       if (div2 != null) 
          div2.style.display = "none";
    } // foreach tab
    // remeber which tab is selected
    selectedDetailTabName = tabName;
    // hide or display the "see more info" link
    var moreInfoLink = document.getElementById('moreInfoLink');
    if (moreInfoLink != null) {
      if (tabObj.enableMoreInfoLink)
        moreInfoLink.style.display = "block";
      else
        moreInfoLink.style.display = "none";
    }
  }



function openDetailTabPopup(url) {
window_handle = window.open(url,'ProductDetail',"location=0,menubar=0,resizable=no,height=550,width=600,scrollbars=yes,left=220,screenX=220,top=70,screenY=70");
    if( window_handle ){
        window_handle.focus();
    }
  }


/***********************************************************************************************/
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
/********************************************************************************************************/