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';
  }  
}

//----- popup Div [start] ------
var popupStatus = 0; //0 means disabled; 1 means enabled;

function loadPopup(popup_box_id){
	if(popupStatus==0){
		$(".popup-background").css({
			"opacity": "0.7"
		});
		$(".popup-background").fadeIn("slow");
		$(popup_box_id).fadeIn("slow");
		popupStatus = 1;	  
    
  	$(".popup-close").click(function(){
  		disablePopup(popup_box_id);
  	});
  	$(".popup-background").click(function(){
  		disablePopup(popup_box_id);
  	});
  	$(document).keypress(function(e){
  		if(e.keyCode==27 && popupStatus==1){
  			disablePopup(popup_box_id);
  		}
  	});
  }
}

function disablePopup(popup_box_id){
	if(popupStatus==1){
		$(".popup-background").fadeOut("slow");
		$(popup_box_id).fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(popup_box_id){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(popup_box_id).height();
	var popupWidth = $(popup_box_id).width();
	$(popup_box_id).css({
		"position": "absolute",
		"top": ( $(window).height() - popupHeight ) / 2+$(window).scrollTop() + "px",
		"left": ( $(window).width() - popupWidth ) / 2+$(window).scrollLeft() + "px"
	});  

	//only need force for IE6	
	$(".popup-background").css({
		"height": windowHeight
	});
	
}

(function($){ 		  
	$.fn.popupWindow = function(instanceSettings){
		
		return this.each(function(){
		
		$(this).click(function(){
		
		$.fn.popupWindow.defaultSettings = {
			centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
			centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
			height:500, // sets the height in pixels of the window.
			left:0, // left position when the window appears.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			width:500, // sets the width in pixels of the window.
			windowName:null, // name of window set from the name attribute of the element that invokes the click
			windowURL:null, // url used for the popup
			top:0, // top position when the window appears.
			toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
		};
		
		settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});
		
		var windowFeatures =    'height=' + settings.height +
								',width=' + settings.width +
								',toolbar=' + settings.toolbar +
								',scrollbars=' + settings.scrollbars +
								',status=' + settings.status + 
								',resizable=' + settings.resizable +
								',location=' + settings.location +
								',menuBar=' + settings.menubar;

				settings.windowName = this.name || settings.windowName;
				settings.windowURL = this.href || settings.windowURL;
				var centeredY,centeredX;
			
				if(settings.centerBrowser){
						
					if ($.browser.msie) {//hacked together for IE browsers
						centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
						centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
					}else{
						centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
						centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
					}
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else if(settings.centerScreen){
					centeredY = (screen.height - settings.height)/2;
					centeredX = (screen.width - settings.width)/2;
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else{
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	
				}
				return false;
			});
			
		});	
	};
})(jQuery);

function confirmEmail(email_id,confirm_id)
{
  if($(email_id).val() > '' && $(confirm_id).val() > ''){
    if($(email_id).val()==$(confirm_id).val()){
      $(confirm_id+'-msg').html('<img src="http://www.smartkiddies.com.au/images/result-assessment-2.gif" alt="ok"> emails are the same');
    }
    else{
      $(confirm_id+'-msg').html('<img src="http://www.smartkiddies.com.au/images/result-assessment-0.gif" alt="fail"> emails are different <br /><span style="color:#404040;font-size:10px;">(click here to recheck)</span>');
    }
    $(confirm_id+'-msg').show();  
  }
}
function emailAvailable(email_id, extra_args)
{
  extra_args = typeof(extra_args) != 'undefined' ? extra_args : '';
  var data_string = 'email='+encodeURIComponent($(email_id).val())+'&sk=1&email_id='+encodeURIComponent(email_id)+extra_args;
  $.ajax({
    type: "GET",
    url: "http://www.studyladder.com/user/email-check",
    data: data_string,   
    dataType:'script',
    success: function(data) {  
    }
  });
}
function usernameAvailable(username_id, extra_args)
{
  extra_args = typeof(extra_args) != 'undefined' ? extra_args : '';
  var data_string = 'username='+encodeURIComponent($(username_id).val())+'&username_id='+encodeURIComponent(username_id)+extra_args;
  $.ajax({
    type: "GET",
    url: "http://www.studyladder.com/user/username-check",
    data: data_string,   
    dataType:'script',
    success: function(data) {  
    }
  });
}
