// Functions for select a codevim css

var cv_add = false;
if (!window.onload){
  LOAD_STACK = new Array();
  window.onload = function(){for (var i=0,j=LOAD_STACK.length;i<j;i++){f = LOAD_STACK[i];f();}LOAD_STACK = null;};
  function add_load_event(e){if ('function' == typeof(e)){LOAD_STACK.push(e);}}
  cv_add = true;
}

String.prototype.trim = function () {
 return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

if (!window.setCookie){
  function setCookie(name, value, permanent) {
    var expires = '';
    if (permanent) {
      //expires = '; expires=' + (new Date()).toGMTString().replace(/20\d\d/, 2010);
      expires = '; expires=Sat, 22 Feb 2020 11:42:36 GMT';
    }
    var cookie = name+"="+value+expires+"; path=/";
    document.cookie = cookie;
  }
}
if (!window.getCookie){
  function getCookie(name) {
    var i, crumbs, crumb;
    crumbs = document.cookie.split(';');
    for (var i=0; i<crumbs.length; i++) {
      crumb = crumbs[i].trim();
      if (crumb.indexOf(name + "=") == 0) {
        return crumb.substring((name + "=").length);
      }
    }
    return '';
  }
}

// codevim
function codevim_save(type, css){
  setCookie('codevim_type', type, true);
  setCookie('codevim_css',  css,  true);
}
function codevim_refresh(){
  var type= document.getElementById('codevim_type').value;
  var css = document.getElementById('codevim_css').value;

  codevim_save(type, css);
  window.location.reload();
}

function codevim_init(){
  var type = getCookie('codevim_type');
  var css  = getCookie('codevim_css');
  if (!css){
    css= 'default';
    type='gui';
    codevim_save(type, css);
  }
  otype = document.getElementById('codevim_type');
  ocss  = document.getElementById('codevim_css');
  if (otype && ocss){
    otype.value = type;
    otype.disabled = false;
    ocss.value = css;
    ocss.disabled = false;
  }
}


// Bind to the init
if (cv_add){
  add_load_event(function(){
    codevim_init();
  });
}
