Index: schedule/Module/control.php
===================================================================
--- schedule/Module/control.php	(revision 17478)
+++ schedule/Module/control.php	(revision 17487)
@@ -35,5 +35,5 @@
 				select = document.createElement("select"),
 				select.setAttribute("class","measure"),
-				$.ajax({																	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
+				$.ajax({	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
 				type:"post",
 				url:"Transaction/measurement.php",
@@ -48,5 +48,5 @@
 					})
 				}
-				})																				// End of retrieving
+				})	// End of retrieving
 			);
 			newtd_c2.setAttribute("width","115");
@@ -66,5 +66,5 @@
 					selection = document.createElement("select"),
 					selection.setAttribute("class","source"),
-					$.ajax({																	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
+					$.ajax({	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
 						type:"post",
 						url:"Transaction/source.php",
@@ -80,5 +80,5 @@
 							});
 						}
-					})																			// End of retrieving		
+					})	// End of retrieving		
 			);
 		var newtd_c4 = document.createElement("td");
@@ -147,5 +147,5 @@
 $prev_time = array();
 ?>
-function addRowClone1(nextrow){
+function addRowCloneNew(nextrow){
 	var targetView = document.getElementById("Data");
 	// CREATE ELEMENT
@@ -190,5 +190,5 @@
 			input_data.setAttribute("value","+"),
 			input_data.onclick = function(){
-				addRowClone1("list_"+newlist);
+				addRowCloneNew("list_"+newlist);
 			}
 		);
@@ -200,5 +200,5 @@
 			select = document.createElement("select"),
 			select.setAttribute("class","measure"),
-			$.ajax({																	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
+			$.ajax({	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
 			type:"post",
 			url:"Transaction/measurement.php",
@@ -214,6 +214,5 @@
 			
 			}
-			})																			// End of retrieving
-			
+			}) // End of retrieving
 		);
 		newtd_c2.setAttribute("width","115");
@@ -233,5 +232,5 @@
 			selection = document.createElement("select"),
 			selection.setAttribute("class","source"),
-			$.ajax({																	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
+			$.ajax({	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
 				type:"post",
 				url:"Transaction/source.php",
@@ -247,5 +246,5 @@
 					});
 				}
-			})																			// End of retrieving
+			})	// End of retrieving
 		);
 	var newtd_c4 = document.createElement("td");
@@ -306,203 +305,198 @@
 
 function addRowClone(nextrow){
-<?php
-$fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) = '$days' ORDER BY fScheduleID ASC, fMeasurementID ASC") or die(mysql_error());
-$observationsCount = mysql_query("SELECT COUNT(DISTINCT fStart) FROM schedule WHERE date(fStart) = '$days'");
-$observationsTime = mysql_query("SELECT DISTINCT fStart FROM schedule WHERE date(fStart) = '$days'");
-
-$cnt3=0;
-$cnt2=0;
-$cnt4 = 0;
-$cnt5 = 0;
-//$data  = array();
-//$counter=0;
-$prevtimestamp = 0;
-while($times = mysql_fetch_array($observationsTime))
-{
-		$timestamp=strtotime($times['fStart']);
-		$actualtime = date('Y-m-d H:i:s', $timestamp);
-		$timestamp2 = date('Y-m-d',$timestamp);
-		$date_time = date('H:i:s',$timestamp);
-		$prev_time[$cnt3]= $date_time;
-?>
-		$('#save').attr('value','UPDATE');
-			var targetView = document.getElementById("Data");
-			// CREATE ELEMENT
-			// COUNT LIST
-			var list     = $(".datalisting").length;
-			var newlist = list+1;
-			
-			var cctr=$('.dataTable tr').length;
-				 ctr=cctr+1;
-				 
-			var newdiv   = document.createElement("div");
-				newdiv.setAttribute("id","list_"+newlist);
-				newdiv.setAttribute("class","datalisting");
-				newdiv.setAttribute("style","margin:5px 0;");
-			
-			var newtable = document.createElement("table");
-				newtable.setAttribute("class","dataTable");
-				newtable.setAttribute("width","100%");
-				newtable.setAttribute("border","1");
-				newtable.setAttribute("cellspacing","0");
-				newtable.setAttribute("cellpadding","0");
-			
-			var newInnertable = document.createElement("table");
-				newInnertable.setAttribute("class","dataTable");
-				newInnertable.setAttribute("width","100%");
-				newInnertable.setAttribute("border","1");
+	<?php
+	$fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) = '$days' ORDER BY fScheduleID ASC, fMeasurementID ASC") or die(mysql_error());
+	$observationsCount = mysql_query("SELECT COUNT(DISTINCT fStart) FROM schedule WHERE date(fStart) = '$days'");
+	$observationsTime = mysql_query("SELECT DISTINCT fStart FROM schedule WHERE date(fStart) = '$days'");
+
+	$cnt3=0;
+	$prevtimestamp = 0;
+	while($times = mysql_fetch_array($observationsTime))
+	{
+			$timestamp=strtotime($times['fStart']);
+			$actualtime = date('Y-m-d H:i:s', $timestamp);
+			$timestamp2 = date('Y-m-d',$timestamp);
+			$date_time = date('H:i:s',$timestamp);
+			$prev_time[$cnt3]= $date_time;
+	?>
+			$('#save').attr('value','UPDATE');
+				var targetView = document.getElementById("Data");
+				// CREATE ELEMENT
+				// COUNT LIST
+				var list     = $(".datalisting").length;
+				var newlist = list+1;
+			
+				var cctr=$('.dataTable tr').length;
+					 ctr=cctr+1;
+					 
+				var newdiv   = document.createElement("div");
+					newdiv.setAttribute("id","list_"+newlist);
+					newdiv.setAttribute("class","datalisting");
+					newdiv.setAttribute("style","margin:5px 0;");
+			
+				var newtable = document.createElement("table");
+					newtable.setAttribute("class","dataTable");
+					newtable.setAttribute("width","100%");
+					newtable.setAttribute("border","1");
+					newtable.setAttribute("cellspacing","0");
+					newtable.setAttribute("cellpadding","0");
+			
+				var newInnertable = document.createElement("table");
+					newInnertable.setAttribute("class","dataTable");
+					newInnertable.setAttribute("width","100%");
+					newInnertable.setAttribute("border","1");
 				
-				newInnertable.setAttribute("cellspacing","0");
-				newInnertable.setAttribute("cellpadding","0");
-			
-			var newtd_c1 = document.createElement("td");
-				newtd_c1.setAttribute("width","200");
-				newtd_c1.setAttribute("align","center");
-				newtd_c1.appendChild(
-					input_data = document.createElement("input"),
-					input_data.setAttribute("type","time"),
-					input_data.setAttribute("class","time"),
-					input_data.setAttribute("size","10"),
-					input_data.setAttribute("value","<?php echo $date_time; ?>"),
-					input_data.setAttribute("autofocus","true")
-				);
-				newtd_c1.appendChild(
-					input_data = document.createElement("input"),
-					input_data.setAttribute("type","button"),
-					input_data.setAttribute("value","+"),
-					input_data.onclick = function(){
-						addRowClone1("list_<?php echo $cnt+1; ?>");
-					}
-				);
-			
-	<?php
-	
-	$observations = mysql_query("SELECT * FROM schedule WHERE fStart = '$actualtime'");
-
-	while($rows = mysql_fetch_array($observations))
-	{
-	?>
-			var newtr<?php echo $cnt; ?> = document.createElement("tr");
-				newtr<?php echo $cnt; ?>.setAttribute('class','tr');
-
-			var newtd_c2 = document.createElement("td");
-				newtd_c2.setAttribute("width","138");
-				newtd_c2.setAttribute("align","center");
-				newtd_c2.appendChild(
-					selection = document.createElement("select"),
-			<?php   
-			$selectm = mysql_query("SELECT * FROM measurement");
-			while($rowmeasure = mysql_fetch_array($selectm))
-			{
-			?>
-						selection.appendChild(
-						option = document.createElement("option"),
-						option.setAttribute("value","<?php echo $rowmeasure['fMeasurementKey']; ?>"),
-						<?php  if($rows['fMeasurementTypeKey']==$rowmeasure['fMeasurementKey']){ echo "option.setAttribute('selected',true),";}   ?>
-						option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
-						),
-			<?php 
-			} 
-			?>
-						
-						
-						selection.setAttribute('id','measure'),
-						selection.setAttribute('class','measure')
+					newInnertable.setAttribute("cellspacing","0");
+					newInnertable.setAttribute("cellpadding","0");
+			
+				var newtd_c1 = document.createElement("td");
+					newtd_c1.setAttribute("width","200");
+					newtd_c1.setAttribute("align","center");
+					newtd_c1.appendChild(
+						input_data = document.createElement("input"),
+						input_data.setAttribute("type","time"),
+						input_data.setAttribute("class","time"),
+						input_data.setAttribute("size","10"),
+						input_data.setAttribute("value","<?php echo $date_time; ?>"),
+						input_data.setAttribute("autofocus","true")
 					);
-					newtd_c2.setAttribute("width","115");
-					newtd_c2.setAttribute("align","center");
-					newtd_c2.appendChild(
+					newtd_c1.appendChild(
 						input_data = document.createElement("input"),
 						input_data.setAttribute("type","button"),
 						input_data.setAttribute("value","+"),
-						input_data.onclick = function(){ 
-						return addRow(newtr<?php echo $cnt; ?>);
-							ctr++;
-						});
-				var newtd_c3 = document.createElement("td");
-					newtd_c3.setAttribute("width","98");
-					newtd_c3.setAttribute("align","center");
-					newtd_c3.appendChild(
+						input_data.onclick = function(){
+							addRowCloneNew("list_<?php echo $cnt+1; ?>");
+						}
+					);
+			
+		<?php
+	
+		$observations = mysql_query("SELECT * FROM schedule WHERE fStart = '$actualtime'");
+
+		while($rows = mysql_fetch_array($observations))
+		{
+		?>
+				var newtr<?php echo $cnt; ?> = document.createElement("tr");
+					newtr<?php echo $cnt; ?>.setAttribute('class','tr');
+
+				var newtd_c2 = document.createElement("td");
+					newtd_c2.setAttribute("width","138");
+					newtd_c2.setAttribute("align","center");
+					newtd_c2.appendChild(
 						selection = document.createElement("select"),
-			<?php
-			$select = mysql_query("SELECT * FROM source");
-			while($rowsource = mysql_fetch_array($select))
-			{
-			?>
+				<?php   
+				$selectm = mysql_query("SELECT * FROM measurement");
+				while($rowmeasure = mysql_fetch_array($selectm))
+				{
+				?>
 							selection.appendChild(
 							option = document.createElement("option"),
-							option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
-							<?php if($rows['fSourceKey'] == $rowsource['fSourceKEY']){ echo "option.setAttribute('selected',true),"; } ?>
-							option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
+							option.setAttribute("value","<?php echo $rowmeasure['fMeasurementKey']; ?>"),
+							<?php  if($rows['fMeasurementTypeKey']==$rowmeasure['fMeasurementKey']){ echo "option.setAttribute('selected',true),";}   ?>
+							option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
 							),
-			<?php
-			} 
+				<?php 
+				} 
+				?>
+						
+						
+							selection.setAttribute('id','measure'),
+							selection.setAttribute('class','measure')
+						);
+						newtd_c2.setAttribute("width","115");
+						newtd_c2.setAttribute("align","center");
+						newtd_c2.appendChild(
+							input_data = document.createElement("input"),
+							input_data.setAttribute("type","button"),
+							input_data.setAttribute("value","+"),
+							input_data.onclick = function(){ 
+							return addRow(newtr<?php echo $cnt; ?>);
+								ctr++;
+							});
+					var newtd_c3 = document.createElement("td");
+						newtd_c3.setAttribute("width","98");
+						newtd_c3.setAttribute("align","center");
+						newtd_c3.appendChild(
+							selection = document.createElement("select"),
+				<?php
+				$select = mysql_query("SELECT * FROM source");
+				while($rowsource = mysql_fetch_array($select))
+				{
+				?>
+								selection.appendChild(
+								option = document.createElement("option"),
+								option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
+								<?php if($rows['fSourceKey'] == $rowsource['fSourceKEY']){ echo "option.setAttribute('selected',true),"; } ?>
+								option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
+								),
+				<?php
+				} 
+				?>
+					
+							selection.setAttribute('id','source'),	// End of retrieving
+							selection.setAttribute('class','source')	// End of retrieving
+						);
+					var newtd_c4 = document.createElement("td");
+						newtd_c4.setAttribute("width","119");
+						newtd_c4.setAttribute("align","center");
+						newtd_c4.appendChild(
+							input_data = document.createElement("input"),
+							input_data.setAttribute("type","text"),
+							input_data.setAttribute("class","selected"),
+							input_data.setAttribute("size","12"),
+							input_data.setAttribute("value","<?php echo $rows['fData']; ?>"),
+							input_data.setAttribute("placeholder","Value")
+						);
+					var newtd_c5 = document.createElement("td");
+						newtd_c5.setAttribute("width","115");
+						newtd_c5.setAttribute("align","center");
+						newtd_c5.setAttribute("width","115");
+						newtd_c5.setAttribute("align","center");
+						newtd_c5.appendChild(
+							input_data = document.createElement("input"),
+							input_data.setAttribute("type","button"),
+							input_data.setAttribute("value","Delete"),
+							input_data.onclick = function(){ return clearNode(newtr<?php echo $cnt; ?>);
+							}
+						);
+			
+					newtr<?php echo $cnt; ?>.appendChild(newtd_c2);
+					newtr<?php echo $cnt; ?>.appendChild(newtd_c3);
+					newtr<?php echo $cnt; ?>.appendChild(newtd_c4);
+					newtr<?php echo $cnt; ?>.appendChild(newtd_c5);
+					newInnertable.appendChild(newtr<?php echo $cnt; ?>);
+			<?php		
+				$cnt++;
+				$prevtimestamp = $timestamp;
+			}
 			?>
-					
-						selection.setAttribute('id','source'),	// End of retrieving
-						selection.setAttribute('class','source')	// End of retrieving
-					);
-				var newtd_c4 = document.createElement("td");
-					newtd_c4.setAttribute("width","119");
-					newtd_c4.setAttribute("align","center");
-					newtd_c4.appendChild(
-						input_data = document.createElement("input"),
-						input_data.setAttribute("type","text"),
-						input_data.setAttribute("class","selected"),
-						input_data.setAttribute("size","12"),
-						input_data.setAttribute("value","<?php echo $rows['fData']; ?>"),
-						input_data.setAttribute("placeholder","Value")
-					);
-				var newtd_c5 = document.createElement("td");
-					newtd_c5.setAttribute("width","115");
-					newtd_c5.setAttribute("align","center");
-					newtd_c5.setAttribute("width","115");
-					newtd_c5.setAttribute("align","center");
-					newtd_c5.appendChild(
+				var newtd_c6 = document.createElement("td");
+					newtd_c6.appendChild(newInnertable);
+
+				var newtd_c7 = document.createElement("td");
+					newtd_c7.setAttribute("width","115");
+					newtd_c7.setAttribute("align","center");
+					newtd_c7.appendChild(
 						input_data = document.createElement("input"),
 						input_data.setAttribute("type","button"),
-						input_data.setAttribute("value","Delete"),
-						input_data.onclick = function(){ return clearNode(newtr<?php echo $cnt; ?>);
-						}
+						input_data.setAttribute("value","Delete Main"),
+						input_data.onclick = function(){ return clearNode(newdiv); }
 					);
-			
-				newtr<?php echo $cnt; ?>.appendChild(newtd_c2);
-				newtr<?php echo $cnt; ?>.appendChild(newtd_c3);
-				newtr<?php echo $cnt; ?>.appendChild(newtd_c4);
-				newtr<?php echo $cnt; ?>.appendChild(newtd_c5);
-				newInnertable.appendChild(newtr<?php echo $cnt; ?>);
-		<?php		
-			$cnt++;
-			$prevtimestamp = $timestamp;
-		}
-		?>
-			var newtd_c6 = document.createElement("td");
-				newtd_c6.appendChild(newInnertable);
-
-			var newtd_c7 = document.createElement("td");
-				newtd_c7.setAttribute("width","115");
-				newtd_c7.setAttribute("align","center");
-				newtd_c7.appendChild(
-					input_data = document.createElement("input"),
-					input_data.setAttribute("type","button"),
-					input_data.setAttribute("value","Delete Main"),
-					input_data.onclick = function(){ return clearNode(newdiv); }
-				);
-
-			var newOutertr = document.createElement("tr");
-
-			newtable.appendChild(newtd_c1);
-			newtable.appendChild(newtd_c6);
-			newtable.appendChild(newtd_c7);
-
-			newdiv.appendChild(newtable);
-
-			if(nextrow != null){	
-				var doc = document.getElementById(nextrow);
-				$(doc).after(newdiv);
-			} else {
-				targetView.appendChild(newdiv);
-			}	
-	<?php
+
+				var newOutertr = document.createElement("tr");
+
+				newtable.appendChild(newtd_c1);
+				newtable.appendChild(newtd_c6);
+				newtable.appendChild(newtd_c7);
+
+				newdiv.appendChild(newtable);
+
+				if(nextrow != null){	
+					var doc = document.getElementById(nextrow);
+					$(doc).after(newdiv);
+				} else {
+					targetView.appendChild(newdiv);
+				}	
+		<?php
 	}
 
@@ -511,5 +505,5 @@
 	?>
 		$('#save').attr('value','SAVE');
-		addRowClone1();
+		addRowCloneNew();
 	<?php
 	}
