function fillDeliverySchedule(){ 
addOption(document.Calendar.deliverySchedule, "2", "Every 2 Weeks", "");
addOption(document.Calendar.deliverySchedule, "4", "Every 4 Weeks", "");
}

function SelectDeliverySchedule(){
	removeAllOptions(document.Calendar.deliveryRoute);

	if(document.Calendar.deliverySchedule.value == '4'){
		addOption(document.Calendar.deliveryRoute,"", "Select Route Number");
		addOption(document.Calendar.deliveryRoute,"1", "Route 1");
		addOption(document.Calendar.deliveryRoute,"2", "Route 2");
		addOption(document.Calendar.deliveryRoute,"3", "Route 3");
		addOption(document.Calendar.deliveryRoute,"4", "Route 4");
		addOption(document.Calendar.deliveryRoute,"5", "Route 5");
		addOption(document.Calendar.deliveryRoute,"6", "Route 6");
		addOption(document.Calendar.deliveryRoute,"7", "Route 7");
		addOption(document.Calendar.deliveryRoute,"8", "Route 8");
		addOption(document.Calendar.deliveryRoute,"9", "Route 9");
		addOption(document.Calendar.deliveryRoute,"10", "Route 10");
		addOption(document.Calendar.deliveryRoute,"11", "Route 11");
		addOption(document.Calendar.deliveryRoute,"12", "Route 12");
		addOption(document.Calendar.deliveryRoute,"13", "Route 13");
		addOption(document.Calendar.deliveryRoute,"14", "Route 14");
		addOption(document.Calendar.deliveryRoute,"15", "Route 15");
		addOption(document.Calendar.deliveryRoute,"16", "Route 16");
		addOption(document.Calendar.deliveryRoute,"17", "Route 17");
		addOption(document.Calendar.deliveryRoute,"18", "Route 18");
		addOption(document.Calendar.deliveryRoute,"19", "Route 19");
		addOption(document.Calendar.deliveryRoute,"20", "Route 20");
	}
	if(document.Calendar.deliverySchedule.value == '2'){
		addOption(document.Calendar.deliveryRoute,"", "Select Route Number");
		addOption(document.Calendar.deliveryRoute,"1", "Route 1/11");
		addOption(document.Calendar.deliveryRoute,"2", "Route 2/12");
		addOption(document.Calendar.deliveryRoute,"3", "Route 3/13");
		addOption(document.Calendar.deliveryRoute,"4", "Route 4/14");
		addOption(document.Calendar.deliveryRoute,"5", "Route 5/15");
		addOption(document.Calendar.deliveryRoute,"6", "Route 6/16");
		addOption(document.Calendar.deliveryRoute,"7", "Route 7/17");
		addOption(document.Calendar.deliveryRoute,"8", "Route 8/18");
		addOption(document.Calendar.deliveryRoute,"9", "Route 9/19");
		addOption(document.Calendar.deliveryRoute,"10", "Route 10/20");
	}
	if(document.Calendar.deliverySchedule.value == ''){
		addOption(document.Calendar.deliveryRoute,"", "Route Number (Select frequency first)");
	}
}

function removeAllOptions(selectbox)
	{
		var i;
		for(i=selectbox.options.length-1;i>=0;i--)
		{
			selectbox.remove(i);
		}
	}


function addOption(selectbox, value, text )
	{
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
	
		selectbox.options.add(optn);
	}
	













function WAtrimIt(theString,leaveLeft,leaveRight)  {
  if (!leaveLeft)  {
    while (theString.charAt(0) == " ")
      theString = theString.substring(1);
  }
  if (!leaveRight)  {
    while (theString.charAt(theString.length-1) == " ")
      theString = theString.substring(0,theString.length-1);
  }
  return theString;
}

function WAFV_GetValueFromInputType(formElement,inputType,trimWhite) {
  var value="";
  if (inputType == "select")  {
    if (formElement.selectedIndex != -1 && formElement.options[formElement.selectedIndex].value && formElement.options[formElement.selectedIndex].value != "") {
      value = formElement.options[formElement.selectedIndex].value;
    }
  }
  else if (inputType == "checkbox")  {
    if (formElement.length)  {
      for (var x=0; x<formElement.length ; x++)  {
        if (formElement[x].checked && formElement[x].value!="")  {
          value = formElement[x].value;
          break;
        }
      }
    }
    else if (formElement.checked)
      value = formElement.value;
  }
  else if (inputType == "radio")  {
    if (formElement.length)  {
      for (var x=0; x<formElement.length; x++)  {
        if (formElement[x].checked && formElement[x].value!="")  {
          value = formElement[x].value;
          break;
        }
      }
    }
    else if (formElement.checked)
      value = formElement.value;
  }
  else if (inputType == "radiogroup")  {
    for (var x=0; x<formElement.length; x++)  {
      if (formElement[x].checked && formElement[x].value!="")  {
        value = formElement[x].value;
        break;
      }
    }
  }
  else  {
    var value = formElement.value;
  }
  if (trimWhite)  {
    value = WAtrimIt(value);
  }
  return value;
}

function WAAddError(formElement,errorMsg,focusIt,stopIt)  {
  if (document.WAFV_Error)  {
	  document.WAFV_Error += "\n" + errorMsg;
  }
  else  {
    document.WAFV_Error = errorMsg;
  }
  if (!document.WAFV_InvalidArray)  {
    document.WAFV_InvalidArray = new Array();
  }
  document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement;
  if (focusIt && !document.WAFV_Focus)  {
	document.WAFV_Focus = focusIt;
  }

  if (stopIt == 1)  {
	document.WAFV_Stop = true;
  }
  else if (stopIt == 2)  {
	formElement.WAFV_Continue = true;
  }
  else if (stopIt == 3)  {
	formElement.WAFV_Stop = true;
	formElement.WAFV_Continue = false;
  }
}

function WAValidateRQ(formElement,errorMsg,focusIt,stopIt,trimWhite,inputType)  {
  var isValid = true;
  if (!document.WAFV_Stop && !formElement.WAFV_Stop)  {
    var value=WAFV_GetValueFromInputType(formElement,inputType,trimWhite);
    if (value == "")  {
	    isValid = false;
    }
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}

function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm)  { 
  if (!document.WAFV_StopAlert)  { 
	  document.WAFV_StopAlert = true;
	  if (document.WAFV_InvalidArray)  {  
	    document.WAFV_Stop = true;
        var errorMsg = document.WAFV_Error;
	    if (errorHead!="")
		  errorMsg = errorHead + "\n" + errorMsg;
		if (errorFoot!="")
		  errorMsg += "\n" + errorFoot;
		document.MM_returnValue = false;
		if (document.WAFV_Error!="")
		  alert(errorMsg.replace(/&quot;/g,'"'));
		else if (submitForm)
		  submitForm.submit();
	    if (setFocus && document.WAFV_Focus)  {
		  document.tempFocus = document.WAFV_Focus;
          setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1); 
        }
        else {
          document.WAFV_Stop = false;
          document.WAFV_StopAlert = false;
        }
        for (var x=0; x<document.WAFV_InvalidArray.length; x++)  {
	      document.WAFV_InvalidArray[x].WAFV_Stop = false;
	    }
	  }
	  else  {
        document.WAFV_Stop = false;
        document.WAFV_StopAlert = false;
	    if (submitForm)  {
	      submitForm.submit();
	    }
	    document.MM_returnValue = true;
	  }
      document.WAFV_Focus = false;
	  document.WAFV_Error = false;
	  document.WAFV_InvalidArray = false;
  }
}
