/*
===============================
The Javascript file nocopy.js
===============================
*/
 
/*****************Globals****************/
var currentText = new Array();
var textArea = new Array();
var pasteMsg = '';
/****************************************/


/****************************************************************************
void startPreventPaste();
initializes the copy paste monitor.

****************************************************************************/

function startPreventPaste(TextAreaArray, msg){
  for(i = 0; i < TextAreaArray.length; i++)
  {
    textArea[i] = document.getElementById(TextAreaArray[i]);
    currentText[i] = textArea[i].value;
  }

  if(msg){
    pasteMsg = msg
  }else if (msg === false){
    pasteMsg = msg;
  }

  if(document.all){
    //it it is ie do the onpaste function
    var brwsr = navigator.userAgent.toLowerCase();
    if(brwsr.search(/opera[\/\s](\d+(\.?\d)*)/) != -1) {
      // Opera
      doLoop();
      }else{
      for(i = 0; i < textArea.length; i++)
      {
          textArea[i].onpaste = function (){
          showMessage();//shoe the message
          return false;//don't paste
        }
      }
    }
  }else{
    doLoop();
  }
}
/****************************************************************************
void doLoop()
starts the timer. Checks the text.
****************************************************************************/

function doLoop(){
  checkText();
  pccpTimer = window.setTimeout("doLoop();", 10);
}
/****************************************************************************
void checkText()
checks the length of the string in the textbox and compares it with
the length of the string in the saved currentText string. If the
text box text is 10 characters longer than the saved string then it
assumes that they have pasted. it puts the current string back into
the textarea over what they pasted and then shows them the message.
if it isn't longer then it just puts the text into the saved text.

****************************************************************************/

function checkText(){
  for(i = 0; i < textArea.length; i++)
  {
    if(textArea[i]){
      newTextLength = textArea[i].value.length;//gets length of the textarea right now.
      currentTextLength = currentText[i].length;//gets length of the saved text from the textarea
    
      if(newTextLength > (currentTextLength + 50)){//is the new more then 10 characters longer?
        textArea[i].value = currentText[i];//put the saved text back in/
        showMessage();//tell them they cannot paste.
      }else{
          currentText[i] = textArea[i].value;//if it is ok then save the text.
      }
    }
  }
}
/****************************************************************************
void showMessage();
if they calling function wants to show a message when they paste then
the message is alerted.
****************************************************************************/

function showMessage(){
  if(pasteMsg !== false){
    //alert(pasteMsg);
  }
}

/*
===============================
The Javascript disable selection
===============================
*/


function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}
