/*
 * default.js
 *
 * contains scripting for continentalline.org
 *
 * history:
 *    22 feb 05: file created - sjr
 *    11 mar 05: file updated - sjr
 *
 */

var openQuestion = "";     // open question number (if any)

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  if (myWidth < 750) {
    //window.alert('Width less than 750');
    document.getElementById("rightnav").style.display ="none";
    //document.getElementById("strapline").style.display ="none";
  }
}

function getOpenYear() {

  //Cookies for Newsletter opening from breadcrumb path
  var openYear = getCookie( 'breadcrumb' ); // if the user is returning to the site in the same
  if (openYear != "null") {    // 
    showQuestion( openYear );
    setCookie('breadcrumb', null, null, "/");
  }
}

function showYear( ID ) { // function setting cookie for Newsletter opening
      setCookie("breadcrumb", ID, null, "/");
      location.href ="/en/newsletter.html#"+ ID;
}

function showQuestion( ID ) {
   
   if( openQuestion == "" ) {
      document.getElementById( "qa" + ID ).style.background = "transparent";
      document.getElementById(  "a" + ID ).style.display = "block";
      openQuestion = ID;
      return;
   }

   if( openQuestion == ID ) {            
      if( document.getElementById( "a" + ID ).style.display == "block" ) {
         document.getElementById( "a" + ID ).style.display = "none";
         document.getElementById( "qa" + ID ).style.background = "transparent";
         openQuestion = "";
      } else {
         document.getElementById( "a" + ID ).style.display = "block";
         document.getElementById( "qa" + ID ).style.background = "transparent";
         openQuestion = ID;
      }
      return;
   }

   document.getElementById( "qa" + openQuestion ).style.background = "transparent";
   document.getElementById( "a" + openQuestion ).style.display = "none";

   document.getElementById( "a" + ID ).style.display = "block";
   document.getElementById( "qa" + ID ).style.background = "transparent";

   openQuestion = ID;

}


function newsletters( file, winname ) {
   newwindow = window.open( '/newsletters/'+file+'.pdf', winname, 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width=640,height=450,left=50,top=50');
   newwindow.focus();
}
function articles( file, winname ) {
   newwindow = window.open( '/articles/'+file+'.htm', winname, 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width=640,height=400,left=50,top=50');
   newwindow.focus();
}

// client-side cookie function.
// one user-value per cookie UNLESS you concatenate the desired values
// in to one string and store that string.
//

function getCookie(name){     // retrieves a cooke from a user's machine
  var cname = name + "=";     // if cookie not located, it returns a "null" value.
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return null;
}

function setCookie(name, value, expires, path, domain, secure) {     // sets a cookie on the user's machine
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +  // if exipres == null, coookie will expire at end of session
  ((path == null) ? "" : "; path=" + path) +                         // if path == null, cookie will only be accessbile to the directory the creating file was housed in
  ((domain == null) ? "" : "; domain=" + domain) +                   // if domain == null, cookie will only be accessbile to the server the creating file was hosted on.
  ((secure == null) ? "" : "; secure");                              // if secure == null, cookie could be hacked...cookies ARE NOT secure. just leave this one  blank.
}

function delCookie (name,path,domain) {      // deletes named cookie from user's machine
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +        // if path == null, cookie MUST be deleted by the page/directory that created it
    ((domain == null) ? "" : "; domain=" + domain) +  // if domain == null, cookie MUST be deleted by the directory/server that created it.
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

