Index: /gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/generate-collection-space.pl.in
===================================================================
--- /gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/generate-collection-space.pl.in	(revision 26746)
+++ /gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/generate-collection-space.pl.in	(revision 26747)
@@ -60,4 +60,7 @@
 	
 	<script type="text/javascript">
+		var clLinks = [];
+		var numClLinks;
+	
 		\$(function(){
 			\$('#progress').progressbar();
@@ -81,75 +84,94 @@
 				}
 				
-				var gs2 = $isGSDL2;
-				
-				var url;
-				
-				if(gs2){
-					url = "library.cgi";
-					url += "?c=" + collect + "&a=d&cl=" + cl;
-				}else{
-					url = "library";
-					url += "?c=" + collect + "&a=b&rt=s&s=ClassifierBrowse&cl=" + cl;
-					url += "&excerptid=gs_content";
-				}
-				
-				docOIDs = [];
-				var outstandingURLs = [];
-				var visitedURLs = {};
-				
-				outstandingURLs.push(url);
-				visitedURLs[url] = 1;
-								
-				while(outstandingURLs.length>0){
-					var clHtml = urlGetSync(url);
-				
-					var aElems;
-					var workingTrav = document.getElementById("workingTraverse");
-					workingTrav.innerHTML = clHtml;
-					aElems = workingTrav.getElementsByTagName("a");
-				
-					//console.log(aElems.length);
-				
-					var actionRE = new RegExp("(\\\\/)(?:document|browse)(\\\\/)");
-					var clRE = new RegExp("(\\\\/)browse\\\\/" + cl + "(\\\\/\\\\d+)+(\$)");
-					var docRE = new RegExp("(?:\\\\/)document\\\\/(.*?)(?:\$)");
-				
-					for(var i = 0; i < aElems.length; i++){
-						var aElem = aElems[i];
-						
-						var href = aElem.href;
-						
-						if(href && href.match(actionRE)){
-							if(href.match(clRE)){
-								if(!visitedURLs[href]){
-									outstandingURLs.push(href);
-									visitedURLs[href] = 1;
-									
-								}
-							}else if(href.match(docRE)){
-								if(!visitedURLs[href]){
-									var docMatch = docRE.exec(href);
-									var docOID = docMatch[1];
-									
-									console.log("found a new doc line: " + docOID);
-									visitedURLs[href] = 1;
-									docOIDs.push(docOID);
-								}
-							}
-						}
-					}
-				}
-				
-				numDocOIDs = docOIDs.length;
-			});
-			
+				
+				
+				
 			return false;
 		});
 		
 		function pageLoaded(){
-			
-			\$(function(){
-				\$('#progressbar').progressbar({ value: 0 });
-			});
+		
+			var iframe = document.getElementById("iframe");
+			
+			if(iframe.src){
+				if(iframe.style.display != "block"){
+					iframe.height = "90%";
+					iframe.style.display = "block";
+				}
+				
+				var iframeDoc;
+				
+				if(iframe.contentDocument){
+					/* FF */
+					iframeDoc = iframe.contentDocument;
+				}else if(iframe.contentWindow){
+					/* IE */
+					iframeDoc = iframe.contentWindow.document;
+				}
+				
+				var frameNum = (numClPages - clPages.length);
+				var progressPercent = frameNum/numClPages * 100;
+				
+				\$(function(){
+					\$('#progressbar').progressbar({ value: 0 });
+				});
+				
+				var gsContent = iframeDoc.getElementById("gs_content");
+				
+				//Need to change htmlToExpeditee code to account for links
+				var expFrameTre = htmlToExpeditee(gsContent);
+				
+				var collect = document.getElementById("collect").value;
+				var site = document.getElementById("site").value;
+				
+				var url = "cgi-bin/generate-collection-space.pl";
+				var params = "c=" + collect;
+				
+				if(site.match(/\\w/)){
+					params += "&site=" + site;
+				}
+				
+				params += "&a=generate-frame&fn=" + frameNum;
+				params += "&json=" + escape(expFrame);
+				
+				var clHtml = urlPostSync(url,params);
+				
+				if(!clHtml.match(/html-to-expeditee saved frame/)){
+					alert("Error processing url: " + url);s
+				}
+				
+				if(clPages.length > 0){
+					var clPage = clPages.shift();
+					
+					var cl = document.getElementById("cl").value;
+					
+					var gs2 = $isGSDL2;
+					
+					var url;
+					
+					var url;
+					
+					if(gs2){
+						url = "library.cgi";
+						url += "?c=" + collect + "&a=d&d=" + docOID;
+					}else{
+						url = "library";
+						url += "?c=" + collect + "&a=d&d=" + docOID;
+					}
+					
+					iframe.src = url;
+				}else{
+				
+					var progressbar = document.getElementById("progressbar");
+					progressbar.style.display = "none";
+					
+					iframe.style.display = "none";
+					delete iframe.src;
+				}
+				
+				
+			}
+			
+			
 		}
 	</script>
@@ -157,5 +179,4 @@
 	<div id="progressbar" width="100%" style="display: none; margin: 10px; height: 10px;"></div>
 	
-	<!-- set display to "none" for this div-->
 	<div id="workingTraverse" style="display: none"></div>
 	
@@ -181,5 +202,5 @@
     $gsdl_cgi->checked_chdir($gsdlhome);
 
-    require cgiactions::HtmlToExpediteeAction;
+    require cgiactions::CollectionSpaceAction;
 	
 	$gsdl_cgi->parse_cgi_args();
@@ -188,30 +209,33 @@
     $gsdl_cgi->{'xml'} = 0;
 	
-	
-	#my $action = new HtmlToExpediteeAction($gsdl_cgi,$iis6_mode);
-
-	#$action->do_action();
-	
-	my $collect = $gsdl_cgi->clean_param("collect");
-	my $cl = $gsdl_cgi->clean_param("cl");
-	
-	#Establish collect_dir using defining 'site' along the way if GS3
-	my $site = undef;
-	my $isGSDL2 = undef;
-	
-	if($gsdl_cgi->greenstone_version() == 2){
-		$isGSDL2 = 1;
+	my $fn = $gsdl_cgi->clean_param("fn");
+	
+	if(defined $fn){
+		#Generate a frame.
+		my $action = new CollectionSpaceAction($gsdl_cgi,$iis6_mode);
+		$action->do_action();
 	}else{
-		$isGSDL2 = 0;
-		
-		#GS3 makes use of 'site'
-		$site = $gsdl_cgi->clean_param("site");
-		
-		if(!defined $site){
-			$gsdl_cgi->generate_error("No site specified.");
+		my $collect = $gsdl_cgi->clean_param("collect");
+		my $cl = $gsdl_cgi->clean_param("cl");
+	
+		#Establish collect_dir using defining 'site' along the way if GS3
+		my $site = undef;
+		my $isGSDL2 = undef;
+	
+		if($gsdl_cgi->greenstone_version() == 2){
+			$isGSDL2 = 1;
+		}else{
+			$isGSDL2 = 0;
+		
+			#GS3 makes use of 'site'
+			$site = $gsdl_cgi->clean_param("site");
+		
+			if(!defined $site){
+				$gsdl_cgi->generate_error("No site specified.");
+			}
 		}
+	
+		generate_html_form($isGSDL2,$site,$collect,$cl);
 	}
-	
-	generate_html_form($isGSDL2,$site,$collect,$cl);
 }
 
