




/*
     FILE ARCHIVED ON 4:25:15 Jun 22, 2007 AND RETRIEVED FROM THE
     INTERNET ARCHIVE ON 12:37:32 Feb 13, 2012.
     JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.

     ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
     SECTION 108(a)(3)).
*/

		var keyword;
		var blogBody;
					
		var timeStampDisplay;
		var amazonDisplay;
		var yahooWordsDisplay;
		var googleNewsDisplay;
		var siteSearchDisplay;
		var mapImageDisplay;
		var flickrImagesDisplay;
		var iconDisplay;
		var yahooAnswersDisplay;
		
		var dateStatementInput="";
		var opinionStatementInput="";
		var googleNewsInput="";
		var amazonInput="";
		var amazonIdInput="";
		var siteSearchInput="";
		var siteAddressInput="";	
		var flickrImagesInput="";	
		var yahooAnswersInput="";
		
		var googleNewsArray = new Array(10);
		var yahooAnswersArray = new Array(10);
		var siteSearchArray = new Array(10);
		var amazonArray = new Array(10);
		
		var flickrPicCount = 1;		
		
		dojo.addOnLoad(init)
		
		function controller()
		{
			clearInput();
			dateStatementInput = "Timestamp: ";
		 	opinionStatementInput = "My Standpoint: ";
			keyword = document.forms["mashup"].elements["keyword"].value;		
			blogBody = "";
			
			if(keyword.length == 0){
				keyword = "";				
				return;
			}
			else{
				document.forms["mashup"].elements["keyword"].disabled = true;
				
				document.getElementById("autoContentTargetDiv").style.display = ""; 
				
				document.getElementById("htmlContentTargetDiv").style.display = ""; 
			}
		
			submitBlogBody();

			displayTimestamp();
					
			getYahooWords();

					
			if(googleNewsInput == ""){
			  	googleNewsInput = keyword;
			}
			var url= "googlenews.php?q=";
			getGoogleService(url , googleNewsInput, displayGoogleNews);				
		
		
			if(amazonInput == ""){
			  	amazonInput = keyword;
			}
			getAmazonProducts(amazonInput);				
		
		
			if(siteSearchInput == ""){
			  	siteSearchInput = keyword;
			}
			if(siteAddressInput != ""){
				var url = "googlesearch.php?site=" + siteAddressInput + "&q=";
				getGoogleService(url , siteSearchInput, displaySiteSearch);
			}
			else{
				document.getElementById("siteSearchTargetDiv").innerHTML = "";
			}

		
			if(yahooAnswersInput == ""){
			  	yahooAnswersInput = keyword;
			}
			getYahooAnswers(yahooAnswersInput, displayYahooAnswers);				
		
			
			if(flickrImagesInput == ""){
			  	flickrImagesInput = keyword;				
			}
			getFlickrImages(flickrImagesInput, 1, displayFlickrImages);
		
		
			submitMap();
			
			submitOpinion();
				
		}
		
		function saveDateStatementInput(newValue, oldValue) {			
			dateStatementInput = newValue;
			document.forms["mashup"].elements["wanttimestamp"].checked = true;
		}		
		
		function saveOpinionStatementInput(newValue, oldValue) {
			opinionStatementInput = newValue;
		}	
				
		function saveGoogleNewsInput(newValue, oldValue) {
			displayLoadingImage("googleNewsTargetDiv");
			googleNewsInput = newValue;
			var url= "googlenews.php?q=";
			document.forms["mashup"].elements["wantnews"].checked = true;
			getGoogleService(url , googleNewsInput, displayGoogleNews);
		}
		
		function saveAmazonInput(newValue, oldValue) {
			displayLoadingImage("amazonTargetDiv");
			amazonInput = newValue;
			document.forms["mashup"].elements["wantamazon"].checked = true;
			getAmazonProducts(amazonInput);
		}
		
		function saveAmazonIdInput(newValue, oldValue) {
			displayLoadingImage("amazonTargetDiv");
			amazonIdInput = newValue;
			document.forms["mashup"].elements["wantamazon"].checked = true;	
			getAmazonProducts(amazonInput);		
		}
		
		function saveSiteSearchInput(newValue, oldValue) {
			siteSearchInput = newValue;
			if(siteAddressInput != ""){
				displayLoadingImage("siteSearchTargetDiv");
				var url = "googlesearch.php?site=" + siteAddressInput + "&q=";
				getGoogleService(url , siteSearchInput, displaySiteSearch);
			}
			else{
				document.getElementById("siteSearchTargetDiv").innerHTML = "";
			}				
		}
		
		function saveSiteAddressInput(newValue, oldValue) {
			siteAddressInput = newValue;
			if(siteAddressInput != ""){
				displayLoadingImage("siteSearchTargetDiv");
				document.forms["mashup"].elements["wantsitesearch"].checked = true;
				var url = "googlesearch.php?site=" + siteAddressInput + "&q=";
				getGoogleService(url , siteSearchInput, displaySiteSearch);
			}
			else{
				document.getElementById("siteSearchTargetDiv").innerHTML = "";
			}
		}
			
		function saveFlickrImagesInput(newValue, oldValue) {
			displayLoadingImage("flickrImagesTargetDiv");
		  	flickrImagesInput = newValue;
			document.forms["mashup"].elements["wantpics"].checked = true;
			getFlickrImages(flickrImagesInput, 1, displayFlickrImages);
		}
		
		function saveYahooAnswersInput(newValue, oldValue) {
			displayLoadingImage("yahooAnswersTargetDiv");
		  	yahooAnswersInput = newValue;
			document.forms["mashup"].elements["wantanswers"].checked = true;
			getYahooAnswers(yahooAnswersInput, displayYahooAnswers);
		}
		
	  	function init() {			
			document.mashup.keyword.focus();
			dojo.widget.byId("dateStatementInput").onSave = saveDateStatementInput;
			dojo.widget.byId("opinionStatementInput").onSave = saveOpinionStatementInput;
	  		dojo.widget.byId("googleNewsInput").onSave = saveGoogleNewsInput;
			dojo.widget.byId("amazonInput").onSave = saveAmazonInput;
			dojo.widget.byId("amazonIdInput").onSave = saveAmazonIdInput;
			dojo.widget.byId("siteSearchInput").onSave = saveSiteSearchInput;
			dojo.widget.byId("siteAddressInput").onSave = saveSiteAddressInput;
			dojo.widget.byId("flickrImagesInput").onSave = saveFlickrImagesInput;
			dojo.widget.byId("yahooAnswersInput").onSave = saveYahooAnswersInput;
	  	}
		
		function submitBlogBody(){
			updateRTE('blogbody');
			blogBody = document.forms["mashup"].elements["blogbody"].value;
			if(blogBody.length == 0){
				blogBody = "";
			}
			document.getElementById("blogBodyTargetDiv").innerHTML = '<div class="blockquote">' + blogBody + '</div>';
			document.forms["mashup"].elements["wantblogbody"].checked = true;
		}

		function submitTimestamp(){
			displayTimestamp();
			document.forms["mashup"].elements["wanttimestamp"].checked = true;
		}

		function submitMap(){
			var address = document.forms["mashup"].elements["address"].value;
		  	var zoom = document.forms["mashup"].elements["zoom"].value;	
			if(zoom.length <= 0 || zoom > 12){
				zoom = 6;
			}
			if(address.length != 0){
				displayLoadingImage("mapImageTargetDiv");
			  	getMapImage(address, zoom, displayMapImage);
				document.forms["mashup"].elements["wantmap"].checked = true;
			}
			else{
				document.getElementById("mapImageTargetDiv").innerHTML = "";
				mapImageDisplay = "";
			}
		}

		function submitOpinion(){
			if((document.forms["mashup"].elements["wantagreeicon"].checked == true) || (document.forms["mashup"].elements["wantdisagreeicon"].checked == true)){
				displayIcon();
			}
			else{		
				document.getElementById("iconTargetDiv").innerHTML = "";							
			}
		}
				
		function clearInput(){
			document.forms["mashup"].elements["keyword"].disabled = false;
			document.getElementById("autoContentTargetDiv").style.display = "none"; 
			document.getElementById("htmlContentTargetDiv").style.display = "none"; 
			
			googleNewsInput="";	
			siteSearchInput="";
			flickrImagesInput="";	
			yahooAnswersInput="";
			amazonInput="";
		
			timeStampDisplay="";
			yahooWordsDisplay="";
			googleNewsDisplay="";
			amazonDisplay="";
			amazonDetailsDisplay="";
			siteSearchDisplay="";
			yahooAnswersDisplay=""
			mapImageDisplay="";
			flickrImagesDisplay="";
			iconDisplay="";

			flickrPicCount = 1;
			document.getElementById("finalDiv").innerHTML = "";
			document.getElementById("amazonDetailsDiv").innerHTML = "";
		}
		
		function showDiv(divName){
			document.getElementById(divName).style.display = ""; 
		}
		
		function hideDiv(divName){
			document.getElementById(divName).style.display = "none"; 
		}
		
		function displayIcon(){
			var iconTarget = document.getElementById("iconTargetDiv");
		  	iconDisplay = opinionStatementInput;	
			if(document.forms["mashup"].elements["wantagreeicon"].checked == true){
				iconDisplay = iconDisplay + '<img src="http://web.archive.org/web/20070622042515/http://stuffablog.com/bmash/images/thumbs-up.gif"/>';			
			}
		
			if(document.forms["mashup"].elements["wantdisagreeicon"].checked == true){
				iconDisplay = iconDisplay + '<img src="http://web.archive.org/web/20070622042515/http://stuffablog.com/bmash/images/thumbs-down.gif"/>';	
			}			
			iconTarget.innerHTML = '<div class="blockquote">' + iconDisplay + '</div>';
		}

		function displayTimestamp()
		{		 
			var startDate = dojo.widget.byId("startDate").storedDate;
			var endDate = dojo.widget.byId("endDate").storedDate; 
			
			var timeStampTarget = document.getElementById("timeStampTargetDiv");		
			timeStampDisplay = dateStatementInput + startDate + "  " + endDate + "<br>";
      		timeStampTarget.innerHTML = '<div class="blockquote">' + timeStampDisplay + '</div>';
		}
		
		function displayHTML()
		{
			document.getElementById("finalDiv").innerHTML = '<br><strong>HTML</strong><br>' + '<TEXTAREA READONLY name="htmlText" id="htmlText" COLS=60 ROWS=10 wrap="virtual" onclick="javascript:select();">' + finalHtml() + '</TEXTAREA>';
			document.getElementById("finalDiv").style.display = "";
		}
		
		
		function displayPreview()
		{
			document.getElementById("finalDiv").innerHTML = '<br><strong>Preview</strong><br>' + finalHtml();
			document.getElementById("finalDiv").style.display = "";
		}
			
		function finalHtml(){
			var finalDisplay = "";
		
			if(document.forms["mashup"].elements["wantblogbody"].checked == true){
				submitBlogBody();
				finalDisplay = finalDisplay + blogBody;
			}

			if(document.forms["mashup"].elements["wanttimestamp"].checked == true){
				finalDisplay = finalDisplay + "<br>";
				displayTimestamp();
				finalDisplay = finalDisplay + timeStampDisplay;
			}	
			
			if(document.forms["mashup"].elements["wanttags"].checked == true){
				finalDisplay = finalDisplay + "<br>";
				finalDisplay = finalDisplay + yahooWordsDisplay;
			}
			
			if(document.forms["mashup"].elements["wantmap"].checked == true){
				submitMap();
				finalDisplay = finalDisplay + "<br>";
				finalDisplay = finalDisplay + mapImageDisplay;
			}
			
			if(document.forms["mashup"].elements["wantpics"].checked == true){
				finalDisplay = finalDisplay + "<br>";
				finalDisplay = finalDisplay + flickrImagesDisplay + "<br>";
			}
			
			if(document.forms["mashup"].elements["wantnews"].checked == true){
				finalDisplay = finalDisplay + "<br>" + "<strong>Related News</strong><br>";
				finalDisplay = finalDisplay + getCheckValues(document.forms["mashup"].elements["googleNewsSelector"], googleNewsArray); 
			}
			
			if(document.forms["mashup"].elements["wantanswers"].checked == true){
				finalDisplay = finalDisplay + "<br>" + "<strong>Yahoo Answers</strong><br>";
				finalDisplay = finalDisplay + getCheckValues(document.forms["mashup"].elements["yahooAnswersSelector"], yahooAnswersArray);
			}
			
			if(document.forms["mashup"].elements["wantamazon"].checked == true){
				finalDisplay = finalDisplay + "<br>" + "<strong>Product Details from Amazon</strong><br>";
				finalDisplay = finalDisplay + amazonDetailsDisplay;
			}
			
			if(document.forms["mashup"].elements["wantsitesearch"].checked == true){
				finalDisplay = finalDisplay + "<br>";
				finalDisplay = finalDisplay + siteSearchDisplay + "<br>";
			}
			
			if((document.forms["mashup"].elements["wantagreeicon"].checked == true) || (document.forms["mashup"].elements["wantdisagreeicon"].checked == true)){				
				displayIcon();
				finalDisplay = finalDisplay + "<br>";
				finalDisplay = finalDisplay + iconDisplay + "<br>";
			}

			finalDisplay = finalDisplay + '<br><font size=1><a href="http://web.archive.org/web/20070622042515/http://stuffablog.com" target="_blank">Powered by StuffaBlog</a></font>';
			
			return finalDisplay;
		}
		
		
		function getCheckValues(checkBoxArray, contentArray){
			var displayText = "";
			if(contentArray.length == 0){
				return displayText;	
			}	
			if(contentArray.length == 1){
			   if (checkBoxArray.checked == true){
			   	 displayText = displayText + contentArray[0]  + "<br>";
			   }	
			}	

			if(contentArray.length > 1)
			{			   			
			for (i = 0; i < contentArray.length; i++){
			   if (checkBoxArray[i].checked == true){
			   	 displayText = displayText + contentArray[i]  + "<br>";
			   }
			}
			}
			return displayText;
		}
		
		function displayGoogleNews(values)
		{
			var displayText = "";
	   		var googleNewstarget = document.getElementById("googleNewsTargetDiv");
			googleNewsArray.length = values.length;
			displayText = "<strong>Related News</strong><br>";			
			for (loopIndex = 0; loopIndex < values.length; loopIndex++) {
				 googleNewsArray[loopIndex] = values[loopIndex];
				 if(loopIndex < 4){
				 	displayText = displayText + '<INPUT TYPE="CHECKBOX" Name="googleNewsSelector"  checked />';  
				 }
				 else{				 	
				 	displayText = displayText + '<INPUT TYPE="CHECKBOX" Name="googleNewsSelector" />';
				 } 
				 displayText = displayText + values[loopIndex] + "<br>";
			}
	  		googleNewsDisplay = displayText ;
			googleNewstarget.innerHTML = '<div class="blockquote">' + googleNewsDisplay + '<font size=1> Powered by <a href="http://web.archive.org/web/20070622042515/http://news.google.com/">Google</a></font>' + "</br>" + '</div>';			
		}
		
		function displayAmazon(values)
		{
			var displayText = "";
	   		var amazontarget = document.getElementById("amazonTargetDiv");
			displayText = "<strong>Amazon products</strong><br>";
			for (loopIndex = 0; loopIndex < values.length; loopIndex++) {
				 amazonArray[loopIndex] = values[loopIndex];
				 displayText = displayText + '<img src="images/expand.gif"/>' + values[loopIndex] + "<br>";
			}
	  		amazonDisplay = displayText ;
			amazontarget.innerHTML = '<div class="blockquote">' + amazonDisplay + '<font size=1> Powered by <a href="http://web.archive.org/web/20070622042515/http://amazon.com">Amazon</a></font>' + "</br>" + '</div>';			
		}
		
		function displaySiteSearch(values)
		{
			var displayText = "";
	   		var siteSearchtarget = document.getElementById("siteSearchTargetDiv");
			siteSearchArray.length = values.length;
			for (loopIndex = 0; loopIndex < values.length; loopIndex++) {
				 siteSearchArray[loopIndex] = values[loopIndex];
				 displayText = displayText + values[loopIndex] + " - ";
			}
			siteSearchDisplay = "<strong>Some of my recent related posts</strong><br>";
	  		siteSearchDisplay = siteSearchDisplay + displayText ;			
			siteSearchtarget.innerHTML = '<div class="blockquote">' + siteSearchDisplay + '<br> <font size=1> Powered by <a href="http://web.archive.org/web/20070622042515/http://blogsearch.google.com/">Google</a> </font>' + "</br>" + '</div>';			
		}
		
		
		function displayFlickrImages(displayHtml)
		{		  
			var flickrImagesTarget = document.getElementById("flickrImagesTargetDiv");
			flickrImagesDisplay = "<strong>Relevant pics from Flickr</strong><br><br>";
			flickrImagesDisplay = flickrImagesDisplay + displayHtml;
			flickrImagesTarget.innerHTML = '<div class="blockquote">' + flickrImagesDisplay 
											+ '<br><font size=1> Powered by <a href="http://web.archive.org/web/20070622042515/http://flickr.com/">Flickr</a> </font>' + "</div>";	
		}
		
		function displayLoadingImage(divName){
			document.getElementById(divName).innerHTML = '<img src="images/loading.gif" alt="Loading..."/>';
		}
		
		function moreFlickrImages()
		{				
			displayLoadingImage("flickrImagesTargetDiv");		
			flickrPicCount = flickrPicCount + 1;
			getFlickrImages(flickrImagesInput, flickrPicCount, displayFlickrImages);					
		}
		
		function prevFlickrImages()
		{					
			displayLoadingImage("flickrImagesTargetDiv");
			flickrPicCount = flickrPicCount - 1;
			if(flickrPicCount < 1){
				flickrPicCount = 1;
			}
			getFlickrImages(flickrImagesInput, flickrPicCount, displayFlickrImages);						
		}
		
		function displayMapImage(displayHtml)
		{
			var mapImagetarget = document.getElementById("mapImageTargetDiv");
			mapImageDisplay = "<strong>Yahoo Map image</strong><br>";
			mapImageDisplay = mapImageDisplay + displayHtml ;
			mapImagetarget.innerHTML = '<div class="blockquote">' + mapImageDisplay + '<br><font size=1> Powered by <a href="http://web.archive.org/web/20070622042515/http://maps.yahoo.com/">Yahoo</a> </font>' + "</br>" + '</div>';		
		}
		
		function displayYahooAnswers(values)
		{
			var displayText = "";
	   		var yahooAnswerstarget = document.getElementById("yahooAnswersTargetDiv");
			yahooAnswersArray.length = values.length;			
			for (loopIndex = 0; loopIndex < values.length; loopIndex++) {
				 yahooAnswersArray[loopIndex] = values[loopIndex];
				 if(loopIndex < 4){
				 	displayText = displayText + '<INPUT TYPE="CHECKBOX" Name="yahooAnswersSelector"  checked />';  
				 }
				 else{				 	
				 	displayText = displayText + '<INPUT TYPE="CHECKBOX" Name="yahooAnswersSelector" />';
				 } 
				 displayText = displayText + values[loopIndex] + "<br>";
			}
			yahooAnswersDisplay = "<strong>Yahoo Answers</strong><br>";
	  		yahooAnswersDisplay = yahooAnswersDisplay + displayText ;
			yahooAnswerstarget.innerHTML = '<div class="blockquote">' + yahooAnswersDisplay + '<font size=1> Powered by <a href="http://web.archive.org/web/20070622042515/http://answers.yahoo.com/">Yahoo</a> </font>' + "</br>" + '</div>';			
		}

	    function getYahooWords()
	    {
	      var XMLHttpRequestObject = false; 
	      var mozillaFlag = false;
	      var blogInput = keyword + blogBody;
	      var dataSource = "stuffablog.php" ;
			
	      if (window.XMLHttpRequest) 
				{
	        XMLHttpRequestObject = new XMLHttpRequest();     
	        mozillaFlag = true;
	      } 
	      else if (window.ActiveXObject) 
				{
	        XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
	      }
	
	      if(XMLHttpRequestObject) 
				{
	        XMLHttpRequestObject.open("POST", dataSource); 
	   			XMLHttpRequestObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	  
	        XMLHttpRequestObject.onreadystatechange = function() 
	        { 
	          if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) 
	  			{ 
	            var xmlDocument = XMLHttpRequestObject.responseXML;
	            if(mozillaFlag){
	              removeWhitespace(xmlDocument);
	          	}
	            //alert(xmlDocument.documentElement.xml);
	            extractYahooWords(xmlDocument);																
	          } 
	        }
	        XMLHttpRequestObject.send("blogtext="+blogInput); 			
	      }					
	     }
	
	      function extractYahooWords(xmldoc)
	      {	  	 
	        var loopIndex;
	        var displayText="";        
	
	        resultnodes = xmldoc.getElementsByTagName("Result");                  	 
	
	        for (loopIndex = 0; loopIndex < 6; loopIndex++) {
	          if(resultnodes[loopIndex]){
	
	             resultnode = resultnodes[loopIndex];
	
	             displayText = displayText + resultnode.firstChild.nodeValue + " , ";
	          }
	        }
	        
			yahooWordsDisplay = "<strong>Tags</strong><br>" + displayText ;
			yahooWordstarget = document.getElementById("yahooWordsTargetDiv");
			yahooWordstarget.innerHTML = '<div class="blockquote">' + yahooWordsDisplay + + "<br><font size=1> Powered by Yahoo </font>" + "</br>" + '</div>' ;
	      }
	
		
		
	      function removeWhitespace(xml) 
	      {
	        var loopIndex;
	
	        for (loopIndex = 0; loopIndex < xml.childNodes.length; 
	          loopIndex++) {
	
	          var currentNode = xml.childNodes[loopIndex];
	
	          if (currentNode.nodeType == 1) {
	            removeWhitespace(currentNode);
	          }
	
	          if (((/^\s+$/.test(currentNode.nodeValue))) &&   
	            (currentNode.nodeType == 3)) {
	              xml.removeChild(xml.childNodes[loopIndex--]);
	          }
	        }
	      }

