// JavaScript Document
function dirSet() {
		newInput('orgstatus','all');
		newInput('search','simple');
		newInput('mail','');
		newInput('phone','');
		newInput('department','null');
		newInput('showresults','yes');
		newInput('givenname','');
		newInput('surname','');
		document.searchform.action = "http://www.uoguelph.ca/directory/";
		document.searchform.commonname.value = document.searchform.q.value;
		document.searchform.method = "POST";
		document.getElementById('searchl1').setAttribute("class", "altsearch"); 
		document.getElementById('searchl2').setAttribute("class", "activesearch"); 
		document.getElementById('searchl3').setAttribute("class", "altsearch"); 						
		return false;
}
function libSet() {
		newInput('Search_Code','FT*');
		newInput('CNT','25');
		newInput('HIST','1');
		newInput('SL','none');
		newInput('DB','local');
		newInput('searchclass','catalogue');
		newInput('Search_Arg','');
		document.searchform.action = "http://www.lib.uoguelph.ca/components/search/trellis_search_processor.cfm";
		document.searchform.Search_Arg.value = document.searchform.q.value;		
		document.searchform.method = "POST";
		document.getElementById('searchl1').setAttribute("class", "altsearch"); 
		document.getElementById('searchl2').setAttribute("class", "altsearch"); 
		document.getElementById('searchl3').setAttribute("class", "activesearch"); 		
		return false;
}

function webSet() {
	 	clearInput('orgstatus');
		clearInput('search');
		clearInput('mail');
		clearInput('phone');
		clearInput('department');
		clearInput('showresults');
		clearInput('givenname');
		clearInput('surname');
		clearInput('Search_Code');
		clearInput('CNT');
		clearInput('HIST');
		clearInput('SL');
		clearInput('DB');
		clearInput('searchclass');
		clearInput('Search_Arg');
		document.searchform.action = action="http://www.uoguelph.ca/search/";
		document.searchform.method = "GET";
		document.getElementById('searchl1').setAttribute("class", "activesearch"); 
		document.getElementById('searchl2').setAttribute("class", "altsearch"); 
		document.getElementById('searchl3').setAttribute("class", "altsearch"); 				
		return false;
}

function dosearch() {
	if (document.searchform.rsearch[1].checked) {
		dirSet();
		if (document.searchform.q.value == '') { document.searchform.q.value = 'admission'; }
		document.searchform.commonname.value = document.getElementById('searchtext').value;
		document.searchform.submit();
		return false;
	} else if (document.searchform.rsearch[2].checked) {	
		libSet();
		document.searchform.Search_Arg.value = document.getElementById('searchtext').value;
		document.searchform.submit();
		return false;
	 }	else {
	 	webSet();
		if (document.searchform.q.value == '') { document.searchform.q.value = 'admission'; }
		window.location.href = submitto;
		return false;
	 }
}

function newInput(x,y) {
	if ( !(checkVar = document.getElementById(x) ) ) { 
		var myForm = document.getElementById('searchbox_011117603928904778939:tp3ks5ha2dw');
		var newField = document.createElement('input');
		myForm.appendChild(newField);
		newField.setAttribute('id', x);
	} else {
		var newField = document.getElementById(x);
	}
	newField.setAttribute('type','hidden');
	newField.setAttribute('name', x);
	newField.setAttribute('value', y);
}

function clearInput(x){
	if ( (checkVar = document.getElementById(x) ) ) { 
		var d = document.searchform;
  		var olddiv = document.getElementById(x);
  		d.removeChild(olddiv);
	}
}

function altSearch(){
document.writeln('<input name="rsearch" type="radio" value="cse" checked="checked" id="rsearcha" onclick="webSet();" /><label id="searchl1" for="rsearcha" class="activesearch"><span><a href="#" onclick="document.searchform.rsearch[0].click(); webSet(); return false;">Web</a></span></label><input name="rsearch" type="radio" value="directory" id="rsearchb" onclick="dirSet();" /><label id="searchl2" for="rsearchb"><span><a href="#" onclick="document.searchform.rsearch[1].click(); dirSet(); return false;">Directory</a></span></label><input name="rsearch" type="radio" value="library" id="rsearchc" onclick="libSet();" /><label id="searchl3" for="rsearchc"><span><a href="#" onclick="document.searchform.rsearch[2].click(); libSet(); return false;">Library</a></span></label>');
}
