//dataentry.js	Donghai Huangfu	02/16/2000
//	for dateentry.asp----facjobs

// Current Date var
var currDate = new Date()
var currDay  = currDate.getDate()
var currMonth= currDate.getMonth() + 1
var currYear = currDate.getYear()
currYear = currYear % 100; 
if (currYear < 9) { currYear = "0" + currYear; }
if (currMonth < 9) { currMonth = "0" + currMonth; }
if (currDay < 9) { currDay = "0" + currDay; }
currDateStr  = currMonth + "/" + currDay + "/" + currYear	

function setDateBlank ( form ) {		//set to blank 
	form.deadline.value = ""
}

function checkRadio ( form ) {
	if ( form.R1[3].checked ) {
		form.deadline.value = ""
	}
}


function addInfo ( form ) {

	//if(form.pswd.value != "560412") {
	//	alert("Wrong password!");
	//	location="password.htm"
	//	return
	//}
		
	form.ContactName.value = form.ContactNam.value
	if ( form.ContactPhone.value != "" ) {
		form.ContactName.value +=  " Phone:"
		form.ContactName.value += form.ContactPhone.value
	}
	if ( form.Fax.value != "" ) {
		form.ContactName.value += " Fax:"
		form.ContactName.value += form.Fax.value
	}
	if ( form.ContactWeb.value != "" ) {
		form.ContactName.value += " Web:"
		form.ContactName.value += form.ContactWeb.value
	}

	if ( form.JobTitle.value == "" ) {
		form.JobTitle.value =form.JobRank.value
	}	

	if ( form.R1[0].checked ) {
		form.RDeadline.value = "" + form.deadline.value
	} else if ( form.R1[1].checked ) {
		form.RDeadline.value = "Review Begins " + form.deadline.value
	} else if ( form.R1[2].checked ) {
		form.RDeadline.value = "Must be postmarked by " + form.deadline.value
	} else {
		form.RDeadline.value = "Open until Filled"
	}
		
	form.unitAbb.value = getUnitAbb( form );
	//form.DateEntered.value = currDateStr
}

function getUnitAbb( form ) {

	if ( form.Unit.selectedIndex == 1 ) { return "Arts"; }
	if ( form.Unit.selectedIndex == 2 ) { return "AH"; }
	if ( form.Unit.selectedIndex == 3 ) { return "Business"; }
	if ( form.Unit.selectedIndex == 4 ) { return "Dentistry"; }
	if ( form.Unit.selectedIndex == 5 ) { return "Education"; }
	if ( form.Unit.selectedIndex == 6 ) { return "Engineering"; }
	if ( form.Unit.selectedIndex == 7 ) { return "HAS"; }
	if ( form.Unit.selectedIndex == 8 ) { return "Medicine"; }
	if ( form.Unit.selectedIndex == 9 ) { return "Nursing"; }
	if ( form.Unit.selectedIndex == 10 ) { return "Pharmacy"; }
	if ( form.Unit.selectedIndex == 11 ) { return "SW"; }
	if ( form.Unit.selectedIndex == 12 ) { return "Life"; }
	if ( form.Unit.selectedIndex == 13 ) { return "Athletics"; }
	if ( form.Unit.selectedIndex == 14 ) { return "AA"; }
	if ( form.Unit.selectedIndex == 15 ) { return "Advancement"; }
	if ( form.Unit.selectedIndex == 16 ) { return "Finance"; }
	if ( form.Unit.selectedIndex == 17 ) { return "GCR"; }
	if ( form.Unit.selectedIndex == 18 ) { return "HSD"; }
	if ( form.Unit.selectedIndex == 19 ) { return "IT"; }
	if ( form.Unit.selectedIndex == 20 ) { return "Massey"; }
	if ( form.Unit.selectedIndex == 21 ) { return "President"; }
	if ( form.Unit.selectedIndex == 22 ) { return "RGS"; }
	if ( form.Unit.selectedIndex == 23 ) { return "SA"; }
	if ( form.Unit.selectedIndex == 24 ) { return "Library"; }
	if ( form.Unit.selectedIndex == 25 ) { return "UO"; }
	if ( form.Unit.selectedIndex == 26 ) { return "UC"; }
}



//####################################################
function FrontPage_Form1_Validator(theForm)
{

  if (theForm.Unit.selectedIndex < 0)
  {
    alert("Please select one of the \"School/College/Admin\" options.");
    theForm.Unit.focus();
    return (false);
  }

  if (theForm.Unit.selectedIndex == 0)
  {
    alert("The first \"School/College/Admin\" option is not a valid selection.  Please choose one of the other options.");
    theForm.Unit.focus();
    return (false);
  }

  if (theForm.Dept.value == "")
  {
    alert("Please enter a value for the \"Department\" field.");
    theForm.Dept.focus();
    return (false);
  }

  if (theForm.Dept.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"Department\" field.");
    theForm.Dept.focus();
    return (false);
  }

  if (theForm.DeptPhone.value == "")
  {
    alert("Please enter a value for the \"DeptPhone\" field.");
    theForm.DeptPhone.focus();
    return (false);
  }

  if (theForm.DeptPhone.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"DeptPhone\" field.");
    theForm.DeptPhone.focus();
    return (false);
  }

  var checkOK = "0123456789-()- \t\r\n\f";
  var checkStr = theForm.DeptPhone.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit, whitespace and \"()-\" characters in the \"DeptPhone\" field.");
    theForm.DeptPhone.focus();
    return (false);
  }

  var chkVal = theForm.DeptPhone.value;
  var prsVal = chkVal;
  if (chkVal != "" && !(prsVal >= "(804)"))
  {
    alert("Please enter a value greater than or equal to \"(804)\" in the \"DeptPhone\" field.");
    theForm.DeptPhone.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.VCUBox.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"VCUBox\" field.");
    theForm.VCUBox.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid number in the \"VCUBox\" field.");
    theForm.VCUBox.focus();
    return (false);
  }

  var chkVal = allNum;
  var prsVal = parseFloat(allNum);
  if (chkVal != "" && !(prsVal >= "100000" && prsVal <= "999999"))
  {
    alert("Please enter a value greater than or equal to \"100000\" and less than or equal to \"999999\" in the \"VCUBox\" field.");
    theForm.VCUBox.focus();
    return (false);
  }

  if (theForm.JobRank.value == "")
  {
    alert("Please enter a value for the \"Rank\" field.");
    theForm.JobRank.focus();
    return (false);
  }

  if (theForm.JobRank.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"Rank\" field.");
    theForm.JobRank.focus();
    return (false);
  }

  var checkOK = "0123456789-/";
  var checkStr = theForm.deadline.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit and \"/\" characters in the \"ApplyDate\" field.");
    theForm.deadline.focus();
    return (false);
  }

  if (theForm.HireDate.value == "")
  {
    alert("Please enter a value for the \"Anticipate Hire Date\" field.");
    theForm.HireDate.focus();
    return (false);
  }

  if (theForm.HireDate.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Anticipate Hire Date\" field.");
    theForm.HireDate.focus();
    return (false);
  }

  var checkOK = "0123456789-/";
  var checkStr = theForm.HireDate.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit and \"/\" characters in the \"Anticipate Hire Date\" field.");
    theForm.HireDate.focus();
    return (false);
  }

  var chkVal = theForm.HireDate.value;
  var prsVal = chkVal;
  if (chkVal != "" && !(prsVal >= "01/01/00"))
  {
    alert("Please enter a value greater than or equal to \"01/01/00\" in the \"Anticipate Hire Date\" field.");
    theForm.HireDate.focus();
    return (false);
  }

  if (theForm.Duties.value == "")
  {
    alert("Please enter a value for the \"Duties\" field.");
    theForm.Duties.focus();
    return (false);
  }

  if (theForm.Qualifications.value == "")
  {
    alert("Please enter a value for the \"Qualifications\" field.");
    theForm.Qualifications.focus();
    return (false);
  }

  if (theForm.Process.value == "")
  {
    alert("Please enter a value for the \"Process\" field.");
    theForm.Process.focus();
    return (false);
  }

  if (theForm.ContactPhone.value == "")
  {
    alert("Please enter a value for the \"Phone\" field.");
    theForm.ContactPhone.focus();
    return (false);
  }

  if (theForm.ContactPhone.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Phone\" field.");
    theForm.ContactPhone.focus();
    return (false);
  }

  var checkOK = "0123456789-()- \t\r\n\f";
  var checkStr = theForm.ContactPhone.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit, whitespace and \"()-\" characters in the \"Phone\" field.");
    theForm.ContactPhone.focus();
    return (false);
  }

  var chkVal = theForm.ContactPhone.value;
  var prsVal = chkVal;
  if (chkVal != "" && !(prsVal >= "(804)"))
  {
    alert("Please enter a value greater than or equal to \"(804)\" in the \"Phone\" field.");
    theForm.ContactPhone.focus();
    return (false);
  }

  var checkOK = "0123456789-()- \t\r\n\f";
  var checkStr = theForm.Fax.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit, whitespace and \"()-\" characters in the \"Fax\" field.");
    theForm.Fax.focus();
    return (false);
  }
  return (true);
}