text: /*
  Ganan Sivagnanenthirarajah
  CO-OP Student
  Technical Trainee PCS
  City of Toronto Water
  Created June 26, 2018
  Last Modified July 6, 2018
  
  TO DO:
  */
  
  //Keeps all the element titles for easy use when inserting info
  var mainFormElements = ["Date:", "Project Number:", "Project Name:", "PCS Representative:", "City Project Manager:", "Consultant Name:", "Consultant Phone:", "Consultant Email:", "Consultant Organization:", "Expected Return Date:", "Agreement/Notes:"];
  //global variables
  var mainTable;
  var smallTable;
  var numEntries;
  var queries;
  var foundGlobal;
  
  
  //Decodes the info
  var queryString = document.cookie;
  queryString = queryString.substring(1);
  var sub_code = queryString;//Used if cookie was an ID
  
  
  //PHP will only take action after the method is done so the preload and postload were created
  function preLoad (oForm)
  {
  //alert(pattern.test(queryString));
  var pattern = /^[A-Z0-9]{7}$/;//Accepts: a combination of 7 characters from A-Z and/or 0-9;
  
  //If there is a link to review
  if (pattern.test(queryString)){
  	//FIND INFO AND GENERATE QUERY STRING TO PASS TO CONTINUE
  	//more info @ https://www.w3schools.com/php/php_mysql_select.asp
  	jQuery.ajax({
      type: "POST",
      url: 'php/Document Review.php',
      dataType: 'json',
      data: {functionname: 'locate', arguments: [queryString]},
  
      success: function (obj, textstatus) {
                    if( !('error' in obj) ) {
  					  var found = ''+ obj.result;
  					  //alert(found);
  					  postLoad(oForm, found);
                    }
                    else {
                        console.log('3'+obj.error);
                    }
              }
  	});
  	}
  	else{//if no pattern is found proceed to regular review page called by Firewall Form
  		postLoad(oForm, '');
  	}	
  }
  
  function findNumRelease(fileData, rowNum) {
  	//FIND INFO AND GENERATE QUERY STRING TO PASS TO CONTINUE
  	//more info @ https://www.w3schools.com/php/php_mysql_select.asp
  	jQuery.ajax({
  	type: "POST",
  	url: 'php/Document Num Release.php',
  	dataType: 'json',
  	data: {functionname: 'locate', arguments: [fileData]},
  		success: function (obj, textstatus) {
  				  if( !('error' in obj) ) {
  						var found = ''+ obj.result;
  						var table = document.getElementById("techInfo");
  						table.rows[rowNum].cells[7].innerHTML = found;
  				  }
  				  else {
  					  console.log('3'+obj.error);
  				  }
  			}
  	});
  }
  
  function postLoad (oForm, found)
  {	
  	if (found != ''){//checks if the string was from the submission code
  		queryString = found;
  	}
  	
  	console.log(queryString);
  	
  	foundGlobal = found;
  	//Splits main data and documents data into an array of size 2
  	queries = queryString.split("?");
  
  	//Puts in the data into arrays for each part
  	mainTable= (queries[0]).split("#");
  	mainTable.splice(0, 1); //needed to remove null object
  	smallTable= (queries[1]).split("#");
  	smallTable.splice(0, 1); //needed to remove null object
  
  for(var i= 0; i < smallTable.length; i++)
  {
  	if(smallTable[i] == '1' || smallTable[i] == 'true'){
  		smallTable[i] = 'YES';
  	}
  	else if (smallTable[i] == '0' || smallTable[i] == 'false'){
  		smallTable[i] = 'NO';
  	}
  }
  
  //Handle Previous Entries when filling null values
  prevEntry= ['','','','','',''];
  
  //Finds the number of IP traffic table entries
  numEntries = (smallTable.length)/6;
  
  insertInfo(oForm);
  }
  //Function to insert the info into a table
  function insertInfo(oForm)
  {	
  	
  	//Fills out the main input of the form into the web variables
  	var table = document.getElementById("form");
  	for (var i= 0; i< mainTable.length; i++)
  	{
  		//Creates new row in table
  		var tr = document.createElement("tr");
  		
  		//The following populates the new row in the table
  		var td = document.createElement("td");
  		var txt = document.createTextNode(mainFormElements[i]); //inserts row name
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		var td = document.createElement("td");
  		var txt = document.createTextNode(mainTable[i]);//inserts info
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		//Attaches the finished row
  		table.appendChild(tr);
  	}
  
  	//Creates the table entries for IP Traffic Definition
  	var table = document.getElementById("techInfo");
  	for(var i= 0; i < numEntries; i++)
  	{
  		//Creates new row in table
  		var tr = document.createElement("tr");
  		
  		//The following populates the new row in the table
  		var td = document.createElement("td");
  		var txt = document.createTextNode(i + 1); //numbers each row
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		var td = document.createElement("td");
  		if (smallTable[i*6] == ''){//replace with previous entry
  			var txt = document.createTextNode(prevEntry[0]);//data
  		}else{
  			var txt = document.createTextNode(smallTable[i*6]);//data
  			prevEntry[0]= smallTable[i*6];
  		}
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		var td = document.createElement("td");
  		if (smallTable[i*6+1] == ''){
  			var txt = document.createTextNode(prevEntry[1]);//releaseDate
  		}else{
  			var txt = document.createTextNode(smallTable[i*6+1]);//releaseDate
  			prevEntry[1]= smallTable[i*6+1];
  		}
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		var td = document.createElement("td");
  		if (smallTable[i*6+2] == ''){
  			var txt = document.createTextNode(prevEntry[2]);//released
  		}else{
  			var txt = document.createTextNode(smallTable[i*6+2]);//released
  			prevEntry[2]= smallTable[i*6+2];
  		}
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		var td = document.createElement("td");
  		if (smallTable[i*6+3] == ''){
  			var txt = document.createTextNode(prevEntry[3]);//returnDate
  		}else{
  			var txt = document.createTextNode(smallTable[i*6+3]);//returnDate
  			prevEntry[3]= smallTable[i*6+3];
  		}
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		var td = document.createElement("td");
  		if (smallTable[i*6+4] == ''){
  			var txt = document.createTextNode(prevEntry[4]);//returned
  		}else{
  			var txt = document.createTextNode(smallTable[i*6+4]);//returned
  			prevEntry[4]= smallTable[i*6+4];
  		}
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		var td = document.createElement("td");
  		if (smallTable[i*6+5] == ''){
  			var txt = document.createTextNode(prevEntry[5]);//archived
  		}else{
  			var txt = document.createTextNode(smallTable[i*6+5]);//archived
  			prevEntry[5]= smallTable[i*6+5];
  		}
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		var td = document.createElement("td");
  		
  		var txt = document.createTextNode('');//archived
  
  		td.appendChild(txt);
  		tr.appendChild(td);
  		
  		//Attaches the finished row
  		table.appendChild(tr);
  	}
  	
  	var table = document.getElementById("techInfo");
  	var fileDataTemp = '';
  	for (var j = 1; j < table.rows.length; j++){
  		fileDataTemp = table.rows[j].cells[1].innerHTML;
  		fileDataTemp = fileDataTemp.replace('amp;', '');
  		findNumRelease(fileDataTemp, j);
  	}
  	
  	//Checks if submit was pressed on main form page
  	//KEEP HERE: order matters
  	if (foundGlobal != ''){
  		document.getElementById("message").innerHTML = 'Submission Code: ' + sub_code;
  		document.getElementById("message").setAttribute("onclick", "loadEdit('"+sub_code+"')");
  		document.getElementById("message").style.display = "block";
  	}
  	else{
  		document.getElementById("message").innerHTML = 'Please press submit to finish';
  	}
  }
  //Goes back to main form page when back or submit are pressed
  function goBack(submitBool)
  {
  	close();
  }
  function loadEdit(code){
  	document.cookie = "" + code;
  	window.location.assign('Document Request Form v2.html');
  }
  function hideBottom (oForm, hide)
  {
  	if (hide == true){
  		//Hides the buttons and message at bottom of the page
  		document.getElementById("back").disabled = true;
  		document.getElementById("back").style.display = "none";
  		document.getElementById("print").disabled = true;
  		document.getElementById("print").style.display = "none";
  		document.getElementById("message").style.display = "none";
  	}
  	else{
  		//Enables buttons and message at bottom of the page
  		document.getElementById("back").disabled = false;
  		document.getElementById("back").style.display = "block";
  		document.getElementById("print").disabled = false;
  		document.getElementById("print").style.display = "block";
  		document.getElementById("message").style.display = "block";
  	}
  }
  
  function printPage(oForm)
  {
  	//Hides the buttons to make print cleaner
  	hideBottom(oForm, true);
  	
  	//Opens print
  	window.print();
  	
  	//Enables buttons so they are there after print is done or canceled
  	hideBottom(oForm, false);
  }