/*------------------------------------------------------*
 * File: anCMS.js
 * Desc:
 * Notes:
 * Author: Nishikant Kapoor
 *------------------------------------------------------*/
  var xmlHttp; var modSpanId; var modDetailSpanId; var ratingSpanId;
  var tagSpan0Id; var tagSpan1Id; var tagSpan2Id;
  var tagSpan3Id; var ufrSpanId;  var ufrTeSpanId; // USR: UseForRecs
  var stateToggle = 0; var merItemSpanId; //delete mer item attachment
  var weatherContentSpanId; var weatherErrSpanId; var weatherEditSpanId;
  var grpSpanId;
  var gmarker;


/*------------------------------------------------------*
 * Function: getElementsByClass()
 * Desc: How it works
 *     " It's simple. It works just how you think getElementsByClass would work, except better.
 *  1. Supply a class name as a string.
 *  2. (optional) Supply a node. This can be obtained by getElementById, or simply by just throwing in "document" (it will be document if don't supply a node)). It's mainly useful if you know your parent and you don't want to loop through the entire D.O.M.
 *  3. (optional) Limit your results by adding a tagName. Very useful when you're toggling checkboxes and etcetera. You could just supply "input". Or, if you're like me, and you said Good Bye to IE5, you can use the "*" asterisk as a catch-all (meaning 'any element).
 *
 * Notes: http://www.dustindiaz.com/getelementsbyclass/
 *      : http://ejohn.org/blog/getelementsbyclassname-speed-comparison/
 *------------------------------------------------------*/
  function getElementsByClass(searchClass,node,tag) {
        var classElements = new Array();
        if (node == null) {node = document;}
        if (tag == null) {tag = '*';}
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
          if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
          }
        }
        return classElements;
  } //end of getElementByClass()

/*------------------------------------------------------*
 * Function: redirectTo()
 * Desc:
 * Notes:
 *------------------------------------------------------*/
  function redirectTo (destination) {
    window.location=destination;

  } // end of redirectTo()

  /*------------------------------------------------------*
   * Function: validEmail()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function validEmail (em0) {

    var errMsg='';
    var filter = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;

    var em1 = em0.replace(/,/g," ");
    var em = em1.replace(/;/g," ");
    var pattern = /\s+/;
    var emArr = em.split(pattern);

    for (var i=0; i < emArr.length; i++) {
      if (!filter.test(emArr[i])) {
        if (errMsg == '') {errMsg += ' ';}
        errMsg += emArr[i] + ' ';
        //alert("validEmail(anCMS.js):em=" + em + " i=" + i + " e=" + emArr[i] + " - F");
      }
    }

    return errMsg;
  } // end of validEmail()

  /*------------------------------------------------------*
   * Function: submitForm()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitForm(action, form, param) {
    form.action.value = action;
    if (param == 'newWin') {form.target='_blank';} else {form.target='';}

    //WYSIWYG bug: http://www.openwebware.com/forum/viewtopic.php?f=1&t=2235
    //It still does not work with MAC
    if (form.dBody) {WYSIWYG.updateTextArea('dBody');}
    if (form.nHead) {WYSIWYG.updateTextArea('nHead');}
    if (form.nBody) {WYSIWYG.updateTextArea('nBody');}

    form.submit();

  } // end of submitForm()

  /*------------------------------------------------------*
   * Function: submitModConfig()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitModConfig(action, form, param, mSpanId, modId) {
    var itemCount = form.itemCount.value;
    var script = param;
    modSpanId = mSpanId; //set it so that doModConfig() can access it

    //strip off the args for cetain mods - syndicated news
    var txt = '?';
    var i = script.indexOf(txt);
    if (i != -1) {script = script.substring(0,i);}

    var url = "/cgi-bin/anCMS/" + script;
        url += "?action=" + action + "&itemCount=" + itemCount;
        url += "&modId=" + modId;

    xmlHttp = getXmlHttpObject(doModConfig);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;

  } //end of submitModConfig()

  /*------------------------------------------------------*
   * Function: submitModConfigDetail()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitModConfigDetail(action, form, param, mSpanId) {
    var itemCount = form.itemCount.value;
    var script = param;
    modDetailSpanId = mSpanId; //set it so that doModConfigDetail() can access it

    /*********
    if (itemCount == 0) {
      var msg = "\nSelecting zero items will disable this block!" + 
            "\n\nYou can enable it from 'Preferences' under 'Personalize' menu.";
      if (!confirm(msg)) return (false);
    }
    ***********/

    //alert("action=" + action + " form=" + form + " itemCount=" + itemCount + " script=" + script);

    var url = "/cgi-bin/anCMS/" + script;
        url += "?action=" + action + "&itemCount=" + itemCount;

    xmlHttp = getXmlHttpObject(doModConfigDetail);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;

  } //end of submitModConfigDetail()

  /*------------------------------------------------------*
   * Function: submitRating()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitRating(action,form,itemSpanId,itemId,
                        modId,rating,sideBySide) {
    ratingSpanId = itemSpanId; //set it so that doRating() can access it

    /***
    var rating = 0;
    for (var i=1; i <= 5; i++) {
      if (eval("form.rating[" + (i-1) + "].checked") == true) {
        rating = i;
        break;
      }
    }
    ***/

    var url = "/cgi-bin/anCMS/rating.cgi";
        url += "?action=" + action + "&iId=" + itemId;
        url += "&rating=" + rating + "&modId=" + modId;
        url += "&sideBySide=" + sideBySide;

    xmlHttp = getXmlHttpObject(doRating);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;

  } //end of submitRating()

  /*------------------------------------------------------*
   * Function: stripSpaces()
   *
   *------------------------------------------------------*/
  function stripSpaces(str) {
    if ( (!isBlank(str)) && (str != null) ) {
      // this will get rid of leading spaces
      while (str.substring(0,1) == ' ')
        str = str.substring(1);

      // this will get rid of trailing spaces
      while (str.substring(str.length-1, str.length) == ' ')
        str = str.substring(0,str.length-1);
    }

    return (str);

  } // end of stripSpaces()

  /*------------------------------------------------------*
   * Function: isBlank()
   *
   *------------------------------------------------------*/
  function isBlank(s) {
    return (s == "");

  } // end of isBlank()

  /*------------------------------------------------------*
   * Function: isInteger()
   *
   *------------------------------------------------------*/
  function isInteger (contents) {
  /***
    if (((contents / contents) != 1) && (contents != 0)) {
      return false;
    }
    return true;
  ***/

    /***
    //var objRegExp  = /(^\d*$)/;
    var objRegExp  = /(^-?\d\d*$)/;

    //check for integer characters
    return objRegExp.test(contents);
    ***/

   var ints = "0123456789.";
   
   for (var i = 0; i < contents.length; i++) {
     if (ints.indexOf(contents.charAt(i)) == -1)
       return false;
   }
   return true;

  } // end of isInteger()

  /*------------------------------------------------------*
   * Function: openCal()
   * Desc:
   * Notes: In the generated cal, each date should be a link to a JS fn
   #      : that would set the particular field's value to clicked date
   #      : <a href="javascript:returnDate('2006-03-27',form,fld)">27</a>
   *------------------------------------------------------*/
    /*****************************
  function openCal(action, form, param) {

    //var login = form.login.value;
    //param is the field that needs to be populated

    var cgi = "/cgi-bin/anCMS/cal.cgi";
    var str = cgi + "?action=" + action + "&fld=" + param;

    var winWidth      = 100;
    var winHeight     = 100;
    var winScrollbars = 'no';

    var winStr = 'width='+winWidth+',height='+winHeight+',scrollbars='+winScrollbars;
    winStr += ',menubar=no,resizable=yes,location=no,statusbar=no,screenX=150,screenY=150,top=150,left=150';

    window.open(str,'Calendar',winStr);

  } // openCal()
*********************************/

  /*------------------------------------------------------*
   * Function: returnDate()
   * Desc: /var/www/html/admin/phpMyAdmin/libraries
   * Notes: vi tbl_change.js ../calendar.php
   *------------------------------------------------------*/
/*****************************
  function returnDate(d, form, fld) {
    txt = d;
    if (window.opener.dateType != 'date') {
        // need to get time
        h = parseInt(document.getElementById('hour').value,10);
        m = parseInt(document.getElementById('minute').value,10);
        s = parseInt(document.getElementById('second').value,10);
        if (window.opener.dateType == 'datetime') {
            txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
        } else {
            // timestamp
            txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
        }
    }
    window.opener.fld.value = txt;
    window.close();
} // returnDate()

*********************************/

  /*------------------------------------------------------*
   * Function: openPrfAssign()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function openPrfAssign(action, form, param) {
    //alert("action=" + action + " form=" + form + " param=" + param);

    var url = "/cgi-bin/anCMS/prf.cgi";
        url += "?action=" + action + "&prfId=" + param;

    xmlHttp = getXmlHttpObject(stateChanged);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;
  } // end of openPrfAssign()

  /*------------------------------------------------------*
   * Function: getXmlHttpObject()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function getXmlHttpObject(handler) { 
    var objXmlHttp = null;

    if (navigator.userAgent.indexOf("Opera") >= 0) {
      alert("This option doesn't work in Opera");
      return;
    }

    if (navigator.userAgent.indexOf("MSIE") >= 0) {
      var strName="Msxml2.XMLHTTP";
      if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {strName = "Microsoft.XMLHTTP";} 

      try { 
        objXmlHttp = new ActiveXObject(strName);
        objXmlHttp.onreadystatechange = handler;
        return objXmlHttp;
      }
      catch(e) { 
        alert("Error! Scripting for ActiveX might be disabled");
        return;
      } 
    } //if (navigator.userAgent.indexOf("MSIE") >= 0)

    if (navigator.userAgent.indexOf("Mozilla") >= 0) {
      objXmlHttp = new XMLHttpRequest();
      /***
      if (objXmlHttp.overrideMimeType) {
        //set type accordingly to anticipated content type
        //objXmlHttp.overrideMimeType('text/xml');
        objXmlHttp.overrideMimeType('text/html');
      }
      ***/
      objXmlHttp.onload = handler;
      objXmlHttp.onerror = handler;
      return objXmlHttp;
    }
  } //end of getXmlHttpObject()

  /*------------------------------------------------------*
   * Function: stateChanged()
   *
   *------------------------------------------------------*/
  function stateChanged() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      //document.getElementById("paName").innerHTML =  'Welcome';
      //document.getElementById("paId").innerHTML =  'Welcome';
      //alert("xmlHttp.responseText=" + xmlHttp.responseText);

      var wWd=500; var wHt=350; var wSb='yes';
      var winStr = 'width='+wWd+',height='+wHt+',scrollbars='+wSb;
      winStr += ',menubar=no,resizable=yes,location=no,statusbar=no';
      winStr += ',screenX=150,screenY=150,top=150,left=150';

      var winH;
      //if (winH.opener == null) {
        winH = window.open('','PRF Assignments',winStr);
        winH.document.write(xmlHttp.responseText);
        winH.focus();
        winH.document.close();
      //}
    }
    return;

  } //end of stateChanged()

  /*------------------------------------------------------*
   * Function: submitPrfMaint()
   *
   *------------------------------------------------------*/
  function submitPrfMaint() {
    var form = document.prfMaintForm;

    form.paId.value = document.getElementById("paId").innerHTML;

    //alert("document.getElementById(paId).innerHTML=" + document.getElementById("paId").innerHTML);

    return true;

  } // end of submitPrfMaint()

  /*------------------------------------------------------*
   * Function: doModConfig()
   * Desc: whoever calls modConfig() passes its spanId, which is 
   *     : then copied into the global modSpanId, which is what this
   *     : fn() populates with AJAX response.
   *------------------------------------------------------*/
  function doModConfig() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(modSpanId);
      elem.innerHTML = xmlHttp.responseText;
      //alert("doModConfig(anCMS.js):xmlHttp.responseText=" + xmlHttp.responseText);

      //1. if you put a script there, it should be in <script language=javascript tag.
      //2. The following code will execute all scripts
      var x = elem.getElementsByTagName("script"); 
      for (var i=0;i<x.length;i++) {eval(x[i].text);}
    }
    return;

  } //end of doModConfig()

  /*------------------------------------------------------*
   * Function: doRating()
   * Desc: whoever calls doRating() passes its spanId, which is 
   *     : then copied into the global ratingSpanId, which is what this
   *     : fn() populates with AJAX response.
   *------------------------------------------------------*/
  function doRating() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(ratingSpanId);
      //alert("doRating():xmlHttp.responseText=" + xmlHttp.responseText);
      elem.innerHTML = xmlHttp.responseText;
    }
    return;

  } //end of doRating()

  /*------------------------------------------------------*
   * Function: doModConfigDetail()
   * Desc: Detailed listing for News module
   *------------------------------------------------------*/
  function doModConfigDetail() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(modDetailSpanId);
      //elem.style.display = 'Block';
      //elem.style.visibility = 'hidden';
      //elem.style.display = 'None';
      elem.innerHTML = xmlHttp.responseText;

      //alert("xmlHttp.responseText=" + xmlHttp.responseText);
    }
    return;

  } //end of doModConfigDetail()

  /*------------------------------------------------------*
   * Function: submitPayPal()
   *
   *------------------------------------------------------*/
  function submitPayPal() {
    var valid = true;
    var msg = "Form Submission:\n\n";

    var form = document.payPalForm;

    var feeAmt = stripSpaces(form.memberFee.value);
    if (!isBlank(feeAmt)) {
      if (! isInteger(feeAmt)) { // make sure it is all numeric
        msg += "Invalid fee amount !\n";
        valid = false;
      }
      else {
        feeAmt = parseInt(feeAmt);
      }
    }
    else {
      feeAmt = 0; // fee is blank
    }

    var contribAmt = stripSpaces(form.memberContrib.value);
    if (!isBlank(contribAmt)) {
      if (! isInteger(contribAmt)) { // make sure it is all numeric
        msg += "Invalid contribution amount !\n";
        valid = false;
      }
      else {
        contribAmt = parseInt(contribAmt);
      }
    }
    else {
      // contrib is blank
      contribAmt = 0;
    }

    // validate currency code
    var sIndex = form.currency_code.selectedIndex;
    var cc = form.currency_code[sIndex].value;
    if (cc == "INR") {
      msg += "At present, PayPal does not allow payments in " + cc + " !\n";
      msg += "Please choose one of the other acceptable currencies.\n";
      valid = false;
    }

    if (!valid) {
      alert (msg);
      return false;
    }

    form.amount.value = feeAmt + contribAmt;

    var yrIdx = form.years.selectedIndex;
    var yrs = form.years[yrIdx].value;
    form.cn.value = "Membership for " +  yrs + " years"; //comments

    // avoid putting in email in .shtml or else spammers get it
    form.business.value = "treasurer@wpaa.org";

    return true;

  } // end of submitPayPal()

  /*------------------------------------------------------*
   * Function: changePayPal()
   *
   *------------------------------------------------------*/
  function changePayPal(form, source) {
    var ccArr = new Array(); var i=0;
    ccArr[i] = 12;  i++; //USD
    ccArr[i] = 100; i++; //INR
    //ccArr[i] = 15; i++; //CAD
    ccArr[i] = 10; i++; //EUR
    //ccArr[i] = 20; i++; //GBP
    //ccArr[i] = 20; i++; //Yen

    var ccIdx = form.currency_code.selectedIndex;
    var yrIdx = form.years.selectedIndex;
    var amt = 0;

    var yrs = form.years[yrIdx].value;

    if ((source == 1) || (source == 2)) { // 1/years  2/currency_code
      amt = yrs * ccArr[ccIdx];
    }
    else {
      alert ("Invalid source: " + source);
      return;
    }
  
    //alert ("ccIdx=" + ccIdx + " yrIdx=" + yrIdx + " amt=" + amt);
    form.memberFee.value = amt;
    return;
  } //end of changePayPal()

  /*------------------------------------------------------*
   * Function: toggleAllOld()
   * Description:
   *------------------------------------------------------*/
  function toggleAllOld (form, source) {

    //alert("toggleAll(): source=" + source);

    if (!source) {source = form.toggleCB;}

    var str="";
    if (source) {
      var state = source.checked;
      for (var i = 0; i < form.elements.length; i++) {
        if ((form.elements[i].name.indexOf('cb') > -1)) {
          str += " i=" + i + " name=" + form.elements[i].name + "\n";
          form.elements[i].checked = state; //found a checkbox
        }
      }
    }

    //alert("toggleAll(): source=" + source + " str=" + str);

    return;

  } //end of toggleAllOld()

/*------------------------------------------------------*
 * Function: toggleCB()
 * Description: toggle check boxes
 *------------------------------------------------------*/
function toggleCB (form1, form2, source) {
  //alert("toggleCB(anCMS.js):form1=" + form1 + " form2=" + form2 +
  //        " source=" + source);

  /*** not sure where it is being called from - there is no users.tmpl *
  if (source == 0) {  //called from users.tmpl
    if (form.toggleCB) {
      var state = form.toggleCB.checked;
      for (var i = 0; i < form.elements.length; i++) {
        if ((form.elements[i].name.indexOf('cb') > -1)) {//found checkbox
          form.elements[i].checked = state;
        }
      }
      return;
    }
  } //if (source == 0)
  * not sure where it is being called from - there is no users.tmpl ***/

  if (source == 1 || source == 2) { //from PF selections in TL
    var state;                      //from Team selections in TL
    if (source == 1) {
      state = form1.toggleCB1.checked;
      //form2.toggleCB2.checked = state;
      if (form2) {if (form2.toggleCB2) {form2.toggleCB2.checked = state;}}
    }

    if (source == 2) {
      state = form2.toggleCB2.checked;
      if (form1) {if (form1.toggleCB1) {form1.toggleCB1.checked = state;}}
    }

    var str="";
    for (var i=0; i < document.forms.length; i++) {
      var f = document.forms[i];
      str += " f=" + f.name + "\n";
      if ( (f.name.indexOf('artForm') > -1) ||
           (f.name.indexOf('ufrForm') > -1) ||
           (f.name.indexOf('resListForm') > -1) ||
           (f.name.indexOf('mailListForm') > -1) ||
           (f.name.indexOf('uListForm') > -1) ) {
        for (var j = 0; j < f.elements.length; j++) {
          if ((f.elements[j].name.indexOf('cb') > -1)) {
            f.elements[j].checked = state;  //found a checkbox
          }
        }
      } //if ((f.name.indexOf('artForm') > -1))
    } //for (var i = 0; i < document.forms.length; i++)

    //alert("toggleCB(anCMS.js): source=" + source + " str=" + str);
    return;
  } //if ((source == 1) || (source == 2)

  /* not sure where is it being called from *
  if (source == 3) {
    for (var i = 0; i < form.elements.length; i++) {
      if ((form.elements[i].name.indexOf('cb') > -1)) {
        //found a checkbox
        form.elements[i].checked = stateToggle;
      }
    }
    stateToggle = !stateToggle;
    return;
  } //if (source == 3)
  * not sure where is it being called from */

  if (source == 4) { //from pics pending approval
    var state = document.picsListForm.toggleCB1.checked;

    for (var i=0; i < document.forms.length; i++) {
      var form = document.forms[i];
      if ((form.name.indexOf('picsListForm') > -1)) {
        for (var j = 0; j < form.elements.length; j++) {
          if ((form.elements[j].name.indexOf('cb') > -1)) {
            form.elements[j].checked = state;  //found a checkbox
          }
        }
      } //if ((form.name.indexOf('picsListForm') > -1))
    } //for (var i = 0; i < document.forms.length; i++)

    return;
  } //if ((source == 4)

  if (source == 5) { //from mer channel update (merMaint.tmpl)
    var state = document.merMaintForm.cbToggle.checked;

    for (var i=0; i < document.forms.length; i++) {
      var form = document.forms[i];
      if ((form.name.indexOf('merMaintForm') > -1)) {
        for (var j = 0; j < form.elements.length; j++) {
          if ((form.elements[j].name.indexOf('cb') > -1)) {
            form.elements[j].checked = state;  //found a checkbox
          }
        }
      } //if ((form.name.indexOf('merMaintForm') > -1))
    } //for (var i = 0; i < document.forms.length; i++)

    return;
  } //if ((source == 5)

} //end of toggleCB()

  /*------------------------------------------------------*
   * Function: submitComment()
   *
   *------------------------------------------------------*/
  function submitComment() {
    var valid = true;
    var msg = "Form Submission:\n\n";

    var form = document.commentForm;

    var comText = stripSpaces(form.comText.value);
    if (isBlank(comText)) {
        msg += "Please enter some valid text!\n";
        valid = false;
    }

    if (!valid) {
      alert (msg);
      return false;
    }

    return true;

  } // end of submitComment()

/*------------------------------------------------------*
 * Function: changed()
 *
 *------------------------------------------------------*/
function changed(form) {
  if (form.tMode.options[form.tMode.selectedIndex].text == 'PayPal') {
    //PayPal transactions have a fee = some % of transaction amount
    amount = (((form.tAmt.value - 0) * (form.payPalStdRate.value - 0))/100) +
             (form.payPalStdFee.value - 0);

    /***
    alert ("amount=" + amount + " tAmt=" + form.tAmt.value
         + " stdRate=" + form.payPalStdRate.value 
         + " payPalStdFee=" + form.payPalStdFee.value);
    ***/

    amount = (Math.round(amount*100))/100;
    fee = (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);

    form.tOverheads.value = fee;

    //alert ("fee=" + fee);
  } //if (form.tMode.options[form.tMode.selectedIndex].text == 'PayPal')
  else {
    form.tOverheads.value = '';
  }

} //end of changed()

/*------------------------------------------------------*
 * Function: popup()
 * Desc: 
 * Notes: 
 *------------------------------------------------------*/
function popup(action) {
  var msg = '';

  /*******************************************
  var str="";
  var tmpValue = "oneword (5)";
  str += " (0)tmpValue=" + tmpValue;
  var words = tmpValue.split(/\s/g);
  //tmpValue = words[0];
  str += " Selected=";
  for (var i=0; i< words.length-1; i++) {
    if (i > 0) {str += " ";}
    str += words[i];
  }
  str += " (1)tmpValue=" + tmpValue + " len=" + words.length + " \n";

  tmpValue = "two words (7)";
  str += " (0)tmpValue=" + tmpValue;
  words = tmpValue.split(/\s/g); 
  //tmpValue = words[0];
  str += " Selected=";
  for (var i=0; i< words.length-1; i++) {
    if (i > 0) {str += " ";}
    str += words[i];
  }
  str += " (1)tmpValue=" + tmpValue + " len=" + words.length + " \n";

  alert(str); return;
  *****************************************************/

  if (action == "quizStats") {
    msg = "To maintain privacy and anonymity of quiz respondents, these statistics are displayed only after sufficient number of responses have been received.";
  }

  if (action == "cookie") {
    msg = "Cookies are small data structures used by a web site (server)\nto deliver data to a web client (user); request that the\nclient store the information; and in certain circumstances,\nreturn the information to the web site. Contrary to popular\nfears and misconceptions, cookies were not created to spy on or\notherwise invade the privacy of Internet users. Cookies\ncontain only information that users volunteer, and they do not\nhave the capability of infiltrating a user`s hard drive and\nsneaking away with personal information. The client stores\ncookie data in one or more flat files on its local hard drive.";
  }

  if (action == "overheads") {
    msg = "Payments made through Google Checkout carry a surcharge which is deducted\n from the actual amount. For example, if you deposit $12,\n WPAA receives only $11.23.\n Remaining .77 goes to Google as service charge. This is the overheads.";
  }

  if ( (action == "resPhone") || (action == "resFax") ||
       (action == "resUrl") || (action == "resEmail") ) {
    msg = "Use space to separate multiple entries in this field.";

    if ( (action == "resPhone") || (action == "resFax") ) {
      msg += "\nFormat: ###-###-####";
      msg += "\nPhone must be capable to be able to receive an SMS.";
    }

    if (action == "resEmail") {
      msg += "\nIf you want to be notified when this item is rated or reviewed,";
      msg += "\n  you must provide your email address.";
    }
  }

  if (action == "youAreNotLoggedOn") {
    msg  = "You are not logged on!\n\n";
    msg += "Please log on to access this feature.";
  }

  if (action == "youTube") {
    msg  = "If you want a YouTube video to be linked to this item, specify its ID here.\n";
    msg += "For example, 0Bs2qBN70Wo is the ID for the SOURYAM (Telugu) movie trailor.\n";
    msg += "Or, you can specify the complete URL, i.e.,\n";
    msg += "http://www.youtube.com/watch?v=0Bs2qBN70Wo";
  }
  if (action == "tabTitleHelp") {
    msg  = "Title of the tab - a max of 16 characters.\n";
    msg += "Try to limit it to one or two short words";
  }
  if (action == "ttCodeHelp") {
    msg  = "What type of format do you want for the content for this tab.\n";
    msg += "Various types are Listing, Slide Show, Free Text, etc. etc.\n";
    msg += "Currently, only Listing and Slide Show are supported.";
  }
  if (action == "tabPosHelp") {
    msg  = "This decides the order of appearance of the tabs for the channel.\n";
    msg += "Assigning duplicates might cause the channel to mal-function.";
  }
  if (action == "tabDefHelp") {
    msg  = "Select this tab as the default whenever the channel is displayed.\n";
    msg += "There must always be a default.";
  }
  if (action == "tabActiveHelp") {
    msg  = "Tab Active help text\n";
    msg += "Tab Active ...more help text";
  }

  if (action == "chAccessHelp") {
    msg  = "Local Channel Access help text\n";
    msg += "Local Channel Access...more help text";
  }

  alert(msg);

  } // end of popup()

/*------------------------------------------------------*
 * Function: getCapImg()
 * Desc:
 * Notes:
 *------------------------------------------------------*/
function getCapImg(form) {
  var maxId=10;

  var randomNum = Math.floor(Math.random()*maxId);

  //alert("getCapImg():randomNum=" + randomNum);
  document.mainForm.capImg.src = "pics/cap/" + randomNum + ".png";
  return;

} //end of getCapImg()

/*------------------------------------------------------*
 * Function: samplePopup()
 * Desc: Pops open a window to display sample items for a News channel
 * Notes:
 *------------------------------------------------------*/
function samplePopup(action, form, param) {
  var cgi = "/cgi-bin/anCMS/synd.cgi";
  var str = cgi + "?action=" + action + "&modId=" + param;

  var winWidth      = 300;
  var winHeight     = 500;
  var winScrollbars = 'yes';

  var winStr = 'width='+winWidth+',height='+winHeight+',scrollbars='+winScrollbars;
  winStr += ',menubar=no,resizable=yes,location=no,statusbar=no,screenX=150,screenY=150,top=150,left=150';

  //alert("samplePopup():str=" + str);

  window.open(str,'Sample',winStr);

} //end of samplePopup()

/*------------------------------------------------------*
 * Function: submitSsAccessUpdate()
 * Description:
 * Notes: we are not expecting any text back from this AJAX call
 *------------------------------------------------------*/
function submitSsAccessUpdate(action, form, param) {
  var cbVar = 'cb' + param + 'a';
  var state = eval ("form." + cbVar + ".checked"); // shows final state
  //if cb goes from unchecked to checked, state is true
  //if cb goes from checked to unchecked, state is false

  var msg = "Form Submission:\n\n";
  msg += "action=" + action + " form=" + form + " param=" + param;
  msg += " state=" + state;
  //alert(msg);

  var url = "/cgi-bin/anCMS/ss.cgi";
      url += "?action=" + action + "&ssId=" + param;
      url += "&state=" + state;

  xmlHttp = getXmlHttpObject(); //we're not expecting any text back
  xmlHttp.open("GET", url , true);
  xmlHttp.send(null);

  return;
} // end of submitSsAccessUpdate()

/*------------------------------------------------------*
 * Function: submitSS()
 * Description: Saved Search selection for updates
 * Notes:
 *------------------------------------------------------*/
function submitSS(action, form, param) {
  var ok = true;
  var msg = "Form Submission:\n\n";

  var dupArr = new Array();
  var ssList = ''; var cbStr = 'cb';
  for (var j=0; j < form.elements.length; j++) {
    var formElem = form.elements[j];
    var idx = formElem.name.indexOf(cbStr);
    if (idx > -1) {
      var ssId = formElem.name.substring(cbStr.length);
      if (isInteger(ssId)) { // make sure ssId is numeric
        var ssIdProcessed = false;  //to handle duplicates
        for (var i in dupArr) {
          if (dupArr[i] == ssId) {ssIdProcessed = true; break;}
        }
        if (!ssIdProcessed) {
          if (eval("form." + cbStr + ssId + "[0].checked") == true) {
            if (ssList != '') {ssList += ',';}
            ssList += ssId + 'd'; //Del
          }
          else {
           if (eval("form." + cbStr + ssId + "[1].checked") == true) {
              if (ssList != '') {ssList += ',';}
              ssList += ssId + 'e'; //Empty
            }
          }
        }
        dupArr[j] = ssId;
      } //if (isInteger(ssId))
    }
  } //for (var j=0; j < form.elements.length; j++)

  //alert("submitSS(): action=" + action + " form=" + form + " param=" + param + " ssList=" + ssList);

  form.cbSsList.value = ssList;
  form.action.value = action;
  form.submit();

} // end of submitSS()

/*------------------------------------------------------*
 * Function: submitTEold()
 * Description: validate team selection from the dropdown
 * Notes:
 *------------------------------------------------------*/
function submitTEold(action, form, param) {
  var ok = true;
  var msg = "Form Submission:\n\n";

  if (param != 'showItem') {
    var authList = ''; var cbStr = 'cb';
    var ppStr = 'P'; //most authors begin with PP, some with just P
    for (var j=0; j < form.elements.length; j++) {
      var formElem = form.elements[j];
      var idx = formElem.name.indexOf(cbStr);
      if (idx > -1) {
        if (formElem.checked) { //found a checked checkbox
          var authId = formElem.name.substring(cbStr.length);
          //ACM DL has authors IDs starting with PP
          //TL3 has its users IDs as all numeric
          var good=0;
          if (isInteger(authId)) {good=1;} //its a TL3 user
          else {if (authId.indexOf(ppStr) > -1) {good=1;}} //ACM author
          if (good) {
            if (authList != '') {authList += ',';}
            authList += authId;
          }
        } //if (formElem.checked)
      } //if (idx > -1)
    } //for (var j=0; j < form.elements.length; j++)

    if (authList == '') {
      ok = false;
      msg += "Please select at least one item! \n";
    }
    else {
      form.cbAuthList.value = authList;
    }
  } //if (param != 'showItem')

  var sIndex = form.teamId2.selectedIndex;
  var teamId = form.teamId2[sIndex].value;

  if (teamId == 0) {
    msg += "Please select appropriate destination! \n";
    ok = false;
  }

  if (!ok) {alert (msg); return false;}

  form.action.value = action;
  form.submit();

} // end of submitTEold()

/*------------------------------------------------------*
 * Function: submitTE()
 * Description: validate PF selection from the dropdown
 * Notes:
 *------------------------------------------------------*/
function submitTE(action, form, param) {
  //alert("submitTE(): action=" + action + " form=" + form + " param=" + param);

  var ok = true;
  var msg = "Form Submission:\n\n";

  if (param != 'showItem') {
    var destList = ''; var cbStr = 'cb';
    for (var i=0; i < document.forms.length; i++) {
      var f = document.forms[i];
      //if (f.name.indexOf('artForm') > -1) {
        for (var j=0; j < f.elements.length; j++) {
          var fElem = f.elements[j];
          var idx = fElem.name.indexOf(cbStr);
          if (idx > -1) {
            if (fElem.checked) {   //found a checked checkbox
              if (destList != '') {destList += ',';}
              destList += fElem.name.substring(cbStr.length);
            }
          }
        } //for (var j=0; j < f.elements.length; j++)
      //} //if ((f.name.indexOf('artForm') > -1))
    } //for (var i=0; i < document.forms.length; i++)

    if (destList == '') {
      ok = false;
      msg += "Please select at least one item! \n";
    }
    else {form.cbDestList.value = destList;}
  } //if (param != 'showItem')

  var sIdx = form.id2.selectedIndex;
  var sVal = form.id2[sIdx].value;

  if (sVal == 0) {
    msg += "Please select appropriate destination! \n";
    ok = false;
  }

  if (!ok) {alert (msg); return false;}

  form.action.value = action;
  form.submit();

} // end of submitTE()

/*------------------------------------------------------*
 * Function: submitPfe()
 * Description: validate PF selection from the dropdown
 * Notes:
 *------------------------------------------------------*/
function submitPfe(action, form, param) {
  //alert("submitPfe(): action=" + action + " form=" + form + " param=" + param);

  var ok = true;
  var msg = "Form Submission:\n\n";

  if (param != 'showItem') {
    var artList = ''; var cbStr = 'cb';
    for (var i=0; i < document.forms.length; i++) {
      var f = document.forms[i];
      if ( (f.name.indexOf('artForm') > -1) ||
	   (f.name.indexOf('resListForm') > -1) ) {
        for (var j=0; j < f.elements.length; j++) {
          var fElem = f.elements[j];
          var idx = fElem.name.indexOf(cbStr);
          if (idx > -1) {
            if (fElem.checked) {   //found a checked checkbox
              if (artList != '') {artList += ',';}
              artList += fElem.name.substring(cbStr.length);
            }
          }
        } //for (var j=0; j < f.elements.length; j++)
      } //if ((f.name.indexOf('artForm') > -1))
    } //for (var i=0; i < document.forms.length; i++)

    if (artList == '') {
      ok = false;
      msg += "Please select at least one item! \n";
    }
    else {form.cbArtList.value = artList;}
  } //if (param != 'showItem')

  var sIdx = form.pfId2.selectedIndex;
  var sVal = form.pfId2[sIdx].value;

  if (sVal == 0) {
    msg += "Please select appropriate destination! \n";
    ok = false;
  }

  if (!ok) {alert (msg); return false;}

  form.action.value = action;
  form.submit();

} // end of submitPfe()

/*------------------------------------------------------*
 * Function: submitPicsPending()
 * Description: 
 * Notes:
 *------------------------------------------------------*/
function submitPicsPending(action, form, param) {
  //alert("submitPicsPending(): action=" + action + " form=" + form + " param=" + param);

  var ok = true;
  var msg = "Form Submission:\n\n";

  var picList = ''; var cbStr = 'cb';
  for (var i=0; i < document.forms.length; i++) {
    var f = document.forms[i];
    if (f.name.indexOf('picsListForm') > -1) {
      for (var j=0; j < f.elements.length; j++) {
        var fElem = f.elements[j];
        var idx = fElem.name.indexOf(cbStr);
        if (idx > -1) {
          if (fElem.checked) {   //found a checked checkbox
            if (picList != '') {picList += ',';}
            picList += fElem.name.substring(cbStr.length);
          }
        }
      } //for (var j=0; j < f.elements.length; j++)
    } //if ((f.name.indexOf('picsListForm') > -1))
  } //for (var i=0; i < document.forms.length; i++)

  if (picList == '') {
    ok = false;
    msg += "Please select at least one item! \n";
  }
  else {form.cbPicList.value = picList;}

  if (!ok) {alert (msg); return false;}

  form.action.value = action;
  form.submit();

} // end of submitPicsPending()

/*------------------------------------------------------*
 * Function: submitRecsInputSel()
 * Description: validate team selection from the dropdown
 * Notes:
 *------------------------------------------------------*/
function submitRecsInputSel(action, form, param) {
  var ok = true;
  var msg = "Form Submission:\n\n";

  var selList = ''; var cbStr = 'cb';
  for (var j=0; j < form.elements.length; j++) {
    var formElem = form.elements[j];
    var idx = formElem.name.indexOf(cbStr);
    if (idx > -1) {
      if (formElem.checked) { //found a checked checkbox
        var selId = formElem.name.substring(cbStr.length);
          if (selList != '') {selList += ',';}
          selList += selId;
        }
      }
    } //for (var j=0; j < form.elements.length; j++)

    if (selList == '') {
      ok = false;
      msg += "Please select at least one item! \n";
    }
    else {
      form.cbSelList.value = selList;
    }

  if (!ok) {alert (msg); return false;}

  form.action.value = action;
  form.submit();

} // end of submitRecsInputSel()

/*------------------------------------------------------*
 * Function: syncSelectTE()
 * Description:
 *------------------------------------------------------*/
function syncSelectTE(form, source) {
  if (! form.teamId1) {return;}
  if (! form.teamId2) {return;}

  var idx1 = form.teamId1.selectedIndex;
  var idx2 = form.teamId2.selectedIndex;

  if (source == 1) {form.teamId2.selectedIndex = idx1; return;}
  if (source == 2) {form.teamId1.selectedIndex = idx2; return;}

} //end of syncSelectTE()

/*------------------------------------------------------*
 * Function: syncSelect()
 * Description:
 *------------------------------------------------------*/
function syncSelect(form, source) {

  //for some reason, form MUST be identified here
  var form1 = document.pfSelectForm1;
  var form2 = document.pfSelectForm2;

  if (! form1) {return;}; if (! form1.pfId2) {return;}
  if (! form2) {return;}; if (! form2.pfId2) {return;}

  var idx1 = form1.pfId2.selectedIndex;
  var idx2 = form2.pfId2.selectedIndex;

  if (source == 1) {
    form2.pfId2.selectedIndex = idx1;
    return;
  }

  if (source == 2) {
    form1.pfId2.selectedIndex = idx2;
    return;
  }

} //end of syncSelect()

/*------------------------------------------------------*
 * Function: toggleLayer()
 * Description: mode=1 is show tag entry form; mode=0 is hide
 * Notes: Don't use document.all.
 *      : document.getElementById() is supported by every JS supporting
 *      : browser released since 1998.
 *------------------------------------------------------*/
function toggleLayer(span0Id, span1Id, span2Id, mode) {

  var prop0='none'; var prop1='inline'; var prop2='inline';
  if (mode == 1) {
    prop0 = 'inline'; //show tag entry form; reset tagText
    prop2 = 'none';
    var tmpArr = span0Id.split("span0"); //split into span0 & artId
    var tagTextId = 'autocomplete' + tmpArr[1];
    document.getElementById(tagTextId).value = '';
    //alert ("toggleLayer(): span0Id=" + span0Id + " 0=" + tmpArr[0] + " 1=" + tmpArr[1]);
    //document.myFormName.autocomplete3677.focus();  //does not work :-(
  }

  //alert ("toggleLayer(): span0Id=" + span0Id + " span2Id=" + span2Id +
  //         " mode=" + mode);

  if (document.getElementById) {   //this is the way the standards work
    document.getElementById(span0Id).style.display = prop0;
    document.getElementById(span1Id).style.display = prop1;
    document.getElementById(span2Id).style.display = prop2;
  }
  else if (document.all) {   //this is the way old msie versions work
    document.all(span0Id).style.display = prop0;
  }
  else if (document.layers) {  //this is the way nn4 works
    document.layers(span0Id).style.display = prop0;
  }

} // end of toggleLayer()

/*------------------------------------------------------*
 * Function: showHide()
 * Desc: if elem is already visible, hide it, otherwise show it.
 *------------------------------------------------------*/
function showHide(divId) {
  if (divId) {
    var act = document.getElementById(divId).style.display;
    if (act != "none") {act = 'none';} else {act = 'inline';}
    eval("document.getElementById('" + divId + "').style.display = '" + act + "'");
  }
} //end of showHide()

/*------------------------------------------------------*
 * Function: show0()
 *
 *------------------------------------------------------*/
function show0(divId) {
  document.getElementById(divId).style.display = 'block';
}

/*------------------------------------------------------*
 * Function: hide0()
 *
 *------------------------------------------------------*/
function hide0(divId) {
  document.getElementById(divId).style.display = 'none';
}

/*------------------------------------------------------*
 * Function: hideArticles()
 * Desc: Called when tags are shown/hidden in TL
 *------------------------------------------------------*/
function hideArticles(divId,alCode,tagText) {
  var elem = document.getElementById(divId);

  //when - is clicked, we need to create the original tagText & + links
  //and replace the entire span (or div) with it
  var txt = "<a href=\"/cgi-bin/anCMS/tagTL.cgi?action=taggedList";
      txt += "&tagText=" + tagText;
      txt += "&alCode=" + alCode + "\">";
      txt += tagText + "</a>";
      txt += " (<font size=\"+1\" <a href=\"javascript:tagPlus('tagPlus', '";
      txt += divId + "', '" + tagText + "', " + alCode + ")\" title=\"Show articles\">+</a></font>)";

  elem.innerHTML = txt;
  //alert ("hideArticles():divId=" + divId + " alCode=" + alCode + 
  //       " tagText=" + tagText + " txt=" + txt);

} // end of hideArticles()

/********************************
window.onload = hide0;
*******************************/

  /*------------------------------------------------------*
   * Function: submitTagSave()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitTagSave(action, form, artId) {
    tagSpan0Id = 'span0'+artId; //set it so doTagSave() can access it
    tagSpan1Id = 'span1'+artId; //set it so doTagSave() can access it
    tagSpan2Id = 'span2'+artId; //set it so doTagSave() can access it

    var tagTextId ='autocomplete'+artId;
    var tagText   = document.getElementById(tagTextId).value;

    if (stripSpaces(tagText) == "") {
      //no text entered; just close the tag entry form, and go back
      toggleLayer(tagSpan0Id, tagSpan1Id, tagSpan2Id, 0);
      return false;
    }

    var url = "/cgi-bin/anCMS/tagTL.cgi";;
        url += "?action=" + action + "&artId=" + artId;
        url += "&tagText=" + tagText;

    var alCode='alCode'+artId; var alCodeId='alCodeId'+artId;
    //following check for missing alCode (when 'select' element does not
    //exist) is not working???
    //if (form.alCode) {
      //if there are no active tag types, alCode is not displayed
      var alCodeVal  = document.getElementById(alCodeId).value;
      url += "&alCode=" + alCodeVal;
    //}

    /***************************************
    var str = "";
    for (var i=0; i < form.elements.length; i++) {
      //var element = form.elements[i];
      //str += " i=" + i + " element=" + element + " value=" + element.value;
    }
    //http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/form.asp
    //var str = " tagText=" + document.forms[0].tagText.value

    alert("submitTagSave(anCMS.js):action=" + action +
          " form=" + form + " artId=" + artId +
          " tagText=" + tagText + " alCode=" + alCode +
          " url=" + url + " str=" + str);
    ********************************************/

    xmlHttp = getXmlHttpObject(doTagSave);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;

  } //end of submitTagSave()

  /*------------------------------------------------------*
   * Function: doTagSave()
   *
   *------------------------------------------------------*/
  function doTagSave() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem1 = document.getElementById(tagSpan1Id);
      elem1.innerHTML = xmlHttp.responseText;

      //alert("doTagSave():xmlHttp.responseText=" + xmlHttp.responseText);
      toggleLayer(tagSpan0Id, tagSpan1Id, tagSpan2Id, 0);
    }
    return;

  } //end of doTagSave()

  /*------------------------------------------------------*
   * Function: noEnter()
   *
   *------------------------------------------------------*/
  function noEnter() {
    return !(window.event && window.event.keyCode == 13);

    //if ( (window.event && window.event.which == 13) ||
    //     (window.event && window.event.keyCode == 13))
    //return false;

  } // end of noEnter()

  /*------------------------------------------------------*
   * Function: submitTagMore()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitTagMore(action, artId) {
    tagSpan0Id = 'span0'+artId; //set it so doTagSave() can access it
    tagSpan1Id = 'span1'+artId; //set it so doTagSave() can access it
    tagSpan2Id = 'span2'+artId; //set it so doTagSave() can access it

    var url = "/cgi-bin/anCMS/tagTL.cgi";;
        url += "?action=" + action + "&artId=" + artId;

    xmlHttp = getXmlHttpObject(doTagSave);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;

  } //end of submitTagMore()

  /*------------------------------------------------------*
   * Function: submitTagForm()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitTagForm(action, form, artId) {
    submitTagSave(action, form, artId);
    return false;
  } //end of submitTagForm()

  /*------------------------------------------------------*
   * Function: toggleTaggedList()
   * Description: mode=1 is show tagged list; mode=0 is hide
   * Notes: Don't use document.all.
   *      : document.getElementById() is supported by every JS supporting
   *      : browser released since 1998.
   *------------------------------------------------------*/
  function toggleTaggedList(span3Id, mode) {
    var prop='none'; if (mode == 1) {prop = 'inline';}

    //alert ("toggleTaggedList(): span3Id=" + span3Id + " mode=" + mode);

    if (document.getElementById) {   //this is the way the standards work
      document.getElementById(span3Id).style.display = prop;
    }
    else if (document.all) {   //this is the way old msie versions work
      document.all(span3Id).style.display = prop;
    }
    else if (document.layers) {  //this is the way nn4 works
      document.layers(span3Id).style.display = prop;
    }

  } // end of toggleTaggedList()

  /*------------------------------------------------------*
   * Function: tagPlus()
   * Desc: Gets list of tagged articles for a particular tag
   * Notes: called when + is clicked in 'My Tags' listing
   *------------------------------------------------------*/
  function tagPlus(action, span3Id, tagText, alCode, tagId) {
    tagSpan3Id = span3Id; //set it so doTaggedList() can access it

    //alert("tagPlus():action=" + action + " span3Id=" + span3Id +
    //      " tagText=" + tagText + " alCode=" + alCode);

    var url = "/cgi-bin/anCMS/tagTL.cgi";;
        url += "?action=" + action + "&tagText=" + tagText;
        url += "&alCode=" + alCode;
        url += "&span3Id=" + span3Id;

    if (tagId) {url += "&tagId=" + tagId;} //used by tagPlusDel

    xmlHttp = getXmlHttpObject(doTagPlus);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;

  } //end of tagPlus()

  /*------------------------------------------------------*
   * Function: doTagPlus()
   *
   *------------------------------------------------------*/
  function doTagPlus() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(tagSpan3Id);
      elem.innerHTML = xmlHttp.responseText;

      //alert("doTagPlus():xmlHttp.responseText=" + xmlHttp.responseText);
      //toggleTaggedList(tagSpan3Id, 1);
      //document.getElementById(tagSpan3Id).style.display = 'inline';
      document.getElementById(tagSpan3Id).style.display = 'block';
    }
    return;

  } //end of doTagPlus()

  /*------------------------------------------------------*
   * Function: toHere()
   * Desc: Gets Google Maps directions to the specified coordinates
   * Notes:
   *------------------------------------------------------*/
  function toHere(resLat, resLng, resTitle) {
    var to_html = resTitle + '<br>Directions: <b>To here</b> - <a href="javascript:fromHere(' + resLat + ', ' + resLng + ', \'' + resTitle + '\')">From here</a>' +
           '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + resLat + ',' + resLng + 
           "(" + resTitle + ")" + 
           '"/>';
    //alert("(toHere): resLat=" + resLat + " resLng=" + resLng + " to_html=" + to_html);
    gmarker.openInfoWindowHtml(to_html);
  } //end of toHere()

  /*------------------------------------------------------*
   * Function: fromHere()
   * Desc: Gets Google Maps directions from the specified coordinates
   * Notes:
   *------------------------------------------------------*/
  function fromHere(resLat, resLng, resTitle) {
    var from_html  = resTitle + '<br>Directions: <a href="javascript:toHere(' + resLat + ', ' + resLng + ', \'' + resTitle + '\')">To here</a> - <b>From here</b>' +
           '<br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + resLat + ',' + resLng +
           "(" + resTitle + ")" + 
           '"/>';
    gmarker.openInfoWindowHtml(from_html);
  } //end of fromHere()

  /*------------------------------------------------------*
   * Function: insertNthChar()
   * Desc: insert a character after every Nth character in a string
   * Notes:
   *------------------------------------------------------*/
  function insertNthChar(string, chr, nth) {
    var output = '';
    for (var i=0; i<string.length; i++) {
      if (i > 0 && i % nth == 0) {output += chr;}
      output += string.charAt(i);
    }

    return output;
  } //end of insertNthChar()

  /*------------------------------------------------------*
   * Function: submitRefFmt()
   * Desc: User wants to display ref(s) in a particular format
   * Notes:
   *------------------------------------------------------*/
  function submitRefFmt(action, form, param) {
    //param is the field that needs to be populated

    var sIdx = form.rfCode.selectedIndex;
    var rfCode = form.rfCode[sIdx].value;

    if (rfCode == 0) {return;}

    var cgi = "/cgi-bin/anCMS/art.cgi";
    var str = cgi + "?action=" + action + "&rfCode=" + rfCode;

    if (param == undefined) {  //its the "With selected" option
      param = ''; var cbStr = 'cb';
      for (var i=0; i < document.forms.length; i++) {
        var f = document.forms[i];
        if (f.name.indexOf('artForm') > -1) {
          for (var j=0; j < f.elements.length; j++) {
            var fElem = f.elements[j];
            var idx = fElem.name.indexOf(cbStr);
            if (idx > -1) {
              if (fElem.checked) {   //found a checked checkbox
                if (param != '') {param += ',';}
                param += fElem.name.substring(cbStr.length);
              }
            }
          } //for (var j=0; j < f.elements.length; j++)
        } //if ((f.name.indexOf('artForm') > -1))
      } //for (var i=0; i < document.forms.length; i++)

      if (param == '') {
        alert("Please select at least one item! \n");
        return;
      }

      //form.artId.value = param;

    } //if (param == undefined)

    str += "&artId=" + param;

    //alert("submitRefFmt(anCMS.js):artId=" + param);

    var winWidth      = 600;
    var winHeight     = 400;
    var winScrollbars = 'yes';

    var winStr = 'width='+winWidth+',height='+winHeight+',scrollbars='+winScrollbars;
    winStr += ',menubar=no,resizable=yes,location=no,statusbar=no,screenX=150,screenY=150,top=150,left=150';

    //alert("action=" + action + " form=" + form + " param=" + param +
    //      " str=" + str);

    window.open(str,'Reference',winStr);

    return;

  } // submitRefFmt()

  /*------------------------------------------------------*
   * Function: doPfeUpdate()
   * Desc: whoever calls doPfeUpdate() passes its spanId, which is 
   *     : then copied into the global ufrSpanId, which is what this
   *     : fn() populates with AJAX response.
   *------------------------------------------------------*/
  function doPfeUpdate() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(ufrSpanId);
      var resp = xmlHttp.responseText;
      //alert("doPfeUpdate():xmlHttp.responseText=" + resp);
      elem.innerHTML = resp;
    }
    return;

  } //end of doPfeUpdate()

  /*---------------------------------------------------------------*
   * Function: submitPfeUpdate()
   * Description: Update PFE - "use it or not" for recommendations
   * Notes: we are not expecting any text back from server for this AJAX call
   *      : we use this same routine for PF and PFE; if artId is
   *      : available, it is for PFE, otherwise it is for PF.
   *---------------------------------------------------------------*/
  function submitPfeUpdate(action, form, uSpanId, pfId, artId, sn) {

    ufrSpanId = uSpanId; //set it so that doPfeUpdate() can access it

    var url = "/cgi-bin/anCMS/pf.cgi?action="+action+"&pfId="+pfId;
        url += "&sn=" + sn;

    if (artId) {
      url = "/cgi-bin/anCMS/pfe.cgi?action="+action+"&pfId="+pfId;
      url += "&artId=" + artId;
    }

    xmlHttp = getXmlHttpObject(doPfeUpdate); //we're not expecting any text back
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);

    return;
  } // end of submitPfeUpdate()

  /*------------------------------------------------------*
   * Function: doTeUpdate()
   * Desc: whoever calls doTeUpdate() passes its spanId, which is 
   *     : then copied into the global ufrTeSpanId, which is what this
   *     : fn() populates with AJAX response.
   *------------------------------------------------------*/
  function doTeUpdate() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(ufrTeSpanId);
      var resp = xmlHttp.responseText;
      //alert("doPfeUpdate():xmlHttp.responseText=" + resp);
      elem.innerHTML = resp;
    }
    return;

  } //end of doTeUpdate()

  /*------------------------------------------------------*
   * Function: submitTeUpdate()
   * Description: Update TE - "use it or not" for recommendations
   * Notes: we are not expecting any text back from server for this AJAX call
   *------------------------------------------------------*/
  function submitTeUpdate(action, form, uSpanId, teamId, authId, sn) {

    ufrTeSpanId = uSpanId; //set it so that doTeUpdate() can access it

    var url = "/cgi-bin/anCMS/team.cgi?action="+action+"&teamId="+teamId;
        url += "&sn=" + sn;

    if (authId) {
      url = "/cgi-bin/anCMS/te.cgi?action="+action+"&teamId="+teamId;
      url += "&authId=" + authId;
    }

    xmlHttp = getXmlHttpObject(doTeUpdate); //we're not expecting any text back
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);

    return;
  } // end of submitTeUpdate()

  /*------------------------------------------------------*
   * Function: doMerItemUpdate()
   * Desc: whoever calls this() passes the destination spanId, which is 
   *     : then copied into the global spanId, which is what this
   *     : fn() populates with AJAX response.
   *------------------------------------------------------*/
  function doMerItemUpdate() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(merItemSpanId);
      var resp = xmlHttp.responseText;
      //alert("doMerItemUpdate():xmlHttp.responseText=" + resp);
      elem.innerHTML = resp;
    }
    return;

  } //end of doMerItemUpdate()

  /*------------------------------------------------------*
   * Function: submitMerItemUpdate()
   * Description: Delete Mer item attachment.
   * Notes:
   *------------------------------------------------------*/
  function submitMerItemUpdate(action, form, miSpanId, scModId, scSeq) {

    merItemSpanId = miSpanId; //so that doMerItemUpdate() can access it

    var url = "/cgi-bin/anCMS/mer.cgi?action=" + action;
        url += "&scModId=" + scModId + "&scSeq=" + scSeq;

    xmlHttp = getXmlHttpObject(doMerItemUpdate);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);

    return;
  } // end of submitMerItemUpdate()

  /*** nkk - since this code is not in use but the fn() is being called
	       in <body> of every shtml file, put a dirty fix here.
       This fix used to be in imageCarousal.js but then the file still
       needed to be called. Not if does not have to be. ***/
  function Carousel() {return;}

  /*------------------------------------------------------*
   * Function: limitText()
   * Description:
   * Notes:  limitField - field where chars limit needs to be implemented
   *         limitCount - field where balance nos. of chars is displayed
   *         limitNum - max allowed chars in the limitField
   *------------------------------------------------------*/
  function limitText(limitField, limitCount, limitNum) {
    var str = '';

    /***
    var f = document.tabForm1;
    for (var i = 0; i < f.elements.length; i++) {
      var el = f.elements[i]; str += " el=" + el.name + "\n";
    }

    for (var i=0; i < document.forms.length; i++) {
      var f = document.forms[i]; str += " f=" + f.name + "\n";
    }
    ***/

    var currLen = limitField.value.length;

    //alert("limitText(anCMS.js): currLen=" + currLen + " limitNum=" + limitNum + " str=" + str);

    if (currLen > limitNum) {
      limitField.value = limitField.value.substring(0, limitNum);
    }
    else {
      limitCount.value = limitNum - currLen;
    }

  } // end of limitText()

  /*------------------------------------------------------*
   * Function: sv() - ShowVideo
   * Description:
   * Notes:
   *------------------------------------------------------*/
  function sv(modId,tabSeq,itemSeq,videoId) {
    showElm(modId, tabSeq, itemSeq);
    var elm = document.getElementById("expandee" + modId + "_" + tabSeq + "_" + itemSeq);  //expandee_#_#
    if (elm) {
      elm.innerHTML = "<a href=\"javascript:hideVideo(" + modId + "," + tabSeq + "," + itemSeq + ",'" + videoId + "')\">- Hide video</a><br />";
      elm.innerHTML += "<object><embed src=\"http://www.youtube.com/v/" + videoId + "&amp;autoplay=1\" type=\"application/x-shockwave-flash\" style=\"width:200px; height:200px; margin:0; padding:0;\"></object>";
      //alert("sv(anCMS.js):modId=" + modId + " tabSeq=" + tabSeq + " videoId=" + videoId + " elm=" + elm);
    }
  } //end of sv()

  /*------------------------------------------------------*
   * Function: hideVideo()
   * Description: 
   * Notes:
   *------------------------------------------------------*/
  function hideVideo(modId,tabSeq,itemSeq,videoId) {
    var elm = document.getElementById("expandee" + modId + "_" + tabSeq + "_" + itemSeq);
    if (elm) {elm.innerHTML = "&nbsp;";}
    hideElm(modId,tabSeq,itemSeq);
  } //end of hideVideo()

  /*------------------------------------------------------*
   * Function: showElm()
   * Description: 
   * Notes:
   *------------------------------------------------------*/
  function showElm(modId,tabSeq,itemSeq) {
    var name = "expandee" + modId + "_" + tabSeq + "_" + itemSeq;
    var elm = document.getElementById(name);
    if (elm) { elm.style.display = "inline"; }

    //hide every element other othan the clicked one
    for (var i = 1; i < 4; i++) {
      for (var j = 1; j < 10; j++) {
        //if (i == tabSeq) {continue;}
        if (i == tabSeq && j == itemSeq) {continue;}
        name = 'expandee' + modId + "_" + i + "_" + j;  //expandee_#_#
        elm = document.getElementById(name);
        if (elm) {elm.style.display = "none";}
      }
    }
  } //end of showElm()

  /*------------------------------------------------------*
   * Function: hideElm()
   * Description: 
   * Notes:
   *------------------------------------------------------*/
  function hideElm(modId,tabSeq,itemSeq) {
    var elm; var name;
    for (var i = 1; i < 4; i++) {
      for (var j = 1; j < 10; j++) {
        name = 'expandee' + modId + "_" + i + "_" + i;
        elm = document.getElementById(name);
        if (elm) {elm.style.display = "none";}
      }
    }
  } //end of hideElm()

  /*------------------------------------------------------*
   * Function: submitUS() - submit User Selection
   * Description: validate selection from the dropdown in user listing
   * Notes:
   *------------------------------------------------------*/
  function submitUS(action, form, newItem) {
    var ok = true;
    var msg = "Form Submission:\n\n";

    var sIdx1,sVal1,sIdx2,sVal2g=0,sVal2=0,sIdx3,sVal3m=0,sVal3=0;

    //user action dropdown
    sIdx1 = form.us1.selectedIndex; sVal1 = form.us1[sIdx1].value;

    //group dropdown
    if (form.us2) {
      sIdx2 = form.us2.selectedIndex; sVal2g = form.us2[sIdx2].value;
    }

    //module dropdown
    if (form.us3) {
      sIdx3 = form.us3.selectedIndex; sVal3m = form.us3[sIdx3].value;
    }

  /**************************************************
100 101 110 111 - 3 dropdowns

Status: Admin (A), Instructor (I), Student (S)

With selected members:
sVal1 |     sVal2      |     sVal3       |    cgi    | act       | State
------|----------------|-----------------|-----------|-----------|------
1)Add | Existing group |                 | grp.cgi   | grpAdd    | 1
  Add | New group      |                 | grp.cgi   | grpNew    | 2
  Add |                | Existing cnhMod | cnhMod.cgi| cnhModAdd | 3
  Add |                | New cnhMod      | cnhMod.cgi| cnhModNew | 4

2)Move| Existing group |                 | grp.cgi   | grpMove   | 5
  Move| New group      |                 | grp.cgi   | grpNew    | 6
  Move|                | Existing cnhMod | cnhMod.cgi| cnhModMove| 7
  Move|                | New cnhMod      | cnhMod.cgi| cnhModNew | 8

3)Copy| Existing group |                 | grp.cgi   | grpCopy   | 9
  Copy| New group      |                 | grp.cgi   | grpNew    | 10
  Copy|                | Existing cnhMod | cnhMod.cgi| cnhModCopy| 11
  Copy|                | New cnhMod      | cnhMod.cgi| cnhModNew | 12

4)Del |                |                 | user.cgi  | uDel      | 13

5)Email| Existing group|                 | mail.cgi  | mailToGrp   | 14
Email  |               | Existing cnhMod | mail.cgi  | mailToCnhMod| 15

Move & Copy will be acroos groups & modules.
No groups and/or cnhMod for 'Delete' option.

   **************************************************/

  var destList = ''; var cbStr = 'cb';
  for (var i=0; i < document.forms.length; i++) {
    var f = document.forms[i];
    if (f.name.indexOf('uListForm') > -1) {
      for (var j=0; j < f.elements.length; j++) {
        var fElem = f.elements[j];
        var idx = fElem.name.indexOf(cbStr);
        if (idx > -1) {
          if (fElem.checked) {   //found a checked checkbox
            if (destList != '') {destList += ',';}
            destList += fElem.name.substring(cbStr.length);
          }
        }
      } //for (var j=0; j < form.elements.length; j++)
    } //if (f.name.indexOf('uListForm') > -1)
  } //for (var i=0; i < document.forms.length; i++)

  //msg += " sVal1=" + sVal1 + " sVal2=" + sVal2;
  //if (form.us3) {msg += " sVal3=" + sVal3 + "\n";}
  //msg += "\n";

  var regExp = /(^\d*)[g|m]$/;

  if (form.us2) {
    if (regExp.test(sVal2g)) {sVal2 = RegExp.$1;}
    else {sVal2 = sVal2g;} //New group...
  }

  if (form.us3) {
    if (regExp.test(sVal3m)) {sVal3 = RegExp.$1;}
    else {sVal3 = sVal3m;} //New module...
  }

  var url=''; var act=''; var state=0;

  if (sVal1==1 || sVal1==2 || sVal1==3) {  //Add,Move,Copy
    if (destList == '') {
      msg += "Please select at least one member! \n";
      ok = false;
    }
    if ( (sVal2==0 || sVal2 == undefined) &&
         (sVal3==0 || sVal3 == undefined) ) {  //Select group or module
      msg += "Please select appropriate destination! \n";
      ok = false;
    }
  }

  if (sVal1==4) {  //Delete
    if (destList == '') {
      msg += "Please select at least one member! \n";
      ok = false;
    }
  }

  if (sVal1==5) {  //Email
    if (sVal2g != '') {
      if (sVal2g != 0 && sVal2g != newItem) {
        if (destList != '') {destList += ',';}
        destList += sVal2g;
      }
    }
    if (form.us3) {
      if (sVal3m != '') {
        if (sVal3m != 0 && sVal3m != newItem) {
          if (destList != '') {destList += ',';}
          destList += sVal3m;
        }
      }
    }
    if (destList == '') {
      if ( (sVal2==0 && sVal3==0) || 
           (sVal2==0 && sVal3==newItem) || (sVal2==newItem && sVal3==0) ) {
        msg += "Please select appropriate destination! \n";
        ok = false;
      }
    }
  } //if (sVal1==5)

       if (sVal1==1 && sVal2>0) {state=1; if (sVal2 == newItem) {state=2;}}
  else if (sVal1==1 && sVal3>0) {state=3; if (sVal3 == newItem) {state=4;}}
  else if (sVal1==2 && sVal2>0) {state=5; if (sVal2 == newItem) {state=6;}}
  else if (sVal1==2 && sVal3>0) {state=7; if (sVal3 == newItem) {state=8;}}
  else if (sVal1==3 && sVal2>0) {state=9; if (sVal2 == newItem) {state=10;}}
  else if (sVal1==3 && sVal3>0) {state=11; if (sVal3 == newItem) {state=12;}}
  else if (sVal1==4) {state=13;}
  else if (sVal1==5 && destList != '') {state=14;}
  else if (sVal1==5){
    state=14;
    if (sVal2>0) {state=15;}
    else if (sVal2 == 0 || sVal2 == newItem) {state=14;}

    if (sVal3>0) {if (state == 15) {state=17;} else {state=16;}}
    else if (sVal3 == 0 || sVal3 == newItem) {state=14;}
  }
  //else {msg += "Invalid action!\n"; ok=false;}

  if (!ok) {alert (msg); return false;}

  //generate url+action based on user selections
  //if cnhMod and group both are selected, cnhMod gets higher precedence
  switch(state) {
    case 1: url='/cgi-bin/anCMS/grp.cgi'; act='geAdd';
      form.destId.value = sVal2;
      break;
    case 2: url='/cgi-bin/anCMS/grp.cgi'; act='grpNew';
      form.destId.value = sVal2;
      break;
    case 3: url='/cgi-bin/anCMS/cnhMod.cgi'; act='cnhModAdd';
      form.destId.value = sVal3;
      break;
    case 4: url='/cgi-bin/anCMS/cnhMod.cgi'; act='cnhModNew'; break;
    case 13: url='/cgi-bin/anCMS/user.cgi'; act='delUsers'; break;
    case 14: url='/cgi-bin/anCMS/mail.cgi'; act='mailToMember'; break;
    case 15: url='/cgi-bin/anCMS/mail.cgi'; act='mailToGrp';
      form.destId.value = sVal2;
      break;
    case 16: url='/cgi-bin/anCMS/mail.cgi'; act='mailToCnhMod';
      form.destId.value = sVal3;
      break;
    case 17: url='/cgi-bin/anCMS/mail.cgi'; act='mailToCnhMod';
      form.destId.value = sVal2 + "," + sVal3;
      break;
    default: alert("submitUS(anCMS.js): Invalid state=" + state); return false;
  } //switch(state)

  msg += " state=" + state + " url=" + url+ " act=" + act + "\n";
  msg += " sVal1=" + sVal1 + " sVal2=" + sVal2 + " sVal3=" + sVal3 + "\n";
  msg += " sVal2g=" + sVal2g + " sVal3m=" + sVal3m + "\n";
  msg += " destList=" + destList;
  //alert("submitUS(anCMS.js): " + msg); return false;

  if (url != '') {form.action = url;}
  if (act != '') {form.act.value = act;}
  if (destList != '') {form.cbDestList.value = destList;}

  form.submit();
  return true;

  } // end of submitUS()

  /*------------------------------------------------------*
   * Function: assign()
   * Description:
   * Notes:
   *------------------------------------------------------*/
  function assign(object) {
    //var object = document.paListForm;
    var index = object.all.selectedIndex;
    if (index > -1) {
      var newoption = new Option(object.all.options[index].text,
                                 object.all.options[index].value,
                                 true, true);
      object.assigned.options[object.assigned.length] = newoption;
      object.all.options[index] = null;
      //object.all.selectedIndex = 0;
    }
  } //end of assign()

  /*------------------------------------------------------*
   * Function: unAssign()
   * Description:
   * Notes:
   *------------------------------------------------------*/
  function unAssign(object) {
    //var object = document.paListForm;
    var index = object.assigned.selectedIndex;
    if (index > -1) {
      var newoption = new Option(object.assigned.options[index].text,
                                 object.assigned.options[index].value,
                                 true, true);
      object.all.options[object.all.length] = newoption;
      object.assigned.options[index] = null;
    }
  } //end of unAssign()

  /*------------------------------------------------------*
   * Function: processList()
   * Description: get selected names and IDs from the selectTo.tmpl
   * Notes:
   *------------------------------------------------------*/
  function processList(form) {
    //var object = document.paListForm;
    //var listLen = object.assigned.length;
    var listLen = form.assigned.length;

    var paName = ""; var paId = "";
    for (var i=0; i < listLen; i++) {
      if (paName != "") {paName += ", "; paId += ", ";}
      //paName += object.assigned.options[i].text;
      //paId += object.assigned.options[i].value;
      paName += form.assigned.options[i].text;
      paId += form.assigned.options[i].value;
    }
    //top.opener.window.document.getElementById("to").innerHTML = paName;
    //top.opener.window.document.form.toList.value = paId;
    form.toName.value = paName;
    form.cbDestList.value = paId;
    //alert("processList(selectTo.php):paName=" + paName + " paId=" + paId);
  } //end of processList()

  /*------------------------------------------------------*
   * Function: selectGrp()
   * Description: Select a group, and show its details
   * Notes: grpId=0 means there are no groups...yet...
   *------------------------------------------------------*/
  function selectGrp(grpId, grpTitle) {
    var act, gSpanId;
    var form = document.grpForm;

    form.parentId.value=grpId; //selected group becomes the parent
    document.getElementById("parentDiv").innerHTML = 
    grpTitle+" <input type=\"hidden\" name=\"parentId\" value=\""+grpId+"\" /><input type=\"hidden\" name=\"parentTitle\" value=\""+grpTitle+"\" />";
    return;

  } // end of selectGrp()

  /*------------------------------------------------------*
   * Function: submitActForm()
   * Desc: This form has 'act' instead of 'action' 
   * Notes: called by grp.tmpl
   *------------------------------------------------------*/
  function submitActForm(act, form, param) {
    form.act.value = act;

    var listLen = form.assigned.length;
    var paId = "";
    for (var i=0; i < listLen; i++) {
      if (paId != "") {paId += ",";}
      paId += form.assigned.options[i].value;
    }
    form.cbDestList.value = paId;

    form.submit();
  } // end of submitActForm()

  /*------------------------------------------------------*
   * Function: submitMailList()
   *
   *------------------------------------------------------*/
  function submitMailList(act, form, param) {

    var msg = "Form Submission:\n\n";

    var ok = true; var mailList = ''; var cbStr = 'cb';

    for (var i=0; i < document.forms.length; i++) {
      var f = document.forms[i];
      if (f.name.indexOf('mailListForm') > -1) {
        for (var j=0; j < f.elements.length; j++) {
          var fElem = f.elements[j];
          var idx = fElem.name.indexOf(cbStr);
          if (idx > -1) {
            if (fElem.checked) {   //found a checked checkbox
              if (mailList != '') {picList += ',';}
              mailList += fElem.name.substring(cbStr.length);
            }
          }
        } //for (var j=0; j < f.elements.length; j++)
      } //if ((f.name.indexOf('mailListForm') > -1))
    } //for (var i=0; i < document.forms.length; i++)

  if (mailList == '') {
    ok = false;
    msg += "Please select at least one item! \n";
  }
  else {form.cbDestList.value = mailList;}

  if (!ok) {alert (msg); return false;}

  form.act.value = act;
  form.submit();

  } // end of submitMailList()

  /*------------------------------------------------------*
   * Function: submitConsent()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitConsent(act, form, param) {
    alert("submitConsent():act=" + act + " form=" + form + " param=" + param);
    form.act.value = act;
    form.submit();
    return;
  } // end of submitConsent()

  /*------------------------------------------------------*
   * Function: handleBrowse()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function handleBrowse(form, tabSeq, scSeq) {

    var noBrowseVal = 9; //BAD! the value of attachType for which Browse btn is not visible (YouTube)

    var elem = "scAttachType" + tabSeq + scSeq;
    var idx = eval("form." + elem + ".selectedIndex");
    //var val = eval("form." + elem + "[" + idx + "].value");
    var tmpVal = eval("form." + elem + "[" + idx + "].value");
    var vals = tmpVal.split(/:/); var val = vals[0];

    //alert("handleBrowse():form=" + form + " elem=" + elem + " tabSeq=" + tabSeq + " scSeq=" + scSeq + " idx=" + idx + " val=" + val);

    if (noBrowseVal == val) { //9 is YouTube; turn OFF Browse btn for YouTube
      eval("document.getElementById('noBrowseSpan" + tabSeq + scSeq + "').style.display='inline'");
      eval("document.getElementById('browseSpan" + tabSeq + scSeq + "').style.display='none'");
      eval("document.getElementById('merItemSpan" + tabSeq + scSeq + "').style.display='none'");

      if ( eval("document.getElementById('merItemSpan" + tabSeq + scSeq + "')") ||
           eval("window.merItemSpan" + tabSeq + scSeq) ) {
        eval("document.getElementById('merItemSpan" + tabSeq + scSeq + "').style.display='none'");
      }
    }
    else { //turn ON Browse btn for 1/attachment and 2/image
      eval("document.getElementById('noBrowseSpan" + tabSeq + scSeq + "').style.display='none'");
      eval("document.getElementById('browseSpan" + tabSeq + scSeq + "').style.display='inline'");

      var scAttachF = eval("document.getElementById('scAttachF" + tabSeq + scSeq + "').value");
      var dispStat = eval("document.getElementById('merItemSpan" + tabSeq + scSeq + "').style.display");

      if (1 == val) { //1 is attachment; turn ON autoUpload for attachment, and OFF for 'Inline image'
        if (scAttachF != '') {dispStat = 'inline';}
        eval("document.getElementById('merItemSpan" + tabSeq + scSeq + "').style.display='"+dispStat+"'");
      }
      else {
        eval("document.getElementById('merItemSpan" + tabSeq + scSeq + "').style.display='none'");
      }

      if ( eval("document.getElementById('merItemSpan" + tabSeq + scSeq + "')") ||
           eval("window.merItemSpan" + tabSeq + scSeq) ) {
        eval("document.getElementById('merItemSpan" + tabSeq + scSeq + "').style.display='inline'");
      }
    }

    return;
  } // end of handleBrowse()

  /*------------------------------------------------------*
   * Function: submitModItem()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
function submitModItem(action, form, param, mSpanId, modId, remId, remAuth) {
    var itemCount = form.itemCount.value;
    var script = param;
    modSpanId = mSpanId; //set it so that doModConfig() can access it

    //strip off the args for cetain mods - syndicated news
    var txt = '?';
    var i = script.indexOf(txt);
    if (i != -1) {script = script.substring(0,i);}

    var url = "/cgi-bin/anCMS/" + script;
        url += "?action=" + action + "&itemCount=" + itemCount;
        url += "&modId=" + modId;
        url += "&remId=" + remId;
        url += "&remAuth=" + remAuth;

    xmlHttp = getXmlHttpObject(doModConfig);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;

  } //end of submitModItem()

  /*------------------------------------------------------*
   * Function: submitRes()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitRes(resSpan,action,resId,sText,so,cso,foundCount,sn,catIdU,scIdU,pfId) {
    modSpanId = resSpan; //set it so that doModConfig() can access it

    var resSpanW = document.getElementById(resSpan).offsetWidth;
    //alert("resSpanW=" + resSpanW);

    var url = "/cgi-bin/anCMS/res.cgi";
        url += "?action=" + action + "&iId=" + resId;
        url += "&sText=" + sText;
        url += "&so=" + so;
        url += "&cso=" + cso;
        url += "&f=" + foundCount;
        url += "&sn=" + sn;
        url += "&w=" + resSpanW;
        url += "&catIdU=" + catIdU;
        url += "&scIdU=" + scIdU;
        url += "&pfId=" + pfId;

    xmlHttp = getXmlHttpObject(doModConfig);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
    return;

  } //end of submitRes()

  /*------------------------------------------------------*
   * Function: doSubmitWeather()
   * Desc: 
   *------------------------------------------------------*/
  function doSubmitWeather() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var errId = document.getElementById(weatherErrSpanId);
      var editId = document.getElementById(weatherEditSpanId);
      var contentId = document.getElementById(weatherContentSpanId);

      var content = xmlHttp.responseText;
      var content = content.split("\n").join("");

      var ar = content.match(/^\[(\d*),\s*(.*)\](.*)/); // [err, errMsg]template text...

      var err = parseInt(RegExp.$1);
      var errMsg = RegExp.$2; if (isNaN(err)) {err=0;}
      content = RegExp.$3; //err & errMsg extracted; set the rest to content

      switch(err) {
        case 0:
          if (content != "") {contentId.innerHTML = content;}
          if (errMsg != "") {
            errId.style.display='inline';
            errId.innerHTML = "<font color=\"red\">" + errMsg + "</font><br />";
	  }
          else {
            // close weatherLoc
            editId.style.display='none';
	  }
        break;

        case 1:
          if (errMsg != "") {
            errId.style.display='inline';
            errId.innerHTML = "<font color=\"red\">" + errMsg + "</font><br />";
	  }
        break;

        default: 
          break;
      } // end of switch

      //alert("doSubmitWeather(anCMS.js): err=" + err + " errMsg=" + errMsg + " content=" + content);
      //alert("doSubmitWeather(anCMS.js): err=" + err + " errMsg=" + errMsg);

    }  //if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

    return;

  } //end of doSubmitWeather()

  /*------------------------------------------------------*
   * Function: submitWeather()
   * Desc:
   * Notes:
   *------------------------------------------------------*/
  function submitWeather(act, modId, alive) {

    var form = 'weatherF' + modId;
    var editId = 'edit' + modId;
    var errId = 'err' + modId;
    var contentId = 'modSpan' + modId;

    eval("document.getElementById('" + errId + "').style.display='none'");

    if (act == "cancelW") {
      eval("document.getElementById('" + editId + "').style.display='none'");
      return false;
    }

    if (act == "okW") {
      var areaList = eval("document."+form+".areaList.value");
      var ut = eval("document."+form+".ut.value");
      var fcastD = eval("document."+form+".fcastD.value");

      //validate areaList for (a) invalid chars (b) comma separation (c) max (d) blank

      /*****************************************************
      if (alive == 0) {
        eval("document.getElementById('" + errId + "').innerHTML='<font color=\"red\">Please log on to save your settings!<br/></font>'");
        eval("document.getElementById('" + errId + "').style.display='inline'");
        return false;
      }
      *********************************************/

      if (stripSpaces(areaList) == "") {
        eval("document.getElementById('" + errId + "').innerHTML='<font color=\"red\">Input text is all blank!<br/></font>'");
        eval("document.getElementById('" + errId + "').style.display='inline'");
        return false;
      }

      var url = "/cgi-bin/anCMS/weather.cgi";;
          url += "?act=" + act + "&modId=" + modId;
          url += "&areaList=" + areaList;
          url += "&ut=" + ut;
          url += "&fcastD=" + fcastD;
	  //rsCode?

    } // okW

    weatherContentSpanId = contentId; //set it so that doSubmitWeather() can access it
    weatherErrSpanId = errId; //set it so that doSubmitWeather() can access it
    weatherEditSpanId = editId; //set it so that doSubmitWeather() can access it

    xmlHttp = getXmlHttpObject(doSubmitWeather);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);

    /* alert("submitWeather(anCMS.js): form=" + form + " modId=" + modId +
       " areaList=" + areaList + " weatherErrSpanId=" + weatherErrSpanId + " url=" + url); */

    return false;

  } //end of submitWeather()

  /*------------------------------------------------------*
   * Function: textLimit()
   * Desc:
   * Notes: <textarea cols="20" rows="2" value="" onkeyup="textLimit(this, 40);"></textarea>
   *------------------------------------------------------*/
  function textLimit(field, maxlen) {
    if (field.value.length > maxlen + 1)
    alert('your input has been truncated!');
    if (field.value.length > maxlen)
    field.value = field.value.substring(0, maxlen);
  } //end of textLimit()

  /*------------------------------------------------------*
   * Function: evalResponse()
   * Desc: Evaluate xmlHttp.responseText;
   * Notes: After approving a pending channel, we need to redirect to pending
   *      : another channel, but since this is a AJAX call, we need to evaluate
   *      : the server response first, and then decide course of action.
   * update mer set pending=1 where modId > 1013;
   * UPDATE module SET pending=10 WHERE modId=24;
   * delete from tab where tabModId > 1013 and ttCode=99;
   *------------------------------------------------------*/
  function evalResponse(resp) {
    var str='proceed';

    var pattern = /\s+/;
    var respArr = resp.split(pattern);

    //we expect response to be 'action param1 param2...'
    //var msg='';
    //for (var i=0; i < respArr.length; i++) {
    //msg += i + '=' + respArr[i] + ' ';
    //}

    //alert("evalResponse(anCMS.js): msg:" + msg);

    if (respArr[0] == 'redirect') {
      redirectTo(respArr[1]);
      //redirectTo("http://127.0.0.1/cgi-bin/anCMS/mer.cgi?action=pending");
      str='doNotProceed';
    }

    return str;
  } //end of evalResponse()

  /*------------------------------------------------------*
   * Function: doSubmitCh()
   * Desc: 
   *------------------------------------------------------*/
  function doSubmitCh() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      //var elem = modSpanId;
      var elem = document.getElementById(modSpanId);

      var str = '';
      //alert("submitCh(anCMS.js): xmlHttp.responseText=" + xmlHttp.responseText);

      if (evalResponse(xmlHttp.responseText) == 'doNotProceed') {
        return false;
      }

      elem.innerHTML = xmlHttp.responseText;

      //alert("submitCh(anCMS.js): elem=" + elem + " elem.innerHTML=" + elem.innerHTML);

      //eval("document.getElementById('" + elem + "').style.display='inline'");
      //eval(elem + ".style.display='inline'");
      eval("document.getElementById('" + modSpanId + "').style.display='inline'");

      //if there is any JS file included, execute it
      var x = elem.getElementsByTagName("script");
      for (var i=0;i<x.length;i++) {
        //alert("submitCh(anCMS.js): i=" + i + " x=" + x + " length=" + x.length + " text=" + x[i].text);
        eval(x[i].text);
        //str += " i=" + i + " x=" + x + " length=" + x.length + " text=" + x[i].text + "\n";
      }
      //alert("submitCh(anCMS.js): str=" + str);
    }

    return false;

  } //end of doSubmitCh()

  /*------------------------------------------------------*
   * Function: submitCh()
   * Desc: submit Channel
   * Notes: We use this submission for 
   * ">>> After you have set up your Tabs, click here to go to Step 2 >>>"
   * and "Save" links 'cos we want the Mer items area/form to be updated via AJAX.
   *------------------------------------------------------*/
  function submitCh(act, spanId, merModId) {

    modSpanId = spanId; //set it so that doSubmitCh() can access it

    xmlHttp = getXmlHttpObject(doSubmitCh);
    //xmlHttp = getXmlHttpObject(doModConfig);

    var str="";
    var defFound=0;

    var spanW = document.getElementById('tdW').offsetWidth;
    str += "&spanW=" + spanW;
    str += "&modId=" + merModId;

    var form = document.merMaintForm;
    for (var i = 0; i < form.elements.length; i++) {
      var formElem = form.elements[i];
      if ( formElem.name.indexOf('tabSeq')   > -1 ||
           formElem.name.indexOf('tabTitle') > -1 ||
           formElem.name.indexOf('ttCode')   > -1 ||
           formElem.name.indexOf('merTitle') > -1 ||
           formElem.name.indexOf('merEmail') > -1 ||
           formElem.name.indexOf('merLink')  > -1 ) {
        str += "&" + formElem.name + "=" + formElem.value;
      }
      //if ( formElem.name.indexOf('tabDefSel') > -1 || formElem.name.indexOf('tabActive') > -1) {
      if ( formElem.name.indexOf('tabDefSel') > -1) {
        if (formElem.checked) {   //found a checked checkbox
          //str += "&" + formElem.name + "=" + html_entity_decode(formElem.value);
          str += "&" + formElem.name + "=" + formElem.value;
          defFound = 1;
	}
      }
    }
    //alert("submitCh(anCMS.js):str=" + str);

    if (defFound == 0) { //we need a default selected Tab
      str += "&tabDefSel1=1";
      document.merMaintForm.tabDefSel1.checked=1;
    }

    /*** following moved to server-side
    document.tabForm9P.btnPreview.disabled=false;
    document.tabForm9U.btnSave.disabled=false;
    ***/

    var url = "/cgi-bin/anCMS/mer.cgi?action=" + act;
    if (str != "") {url += str;}

    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);

    return;

  } //end of submitCh()

  /*------------------------------------------------------*
   * Function: validateMerChData()
   * Desc: submit Channel for save/update
   * Notes:
   *------------------------------------------------------*/
  function validateMerChData() {

    var str = "";

    var el = document.merMaintForm.merTitle;
    if (stripSpaces(el.value) == "") {
      str += "Channel title can not be blank! \n";
    }

    el = document.merMaintForm.merEmail;
    if (el) {  // el is not defined when user is logged on
      if (stripSpaces(el.value) == "") {
        str += "Email can not be blank! \n";
      }
      else {
        //var filter = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
        //if (!filter.test(el.value)) {
        var errMsg = validEmail(el.value);
        if (errMsg != '') {
          //str += "Please provide a valid email address!";
          str += "Invalid email - " + errMsg + "!";
        }
      }
    }

    el = document.merMaintForm.fName;
    if (el) {  // el is not defined when user is logged on
      if (stripSpaces(el.value) == "") {
        str += "First name can not be blank! \n";
      }
    }

    return str;

  } //end of validateMerChData()

  /*------------------------------------------------------*
   * Function: submitMerSave()
   * Desc: submit Channel for save/update
   * Notes:
   *------------------------------------------------------*/
  function submitMerSave(act, spanId, merModId) {

    var errMsg = validateMerChData();

    if (errMsg != "") {alert(errMsg); return;}

    modSpanId = spanId; //set it so that doSubmitCh() can access it

    xmlHttp = getXmlHttpObject(doSubmitCh);

    var spanW = document.getElementById('tdW').offsetWidth; //get <td> width

    var url  = "/cgi-bin/anCMS/mer.cgi";
    var str  = "action=" + act;
        str += "&spanW=" + spanW;
        str += "&modId=" + merModId;
        str += "&" + getMerChData();

    //alert("submitMerSave(anCMS.js):modId=" + merModId + "\n" + "merChData=" + getMerChData());

    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", str.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(str);
    return;

  } //end of submitMerSave()

  /*------------------------------------------------------*
   * Function: submitMerPreview()
   * Desc: Submit channel for preview
   * Notes:
   *------------------------------------------------------*/
  function submitMerPreview(act, modId) {

    var merChData = getMerChData();

    //alert("submitMerPreview(anCMS.js):modId=" + modId + "\n" + "merChData=" + merChData);

    var winW  = 400;  //width
    var winH  = 600;  //height
    var winSB = 'no'; //scrollbars

    var winStr = 'width='+winW+',height='+winH+',scrollbars='+winSB;
    winStr += ',menubar=no,resizable=yes,location=no,statusbar=no,screenX=150,screenY=150,top=150,left=150';

    //before we enable 'Save' and 'Done' buttons, make sure inputs are all valid
    var errMsg = validateMerChData();
    //alert("submitMerPreview(anCMS.js):errMsg=" + errMsg);
    if (errMsg != "") {document.tabForm9U.btnSave.disabled=true;} //U for Update/Save
    else {document.tabForm9U.btnSave.disabled=false;}

    document.tabForm9P.merChData.value=merChData; //P for Preview
    document.tabForm9P.action.value=act;
    window.open('','newWin',winStr);
    window.setTimeout("document.tabForm9P.submit();",100);
    //if (window && window.focus) {window.focus();}
    //document.tabForm9P.submit();

  } // end of submitMerPreview()

  /*------------------------------------------------------*
   * Function: getMerChData()
   * Desc:  Get all the data for all the channels for the merchant
   * Notes:
   *------------------------------------------------------*/
  function getMerChData() {
    var str=''; var strP=''; var defFound=0;
    for (var i=0; i < document.forms.length; i++) {
      var f = document.forms[i];
      //str += " f=" + f.name + "; ";
      if ( (f.name.indexOf('merMaintForm') > -1) ||
           (f.name.indexOf('tabForm')      > -1) ) { //multiple tabForm## are expected
        for (var j = 0; j < f.elements.length; j++) {
          var el = f.elements[j];
	  if ( (el.name.indexOf('tabDefSel') > -1) || (el.name.indexOf('tabActive') > -1) ||
	       (el.name.indexOf('scCenter')  > -1) || (el.name.indexOf('scInform')  > -1) ||
	       (el.name.indexOf('scActive')  > -1) || (el.name.indexOf('scDel')     > -1) ||
               (el.name.indexOf('merInform') > -1) ) {
            if (el.checked) {
              if (str != '') {str += '&';}
              str += el.name + "=" + el.value; //found a checked checkbox
	      strP += "name=" + el.name + " value=" + el.value + "\n";
              if (el.name.indexOf('tabDefSel') > -1) {defFound=1;}
            }
          }
	  else {
            if ( (el.name != 'merChData') //or else, it keeps getting picked at every submit
                 && (el.name != 'action') ) {
              if (str != '') {str += '&';}
              str += el.name + "=" + html_entity_decode(el.value);
	    }
	  }
        } //for (var j = 0; j < f.elements.length; j++)
      }
    } //for (var i = 0; i < document.forms.length; i++)

    //alert(str);

    if (defFound == 0) { //if no default selected; hand-pick the first one
      str += "&tabDefSel1=1";
      document.merMaintForm.tabDefSel1.checked=1;
    }

    return str;
  } // end of getMerChData()

  /*------------------------------------------------------*
   * Function: html_entity_decode()
   * Desc: 
   * Notes:
   *------------------------------------------------------*/
  function html_entity_decode(str) {
    //var newStr = str.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
    //var newStr = str.replace(/&/g,"&amp;");
    var newStr = str.replace(/&/g,"{amp}");
    //var newStr = escape(encodeURI((str));
    return newStr;
  } //end of html_entity_decode()

  /*------------------------------------------------------*
   * Function: generateEmailAddr()
   * Desc: 
   * Notes:
   *------------------------------------------------------*/
  function generateEmailAddr(userN, hostN) {
    var atsign = "&#64;";
    //var domain = ".calpoly.edu";
    //var addr = userN + atsign + hostN + domain;
    var addr = userN + atsign + hostN;
    document.write("<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" + addr + "<\/a>");
  } //end of generateEmailAddr()

/*------------------------------------------------------*
 * Function: setDefaultTab()
 * Description: Uncheck the rest, check the source CB.
 *            : Callled from merMaint.tmpl. Similar to Tabs.setDefaultTabInStep1()
 *------------------------------------------------------*/
function setDefaultTab (form, clickedTabSeq) {
  var tabDefSelStr = 'tabDefSel';
  for (var j=0; j < form.elements.length; j++) {
    var el = form.elements[j];
    if (el.name.indexOf(tabDefSelStr) > -1) {
      var tmpArr2 = el.name.split(tabDefSelStr); //split into tabDefSel & tabSeq
      if (tmpArr2[1] == clickedTabSeq) { //this tab in Step 1 is same as what user clicked on in Step 2
        el.checked=1;
      }
      else {el.checked=0;}
    }
  }

} //end of toggleDefaultTab()

  /*------------------------------------------------------*
   * Function: doAutoUpload()
   * Desc: 
   *------------------------------------------------------*/
  function doAutoUpload() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(modSpanId);
      elem.innerHTML = xmlHttp.responseText;

      //eval("document.getElementById('" + modSpanId + "').style.display='inline'");
    }

    return false;

  } //end of doAutoUpload()

  /*------------------------------------------------------*
   * Function: submitAutoUpload()
   * Desc: 
   * Notes: Use this sub for file uploads for Mer tabs in Step 2
   *------------------------------------------------------*/
  function submitAutoUpload(act, spanId, tabSeq, scSeq, scModId) {

    modSpanId = spanId; //set it so that doAutoFileUpload() can access it

    document.getElementById(spanId).innerHTML = '<img src="pics/site/waitAnim.gif" />';
    document.getElementById(spanId).style.display = 'inline';

    if (act == "autoUploadDel") {
      //for an image/attachment file in the channel, we do not delete it until the channel is saved.
      //BUT, we need to not show it in the Preview.
      eval("document.tabForm"+tabSeq+scSeq+".scAttachF"+tabSeq+scSeq+".value=''");
      eval("document.tabForm"+tabSeq+scSeq+".scAttach"+tabSeq+scSeq+".value=''");
    }

    xmlHttp = getXmlHttpObject(doAutoUpload);

    var url = "/cgi-bin/anCMS/mer.cgi";
    var str  = "action=" + act;
        str += "&tabSeq=" + tabSeq;
        str += "&scSeq=" + scSeq;
        str += "&scModId=" + scModId;
        str += "&source=";  //leave it blank for Ajax call, it is set to 'formSubmit' in the form

    if (act == "autoUpload") {  //image for Slideshow
      var scAttachType = eval("document.tabForm"+tabSeq+scSeq+".scAttachType"+tabSeq+scSeq+".value");
      //alert("submitAutoUpload(anCMS.js):scAttachType" + scAttachType);
      str += "&scAttachType=" + scAttachType;
    }

    xmlHttp.open("GET", url+"?"+str, true);
    xmlHttp.send(null);

    /***
    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-type", "multipart/form-data"); //Err! Malformed multipart POST: data truncated
    xmlHttp.setRequestHeader("Content-length", str.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(str);
    ***/

    if (act == "autoUpload" || act == "autoUploadSS") {
      eval("document.tabForm" + tabSeq + scSeq + ".submit()");
    }

    return;

  } //end of submitAutoUpload()

  /*------------------------------------------------------*
   * Function: doChTellSomeone()
   * Desc: Tell someone about this channel
   *------------------------------------------------------*/
  function doChTellSomeone() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(modSpanId);
      elem.innerHTML = xmlHttp.responseText;
    }

    return false;

  } //end of doChTellSomeone()

  /*------------------------------------------------------*
   * Function: doChSubs()
   * Desc: Channel Subscription
   *------------------------------------------------------*/
  function doChSubs() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      var elem = document.getElementById(modSpanId);
      elem.innerHTML = xmlHttp.responseText;
    }

    return false;

  } //end of doChSubs()

  /*------------------------------------------------------*
   * Function: submitChSubs()
   * Desc: Submit channel subscription.
   * Notes: To avoid spam form submissions, we would generally use CAPTCHA.
   *      : However, we can also use 'confirm()' popup to have the same effect.
   *------------------------------------------------------*/
  function submitChSubs(act, modId, form, spanId) {

    var url    = "/cgi-bin/anCMS/mer.cgi";
        urlStr = "action=" + act + "&modId=" + modId;

    var errStr='';
    if (act == "subscribe") {
      xmlHttp = getXmlHttpObject(doChSubs);
      var email = stripSpaces(eval(form+".email.value"));
      if (email == "") {errStr += "Email can not be blank! \n";}
      else {
        //var filter = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
        //if (!filter.test(email)) {
        var errMsg = validEmail(email);
        if (errMsg != '') {
          //errStr += "Please provide a valid email address!\n";
            errStr += "Invalid email - " + errMsg + "\n";
        }
        else {urlStr += "&email=" + email;}
      } //else
    }
    else {
      if (act == "tellSomeone") {
        xmlHttp = getXmlHttpObject(doChTellSomeone);
        if (eval(form+".fromEmail")) { //when user is logged on, this field is not available
          var fromEmail = stripSpaces(eval(form+".fromEmail.value"));
          if (fromEmail == "") {errStr += "'From' email can not be blank! \n";}
          else {
            //var filter = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
            //if (!filter.test(fromEmail)) {
            var errMsg = validEmail(fromEmail);
            if (errMsg != '') {
	      //errStr += "Please provide a valid 'From' email address!\n";
              errStr += "Invalid 'From' email - " + errMsg + "\n";
            }
            else {urlStr += "&fromEmail=" + fromEmail;}
          } //else
	} //if (eval(form+".fromEmail"))

        var toEmail = stripSpaces(eval(form+".toEmail.value"));
        if (toEmail == "") {errStr += "'To' email can not be blank! \n";}
        else {
          //var filter = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
          //if (!filter.test(toEmail)) {
          var errMsg = validEmail(toEmail);
          if (errMsg != '') {
            //errStr += "Please provide a valid 'To' email address!\n";
            errStr += "Invalid 'To' email(s) - " + errMsg + "\n";
          }
          else {urlStr += "&toEmail=" + toEmail;}
        } //else
      } //if (act == "tellSomeone")
      else {
        alert("submitChSubs(anCMS.js): invalid act=" + act);
        return;
      }
    }

    if (eval(form+".uA")) { //when user is logged on, this field is not available
      var uA = stripSpaces(eval(form+".uA.value"));
      var qA = eval(form+".qA.value");
      //alert ("submitChSubs(anCMS.js):qA=" + qA + " uA=" + uA);
      if (uA != qA) {errStr += "Incorrect answer! \n";}
      //else {urlStr += "&qA=" + qA + "&uA=" + uA;}
      urlStr += "&qA=" + qA + "&uA=" + uA;
    }

    if (errStr != '') {alert(errStr); return;}

    var merTitle = eval(form+".merTitle.value");
    urlStr += "&merTitle=" + merTitle;

    modSpanId = spanId; //set it so that doChSubs() can access it

    //alert("submitChSubs(anCMS.js): urlStr=" + urlStr);

    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", urlStr.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(urlStr);
    return;

  } //end of submitChSubs()

