function openDiv(divID)
{
  if(document.getElementById(divID).style.display=='block'){
    document.getElementById(divID).style.display='none';
    document.getElementById(divID+'-span').innerHTML='click to open +';
    
  }
  else{
    document.getElementById(divID).style.display='block';
    document.getElementById(divID+'-span').innerHTML='click to close -';
  }
}

function CreateBookmarkLink(title,url) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
    
    
}
function checkAll(controlObj,fieldName)
{
  checkField = false;
  if(controlObj.checked)
    checkField = true;
  for(i=0;i<100;i++){
    if(document.getElementById(fieldName+'['+i+']'))
      document.getElementById(fieldName+'['+i+']').checked = checkField;
    else
      break;
  }    
}
function checkAllTwoWay(controlObj,fieldNamePre, fieldNameApp)
{
  checkField = false;
  if(controlObj.checked)
    checkField = true;
  for(i=0;i<100;i++){
    if(document.getElementById(fieldNamePre+'['+i+']'+fieldNameApp))
      document.getElementById(fieldNamePre+'['+i+']'+fieldNameApp).checked = checkField;
    else
      break;
  }    
}

function PopUpWindow(imgURL) {
  var width = 640;
  var height = 480;
  if (screen.width > 800) {
      width = 800;
      height = 600;
  }
  if (screen.width > 900) {
      width = 900;
      height = 600;
  }
  if (screen.width > 1000) {
      width = 1000;
      height = 600;
  }
  //bypass norton internet security popup blocker
  if (typeof SymRealWinOpen != 'undefined') {
      if(navigator.appVersion.indexOf("MSIE")!=-1) { /* ie */
          window.open = SymRealWinOpen;
      } else {
          alert('Norton Internet Security may block this popup.\nPlease disable your popup blocker if you experience any problems.');
      }
  }
  // pop appropriately sized window
  if (screen.width > 800)
      w=window.open(imgURL,'PopUpWindow','menubar=no,toolbar=no,status=no,width='+(width+60)+',height='+(height+150)+',resizable=yes,scrollbars=yes');
  else
      w=window.open(imgURL,'PopUpWindow','menubar=no,toolbar=no,status=no,width='+(width+40)+',height='+(height+120)+',resizable=yes,scrollbars=yes');
  w.focus();
} 
function PopUpWindowCustom(imgURL,width,height) {
  //bypass norton internet security popup blocker
  if (typeof SymRealWinOpen != 'undefined') {
      if(navigator.appVersion.indexOf("MSIE")!=-1) { /* ie */
          window.open = SymRealWinOpen;
      } else {
          alert('Norton Internet Security may block this popup.\nPlease disable your popup blocker if you experience any problems.');
      }
  }
  // pop appropriately sized window
  if (screen.width > 800)
      w=window.open(imgURL,'PopUpWindow','menubar=no,toolbar=no,status=no,width='+(width+60)+',height='+(height+150)+',resizable=yes,scrollbars=yes');
  else
      w=window.open(imgURL,'PopUpWindow','menubar=no,toolbar=no,status=no,width='+(width+40)+',height='+(height+120)+',resizable=yes,scrollbars=yes');
  w.focus();
} 
var linkObjFirstChildF;
function AddMyFavourites(lessonID, linkObj)
{
  linkObjFirstChildF = linkObj.firstChild;
  doRemoteQuery('/teachersfavourites/addmyfavourites?lid='+lessonID);
}
var linkObjFirstChildC;
function AddClassView(lessonID, linkObj)
{
  linkObjFirstChildC = linkObj.firstChild;
  doRemoteQuery('/teachersfavourites/addclassview?lid='+lessonID);
}


var xmlHttp;
var searching = false;
function doRemoteQuery (lookupURL)
{
  searching = true;
  if(xmlHttp && xmlHttp.readyState != 0) {
    xmlHttp.abort()
  }    
  xmlHttp=getXMLHTTP();
  if(xmlHttp){
    xmlHttp.open("GET", lookupURL, true);
              
    xmlHttp.onreadystatechange = function() { 
      if (xmlHttp.readyState == 4 && xmlHttp.responseText && searching) {
        eval(xmlHttp.responseText);
        searching = false;
      }
    }
    ;      
    xmlHttp.send(null);
  }    
}
function getXMLHTTP(){
  var A = null;
  
  try{
    A = new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
    try{
      A = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(oc){
      A = null;
    }
  }
  
  if(!A && typeof XMLHttpRequest != "undefined") {
    A = new XMLHttpRequest();
  }
  
  return A;
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function addUnloadEvent(func) {
  var oldunload = window.onunload;
  if (typeof window.onunload != 'function') {
    window.onunload = func;
  } else {
    window.onunload = function() {
      if (oldonunload) {
        oldonunload();
      }
      func();
    }
  }
}

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
var mouseOnTarget = false;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX+10) + "px";
d.style.top = (cY+10) + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(mouseOnTarget != true){ return; }
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}
function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function correctCounter()
{
  counterSpan = document.getElementById('correct-counter');
  counterSpan.innerHTML = (parseInt(counterSpan.innerHTML)+rand(20))
  window.setTimeout("correctCounter()",1000)  
}
function memberCounter()
{
  counterSpan = document.getElementById('member-counter');
  counterSpan.innerHTML = (parseInt(counterSpan.innerHTML)+rand(5))
  window.setTimeout("memberCounter()",20000)  
}
var lastMoveNeg = true;
function onlineCounter()
{
  counterSpan = document.getElementById('online-counter');
  if(lastMoveNeg){
    counterSpan.innerHTML = (parseInt(counterSpan.innerHTML)+rand(50))
    lastMoveNeg = false;
  }
  else{
    counterSpan.innerHTML = (parseInt(counterSpan.innerHTML)-rand(50))
    lastMoveNeg = true;
  }
  window.setTimeout("onlineCounter()",3000)  
}

function updateEmailCheck(fieldName)
{
  if(document.getElementById(fieldName).value == document.getElementById('check-email').value){
    document.getElementById('email-check-result').innerHTML = '<img src="http://www.smartkiddies.com.au/images/result-assessment-2.gif" alt="ok"> emails are the same';
  }
  else{
    document.getElementById('email-check-result').innerHTML = '<img src="http://www.smartkiddies.com.au/images/result-assessment-0.gif" alt="fail"> emails are differnt';
  }  
}