function editFunc1(form) {

	

	var bActualVal = form.bActual.value
	var y1ActualVal = form.y1Actual.value
	var y2ActualVal = form.y2Actual.value
	var y3ActualVal = form.y3Actual.value

	var bNormalizedVal
	var y1NormalizedVal
	var y2NormalizedVal
	var y3NormalizedVal
	
	
		
		if (bActualVal != "" && !isNaN(bActualVal.replace(",",""))) {
			form.bNormalized.value = bActualVal.replace(",","") / 1
			
		} 

		

if (y1ActualVal != "" && form.y1Norm.value != "" && !isNaN(y1ActualVal.replace(",","")) && 

!isNaN(form.y1Norm.value.replace(",",""))) {

			form.y1Normalized.value = y1ActualVal.replace(",","") / form.y1Norm.value.replace(",","")
			form.y1Normalized.value = Math.round(form.y1Normalized.value*1000)/1000 
			
		} 
		
		
	
if (y2ActualVal != "" && form.y2Norm.value != "" && !isNaN(y2ActualVal.replace(",","")) && 

!isNaN(form.y2Norm.value.replace(",",""))) {

			form.y2Normalized.value = y2ActualVal.replace(",","") / form.y2Norm.value.replace(",","")
			form.y2Normalized.value = Math.round(form.y2Normalized.value*1000)/1000 
			
		} 
		

	
if (y3ActualVal != "" && form.y3Norm.value != "" && !isNaN(y3ActualVal.replace(",","")) && 

!isNaN(form.y3Norm.value.replace(",",""))) {

			form.y3Normalized.value = y3ActualVal.replace(",","") / form.y3Norm.value.replace(",","")
			form.y3Normalized.value = Math.round(form.y3Normalized.value*1000)/1000 
			
		} 
		
		
	
	
	
	return true;

	

}


function submitCategory(form) {

	form.submit()
	return true;
}

function submitYear(form) {

	form.submit()
	return true;
}

function submitnextYear(form) {
	
	var yearVal = form.nextYear.value

	var strConfirm = confirm("Are you sure you want to create " + yearVal + " reports?")

	if (strConfirm) {
		return true;
	
	} else {
		return false;
	}

}

function selectFacilities (form) {
	//if (form.selectedFac.length == 0) {
		//alert("Please select atleast one facility")
		//return false;
	//}
	

	for (i = 0; i < form.selectedFac.length; i++) {
		form.selectedFac.options[i].selected = true
	}
}


function addOption(theSel, theText, theValue)
{
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{	
	var selLength = theSel.length;
	if(selLength>0)
	{
		theSel.options[theIndex] = null;
	}
}


function moveFacilities(theSelFrom, theSelTo) {

       
       var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;
	
	var i;
	
	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			selectedText[selectedCount] = theSelFrom.options[i].text;
			selectedValues[selectedCount] = theSelFrom.options[i].value;
			deleteOption(theSelFrom, i);
			selectedCount++;
		}
	}
	
	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	
	for(i=selectedCount-1; i>=0; i--)
	{
		addOption(theSelTo, selectedText[i], selectedValues[i]);
	}
	
}		




function ValidatePwdEmail(form) {
	var email = form.emailAddress.value;
	
	var formOK = "true";
	var alertMsg = "Please enter the following information\n\n"; 
	
	if (email == "") {
		formOK = "false";
		alertMsg += "Please enter an email address!\n"
		//return false;
	} else {
		emailVal = emailCheck(email)
		if (emailVal == false) {
			formOK = "false";
			alertMsg += "Please enter a valid email address!\n"
		}
		
			
	}
	
	if (formOK == "false") {
		alert(alertMsg)
		return false;
	} else {
		return true;
	}

}


function ValidateChangePassword(form) {
	var login = form.login.value;
	var oldPassword = form.old_password.value;
	var newPassword = form.new_password.value;
	var confirmPassword = form.confirm_password.value;
	var email = form.email.value;
	
	var formOK = "true";
	var alertMsg = "Please enter the following information\n\n"; 
	
	//login validation
	
	if (login == "") {
		formOK = "false";
		alertMsg += "Please enter your login value!\n"
		//return false;
	}
	
	//old password validation
	
	if (oldPassword == "") {
		formOK = "false";
		alertMsg += "Please enter your old password value!\n"
		//return false;
	}
	
	//new password validation
	
	if (newPassword == "") {
		formOK = "false";
		alertMsg += "Please enter your new password value!\n"
		//return false;
	}
	
	//confirm password validation
	
	if (confirmPassword == "") {
		formOK = "false";
		alertMsg += "Please confirm your new password value!\n"
		//return false;
	}
	
	//email validation
	
	if (email == "") {
		formOK = "false";
		alertMsg += "Please enter an email address!\n"
		//return false;
	} else {
		emailVal = emailCheck(email)
		if (emailVal == false) {
			formOK = "false";
			alertMsg += "Please enter a valid email address!\n"
		}
		
			
	}
	
	if (formOK == "false") {
		alert(alertMsg)
		return false;
	} else {
		return true;
	}
	

}

function ValidateGenInfo (form) {
	var facName = form.facName.value;

	if (facName == "") {
		alert("Please enter a facility name")
		return false;
	}

}

function ValidateRequest (form) {
	alert("hello")
	return false;

}


function deleteReport (form) {
	
	
	var strConfirm = confirm("Are you sure you want to delete this report?")

	if (strConfirm) {
		return true;
	
	} else {
		return false;
	}

	
	


}



function ValidateSubmittal (form) {
	
	today = new Date()

	var strInitials = form.initials.value;
	var strDate = new Date(form.sigDate.value);

	var formOK = "true";
	var alertMsg = "Please enter the following information\n\n"; 


	var strConfirm = confirm("Warning! Once you submit, you will not be able to edit this report.")

	if (strConfirm) {
		//initials validation
	
		if (strInitials == "") {
			formOK = "false";
			alertMsg += "Please enter your initials!\n"
			//return false;
		}
	
		//sig date validation

		
	
		if (strDate == "NaN" || strDate == "Invalid Date") {
			formOK = "false";
			alertMsg += "Please enter a valid date!\n"
			//return false;
		}

		if (formOK == "false") {
			alert(alertMsg)
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}

	
	


}

function ValidateAttachment (form) {
	var strFile = form.attachment.value;

	if (strFile == "") {
		alert("Please enter an attachment")
		return false;
	}


}


function Validate (form) {
	var firstname = form.firstName.value;
	var lastname = form.lastName.value;
	var emailaddr = form.email.value;
	var pwdVal	= form.Pwd.value;
	var confirmPwdVal = form.confirmPwd.value;
	var formOK = "true";
	var alertMsg = "Please enter the following information\n\n";
	
	//first name validation
	
	if (firstname == "") {
		formOK = "false";
		alertMsg += "Please enter a first name!\n"
		//return false;
	}
	
	//last name validation
	
	if (lastname == "") {
		formOK = "false";
		alertMsg += "Please enter a last name!\n"
		//return false;
	}
	
	//email validation
	
	if (emailaddr == "") {
		formOK = "false";
		alertMsg += "Please enter an email address!\n"
		//return false;
	} else {
		emailVal = emailCheck(emailaddr)
		if (emailVal == false) {
			formOK = "false";
			alertMsg += "Please enter a valid email address!\n"
		}
	}

	//password validation

	if (pwdVal == "") {
		formOK = "false";
		alertMsg += "Please enter a password!\n"
		//return false;
	
	}

	//password validation

	if (confirmPwdVal == "") {
		formOK = "false";
		alertMsg += "Please enter a confirmation password!\n"
		//return false;
	
	}

	if (pwdVal != confirmPwdVal) {
		formOK = "false";
		alertMsg += "Please make sure the password values match!\n"
		//return false;
	}

	
	//return true;
	
	if (formOK == "false") {
		alert(alertMsg)
		return false;
	} else {
		return true;
	}	
}





function emailCheck (emailStr) {

/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */

var emailPat=/^(.+)@(.+)$/

/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */

var validChars="\[^\\s" + specialChars + "\]"

/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
   
var quotedUser="(\"[^\"]*\")"

/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

/* The following string represents an atom (basically a series of
   non-special characters.) */

var atom=validChars + '+'

/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
   
var word="(" + atom + "|" + quotedUser + ")"

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
   
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	//alert("Please enter a valid email address!")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("Please enter a valid email address!")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        //alert("Please enter a valid email address!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("Please enter a valid email address!")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   //alert("Please enter a valid email address!")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="Please enter a valid email address!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}


function deleteCategories(form) {
	var chkBoxLength = form.deleteCatInd.length
	
	var formOK = "true";
	var alertMsg = "Please select atleast one Category and Indicator combination to delete\n\n"; 
	
	for (i=0; i < chkBoxLength; i++) {
		if (form.deleteCatInd[i].checked == false) {
			formOK = "false";
		} else {
			formOK = "true";
			break;
		}
	}
	
	if (formOK == "false") {
		alert(alertMsg)
		return false;
	} else {
		confirmVar = confirm ("Are you sure you want to delete the selected category/indicator combination?")
		
		if (confirmVar) {
			return true;
		} else {
			return false;
		}	
	}
	
	
}


function deleteFiles(form) {
	var chkBoxLength = form.deleteAttachment.length
	
	var formOK = "true";
	var alertMsg = "Please select atleast one attachment to delete\n\n"; 
	
	for (i=0; i < chkBoxLength; i++) {
		if (form.deleteAttachment[i].checked == false) {
			formOK = "false";
		} else {
			formOK = "true";
			break;
		}
	}
	
	if (formOK == "false") {
		alert(alertMsg)
		return false;
	} else {
		confirmVar = confirm ("Are you sure you want to delete the selected attachment(s)?")
		
		if (confirmVar) {
			return true;
		} else {
			return false;
		}	
	}
	
	
}










