//
// support code for HGSE Usable Knowledge site
//

// Dreamweaver functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//
// set font size
// sets the font size style on the body tag
//
var fontsizes = new Array("100%", "100%", "125%");
function setfontsize(n) {
  document.body.style.fontSize = fontsizes[n];
  set_cookie("fontsize", n);
}

//
// initialize font size
// sets the initial font size
//
function initfontsize() {
  setfontsize(get_cookie("fontsize", 1));
}

///
/// cookies
///
// get cookie value
//
function get_cookie(cookiename, defaultvalue) {
  var ret = defaultvalue;
  var cookies = document.cookie.split(';');
  for (i = 0; i < cookies.length; i++) {
    if (cookies[i].indexOf(cookiename) > -1) { // found in cookie
      cookieparts = cookies[i].split('=')
      if (typeof cookieparts[1] != 'undefined')
        ret = unescape(cookieparts[1]);
      break;
    }
  }
  return ret;
}
// set cookie value
//
function set_cookie(cookiename, value) {
  //var expire = new Date ();
  //expire.setTime (expire.getTime() + (10*365*24*60*60*1000)); //expires in 10 years
  //expire = '; expires='+expire.toGMTString();
  var expire = ''; // let it expire when browser closes
  var str = cookiename+'='+escape(value)+'; path=/'+expire;
  document.cookie = str;
}


//
// open link in popup window
//
function popup(x) {
  var w = window.open(x.href, '', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=650,height=450,left = 440,top = 225');
  return false;
}

function emailpage() {
  window.location.href = "mailto:" + " ?subject=Recommended article from HGSE Usable Knowledge site&body=I recommend this article from Harvard Graduate School of Education's Usable Knowledge web site. Here is the link:%0A%0A" + window.location  + "%0A%0A";
  return false;
}


//
// Open/close content
// This function assumes the following:
// -The object calling this function is inside another element with class="open" or class="closed"
// This function looks for the first containing element with either of those classes,
// and changes it to the other class (in other words, it acts like a toggle). The rest must be done by CSS.
//
function togglecontent(obj) {
  if (typeof obj.className != 'undefined') {
    if (obj.className == 'open') {
      obj.className = 'closed';
      return;
    }
    else if (obj.className == 'closed') {
      obj.className = 'open';
      return;
    }
    else if (typeof obj.parentNode != 'undefined') {
      togglecontent(obj.parentNode);
    }
  }
}
// these two functions ONLY open or close
function opencontent(obj) {
  if (typeof obj.className != 'undefined') {
    if (obj.className == 'open') {
      // already open, so stop here
      return;
    }
    else if (obj.className == 'closed') {
      obj.className = 'open';
      return;
    }
    else if (typeof obj.parentNode != 'undefined') {
      opencontent(obj.parentNode);
    }
  }
}
function closecontent(obj) {
  if (typeof obj.className != 'undefined') {
    if (obj.className == 'open') {
      obj.className = 'closed';
      return;
    }
    else if (obj.className == 'closed') {
      // already closed, so stop here
      return;
    }
    else if (typeof obj.parentNode != 'undefined') {
      closecontent(obj.parentNode);
    }
  }
}


function open_win()
{
window.open("http://www.w3schools.com","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
}