// functions for ETD main Website forms

var basic_reqdflds = new Array('school', 'countryId', 'currentSite', 'prim_firstName', 'prim_lastName', 'prim_title', 'prim_email', 'prim_phone', 'prim_countryId', 'prim_address1', 'prim_city', 'prim_stateId', 'prim_zip');

var basic_attrlabels = new Array(labels['univname'], labels['univcntry'], labels['primadminfirst'], labels['primadminlast'], labels['primadminjob'], labels['primadminemail'], labels['primadminphone'], labels['primadmincntry'], labels['primadminaddr'], labels['primadmincity'], labels['primadminstate'], labels['primadminzip']);

/*
var other_reqdflds = new Array('coAuthor');
var other_attrlabels = new Array('CoAuthors allowed?');
*/

var puboptionsetup_reqdflds = new Array('degreeType', 'pubopt', 'allowEmbargo', 'allow3rdPartySales', 'allow3rdPartySearch');
var puboption_attrlabels = new Array(labels['degreegrad'], labels['puboptoffered'], labels['allowemb'], labels['thirdpartysales'], labels['thirdpartysrch']);

var other_reqdflds = new Array('siteLanguage');
var other_attrlabels = new Array(labels['language']);

var ftp_reqdflds = new Array('ftp_name', 'ftp_email', 'ftp_phone');
var ftp_attrlabels = new Array(labels['ftpname'], labels['ftpemail'], labels['ftpphone']);

var contact_reqdflds = new Array('dean_firstName', 'dean_lastName', 'dean_title', 'dean_email', 'dean_phone', 'coord_firstName', 'coord_lastName', 'coord_title', 'coord_email', 'coord_phone', 'payment', 'inv_countryId', 'inv_address1', 'inv_city', 'inv_stateId', 'inv_zip');

var contact_attrlabels = new Array(labels['gradfirst'], labels['gradlast'], labels['gradjob'], labels['grademail'], labels['gradphone'], labels['dtfirst'], labels['dtlast'], labels['dtjob'], labels['dtemail'], labels['dtphone'], labels['payforpub'], labels['invcntry'], labels['invaddr'], labels['invcity'], labels['invstate'], labels['invzip']);

var contact_attrlabels_CAN = new Array(labels['gradfirst'], labels['gradlast'], labels['gradjob'], labels['grademail'], labels['gradphone'], labels['tfirst'], labels['tlast'], labels['tjob'], labels['temail'], labels['tphone'], labels['payforpub'], labels['invcntry'], labels['invaddr'], labels['invcity'], labels['invstate'], labels['invzip']);
var order_reqdflds = new Array('standing_firstName', 'standing_lastName', 'standing_title', 'standing_email', 'standing_phone', 'shipping_countryId', 'shipping_address1', 'shipping_city', 'shipping_stateId', 'shipping_zip', 'invoice_countryId', 'invoice_address1', 'invoice_city', 'invoice_stateId', 'invoice_zip');

var order_attrlabels = new Array(labels['sofirst'], labels['solast'], labels['sojob'], labels['soemail'], labels['sophone'], labels['sacntry'], labels['saaddr'], labels['sacity'], labels['sastate'], labels['sazip'], labels['invcntry'], labels['invaddr'], labels['invcity'], labels['invstate'], labels['invzip'])

var name_flds = new Array('name', 'firstName', 'middleName', 'lastName', 'suffix', 'title', 'email', 'phone');

var name_reqdflds = new Array('firstName', 'lastName', 'title', 'email', 'phone');

var name_attrlabels = new Array(labels['firstName'], labels['lastName'], labels['jobtitle'], labels['email'], labels['phone']);

var addr_flds = new Array('countryId', 'countryIdPick', 'school', 'address1', 'address2', 'address3', 'city', 'stateId', 'state', 'stateIdPick', 'zip');

var addr_reqdflds = new Array('countryId', 'address1', 'city', 'stateId', 'zip');
var addr_attrlabels = new Array(labels['country'], labels['address'], labels['city'], labels['stateprov'], labels['zip']);


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

function sitesetup_init() {
  if (document.forms[0].prim_stateId &&
     (document.forms[0].prim_stateId.options && document.forms[0].prim_stateId.options.length))  {
   showItem("prim_stateIdlabel_reqd");
   showItem("prim_stateId_reqd");
  }

  if (document.forms[0].inv_stateId &&
     (document.forms[0].inv_stateId.options && document.forms[0].inv_stateId.options.length))  {
   showItem("inv_stateIdlabel_reqd");
   showItem("inv_stateId_reqd");
  }

  if (document.forms[0].shipping_stateId &&
     (document.forms[0].shipping_stateId.options && document.forms[0].shipping_stateId.options.length))  {
   showItem("shipping_stateIdlabel_reqd");
   showItem("shipping_stateId_reqd");
  }

  if (document.forms[0].invoice_stateId &&
     (document.forms[0].invoice_stateId.options && document.forms[0].invoice_stateId.options.length))  {
   showItem("invoice_stateIdlabel_reqd");
   showItem("invoice_stateId_reqd");
  }

  if (document.forms[0].stateId &&
     (document.forms[0].stateId.options && document.forms[0].stateId.options.length))  {
   showItem("stateIdlabel_reqd");
   showItem("stateId_reqd");
  }

  //checkEmbargos(document.forms[0]);
}

/** get value from field   **/
function getValue(theField) {

  var value = "";
  var fldName = theField.name;
  var theForm = document.forms[0];

  if (theField.type.indexOf("select") != -1) {
    var theChoices = theField.options;
    var numChoices = theChoices.length;

    for (var j=0; j < theChoices.length; j++) {
      if (theField.options[j].selected) {
        value = theField.options[j].value;
         break;
      }
    }
    if (value.indexOf("Select ") != -1) {
      value = "";
    }

    // check if state field has any selectable states - if not don't require it
    if (!value && (fldName.indexOf("stateId") != -1)) {
      if (!numChoices) {
            value = "n/a";
       }
    }
    if (value && ((fldName.indexOf("countryId") != -1) ||
                  (fldName.indexOf("stateId") != -1))) {
      updatePickValue(document.forms[0], theField);
    }
  }
  else if (theField.type.indexOf("checkbox") != -1) {
    if (theField.checked) {
      value = theField.value;
    }
  }
  else if (theField.type.indexOf("radio") != -1) {
    if (theField.length) {
      for (var k = 0; k < theField.length; k++) {
        if (theField[k].checked) {
          value = theField[k].value;
        }
      }
    }
    else {
      if (theField.checked) {
        value = theField.value;
      }
    }
  }
  else {
    value = theField.value;
  }
  return value;
}

function checkNum(theField) {
  return validNum(theField, true);
}

function validNum(theField, showMsg) {
  var valid = true;
  var num = theField.value;
  var errmsg = "";
  if (num) {
    if (!isInteger(num)) {
      errmsg = errors['nonnum'] + " (" + num + ").  " + errors['enternum'];
      valid = false;
    }
    else if (num < 0) {
      errmsg = errors['negnum'] + " (" + num + ").  " +  errors['enterposnum'];
      valid = false;
    }
    if (!valid) {
      if (showMsg) {
        alert(errmsg);
        theField.value = ""
        theField.select();
        theField.focus();
        return valid;
      }
      else {
        return errmsg;
      }
    }
  }
  if (showMsg) {
    return valid;
  }
  else {
   return errmsg;
  }
}


/** check required fields for setup   **/
function validateSetup(theForm, sectionVal) {
  var valid = true;
  var errmsg = "";

  // check for required fields
  var missingFlds = new Array();
  var reqdflds;
  var attrlabels;

  if (sectionVal == 'sitesetup') {
    reqdflds = basic_reqdflds;
    attrlabels = basic_attrlabels;
  }
  else if (sectionVal == 'puboptionsetup') {
    reqdflds = puboptionsetup_reqdflds;
    attrlabels = puboptionsetup_attrlabels;
  }
  else if (sectionVal == 'contactsetup') {
    reqdflds = contact_reqdflds;
    attrlabels = contact_attrlabels;
    if (document.forms.info.geoclass.value == "CAN") {
      attrlabels = contact_attrlabels_CAN;
    }
  }
  else if (sectionVal == 'ordersetup') {
    reqdflds = order_reqdflds;
    attrlabels = order_attrlabels;
  }
  else if (sectionVal == 'othersetup') {
    reqdflds = other_reqdflds;
    attrlabels = other_attrlabels;
  }

//alert("validateSetup: sectionVal=" + sectionVal);
  // check that there is a value for each required field 
  for (var i = 0; i < reqdflds.length; i++) {
    var fldName = reqdflds[i];
    var fld = theForm[fldName];

    if (fld) {
      var value = "";
      if (!fld.type) {
        if (fld.length) {
          for (var k = 0; k < fld.length; k++) {
            value = getValue(fld[k]);
            if (value) { break; }
          }
        }
      }
      else {
        value = getValue(fld);
      }

      if (!value || value == 0) {
        var fieldLabel = attrlabels[i];
        if (fieldLabel) {
          missingFlds[missingFlds.length] = fieldLabel;
        }
      }
      else {
        if (fldName.indexOf("email") != -1) {
          if (! validEmail(value)) {
           errmsg += attrlabels[i] + ": " + errors['invalemailfmt'] + "\n" +
                     errors['reenteremail'];
           valid = false;
          }
        }
      }
    }
  }

  if (sectionVal == 'sitesetup') {
    // now check that there is a value for each required field if a 
    // 	contact was entered
    var totOthers = theForm.totOtherAdmins.value;
    for (var j = 0; j < totOthers-1; j++) {
      var fname = "firstName_" + j;
      var mname = "middleName_" + j;
      var lname = "lastName_" + j;
      if (theForm[fname].value || theForm[mname].value || theForm[lname].value) {
        for (var i = 0; i < name_reqdflds.length; i++) {
          var fldName = name_reqdflds[i] + "_" +  j;
          var fld = theForm[fldName];
          var value = "";

          if (!fld.type) {
            if (fld.length) {
              for (var k = 0; k < fld.length; k++) {
                value = getValue(fld[k]);
              }
            }
          }
          else {
            value = getValue(fld);
          }

          var fieldLabel = labels['otheradmin'] + " " + j + ": " + name_attrlabels[i];
          if (!value || value == 0) {
            if (name_attrlabels[i]) {
              missingFlds[missingFlds.length] = fieldLabel;
            }
          }
          else {
            if (fldName.indexOf("email") != -1) {
              if (! validEmail(value)) {
                errmsg += fieldLabel + " " + errors['invalemailfmt'] + "\n" +
                          errors['reenteremail'];
                valid = false;
              }
            }
          }
        }
      }
    }
  }
  else if (sectionVal == 'puboptionsetup') {
    // check that there are embargo values specified if necessary
    var allowEmbValue = 0;
    var delayRelease = false;
    var embField = theForm.allowEmbargo;
    for (var i = 0; i < embField.length; i++) {
      if (embField[i].checked) {
        allowEmbValue = embField[i].value;
        break;
      }
    }
    if (allowEmbValue.indexOf("yes") != -1) {
        delayRelease = true;
    }
    if (delayRelease) {
      // check that at least one embargoPeriod has been selected
      var hasPeriodVal = false;
      for (var j = 1; j <= 3; j++) {
        var embPeriod = theForm["embargoPeriod_"+j];
        if (embPeriod) {
          if (embPeriod.checked) {
            hasPeriodVal = true;
            break;
          }
        }
      }
      if (!hasPeriodVal) {
        missingFlds[missingFlds.length] = labels['puboptdelrel'];
        valid = false;
      }
    }
  }
  else if (sectionVal == 'contactsetup') {
    var contactTypes = new Array('lib', 'inv');
    var contactLabels = new Array('Library Contact', 'Invoicing Contact');
    for (var j = 0; j < contactTypes.length; j++) {
      var fname = contactTypes[j] + "_firstName";
      var mname = contactTypes[j] + "_middleName";
      var lname = contactTypes[j] + "_lastName";
      if (theForm[fname].value || theForm[mname].value || theForm[lname].value) {
        for (var i = 0; i < name_reqdflds.length; i++) {
          var fldName = contactTypes[j] + "_" + name_reqdflds[i];
          var fld = theForm[fldName];
          var value = "";
          if (!fld.type) {
            if (fld.length) {
              for (var k = 0; k < fld.length; k++) {
                value = getValue(fld[k]);
              }
            }
          }
          else {
            value = getValue(fld);
          }

          var fieldLabel = contactLabels[j] + ": " + name_attrlabels[i];
          if (!value || value == 0) {
            if (fieldLabel) {
              missingFlds[missingFlds.length] = fieldLabel;
            }
          }
          else {
            if (fldName.indexOf("email") != -1) {
              if (! validEmail(value)) {
                errmsg += fieldLabel + " " + errors['invalemailfmt'] + "\n" +
                          errors['reenteremail'];
                valid = false;
              }
            }
          }
        }
      }
    }
  }
  else if (sectionVal == 'ordersetup') {
     var showMsg = false;
     var d_elems = document.getElementById("d_standingOrder").getElementsByTagName("input");
     for(var i=0; i < d_elems.length; i++){
       var emsg = validNum(d_elems[i], showMsg);
       if (emsg != "") {
         errmsg += "\n" +  emsg + "\n";
         valid = false;
         break;
       }
     }

     var m_elems = document.getElementById("m_standingOrder").getElementsByTagName("input");
     for(var i=0; i < m_elems.length; i++){
       var emsg = validNum(m_elems[i], showMsg);
       if (emsg != "") {
         errmsg +="\n" +  emsg + "\n";
         valid = false;
         break;
       }
     }
  }
  else if (sectionVal == 'othersetup') {
    var want_ftp = document.getElementById('wantFTP');
    if (want_ftp.checked) {
      for (var i = 0; i < ftp_reqdflds.length; i++) {
        var fldName = ftp_reqdflds[i];
        var fld = theForm[fldName];
        var value = "";
        if (!fld.type) {
          if (fld.length) {
            for (var k = 0; k < fld.length; k++) {
              value = getValue(fld[k]);
            }
          }
        }
        else {
          value = getValue(fld);
        }
        if (!value || value == 0) {
          var fieldLabel = ftp_attrlabels[i];
          if (fieldLabel) {
            missingFlds[missingFlds.length] = fieldLabel;
          }
        }
        else {
          if (fldName.indexOf("email") != -1) {
            if (! validEmail(value)) {
              errmsg += ftp_attrlabels[i] + ": " + errors['invalemailfmt'] + "\n" +
                        errors['reenteremail'];
              valid = false;
            }
          }
        }
      }
    }

    if (document.forms[0].extra_email.value) {
      if (! validEmail(document.forms[0].extra_email.value)) {
        errmsg += labels['email'] + ": " + errors['invalemailfmt'] + "\n" +
                  errors['reenteremail'];
        valid = false;
      }
    }

    // check if instructions language selections are different
    if (document.forms[0].instructionsLang && 
        document.forms[0].alt_instructionsLang) {
       var instrText = trim(document.forms[0].instructionsText.value);
       var alt_instrText = trim(document.forms[0].alt_instructionsText.value);
       var instrLang = document.forms[0].instructionsLang.value;
       var alt_instrLang = document.forms[0].alt_instructionsLang.value;

       if (instrText && (instrLang == 0)) {
         missingFlds[missingFlds.length] = labels['instrlang'];
         valid = false;
       }
       if (alt_instrText && (alt_instrLang == 0)) {
         missingFlds[missingFlds.length] = labels['altinstrlang'];
         valid = false;
       }
       if (instrText && alt_instrText) {
         if ((instrLang && alt_instrLang) && (instrLang == alt_instrLang)) {
           errmsg += errors['samelanguage'];
           valid = false;
           showAltLangInst();
         }
       }
    }
  }

  if (missingFlds.length != 0) {
      // construct error message
      if (errmsg) {
        errmsg += "\n\n";
      }
      var valueStr = labels['thesevals'];
      if (missingFlds.length == 1) {
        errmsg += errors['missingdata']; 
        valueStr = labels['thisval'];
      }
      else {
        errmsg += errors['missingdatas']; 
      }
      errmsg += "\n\n" + missingFlds.join("\n") + "\n\n" +
                errors['pleaseenter'] + " " + valueStr + " " + 
                errors['andtryagain'];
      valid = false;
  }

  if (!valid) {
    alert(errmsg);
  }

  return valid;
}

function saveSetup(sectionVal) {
  var valid = true;
  var theForm = document.forms[0];
  valid = validateSetup(theForm, sectionVal);
  if (valid) {
    theForm.rm.value = sectionVal + "_save";
    //theForm.submit();
  }
  return valid;
}

function addother(theForm, tabidx) {
  if (!theForm) {
    theForm = document.forms[0];
  }
  var totalmem = parseInt(theForm.totOtherAdmins.value, 10);
  var newid = 0;
  var hasHeader = 0;

  if (totalmem == 1) {
     document.getElementById("otherAdmins").rows.item(newid).style.display = '';
  }
  else {
      newid = appendRow("otherAdmins", hasHeader, 0);
  }

  // Clear out data from new row
  var curnodeId = 'firstName_' + newid;
  var curnode = document.getElementById('firstName_' + newid);
  curnode.value = "";
  var newTabidx = tabidx + (parseInt(newid) * 7);
  curnode.tabIndex = newTabidx;

  curnode = document.getElementById('middleName_' + newid);
  curnode.value = "";
  newTabidx += 1;
  curnode.tabIndex = newTabidx;

  curnode = document.getElementById('lastName_' + newid);
  curnode.value = "";
  newTabidx += 1;
  curnode.tabIndex = newTabidx;

  curnode = document.getElementById('suffix_' + newid);
  curnode.value = "";
  newTabidx += 1;
  curnode.tabIndex = newTabidx;

  curnode = document.getElementById('title_' + newid);
  curnode.value = "";
  newTabidx += 1;
  curnode.tabIndex = newTabidx;

  curnode = document.getElementById('email_' + newid);
  curnode.value = "";
  newTabidx += 1;
  curnode.tabIndex = newTabidx;

  curnode = document.getElementById('phone_' + newid);
  curnode.value = "";
  newTabidx += 1;
  curnode.tabIndex = newTabidx;

  // update total
  theForm.totOtherAdmins.value = totalmem + 1; 

  setTimeout("document.getElementById('" + curnodeId + "').focus();",1);
  setTimeout("document.getElementById('" + curnodeId + "').select();",1);

  return;
}

function copy_fields(theForm, fldtype, from, to, callOnChange) {

  var theflds = name_flds;
  if (fldtype == "address") {
    theflds = addr_flds;
  }

  for (var i=0; i < theflds.length; i++) {
    var fromName = from + theflds[i];
    var toName = to + theflds[i];
    if (theForm[toName]) {
      theForm[toName].value = "";
    }
    if (theForm[fromName] && theForm[toName]) {
      var fromType = theForm[fromName].type;
      if (fromType.indexOf("select") != -1) {
        // pick list field
        var selectedIndex = theForm[fromName].selectedIndex;
        if (selectedIndex >= 0) {
          var fromValue = theForm[fromName].options[selectedIndex].value;
          theForm[toName].value = fromValue;
        }
      }
      else {
        theForm[toName].value = theForm[fromName].value;
      }
      if (callOnChange) {
         if (theForm[toName].onchange) {
           theForm[toName].onchange();
         }
      }
    }
  }
  return;
}

function selectContact(theForm, theField) {
  var fldname = theField.name;
  var spl = fldname.split('_');
  var to = spl[0] + "_";

  var from = "_admin_"; 
  var selectedIndex = theField.selectedIndex;
  if (selectedIndex >= 0) {
    var fromValue = theField.options[selectedIndex].value;
    from += fromValue + "_";
  }
//alert("selectContact: fldname=" + fldname + " to=" + to + " from=" + from);

  /* call copy_fields with calling onChange procs */
  copy_fields(theForm, 'name', from, to, true);

  /* now call copy_fields after waiting for a second - without
   *  calling onChange procs to fix any values overwritten by
   *  race conditions */
  function cpyflds() {
    copy_fields(theForm, 'name', from, to, false);
  }
  setTimeout(cpyflds, 1000);

  return;
}


/** transfer shipping address info to invoice address fields **/
function useSameAddress(usebox, theForm, fromType, toType) {
  var fromName = fromType + "_";
  var toName = toType + "_";

  if (usebox.checked) {
      /* call copy_fields with calling onChange procs */
      copy_fields(theForm, 'address', fromName, toName, true);
      /* now call copy_fields after waiting for a second - without
       *  calling onChange procs to fix any values overwritten by
       *  race conditions */
       function cpyflds() {
         copy_fields(theForm, 'address', fromName, toName, false);
       }
       setTimeout(cpyflds, 1000);
  }
  else {   /* clear and enable the future address fields */
      var fldTotal = addr_flds.length;
      for (var i=0; i < fldTotal; i++) {
        var toFld = toName + addr_flds[i];
        if (theForm[toFld]) {
          var fieldType = theForm[toFld].type;
          if ((fieldType.indexOf("select") != -1) ||(fieldType == "checkbox") ||
              (fieldType.indexOf("radio") != -1)) {
            clearChoices(toFld);
          }
          else {
            theForm[toFld].value = "";
          }
        }
      }
  }
  return;
}

function checkEmbargos(theForm) {
  var embDiv;
  var hasEmbargo = false;
  var numPeriods = theForm.numEmbargoes.value;

  // determine embargo option selected
  var optionField = theForm.allowEmbargo;
  for (var i=0; i < optionField.length; i++) {
    if (optionField[i].checked) {
      if (optionField[i].value == "yes") {
        hasEmbargo = true;
      }
    }
  }

  if (hasEmbargo) {
    // enable embargo fields
    for (i=1; i <= numPeriods; i++) {
      var embfldname = "embargoPeriod_" + i;
      theForm[embfldname].disabled = false;
    }
    embDiv = document.getElementById("embargoOptDiv");
    if (embDiv) {
      embDiv.className = "";
    }
  }
  else {
    // disable embargo fields
    for (i=1; i <= numPeriods; i++) {
      var embfldname = "embargoPeriod_" + i;
      theForm[embfldname].disabled = true;
      theForm[embfldname].checked = false;
    }
    embDiv = document.getElementById("embargoOptDiv");
    if (embDiv) {
      embDiv.className = "disabled";
    }
  }
  return;
}

function checkIREmbargos(theForm) {
  var embDiv;
  var hasIREmbargo = false;
  var numPeriods = theForm.numIREmbargoes.value;

  // determine embargo option selected
  var optionField = theForm.allowIREmbargo;
  for (var i=0; i < optionField.length; i++) {
    if (optionField[i].checked) {
      if (optionField[i].value == "yes") {
        hasIREmbargo = true;
      }
    }
  }

  if (hasIREmbargo) {
    // enable embargo fields
    for (i=1; i <= numPeriods; i++) {
      var embfldname = "irembargoPeriod_" + i;
      theForm[embfldname].disabled = false;
    }
    embDiv = document.getElementById("irembargoOptDiv");
    if (embDiv) {
      embDiv.className = "";
    }
  }
  else {
    // disable embargo fields
    for (i=1; i <= numPeriods; i++) {
      var embfldname = "irembargoPeriod_" + i;
      theForm[embfldname].disabled = true;
      theForm[embfldname].checked = false;
    }
    embDiv = document.getElementById("irembargoOptDiv");
    if (embDiv) {
      embDiv.className = "disabled";
    }
  }
  return;
}

function checkIR(theForm) {
  var irDiv;
  var hasIR = false;

  // determine ir option selected
  var optionField = theForm.allowIR;
  for (var i=0; i < optionField.length; i++) {
    if (optionField[i].checked) {
      if (optionField[i].value == "yes") {
        hasIR = true;
      }
    }
  }

  if (hasIR) {
    irDiv = document.getElementById("irOptDiv");
    if (irDiv) {
      irDiv.className = "";
    }
  }
  else {
    // disable embargo fields
    irDiv = document.getElementById("irOptDiv");
    if (irDiv) {
      irDiv.className = "disabled";
    }
  }
  return;
}

function checkOptions(theForm, theField) {
  var pubopt_div;

  var selectedIndex = theField.selectedIndex;
  if (selectedIndex >= 0) {
    var theVal = theField.options[selectedIndex].text;
    if (theVal == "Canada") {
      // default selection to Traditional Publishing
      var puboptElem = document.getElementById("pubopt_TP");
      if (puboptElem !== null) {
        puboptElem.checked = true;
        hideItem("puboptDiv");
      }
    }
    else {
      showItem("puboptDiv");
      var pubopt_elem = document.getElementById("pubopt_TP");
      if (pubopt_elem !== null) {
        pubopt_elem.checked = false;
      }
    }
  }
  return;
}

function goToTag(theForm, theField) {
  var selectedIndex = theField.selectedIndex;
  var theVal = theField.options[selectedIndex].value;
  if(theVal == ""){
    alert(errors['validcountry']);
  }
  var tagurl = "#" + theVal;
  this.location.href = tagurl;
}

function goToForm(sectionVal) {
  var theForm = document.forms.info;
  if (theForm && theForm.rm) {
    theForm.rm.value = sectionVal;
  }
  theForm.submit();
  return;
}

function showAltLangInst() {
  showItem("collapseAltLang");
  showItem("altLangInstructs");
}

function hideAltLangInst() {
  hideItem("collapseAltLang");
  hideItem("altLangInstructs");
}

/** clear instructions field **/
function clearInstructs(txtFldName, pickFldName, defLang) {
  theField = document.forms[0][txtFldName];
  if (theField) {
    needToConfirm = false;
    theField.value = "";
    // theLangField = document.forms[0][pickFldName];
    // if (theLangField) {
    //   clearSelect(pickFldName);
    //   theLangField.value = defLang;
    // }
    setTimeout("document.getElementById('" + txtFldName + "').focus();",1);
  }
  return;
}


function checkLogoValid(theField) {
  if (!theField) {
   theField = document.forms[0].logoFile;
  }
  var valid = true;
  var errmsg = "";

  // check for valid filename and extension
  if (theField) {
    var newFileName = trim(theField.value);
    valid = false;

    if (newFileName) {
      valid = checkFileName(theField, '.jpg, .png, or .gif');

      if (valid) {
        // now check for valid extensions
        var ext = newFileName.substring(newFileName.lastIndexOf('.') + 1);
        if ( ((ext == "gif") || (ext == "GIF"))
          || ((ext == "jpg") || (ext == "JPG"))
          || ((ext == "png") || (ext == "PNG")) ) {
          valid = true;
        }
        else {
         errmsg = errors['logofiles'] + "\n" + errors['logosuffix'];
         valid = false;
        }
      }
    }
  }

  if (!valid) {
    if (errmsg) {
      alert(errmsg);
    }
    theField.value = "";
    setTimeout("document.getElementById('logoFile').focus();",1);
    setTimeout("document.getElementById('logoFile').select();",1);
  }
  return(valid);
}


