/* Specifies the period of time between updates:
    month - once a month
    date - once per every day of the month (repeats the next month)
    weekday - once per every day of the week (repeats the next week)
    hour - once per hour (repeats the next day)
    request - once per browser request (default)
*/

var updatePeriodsPROD = new Array("month","date","weekday","hour","request")

// Invoked to display rotated HTML content in a Web page. The period
// argument should be an element of the updatePeriods array.

function displayRotatedPROD(periodPROD) {
 var updatePeriodPROD = -1
 for(var PRODi=0;PRODi<PROD.length;++PRODi) {
  if(periodPROD.toLowerCase() == updatePeriodsPROD[PRODi].toLowerCase()) {
   updatePeriodPROD = PRODi
   break
  }
 }
 var sPROD = selectHTMLPROD(updatePeriodPROD)
 document.writeln(sPROD)
}

function selectHTMLPROD(updatePeriodPROD) {
 var nPROD = 0
 var maxPROD = PROD.length
 var dPROD = new Date()
 switch(updatePeriodPROD) {
  case 0: // Month (0 - 11)
   nPROD = dPROD.getMonth()
   break
  case 1: // Date (1 - 31 scaled to 0 - 30)
   nPROD = dPROD.getDate() - 1
   break
  case 2: // Weekday (0 - 6)
   nPROD = dPROD.getDay()
   break
  case 3: // Hour (0 - 23)
   nPROD = dPROD.getHours()
   break
  case 4: // Request (Default)
  default:
   nPROD = selectRandom(maxPROD)
 }
 nPROD %= maxPROD
 return PROD[nPROD+1]
}

// Select a random integer that is between 0 (inclusive) and max (exclusive)
function selectRandomPROD(maxPROD) {
 var rPROD = Math.random()
 rPROD *= maxPROD
 rPROD = parseInt(rPROD)
 if(isNaN(rPROD)) rPROD = 0
 else rPROD %= maxPROD
 return rPROD
}