//--------------------------------------------------------------------------------------
//This fuction and the following code stop users from right-clicking on the page.
//This helps to protect the images that will come in the test and from
//finding out about the addresses, etc. used in the test. In short, it helps
//stop people from hacking the test.

//function right(e) {
//  if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false;
//  else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
//    alert("Sorry, you do not have permission to right click.");
//    return false;
//  }
//
//  return true;
//}

//document.onmousedown=right;
//document.onmouseup=right;
//if (document.layers) window.captureEvents(Event.MOUSEDOWN);
//if (document.layers) window.captureEvents(Event.MOUSEUP);
//window.onmousedown=right;
//window.onmouseup=right;

//-------------------------------------------------------------------------------------
//This fuction and code play the audio files for each item.
//This also hides the "Play Audio" button after it is clicked 2 times.

function playAudio(audiofile) {
  var playCount = parseInt(document.getElementById("playCount").value);

  var htmlstring = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,47,0" WIDTH="0" HEIGHT="0" id="wimpy_button_1" name="wimpy_button01">\n<PARAM NAME=movie VALUE="wimpy_button.swf?theFile=audio/' + audiofile + '&autoplay=yes">\n<PARAM NAME=quality VALUE=high>\n<PARAM NAME=wmode VALUE=transparent>\n<EMBED src="wimpy_button.swf?theFile=audio/' + audiofile + '&autoplay=yes" quality=high WIDTH="0" HEIGHT="0" NAME="wimpy_button01" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>\n</OBJECT>';
  document.getElementById("audioLayer").innerHTML = htmlstring;
  playCount++;

  if(playCount == 2) {
    document.getElementById("buttonLayer").innerHTML = '<img src="images/noaudio.gif" border="0" alt="No Audio">';
  } else {
    document.getElementById("playCount").value = playCount;
  }
}

//------------------------------------------------------------------------------------
//This function preloads any images on the page

function preload(imgs) {
  var tmp = null;

  for (var j = 0; j < imgs.length; j++) {
    tmp = imgs[j];
    imgs[j] = new Image();
    imgs[j].src = tmp;
  }
}

//-------------------------------------------------------------------------------------
//This function does rollover images on mouseover and mouseout or whenever specified

function imgSwap(myImage, swap) {
  var image = eval(document.images[myImage]);
  image.src = imgs[swap].src;
}

//-------------------------------------------------------------------------------------
//This function checks to make sure the user selected an answer on each item page

function validateForm(formObj) {
  var isChecked = 0;
  for(i = 0; i < formObj.answer.length; i++) {
    if(formObj.answer[i].checked) {
      isChecked = 1;
      break;
    }
  }

  if(!isChecked) {
    if(formObj.s.value == "v" || formObj.s.value == "c" || formObj.s.value == "ss1" || formObj.s.value == "ss2") {
      alert('You must choose either A or B, or "I don\'t know."!');
    } else if(formObj.s.value == "ws") {
      alert('You must choose a syllable pattern, or "I don\'t know."!');
    } else if(formObj.s.value == "i1") {
      alert('You must choose either "Question" or "Statement" or "I don\'t know."!');
    } else if(formObj.s.value == "i2") {
      alert('You must choose "Information" or "Comment" or "I don\'t know."!');
    }
    return false;
  }
}

//-------------------------------------------------------------------------------------
//This function displays the "Other Language" box is the user selects "Other (Please specify)"
//from the Language list.

function checkOther(elObj) {
  if(elObj.options[elObj.selectedIndex].text == "Other (please specify)") {
    document.getElementById("otherLang").style.display = '';
  } else {
    document.getElementById("otherLang").style.display = 'none';
  }
}

//-------------------------------------------------------------------------------------
//This function moves to the next item in any section

function nextItem() {
  var formObj = eval(document.item);
  if(!formObj.answer[0].checked && !formObj.answer[1].checked && !formObj.answer[2].checked) {
    alert('You must choose either A or B, or "I don\'t know!"!');
    return false;
  } else {
    formObj.submit();
    return false;
  }
}

//-------------------------------------------------------------------------------------
//This function checks to make sure the user selected "Yes" or "No" on the consent form

function checkConsent(formObj) {
  var radioObj = formObj.consent;
  if(!radioObj[0].checked && !radioObj[1].checked) {
    alert('You must check "Yes" or "No"');
    return false;
  }
}
