
var printmsg = new Array();

printmsg[0] = "Note: For shaded backgrounds and images to print correctly...\n\nInternet Explorer: Tools > Internet Options > Advanced tab > (scroll down) Printing - tick checkbox\n\nMozilla: File > Page Setup > Format and Options tab > Options - tick checkbox";

printmsg[1] = "If already awarded, please enter the awarded dollar amount for each year of the project for this fund source. \nPlease also enter the Cost Centre and Fund Number for this fund source.\n\nOtherwise, if at application stage, uncheck the Awarded checkbox  - and for each year of the project, please \nenter the dollars applied.";


// Cookie Functions  ////////////////////  (:)



// Set the cookie.

// SetCookie('your_cookie_name', 'your_cookie_value', exp);



// Get the cookie.

// var someVariable = GetCookie('your_cookie_name');



var expDays = 100;

var exp = new Date(); 

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));



function getCookieVal (offset) {  

	var endstr = document.cookie.indexOf (";", offset);  

	if (endstr == -1) { endstr = document.cookie.length; }

	return unescape(document.cookie.substring(offset, endstr));

}



function GetCookie (name) {  

	var arg = name + "=";  

	var alen = arg.length;  

	var clen = document.cookie.length;  

	var i = 0;  

	while (i < clen) {    

		var j = i + alen;    

		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    

		i = document.cookie.indexOf(" ", i) + 1;    

		if (i == 0) break;   

	}  

	return null;

}



function SetCookie (name, value) {  

	var argv = SetCookie.arguments;  

	var argc = SetCookie.arguments.length;  

	var expires = (argc > 2) ? argv[2] : null;  

	var path = (argc > 3) ? argv[3] : null;  

	var domain = (argc > 4) ? argv[4] : null;  

	var secure = (argc > 5) ? argv[5] : false;  

	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");

}



// cookieForms saves form content of a page.



// use the following code to call it:

//  <body onLoad="cookieForms('open', 'form_1', 'form_2', 'form_n')" onUnLoad="cookieForms('save', 'form_1', 'form_2', form_n')">



// It works on text fields and dropdowns in IE 5+

// It only works on text fields in Netscape 4.5





function cookieForms() {  

	var mode = cookieForms.arguments[0];

	

	for(f=1; f<cookieForms.arguments.length; f++) {

		formName = cookieForms.arguments[f];		

		if(mode == 'open') {	

			cookieValue = GetCookie('saved_'+formName);

			if(cookieValue != null) {

				var cookieArray = cookieValue.split('#cf#');
									if(cookieArray.length == document[formName].elements.length) {

						for(i=0; i<document[formName].elements.length; i++) {
													if(cookieArray[i].substring(0,6) == 'select') { 								document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }

							else 							if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { 								document[formName].elements[i].checked = true; }

							else 							if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }

							else 							{ document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }

					}

				}

			}

		}				

		if(mode == 'save') {	

			cookieValue = '';

			for(i=0; i<document[formName].elements.length; i++) {

				fieldType = document[formName].elements[i].type;
				

				if(fieldType == 'password') { 
					passValue = ''; }

				else if(fieldType == 'checkbox') { 
					passValue = 'cb'+document[formName].elements[i].checked; }

				else if(fieldType == 'radio') { 
					passValue = 'rb'+document[formName].elements[i].checked; }

				else if(fieldType == 'select-one') { 
					passValue = 'select'+document[formName].elements[i].options.selectedIndex; }

				else { 
					passValue = document[formName].elements[i].value; }

			

				cookieValue = cookieValue + passValue + '#cf#';

			}

			cookieValue = cookieValue.substring(0, cookieValue.length-4); 

// Remove last delimiter

			SetCookie('saved_'+formName, cookieValue, exp);		

		}	

	}

}


function showIt(whichForm, callingElement, showWhich) {

 var frm = document.forms[whichForm];
 var theSelectedAOUorEntity = frm.elements[callingElement];

 document.getElementById(showWhich).style.display='none';

 if (theSelectedAOUorEntity[0].checked==true)
 {
  document.getElementById(showWhich).style.display='';
 }
 else
 {
  document.getElementById(showWhich).style.display='none';
 } 


}


function disableAOUFacCampus(invext, AOU, Fac, Campus, StaffID, hiddenExtOrgName, extOrg)
{

 if (document.getElementById(invext).checked==true)
 {
  document.getElementById(AOU).disabled=true;
  document.getElementById(Fac).disabled=true;
  document.getElementById(Campus).disabled=true;
  document.getElementById(StaffID).disabled=true;
  document.getElementById(hiddenExtOrgName).style.display='';
  document.getElementById(extOrg).focus()
 }
 else
 {
  document.getElementById(AOU).disabled=false;
  document.getElementById(Fac).disabled=false;
  document.getElementById(Campus).disabled=false;
  document.getElementById(StaffID).disabled=false;
  document.getElementById(extOrg).value=''; 
  document.getElementById(hiddenExtOrgName).style.display='none';
 } 

}

 
function calculatepercentage(type, operand1, operand2, operand3, operand4, operand5) {

var operandTable = new Array();
operandTable[0] = document.getElementById(operand1).value;
operandTable[1] = document.getElementById(operand2).value;
operandTable[2] = document.getElementById(operand3).value;
operandTable[3] = document.getElementById(operand4).value;
operandTable[4] = document.getElementById(operand5).value;


for (var i=0; i<5; i++)  {

 if (operandTable[i]=="") {
 operandTable[i]=0;
 }

}

var sumofpercentages = eval(operandTable[0]) + eval(operandTable[1]) + eval(operandTable[2]) + eval(operandTable[3]) + eval(operandTable[4]);

if (sumofpercentages != 100) {

document.getElementById(operand1).select();
alert('The total of the ' + type + ' percentage(s) entered equals ' + sumofpercentages + ' not 100.\nPlease can you amend?');


}
}


 


function setEthics(ethicsCommitteeStatus, ethicsPendAppNo1, ethicsPendAppNo2, ethicsPendAppNo3, ethicsSubmitBy)
{
 var frm = document.forms["contractschecklist"];
 var ethicsCommStatRadioCollection = frm.elements[ethicsCommitteeStatus];
 var ethicsPendAppNumber1 = frm.elements[ethicsPendAppNo1];
 var ethicsPendAppNumber2 = frm.elements[ethicsPendAppNo2];
 var ethicsPendAppNumber3 = frm.elements[ethicsPendAppNo3];
 var ethicsSubmitAppBy = frm.elements[ethicsSubmitBy];


// What, if anything, does the user have to enter?



 if(ethicsCommStatRadioCollection[0].checked) {

/* 

If ethics committee approval is N/A, then hide and zero everything that matters:

*/

    if(document.getElementById('AEsubmitby').value != "" || document.getElementById('IRsubmitby').value != "" ||       document.getElementById('GMOsubmitby').value != "" || document.getElementById('HEsubmitby').value != "" || 
document.getElementById('AEpendappno1').value != "" || document.getElementById('IRpendappno1').value != "" || 
document.getElementById('GMOpendappno1').value != "" || document.getElementById('HEpendappno1').value != "") { 


   ethicsPendAppNumber1.value='';
   ethicsPendAppNumber2.value='';
   ethicsPendAppNumber3.value='';
   ethicsSubmitAppBy.value='';

}
else{


   ethicsPendAppNumber1.value='';
   ethicsPendAppNumber2.value='';
   ethicsPendAppNumber3.value='';
   ethicsSubmitAppBy.value='';

document.getElementById('hiddenEthicsSubmitByDate').style.display='none'
document.getElementById('hiddenEthicsPendingApprovalNo').style.display='none';

}


 }



 if(ethicsCommStatRadioCollection[1].checked) {

/* 
   If ethics committee approval has been received, 
   zero and hide "submit application  
   by when" field, show section and focus cursor 
   for entry of approval (or pending) no.
*/

   ethicsSubmitAppBy.value='';
    
    if(document.getElementById('AEsubmitby').value!="" || document.getElementById('IRsubmitby').value!="" ||       document.getElementById('GMOsubmitby').value!="" || document.getElementById('HEsubmitby').value!="") {  

     document.getElementById('hiddenEthicsSubmitByDate').style.display='';

    }
    else {

     document.getElementById('hiddenEthicsSubmitByDate').style.display='none';
    }

   document.getElementById('hiddenEthicsPendingApprovalNo').style.display='';

   ethicsPendAppNumber1.focus();
 }





 if(ethicsCommStatRadioCollection[2].checked) {

/* 
   If ethics committee approval is pending, 
   zero and hide "submit application  
   by when" field, show section and focus cursor 
   for entry of pending (or approval) no.
*/

 
   ethicsSubmitAppBy.value='';

    if(document.getElementById('AEsubmitby').value!="" || document.getElementById('IRsubmitby').value!="" ||       document.getElementById('GMOsubmitby').value!="" || document.getElementById('HEsubmitby').value!="") { 

     document.getElementById('hiddenEthicsSubmitByDate').style.display='';
 
    }
    else {

     document.getElementById('hiddenEthicsSubmitByDate').style.display='none';
    }

   document.getElementById('hiddenEthicsPendingApprovalNo').style.display=''; 
   ethicsPendAppNumber1.focus();

 }





 if(ethicsCommStatRadioCollection[3].checked) {

/* 
   If ethics committee approval is known to be required
   but hasn't yet been sought, zero and hide pending/approval
   no. fields - and show "submit application by when" field,
   prompting for entry of submission date
*/

   ethicsPendAppNumber1.value='';
   ethicsPendAppNumber2.value='';
   ethicsPendAppNumber3.value='';


    if(document.getElementById('AEpendappno1').value!="" || document.getElementById('IRpendappno1').value!="" || document.getElementById('GMOpendappno1').value!="" || document.getElementById('HEpendappno1').value!="") {  

      document.getElementById('hiddenEthicsPendingApprovalNo').style.display='';

    }
    else {

      document.getElementById('hiddenEthicsPendingApprovalNo').style.display='none';

    }


   document.getElementById('hiddenEthicsSubmitByDate').style.display='';

   ethicsSubmitAppBy.value='dd/mm/yyyy';
   ethicsSubmitAppBy.select();
   
 }
  
}



function showHideCostCentreFundAcc(whichOne, showIt)
{
 var frm = document.forms["contractschecklist"];
 var theSelectedAOUorEntity = frm.elements[whichOne];

 
 document.getElementById(showIt).style.display='none';


 if (theSelectedAOUorEntity.checked==true)
 {
  document.getElementById(showIt).style.display='';
  alert(printmsg[1]);
 }
 else
 {
  document.getElementById(showIt).style.display='none';
 } 
}


function otherPersonWhoSubmit()
{

 var Current = document.contractschecklist.yourPos.length;

 if (Current==document.contractschecklist.yourPos.selectedIndex + 1)
 {
  document.getElementById('hiddenSoWhoIsIt').style.display='';
 }
 else
 {
  document.getElementById('hiddenSoWhoIsIt').style.display='none';
 } 
}



function showinv(addinvestigator)
{
  document.getElementById(addinvestigator).style.display='';
}


function hideAddInvButton(buttonID)
{
  document.getElementById(buttonID).style.display='none';
}


function calculatepercentage(type, operand1, operand2, operand3) {

var operandTable = new Array();
operandTable[0] = document.getElementById(operand1).value;
operandTable[1] = document.getElementById(operand2).value;
operandTable[2] = document.getElementById(operand3).value;


	for (var i=0; i<3; i++)  {

	 if (operandTable[i]=="") {
	 operandTable[i]=0;
	 }

	}

var sumofpercentages = eval(operandTable[0]) + eval(operandTable[1]) + eval(operandTable[2]);

	if (sumofpercentages != 100) {

	 document.getElementById(operand1).select();
	 alert('The total of the ' + type + ' percentage(s) entered equals ' + sumofpercentages + ' not 100.\nPlease can you amend?');


	}
}



function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}


function checkForSixChars(whichfield) {
	
var whatsinit = document.getElementById(whichfield).value;
var count = whatsinit.length;
var codetype = Left(whichfield,3);
codetype = codetype.toUpperCase();

if (whichfield == "for1" || whichfield == "seo1") {
	if (count == 0) {
		alert("Please ensure you enter at least one valid six-digit " +codetype+ " code.");
		document.getElementById(whichfield).select();		
	}
	else if (count > 0 && count < 6) {
		alert("Please enter the full six-digit code. " +count+ "-digit codes are not sufficient for Monash reporting purposes.");
		document.getElementById(whichfield).select();
	}
}
else {
	if (count > 0 && count < 6) {
		alert("Please enter the full six-digit code. " +count+ "-digit codes are not sufficient for Monash reporting purposes.");
		document.getElementById(whichfield).select();		
	}
	
}
	
}



function appendRecipients() {

var facultyEmailAddress = new Array();

/*
** The number of elements in this array is dependent on the 
** number of faculty list items 
*/

facultyEmailAddress[0] = "";
facultyEmailAddress[1] = "";
facultyEmailAddress[2] = "";
facultyEmailAddress[3] = "";
facultyEmailAddress[4] = "";
facultyEmailAddress[5] = "";
facultyEmailAddress[6] = "";
facultyEmailAddress[7] = "";
facultyEmailAddress[8] = "";
facultyEmailAddress[9] = "kathie.barwick@artdes.monash.edu.au";
facultyEmailAddress[10] = "research.enquiries@arts.monash.edu.au";
facultyEmailAddress[11] = "steven.gardner@buseco.monash.edu.au,research@buseco.monash.edu.au";
facultyEmailAddress[12] = "research@education.monash.edu.au";
facultyEmailAddress[13] = "research.enquiries@eng.monash.edu.au";
facultyEmailAddress[14] = "researchgrants@infotech.monash.edu.au";
facultyEmailAddress[15] = "research@law.monash.edu.au";
facultyEmailAddress[16] = "medicine.research@med.monash.edu.au";
facultyEmailAddress[17] = "carolyn.fox@vcp.monash.edu.au";
facultyEmailAddress[18] = "manager.research@sci.monash.edu.au";
facultyEmailAddress[19] = "";
facultyEmailAddress[20] = "";
facultyEmailAddress[21] = "";
facultyEmailAddress[22] = "";
facultyEmailAddress[23] = "";
facultyEmailAddress[24] = "";
facultyEmailAddress[25] = "";
facultyEmailAddress[26] = "";
facultyEmailAddress[27] = "";
facultyEmailAddress[28] = "";
facultyEmailAddress[29] = "chua.khong.wai@adm.monash.edu.my";
facultyEmailAddress[30] = "dina.burger@adm.monash.edu";
facultyEmailAddress[31] = "";
facultyEmailAddress[32] = "noelene.deveson@muarc.monash.edu.au";
facultyEmailAddress[33] = "";
facultyEmailAddress[34] = "";
facultyEmailAddress[35] = "";
facultyEmailAddress[36] = "";
facultyEmailAddress[37] = "";
facultyEmailAddress[38] = "";
facultyEmailAddress[39] = "";



var campusField = new Array();

/* 
** Whereas the number of elements in this array is dependent 
** upon the maximum number of investigators the form can process
*/

campusField[0] = "campus0";
campusField[1] = "campus1";
campusField[2] = "campus2";
campusField[3] = "campus3";
campusField[4] = "campus4";
campusField[5] = "campus5";
campusField[6] = "campus6";
campusField[7] = "campus7";
campusField[8] = "campus8";
campusField[9] = "campus9";
campusField[10] = "campus10";
campusField[11] = "campus11";
campusField[12] = "campus12";
campusField[13] = "campus13";
campusField[14] = "campus14";
campusField[15] = "campus15";



var facultyField = new Array();

/* 
** The number of elements in this array is also dependent upon 
** the maximum number of investigators the form can process
*/

facultyField[0] = "fac0";
facultyField[1] = "fac1";
facultyField[2] = "fac2";
facultyField[3] = "fac3";
facultyField[4] = "fac4";
facultyField[5] = "fac5";
facultyField[6] = "fac6";
facultyField[7] = "fac7";
facultyField[8] = "fac8";
facultyField[9] = "fac9";
facultyField[10] = "fac10";
facultyField[11] = "fac11";
facultyField[12] = "fac12";
facultyField[13] = "fac13";
facultyField[14] = "fac14";
facultyField[15] = "fac15";




var extInvestigatorField = new Array();

/* 
** The number of elements in this array is also dependent upon 
** the maximum number of investigators the form can process
*/

extInvestigatorField[0] = "inv0ext";
extInvestigatorField[1] = "inv1ext";
extInvestigatorField[2] = "inv2ext";
extInvestigatorField[3] = "inv3ext";
extInvestigatorField[4] = "inv4ext";
extInvestigatorField[5] = "inv5ext";
extInvestigatorField[6] = "inv6ext";
extInvestigatorField[7] = "inv7ext";
extInvestigatorField[8] = "inv8ext";
extInvestigatorField[9] = "inv9ext";
extInvestigatorField[10] = "inv10ext";
extInvestigatorField[11] = "inv11ext";
extInvestigatorField[12] = "inv12ext";
extInvestigatorField[13] = "inv13ext";
extInvestigatorField[14] = "inv14ext";
extInvestigatorField[15] = "inv15ext";


var hardCodedRecipient = document.getElementById('recipient').value;
var selectedFacultyRecipient = "";
var selectedCampusAddress = "";
var selectedCampusField = "";
var contactPersonRecipient = document.getElementById('email').value;

/*
** Loop through all investigators until the first internal
** one is found - then obtain the selected faculty for that 
** investigator...
*/


for(i=1;1<31;i++) {

 if(document.getElementById(extInvestigatorField[i]).checked==false) {

  var selectedFacultyIndexNo = document.getElementById(facultyField[i]).selectedIndex;
  break;
}
else {}

}


/*
** Obtain from facultyEmailAddress[] array above the correct email address
** ...if there is one for a given faculty or institute:
*/


  if (facultyEmailAddress[selectedFacultyIndexNo] != "") {
   selectedFacultyRecipient = "," + facultyEmailAddress[selectedFacultyIndexNo];
  }


/* 
** Now loop through the campus field data for all 30 investigators - 
** - if one is set to Gippsland, append Gippsland's RO's email address
** - in future, a switch statement may be used to append several campus's
** email addresses, if ever required
*/


for(i=1;i<31;i++)  {

  selectedCampusField = document.getElementById(campusField[i]).selectedIndex;

  if (selectedCampusField == "10") {
  selectedCampusAddress = "," + "Gippsland.Research@adm.monash.edu.au";
  }
}


// Now concatenate all components of the recipient email list:


document.getElementById('recipient').value = hardCodedRecipient + selectedFacultyRecipient + "," + contactPersonRecipient + selectedCampusAddress;

}


function appendRecipients2() {

var hardCodedRecipient = document.getElementById('recipient').value;

var otherRecipients = document.getElementById('otheremailrecipients').value;

document.getElementById('recipient').value = hardCodedRecipient + "," + otherRecipients;

}


