//=============================================================
//	bookmarkFix() : 
//  Creates querystring values from form values and submits 
//  form. Added querystrings are used in bookmarking process to
//  add direct links to db query results.
//=============================================================
function bookmarkFix(){
	var p = document.selectSection.pgStart.value;
	var c = document.selectSection.client.value;
	var k = document.selectSection.industry.value;
	
	var s = document.selectSection.searchField.value;
	var so = document.selectSection.sortID.value;
	
	c = cleanString(c," ");
	
	if(s.indexOf("+") != -1){
		s = cleanString(s,"+");
	}else if(s.indexOf("&") != -1){
		s = cleanString(s,"&");
	}else if(s.indexOf(" and ") != -1){
		s = cleanString(s," and ");
	}else if(s.indexOf(" AND ") != -1){
		s = cleanString(s," AND ");
	}else if(s.indexOf(" or ") != -1){
		s = cleanString(s," or ");
	}else{
		s = cleanString(s," ");
	}
	
	document.selectSection.client.value = c;
	document.selectSection.searchField.value = s;
	
	document.selectSection.action = "list.asp?p=" + p + "&c=" + escape(c) + "&k=" + k + "&s=" + escape(s) + "&so=" + so;
	document.selectSection.submit();
}

//=============================================================
//	setNext() : 
//  Calculates what portion of recordset should be shown when
//  next is clicked, sets form values, then calls
//  bookmarkFix() to submit the query.
//=============================================================
function setNext(){
	if(document.selectSection.pgStart.value != ""){
		var FirstElement = parseInt(document.selectSection.pgStart.value);
		document.selectSection.pgStart.value = FirstElement + 15;
	}else{
		document.selectSection.pgStart.value = 16;
	}
	
	bookmarkFix();
}

//=============================================================
//	setPrevious() : 
//  Calculates what portion of recordset should be shown when
//  previous is clicked, sets form values, then calls
//  bookmarkFix() to submit the query.
//=============================================================
function setPrevious(){
	if(document.selectSection.pgStart.value != ""){
		var FirstElement = parseInt(document.selectSection.pgStart.value);
		document.selectSection.pgStart.value = FirstElement - 15;
	}else{
		document.selectSection.pgStart.value = 0;
	}
	
	bookmarkFix();
}

//=============================================================
//	selectFilter(which) : 
//  Reads the value of the select menu or text field that has 
//  been used as the search criteria, changes form field values
//  then calls bookmarkFix() to submit the query.
//=============================================================
function selectFilter(which){
	
	var indVal = "";
	var clientVal = "";
	var startVal = "";
	var searchVal = "";
	var reset = true;
	
	switch(which) {
		case "2":
			clientVal = document.selectSection.strClient.options[document.selectSection.strClient.selectedIndex].value;
			document.selectSection.strClient.selectedIndex != 0?reset = false:reset = true;
			break;
		case "3":
			if(document.selectSection.strIndustry.options[document.selectSection.strIndustry.selectedIndex].value != "0"){
				indVal = document.selectSection.strIndustry.options[document.selectSection.strIndustry.selectedIndex].value;
				reset = false;
			}else{
				reset = true;
			}
			break;
		case "5":
			searchVal = document.selectSection.searchField.value;
			indVal = "";
			clientVal = "";
			startVal = "";
			reset = false;
			break;
		default:
			break;
	}
			
	document.selectSection.sortID.value = '4';
	document.selectSection.pgStart.value = startVal;
	document.selectSection.industry.value = indVal;
	document.selectSection.client.value = clientVal;
	document.selectSection.searchField.value = searchVal;
	reset == false?bookmarkFix():void(0);
}

//=============================================================
//	sortCols(which) : 
//  Sets sortID value, then calls bookmarkFix() to submit
//  the query.
//=============================================================
function sortCols(which){
	
	document.selectSection.sortID.value = which;
	bookmarkFix();
}
