function displayDirDecode(imgNumInput,returnType) {
   result = new Array()
   if ( isNaN(imgNumInput) == true ) { 
      dirCode = imgNumInput.substr(0,2) ; 
      for ( aM=0; aM<dirDecodeDB.length; aM++ ) {
         if ( dirDecodeDB[aM][0] == dirCode ) { result = dirDecodeDB[aM] ; break ;}
      }
   }
   else { result = dirDecodeDB[imgNumInput] ; }
   
   if ( returnType == "dirCode" ) { return ( result[0] ); }
   else if ( returnType == "dir" ) { return ( result[1] ); }
   else if ( returnType == "page" ) { return ( result[2] ); }
   else if ( returnType == "galleryIndex" ) { return ( result[3] ); }
   else if ( returnType == "numTopRightImgs" ) { return ( result[4] ); }
   else if ( returnType == "noTopRightText" ) { 
      if (result[4] < 1) { databaseNoTopRightText = true ; }
      else { databaseNoTopRightText = false ; }
   }
}




function displayURL(linkk,img) {
      if (linkk == "std") { return ( 'photos/display.php?imgNum=' + img ) ; }
      else { return linkk ; }
}





function displayImagePage(img,type) {
    if ( type != undefined && type == "cardSet" ) {
       window.location = ( displayBaseURL + "products/cards/cardsetdisplay.php?" + img ) ;
    }
    else if ( type != undefined && type == "scrSaver" ) {
       window.location = ( displayBaseURL + "products/screensavers/ssimagedisplay.php?ssID=" + img ) ;
    }
    else {
       window.location = ( displayBaseURL + "photos/display.php?imgNum=" + img ) ;
    }
}



function displayGallFirstRow(gallData) {
    databaseSplitGallery( gallData ) ;
    displayFirstRow( databaseRegExpResult1[1],databaseRegExpResult2[1],"std" ) ;
}


function displayGallRow(gallData) {
    databaseSplitGallery( gallData ) ;
    if ( databaseRegExpResult1[1].length == 1 ) {
       displayImageRow( databaseRegExpResult1[1],databaseRegExpResult2[1],"std" ) ; }
    else if ( databaseRegExpResult1[1].length == 2 ) {
       displayImageRow( databaseRegExpResult1[1],databaseRegExpResult2[1],"std",databaseRegExpResult4[1],"std" ) ; }
    else { displayImageRow( databaseRegExpResult1[1],databaseRegExpResult2[1],"std",databaseRegExpResult3[1],"std",databaseRegExpResult4[1],"std" ) ; }
}




//I think this can be deleted 11/8/08
function displayCardSetLink(topRightImg) {
   if ( !cartRetailerTest() ) {
      var galleryInd = displayDirDecode(topRightImg,"galleryIndex") ;
      try {
         if ( dirDecodeDB[galleryInd][5][0] ) {
            document.write( "<DIV ALIGN=CENTER STYLE=\"margin-top: 12px\"><A HREF=\"javascript:displayImagePage('" + displayDirDecode(topRightImg,"dirCode") + "','cardSet');\" CLASS=faqHeadnb>" + displayDirDecode(topRightImg,"page") + " Note Card Sets</A></DIV>" ) ;
         }
      }
      catch(err) {}
   }
}





function displayIdentifyOS() {
   info = new String(navigator.platform) ;
   if ( info.search(/Win/i) ) { return "Windows" ;}
   else if ( info.search(/Mac/i) ) { return "Mac" ;}
   else { return "unknown" ;}
}





function displayViewBookmarks() {
   if (document.getElementById("bmLocation").value != "none") {
      window.location=( displayBaseURL + 'products/bookmarks/bookmarkdisplay.php?' + document.getElementById("bmLocation").value ) ;
   }
   else { alert("Please select a location from the drop-down menu first.") ; }
}




function displayTimeDelay(varName,action,delay) {
   reFunction = new RegExp ( "[\(\)]" , "g" ) ;
   if ( !reFunction.test(action) ) { action = "cartLaunchChoice('" + action + "')"; }
   var varName = setTimeout(action,delay)
}

function displayStopTimeDelay(varName) {
   clearTimeout(varName)
}



function displayBrowserWinDim(HeightOrWidth) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth; myHeight = window.innerHeight; }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; }
  else { myWidth = 0; myHeight = 0; }
    
  if (HeightOrWidth == "width") { return myWidth; }
  else if (HeightOrWidth == "height") { return myHeight; }
}



function displayToggleBox(divID, iState) // iState=1 visible, 0 hidden
{
    if(document.getElementById) { //gecko(NN6) + IE 5+
        document.getElementById(divID).style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.layers) { //NN4+
       document.layers[divID].visibility = iState ? "show" : "hide";
    }
    else if(document.all) { //IE 4
        document.all[divID].style.visibility = iState ? "visible" : "hidden";
    }
}


function displayToggleBoxInline(divID) {
   if (document.getElementById) {  // this is the way the standards work
      var style2 = document.getElementById(divID).style;
      style2.display = style2.display? "":"block";
   }
   else if (document.all) { // this is the way old msie versions work
      var style2 = document.all[divID].style;
      style2.display = style2.display? "":"block"; 
   }
   else if (document.layers) { // this is the way nn4 works
      var style2 = document.layers[divID].style;
      style2.display = style2.display? "":"block";
   }
}








displayFaderArray = new Array();
fadeCounterImgSize = 0 ; fadeCounterStart = 2 ; fadeCounterRestart = 1 ; // reflect places in displayFaderArray
var fadeCounter0 = fadeCounterStart; var fadeCounter1 = fadeCounterStart; var fadeCounter2 = fadeCounterStart; var fadeCounter3 = fadeCounterStart; var fadeCounter4 = fadeCounterStart; var fadeCounter5 = fadeCounterStart; var fadeCounter6 = fadeCounterStart;

function faderControl(faderInterval) {
   for ( fadeArrayNum=0 ; fadeArrayNum < displayFaderArray.length ; fadeArrayNum++ ) {
      newImg = displayFaderArray[fadeArrayNum][fadeCounterRestart] ;
      document.getElementById("image"+fadeArrayNum+"B").src = "photos/" + displayDirDecode(newImg,'dir') + "/" + databaseFind2(newImg,0,1) + displayFaderArray[fadeArrayNum][fadeCounterImgSize] + ".jpg" ;
      document.getElementById("link"+fadeArrayNum+"B").href = ("photos/display.php?imgNum=" + newImg ) ;
      document.getElementById("label"+fadeArrayNum+"B").innerHTML = databaseFind2(newImg,0,3) + "<BR>" + databaseFind2(newImg,0,4) ;
   }

   startAllFades(faderInterval);
   setInterval ( "startAllFades('" + faderInterval + "');", faderInterval);
}


function startAllFades(faderInterval) {
   var timeStep = Math.floor(faderInterval/displayFaderArray.length); 
   var timeDelay=0; 
   for ( fadeArrayNum=0 ; fadeArrayNum < displayFaderArray.length ; fadeArrayNum++ ) {
      setTimeout ( "startFade( '" + fadeArrayNum + "' , '" + displayFaderArray[fadeArrayNum][fadeCounterImgSize] + "' );", timeDelay );
      timeDelay+=timeStep;
   }
}


function startFade(divIDCode,imgSize) {
   //divIDCode is just the NUMBER from "frame1A" , "label1B" , etc., in this example, "1"
   
   eval( "fadeCounter=fadeCounter" + divIDCode ) ; 
   newImg = displayFaderArray[divIDCode][fadeCounter] ;
   
   if ( document.getElementById("frame"+divIDCode+"A").style.zIndex > document.getElementById("frame"+divIDCode+"B").style.zIndex ) { var fadedinDivID = (divIDCode+"A"); var fadedoutDivID = (divIDCode+"B"); }
   else { var fadedinDivID = (divIDCode+"B"); var fadedoutDivID = (divIDCode+"A"); }
   
   document.getElementById("image"+fadedoutDivID).src = "photos/" + displayDirDecode(newImg,'dir') + "/" + databaseFind2(newImg,0,1) + imgSize + ".jpg" ;

   document.getElementById("frame"+fadedoutDivID).style.zIndex = 20 ; //puts faded out div on top
   document.getElementById("frame"+fadedinDivID).style.zIndex = 10 ;
   document.getElementById("link"+fadedoutDivID).href = "" ;
   document.getElementById("label"+fadedoutDivID).innerHTML = ( "<NOBR>" + databaseFind2(newImg,0,3) + "</NOBR><BR><NOBR>" + databaseFind2(newImg,0,4) + "</NOBR>");

   FadeOpacity(("frame"+fadedoutDivID),0,100,1000,10,newImg) ;
   
   fadeCounter++;
   if (fadeCounter==displayFaderArray[divIDCode].length) { fadeCounter = fadeCounterRestart ; } // resets to beginning after 6th image
   eval( "fadeCounter" + divIDCode + "=fadeCounter" ) ;
}



//borrowed from http://www.akxl.net/labs/articles/use-javascript-to-change-or-fade-opacity-or-transparency-of-html-entities/
function SetOpacity(elem, opacityAsInt) {
   var opacityAsDecimal = opacityAsInt;

   if (opacityAsInt > 100) {
      opacityAsInt = opacityAsDecimal = 100; 
   }
   else if (opacityAsInt < 0) {
      opacityAsInt = opacityAsDecimal = 0; 
   }

   opacityAsDecimal /= 100;
   if (opacityAsInt < 1) {
      opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
   }

   elem.style.opacity = (opacityAsDecimal);
   elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}


function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps, newImg) { //time is the total length of the fade effect
   var steps = Math.ceil(fps * (time / 1000));
   var delta = (toOpacity - fromOpacity) / steps;

   FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps), newImg);
}


function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep, newImg) {
   SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

   if ( stepNum == 3 ) {
      fadedoutDivID = elemId.match("\\d\\w") ;
      
      if (elemId.charAt(6) == "A") { fadedinDivID = elemId.charAt(5) + "B"; }
      else { fadedinDivID = elemId.charAt(5) + "A"; }
      document.getElementById("link"+fadedoutDivID).href = ("photos/display.php?imgNum=" + newImg ) ;
      document.getElementById("label"+fadedoutDivID).innerHTML = ("<NOBR>" + databaseFind2(newImg,0,3) + "</NOBR><BR><NOBR>" + databaseFind2(newImg,0,4) + "</NOBR>");
      document.getElementById("label"+fadedinDivID).innerHTML="&nbsp;<BR>&nbsp;";
   }

   if (stepNum < steps) {
      setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ", '" + newImg + "');", timePerStep);
   }
}