var bigstring = " ";

function convert(el,target){
	text1 = el.value;
	select = $(target);

	var newstring = text1.split(" ");
	//var numstring =  "50 01 02 03 04 05 06 51 07 08 09 49 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";
 	//var numstates = numstring.split(" ");
	var states_list = "ak al ar az ca co ct dc 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 == "clear"){
	  for(var i=0;i<51;i++){
	    select.options[i].selected = false;
	  }
	  return;
	}

	if(text1 == "all"){
	  for(var i=0;i<51;i++){
	    select.options[i].selected = true;
	  }
	  return;
	}

	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!=11)) || (newstring[j]=="50")){
					select.options[i].selected = true;
				}
			}
		}
	}
}

function selectState(value, ids){
  if(value < 0) return;
  var select_ids = ids.split(" ");
  for(var i = 0 ; select_ids[i] ; i++){
    $(select_ids[i]).options[value].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.value, '- Full 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')

  doesexistradio(document.form1.disclosure, '- Transport21 Disclosure/Release', 1)
  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 change_total_option() {
	//called from form_manage.php to select option for One Company, Specified Date

    document.totals.total_option[3].checked = true;
}

function confirmdeleteall() {
	//called from include_application app approve/delete multiple page without details

	var answer = confirm('Are you sure you want to delete all the checked applications?')

	if(answer) {
		theform.operation.value='application_Delete_Multiple';
		theform.submit()
	}else{
		alert('No applications were deleted.')
	}
}
