                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
// 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;
	19 
	 
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/Curzon/' 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/HowgateStable/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,603,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/LordSearchandSelection/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,615,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/michaelpage/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,621,00.gif' 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/kha_resourcing' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,51959,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/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://appointments.timesonline.co.uk/Sites/regent_consulting/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,73233,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/em_group/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,37107,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,,629,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://www.e-m.co.uk/pages/risk_form.asp' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,107045,00.gif' height=44 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+-L209363' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,107043,00.gif' 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+-L209361' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,107042,00.gif' 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+-L209362' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,107044,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/fr_europe' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,114455,00.gif' height=40 width=100></img></a>";
			cellN++;
	    
			dataArray[cellN] = "<a href='http://appointments.timesonline.co.uk/Sites/calcom/' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,114453,00.gif' 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+-L201364' target=_blank><img border=0 src='http://images.thetimes.co.uk/Class/image/high/0,,31262,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;
		
	  for (iRow=0;iRow < numberOfRows; iRow++) {
	   	 oRow=logoTable.insertRow();
		 	for (iCol=0; iCol < noCols; iCol++) {
			 oRow.insertCell();
			 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);
}




