////
// this js file is for the agent part of 
// Mimian software
// writen by Jacob Daniel Haddon
////

 
 
 
function stringSplit ( string, delimiter ) { 
    if ( string == null || string == "" ) { 
   return null ; 
    } else if ( string.split != null ) { 
   return string.split ( delimiter ) ; 
    } else { 
   var ar = new Array() ; 
   var i = 0 ; 
   var start = 0 ; 
   while( start >= 0 && start < string.length ) { 
       var end = string.indexOf ( delimiter, start ) ; 
       if( end >= 0 ) { 
      ar[i++] = string.substring ( start, end ) ; 
      start = end+1 ; 
       } else { 
      ar[i++] = string.substring ( start, string.length ) ; 
      start = -1 ; 
       } 
   } 
   return ar ; 
    } 
} 
 
var menu1 = new Array(); 
var menu2 = new Array(); 
 
function createMenus () { 
 
    for ( var i=0; i < counties.length; i++ ) { 
        menu1[i] = stringSplit ( counties[i], '*' ); 
        menu2[i] = stringSplit ( menu1[i][1], '|' ); 
    } 
 
    var statelist = document.states.cov_state; 
 //   var countylist = document.states.cov_county; 
 
 
 
    statelist.length = menu1.length; 
//    countylist.length = menu2[0].length; 
    for ( var i=0; i < menu1.length; i++ ) { 
         statelist.options[i].value  = menu1[i][0]; 
         statelist.options[i].text   = menu1[i][0]; 
    } 
    document.states.cov_state.selected = 0; 
//    for (var x=0; x < menu2[0].length; x++) { 
//         countylist.options[x].text = menu2[0][x]; 
//         countylist.options[x].value = menu2[0][x]; 
//    } 
} 
 
function createMenus2 (form) { 
 
    for ( var i=0; i < counties.length; i++ ) { 
        menu1[i] = stringSplit ( counties[i], '*' ); 
        menu2[i] = stringSplit ( menu1[i][1], '|' ); 
    } 
 
    var statelist = document[form].cov_state; 
    var countylist = document[form].cov_county; 
 
 
 
    statelist.length = menu1.length; 
    countylist.length = menu2[0].length; 
    for ( var i=0; i < menu1.length; i++ ) { 
         statelist.options[i].value  = menu1[i][0]; 
         statelist.options[i].text   = menu1[i][0]; 
    } 
    document[form].cov_state.selected = 0; 
    for (var x=0; x < menu2[0].length; x++) { 
         countylist.options[x].text = menu2[0][x]; 
         countylist.options[x].value = menu2[0][x]; 
    } 
} 
 
function updateMenus ( what ,form) { 
    var sel = what.selectedIndex; 
    var temp = menu2[sel]; 
    document[form].cov_county.length = temp.length; 
 
    for ( var i = 0; i < temp.length; i++ ) { 
  document[form].cov_county.options[i].text = temp[i]; 
  document[form].cov_county.options[i].value = temp[i]; 
    } 
} 
 
function stateSelect () { 
var tito = document.states.cov_state; 
if (tito.options[tito.selectedIndex].value != "none") { 
location = 'http://www.ushud.com/cgi-bin/counties.pl?state=' + tito.options[tito.selectedIndex].value;
  } 
} 
