// JavaScript Document// CED Accreditation Search
// Adapted from ced Search Library
// library for using the Google Custom Search Engine
// requires common.js

if(!window.ced){
	window.ced = new Object(); // instantiate namespace object if it doesn't exist already
}

if(window.ced){
	window.ced.googleCSE = new Object();
	window.ced.googleCSE.boxID = 'googlesearchbox'
	window.ced.googleCSE.cx = '003079700105612375887:6nbu7xd8ug8'
	window.ced.googleCSE.resultsURL = 'http://www.lazoo.org/search/index.html'
	window.ced.googleCSE.boxSize = 40
	window.ced.googleCSE.resizeIFrame = true
	window.ced.googleCSE.iFrameHeight = '85em'
	window.ced.googleCSE.iFrameWidth = '100%'
	window.ced.googleCSE.headerSearchBox = new Object();
	window.ced.googleCSE.headerSearchBox.doRewrite = false; // off by default
	window.ced.googleCSE.headerSearchBox.formid = 'content_searchtools'

	if(document.getElementById){
		addEvent(window,'load',insertSearchBox)
		addEvent(window,'load',rewriteHeaderSearchForm)
	}
}

function getSearchQuery(){
	// get the google search query term
	var s = ''
	if(window.location.search){
		var z = window.location.search.split('&')
		for(var i=0;i<z.length;i++){
			var x = z[i].split('=')
			x[0] = x[0].replace('?','');
			if (x[0]=='q'){ s = x[1]; break;  }
		}
	}
	s = unescape(s.replace(/\+/g,' '))
	// resize the results box 
	if(s==''){
		// no search term
		setResultsBoxSize(window.ced.googleCSE.iFrameWidth,'1em')
	}else{
		// search term exists
		setResultsBoxSize(window.ced.googleCSE.iFrameWidth,window.ced.googleCSE.iFrameHeight); 
	}
	return s
}

function setResultsBoxSize(w,h){
	var results = document.getElementsByTagName('iframe')
	if(results.length>0 && window.ced.googleCSE.resizeIFrame){
		results[0].style.width = w; 
		//results[0].style.height = h; 
	}
}


function buildSearchForm(){
	// create the form element
	// IE doesn't seem able to do this properly width DOM, so do it with innerHTML...
	// create the following form: 
	/* 
	<form id="searchbox_013231838821823520426:f4dg3j1yiy0" action="http://www.ced.csulb.edu/accreditation/search.html">
	  <input type="hidden" name="cx" value="003079700105612375887:6nbu7xd8ug8" />
	  <input name="q" type="text" size="40" />
	  <input type="submit" name="sa" value="Search" />
	  <input type="hidden" name="cof" value="FORID:11" />
	</form>
	*/
	var form = document.createElement('form')
	form.setAttribute('id','searchbox_'+window.ced.googleCSE.cx)
	form.setAttribute('action',window.ced.googleCSE.resultsURL)
	form.setAttribute('method','get')
	var input = document.createElement('span')
	input.innerHTML = '<input type="hidden" name="cx" value="'+window.ced.googleCSE.cx+'" />'
	form.appendChild(input);
	var input = document.createElement('span')
	input.innerHTML = '<input type="hidden" name="cof" value="FORID:11" />'
	form.appendChild(input);
	var input = document.createElement('span')
	input.className = 'gCSEtextfield'
	input.innerHTML = '<label for="q" class="hidden">Search: </label><input type="text" name="q" id="q" size="'+window.ced.googleCSE.boxSize+'" value="'+getSearchQuery()+'" />'
	form.appendChild(input);
	var input = document.createElement('span')
	input.innerHTML = '<input type="submit" name="sa" value="Search" />'
	form.appendChild(input);
	return form	
}

function insertSearchBox(){
	var hanger = document.getElementById(window.ced.googleCSE.boxID)
	if(hanger){
		var formContainer = document.createElement('div')
		var form = buildSearchForm()
		formContainer.appendChild(form)
		hanger.innerHTML = formContainer.innerHTML
	}
}

function rewriteHeaderSearchForm(){
	var form=null
	// rewrite the small searchbox in the header section
	if(document.getElementById && window.ced.googleCSE.headerSearchBox.doRewrite){ 
		form = document.getElementById(window.ced.googleCSE.headerSearchBox.formid) 
	}
	if(form){
//		alert('rewriting header search form')
		// build a reference form to pull from
		var ref = buildSearchForm()
		form.action = ref.action
		form.method = ref.method
		var inputs = form.getElementsByTagName('input')
		// make sure we have cof and cx fields
		var foundCOF = false; var foundCX = false;
		for(var i=0;i<inputs.length;i++){
			var node = inputs[i]
			if(node.getAttribute('name')=='cx'){ 
				node.value = ref.cx.value 
				foundCX = true;
			}
			if(node.getAttribute('name')=='cof'){ 
				node.value = ref.cof.value 
				foundCOF = true;
			}
			if(foundCOF && foundCX){ break; }
		}
		if(!foundCOF){ form.appendChild(ref.cof) }
		if(!foundCX){ form.appendChild(ref.cx) }
//	} else {
//		z = '//no header form found\nwindow.ced.googleCSE.headerSearchBox.formid=\n'
//		z += window.ced.googleCSE.headerSearchBox.formid
//		alert(z)
	}
}
<!-- Google Search Result Snippet Begins -->
  var googleSearchIframeName = "results_003079700105612375887:6nbu7xd8ug8";
  var googleSearchFormName = "searchbox_003079700105612375887:6nbu7xd8ug8";
  var googleSearchFrameWidth = 600;
  var googleSearchFrameborder = 0;
  var googleSearchDomain = "www.google.com";
  var googleSearchPath = "/cse";
<!-- Google Search Result Snippet Ends -->
          