/*
   iching-lib.js
   functions used in the iching reading.
   coin toss functions are located in iching-cointoss.js

  the newWindow function used here is from js/new_window.js
  which is included as part of the whole page setup.
*/   

function ichingHelp(context) {
  // this will open a "help popup"
  // all text is in this file
  var file = "help.php?context=" + context;
  newWindow(file, 381, 381, 100, 100, 'help', 'no', 'yes');
}
// end of function ichingHelp()


function ichingLines() {
  newWindow("lines.php", 381, 381, 100, 100, 'help', 'no', 'yes');
}
// end of function ichingSound()


// limit chars in the reading subject textarea
function textLimit(field, counterField, maxlimit) {
    var strLen = field.value.length;
    if (strLen > maxlimit) // if too long...trim it!
    {
        field.value = field.value.substring(0, maxlimit);
        var winString = "0";
    }
    // otherwise, update 'characters left' counter
    else 
    {
        var winString = maxlimit - strLen;
    }
    var winTxt = document.createTextNode(winString);
    var winElem = document.getElementById(counterField);
    var oldTxt1 = winElem.replaceChild(winTxt, winElem.firstChild);
}

/* basic image swap, images must be preloaded: imgSrc = new Image(), ect 
    most of these are in iching-cointoss.js */
function imgSwap (imgName, imgSrc) {
  document[imgName].src = imgSrc.src;
}

// open larger version of the hexagram painting in a popup
function zoomPic(hex) {
  var file="enlarge.php?h=" + hex;
  var name="hex" + hex;
  newWindow( file, 660, 520, 10, 10, name, 'no', 'no' );
}

