// number formatting function
// copyright Stephen Chapman 24th March 2006, 10th February 2007
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0');y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}

function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  indian = document.inventoryForm.percentIndian.value;
  asian = document.inventoryForm.percentAsian.value;
  black = document.inventoryForm.percentBlack.value;
  hawaiian = document.inventoryForm.percentHawaiian.value;
  white = document.inventoryForm.percentWhite.value;
  hispanic = document.inventoryForm.percentHispanic.value;
  other = document.inventoryForm.percentOther.value;
  document.inventoryForm.percentTotal.value = formatNumber((indian * 1) + (asian * 1) + (black * 1) + (hawaiian * 1) + (white * 1) + (hispanic * 1) + (other * 1),0,',','','','','-','');
  total = document.inventoryForm.percentTotal.value;
  if(total > 100){
	  document.inventoryForm.percentIndian.value = '';
	  document.inventoryForm.percentAsian.value = '';
	  document.inventoryForm.percentBlack.value = '';
	  document.inventoryForm.percentHawaiian.value = '';
	  document.inventoryForm.percentWhite.value = '';
	  document.inventoryForm.percentHispanic.value = '';
	  document.inventoryForm.percentOther.value = '';
	  alert("100% maximum");
  }
  //dmd = document.vendorForm.diamond.value;
  //document.vendorForm.diamondtotal.value = formatNumber((dmd * 2500),0,',','','','','-','');
  //rby = document.vendorForm.ruby.value;
  //document.vendorForm.rubytotal.value = formatNumber((rby * 1700),0,',','','','','-','');
  //prl = document.vendorForm.pearl.value;
  //document.vendorForm.pearltotal.value = formatNumber((prl * 1100),0,',','','','','-','');
  //indstry = document.vendorForm.industry.value;
  //glf = document.vendorForm.golf.value;
  //document.vendorForm.totalcost.value = formatNumber((dmd * 2500) + (rby * 1700) + (prl * 1100) + (indstry * 1) + (glf * 1),0,',','','','','-','');
}
function stopCalc(){
  clearInterval(interval);
}

function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

for (i = 0;  i < checkStr.value.length;  i++)
{
ch = checkStr.value.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{	
alertsay = "Please enter only these values \""
alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
{
alertsay = "Please enter a value greater than or "
alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}
}

function submitform() {
	document.myform.submit();
}

function validateInventory() {
var chkselect = '';

	if (document.inventoryForm.eventTitle.value == "") {
	
	} else {
		var eventRole_choice = false;
		for (eventRole_counter = 0; eventRole_counter < document.inventoryForm.eventRole.length; eventRole_counter++) {
			if (document.inventoryForm.eventRole[eventRole_counter].checked)
			eventRole_choice = true; 
		}
		if (!eventRole_choice) {
			p = 1;
			chkselect= 'CONNECTION to COSEE SE\n-Event Role\n\n';
		}
	}
	
	if (document.inventoryForm.fullName.value == "") {
		chkselect= chkselect + '-Full name\n';
		//alert("Full name is required.");
		//document.inventoryForm.fullName.focus();
		//return (false);
	}
	if (document.inventoryForm.workPlace.value == "") {
		chkselect= chkselect + '-Place of Work\n';
	}
	if (document.inventoryForm.workPhone.value == "") {
		chkselect= chkselect + '-Work Phone\n';
	}
	if (document.inventoryForm.workAddress.value == "") {
		chkselect= chkselect + '-Work Address\n';
	}
	if (document.inventoryForm.workCity.value == "") {
		chkselect= chkselect + '-Work City\n';
	}
	if (document.inventoryForm.workState.value == "") {
		chkselect= chkselect + '-Work State\n';
	}
	if (document.inventoryForm.workZip.value == "") {
		chkselect= chkselect + '-Work Zip Code\n';
	}
	if (document.inventoryForm.emailPrimary.value == "") {
		chkselect= chkselect + '-Primary Email address\n';
	}
	
	var raceEthnicity_choice = false;
	for (raceEthnicity_counter = 0; raceEthnicity_counter < document.inventoryForm.raceEthnicity.length; raceEthnicity_counter++) {
		if (document.inventoryForm.raceEthnicity[raceEthnicity_counter].checked)
		raceEthnicity_choice = true; 
	}
	if (!raceEthnicity_choice) {
		p = 1;
		chkselect= chkselect + 'Diversity Information\n-Race and Ethnicity\n\n';
	}
	
	var profession_choice = false;
	for (profession_counter = 0; profession_counter < document.inventoryForm.profession.length; profession_counter++) {
		if (document.inventoryForm.profession[profession_counter].checked)
		profession_choice = true; 
	}
	if (!profession_choice) {
		p = 1;
		chkselect= chkselect + 'Profession\n-Profession\n\n';
	}
	
	var scientistResearcher_choice = false;
	for (scientistResearcher_counter = 0; scientistResearcher_counter < document.inventoryForm.scientistResearcher.length; scientistResearcher_counter++) {
		if (document.inventoryForm.scientistResearcher[scientistResearcher_counter].checked)
		scientistResearcher_choice = true; 
	}
	if (!scientistResearcher_choice) {
		p = 1;
		chkselect= chkselect + 'For Scientists/Researchers\n-Scientists/Researchers\n\n';
	}
	
	
	if(chkselect) {
		alert('The following fields are required:\n' + chkselect)
	return (false);
	}
return (true);
}


function printWindow(){
	   bV = parseInt(navigator.appVersion)
	   if (bV >= 4) window.print()
}