//detect IE6
Prototype.Browser.IE6=Prototype.Browser.IE && parseInt(navigator.userAgent.substring (navigator.userAgent.indexOf("MSIE")+5))==6;
	

//==============================================================================
// The onPageLoad() func is called for every page load. It's job is to call functions 
// needed for every page, plus call the VERY SPECIAL _onload() func, which is a
// page-level func that is only defined when a specific page needs onload 
// funtionality.
//==============================================================================
function onLoad() {
}


function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function focus_first_field() {
	var set = false;
	for(i=0; i < document.forms[0].length; i++){
		if (document.forms[0][i].type != "hidden" && document.forms[0][i].disabled != true){
			document.forms[0][i].focus();
			var set = true;
		}
		if (set == true){
			break;
		}
	}
}
function hideshow(id) 
{
    this_box = document.getElementById(id);
    if (this_box.style.display == "none")  {
        this_box.style.display = "";
    } else {
        this_box.style.display = "none";
    }
}

function inspect (o, cont) 
{
	if (!cont) cont = $('inspect');
	if (typeof(o) == 'string') { 
		$(cont).innerHTML = $(cont).innerHTML + "<p>"+ o +"</p>";
	} else {
		$(cont).innerHTML = $(cont).innerHTML + dump(o);
	}
}
function dump(theObj){
  var output = '';
  if(theObj.constructor == Array || theObj.constructor == Object){
    output +="<ul>";
    for(var p in theObj){
      if(theObj[p].constructor == Array|| theObj[p].constructor == Object){
		output += "<li>["+p+"] => "+typeof(theObj)+"</li>";
        output += "<ul>";
        output += dump(theObj[p]);
        output += "</ul>";
      } else {
		output += "<li>["+p+"] => "+theObj[p]+"</li>";
      }
    }
    output +="</ul>";
  }
  return output;
}
function setOrder(field) {
	//get full url for page
	loc	= window.location.href; //string

	//turn query string into an object
	qo	= loc.toQueryParams();	//query obj

	//if not already set, init 
	if (qo.order_by  	   != field ) {
		qo.order_by			= field;
		qo.order_direction	= 'ASC';
	//if so, toggle direction
	} else { 
		if (qo.order_direction == 'DESC') {
			qo.order_direction	= 'ASC';
		} else {
			qo.order_direction	= 'DESC';
		}
	}

	//turn object back into query string to append to url
	qs 	= $H(qo).toQueryString();
	//				  domain name                this is the dir and page         query string
	loc	= "http://" + window.location.hostname + window.location.pathname + "?" + qs;
	
	//go here
	window.location = loc;
}
function downloadNotice (url) { 
	alert(" Your download will begin momentarily. \n You can only download one lesson at a time. \n Once your download is complete you can begin a new download.");
	//alert(url);
	//location.href = "http://google.com";
	location.href = url;
}
