//---------------------------------------------------------------------------
// Function used by searchbox.jsp to control form elements
//---------------------------------------------------------------------------
function Search() {
		
	// Get search property and term values from form elements
	var property 	= document.search_form.searchprop[document.search_form.searchprop.selectedIndex].value;
	var terms 	= encodeURIComponent(document.search_form.searchterms.value);
	terms = removeBad(terms);
	
	if(terms.indexOf("%20AND%20") != -1 || terms.indexOf("%20OR%20") != -1 || terms.indexOf("%20NOT%20") != -1 || terms.indexOf("(") != -1 ) {
		var mode = "matchboolean";	
	}else {
		var mode = document.search_form.searchmode.value;	
	}

	// Set the dimension root to search
	var newNval = "N="+document.search_form.dimensionID.value;
	
	var removeterms = ["N","Ne","No","Nao","Ntk","Ntt","D","Nty","Ntx","Dx","in_dym","in_dim_search","nppir","sqn","ssp"];
	var addterms;
	if(terms != "") {
		addterms = [newNval,"Ntk="+property,"Ntt="+terms,"Nty=1","D="+terms,"Ntx=mode+"+mode,"Dx=mode+"+mode];
	}else { 
		addterms = [newNval];
	}
	var newurl = ConstructURL("CURRENTURL", removeterms, addterms);
	location.href = "controller.jsp" + newurl;
}

function SearchWOptions() {
	// Process the submitted query and add 
	var url = document.search_form.url.value;
	if(document.search_form.dimensionID.value != "NA") {
		var newNval = "N="+document.search_form.dimensionID.value + "+";
		url = url.replace("N=",newNval);		
	}
	
	location.href = "controller.jsp?" + url;
}


//---------------------------------------------------------------------------
// Function used to control form elements and submit a subject search
//---------------------------------------------------------------------------
function SubjectSearch(e) {
		
	// Get search property and term values from form elements
	var terms 	= encodeURIComponent(e);
	terms = removeBad(terms);

	// Create new url with property search and dimension search
	var newUrl = "N=0&Ntk=Subject&Ntt="+terms+"&Nty=1&D="+terms+"&Ntx=mode+matchallpartial&Dx=mode+matchallpartial";
	location.href = "controller.jsp?" + newUrl;
}

//---------------------------------------------------------------------------
// Function used to control form elements and submit a subject search
//---------------------------------------------------------------------------
function TitleAuthorSearch(e) {
		
	// Get search property and term values from form elements
	var terms 	= encodeURIComponent(e);
	terms = removeBad(terms);

	// Create new url with property search and dimension search
	var newUrl = "N=0&Ntk=Title|Author&Ntt="+terms+"&Nty=1&D="+terms+"&Ntx=mode+matchallpartial&Dx=mode+matchallpartial";
	location.href = "controller.jsp?" + newUrl;
	
}


//---------------------------------------------------------------------------
// Function used to control form elements and submit a subject search
//---------------------------------------------------------------------------
function AuthorSearch(e) {
		
	// Get search property and term values from form elements
	var terms 	= encodeURIComponent(e);
	terms = removeBad(terms);

	// Create new url with property search and dimension search
	var newUrl = "N=0&Ntk=Author&Ntt="+terms+"&Nty=1&D="+terms+"&Ntx=mode+matchallpartial&Dx=mode+matchallpartial";
	location.href = "controller.jsp?" + newUrl;
}

//---------------------------------------------------------------------------
// Function used to control form elements and submit a subject search
//---------------------------------------------------------------------------
function KeywordSearch(e) {
	
	// Get search property and term values from form elements
	var terms 	= encodeURIComponent(e);
	terms = removeBad(terms);

	// Create new url with property search and dimension search
	var newUrl = "N=0&Ntk=Search All&Ntt="+terms+"&Nty=1&D="+terms+"&Ntx=mode+matchallpartial&Dx=mode+matchallpartial";
	location.href = "controller.jsp?" + newUrl;

	
}



