1 var debug = 0;
  2 var newWin;
  3 var curPtr;  //global needed so that popup window can refer to its parent value
  4 var errors_array = new Array();
  5 var plaintiff_list = new Array();
  6 var defendant_list = new Array();
  7 var plaintiffaty_list = new Array();
  8 var defendantaty_list = new Array();
  9 
 10 var states = new Array("Alabama",
 11 					   "Alaska",
 12 					   "Arizona",
 13 					   "Arkansas",
 14 					   "California",
 15 					   "Colorado",
 16 					   "Connecticut",
 17 					   "Delaware",
 18 					   "DC",
 19 					   "Florida",
 20 					   "Georgia",
 21 					   "Hawaii",
 22 					   "Idaho",
 23 					   "Illinois",
 24 					   "Indiana",
 25 					   "Iowa",
 26 					   "Kansas",
 27 					   "Kentucky",
 28 					   "Louisiana",
 29 					   "Maine",
 30 					   "Maryland",
 31 					   "Massachusetts",
 32 					   "Michigan",
 33 					   "Minnesota",
 34 					   "Mississippi",
 35 					   "Missouri",
 36 					   "Montana",
 37 					   "Nebraska",
 38 					   "Nevada",
 39 					   "New Hampshire",
 40 					   "New Jersey",
 41 					   "New Mexico",
 42 					   "New York",
 43 					   "North Carolina",
 44 					   "North Dakota",
 45 					   "Northern Mariana Islands",
 46 					   "Ohio",
 47 					   "Oklahoma",
 48 					   "Oregon",
 49 					   "Pennsylvania",
 50 					   "Rhode Island",
 51 					   "South Carolina",
 52 					   "South Dakota",
 53 					   "Tennessee",
 54 					   "Texas",
 55 					   "Utah",
 56 					   "Vermont",
 57 					   "Virginia",
 58 					   "Washington",
 59 					   "West Virginia",
 60 					   "Wisconsin",
 61 					   "Wyoming",
 62 					   "Guam",
 63 					   "Virgin Islands");
 64 			
 65 var citizenships = new Array("NA",
 66 						 	 "1 Citizen of This State",
 67             				 "2 Citizen of Another State",
 68             				 "3 Citizen of Foreign Country",
 69             				 "4 Incorporated or Principal Place of Business in This State",
 70             				 "5 Incorporated and Principal Place of Business in Another State",
 71             				 "6 Foreign Nation");
 72 
 73 var types = new Array("1. Individual", "2. Corporation or Group", "3. U.S. Government", "4. State or Local Government");
 74 
 75 var gov_types = new Array("1. Agency", "2. Agent or Officer", "3. Individual Acting in Official Capacity");
 76 
 77 /**
 78  * Validates that attorney has properly filled out form
 79  * Two different classifications are supported: 
 80  *    1) Condition required   (certain items must be filled or set if particular scenario)
 81  *    2) Required             (always required)
 82  * @return were errors found?
 83  */
 84 
 85 function checkErrors() {
 86    var errors_found = false;
 87    for(var err in err_main_checks) {
 88 	  switch(err) {
 89 		 case "cond_required":
 90 		     for (var cond_req in err_main_checks.cond_required) {
 91                 var err_encountered = false;
 92 			    var formItem = document.forms[0][cond_req];
 93 			    if (formItem) {
 94 
 95                 //Radio group
 96                 if (formItem[0] && formItem[0].type == 'radio') {
 97                    formItem = formItem[ getCheckedMember(formItem) ]; 
 98                 }
 99 				    var cond_req = err_main_checks[err][cond_req];
100                 if ( cond_req.length ) { // array
101 				       for(var x=0; x < cond_req.length; x++) {
102 					       
103                       if ( !formItem ||
104                             eval("formItem." + cond_req[x].condition) ) {
105 						 
106                          for(var y in cond_req[x].required) {
107                             if ( document.forms[0][y].value == "" ||
108                                document.forms[0][y].value == undefined) {
109                                errors_array.push( cond_req[x]["required"][y] + " cannot be blank.");
110 		                         errors_found = true; 
111 						          } 
112 						       }
113 					       }
114 				       }
115 				   
116 				    }
117 		      else {
118 				   if ( !formItem ||
119                     eval("formItem." + cond_req.condition) ) {
120 
121 				       for(var y in cond_req.required) {
122 						  if ( document.forms[0][y].value == "" ||
123                                document.forms[0][y].value == undefined) {
124 							  errors_array.push( cond_req['required'][y] + " cannot be blank.");
125 							  errors_found = true;
126 						  }
127 					   }
128 				   }
129 				}
130 			  } // if formObj defined
131 				
132 			 }// for cond_req
133 			 
134             
135 		     break;
136 			 
137 		 case "required":
138 		     for(var req in err_main_checks.required) {
139 				var err_encountered = false;
140 				var formObj = document.forms[0][req];
141 			   if ( formObj ) {	
142 				if ( formObj[0] ) {
143 				   var is_checked = false;
144 
145                if ( formObj[0].type ) {
146 				      for(var rad=0; rad < formObj.length; rad++) {
147 					      if (formObj[rad].type == "radio") {
148 					         if (formObj[rad].checked) {
149 						         is_checked = true;
150 						         break;  
151 					         }
152 				         }
153 				      }
154      
155 	  			      if ( formObj[0].type == "radio" && !is_checked ) { 
156 					      err_encountered = true;  
157 				      }
158                }
159                else {
160 				      if ( formObj.value == "" || 
161 					      formObj.value == undefined) { 
162 				         err_encountered = true;
163 				      }
164                }
165 				}
166 				else {
167 				   if ( formObj.value == "" || 
168 					    formObj.value == undefined) { 
169 				      err_encountered = true;
170 				   }
171 				}
172 				
173 				if ( err_encountered ) {
174 				   errors_array.push( err_main_checks.required[req] + " cannot be blank.");
175 				   errors_found = true;
176 				}
177 			   } // if formObj exists
178 			 }
179 		     break;
180 		
181 	  }
182    }
183    
184    return errors_found;
185 }
186 
187 // For each designated GUI component, perform the associated checks.
188 /*
189    Template for error checks:
190       if classification == required
191          (array of required fields/form inputs)
192       else if classification == cond_required  (condition required)
193          for each conditional formitem
194              if more than 1 condition
195                 declare array of objects containing:
196                     - condition  (javascript conditional)
197                     - required   (what fields are required when this condition is met)
198              else
199                 declare object containing:
200                     - condition  (javascript conditional)
201                     - required   (what fields are required when this condition is met)
202              end if 
203       end if
204            
205 
206 */
207 var err_main_checks = { 
208 	required:  
209 		{districts: "Filing District",
210 		 NOS: "Nature of Suit",
211 		 Cause_of_Action: "Cause of Action", 
212 		 class_action: "Class Action/Non-Class Action",
213 		 jury_demand: "Jury Demand",
214 		 sheet_date: "Cover Sheet Date",
215 		 sheet_signature: "Cover Sheet Signature",
216 		 plaintiff_county: "Plaintiff's County",
217 		 defendant_county: "Defendant's County",
218 		 districts: "Filing District",
219 		 claim_county: "County Where Claim For Relief Arose"},
220 	cond_required: 
221 		{refiling: [ 
222 			{condition: "value == 'RELATED'",
223 			 required: 
224 			 	{related_no: "Related Case Number", 
225 				 related_judge: "Related Judge"}},
226 			{condition: "value == 'IS'",
227 			 required:  
228 			 	{refile_no: "Refile Case Number", 
229 				 refile_judge: "Refile Judge"}}],
230 		 origin: [
231 		 	{condition: "value == '2. Removed From State Court'",
232 		 	 required: 
233 		 	 	{stateremoval_co: "State Removal County",
234 		 	 	 stateremoval_casenum: "State Removal Case Number"}},
235 		 	{condition: "value == '5. Transferred from another district'",
236 		 	 required: 
237 		 	 	{transfer_district: "Transfer District",
238 		 	 	 transfer_casenum: "Transfer Case Number"}}],
239 		 PrevRewardReview:
240 			{condition: "value == 'Yes'",
241 			 required:  
242 			 	{PrevRewardReview_CaseNum: "Previous Reward Review Case Number" }}}};
243 
244 var err_popup_checks = {};						
245 
246 /**
247  * Container method for setting hidden form variables and calling error checking routines
248  * @param form - HTML form
249  * @return form is validated or not
250  */
251 function checkForm(form) {
252 	setHidden();
253 	if (!checkErrors() ) {
254 		setDynamicCookie();
255 		//form.submit()
256 		createForm(form);
257 	} else {
258 		printErrors(); 
259 		return false;
260 	}
261 }
262 
263 /**
264  * Send all compiled errors to an alert box
265  */
266 function printErrors() {
267 	var errors = '';
268 	for (var x=0; x < errors_array.length; x++) {
269 		errors += errors_array[x] + "\n";     
270 	}
271    
272 	alert(errors);
273    
274 	while(errors_array.length > 0) {
275 		errors_array.pop();   
276 	}
277 }
278 
279 function getCheckedMember(radio) {
280 	for(var i=0; i < radio.length; i++) {
281 		if (radio[i].checked) {
282 			return i;
283 		}
284 	}
285 }
286 
287 /**
288  * Dynamically populates a dropdown with the current attorney's associated clients
289  * @param ptytype Plaintiff Attorney or Defendant Attorney 
290  * @see revealPopup()
291  */
292 function populateParties(ptytype) {
293 	var ptyprefix;
294 	var pty;
295 	switch(ptytype) {
296 		case 'Plaintiff Attorney':
297 			ptyprefix = 'assoc_plas';
298 			pty = 'Plaintiff';
299 			break;
300 		case 'Defendant Attorney':
301 			ptyprefix = 'assoc_dfts';
302 			pty = 'Defendant';
303 			break;
304 		default:
305 			return;    // Not aty screen.
306 	}
307 	var ptyselect = newWin.document.createElement("SELECT");
308 	ptyselect.setAttribute("name",ptyprefix);
309 	ptyselect.setAttribute("id",ptyprefix);
310 	ptyselect.setAttribute("multiple",true);
311 	ptyselect.setAttribute("size",4);
312 	var ptylist = (ptytype == 'Plaintiff Attorney') ? plaintiff_list : defendant_list;
313 	for (var x=0; x < ptylist.length; x++) {
314 		var ptyoption = newWin.document.createElement("OPTION");
315 		var curptyinfo = spacePrint(ptylist[x].title,false) +
316 						 spacePrint(ptylist[x].fname,false) +
317 						 spacePrint(ptylist[x].mname,false) +
318 						 spacePrint(ptylist[x].lname,false) +
319 						 spacePrint(ptylist[x].generation,true); 
320 		ptyoption.appendChild( newWin.document.createTextNode(curptyinfo) );					   
321 		ptyoption.setAttribute("value",x);
322 		ptyselect.appendChild(ptyoption);
323 	}
324    
325 	// Keep a dropdown present, so isn't undefined w/ other code
326 	if (ptyselect.childNodes.length > 0) {
327 		newWin.document.getElementById('assoc_lbl').style.visibility = 'visible';
328 		newWin.document.getElementById(ptyprefix + "_div").appendChild(ptyselect);
329 	} else {
330 		newWin.document.getElementById('assoc_lbl').style.visibility = 'hidden';   
331 	}
332 }
333 
334 /**
335  * Updates the list of plaintiffs, defendants, or attorneys
336  * @param theform The form name: add_form or edit_form
337  * @param type The type of list: plaintiff, defendant, plaintiffaty, or defendantaty\
338  * @see revealPopup()
339  * @see recallPrevFormData()
340  */
341 function updatePersonList(theform,type) {
342 	var curtable = document.getElementById(type + "_tbl");
343 	var currentID=0;
344 	var curlist = eval(type + "_list");
345 	if (theform.name.match(/tempform/)) 
346 		newWin = self;
347 	if (theform.name == "add_form" || theform.name.match(/tempform/) ) {
348 		var person_obj = {title: theform.title,
349 						  fname: theform.fname,
350 						  mname: theform.mname,
351 						  lname: theform.lname,
352 						  generation: theform.generation,
353 						  citizenship: theform.citizenship,
354 						  sor: theform.sor};
355 		var row = document.createElement("TR");
356 		var name_cell = document.createElement("TD");
357 		var link_cell = document.createElement("TD");
358 		var delete_span = document.createElement("SPAN");
359 		var edit_span = document.createElement("SPAN");
360  
361 		link_cell.setAttribute("width","10%");
362 		edit_span.onclick = function() { window.revealPopup(this); };
363 		delete_span.onclick = function() { window.revealPopup(this); };
364 	  
365 		edit_span.setAttribute("name","edit_" + type);
366 		edit_span.appendChild( document.createTextNode("Edit") );
367 		edit_span.style.textDecoration = "underline";
368 		edit_span.style.marginLeft = 5;
369 		edit_span.style.marginRight = 5;
370 		edit_span.style.color = "blue";
371 		edit_span.style.cursor = "pointer";
372 		edit_span.name = "edit_" + type;
373 	 
374 		delete_span.style.textDecoration = "underline";
375 		delete_span.style.color = "blue";
376 		delete_span.style.cursor = "pointer";
377 		delete_span.style.marginLeft = 5;
378 		delete_span.style.marginRight = 5;
379 		delete_span.name = "delete_" + type;
380 		delete_span.appendChild(document.createTextNode("Delete") );
381 	  
382 		name_cell.setAttribute("align","right");
383 		name_cell.setAttribute("width","40%");
384 		name_cell.innerHTML = spacePrint(theform.title.value,false) +
385 							  spacePrint(theform.fname.value,false) +
386 							  spacePrint(theform.mname.value,false) +
387 							  spacePrint(theform.lname.value,false) +
388 							  spacePrint(theform.generation.value,true);
389 		if (curlist.length == 0)
390 			name_cell.innerHTML = spacePrint("<font color=red>First Listed:</font>  ",false) + name_cell.innerHTML;
391 		link_cell.appendChild(edit_span);	  
392 		link_cell.appendChild(delete_span);
393 		link_cell.setAttribute("align","right");
394 	  
395 		var curlistidx = curlist.length;
396 		row.setAttribute("id",type + "_row_" + (curlistidx) );
397 		row.appendChild(name_cell);
398 		row.appendChild(link_cell);
399 		curtable.tBodies[0].appendChild(row);
400 		if (!type.match(/aty/g))
401 		   curlist[curlistidx] = {title: theform.title.value,
402 		   		          fname: theform.fname.value,
403 				          mname: theform.mname.value,
404 				          lname: theform.lname.value,
405 				          generation: theform.generation.value,
406 				          citizenship: theform.citizenship.value,
407 				          sor: theform.sor.value};
408 		else
409 		   curlist[curlistidx] = {title: theform.title.value,
410 		   		          fname: theform.fname.value,
411 				          mname: theform.mname.value,
412 				          lname: theform.lname.value,
413 				          generation: theform.generation.value};
414 		if (type.match(/aty/g) ) {
415 			curlist[curlistidx].firm = theform.firm.value;
416 			curlist[curlistidx].address = theform.address.value;
417 			curlist[curlistidx].phone = theform.phone.value;
418 			curlist[curlistidx].city = theform.city.value;
419 			curlist[curlistidx].state = theform.state.value;
420 			curlist[curlistidx].zip = theform.zip.value;
421 			curlist[curlistidx].fax = theform.fax.value;
422 			curlist[curlistidx].email = theform.email.value;
423 		 
424 			var ptyprefix;
425 
426 			if (!theform.name.match(/tempform/) && newWin.document.getElementById('assoc_lbl').style.visibility == "visible") {
427 				if (newWin.document.getElementById('assoc_plas_div') )
428 					ptyprefix = "assoc_plas";
429 				else
430 					ptyprefix = "assoc_dfts"; 
431 				var ptyselect = theform[ptyprefix];
432 				if (ptyselect.childNodes.length > 0) {
433 					curlist[curlistidx][ptyprefix] = new Array();
434 					for (var x=0; x<ptyselect.options.length; x++)
435 						if (ptyselect.options[x].selected == true)
436 							curlist[curlistidx][ptyprefix].push(ptyselect.options[x].value);
437 				}
438 			}//if add_form && visible
439 
440 			if (theform.name.match(/tempform/) && theform.name.match(/aty/)) {
441 				var ptyprefix;
442 				if (theform.name.match(/plaintiff/)) 
443 					ptyprefix = "assoc_plas";
444 				else 
445 					ptyprefix = "assoc_dfts";
446 				curlist[curlistidx][ptyprefix] = new Array();
447 				var associtems = theform[ptyprefix].value.split(',');
448 				for (var item=0; item < associtems.length; item++)
449 					curlist[curlistidx][ptyprefix].push(associtems[item]);
450 			}
451 		} // if aty
452 							
453 	} else if (theform.name == "edit_form") {	   
454 		var person_obj = {title: theform.title,
455 						  fname: theform.fname,
456 						  mname: theform.mname,
457 						  lname: theform.lname,
458 						  generation: theform.generation,
459 						  citizenship: theform.citizenship,
460 						  sor: theform.sor};
461 					 
462 		if (type.match(/aty/g)) {
463 			person_obj.firm = theform.firm;
464 			person_obj.phone = theform.phone;
465 		        person_obj.address = theform.address;
466 			person_obj.city = theform.city;
467 		 	person_obj.state = theform.state;
468 			person_obj.zip = theform.zip;
469 			person_obj.fax = theform.fax;
470 			person_obj.email = theform.email;
471 		}
472 	
473 		var curRow = curPtr.parentNode.parentNode;     // "Edit Link" => Table "Link" Cell => Table Row
474 		curRow.cells[0].innerHTML = spacePrint(theform.title.value,false) +
475 									spacePrint(theform.fname.value,false) +
476 									spacePrint(theform.mname.value,false) +
477 									spacePrint(theform.lname.value,false) +
478 									spacePrint(theform.generation.value,true);
479 		var a_curRow = curRow.id.split("_");
480 		currentID = a_curRow[2];
481 
482 		if (currentID == 0)
483 			curRow.cells[0].innerHTML = spacePrint("<font color=red>First Listed:</font>  ",false) + curRow.cells[0].innerHTML;
484 			
485 		if (!type.match(/aty/g)) 
486 		   curlist[currentID] = {title: theform.title.value,
487 	                                 fname: theform.fname.value,
488 		   		         mname: theform.mname.value,
489 		   		         lname: theform.lname.value,
490 				         generation: theform.generation.value,
491 				         citizenship: theform.citizenship.value,
492 				         sor: theform.sor.value};   
493 	        else
494 		   curlist[currentID] = {title: theform.title.value,
495 	                                 fname: theform.fname.value,
496 		   		         mname: theform.mname.value,
497 		   		         lname: theform.lname.value,
498 				         generation: theform.generation.value};   
499 						
500 		if (type.match(/aty/g) ) {						
501 			curlist[currentID].firm = theform.firm.value;
502 	        curlist[currentID].address = theform.address.value;
503 	        curlist[currentID].phone = theform.phone.value;	 
504 			curlist[currentID].city = theform.city.value;
505 			curlist[currentID].state = theform.state.value;
506 			curlist[currentID].zip = theform.zip.value;
507 			curlist[currentID].fax = theform.fax;
508 			curlist[currentID].email = theform.email;
509 		 
510             var ptyprefix;
511 		    if (newWin.document.getElementById('assoc_lbl').style.visibility == "visible") {
512 				if (newWin.document.getElementById('assoc_plas_div') )
513 					ptyprefix = "assoc_plas";
514 				else 
515 					ptyprefix = "assoc_dfts"; 
516 		    
517 		       	// Kill the old assoc_pty data  (assoc_pla or assoc_dft), then recreate array
518 				delete curlist[currentID][ptyprefix];
519 				if (theform[ptyprefix].childNodes.length > 0) {
520 					curlist[currentID][ptyprefix] = new Array();
521 					for (var x=0; x < theform[ptyprefix].options.length; x++)
522 						if (theform[ptyprefix].options[x].selected)
523 							curlist[currentID][ptyprefix].push(theform[ptyprefix].options[x].value);
524 				}		 		 
525 			}
526 		}
527 	}
528 	document.getElementById(type + "_tbl_div").style.visibility = "visible";
529 
530 	if (type == "plaintiff" ||type == "defendant") {
531 		if ((theform.name == "add_form" && curlist.length == 1) || (theform.name == "edit_form" && currentID == 0))
532 			if (type == "plaintiff") {
533 				this.document.forms[0].plaintiff_county.value = theform.county.value;
534 				//this.document.forms[0].plaintiff_type.value = theform.type.value;
535 				//this.document.forms[0].plaintiff_gov_type.value = theform.gov_type.value;
536 			} else {
537 				this.document.forms[0].defendant_county.value = theform.county.value;
538 				//this.document.forms[0].defendant_type.value = theform.type.value;
539 				//this.document.forms[0].defendant_gov_type.value = theform.gov_type.value;
540 			}
541 	}
542 	if (!theform.name.match(/tempform/) )
543 		newWin.close();
544 	else
545 		newWin = undefined;
546 }
547 
548 function spacePrint(val,last) {
549 	if (val == "") return "";
550 	else 
551 		if (last) return val + "";
552 		else return val + " ";
553 }
554 /**
555 * Allows input of additional information based on pulldown menu selections ( i.e. "Basis of Jurisdiction" selection on the Case Information tab)
556 * @param elem Selected item
557 * @param yesno true or false
558 * @param popup true or false
559 * @see revealPopup()
560 * @see recallDynamicData()
561 */
562 function revealAssocGUI(elem,yesno,popup) {
563   if (yesno) {
564      if (elem.value == "2. Removed From State Court") {
565         (popup) ? newWin.document.getElementById(elem.name + "GUI").style.display = "block" :
566                   document.getElementById(elem.name + "GUI").style.display = "block";
567         (popup) ? newWin.document.getElementById(elem.name + "GUI").style.visibility = "visible" :
568                   document.getElementById(elem.name + "GUI").style.visibility = "visible";
569         // 12.9.09 RRW -  Block the popups for selection #5...
570         (popup) ? newWin.document.getElementById(elem.name + "GUI2").style.display= "none" : 
571                   document.getElementById(elem.name + "GUI2").style.display= "none"; 
572         (popup) ? newWin.document.getElementById(elem.name + "GUI2").style.visibility = "hidden" :
573                   document.getElementById(elem.name + "GUI2").style.visibility = "hidden";
574                   
575      }else if (elem.value == "5. Transferred from another district") {
576         (popup) ? newWin.document.getElementById(elem.name + "GUI2").style.display = "block" :
577                   document.getElementById(elem.name + "GUI2").style.display = "block";
578         (popup) ? newWin.document.getElementById(elem.name + "GUI2").style.visibility = "visible" :
579                   document.getElementById(elem.name + "GUI2").style.visibility = "visible";
580         // 12.9.09 RRW -  Block the popups for selection #2...
581         (popup) ? newWin.document.getElementById(elem.name + "GUI").style.display= "none" : 
582                   document.getElementById(elem.name + "GUI").style.display= "none"; 
583         (popup) ? newWin.document.getElementById(elem.name + "GUI").style.visibility = "hidden" :
584                   document.getElementById(elem.name + "GUI").style.visibility = "hidden";            
585                   
586      }else if(elem.value == "1. Original Proceeding" || elem.value == "3. Remanded From Appellate Court" || elem.value == "4. Reinstated or Reopened" || elem.value == "6. Multidistrict Litigation" ){
587      //else if(elem.value == "1. Original Proceeding" || elem.value == "3. Remanded From Appellate Court" || elem.value == "4. Reinstated or Reopened" || elem.value == "5. Transferred from another district" || elem.value == "6. Multidistrict Litigation" ){   
588         //alert("revealAssocGUI(" + elem.name + "," + yesno + ") if " + elem.value + " not equal to 2");
589         (popup) ? newWin.document.getElementById(elem.name + "GUI").style.display= "none" : 
590                   document.getElementById(elem.name + "GUI").style.display= "none"; 
591         (popup) ? newWin.document.getElementById(elem.name + "GUI").style.visibility = "hidden" :
592                   document.getElementById(elem.name + "GUI").style.visibility = "hidden";
593           
594      }else { 
595 	    
596 	    //alert("revealAssocGUI(" + elem.name + "," + yesno + ") for Social Security Appeals ");
597        (popup) ? newWin.document.getElementById(elem.name + "GUI").style.display= "block" : 
598                 document.getElementById(elem.name + "GUI").style.display= "block"; 
599         (popup) ? newWin.document.getElementById(elem.name + "GUI").style.visibility = "visible" :
600                   document.getElementById(elem.name + "GUI").style.visibility = "visible";
601         // 12.9.09 RRW -  Block the popups for selection #5...
602         (popup) ? newWin.document.getElementById(elem.name + "GUI2").style.display= "block" : 
603                 document.getElementById(elem.name + "GUI").style.display= "block"; 
604         (popup) ? newWin.document.getElementById(elem.name + "GUI2").style.visibility = "visible" :
605                   document.getElementById(elem.name + "GUI").style.visibility = "visible";
606      }
607   }
608 }
609 
610 /**
611  * Reveals GUI for creating/editing/deleting parties and their attorneys
612  * @param obj - form item  (expected to be a button)
613  */
614 function revealPopup(obj) { 
615    	var objData = obj.name.split("_");
616 	var curmode = objData[0];
617 	var curtype = objData[1];
618 	var winHTML;
619   
620 	if (curmode == undefined) {
621 		alert("UNDEFINED");
622 		newWin.close();
623 		return;
624 	}
625 	if (curmode == "NOS") { //Nature of suit 
626 		newWin = window.open("","newWin","height=150,width=350,toolbar=no,scrollbars=no,status=no,menubar=no");
627 		winHTML = "<html><body><center>";
628 		winHTML += "Does this case seek review of an application that was previously rewarded by this court?";
629 		winHTML += "<select id=\"PrevRewardReview\" name=\"PrevRewardReview\" onchange='javascript:self.opener.revealAssocGUI(this,true,true);'";
630 		winHTML += ">";
631 		winHTML += "  <option value=\"\">Choose an answer";
632 		winHTML += "  <option value=\"Yes\">Yes";
633 		winHTML += "  <option value=\"No\">No";
634 		winHTML += "</select>";
635 		winHTML += "<div id='PrevRewardReviewGUI' style='visibility:hidden'>";
636 		winHTML += "   Case Number: <input type=\"text\" size=\"20\" value=\"\" id=\"prevrewardreview_casenum\" name=\"prevrewardreview_casenum\">";
637 		winHTML += "</div>";
638 		winHTML += "<input type='button' name='prevreward_finish' id='prevreward_finish' value='Continue' onclick='javascript:";
639 		winHTML += " if (this.value == \"\") { } else { ";
640 		winHTML += "  self.opener.document.forms[0].PrevRewardReview.value = document.getElementById(\"PrevRewardReview\").value;";
641 		winHTML += "  self.opener.document.forms[0].PrevRewardReview_CaseNum.value = document.getElementById(\"prevrewardreview_casenum\").value;";
642 		winHTML += "self.opener.newWin.close(); } '>";  //Ending brace for this.value check
643 		winHTML += "</center></body></html>";  
644 		newWin.document.write(winHTML);
645 		newWin.document.close();
646 		if (document.forms[0].PrevRewardReview.value == 'Yes') {
647 			newWin.document.getElementById('PrevRewardReview').value = 'Yes';
648 			newWin.document.getElementById('prevrewardreview_casenum').value = document.forms[0].PrevRewardReview_CaseNum.value;
649 			revealAssocGUI(newWin.document.getElementById('PrevRewardReview'),true,true);
650 		} 
651 	} else if (curmode == "add" || curmode == "edit") { 
652 	    //console.log("curmode = " + curmode);
653 	    if(!document.getElementById('districts')){alert("Filing District is NULL"); return;}
654 	    if(document.getElementById('districts').value == ""){
655 	    alert("Please Select a Filing District");
656 	    return;
657 	    }
658 		var curRow = obj.parentNode.parentNode.id.split("_");   //defendant_link_2 for example
659 		var curlist = eval(curtype + "_list");
660 		var curID = curRow[2];
661 		curPtr = obj;
662 		if (curtype.match(/aty/g) ) {   // Attorney
663 			if (curtype.match(/plaintiff/g) )
664 				curtype = "Plaintiff Attorney";				 
665 			else
666 				curtype = "Defendant Attorney";   
667 			newWin = window.open("","newWin","height=625,width=525,toolbar=no,scrollbars=no,status=no,menubar=no");	   
668 		} else
669 			if ((curmode == "add" && curlist.length == 0) || (curmode == "edit" && curID == 0))
670 				newWin = window.open("","newWin","height=475,width=700,toolbar=no,scrollbars=no,status=no,menubar=no");
671 			else	 
672 				newWin = window.open("","newWin","height=350,width=700,toolbar=no,scrollbars=no,status=no,menubar=no");
673 		winHTML = "<html><head><title>" + curmode.toUpperCase() + " " + curtype.toUpperCase() + "</title>";
674         winHTML += "<body bgcolor='#ffffff' onload=\"javascript:self.opener.populateParties('" + curtype + "');self.opener.loadDistricts2(document.forms[0],'" + document.getElementById('districts').value + "','" + curtype + "');\"><center>";		
675         winHTML += "<form name=\"" + curmode + "_form\" id=\"" + curmode + "_form\">";
676 		winHTML += "<center><h3><u>" + curmode.toUpperCase() + " ";
677 		if ((curmode == "add" && curlist.length == 0) || (curmode == "edit" && curID == 0)) 
678 			winHTML += "FIRST ";
679 		else
680 			winHTML += "ADDITIONAL ";
681 		winHTML += curtype.toUpperCase() + "</u></h3></center>";
682 		winHTML += "<table width=\"90%\"  border=\"0\">";
683 		if (curtype.match(/Attorney/g) && curtype.match(/Plaintiff/g))
684 			winHTML += "<tr><td colspan=2>(Enter \"Pro Se\" if you are representing yourself without the help of an attorney.)</td></tr>";
685 		winHTML += "<tr>";
686 		winHTML += "<td>";
687 		winHTML += "Last Name: <br><input name=\"lname\" id=\"lname\" type=\"text\" size=\"30\"></td>";
688 		winHTML += "<td>First Name: <br><input name=\"fname\" id=\"fname\"type=\"text\" size=\"25\"></td>";
689 		winHTML += "</tr>";
690 		winHTML += "<tr>";
691 		winHTML += "<td>Middle Name: <br><input name=\"mname\" id=\"mname\" type=\"text\" size=\"20\"></td>";
692 		winHTML += "<td>Generation: <br><input type=\"text\" name=\"generation\" id=\"generation\" size=\"10\"></td>";
693 		winHTML += "<td> </td>";
694 		winHTML += "</tr>";
695 		winHTML += "<tr>";
696 		winHTML += "<td>Title: <br><input name=\"title\" id=\"title\" type=\"text\" size=\"20\"></td>";
697 
698 		if (curtype == "plaintiff" || curtype == "defendant") {
699 			winHTML += "</tr><tr><td colspan=2><hr></td></tr>";
700 			winHTML += "<tr><td colspan=2><center><b>Citizenship and State of Residence apply for Diversity Cases Only</b></center></td></tr>";
701 			winHTML += "<tr><td>Citizenship: <select name=\"citizenship\" id=\"citizenship\" onchange=\"javascript:if (this.selectedIndex == 0 || this.selectedIndex == 3 || this.selectedIndex == 6){document.forms[0].sor.selectedIndex=0;document.forms[0].sor.disabled = true;document.forms[0].county.selectedIndex=0;document.forms[0].county.disabled = true;}else if(this.selectedIndex == 1 || this.selectedIndex == 4){document.forms[0].sor.selectedIndex=0;document.forms[0].sor.disabled = true;document.forms[0].county.selectedIndex=0;document.forms[0].county.disabled = false;}else{document.forms[0].sor.disabled=false;document.forms[0].county.disabled=false;}\">";
702 			
703 			for (var i=0;i<citizenships.length;i++)
704 				 winHTML += "<option value=\"" + citizenships[i] + "\">" + citizenships[i] + "</option>";
705 			winHTML += "</select>";
706 			winHTML += "</td>";
707 			
708 			winHTML += "<td>State of Residence: <br><select name=\"sor\" id=\"sor\">";
709 			winHTML += "<option value=\"\"></option>";
710 			
711             for (var i=0;i<states.length;i++)
712             	winHTML += "<option value=\"" + states[i] + "\">" + states[i] + "</option>";
713 			winHTML += "</select></td></tr>";
714 			if ((curmode == "add" && curlist.length == 0) || (curmode == "edit" && curID == 0)) { //first plaintiff or defendant
715 				winHTML += "<tr><td colspan=2><hr></td></tr>";
716 				winHTML += "<tr><td colspan=2>County of residence: <br><select name=\"county\" id=\"county\">";
717 
718 				winHTML += "</select></td></tr>";
719 				
720 			}
721 		} 
722 		if (curtype.match(/Attorney/g)) {
723 			winHTML += "<td>Firm: <br><input name=\"firm\" type=\"text\" size=\"20\"></td></tr>";	 
724 			winHTML += "<tr><td>Address: <br><input type=\"text\" name=\"address\" size=\"30\"></td>";
725 			winHTML += "<td>City: <br><input type=\"text\" name=\"city\" size=\"20\"></td></tr>";
726 			winHTML += "<tr><td>State: <br><select name='state' id='state'>";
727 			for (var st=0; st < states.length; st++)
728 					winHTML += "<option value='" + states[st] + "'>" + states[st] + "\n";	 
729 			winHTML += "</select></td>";
730 			winHTML += "<td>Zipcode: <br><input type=\"text\" name=\"zip\" size=\"20\"></td></tr>";
731 			winHTML += "<tr><td>Phone: <br><input name=\"phone\" type=\"text\" size=\"15\"></td>";		
732 			winHTML += "<td>Fax: <br><input type=\"text\" name=\"fax\" size=\"15\"></td></tr>";
733 			winHTML += "<tr><td>email: <br><input name=\"email\" type=\"text\" size=\"30\"></td>";		
734 			winHTML += "<td><div id='assoc_lbl' name='assoc_lbl'>Associated "; 
735 			if (curtype.match(/Defendant/g)) {
736 				curtype = "defendantaty";
737 				winHTML += "Defendant(s):<br>";
738 				winHTML += "<span name='assoc_dfts_div' id='assoc_dfts_div'></span>";
739 			} else {
740 				curtype = "plaintiffaty";
741 				winHTML += "Plaintiff(s):<br>";
742 				winHTML += "<span name='assoc_plas_div' id='assoc_plas_div'></span>";
743 			}
744 			winHTML += "</div></td></tr>";
745 			winHTML += "<tr><td colspan='2'> </td></tr>";
746 		}
747 		winHTML += "<tr><td colspan='2' align='center'><hr></td></tr>";
748 		winHTML += "<tr><td colspan='2' align='center'><input type=\"button\" name=\"person_add_btn\" value=\"Confirm " + curmode.toUpperCase() + "\" onclick=\"javascript:self.opener.updatePersonList(document.forms[0],'" + curtype + "');\">";
749 		winHTML += "   <input type=\"button\" name=\"person_clear_btn\" value=\"Cancel\" onclick=\"self.close();\"></td>";
750 		winHTML += "</tr>";
751 		winHTML += "</table>";
752 		winHTML += "</form>";
753 		winHTML += "</center></body></html>";
754 		newWin.document.write(winHTML);
755 		newWin.document.close();
756 		newWin.document.forms[0].lname.focus();
757 		if (curmode == "edit") {
758 			populatePersonDetail(obj); 
759 			if (curPtr != null) {
760 				var curRow = curPtr.parentNode.parentNode;     // "Edit Link" => Table "Link" Cell => Table Row
761 				var theform = newWin.document.forms[0];
762 				//console.log("the form = " + theform.name);
763 				if (curRow.cells[0].innerHTML.substring(0,1) == "<")
764 					curRow.cells[0].innerHTML = spacePrint("<font color=red>First Listed:</font>  ",false);
765 				else
766 					curRow.cells[0].innerHTML = "";
767 				curRow.cells[0].innerHTML = curRow.cells[0].innerHTML + 
768 											spacePrint(theform.title.value,false) +
769 											spacePrint(theform.fname.value,false) +
770 											spacePrint(theform.mname.value,false) +
771 											spacePrint(theform.lname.value,false) +
772 											spacePrint(theform.generation.value,true);
773 			}
774 			newWin.document.forms[0].lname.select();
775 		} 	 
776 	} else if (curmode == "delete") {
777 		// Get associated person info.  (parents => table cell => table row)
778 		// Table row children => Name Cell, Link Cell
779 		var assocPerson = obj.parentNode.parentNode.cells[0].innerHTML;
780 		curPtr = obj;  	 
781 		newWin = window.open("","newWin","height=150,width=450,toolbar=no,scrollbars=no,status=no,menubar=no"); 
782 		winHTML = "<html><head><title>" + curmode.toUpperCase() + " " + curtype.toUpperCase() + "</title>";        
783 		winHTML += "<body><center><h4>Delete the following " + curtype + ":<br><h3>" + assocPerson + "</h3></h4>";
784 		winHTML += "<input type='button' value='Confirm Delete' onclick='javascript:self.opener.deletePerson(\"" + curtype + "\");'>";
785 		winHTML += "</center>";
786 		winHTML += "</body></html>";
787 		newWin.document.write(winHTML);
788 		newWin.document.close();
789 	}
790 }
791 
792 /**
793  * Pre-populates associated person information for editing/deleting
794  * @param obj - formitem that called this function
795  * @see revealPopup()
796  */
797 function populatePersonDetail(obj) {
798 
799 	var objData = obj.name.split("_");
800 	var curmode = objData[0];
801 	var curtype = objData[1];	
802 	var curRow = obj.parentNode.parentNode.id.split("_");   //defendant_link_2 for example
803 	var curID = curRow[2];
804 
805 	with (newWin.document.forms[0]) {
806 		fname.value = eval(curtype + "_list[curID]").fname;
807 		lname.value = eval(curtype + "_list[curID]").lname;
808 		mname.value = eval(curtype + "_list[curID]").mname; 
809 		generation.value = eval(curtype + "_list[curID]").generation;
810 		title.value = eval(curtype + "_list[curID]").title; 
811 		//citizenship.selectedIndex = citizenshipIndex(eval(curtype + "_list[curID]").citizenship);
812 		//sor.selectedIndex = stateIndex(eval(curtype + "_list[curID]").sor);
813 		if (curtype == "plaintiff" || curtype == "defendant") {
814 			if (curID == 0) 
815 				if (curtype == "plaintiff") { 
816 				    //alert("populatePersonDetail() sor.value = " + sor.value);       
817 				    citizenship.selectedIndex = citizenshipIndex(eval(curtype + "_list[curID]").citizenship);
818 				    sor.selectedIndex = stateIndex(eval(curtype + "_list[curID]").sor);
819 				    //alert("this.document.forms[0].plaintiff_county.value = " + this.document.forms[0].plaintiff_county.value);
820 	    		    county.selectedIndex = countyIndex2(this.document.forms[0].plaintiff_county.value,sor.value);
821 	    		    //alert("populatePersonDetail() County selected index = " + county.selectedIndex);
822 				    //type.selectedIndex = typeIndex(this.document.forms[0].plaintiff_type.value);
823 					//gov_type.selectedIndex = gov_typeIndex(this.document.forms[0].plaintiff_gov_type.value);
824 				} else if (curtype == "defendant") {
825 					citizenship.selectedIndex = citizenshipIndex(eval(curtype + "_list[curID]").citizenship);
826 		            sor.selectedIndex = stateIndex(eval(curtype + "_list[curID]").sor);
827 					county.selectedIndex = countyIndex2(this.document.forms[0].defendant_county.value,sor.value);
828 					//type.selectedIndex = typeIndex(this.document.forms[0].defendant_type.value);
829 					//gov_type.selectedIndex = gov_typeIndex(this.document.forms[0].defendant_gov_type.value);
830 				}
831 			if (curID > 0) 
832 				if (curtype == "plaintiff") { 
833 				    //alert("populatePersonDetail() Edit Additional Plaintiff");       
834 				    citizenship.selectedIndex = citizenshipIndex(eval(curtype + "_list[curID]").citizenship);
835 		            sor.selectedIndex = stateIndex(eval(curtype + "_list[curID]").sor);
836 	    		} else if (curtype == "defendant") {
837 					//county.selectedIndex = countyIndex(this.document.forms[0].defendant_county.value);
838 					citizenship.selectedIndex = citizenshipIndex(eval(curtype + "_list[curID]").citizenship);
839 		            sor.selectedIndex = stateIndex(eval(curtype + "_list[curID]").sor);
840 					
841 				}	
842 		
843 		}
844 
845 		if (curtype.match(/aty/g)) { 
846 			firm.value = eval(curtype + "_list[curID]").firm;
847 			address.value = eval(curtype + "_list[curID]").address;
848 			phone.value = eval(curtype + "_list[curID]").phone;
849 			city.value = eval(curtype + "_list[curID]").city;
850 			state.value = eval(curtype + "_list[curID]").state;
851 			zip.value = eval(curtype + "_list[curID]").zip;
852 			fax.value = eval(curtype + "_list[curID]").fax;
853 			email.value = eval(curtype + "_list[curID]").email;
854 		 
855 			if (newWin.document.getElementById('assoc_lbl').style.visibility == "visible") {
856 				var ptytype = (curtype.match(/defendant/) ) ? 'assoc_dfts' : 'assoc_plas';
857 				var curlist = eval(curtype + "_list");
858 				var ptyselect = eval("newWin.document.forms[0][ptytype]");
859 			
860 				for (var t=0; t < ptyselect.options.length; t++) 
861 					ptyselect.options[t].selected = false;	
862 				for (var x=0; x < curlist[curID][ptytype].length; x++) 
863 					for (var y=0; y < ptyselect.options.length; y++) 
864 						if (ptyselect.options[y].value == curlist[curID][ptytype][x]) 
865 							ptyselect.options[y].selected = true; 	
866 			}
867 		}
868 	}// End of with statement
869 }
870 /**
871 * Populates Citizenship field of plaintiff or defendant to be edited/deleted
872 * @param Selected plaintiff/defendant's citizenship
873 * @returns Index of selected citizenship in pulldown list
874 * @see populatePersonDetail()
875 */
876 function citizenshipIndex(text) {
877 	for (var i=0;i<citizenships.length;i++)
878 		if (citizenships[i] == text)
879 			return i;
880 	return 0;		
881 }
882 /**
883 * Populates State field of plaintiff or defendant to be edited/deleted
884 * @param Selected plaintiff/defendant's state
885 * @returns Index of selected state in pulldown list
886 * @see populatePersonDetail()
887 */
888 function stateIndex(text) {
889 	for (var i=0;i<states.length;i++)
890 		if (states[i] == text)
891 			return i+1;
892 	return 0;
893 }
894 /**
895 * Populates Type field of plaintiff or defendant to be edited/deleted (NOT USED!!)
896 * @param Selected plaintiff/defendant's type
897 * @returns Index of selected type in pulldown list
898 * @see populatePersonDetail()
899 */
900 function typeIndex(text) {
901 	for (var i=0;i<types.length;i++)
902 		if (types[i] == text)
903 			return i+1;
904 	return 0;
905 }
906 /**
907 * Populates Gov_Type field of plaintiff or defendant to be edited/deleted (NOT USED!!)
908 * @param Selected plaintiff/defendant's government type
909 * @returns Index of selected gov_type in pulldown list
910 * @see populatePersonDetail()
911 */
912 function gov_typeIndex(text) {
913 	for (var i=0;i<gov_types.length;i++)
914 		if (gov_types[i] == text)
915 			return i+1;
916 	return 0;
917 }
918 
919 /**
920  * Change associated party IDs to reflect renumbering (from deletion) of HTML rows
921  * @param curtype - assoc_plas or assoc_dfts
922  * @param oldID - original row ID
923  * @param newID - changed row ID
924  * @see deletePerson()
925  */
926 function updateAssocParties(curtype,oldID,newID) {
927    var curlist = (curtype == 'plaintiff') ? plaintiffaty_list : defendantaty_list;
928    var assoclist = (curlist == plaintiffaty_list) ? 'assoc_plas' : 'assoc_dfts';  	
929    for(var x=0; x < curlist.length; x++) {
930       for(var idx=0; idx < curlist[x][assoclist].length; idx++) {
931          if (curlist[x][assoclist][idx] == oldID) {
932             curlist[x][assoclist][idx] = newID;						
933 			break;
934 		 }
935 	  }
936    }
937 }
938 
939 
940 /** 
941  * Delete associated party IDs (in assoc_plas or assoc_dfts) when the "curlist" element is deleted.
942  * @param curtype - assoc_plas or assoc_dfts
943  * @param ID - ID marked for deletion
944  * @see deletePerson
945  */
946 function deleteAssocParties(curtype,ID) {
947    var curlist = (curtype == 'plaintiff') ? plaintiffaty_list : defendantaty_list;
948    var assoclist = (curlist == plaintiffaty_list) ? 'assoc_plas' : 'assoc_dfts';
949    for(var x=0; x < curlist.length; x++) {
950 	  for(var idx=0; idx < curlist[x][assoclist].length; idx++) {
951          if (curlist[x][assoclist][idx] == ID) {
952 			curlist[x][assoclist].splice(idx,1);
953 			break;
954 		 }
955 	  }
956    }
957 }
958 
959 
960 /**
961  * Removes party or attorney, and associated parties from the associated HTML table
962  * @param curtype - assoc_plas or assoc_dfts 
963  * @see revealPopup()
964  */
965 function deletePerson(curtype) {
966 	// parents => table cell => table row => table body
967 	if (curPtr != null) {
968 		var curlist = eval(curtype + "_list"); 
969 		var del_index = 0;
970 		var curRow = curPtr.parentNode.parentNode; 
971 		var rowinfo_array = curRow.id.split("_");	  
972 		for(var x in curlist) {
973 			if (x == rowinfo_array[2]) break;
974 			del_index++;
975 		}
976 		deleteAssocParties(curtype,rowinfo_array[2]);
977 		curlist.splice(del_index,1);   // Compensate for delete
978 		var curTbl = document.getElementById(curtype + '_tbl').tBodies[0];
979 		var rowIndex = -99;
980 		for (var x=0; x < curTbl.rows.length; x++) {		  
981 			var curID = curTbl.rows[x].id;
982 		 	if (curRow.id == curID) { 
983 				rowIndex = curID.split("_")[2];
984 				break;
985 			}
986 		}
987 		var prevID = -99;
988 		for (var y=++rowIndex; y < curTbl.rows.length; y++) {
989 			var updID = (prevID == -99) ? curTbl.rows[y-1].id.split("_")[2] : prevID;
990 			prevID = curTbl.rows[y].id.split("_")[2]; 
991 			updateAssocParties(curtype,curTbl.rows[y].id.split("_")[2],updID);
992 			curTbl.rows[y].id = curtype + "_row_" +  updID;
993 		}
994 		curTbl.removeChild(curRow);
995 		if(debug) alert("deletePerson(): curlist.length = " + curlist.length + " and del_index = " + del_index);
996 		if (curlist.length == 0) {
997 			document.getElementById(curtype + "_tbl_div").style.visibility = "hidden";  
998 			removeCookie(curtype); 
999 		} else if (del_index == 0) 
1000 			curTbl.rows[0].cells[0].innerHTML = "<font color=red>First Listed:</font>  " + curTbl.rows[0].cells[0].innerHTML;
1001 	}
1002 	curPtr = null;
1003 	newWin.close();
1004 }
1005 
1006 
1007 /**
1008  * Dynamically populates county dropdowns based on Javascript arrays
1009  */
1010 function populateCounties() {
1011 
1012    if(debug) alert("populateCounties() based on district = " + document.forms[0].districts.value);
1013   
1014    if (document.cookie) {
1015       var districts_cookie = readCookie('districts');
1016       var claim_county = readCookie('claim_county');
1017       var state_removal = readCookie('stateremoval');
1018       if(state_removal)var st_remove = state_removal.split('|');
1019       var dist = document.forms[0].districts.value;
1020       if(debug) alert("populateCounties() District = " + districts_cookie + ". " + dist);
1021       if(dist){
1022         /**
1023          * @param formname
1024          * @param district
1025          */
1026         loadDistricts(document.forms[0],document.forms[0].districts);
1027         if (claim_county) document.forms[0].claim_county.selectedIndex = claim_county;
1028         if (st_remove) document.forms[0].stateremoval_co.selectedIndex = st_remove;
1029         }else{
1030 		   // If Filing District is left blank, users should be prompted to choose one in order to select a county.
1031 		   document.forms[0].stateremoval_co.options[0] = new Option("Please Select a Filing District","");
1032 		   document.forms[0].claim_county.options[0] = new Option("Please Select a Filing District","");
1033 
1034       }
1035    }
1036 
1037 }
1038 
1039 
1040 /**
1041  * Dynamically populates state dropdowns with Javascript arrays.  Missouri is automatically selected. (NOT USED!!)
1042  */
1043 function populateStates() {
1044    //console.log("Inside populateStates()");
1045    for(var x=0; x < states.length-1; x++) {
1046 	  newWin.document.forms[0].state.options[x] = new Option(states[x],states[x]);   
1047 	  if (states[x] == 'Missouri') newWin.document.forms[0].state.selectedIndex = x;  
1048    }
1049 }
1050 /**
1051 * Sets a cookie to retain and restore info from previous session
1052 * @see checkForm()
1053 */
1054 
1055 function setDynamicCookie() {
1056    // State Removal Info.
1057    if (document.forms[0].origin.value == '2. Removed From State Court') 
1058       updateCookie("stateremoval",document.forms[0].stateremoval_co.selectedIndex + "|" + document.forms[0].stateremoval_casenum.value);
1059       
1060    if (document.forms[0].origin.value == '5. Transferred from another district') 
1061       updateCookie("transfer",document.forms[0].transfer_district.selectedIndex + "|" + document.forms[0].transfer_casenum.value);
1062 
1063    if (document.forms[0].PrevRewardReview.value == 'Yes') {
1064       var NOS_index = getCheckedMember(document.forms[0].NOS);
1065       var NOS_code = document.forms[0].NOS[NOS_index].value.match(/(\d+)/);
1066       if (NOS_code[0] >= 861 && NOS_code[0] <= 865) {
1067          updateCookie("prevreward",document.forms[0].PrevRewardReview_CaseNum.value);
1068          document.forms[0].PrevRewardReview.value = 'Yes';
1069       }
1070       else 
1071          document.forms[0].PrevRewardReview.value = 'No';
1072    }
1073    if (document.forms[0].districts.selectedIndex != "") {
1074       if(debug)alert("setDynamicCookie(): Districts = " + document.forms[0].districts.selectedIndex);
1075       updateCookie("districts",document.forms[0].districts.selectedIndex);
1076    }
1077    if (document.forms[0].claim_county.selectedIndex != "") {
1078       if(debug) alert("setDynamicCookie(): Claim County = " + document.forms[0].claim_county.selectedIndex);
1079       updateCookie("claim_county",document.forms[0].claim_county.selectedIndex);
1080    }
1081 }
1082 
1083 function setCountyCookie(type){
1084    alert("setCountyCookie(): County = " + document.forms[0].county.selectedIndex);
1085    if (document.forms[0].county.selectedIndex != "") {
1086       if(type == "plaintiff"){ 
1087       alert("setCountyCookie(): Type = " + type);     
1088       //updateCookie("plaintiff_county",document.forms[0].county.selectedIndex);
1089       }else{
1090       alert("setCountyCookie(): Type = " + type);       
1091       //updateCookie("defendant_county",document.forms[0].county.selectedIndex);
1092       }
1093    }
1094 }
1095 
1096 
1097 
1098 /**
1099  * Sets pipe-delimited values for name info. for defendants, plaintiffs, & their
1100  * respective attorneys.
1101  * @see checkForm()
1102  */
1103  
1104 function setHidden() {
1105    var fields = new Array("defendant","plaintiff","defendantaty","plaintiffaty");
1106    for (var x=0; x < fields.length; x++) {
1107       var curlist = eval(fields[x] + "_list");
1108 	  document.forms[0][ fields[x] + "_info"].value = "";
1109 	   
1110       var delimit = 0;
1111       
1112 	  for(var entry in curlist ) {
1113 	     if (entry == "rows" || entry == "ID") { continue; }	   
1114          if (delimit > 0) document.forms[0][ fields[x] + "_info"].value += "^";
1115          else delimit = 1;
1116 
1117          var pipe = 0;
1118 		 for (var elem in curlist[entry]) {
1119 		   if (curlist[entry][elem] == "") { continue; }
1120            if (pipe > 0) document.forms[0][ fields[x] + "_info"].value += "|";
1121            else pipe = 1;
1122      	   document.forms[0][ fields[x] + "_info"].value += elem + ":" + curlist[entry][elem];
1123          }
1124 	  }  
1125       //Update cookie
1126       updateCookie(fields[x], document.forms[0][ fields[x] + "_info"].value);
1127    }
1128    updateCookie('plaintiff_county',document.forms[0].plaintiff_county.value);
1129    updateCookie('defendant_county',document.forms[0].defendant_county.selectedIndex);
1130    updateCookie('claim_county',document.forms[0].claim_county.selectedIndex);
1131 }
1132 
1133 
1134 
1135 function addBlankInput(item,form) {
1136    var newinput = document.createElement("input");
1137    newinput.name = item;
1138    newinput.id = item;
1139    newinput.value = "";
1140    newinput.type = "hidden";
1141    var a = form.appendChild(newinput);
1142 }
1143 /**
1144  * Retrieves cookie values from a temporary form 
1145  * @param item An array containing values stored in a cookie
1146  * @param form The form containing cookie values
1147  * @see recallPrevFormData()
1148  */
1149 
1150 function addCookieInputs(item,form) {
1151    
1152    if (item == '') { return null; }
1153    var curitems = item.split('|');
1154    for(var x=0; x < curitems.length; x++) {
1155       if ( curitems[x] == '') { continue; }
1156       var curfields = curitems[x].split(':');            
1157       var newinput = document.createElement("INPUT");
1158       newinput.name = curfields[0];
1159       newinput.id = curfields[0];
1160       newinput.value = curfields[1];
1161       newinput.type = "hidden";
1162       form.appendChild(newinput);
1163    }
1164 }
1165 
1166 /**
1167  * If a cookie exists, dynamically add back party info. and other dynamically added data items 
1168  * (used when Back button is used from generated Civil Cover Sheet)
1169  *
1170  * Following cookie keys may be present:
1171  *     - plaintiff_info
1172  *     - defendant_info
1173  *     - plaintiffaty_info
1174  *     - defendantaty_info
1175  *     - plaintiff_county   
1176  *     - defendant_county   
1177  *     - PrevRewardReview_CaseNum   (PrevRewardReview is implied as Yes when present)
1178  *     - stateremoval_co    
1179  *     - stateremoval_casenum
1180  *     - districts
1181  *     - claim_county
1182  *     - transfer_district  (Need to add cookie routines for transfer*)
1183  *     - transfer_casenum
1184  */
1185 
1186 function recallPrevFormData() {
1187    var inputs = new Array('title','fname','mname','lname','generation','citizenship','sor');
1188    var aty_inputs = new Array('firm','address','phone','city','state','zip','phone','fax','email');
1189    var fields = new Array("defendant","plaintiff","defendantaty","plaintiffaty");
1190 
1191    if (document.cookie) { 
1192       var defendant_cookie = readCookie('defendant');
1193       var plaintiff_cookie = readCookie('plaintiff');
1194       var placounty_cookie = readCookie('plaintiff_county');
1195       var defendantaty_cookie = readCookie('defendantaty');
1196       var plaintiffaty_cookie = readCookie('plaintiffaty');
1197       var stateremoval_cookie = readCookie('stateremoval_co');
1198       var districts_cookie = readCookie('districts');
1199       var claimcounty_cookie = readCookie('claim_county');
1200       var transfer_cookie = readCookie('transfer');
1201       
1202       var formarray = new Array();
1203  
1204       for(var i=0; i < fields.length; i++) {
1205          if ( eval(fields[i] + "_cookie") ) {
1206              eval("var " + fields[i] + "_values = " + fields[i] + "_cookie.split('^');");
1207              for(var j=0; j < eval(fields[i] + "_values").length; j++) {
1208                 var tempform = document.createElement("form");
1209                 tempform.name = "tempform_" + fields[i] + j;
1210                 tempform.id = tempform.name; 
1211                 addCookieInputs(eval(fields[i] + "_values")[j],tempform);
1212                 formarray.push(tempform);
1213                 //Each row representing a dft or pla requires a new form that contains fields for lname,fname,title,etc.
1214              }
1215           } //eval(_cookie)
1216        }//for fields length 
1217              // Loop through expected form fields, and create any that don't have a cookie value.
1218        for(var h=0; h < formarray.length; h++) {
1219           for(var x=0; x < inputs.length; x++) { 
1220                 var found = false;
1221                 var nodeinfo = '';
1222                 for(var y in formarray[h].childNodes) {
1223                    nodeinfo += " " + formarray[h].childNodes[y].name;
1224                    if ( formarray[h].childNodes[y].name == inputs[x]) {
1225                       found = true;
1226                       break;
1227                    }
1228                 }
1229                 if (!found) addBlankInput(inputs[x],formarray[h]);
1230              }
1231 
1232              if (formarray[h].name.match(/aty/g) ) {
1233                 for(var a=0; a < aty_inputs.length; a++) {
1234                    var found = false;
1235                    for (var b in formarray[h].childNodes) {
1236                       if (formarray[h].childNodes[b].name == aty_inputs[a]) {
1237                          found = true;
1238                          break;
1239                       }
1240                    }
1241                    
1242                    if (!found) addBlankInput(aty_inputs[a],formarray[h]);
1243                 }
1244          }
1245          var curtype = formarray[h].name.match(/tempform_(\w+)\d+/);
1246          updatePersonList(formarray[h],curtype[1]);
1247 
1248       }
1249    }
1250 }
1251 
1252 /**
1253 * Recalls stateremoval_co and stateremoval_casenum info
1254 */
1255 function recallDynamicData() {
1256    if (document.cookie) {
1257       var stateremoval_cookie = readCookie('stateremoval');
1258       if (stateremoval_cookie) {
1259          var stateremoval = stateremoval_cookie.split('|');
1260          document.forms[0].stateremoval_co.selectedIndex = stateremoval[0];
1261          document.forms[0].stateremoval_casenum.value = stateremoval[1];
1262          revealAssocGUI(document.forms[0].origin,true,false);
1263       }
1264       var prevreward_cookie = readCookie('prevreward');
1265       if (prevreward_cookie) {
1266          document.forms[0].PrevRewardReview_CaseNum.value = prevreward_cookie;
1267          document.forms[0].PrevRewardReview.value = 'Yes'; //implied
1268       }
1269       //041409 RRW - Added cookie for filing district...
1270       
1271       var districts_cookie = readCookie('districts');
1272       if(districts_cookie) {
1273         if(debug) alert("recallDynamicData(): Districts cookie exists");
1274         document.forms[0].districts.selectedIndex = districts_cookie;
1275         
1276       }
1277       var transfer_cookie = readCookie('transfer');
1278       if (transfer_cookie) {
1279          var xfer = transfer_cookie.split('|');
1280          document.forms[0].transfer_district.selectedIndex = xfer[0];
1281          document.forms[0].transfer_casenum.value = xfer[1];
1282          revealAssocGUI(document.forms[0].origin,true,false);
1283       }
1284    }
1285 }
1286 
1287 /**
1288  * Modifies an existing cookie value if present.  Otherwise, creates a new key/value pair.
1289  * @see setHidden()
1290  */
1291 function updateCookie(key,val,days) {
1292    var expires = '';
1293    if (days) {
1294       var date = new Date();
1295       date.setTime( date.getTime() + (days * 24 * 60 * 60 * 1000) );
1296       expires = "; expires =" + date.toGMTString(); 
1297    }
1298    else {  //Default to one day
1299       var date = new Date();
1300       date.setTime( date.getTime() + 3600 * 1000 );
1301       expires = "; expires =" + date.toGMTString();
1302    }
1303    if (val) document.cookie = key + "=" + val + expires + "; path=/";
1304 }
1305 
1306 function readCookie(key) {
1307    var nameEQ = key + "=";
1308    var ca = document.cookie.split(';');
1309    for(var x=0; x < ca.length; x++) {
1310       var c = ca[x];
1311       while (c.charAt(0) == ' ') c = c.substring(1,c.length);
1312       if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
1313    }
1314    return null;
1315 }
1316 
1317 function removeCookie(key) {
1318    updateCookie(key,'NULL',-1);
1319 }
1320 
1321 //Delete all cookies to complete resetting form
1322 function resetCookie() { 
1323    if(debug) alert("resetCookie()");
1324    var keys = new Array("defendant","plaintiff","defendantaty","plaintiffaty","plaintiff_county","defendant_county","stateremoval","prevreward","districts","claim_county","transfer");
1325    for(var x=0; x < keys.length; x++)  
1326       removeCookie(keys[x]);
1327 }
1328 function getFormItems(){  
1329     if(!document.getElementById) return;  
1330 	var f = document.getElementById('edit_form');
1331 	//Step through the form elements 
1332 	if(!f){alert("f is NULL")
1333 	}else{ 
1334 		for(var i=0; i < f.elements.length; i++)  
1335 	 	{   
1336     	  alert(f.elements[i].name);  
1337     	 } 
1338     }
1339 }
1340 
1341 function checkFields(){
1342 for(i=0; i<document.JS44.elements.length; i++)
1343 {
1344 document.write("The field name is: " + document.JS44.elements[i].name + " and it�s value is: " + document.JS44.elements[i].value + ".<br />");
1345 }
1346 }
1347