// CareerFountain scripts.

// Last update: HZ, February 01, 2006.
// Added HasAtLeastParagraph() & function CheckJssCreateAccountForm4(Form) DR 9/07
// ***********************************************

function PopUp(URL)
{
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=200,height=200,left=412,top=284');");
}

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

// Function to review resume in jobseeker signup phase.

function Review(URL)
{
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480,left=100,top=100');");
}

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

function CheckJssMemberChangeForm(Form)
{

  return SameValue(Form.Password1, Form.Password2, "Please enter the same Password twice");

}

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

function CheckRsRecruiterChangeForm(Form)
{

  return SameValue(Form.Password1, Form.Password2, "Please enter the same Password twice");

}

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

function CheckJssLoginForm(Form)
{

  return HasValue(Form.userid, "Please enter your User ID") &&
         HasValue(Form.password, "Please enter your Password");

}

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

function CheckRsLoginForm(Form)
{

  return HasValue(Form.userid, "Please enter your User ID") &&
         HasValue(Form.password, "Please enter your Password");

}

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

function CheckForgotPasswordForm(Form)
{

  // We need at least one of the two controls filled

  var ControlsWithValue = 2;

  if((Form.userid.value == "") || (Form.userid.value == null))
  {
    --ControlsWithValue;
  }

  if((Form.email.value == "") || (Form.email.value == null))
  {
    --ControlsWithValue;
  }

  if(ControlsWithValue == 0)
  {
    alert("Please enter a User ID and/or an Email Address");
    Form.userid.focus();
    return false;
  }

  return true;

}

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

function CheckJssForgotPasswordForm(Form)
{

  return CheckForgotPasswordForm(Form);

}

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

function CheckRsForgotPasswordForm(Form)
{

  return CheckForgotPasswordForm(Form);

}

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

function CheckRsCreateAccountForm1(Form)
{

  var Entry = Form.agree.value.toLowerCase();

  if(Entry.indexOf("agree") == -1)
  {
    alert("You must agree to continue!");

    Form.agree.focus();

    return false;
  }

  return true;

}

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

function CheckRsCreateAccountForm2(Form)
{

  return HasValue(Form.userid, "Please enter a User ID") &&
         BoundsCheck(Form.userid, 16, "User ID") &&
         HasValue(Form.password1, "Please enter a Password") &&
         HasValue(Form.password2, "Please enter a Password twice") &&
         BoundsCheck(Form.password1, 16, "Password") &&
         SameValue(Form.password1, Form.password2, "Please enter the same Password twice") &&
         HasValue(Form.given_name, "Please enter your First Name") &&
         HasValue(Form.family_name, "Please enter your Last Name") &&
         HasValue(Form.company_name, "Please enter your Company Name") &&
         HasValue(Form.street_address, "Please enter your Street Address") &&
         HasValue(Form.municipality, "Please enter your City") &&
         IsSelected(Form.region, "Please select a State") &&
         HasValue(Form.postal_code, "Please enter your Zip Code") &&
         HasValue(Form.internet_email_address, "Please enter an Email Address") &&
         HasEmailAddress(Form.internet_email_address) &&
         HasEmailAddressOrEmpty(Form.internet_submission_email_address) &&
         HasValue(Form.telephone, "Please enter a Phone Number");

}

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

function CheckJssCreateAccountForm1(Form)
{

  return HasValue(Form.userid, "Please enter a User ID") &&
         BoundsCheck(Form.userid, 16, "User ID") &&
         HasValue(Form.password1, "Please enter a Password") &&
         HasValue(Form.password2, "Please enter a Password twice") &&
         BoundsCheck(Form.password1, 16, "Password") &&
         SameValue(Form.password1, Form.password2, "Please enter the same Password twice");

}

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

function CheckJssCreateAccountForm2(Form)
{

  return HasValue(Form.given_name, "Please enter a First Name") &&
         BoundsCheck(Form.given_name, 64, "First Name") &&
         HasValue(Form.family_name, "Please enter a Last Name") &&
         BoundsCheck(Form.family_name, 64, "Last Name") &&
         HasValue(Form.street_address, "Please enter a Street Address") &&
         BoundsCheck(Form.street_address, 64, "Street Address") &&
         HasValue(Form.municipality, "Please enter a City") &&
         BoundsCheck(Form.municipality, 64, "City") &&
         IsSelected(Form.region, "Please select a State") &&
         HasValue(Form.postal_code, "Please enter a Zip or Postal Code") &&
         BoundsCheck(Form.postal_code, 16, "Postal Code") &&
         HasValue(Form.internet_email_address, "Please enter an Email Address") &&
         HasEmailAddress(Form.internet_email_address) &&
         BoundsCheck(Form.internet_email_address, 32, "Email Address") &&
         HasValue(Form.telephone, "Please enter a Phone Number") &&
         BoundsCheck(Form.telephone, 32, "Telephone") &&
         BoundsCheck(Form.mobile, 32, "Alt Phone") &&
         BoundsCheck(Form.fax, 32, "Fax");

}

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

function CheckJssCreateAccountForm3(Form)
{

  // They must have selected at least one jobtitle from our list.

  if(Form.job_title_set.value != "ok")
  {
    alert("Warning! Increase your chances of recruiters finding your resume by including at least one job title from the list.");
    return false;
  }

  // Max distance must be a number.

  if(!HasNumber(Form.distance_max))
  {
    alert("Provide a number value for maximum commute distance");
    Form.distance_max.focus();
    return false;
  }

  // Must enter zipcode.

  if(Form.distance_max_from_postal_code.value == "")
  {
    alert("Provide a Zip Code");
    Form.distance_max_from_postal_code.focus();
    return false;
  }

  // Choose either Yes or No for relocation.

  if(GetRadioValue(Form.willing_to_relocate) == "")
  {
    alert("Choose either Yes or No for relocation");
    return false;
  }

  return true;

}

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


function CheckJssCreateAccountForm4(Form)
{

  return HasValue(Form.resume, "You must enter your resume") &&
         HasAtLeastParagraph(Form.resume, 255, "Your complete resume is required");
}
// ***********************************************

function CheckFeedbackForm(Form)
{

  return HasValue(Form.your_name, "Please enter your name") &&
         HasValue(Form.email, "Please enter your email address") &&
         HasEmailAddress(Form.email) &&
         HasValue(Form.comment, "Please enter your comment");
}

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

function HasValue(Control, Message)
{

  if((Control.value == "") || (Control.value == null))
  {
    alert(Message);
    Control.focus();
    return false;
  }

  return true;

}
// ***********************************************
function HasAtLeastParagraph(Control, Bound, Message)

{

  if(Control.value.length < Bound)
  {
    alert(Message);
    return false;
  }

  return true;

}

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

function HasAtLeastOne(Control, Message)
{

  for(var Idx = 0; Idx < Control.length; ++Idx)
  {
    if(Control.options[Idx].selected)
    {
      return true;
    }
  }

  alert(Message);

  return false;

}

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

function SameValue(Control1, Control2, Message)
{

  if(Control1.value != Control2.value)
  {
    alert(Message);
    Control1.focus();
    return false;
  }

  return true;

}

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

function HasEmailAddressOrEmpty(Control)
{

  if(Control.value != "")
  {
    return HasEmailAddress(Control);
  }

  return true;

}

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

function HasEmailAddress(Control)
{

  if(Control.value.match(/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/))
  {
    return true;
  }

  alert("Please enter a valid email address");

  Control.focus();

  return false;

}

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

function IsSelected(Control, Message)
{

  if((Control.value == "Please Select") || (Control.value == ""))
  {
    alert(Message);
    return false;
  }

  return true;

}

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

function RadioSelected(Control, Message)
{

  for(var Idx = 0; Idx < Control.length; ++Idx)
  {
    if(Control[Idx].checked)
    {
      return true;
    }
  }

  alert(Message);

  return false;

}

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

function BoundsCheck(Control, Bound, ControlName)
{

  if(Control.value.length > Bound)
  {
    alert(ControlName + " should be no more than " + Bound + " characters");
    return false;
  }

  return true;

}

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

function HasNumber(Control)
{

  for(var Idx = 0; Idx < Control.value.length; ++Idx)
  {
    var OneChar = Control.value.charAt(Idx);

    if(OneChar < "0" || OneChar > "9")
    {
      return false;
    }
  }

  return (Control.value != "");

}

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

function GetRadioValue(Control)
{

  for(var Idx = 0; Idx < Control.length; ++Idx)
  {
    if(Control[Idx].checked)
    {
      return Control[Idx].value;
    }
  }

  return "";

}

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