 	 
 	function formatAsMoney(mnt) { 
     mnt -= 0; 
     mnt = (Math.round(mnt*100))/100; 
     return (mnt == Math.floor(mnt)) ? mnt + '.00'  
               : ( (mnt*10 == Math.floor(mnt*10)) ?  
                        mnt + '0' : mnt); 
 	} 
 	 
 		function writeHeader() { 
 		        document.write('<div class="labels2" align="center"><br>' + companyName + ' <br>'); 
 				document.write('CLEANING SCHEDULE for ' + cleanDate + ' <br><br></div>');		 
 				document.write('<div class="labels2">Section: _____________________________________ Inspector:_____________________  Start Time: __________________ <br><br><br>'); 
 				document.write('Crew: _________________________________________________________________________  Day: ' + cleanDOW + '   <br></b></div>'); 
 		        document.write('<div class="labels2" align="left">Note: ' + notetext + ' <br></div>'); 
 				document.write('<table class="labels" border="0" cellpadding="1" width="750"><tr>'); 
 				document.write('<th class="cleanTh" width="30">Cplx</th>'); 
 				document.write('<th class="cleanTh" width="60">Unit</th>'); 
 				document.write('<th class="cleanTh" width="30">Clean</th>'); 
 				document.write('<th class="cleanTh" width="30">Size</th>'); 
 				document.write('<th class="cleanTh" width="50">Rate</th>'); 
 				document.write('<th class="cleanTh"  width="30">Mins</th>'); 
 				document.write('<th class="cleanTh" width="30">Key</th>'); 
 				document.write('<th class="cleanTh" width="50">In</th>'); 
 				document.write('<th class="cleanTh" width="50">Out</th>'); 
 				document.write('<th class="cleanTh" width="35">Depart</th>'); 
 				document.write('<th class="cleanTh" width="35">Next<br>Arr</th>'); 
 				document.write('<th class="cleanTh" width="30">Days<br>Away</th>'); 
 				document.write('<th class="cleanTh" width="30">Misc<br>1</th>'); 
 				document.write('<th class="cleanTh" width="30">Misc<br>2</th>'); 
 				document.write('<th class="cleanTh" width="230">Notes</th>'); 
 				document.write('</tr></table>'); 
 				} 
  
 				 
 	function writeClean(a,b,c,d,e,f,g,h,i,j) { 
 	       document.write( '<table class="cleantable" border="10" cellpadding="1" width="750"><tr>' ); 
 		   document.write( '<td class="cleanTD"  width="30" align="center">' + a + '</td>'); //  complex 
    		   document.write( '<td class="cleanTD"  width="60" align="center">' + b + '</td>'); //  unit 
 		   document.write( '<td class="cleanTD"  width="30" align="center">' + c + '</td>'); //  clean type 
    		   document.write( '<td class="cleanTD"  width="30" align="center">' + d + '</td>'); //  size 
 		   document.write( '<td class="cleanTD"  width="50" align="right">' + e + '</td>'); //  charge 
    		   document.write( '<td class="cleanTD"  width="30" align="right">' + f + '</td>'); //  minutes 
 		   document.write( '<td class="cleanTD"  width="30">&nbsp;</td>'); //  key 
 		   document.write( '<td class="cleanTD"  width="50">&nbsp;</td>'); //  in 
    		   document.write( '<td class="cleanTD"  width="50">&nbsp;</td>'); //  out 
 		   document.write( '<td class="cleanTD"  width="35" align="center">' + g + '</td>'); //  depart 
    		   document.write( '<td class="cleanTD"  width="35" align="center">' + h + '</td>'); //  next arr 
    		   document.write( '<td class="cleanTD"  width="30" align="right">' + i + '</td>'); //  days away 
    		   document.write( '<td class="cleanTD"  width="30"> &nbsp; </td>'); //  misc 1 
    		   document.write( '<td class="cleanTD"  width="30"> &nbsp; </td>'); //  misc 2 
    		   document.write( '<td class="cleanTD"  width="230">' + j + '</td>');//	 notes   		   		    
 		   document.write( '</tr></table>' ); 
 	} 
  
 	 
 	 
 	 
 	function createNewSection(name) { 
 		var name = $F('sectionName'); 
 		if (name != '') { 
  
 	       // create the Object of the header line for creating new DIVS 
 		   var headerTag = Builder.node('table', {"id": "tabledetail"+(sections.length + 1), className: 'labels', border: '1', cellpadding: '1', width: '750' },  
 							         [Builder.node('tr',   
 								           [ 
 										   Builder.node('div', {className: 'labels2', align: 'left'}, ' '), 
 										   Builder.node('div', {className: 'labels2', align: 'center'}, companyName), 
 										   Builder.node('div', {className: 'labels2', align: 'center'},'CLEANING SCHEDULE for ' + cleanDate), 
 										   Builder.node('div', {className: 'labels2', align: 'left'}, ' '), 
 										   Builder.node('div', {className: 'labels2', align: 'left'}, 'Section: _____________________________________ Inspector:_____________________  Start Time: __________________'), 
 										   Builder.node('div', {className: 'labels2', align: 'left'}, ' '), 
 										   Builder.node('div', {className: 'labels2', align: 'left'}, ' '), 
 										   Builder.node('div', {className: 'labels2', align: 'left'}, 'Housekeeper: _________________________________________________________________________  Day:' + cleanDOW), 
 										   Builder.node('div', {className: 'labels2', align: 'left'}, 'Note: ' +  notetext), 
 										   Builder.node('th', {className: 'cleanTh', width: '30'},'Cplx'),     
 										   Builder.node('th', {className: 'cleanTh', width: '60'},'Unit'),     
 										   Builder.node('th', {className: 'cleanTh', width: '30'},'Clean'),     
 										   Builder.node('th', {className: 'cleanTh', width: '30'},'Size'),     
 										   Builder.node('th', {className: 'cleanTh', width: '50'},'Rate'),     
 										   Builder.node('th', {className: 'cleanTh', width: '30'},'Mins'),     
 										   Builder.node('th', {className: 'cleanTh', width: '30'},'Key'),     
 										   Builder.node('th', {className: 'cleanTh', width: '50'},'In'),     
 										   Builder.node('th', {className: 'cleanTh', width: '50'},'Out'),     
 										   Builder.node('th', {className: 'cleanTh', width: '35'},'Depart'),     
 										   Builder.node('th', {className: 'cleanTh', width: '35'},'Next Arr'),     
 										   Builder.node('th', {className: 'cleanTh', width: '30'},'Days Away'),     
 										   Builder.node('th', {className: 'cleanTh', width: '30'},'Misc 1'),     
 										   Builder.node('th', {className: 'cleanTh', width: '30'},'Misc 2'),     
 										   Builder.node('th', {className: 'cleanTh', width: '230'},'Notes')     
 										   ] 
 									       )  
 			           				  ]);  
 			var newDiv = Builder.node('div', {id: 'group' + (sections.length + 1), className: 'section', style: 'display:none;' }, [ 
          	  								Builder.node('h3', {className: 'handle'},    
  		   								             [ name + " ",   						    
 			   										    Builder.node('span', {id: 'totalgroup' + (sections.length +1)},   "  Total:  "), 
 				   							    		Builder.node('span',  [																				  
 														                     Builder.node('input', {className: 'Left20', type: 'Text', size: '80'}) 
 																			 ]																									   
 																	)																												 
 													 ]																																  
 													  ), headerTag 																												
 										]);  
 			var newFooter = Builder.node('span', {id: "footersection", className: "footer"}, notetext)			  
 			sections.push(newDiv.id); 
 			$('page').appendChild(newDiv); 
 			//$('page').appendChild(newFooter); 
 			Effect.Appear(newDiv.id); 
 			destroyLineItemSortables(); 
 			createLineItemSortables(); 
 			createGroupSortable(); 
 		} 
 	} 
  
 	function createLineItemSortables() { 
 		for(var i = 0; i < sections.length; i++) { 
 			Sortable.create(sections[i],{tag:'div',dropOnEmpty: true, containment: sections,only:'lineitem'}); 
 		} 
 	} 
  
 	function destroyLineItemSortables() { 
 		for(var i = 0; i < sections.length; i++) { 
 			Sortable.destroy(sections[i]); 
 		} 
 	} 
  
 	function createGroupSortable() { 
 		Sortable.create('page',{tag:'div',only:'section',handle:'handle'}); 
 	} 
  
  
  
 	 
 	 
 	 
  
  
  
 // ------------------------------------------------------------------// 
 	/* 
 	Debug Functions for checking the group and item order 
 	ALSO  Recalc the header totals 
 	*/ 
 	function getGroupOrder() { 
 		var sections = document.getElementsByClassName('section'); 
 		var alerttext = ''; 
 				 
 			  
 		//alert( lineitemList ); 
 		 
 		sections.each(function(section) { 
          		var sectionID = section.id; 
 				var footersectionID = "footer"+sectionID 
 				var totalsectionID = "total"+sectionID 
 			    //alert( totalsectionID ); 
 				var order = Sortable.serialize(sectionID); 
 	   			sectionLength =  Sortable.sequence(section).length ;  
                 //alert(" section length  " + sectionLength); 
 				if (sectionLength <= 0 ) {  
 				                      // Reset To 0.00 when empty 
 				                      eval(totalsectionID).innerHTML = " Total:  0.00 " ;  
 									  } 
 			alerttext += sectionID + ': ' + Sortable.sequence(section) + '\n'; 
 			sectionlist =  Sortable.sequence(section) ; // like  1,2,5,6,8 
 			sectionlist =  'xx' + sectionlist ;   // turn into string xx  like xx1,2,5,6,8 
 		     
 		 
 			var mySplitResult = sectionlist.split(","); 
             
 			var sectionTotal = 0.00 ; 
 			 
 			   for(var i = 0; i < sectionLength; i++) { 
 				 
                 var os = mySplitResult[i]; 
 				var os = os.replace('xx', ''); 
 				var os  = os -1; 
 		  		 //alert( " i and  os...  " + i +"  " + os ); 
 				 lival = eval(lineitems[os].value); 
 				 //alert( lival ); 
 				 sectionTotal += lival;  // lineitems[os].value; 
 				 //alert( sectionTotal ); 
 				 eval(totalsectionID).innerHTML = " Total " + formatAsMoney(sectionTotal); 
 			   } 
 		}); 
 			 
 		return false; 
 	} 
 	 
  
  
  
  
 				 
