function deepCopy(obj) {
    if (Object.prototype.toString.call(obj) === '[object Array]') {
        var out = [], i = 0, len = obj.length;
        for ( ; i < len; i++ ) {
            out[i] = arguments.callee(obj[i]);
        }
        return out;
    }
    if (typeof obj === 'object') {
        var out = {}, i;
        for ( i in obj ) {
            out[i] = arguments.callee(obj[i]);
        }
        return out;
    }
    return obj;
}


function capitalizeWords( original ) {
  lower = original.toLowerCase();
  result = '';
  words = lower.split( ' ' );
  for ( var i = 0; i < words.length; ++i ) {
    result += words[i].substring( 0, 1 ).toUpperCase() + words[i].substring( 1, words[i].length ) + ' ';
  }
  // remove trailing ' '
  result = result.substring( 0, result.length - 1 );
  
  // capitalize letter after opening of parentheses and after colon
  for ( var j = 1; j < result.length - 1; ++j ) {
    if ( result[j] == '(' || result[j] == ':' )
      result = result.substring( 0, j+1 ) + result[j+1].toUpperCase() + result.substring( j+2 );
  } 

  return result;
}


function createCookie( name, value,days ) {
  if ( days ) {
    var date = new Date();
    date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
    var expires = "; expires=" + date.toGMTString();
  }
  else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/; domain=.readingandwritingproject.com";
}


function readCookie( name ) {
  var nameEQ = name + "=";
  var ca = document.cookie.split( ';' );
  for( var i = 0; i < ca.length; i++ ) {
    var c = ca[i];
    while ( c.charAt( 0 ) == ' ' ) c = c.substring( 1, c.length );
    if ( c.indexOf( nameEQ ) == 0 ) return c.substring( nameEQ.length, c.length );
  }
  return null;
}


function eraseCookie( name ) {
  createCookie( name, "" , -1 );
}


function readParameter( name ) {
  var query = window.location.search.substring( 1 );
  var vars = query.split( '&' );
  for ( var i = 0; i < vars.length; i++ ) {
    var pair = vars[i].split( '=' );
    if ( pair[0] == name ) {
      return pair[1];
    }
  } 
  //alert('parameter ' + name + ' not found');
}