/////////////////////////////////////////
// PRESERVATION MICROFILM REQUEST FORM //
/////////////////////////////////////////


//////////////////////////////////////////////////////
//PROCEDURE TO VALIDATE FORM ENTRIES BEFORE SUBMITTING
function MicrofilmRequestForm_ValidateInput(objForm)
{

  var strMessage = "";
  var blnInvalid = "false";
  var names="";

  //VALIDATE optRequestType__________
  if ((objForm.optRequestType__________[0].checked == false) && (objForm.optRequestType__________[1].checked == false) && (objForm.optRequestType__________[2].checked == false))
  {
    if (blnInvalid == false)
    {
      blnInvalid = true;
    }
    if (strMessage == "")
    {
      strMessage = "   * You must specify the type of request you are making.";
    }
    else
    {
      strMessage = strMessage + "\n" + "   * You must specify the type of request you are making.";
    }    
  }

  //VALIDATE txtPatronName___________
  if (IsBlank(objForm.txtPatronName___________.value))
  {
    if (blnInvalid == false)
    {
      blnInvalid = true;
    }
    if (strMessage == "")
    {
      strMessage = "   * You include your name in your submission.";
    }
    else
    {
      strMessage = strMessage + "\n" + "   * You must include your name in your submission.";
    }    
  }


  //VALIDATE txtPatronEmail__________
  if (!(IsEmail(objForm.txtPatronEmail__________.value)))
  {
    if (blnInvalid == false)
    {
      blnInvalid = true;
    }
    if (strMessage == "")
    {
      strMessage = "   * You must include a valid email address in your submission.";
      strMessage = strMessage + "\n" + "           Example:  username@columbia.edu";
    }
    else
    {
      strMessage = strMessage + "\n" + "   * You must include a valid email address in your submission.";
      strMessage = strMessage + "\n" + "           Example:  username@columbia.edu";
    }    
  }

  //VALIDATE txtPatronAffiliation____
  if (IsBlank(objForm.txtPatronAffiliation____.value))
  {
    if (blnInvalid == false)
    {
      blnInvalid = true;
    }
    if (strMessage == "")
    {
      strMessage = "   * You must identify your affiliation with Columbia University.";
    }
    else
    {
      strMessage = strMessage + "\n" + "   * You must identify your affiliation with Columbia University.";
    }    
  }

  //IF VALIDATION FAILED, ALERT USER
  if (!(strMessage==""))
  {
    strMessage = "Please correct the following before submitting this form:\n\n" + strMessage
    alert(strMessage);
    return false;
  }
  else
  {
  //IF VALIDATION WAS SUCCESSFUL, SUBMIT FORM
    //alert("Validation Completed Successfully");
    return true;
  }

}


//////////////////////////////////////////////////////////////////////////////////////////
//PROCEDURE TO DETERMINE WHETHER OR NOT A VALUE IS NULL OR A NULL STRING OR IS ZERO-LENGTH
function IsBlank(varValue)
{

  if ((varValue == null) || (varValue == "") || (!(varValue.length > 0)))
  {
    return true
  }
  else
  {
    return false
  }

}

//////////////////////////////////////////////////////////////////////////////////////////
//PROCEDURE TO DETERMINE WHETHER OR NOT A VALUE REPRESENTS A VALID EMAIL ADDRESS FORMAT
function IsEmail(varValue)
{

  var blnResult = true;
  var intPosition = 0;
  var intLength = 0;
  var intAt = 0;
  var intLastDot = 0;
  var varChar = "";
  var varUserID = ""
  var blnUserID = true
  var varHost = ""
  var blnHost = false
  var varDomain = ""
  var blnDomain = false
  
  strEmail = new String(varValue);

  if (IsBlank(varValue))
  {
    blnResult = false;
  }

  if (strEmail.indexOf("@") == -1)
  {
    blnResult = false;
  }
  if (strEmail.indexOf(".") == -1)
  {
    blnResult = false;
  }
  if (strEmail.lastIndexOf("@") > strEmail.lastIndexOf("."))
  {
    blnResult = false;
  }
  intAt = strEmail.lastIndexOf("@");
  intLastDot = strEmail.lastIndexOf(".");
  if (intAt > intLastDot)
  {
    blnResult = false;
  }
  intLength = strEmail.length
  for (intPosition = 0; intPosition < intLength; intPosition++)
  {
    varChar = strEmail.charAt(intPosition);
    if (varChar == "@")
    {
      blnUserID = false;
      blnHost = true;
    }
    else if (varChar == ".")
    {
      blnHost = false;
      blnDomain = true;
    }
    else
    {
      if (blnUserID == true)
      {
        varUserID = varUserID + varChar;
      }
      else if (blnHost == true)
      {
        varHost = varHost + varChar;
      }
      else if (blnDomain == true)
      {
        varDomain = varDomain + varChar;
      }
    }
  }

  if ((varUserID == "") || (varHost == "") || (varDomain == ""))
  {
    blnResult = false;
  }

  return blnResult;

}


////////////////////////////////////
//PROCEDURE TO DISPLAY COPYRIGHT POP-UP FORM
function display_copyright(url,name)
{
  new_window = window.open('http://www.columbia.edu/cu/lweb/services/preservation/forms/copyright.microfilm.html','copyright', 'status,resizable=no,scrollbars,width=416,height=500,left=10,top=10,titlebar=yes')
}