// This variation of the script introduces a queue system for the mySimpleAds loader
// which is useful if you have more than one ad zone div on the page and you are
// loading banners into them remotely using the mysa_loadad function
// -------------------------------------------------
// Usage: Instead of calling the mysa_loadad(mysa_url,mysa_id) function, call
// the mysa_queue_loadad function(mysa_url,mysa_id,mysa_append).
// Then, call the mysa_queue_execute() function in your body onLoad.
// -------------------------------------------------
// If you pass the mysa_append variable as "append", instead of
// overwriting what's in the div, it will append the new data.
// -------------------------------------------------
// Script will also turn the display of a div to block if it was previously none.
// -------------------------------------------------
// Coded by Thomas Chapin at Tornado Design (http://www.tornadodesign.com)
// Email: tom@tornadodesign.com
// Date: 03/26/2007
// Version: 0.2
// -------------------------------------------------

var mysa_xmlhttp,mysa_gid,mysa_gurl,mysa_gappend
var mysa_gid_queue_array = new Array()
var mysa_gurl_queue_array = new Array()
var mysa_gappend_queue_array = new Array()
var tmpalert=0;

function mysa_loadad(mysa_url,mysa_id,mysa_append)
{
if ((mysa_gid==null) && (mysa_id!="")){mysa_gid=mysa_id}
if ((mysa_gurl==null) && (mysa_url!="")){mysa_gurl=mysa_url}
if ((mysa_gappend==null) && (mysa_append!="")){mysa_gappend=mysa_append}

// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  mysa_xmlhttp=new XMLHttpRequest()
  mysa_xmlhttp.onreadystatechange=mysa_state_Change
  mysa_xmlhttp.open("GET",mysa_gurl,true)
  mysa_xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  mysa_xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (mysa_xmlhttp)
    {
    mysa_xmlhttp.onreadystatechange=mysa_state_Change
	
    mysa_xmlhttp.open("GET",mysa_gurl+"&t="+(new Date()).getTime(),true)
    mysa_xmlhttp.send()
    }
  }
}
function mysa_state_Change()
{
// if xmlhttp shows "loaded"
if (mysa_xmlhttp.readyState==4) {
  // if "OK"
  if (mysa_xmlhttp.status==200) {
	  if(mysa_gappend == "append" || mysa_gappend == "true" || mysa_gappend == true || mysa_gappend == "yes" || mysa_gappend == "1" || mysa_gappend == 1)
	  {
		// append the new info
  		document.getElementById(mysa_gid).innerHTML=document.getElementById(mysa_gid).innerHTML+mysa_xmlhttp.responseText
	  }else{
		// overwrite with the new info
  		document.getElementById(mysa_gid).innerHTML=mysa_xmlhttp.responseText
	  }
	// make the div visible if it's hidden and if the innerHTML contains anything
	if(document.getElementById(mysa_gid).innerHTML.length>0) {
		document.getElementById(mysa_gid).style.display="block"
	}
  }
  // load the next item in the queue
  mysa_queue_execute()
}
}
function mysa_rotate(mysa_url,mysa_id,mysa_interval)
{
mysa_gid=mysa_id
mysa_gurl=mysa_url
mysa_loadad_rotate()
setInterval(mysa_loadad_rotate,mysa_interval);
}
function mysa_loadad_rotate(){
mysa_loadad(mysa_gurl,mysa_gid)
}

// Function used to queue loadad commands
function mysa_queue_loadad(mysa_url,mysa_id,mysa_append){
	mysa_gurl_queue_array.push(mysa_url)
	mysa_gid_queue_array.push(mysa_id)
	mysa_gappend_queue_array.push(mysa_append)
}

// Function used to run the commands in the queue
function mysa_queue_execute(){
	if(mysa_gurl_queue_array.length>0 && mysa_gid_queue_array.length>0)
	{
		// reverse the arrays (so we can get the first item)
		mysa_gurl_queue_array.reverse()
		mysa_gid_queue_array.reverse()
		mysa_gappend_queue_array.reverse()
		// get the last items in the queue
		mysa_gurl=mysa_gurl_queue_array.pop()
		mysa_gid=mysa_gid_queue_array.pop()
		mysa_gappend=mysa_gappend_queue_array.pop()
		// reverse the arrays back again
		mysa_gurl_queue_array.reverse()
		mysa_gid_queue_array.reverse()
		mysa_gappend_queue_array.reverse()
		// load the ad
		mysa_loadad(mysa_gurl,mysa_gid,mysa_gappend)
	}
}