
function roll(img_name, img_src)
{
	document.getElementById(img_name).src = img_src;
}

function setSubmit(but_name)
{
	document.getElementById('submitButton').value = but_name;
}

function trim(str){
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

  
function doSearch(queryString, output) {
    dojo.require("dojox.data.GoogleSearchStore");
    
    var store = new dojox.data.GoogleWebSearchStore();
    var list = dojo.byId(output);
    var done = new Array(0);
	
    //Clean up any previous searches
    while(list.firstChild){
      list.removeChild(list.firstChild);
    }
    
    store.fetch({
      query:{text: queryString},
      count: 20,
      onComplete: function(items, request) {
        //Print out the search results as an unordered 
    //list
        var delay = 0;
		
        dojo.forEach(items, function(item){
          var li = document.createElement("li");
		  var title = store.getValue(item, "title");
		  if(!contains(done,title)){
			  li.innerHTML = 
				"<a href=\"" +
				store.getValue(item, "url")  + 
				"\">" +
				title.substring(0) +
				"</a>" + " - " +
				store.getValue(item, "content");
			  dojo.style(li, "opacity", "0");
			  list.appendChild(li);
			  
			  //Fade in the results.
			  delay += 200;
			  dojo.fadeIn({node:li}).play(delay);          
			  done.length+=1;
			  done[done.length-1] = title;
		  }
        });
      }
    });
}

function unique(a) {
	tmp = new Array(0);
	for(i=0;i<a.length;i++){
		if(!contains(tmp, a[i])){
			tmp.length+=1;
			tmp[tmp.length-1]=a[i];
		}
	}
	return tmp;
}

function contains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}
