var stack = new Array();

function addCube(cube) {
  var id = cube.id;
  var contained = stack.indexOf(id);
  if (contained > -1) {
    cube.style.background="#fff";
    stack.splice(contained,1);
  }
  else {
    stack.push(id);
    cube.style.background="#FFB400";
  }
}

function showCubes(thisDay) {
  if (stack.length > 0) {
  var selected = stack.join(",");
  POP('getSelectedCubes.php?id=' + selected + '&day=' + thisDay, 'your_schedule', 600, 500, 'scrollbars=yes');
  }
  else {
  alert("You haven't selected a schedule yet");
  }
}


if(!Array.indexOf){
 Array.prototype.indexOf = function(obj) {
  for(var i=0; i<this.length; i++){
   if(this[i]==obj){
    return i;
    }
  }
 }
}


function thisPage() {  
  var href    = document.location.href;
  var string  = href.split( "/" );
  var pageClass = "";

for ( var i = 3; i < ( string.length); i++ ) {
    if(!string[i].match(/\./)) {
        pageClass += string[i] + " ";
  }
  }
        document.body.className=pageClass;

}

function POP(u,n,w,h,f){ 
windowFeatures = "width="+w+",height="+h; 
if (f) windowFeatures += ","+f;
popwin = this.open(u, n, windowFeatures);
if (!popwin.opener) popwin.opener=self;
if (popwin.focus) popwin.focus();
return false;
}

function showLink() {
  var linkBox = document.getElementById("linkBox");
linkBox.style.visibility='visible';
linkBox.focus();
linkBox.select();
return false;
}

function validateForm(form) {
  var problem = "";
  to_addresses = form.to.value;
  address_list = to_addresses.split(/,[ ]?/);
  for (var i=0; i<address_list.length; i++) {
    var warning = emailCheck('to', address_list[i]);
    if (warning != true) {
	problem += warning;
    }
  }
  var warning = emailCheck('from', form.from.value);
  if (warning != true) {
    problem += warning;
  }
  if (form.body.value.length > 200) {
  problem += "Please limit comments to 200 characters.\n";
}

  if (problem > '') {
    alert(problem);
    return false;
  } else {
  return true;
  }
}

function emailCheck(field, email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
	var warning = "Invalid address in \"" + field + "\" field: " + email + "\n";
	return warning;
  } else {
   return true;
 }
}

