// Scramble function, takes parameter of number of logos to display,
// retrieves them from the database, mixes them up and returns
// the table


function scrambleLogos (numberOfCells,logoRows,logoCols) {

  var numberOfCells, numberOfRows, noCols, nIndex, nRnd, arrCount,bFound, iRow, iCol,tmpCells, arr;
 
   //swap cells around
  
  numberOfRows = logoRows;
  noCols = logoCols;
  
  // select logos from table
 
  //build up array of all cell values
	dataArray = new Array();
	cellN=0;
	15 
	 
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/curzon_partnership' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,573,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/howgatesable/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,240365,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/PSD/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,83527,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/odgers/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,479303,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/metzger/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,84322,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/barnaby_stewart/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,20592,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/whealethomashodgins_1/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,232834,00.jpg' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://jobs.timesonline.co.uk/cgi-bin/appSrch?-aSTART+-pAPP+-nALL+-c+-s%20+-i1-Y1+-L228641' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,382479,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/mercuri_new/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,820,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://jobs.timesonline.co.uk/Jobs/Jobs.aspx?liCompanyID=200080' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,412189,00.jpg' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/aquista/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,33612,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/the_academy_of_business_strategy/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,123916,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://jobs.timesonline.co.uk/Jobs/Jobs.aspx?liCompanyID=245406' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,430108,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/tribal/site/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,443095,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/adderley_featherstone/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,534197,00.gif' height=40 width=100></img></a>";
			cellN++;
	      //build up random number array based on number of logos 
    nIndex=0;
	if (cellN <= 1) {
		arr = new Array(cellN);
	} else {
		arr =new Array(cellN-1);
	}
	for (nIndex=0; nIndex < cellN; nIndex++) {
      bFound=1;
	  while (bFound == 1) {
	  	bFound=0;
		if (cellN <= 1) {
			nRnd=0;
		} else {
			nRnd=getRandomNum(cellN-1);
		}
		//check number not already in array
		for (arrCount=nIndex; arrCount >= 0; arrCount-- ) {
			if (arr[arrCount]==nRnd) {
				bFound=1;
			}  
		} 
	 }
    
	 arr[nIndex] = nRnd;
   }
  
	
		
	//assign values to new array in random fashion
	if (cellN <= 1) {
		tmpCells=new Array(cellN);
	} else {
    	tmpCells= new Array(cellN-1);
	}
	nIndex=0;
	for (x=0;x < cellN; x++) {
		tmpCells[x] = dataArray[arr[nIndex]];
		nIndex++;
			
	}

    
	//assign values to table cells
	x=0;
    logoTab = document.getElementById("logoTable");
		
	  for (iRow=0;iRow < numberOfRows; iRow++) {
	   	 oRow=logoTab.insertRow(-1);
		 	for (iCol=0; iCol < noCols; iCol++) {
			 oRow.insertCell(-1);
			 if (x < cellN ) {
				oRow.cells[iCol].innerHTML = tmpCells[x];
				//logoBody.rows[iRow].cells[iCol].innerHTML = tmpCells[x];
				x++;
			 } else {
			 	break;
			 }
		}
	 }	
	 }


// Random number generator , used to randomly fill an array with logos 

function getRandomNum(maxValue) {
	//Create new instance of date
	var now=new Date();
	
	//Create a random number
	var randNum = now.getTime() * now.getSeconds() * Math.random();
	
	//Cut random number to an integer to an integer value between 0 and maxValue
	return Math.round(randNum % maxValue);
}




