//<!--- ***********************************************************************
//      Module Name: admin_check_form.cfm
//             Path: \\CDLDB01\WebContent\cmse\calendar\admin\
//     Description: main app page for the "homeroom"
//        Includes: UDF/standardElements.cfm, defaultClientVars.cfm
//  Database Tables:
// Session Variables:
// Client Variables: 

// Revision History:
//		10/07/05 made client requested modifications to function and appearance -- nrm
//		created by mcloyd, date unknown
//************************************************************************ --->
//<!-- All material copyright 2006 Butte County Office of Education / CDL -->

function do_onError(form_object, input_object, object_value, error_message) {
  alert(error_message);
  return false;
}

function chk_hasValue(obj, obj_type) {
  if (obj_type == "TEXT") {
    if (obj.value.length == 0)
      return false;
    else
      return true;
  } else if (obj_type == "TEXTAREA") {
    if (obj.value.length == 0)
      return false;
    else
      return true;
  } else if (obj_type == "SELECT") { 
    for (i=0; i < obj.length; i++) { 
      if (obj[i].selected) { 
        if (obj[i].value != ""){ 
          return true;}
        }
      }
      return false;
  } else if (obj_type == "RADIO") {
    for (i=0; i < obj.length; i++) {
      if (obj[i].checked)
        return true;
      }
    return false;
  } else if (obj_type == "CHECKBOX") {
    for (i=0; i < obj.length; i++) {
      if (obj[i].checked)
        return true;
      }
      
    return false;
  }  
}

function checkYes(obj) {
    for (i=0; i < obj.length; i++) {
      if (obj[i].checked) {
        if (obj[i].value == 0)
          return false;
      }
    }
    return true;
}

function billingAddress(obj) {
    for (i=0; i < obj.length; i++) {
      if (obj[i].checked) {
        if (obj[i].value == 1)
          return false;
      }
    }
    return true;
}
	
	
function checkmyForm(theForm) { 

   if (!chk_hasValue(theForm.eventName, "TEXT")) {
      if (!do_onError(theForm, theForm.eventName, theForm.eventName.value, "You must enter an EVENT NAME to continue.")) {
      theForm.eventName.focus();
      return false;
      }
    }
   
    //if (!chk_hasValue(theForm.description, "TEXT")) {
    //  if (!do_onError(theForm, theForm.description, theForm.description.value, "You must enter a DESCRIPTION to continue.")) {
    //  theForm.description.focus();
    //  return false;
    //  }
    //}

    if (!chk_hasValue(theForm.presenter, "TEXT")) {
      if (!do_onError(theForm, theForm.presenter, theForm.presenter.value, "You must enter a PRESENTER to continue.")) {
      theForm.presenter.focus();
      return false;
      }
    } 

    if (!chk_hasValue(theForm.dueDate1, "TEXT")) {
      if (!do_onError(theForm, theForm.dueDate1, theForm.presdueDate1enter.value, "You must select a DATE to continue.")) {
      return false;
      }
    } 


// billing options... if they select to doBilling, must give at least one bill option 
	for (i=0; i < theForm.doBilling.length; i++) {
		if ((theForm.doBilling[i].checked) && (theForm.doBilling[i].value == 1)) {
			if ((theForm.poNo.checked != true) && (theForm.checkNo.checked != true) && (theForm.freeBCOE.checked != true) && (theForm.noCost.checked != true)) {
				alert('If you select to collect BILLING information, then you must check at least one billing option (PO, Check, No Cost, etc)');
				theForm.poNo.focus();
				return false;
			}
		}
	}
        
    
// event time, location and cost    
   
    if (!chk_hasValue(theForm.eventTime, "TEXTAREA")) {
      if (!do_onError(theForm, theForm.eventTime, theForm.eventTime.value, "You must enter an EVENT TIME to continue.")) {
      theForm.eventTime.focus();
      return false;
      }
    }
   
    if (!chk_hasValue(theForm.location, "TEXTAREA")) {
      if (!do_onError(theForm, theForm.location, theForm.location.value, "You must enter a LOCATION to continue.")) {
      theForm.location.focus();
      return false;
      }
    }
  
    if (!chk_hasValue(theForm.cost, "TEXTAREA")) {
      if (!do_onError(theForm, theForm.cost, theForm.cost.value, "You must enter a COST to continue.")) {
      theForm.cost.focus();
      return false;
      }
    }
    
    if (!chk_hasValue(theForm.contactName, "TEXT")) {
      if (!do_onError(theForm, theForm.contactName, theForm.contactName.value, "You must enter a CONTACT NAME to continue.")) {
      theForm.contactName.focus();
      return false;
      }
    }
    
    if (!chk_hasValue(theForm.contactEmail, "TEXT")) {
      if (!do_onError(theForm, theForm.contactEmail, theForm.contactEmail.value, "You must enter a CONTACT EMAIL to continue.")) {
      theForm.contactEmail.focus();
      return false;
      }
    }    

// SRI district check

//    if (theForm.sriKey.value != 0) {
//      for (d=0; d < theForm.districtName.length; d++) {
//        if (theForm.districtName[d].value.length != "") {
//          return true
//        } else {        
//          if (!do_onError(theForm, theForm.districtName[d], theForm.districtName[d].value, "You must enter one or more PARTICIPATING DISTRICTS to continue.")) {
//          theForm.districtName[d].focus();
//          return false
//          }
//        }
//       }
//      }

	return true;
}

/*******************************************************************************************************************************************************************/

function findObj(n, d) { //v4.01   
alert("one");
	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=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}