/*
* ======================================================================
* ----------------------------------------------------------------------
* zTCselect:	Text Content Selection Script by zon
* Author:		zon
* Website:		http://inimu.com
* ----------------------------------------------------------------------
* You may use and/or modify the codes below and its associated files
* as long as you leave the author credit remain intact
* ----------------------------------------------------------------------
* ======================================================================
*/

function ztcsDeselect() {
 if (document.selection) {
  document.selection.empty();
 } else if (window.getSelection) {
  window.getSelection().removeAllRanges();
 }
}

function ztcsSelect(ztcsCE) {
 ztcsDeselect();
 if (document.selection) {
  var ztcsTR = document.body.createTextRange();
  ztcsTR.moveToElementText(ztcsCE);
  ztcsTR.select();
 } else if (window.getSelection) {
  var ztcsTR = document.createRange();
  ztcsTR.selectNode(ztcsCE);
  window.getSelection().addRange(ztcsTR);
 }
}

function ztcsSelectById(ztcsCEI) {
 ztcsSelect(document.getElementById(ztcsCEI));
}

// set onclick event attribute to select text to every predefined tag element
// example: ztcsSelectByTagName('pre') or: ztcsSelectByTagName('code')
function ztcsSelectByTagName(ztcsTN) {
 var z = 0;
 for (z = 0; z < document.getElementsByTagName(ztcsTN).length; z++) {
  document.getElementsByTagName(ztcsTN)[z].setAttribute('onclick','try{ztcsSelect(this)}catch(err){}');
  document.getElementsByTagName(ztcsTN)[z].title = 'Click to select text';
 }
}

