/*
Author: Emir Plicanic
Title: AJAX engine
Email: emir.plicanic@nelnet.net
*/

function getContent(page, elementid){
//params has to have following format
//i.e.: c=1&id=3....
//page is the server side script. include full path 
//i.e. ../scripts/myscript.php


//Clear our fetching variable
var xmlhttp=false; 
//Try to create active x object
try {
    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); 
    } catch (e) {
    try {
         xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); 
    } catch (E) {
         xmlhttp = false;
    }
 }
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
     xmlhttp = new XMLHttpRequest();
 }

//This is the path to the PHP file on the server
var file = page;

//Open the file through GET, and add the page we want to retrieve as a GET variable
xmlhttp.open('GET', file, true);     

xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState == 1){
 
//Display waiting image and message while content loads. 
//Make sure you have the corect path for the image 
//document.getElementById(elementid).innerHTML = "" ;

   //Check if it is ready to recieve data 
   }else if(xmlhttp.readyState==4) { 
   //Make sure there is something in the content variable
   var content = xmlhttp.responseText; 

      //The content data which has been retrieved
      if( content ){   
      //Change the inner content of your div to the newly retrieved content
      document.getElementById(elementid).innerHTML = content;    
      }
   }
}
//Nullify the XMLHttpRequest
xmlhttp.send(null) 
return;

}

function alternate(id){ 
 if(document.getElementsByTagName){  
   var table = document.getElementById(id);   
   var rows = table.getElementsByTagName("tr");   
   for(i = 0; i < rows.length; i++){           
 //manipulate rows 
     if(i % 2 == 0){ 
       rows[i].className = "even"; 
     }else{ 
       rows[i].className = "odd"; 
     }       
   } 
 } 
}

Array.prototype.shuffle = function() {
  for (var i = 0; i < this.length; i++) {
    // Random item in this array.
    var r = parseInt(Math.random() * this.length);
    var obj = this[r];
 
    // Swap.
    this[r] = this[i];
    this[i] = obj;
  }
}
function randomize(tableID) {
	var myTable = document.getElementById(tableID);
	var myRows = new Array();
	for (i=myTable.rows.length-1; i>=1; i--) {
		var theRow = myTable.rows[i];
		myRows.push(theRow);
		theRow.parentNode.removeChild(theRow);
	}
	myRows.shuffle();
	for (j=0; j<myRows.length; j++) {
		var newTbody = document.createElement("tbody");
		newTbody.appendChild(myRows[j]);
		myTable.appendChild(newTbody);
	}
}
//uncomment and give a table you want to rotate an id "randomtable"
window.onload = function() {
	randomize("randomtable");
}