function Is () {
  var agt=navigator.userAgent.toLowerCase();

  this.major=parseInt(navigator.appVersion);
  this.nav=((agt.indexOf('mozilla')!=-1)&&((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible')==-1)));
  this.nav4=(this.nav && (this.major == 4));
  this.nav4up=this.nav && (this.major >= 4);
  this.ie=(agt.indexOf("msie") != -1);
  this.ie4=(this.ie && (this.major == 4));
  this.ie4up=this.ie  && (this.major >= 4);
}
var is = new Is();

function init() {
  var s;
  s="<MAP NAME='PrivacyMap'><AREA SHAPE='rect' COORDS='205, 0, 290, 18' HREF=\"javascript:hide('privacy')\"></MAP>";
  s+="<IMG BORDER='0' SRC='/images/closex.gif' USEMAP='#PrivacyMap' width='300' height='18'><BR>";
  s+="<FONT SIZE=1>This <I>quickVote</I> is being conducted by goVote’s  on line ballot system from a secure server.<BR>";
  s+="If you choose to participate, goVote guarantees that you will remain anonymous. ";
  s+="We do not capture your e-mail address, IP address, or any other information about you. ";
  s+="For more information about our privacy policy, <A HREF=\"/privacy.htm\">click here</A>.</FONT>";
  makeTip('privacy',300,s);
  
  s="<MAP NAME='DisclaimerMap'><AREA SHAPE='rect' COORDS='205, 0, 290, 18' HREF=\"javascript:hide('disclaimer')\"></MAP>";
  s+="<IMG BORDER='0' SRC='/images/closex.gif' USEMAP='#DisclaimerMap' width='300' height='18'><BR>";
  s+="<FONT SIZE=1>This <I>quickVote</I> facility has been provided by goVote, for the exclusive use of one of our clients.<BR>";
  s+="We have no control over the circumstances in which our clients use this facility, or the questions that they decide to ask.<BR>";
  s+="All our clients have been advised that any inappropriate use by them will result in goVote withdrawing this faciility.<BR>";
  s+="If you think that this <I>quickVote</I> is being used inappropriately, please let us know promptly, using this link: <A HREF=\"mailto:admin@govote.com.au\">admin@govote.com.au</A>.</FONT>";
  makeTip('disclaimer',300,s);
}

function makeTip(id, width, message) {
  document.write('<STYLE TYPE="text/css">#'+id+'{width:'+width+';}</STYLE><DIV CLASS="balloon" id="'+id+'">'+message+'</DIV>');
}

function nil() {
}

function show(id,pos,top) {
  if (is.nav4up) {
    document.layers['privacy'].visibility="hide";
    document.layers['disclaimer'].visibility="hide";
    document.layers[id].left=window.event.pageX + 10;
    document.layers[id].top=window.event.pageY + 10;
    document.layers[id].visibility="show";
  }
  else {
    document.all['privacy'].style.visibility="hidden";
    document.all['disclaimer'].style.visibility="hidden";
    if (pos=='r') {//right-aligned above
      document.all[id].style.pixelLeft=(document.body.scrollLeft+window.event.clientX-300);
      document.all[id].style.pixelTop=(document.body.scrollTop+window.event.clientY-top);
    }
    else if (pos=='c') {//center-aligned above
      document.all[id].style.pixelTop=(document.body.scrollTop+window.event.clientY-top);
      document.all[id].style.pixelLeft=(document.body.scrollLeft+window.event.clientX-150);
    }
    else if (pos=='l') {//left-aligned above
      document.all[id].style.pixelTop=(document.body.scrollTop+window.event.clientY-top);
      document.all[id].style.pixelLeft=(document.body.scrollLeft+window.event.clientX);
    }
    else if (pos=='rb') {//right-aligned below
      document.all[id].style.pixelTop=(document.body.scrollTop+window.event.clientY+10);
      document.all[id].style.pixelLeft=(document.body.scrollLeft+window.event.clientX-300);
    }
    else if (pos=='cb') {//center-aligned below
      document.all[id].style.pixelTop=(document.body.scrollTop+window.event.clientY+10);
      document.all[id].style.pixelLeft=(document.body.scrollLeft+window.event.clientX-150);
    }
    else {//left-aligned below
      document.all[id].style.pixelTop=(document.body.scrollTop+window.event.clientY+10);
      document.all[id].style.pixelLeft=(document.body.scrollLeft+window.event.clientX);
    }  
    document.all[id].style.visibility="visible";
  }
}
  
function settext(id,s) {
  if (is.nav4up) {
    document.all[id].innerHTML=s; //todoooo
  }
  else {
    document.all[id].innerHTML=s;
  }
}

function hide(id) {
  if (is.nav4up) {
    document.layers[id].visibility="hide";
  }
  else {
    document.all[id].style.visibility="hidden";
  }
}

function preload() {
  qv = new Image();
  qv.src = "www.govote.com.au/images/submitqv.gif";
  qv2 = new Image();
  qv2.src = "www.govote.com.au/images/submitqv2.gif";
  qv3 = new Image();
  qv3.src = "www.govote.com.au/images/submitqv3.gif";
}

function submitForm(THISFORM){
  var INDEX, VAL1=0, VAL2, ELEMENT1, ELEMENT2, COLS='', VALS='';

  for(INDEX=0;INDEX<THISFORM.elements.length;INDEX++) {
   // if (INDEX!=THISFORM.elements.length-1 && !THISFORM.elements[INDEX].QNO) continue;

    ELEMENT2=THISFORM.elements[INDEX];
    if (VAL1==-1 && ELEMENT2.name!=ELEMENT1.name) { //no radiobutton checked
      window.scrollTo(0,0);
      ELEMENT1.focus();
      if (!ELEMENT1.QNO || ELEMENT1.QNO=='-') {
        alert('You need to make a selection...');
      }
      else {
        alert('Question ' + ELEMENT1.QNO + '. You need to make a selection.');
      }
      return;
    }
    if (ELEMENT2.type=='radio') {
      if (ELEMENT2.name!=ELEMENT1.name) { VAL1=-1; }
      if (ELEMENT2.checked) {
        VAL1=ELEMENT2.value;
        COLS+=ELEMENT2.name+',';
        VALS+="'"+VAL1+"',";
      }
    }
    if (ELEMENT2.type=='text') {
      VAL1=ELEMENT2.value.replace(/\'/g,'\`');
      if (ELEMENT2.TAG) VAL1=ELEMENT2.TAG.replace(/\'/g,'\`');
      VAL2=VAL1.replace(/\,/g,'\;');
      COLS+=ELEMENT2.name+',';
      VALS+="'"+VAL2+"',";
    }
    if (ELEMENT2.type=='textarea') {
      VAL1=ELEMENT2.value.replace(/\'/g,'\`');
      VAL2=VAL1.replace(/\,/g,'\;');
      VAL1=VAL2.replace(/\r\n/g,'<BR>');
      COLS+=ELEMENT2.name+',';
      VALS+="'"+VAL1+"',";
    }
    if (ELEMENT2.type.substr(0,6)=='select') {
      if (ELEMENT2.selectedIndex==-1) {
        window.scrollTo(0,0);
        ELEMENT2.focus();
        if (!ELEMENT2.QNO || ELEMENT2.QNO=='-') {
          alert('You need to make a selection.');
        }
        else {
          alert('Question ' + ELEMENT2.QNO + '. You need to make a selection.');
        }
        return;
      }
      else {
        VAL1=ELEMENT2.value;
      }
      COLS+=ELEMENT2.name+',';
      VALS+="'"+VAL1+"',";
    }
    if (ELEMENT2.type=='checkbox') {
      if (ELEMENT2.checked) { VAL1=ELEMENT2.value; } else { VAL1=0; }
      COLS+=ELEMENT2.name+',';
      VALS+="'"+VAL1+"',";
    }

    if (ELEMENT2.REQUIRED && ELEMENT2.value=='') {
      ELEMENT2.select();
      ELEMENT2.focus();
      if (!ELEMENT2.QNO || ELEMENT2.QNO=='-') {
        alert('Missing value - Please rectify and Send again.');
      }
      else {
        alert('Question ' + ELEMENT2.QNO + '. \n\nMissing value - Please rectify and Send again.');
      }
      return;
    }
    if (ELEMENT2.MASK) {
      var re = new RegExp(ELEMENT2.MASK);
      if (!re.exec(ELEMENT2.value)) {
        //ELEMENT2.select();
        ELEMENT2.focus();
        if (!ELEMENT2.QNO || ELEMENT2.QNO=='-') {
          alert('Missing or incorrect value - Please rectify and Send again.');
        }
        else {
          alert('Question ' + ELEMENT2.QNO + '. \n\nMissing or incorrect value - Please rectify and Send again.');
        }
        return;
      }
    }
    ELEMENT1=ELEMENT2;
  }
  if (VAL1==-1) { //no radiobutton checked
    window.scrollTo(0,0);
    ELEMENT1.focus();
    if (!ELEMENT1.QNO || ELEMENT1.QNO=='-') {
      alert('You need to make a selection...');
    }
    else {
      alert('Question ' + ELEMENT1.QNO + '. You need to make a selection.');
    }
    return;
  }
  
  THISFORM.reset(); //avoids accidental resubmits
  THISFORM.elements.cols.value=COLS.substr(0,COLS.length-1);
  THISFORM.elements.vals.value=VALS.substr(0,VALS.length-1);
//alert(THISFORM.elements.cols.value+"\n"+THISFORM.elements.vals.value);
  popupWin = window.open('', 'mypopup', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=540,height='+THISFORM.elements.PopupHt.value);
  popupWin.focus();
  THISFORM.target = 'mypopup';
  THISFORM.submit();
}

function viewResults(THISFORM2) {
  THISFORM2.elements.action.value='View';
  popupWin = window.open('', 'mypopup', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=540,height='+THISFORM2.elements.PopupHt.value);
  popupWin.focus();
  THISFORM2.target = 'mypopup';
  THISFORM2.submit();
}

function popupResults(THISFORM3) {
  popupWin = window.open('http:\/\/www.govote.com.au/qkvote/' + THISFORM3.elements.code.value + '.htm', 'mypopup', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=560,height=360');
  popupWin.opener.top.name = 'opener';
  popupWin.focus();
}

