var bigstring = " ";

function convert(){
	text1 = theform.territory.value; 
	var newstring = text1.split(" ");
			// 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 	var states_list = "ak al ar az ca co ct de fl ga hi ia id il in ks ky la ma md me mi mn mo ms mt nc nd ne nh nj nm nv ny oh ok or pa ri sc sd tn tx ut va vt wa wi wv wy";
	var states = states_list.split(" ");
	if ((text1!="")&&((text1.length%3==2)||(text1.length%3==0))){
		for(var i=0;i<51;i++){
			for(var j=0;j<51;j++){
				if((states[i] == newstring[j]) || ((newstring[j]=="48")&&(i!=0)&&(i!=10)) || (newstring[j]=="50")){
					theform.test.options[i].selected = true;			
				}
			}
		}
	}
}
function sf(){
//	document.theform.text(0).focus();
}
function highlight(currfield){
	currfield.style.background="e4ffe4";	// green
	//currfield.style.background="ffd4d4";	// red	
	//currfield.style.background="aaf5fa";	// blue	
}
function whiteout(currfield){
	currfield.style.background="ffffff";
}

function doesexist(inputValue, inputExpected) {
  var aCharExists=0
  if (inputValue) {
    for (var i=0; i<inputValue.length; i++) {
      if (inputValue.charAt(i) != " ") {
        aCharExists = 1
      }
    }
  }
  if (!aCharExists) {
    bigstring = bigstring += inputExpected += "\n ";
  }
}
function doesexistradio(inputValue, inputExpected, size) {
	sum=0;
	for(i=0; i<size; i++)
		if (inputValue[i].checked == true)
			sum++;
	if (!sum) {
		bigstring = bigstring += inputExpected += "\n ";
		return false
  	}
  	return true
  	
}

function checkem() {
  doesexist(document.form1.name_first.value, '- First Name')
  doesexist(document.form1.name_last.value, '- Last Name')
  doesexist(document.form1.address.value, '- Street Address')
  doesexist(document.form1.city.value, '- City')
  //doesexist(document.form1.state.value, '- State')
  doesexist(document.form1.zip.value, '- Zip/Postal Code')
  doesexist(document.form1.phone_day.value, '- Day Phone')
  doesexist(document.form1.phone_night.value, '- Night Phone')
  //doesexist(document.form1.dob.value, '- Date of Birth')
  doesexist(document.form1.ssn.value, '- Social Security Number')
  doesexist(document.form1.time_to_call.value, '- Best Time to Call')
  //doesexist(document.form1.experience.value, '- Years of Tractor Trailer Driving Experience')

  if ((document.form1.owner_operator.checked == "")&&(document.form1.company_driver.checked == 0)&&(document.form1.student.checked == 0)){
    inputExpected = '- I am now a (C/D, O/O, Student)\n ';    
    bigstring = bigstring += inputExpected
  } 
  if (bigstring != " "){
    alert("Please complete the following fields: \n" + bigstring)
    bigstring = " "
    return false
  }
  return true
}

function autotab_toname(evt, cur_field, char_max, goto_field){    
	if (is_nav4){
		if (cur_field.value.length >= char_max){
				goto_field.focus();
			}
	}
	if (is_ie4up || is_nav5up){	// Offset fixed in Nav 6
		if (cur_field.value.length > (char_max-1)){
				goto_field.focus();
		}
	}
}

function reset_first_to_null(a){
	if(a.value == "First Name"){
		a.value = "";
	}
}
function reset_middle_to_null(a){
	if(a.value == "Middle"){
		a.value = "";
	}
}
function reset_last_to_null(a){
	if(a.value == "Last Name"){
		a.value = "";
	}
}
 

function checkMailout() {
	var dfy = document.forms[0].date_from_Y.options[document.forms[0].date_from_Y.selectedIndex].value
	var dfm = document.forms[0].date_from_M.options[document.forms[0].date_from_M.selectedIndex].value
	var dfd = document.forms[0].date_from_D.options[document.forms[0].date_from_D.selectedIndex].value
	var dty = document.forms[0].date_to_Y.options[document.forms[0].date_to_Y.selectedIndex].value
	var dtm = document.forms[0].date_to_M.options[document.forms[0].date_to_M.selectedIndex].value
	var dtd = document.forms[0].date_to_D.options[document.forms[0].date_to_D.selectedIndex].value
	if(dfy == dty){
		if(dfm == dtm){
			if(dfd == dtd){
				alert("Date Range Error: The date range must have a difference of at least one day.")
				return false
			}else if(dfd > dtd){
				alert("Date Range Error: The FROM date must be before the the TO date.")
				return false
			}
		}else if(dfm > dtm){
				alert("Date Range Error: The FROM date must be before the the TO date.")
				return false
		}
	}else if(dfy > dty){
				alert("Date Range Error: The FROM date must be before the the TO date.")
				return false
	}
	return true
}

function change_total_option() { 
	//called from form_manage.php to select option for One Company, Specified Date
	
    document.totals.total_option[3].checked = true;
}


