// 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";
		return false;
}
function libSet() {
		newInput('Search_Code','CMD*');
		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/search/trellis_search_processor.cfm";
		document.searchform.Search_Arg.value = document.searchform.q.value;		
		document.searchform.method = "POST";
		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.google.com/search/";
		document.searchform.method = "GET";
		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_009892788246971066521:5qs_wwtmkua');
		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);
	}
}
