////
// 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 createMenus2(tmpForm) {
	for (var i=0; i < counties.length; i++) {
	  menu1[i] = stringSplit ( counties[i], '*' );
	  menu2[i] = stringSplit ( menu1[i][1], '|' );
	}

	var statelist = document[tmpForm].cov_state;
	var countylist = document[tmpForm].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[tmpForm].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 createMenus () { 
 
    for ( var i=0; i < counties.length; i++ ) { 
        menu1[i] = stringSplit ( counties[i], '*' ); 
        menu2[i] = stringSplit ( menu1[i][1], '|' ); 
    } 
 
    var statelist = document._Email.cov_state; 
    var countylist = document._Email.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].substring(0,22) 
         statelist.options[i].text   = menu1[i][0]
    } 
    document._Email.cov_state.selected = 0; 
    for (var x=0; x < menu2[0].length; x++) { 
//         countylist.options[x].text = menu2[0][x].substring(0,22); 
         countylist.options[x].text = menu2[0][x]
         countylist.options[x].value = menu2[0][x]; 
    } 
} 

function updateMenus2 ( tmpForm, what ) {
	var sel = what.selectedIndex;
	var temp = menu2[sel];
	document[tmpForm].cov_county.length = temp.length;

	for ( var i = 0; i < temp.length; i++ ) {
		document[tmpForm].cov_county.options[i].text = temp[i];
		document[tmpForm].cov_county.options[i].value = temp[i];
	}
}
 
function updateMenus ( what ) { 
    var sel = what.selectedIndex; 
    var temp = menu2[sel]; 
    document._Email.cov_county.length = temp.length; 
 
    for ( var i = 0; i < temp.length; i++ ) { 
//  document._Email.cov_county.options[i].text = temp[i].substring(0,22); 
  document._Email.cov_county.options[i].text = temp[i];
  document._Email.cov_county.options[i].value = temp[i]; 
    } 
} 
 
 
function addStateStr() { 
//// 
// this adds state|counties to the counties list 
//// 
var dec = document.EmailAlert.cov_state 
for ( i=0; i < document.EmailAlert.cov_county.length; i++ ) { 
 if (document.EmailAlert.cov_county.options[i].selected) { 
  var j = document.EmailAlert.counties.length; 
  document.EmailAlert.counties.length++; 
  var stList = dec[dec.selectedIndex].value + "_" + document.EmailAlert.cov_county.options[i].value; 
  if (dec[dec.selectedIndex].value != null) { 
//   document._Email.counties.options[j].text = stList.substring(0,22); 
   document.EmailAlert.counties.options[j].text = stList; 
   document.EmailAlert.counties.options[j].value = stList; 
  } 
 }// if 
 
} // for 
 
 
} // stateStr 
 
function removeStateStr() { 
//// 
// this function removes state|counties from the counties list 
//// 
 
for ( i=0; i < document.EmailAlert.counties.length; i++ ) { 
 if (document.EmailAlert.counties.options[i].value != "msg") { 
  if (document.EmailAlert.counties.options[i].selected) { 
  document.EmailAlert.counties.options[i] = null; 
  }// if 
 } // if 
} // for 
 
} // removeStateStr 
 
function stStr() { 
//// 
// this function creates the strings for the states and the  
// phone numbers for the makeagent perlscript 
//// 
 
var str = "states"; 
for ( i=0; i < document._Email.counties.length; i++ ) { 
 if (document._Email.counties.options[i].value != "msg") { 
  str += "," + document._Email.counties.options[i].value; 
 } // if 
} // for 
document._Email.stateStr.value = str; 
}

