var strIntraCAMsg = 'ABF U-Pack no hace mudanzas de Cañada a Cañada.'

// validate the quote number before retrieving information
function validatePageNumOne()  {
  if (document.frmResubmit.txtQuoteID.value.length < 10) {
    return warnInvalid(objForm.txtQuoteID,'Un NUMERO DE REFERENCIA es requerido.')
  }
  return true
}

function validatePageNumTwo() {
   var objForm = document.frmResubmit;

   var fromState = objForm.cboFromState.options[objForm.cboFromState.selectedIndex].value;
   var toState = objForm.cboToState.options[objForm.cboToState.selectedIndex].value;

   if (isWhitespace(trimWhiteSpace(objForm.txtFirstName.value))) {
      return warnInvalid(objForm.txtFirstName, 'Su primer nombre es requerido...')
   }
   if (isWhitespace(trimWhiteSpace(objForm.txtLastName.value))) {
      return warnInvalid(objForm.txtLastName, 'Su apellido es requerido...')
   }

   if (((objForm.txtFromCity.value == '') && !(fromState == '')) && !(objForm.txtFromZip.value == '')) {
      return warnInvalid(objForm.txtFromCity, 'Una CUIDAD y ESTADO o CODIGO POSTAL valido de origen es requerido...')
   }
   if ((!(objForm.txtFromCity.value == '') && (fromState == '')) && !(objForm.txtFromZip.value == '')) {
      return warnInvalid(fromState, 'Una CUIDAD y ESTADO o CODIGO POSTAL valido de origen es requerido...')
   }
  
   if (((objForm.txtToCity.value == '') && !(toState == '')) && !(objForm.txtToZip.value == '')) {
      return warnInvalid(objForm.txtToCity, 'Una CUIDAD y ESTADO o CODIGO POSTAL valido de destino es requerido...')
   }
   if ((!(objForm.txtToCity.value == '') && (toState == '')) && !(objForm.txtToZip.value == '')) {
      return warnInvalid(toState, 'Una CUIDAD y ESTADO o CODIGO POSTAL valido de destino es requerido...')
   }

   if (objForm.txtFromZip.value != '') {
      if (!ValidUPackZip(objForm.cboFromState, objForm.txtFromZip)) {
         return warnInvalid(objForm.txtFromZip, 'Una CODIGO POSTAL valido de origen es requerido...')
      }
   }

   if (objForm.txtToZip.value != '') {
      if (!ValidUPackZip(objForm.cboToState, objForm.txtToZip)) {
         return warnInvalid(objForm.txtToZip, 'Una CODIGO POSTAL valido de destino es requerido...')
      }
   }

   //check to see if the linear feet has a valid value selected
   if (objForm.cboLinearFeet.options[objForm.cboLinearFeet.selectedIndex].value == '') {
      return warnInvalid(objForm.cboLinearFeet,'Tiene que especificar los PIES LINEALES...');
   }

   if (toState != '') {
      if (fromState.substring(2) == 'CA' && toState.substring(2) == 'CA') {
         return warnInvalid(objForm.cboFromState,strIntraCAMsg);
      }
   }

   if (!ValidEMail(trimWhiteSpace(objForm.txtEmail.value))) {
      return warnInvalid(objForm.txtEmail, 'Un coreo electrónico valido es requerido...');
   }

   if (!isDate(objForm.cboShipYear.options[objForm.cboShipYear.selectedIndex].value, objForm.cboShipDay.options[objForm.cboShipDay.selectedIndex].value, objForm.cboShipMonth.options[objForm.cboShipMonth.selectedIndex].value)) {
      return warnInvalid(objForm.cboShipYear,'Un problema ocurrió cuando estábamos procesando la fecha de mudanza. Por favor cierre el hojeador y regrese a la pagina de cotización para continuar. Si el problema persiste, por favor llame le a un representante de U-Pack al 1-800-413-5182.');
   }

   return true;
}


function validate() {
   var objPage = document.frmResubmit.hidPageNum;

   if ((objPage.value == '') || (objPage.value == 'PageNumOne')) {
      if (validatePageNumOne()) {
         objPage.value = 'PageNumTwo'
      }
      else return false;
   }
   else if (objPage.value == 'PageNumTwo') {
      if (validatePageNumTwo()) {
         objPage.value = 'PageNumThree'
      }
      else return false;
   }
   //else if (objPage.value == 'PageNumThree') {
   //   objPage.value = 'PageNumFour'
   //}

   return true
}


function ValidUPackZip(cboSt, txtZp) {
   if (cboSt.selectedIndex == 0) {
      if (isInteger(txtZp.value)) {
         return ValidUSZip(txtZp)
      }
      else {
         return ValidCAZip(txtZp)
      }
   }
   else {
      if (cboSt.options[cboSt.selectedIndex].value.substr(2,2) == 'US') {
         return ValidUSZip(txtZp)
      }
      else return ValidCAZip(txtZp);
   }
   return true
}

function backUp() {
   document.frmResubmit.hidPageNum.value = 'PageNumTwoBack'
   document.frmResubmit.submit()
}

function setReloCube(obj) {
   var objForm = document.frmResubmit;
   var feet = parseInt(obj.options[obj.selectedIndex].value);

   if (objForm.cboReloCube) {
      if (feet == 5) relocube = '1';
      else if (feet <= 9) relocube = '1-2';
      else if (feet <= 14) relocube = '2-3';
      else if (feet <= 19) relocube = '3-4';
      else relocube = 'None';

      objForm.cboReloCube.options.selectedIndex = getIndexInList(objForm.cboReloCube,relocube);
   }
}
