
/*
 * Job Post Validation
 * !! note !!
 * these are not meant to be called statically (for now)
 * these -must- be called from JValidBase context which means create a JValidBase object
 * and use the 'addValidHandler' method to add in these functions. As a result, this will
 * inherit all JValidBase's functionality.
 * 
 */

function JBBJobPostValidation() {
}


//DEFINE (or override) this pages extra validation handlers here:
JBBJobPostValidation.validateJobTitle = function (title) {
  var error = false;
  if (title == '')
    error = 'blank_jt'; 
  else if (!this.isValidKeyBoardOrSpace(title))
    error = 'invalid_chars';       
  else if (title.length < this.valid.string_min)
    error = 'short_jt';
  else if (title.length > this.valid.jobtitle_max)
    error = 'long_jt';
  return error;
}

JBBJobPostValidation.validateCompanyName = function (company) {
  var error = false;
  if (company == '')
    error = 'blank_cn'; 
  else if (!this.isValidKeyBoardOrSpace(company))
    error = 'invalid_chars';       
  else if (company.length < this.valid.string_min)
    error = 'short_cn';
  else if (company.length > this.valid.companyname_max)
    error = 'long_cn';
  return error;
} 

JBBJobPostValidation.validateDescription = function(description) {
  var error = false;
  if (description == '')
    error = 'blank_desc'; 
  //else if (!this.isValidKeyBoardOrSpace(description))
  //error = 'invalid_chars';      
  else if (description.length < this.valid.jobdescription_min)
    error = 'short_desc';
  else if (description.length > this.valid.jobdescription_max)
    error = 'long_desc';
  return error;
}

JBBJobPostValidation.validateCountry = function(country) {
  country = this.trim(country);

  if (country.length == 0) {
    return 'blank_country';
  }

  return false;
}

//validate based on country selected
//if selected US, validate zip,
//otherwise, validate city
JBBJobPostValidation.validateLocation = function(city_or_zip, args) {
  city_or_zip = this.trim(city_or_zip);
  var len = city_or_zip.length;

  //this method is called two times. one by zip code, and the other by city.
  //the caller needs to tell this function what needs to be validated
  //ie: US is selected, so the zip should be validated, but city should not be
  //even though both input calls this validate function

  //validate zip if in US
  if (args.zip && args.obj.value == 'US') {
    return this.validateZip(city_or_zip);
  }

  //validate city if outside
  if (args.city && args.obj.value != 'US') {
    if (len == 0) {
      return 'blank_city';
    }
    else if (len < 2) {
      return 'short_city';
    }
    else if (len > 128) {
      return 'long_city';
    }
    else {
      return false;
    }
  }

  //should not reach here
  return false;
}
