<!-- hide from older browsers
// universal cookie grabber
function getCookieVal(offset){
  var endstr=document.cookie.indexOf(";",offset);
  if(endstr == -1) endstr=document.cookie.length;
  return unescape(document.cookie.substring(offset,endstr));
}

function getCookie(label){
  var arg=label+"=";
  var alen=arg.length;
  var clen=document.cookie.length;
  var i=0;
  while(i<clen){
    var j=i+alen;
    if(document.cookie.substring(i,j)==arg) return getCookieVal(j);
    i=document.cookie.indexOf(" ",i)+1;
    if(i==0)break;
  }
  return null;
}

// onLoad, set hidden instance value in form
function setInstance(){
  var instance=getCookie("mercuryinstance");
  document.forms[0].instance.value=instance;
  alert(instance);
  return;
}

var whitespace = " \t\n\r";
function charInString (c, s){
  for (i = 0; i < s.length; i++){
    if (s.charAt(i) == c) return true;
  }
  return false
}

// TRUE if field is empty or blanks
var whitespace = " \t\n\r";
function isEmpty(s){
  if((s == null) || (s.length == 0)) return true;
  for(var i=0;i<s.length;i++){
   var c = s.charAt(i);
   if(!charInString(c,whitespace)) return false;
  }
  return true;
}

var badEmailChars=" !\"#$%&()*+,;<=>?[\\]^`{|}~";
function isEmail(e){
  var s=e.value; var s1="";
  for(var i=0;i<s.length;i++){
    var c=s.charAt(i);
    if(badEmailChars.indexOf(c)== -1){ s1+=c; }
  }
  s1=s1.toLowerCase();
  e.value=s1;
  var a1=s1.split('@');
  if(a1.length!=2){ return false; }
  var a2=a1[1].split('.');
  if(a2.length<2){ return false; }
  return true;
}

// error message components...
var msg_head="Please enter your "
var msg_mid=" in the appropriate ";
var msg_tail=".\nThis information is important for our survey. Thank you.";

var cmt_head="You have indicated that you were not satisfied with survey ";
var cmt_mid=" of the Mercury system.\nBefore you submit your feedback, would you please comment about your ";

var rep_head="You have asked us to reply to your comments but you ";

function checkForm(f){
  var s="",e="",error=0;
  /* personal info currently not required.
  if(isEmpty(f.name.value)){ if(error){ e+=", "; } e+="name"; error++; }
  if(isEmpty(f.inst.value)){ if(error){ e+=", "; } e+="institution"; error++; }
  if(isEmpty(f.country.value)){ if(error){ e+=", "; } e+="country"; error++; }
  if(error){
    if(error>1){ var box="boxes"; }else{ var box="box"; }
    s=msg_head+e+msg_mid+box+msg_tail;
    alert(s); return false;
  }
  s=""; e=""; error=0;
  */
  if(!f.one[0].checked && isEmpty(f.comments_one.value)){
    if(error){ e+=" and "; } e+="item 1"; error++;
  }
  if(!f.two[0].checked && isEmpty(f.comments_two.value)){
    if(error){ e+=" and "; } e+="item 2"; error++;
  }
  if(error){
    if(error>1){ var box="concerns?"; }else{ var box="concern?"; }
    s=cmt_head+e+cmt_mid+box;
    if(confirm(s)){ return false; }
  }
  if(f.respond.checked){
    if(isEmpty(f.comments_one.value)
      && isEmpty(f.comments_two.value)
      && isEmpty(f.comments_three.value)){
        s=rep_head+"have no comments.";
        alert(s); return false;
    }
    if(isEmpty(f.email.value)){
      s=rep_head+"listed no E-mail address.";
      alert(s); return false;
    }
  }
  if(!isEmpty(f.email.value) && !isEmail(f.email)){
    s="Your E-mail address doesn't look right.";
    s+="\nShould we try to use it anyway?";
    if(!confirm(s)){ return false; }
  }
  return true;
}
// End hiding -->

