/**
 * Common Scripts
 * @author Jim Tompkins for TAC
 */

/** Dreamweaver scripts
 */
function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/** Custom routines
 */

/**
 * Set blank field
 * @argument string DOM object id
 * @return nothing
 */
function setBlank(a) {
	var obj = MM_findObj(a); 
	if (obj) obj.value = '';
}

/**
 * Validate Form
 * Adapted from Dreamweaver script
 * @argument string args[0,3,6...] DOM object id
 * @argument string args[1,4,7...] Field description language constant
 * @argument string args[2,5,8...] Throw away default value
 * @return If param fields are empty, or equal to throw away value, throws an alert, and returns false
 * @type boolean
 */
function validateForm() { // Check these required fields
  var c=false,i,f,l,p,errors='',args=validateForm.arguments;
  for (i=0; i<(args.length-1); i+=3) { 
    f=args[i+1];
		t=args[i+2];
    obj=MM_findObj(args[i]);
		if (obj.value==t && t!='') errors += f+' is required.\n';
    if (obj) { 
      var l=obj.length
      if (l > 1) {
        // I cannot for some reason get a for loop to work consistently here; go figure
        if (obj[0]) if (obj[0].checked || (obj[0].selected && obj[0].value)) c=true
        if (obj[1]) if (obj[1].checked || (obj[1].selected && obj[1].value)) c=true
        if (obj[2]) if (obj[2].checked || (obj[2].selected && obj[2].value)) c=true
        if (obj[3]) if (obj[3].checked || (obj[3].selected && obj[3].value)) c=true
        if (obj[4]) if (obj[4].checked || (obj[4].selected && obj[4].value)) c=true
        if (obj[5]) if (obj[5].checked || (obj[5].selected && obj[5].value)) c=true
        if (obj[6]) if (obj[6].checked || (obj[6].selected && obj[6].value)) c=true
        if (obj[7]) if (obj[7].checked || (obj[7].selected && obj[7].value)) c=true
        if (obj[8]) if (obj[8].checked || (obj[8].selected && obj[8].value)) c=true
        if (obj[9]) if (obj[9].checked || (obj[9].selected && obj[9].value)) c=true
        if (c!=true) errors += f+' is required.\n';
      }
      else if ((obj=obj.value)=="") errors += f+' is required.\n';
    }
  }
  if (errors) alert('The following error(s) occurred:\n'+errors);
  document.returnValue = (errors == '');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
