

/* This is refine_search.sajax.js */

/* Quick search is in refine_search.inc.php */

/* Sajax functions for refine search dialog */
var currentId = 0;
var newSearchGroup = 0;
var userKey = 0;
var lastColorSearch = '';
var lastRowClass = ''; //The className for the last row clicked, so we can change back to it when user clicks another row
var showButtonValue = 0;
var gKey = 0;
var lastgID = 0;
var w =0;
var tryAgain = 0; //UpdateSearch sanity check failed, so don't submit search.


function updateSearch() {
	/* Save changes from refine search form 
		This one flashes the changed row green after update */
	if (!document.getElementById("termTable")) {

		ret = new Array("",document.getElementById("groupName").innerText);
		displaySavedSearchGroup(ret);
	}
		
	var values1,match_type, search_type, starts, title,mailMe,show,small_bus_check,limit,est_val,recentVal,mustInclude,tdp_check,crit_check,line_check,disadv_check,expiresInCheck,expiresIn;
	expiresInCheck = 0;
//	date_search_val = 0;
	small_bus_check = 0;
	expiresInCheck = 0;
	disadv_check = 0;
	crit_check = 0;
	line_check = 0;
	if (document.all) {
		values1 = document.getElementById("values").innerText;
	}else{
		values1 = document.getElementById("values").value;	 //textContent
//		alert(values1)
//		document.getElementById("values").textContent = "dickdick"		
	}
	if (!values1) {
		alert("Please enter some search terms first!");
		return;
	}
	if (document.getElementById("type0").checked) {search_type = 0;}	//and or not
	if (document.getElementById("type1").checked) {search_type = 1;}

	if (document.getElementById("type2").checked) mustInclude = 0;	//May or Must include
	if (document.getElementById("type3").checked) mustInclude = 1;		

	if (document.getElementById("exact").checked) {match_type = "exact";}
	if (document.getElementById("starts").checked) {match_type = "starts";}	
	if (document.getElementById("contains").checked) {match_type = "contains";}

	category = -1;
	if (document.getElementById("cat0").checked == true) category = 0;
	if (document.getElementById("cat1").checked == true) category = 1;
	if (document.getElementById("cat2").checked == true) category = 2;
	if (document.getElementById("cat3").checked == true) category = 3;
	if (document.getElementById("cat4").checked == true) category = 4;
	if (document.getElementById("cat5").checked == true) category = 5;
	if (document.getElementById("cat8").checked == true) category = 8;							
	if (document.getElementById("cat9").checked == true) category = 9;	
	if (document.getElementById("cat10").checked == true) category = 10;	
	if (category == -1) {alert("Please select a category");tryAgain=1;return false;}
	tryAgain = 0;
	
	if (showButtonValue == 0) show="";
	if (showButtonValue == 1) show="today";
	if (showButtonValue == 2) show="recent";		
	if (showButtonValue == 3) show="date_search";		
	if (document.getElementById("date_search_val").value) date_search_val=document.getElementById("date_search_val").value;
//	sortIndex = document.getElementById("sort").selectedIndex;		
//	sortValue = document.getElementById("sort").options[sortIndex].value; // Got rid of sort in the dialog.  Users can sort by clicking the field heading in the display.

	limitIndex = document.getElementById("limit").selectedIndex;
	limit = document.getElementById("limit").options[limitIndex].value;
	
	valIndex = document.getElementById("est_val").selectedIndex;
	est_val = document.getElementById("est_val").options[valIndex].value;
	
	recentVal = document.getElementById("recentVal").value;

	if (document.getElementById("small_bus").checked) small_bus_check = 1;
	if (document.getElementById("tdp_check").checked) tdp_check = 1;	
	if (document.getElementById("disadv_check").checked) disadv_check = 1;	
	if (document.getElementById("crit_check").checked) crit_check = 1;		
//	if (document.getElementById("line_check").checked) line_check = 1;			
	
	if (document.getElementById("expiresInCheck").checked) expiresInCheck = 1;	
	if (document.getElementById("expiresIn").value) expiresIn = document.getElementById("expiresIn").value;	
	
	if (currentId) {
		idNumber=currentId;
	}else{
		idNumber="new";		

		if (newSearchGroup) {
			title = document.getElementById("showNewNameText").value;

			
			if (document.getElementById("mailMeNew").checked) { 
				mailMe = 'Y';
			} else {
				mailMe = 'N';
			}
		}
		
	}			
	values1 = encodeURIComponent(values1)
	x_updateSearch(values1,match_type,search_type,category,idNumber,title,mailMe,show,limit,date_search_val,sortValue,small_bus_check,expiresInCheck,expiresIn,tdp_check,crit_check,line_check,disadv_check,est_val,recentVal,mustInclude,gKey,updateComplete);
}

function updateComplete(ret) {

//	alert(document.getElementById("row_"+lastRowNum).style.backgroundColor)
//	return;
	/* add the row to the list of searches at the top of the refine search dialog */
	
//	lastRowNum = lastRowNum +  ret[7];
	if (!ret[7]){
		if (lastRowNum) {document.getElementById("row_"+lastRowNum).style.backgroundColor = "lime";document.getElementById("row_"+lastRowNum).style.color = "black";}
		if (lastRowNum) window.setTimeout('document.getElementById("row_"+lastRowNum).style.backgroundColor = "#78BDF6";document.getElementById("row_"+lastRowNum).style.color = "#ECEEEE"',650);
	}
	id_number = ret[0];
	if (ret[8]) {
		gKey = ret[8];		
		lastgID = gKey;
	}
	tbl = document.getElementById("termTable");	
//	alert(tbl.getElementsByTagName("tbody")[0]);
	if (tbl.rows[1]) {	
		if (tbl.rows[1].innerHTML == "<TD align=middle colSpan=6>Enter search terms and click 'Add To Search Group'</TD>" || tbl.rows[1].innerHTML == '<td colspan="6" align="center">Enter search terms and click \'Add To Search Group\'</td>') {tbl.deleteRow(1);}
	}
	

	vals = ret[1];
	if (ret[4] == "0") {
		SearchType = "Add";
	}else{
		SearchType = "Not";	
	}
				
	if (!currentId) {
		/* If there's no currentId, then it's a new row, so add it to the table */ 
		
		
		if (document.all) {
			len = tbl.rows.length;
			oRow = tbl.insertRow(-1);			
			oRow.style.backgroundColor = "#CED9E7";
			oRow.id = "row_"+len;
			oRow.className = "searchGroupRows";
			oRow.style.align = "left";
			oCell = oRow.insertCell();
			oCell.innerHTML = len;									
			oCell.align = "left";
			oCell = oRow.insertCell();
			oCell.innerHTML = ret[2];		//Search Type
			oCell.align = "left";
			oCell = oRow.insertCell();
			oCell.innerHTML = SearchType;  //Add or Not
			oCell.align = "left";
			oCell = oRow.insertCell();
			oCell.innerHTML = vals;
			oCell.align = "left";
			oCell = oRow.insertCell();
			oCell.innerHTML = "<a href='javascript:getSavedSearch(" + id_number + "," + len + ")' class=terms>Edit</a>";		
			oCell.align = "right";
			oCell = oRow.insertCell();
			oCell.innerHTML = "<a href='javascript:dumpSearch(" + id_number + "," + len + ")' class=terms>Delete</a>";									
			oCell.align = "right";
		}else{
			len = tbl.rows.length;
			oRow = document.createElement('TR');
			oRow.style.backgroundColor = "#CED9E7";
			oRow.id = "row_"+len;
			oRow.className = "searchGroupRows";
			oRow.style.align = "left";
			oCell = document.createElement('TD');
			oCell.innerHTML = len;									
			oCell.align = "left";
			oRow.appendChild(oCell);		
			oCell = document.createElement('TD');
			oCell.innerHTML = ret[2];		//Search Type
			oCell.align = "left";
			oRow.appendChild(oCell);				
			oCell = document.createElement('TD');
			oCell.innerHTML = SearchType;  //Add or Not
			oCell.align = "left";
			oRow.appendChild(oCell);						
			oCell = document.createElement('TD');		
			oCell.innerHTML = vals;
			oCell.align = "left";
			oRow.appendChild(oCell);				
			oCell = document.createElement('TD');
			oCell.innerHTML = "<a href='javascript:getSavedSearch(" + id_number + "," + len + ")' class=terms>Edit</a>";		
			oCell.align = "right";
			oRow.appendChild(oCell);						
			oCell = document.createElement('TD');
			oCell.innerHTML = "<a href='javascript:dumpSearch(" + id_number + "," + len + ")' class=terms>Delete</a>";									
			oCell.align = "right";
			oRow.appendChild(oCell);	
			tbl.appendChild(oRow);							
		}

	}else{
		/* If it's an update then update the display to reflect the new search details */ 
		
		
		tbl.rows[lastRowNum].cells[1].innerHTML = ret[2];
		tbl.rows[lastRowNum].cells[2].innerHTML = SearchType;
		tbl.rows[lastRowNum].cells[3].innerHTML = ret[1];	
	}
	if (document.all) {
		document.getElementById("values").innerHTML = "";	
	}else{

		document.getElementById("values").value = "";	
	}
	currentId = 0;	
}


function updateSearchTitle(gKey,title) {
	x_updateSearchTitle(gKey,title,doNothing);
}

function displaySearchValues(values,isGroup) {
	/* Select appropriate form values for refine search */
//	document.getElementById("values").innerText = values[0][0];
	for (i in values) {
//		document.getElementById("values").innerText = document.getElementById("values").innerText + " - " +values[i][0] + "\n";

		if (values[i][0] == "match") {
			/* Clear out match background colors */
			m=document.getElementById('match0');m.style.color='#585240';m.style.backgroundColor='#CED9E7';
			m=document.getElementById('match1');m.style.color='#585240';m.style.backgroundColor='#CED9E7';
			m=document.getElementById('match2');m.style.color='#585240';m.style.backgroundColor='#CED9E7';		
			if (values[i][1] == "exact") {document.getElementById("exact").checked = true;m=document.getElementById("match0");m.style.backgroundColor = "#78BDF6";m.style.color="#F1F1F1"}
			if (values[i][1] == "starts") {document.getElementById("starts").checked = true;m=document.getElementById("match1");m.style.backgroundColor = "#78BDF6";m.style.color="#F1F1F1"}
			if (values[i][1] == "contains") {document.getElementById("contains").checked = true;m=document.getElementById("match2");m.style.backgroundColor = "#78BDF6";m.style.color="#F1F1F1"}
		}
		if (values[i][0] == "type") {
			if (values[i][1] == "0") {document.getElementById("type0").checked = true;selectSearchTypeColor(0);}
			if (values[i][1] == "1") {document.getElementById("type1").checked = true;selectSearchTypeColor(1);}
		}
		if (values[i][0] == "must_include") {
			if (values[i][1] == "0") {document.getElementById("type2").checked = true;selectMayMustColor(0);}
			if (values[i][1] == "1") {document.getElementById("type3").checked = true;selectMayMustColor(1);}
		}
		
		/* Group Preferences */
		
		if (isGroup) {
			if (values[i][0] == "recent") {
				 document.getElementById("recentVal").innerText = values[i][1];
			}
			if (values[i][0] == "limit") {
				if (values[i][1] == "25") document.getElementById("limit").selectedIndex = 0;
				if (values[i][1] == "50") document.getElementById("limit").selectedIndex = 1;
				if (values[i][1] == "100") document.getElementById("limit").selectedIndex = 2;						
				if (values[i][1] == "500") document.getElementById("limit").selectedIndex = 3;									
				if (values[i][1] == "1000") document.getElementById("limit").selectedIndex = 4;					
			}
			
			if (values[i][0] == "show") {
				if (values[i][1] == "") document.getElementById("show0").checked = true;
				if (values[i][1] == "today") document.getElementById("show1").checked = true;
				if (values[i][1] == "recent") document.getElementById("show2").checked = true;		
				if (values[i][1] == "date_search") document.getElementById("dateSearchButton").checked = true;					
								
			}
			if (values[i][0] == "sort") {
				if (values[i][1] == "NSN") document.getElementById("sort").selectedIndex = 0;
				if (values[i][1] == "Solicitation_No") document.getElementById("sort").selectedIndex = 1;
				if (values[i][1] == "Description") document.getElementById("sort").selectedIndex = 2;
				if (values[i][1] == "Part_No") document.getElementById("sort").selectedIndex = 3;
				if (values[i][1] == "Due_Date") document.getElementById("sort").selectedIndex = 4;
				if (values[i][1] == "Issue_Date") document.getElementById("sort").selectedIndex = 5;
			}
			if (values[i][0] == "small_bus_check") {
				if (values[i][1] == "1") document.getElementById("small_bus").checked = true;
			}
			if (values[i][0] == "tdp_check") {
				if (values[i][1] == "1") document.getElementById("tdp_check").checked = true;
			}		
			if (values[i][0] == "crit_check") {
				if (values[i][1] == "1") document.getElementById("crit_check").checked = true;
			}		
			if (values[i][0] == "line_check") {
//				if (values[i][1] == "1") document.getElementById("line_check").checked = true;
			}		
			if (values[i][0] == "disadv_check") {
				if (values[i][1] == "1") document.getElementById("disadv_check").checked = true;
			}		
	
			if (values[i][0] == "expiresInCheck") {
				if (values[i][1] == "1") document.getElementById("expiresInCheck").checked = true;
			}		
			if (values[i][0] == "expiresIn") {
				 document.getElementById("expiresIn").checked = values[i][1];
			}		
			if (values[i][0] == "est_val") {
				document.getElementById("est_val").selectedIndex = 19;
//				alert(values[i][1])
//				if (values[i][1] == "more_100") document.getElementById("est_val").selectedIndex = 1;
				if (values[i][1] == "more_500") document.getElementById("est_val").selectedIndex = 2;
				if (values[i][1] == "more_1000") document.getElementById("est_val").selectedIndex = 3;
				if (values[i][1] == "more_5000") document.getElementById("est_val").selectedIndex = 4;
				if (values[i][1] == "more_10000") document.getElementById("est_val").selectedIndex = 5;
				if (values[i][1] == "more_100000") document.getElementById("est_val").selectedIndex = 6;
				if (values[i][1] == "more_5000000") document.getElementById("est_val").selectedIndex = 7;
				if (values[i][1] == "less_100") document.getElementById("est_val").selectedIndex = 8;
				if (values[i][1] == "less_500") document.getElementById("est_val").selectedIndex = 9;
				if (values[i][1] == "less_1000") document.getElementById("est_val").selectedIndex = 10;
				if (values[i][1] == "less_5000") document.getElementById("est_val").selectedIndex = 11;
				if (values[i][1] == "less_10000") document.getElementById("est_val").selectedIndex = 12;
				if (values[i][1] == "less_100000") document.getElementById("est_val").selectedIndex = 13;
					if (values[i][1] == "less_5000000") document.getElementById("est_val").selectedIndex = 14;
			}
		
	//		if (values[i][0] == "recentVal") {
	//			document.getElementById("recentVal").value = values[i][1];
	//		}
				
		}

	}

}

function selectSearchTypeColor(val) {
	/* Background color for search type radio buttons */
	
	if (!val) {
		m=document.getElementById("withCell");
		m.style.backgroundColor = "#78BDF6";
		m.style.color="#f1f1f1";
		m=document.getElementById("withoutCell");
		m.style.backgroundColor="";
		m.style.color="#ECEEEE";
		document.getElementById('type2').disabled = '';		
		document.getElementById('type0').checked = 'true';		
	}else{	
		document.getElementById('type1').checked = 'true';	//Check radio button of user clicks the TD next to it.
		document.getElementById('type3').checked = 'true'; //Check Must include for reason below
//		document.getElementById('type2').disabled = 'true';	//Disable May include, because it doesn't make sense to have a without / may include
		selectMayMustColor(1);//Disable May include, because it doesn't make sense to have a without / may include
		m=document.getElementById("withoutCell");
		m.style.backgroundColor = "#78BDF6";
		m.style.color="#f1f1f1";
		m=document.getElementById("withCell");
		m.style.backgroundColor="";
		m.style.color="#ECEEEE";
	}
}


function selectMayMustColor(val) {
	/* Background color for may or must include radio buttons */
	if (!val) {
		m=document.getElementById("mayCell");m.style.backgroundColor = "#78BDF6";m.style.color="#f1f1f1";
		m=document.getElementById("mustCell");m.style.backgroundColor="";m.style.color="#585240";
		document.getElementById("type2").checked = true;		
//		alert("bzbzbz")
	}else{
		m=document.getElementById("mayCell");m.style.backgroundColor="";m.style.color="#585240";
		m=document.getElementById("mustCell");m.style.backgroundColor = "#78BDF6";m.style.color="#f1f1f1";		
		document.getElementById("type3").checked = true;
	}
}

function checkMayMust() {
	if (document.getElementById("type1").checked == true) {
		if (document.getElementById("type2").checked == true) {
//			alert("type1:"+document.getElementById("type1").checked+"\ntype2:"+document.getElementById("type2").checked)
			m=document.getElementById("mayCell");m.style.backgroundColor="";m.style.color="#ECEEEE";
			m=document.getElementById("mustCell");m.style.backgroundColor = "#78BDF6";m.style.color="#f1f1f1";		
			document.getElementById("type3").checked = true;		
			alert("A May include, without (-) search would not filter any results, and is not permitted");
			return;
		}
	}
}

function displaySearchElements(elements) {
	/* Propagate form with saved search elements */
		
	document.getElementById("values").value = elements[0];  //linefeed delimited element list
	document.getElementById("cat"+elements[1]).checked = true;
	changeCatColor(elements[1]);
	return;
	for (i in elements) {
		for (dick=0;dick<i.length;dick++) {
			document.getElementById("values").value = document.getElementById("values").value + elements[i][dick] + "\n";
		}
	}
}



lastRowNum = 0;
function getSavedSearch(id_number,rownum) {
	/* Load a saved search into refine search dialog */
	
	currentId = id_number;
	rN = document.getElementById("row_"+rownum);
	x_getSearchValues(id_number, displaySearchValues);	
	x_getSearchElements(id_number, displaySearchElements);	
	if (document.all) {
		updateButton.innerText = "Update search group";
	}else{
		updateButton.textContent = "Update search group";
	}
//	document.getElementById("newSearchLink").style.visibility = "visible";
	if (lastRowNum) {
		document.getElementById("row_"+lastRowNum).style.backgroundColor = "#CED9E7";
		document.getElementById("row_"+lastRowNum).style.color = "#585240";	
	}
	lastRowNum = rownum;

//	rN.className = "dataRowBlue";
	rN.className = "searchGroupHoes";
	rN.style.backgroundColor = "#78BDF6";//#78BDF6, #B9E3F1, #4299C6
	rN.style.color = "#F1F1F1";	//#ECEEEE
}

function getSavedSearchGroup(gID) {
	x_getSavedSearchGroup(gID,displaySavedSearchGroup);
}

var notSearchNumber = 0; //What search row # is the global not search if it exists
function displaySavedSearchGroup(ret) {
	/* Display results from getSavedSearchGroup */ 

//	document.getElementById("test").innerTEXT = document.getElementById("test").innerTEXT + ret[0];
	sL = document.getElementById("searchList");
	tmp = "<table border=0 callpadding=2 cellspacing=1 width=505 class=refine_search_toptable id=termTable><tr><td align=left>#</td><td align=left>CATEGORY</td><td align=left>TYPE</td><td align=left>VALUES</td><td align=right>EDIT</td><td align=right width=25>DELETE</td></tr>";
	tmp += ret[0];
	tmp += "</table>";
//	alert(tmp)
//	alert(ret[0])
	sL.innerHTML = tmp;


	gName = document.getElementById("groupName");
	gName = 1;	
	if (gName) {
		gName.innerHTML = ret[1];
		displaySearchValues(ret[2],1);
	}

	notSearchNumber = ret[5];
//	alert(notSearchNumber);
	/* This is where we open the last search the user viewed */
	if (!bid_search) {
		getSavedSearch(ret[3],ret[4]); //Load last search edited
	}
	nD = document.getElementById("narrowDiv");

	var slideRefineSearch = new slide;
//	slideRefineSearch.setMyDiv(nD);  /* It's a shame to see this go */
}



function dumpSearch(id_number,rownum) {
	/* Verify that user wants to dump search from group */
	
	rowObj = document.getElementById("row_"+rownum);
	lastRowObj = document.getElementById("row_"+lastRowNum);
	tempBgColor = rowObj.style.backgroundColor;
	tempColor = rowObj.style.color;
//	lastTempBgColor = lastRowObj.style.backgroundColor;

//	lastTempColor = lastRowObj.style.color;

	if (lastRowNum) {
		lastRowObj.style.backgroundColor = "#CED9E7";
		lastRowObj.style.color = "#585240";		
	}
	lastRowNum = rownum;

	rowObj.style.backgroundColor = "red";	
	if (confirm("Really Delete this item?")) {
		x_deleteSearch(id_number,doNothing);

		if (document.all) {
			document.getElementById("values").innerText = "";	
		}else{
			document.getElementById("values").textContent = "";	
		}
		currentId = 0;		
		tbl = document.getElementById("termTable");
		tbl.deleteRow(rownum);
		lastRowNum--;
	}else {
		if (lastRowNum) {
			rowObj.style.backgroundColor = tempBgColor;
//			document.getElementById("row_"+lastRowNum).style.backgroundColor = "#DED4B9";//#ECCC7A
//			rowObj.style.color = "#585240";						
			rowObj.style.color = tempColor;						
		}
	}
}

function dumpSearchGroup(g,gID) {
	/* Deletes search group from database */
	
	document.getElementById("tbl_"+g).style.backgroundColor = 'red';
	if (confirm("Really Delete this item?")) {		
		x_deleteGroup(g,gID,removeSearchGroup);
	}else{
		document.getElementById("tbl_"+g).style.backgroundColor = '#F2F8FB';	
	}
}

function removeSearchGroup(g) {
	/* Removes search group from display */
	document.getElementById("tbl_"+g).style.display = "none";
}

function useNotListUpdate(val) {
	if (val == 1) { 
		document.getElementById("notListLED").src = '../images/green_led.jpg';
		document.getElementById("notListLED").alt = "Click to deactivate global NSN not list for this search";
	}else{
		document.getElementById("notListLED").src = '../images/red_led.jpg';		
		document.getElementById("notListLED").alt = "Click to activate global NSN not list for this search";		
	}
}

function doNothing() {
	//dummy function for mandatory response to sajax call
}
function displayResults() {
	tbl = document.getElementById("termTable");	
//	if (tbl.rows[1].innerHTML == "<TD align=middle colSpan=6>Enter search terms and click 'Add To Search Group'</TD>"){
	if (document.getElementById("values").innerText || document.getElementById("values").value) {	

		/* Todo: what if the user adds more than one search to the group? */ 

		updateSearch()
		if (!tryAgain) window.setTimeout('location.href = "/include/bid_frameset.php?g="+lastgID+"&w="+cW;',800);
	}else{
		location.href = "/include/bid_frameset.php?g="+lastgID+"&w="+cW;
	}

}

  ///////////////////
 //  Preferences  //
///////////////////

/* Field Preferences */

function getFieldPref(uKey) {
	userKey = uKey;
	x_getFieldNames(uKey,displayPreferences);	/* anything with an x_ in the function name is in refine_search_sajax.php */
}
fP = '';
displayNewFP = 0;
function displayPreferences(ret) {
//	fP = document.getElementById("field_pref");  /* This was used to cache results so Sajax doesn't have to get them every time, but was removed because FF JS checks the mirrored copy, making the displayed one un-checked */
	pP = document.getElementById("prefPage");	
	displayNewFP = 1;
//	if (fP) return; 
//	alert(ret[0][0]);
	columns = ret[0];
//	alert(columns[1][0])
	userFields = ret[1];
	userFieldCount = ret[2];
	totalBidFields = ret[3];
	b=0;
	tbl = "<BR><table border=0 cellpadding=1 cellspacing=1 width=560 align=center class=termTable2 style='border:2px ridge #585240'>";
	tbl+= "<tr class=darkRow><td colspan=3 align=center><B>Display The Following Fields</td></tr>";
	tbl1 = '<div class="workarea"><h3>My Fields (drag / drop)</h3><ul id="ul2" class="draglist">';	
	tbl2 = '<div class="workarea"><h3>Available Fields</h3><ul id="ul1" class="draglist">';
	tbl3 = '<div class="workarea"><h3>Available Fields</h3><ul id="ul3" class="draglist">';	

	

	for (i=0;i<totalBidFields;i++) {
		if (b==0) tbl+= "<tr>";
		tbl+= "<td align=left bgcolor=#CED9E7><input type='checkbox' id='" + columns[i][0] + "' onchange='saveFieldPref(this)' name='" + columns[i][0] + "'>" + columns[i][0] + "</td>";
		if (i < 22) tbl2+= "<li class='list1' id='li1_" + (i+1) + "'>" + columns[i][0] + "</li>";
		if (i >= 22) tbl3+= "<li class='list1' id='li3_" + (i-19) + "'>" + columns[i][0] + "</li>";		
		b++;
		if (b>2) {b=0;tbl+= "</tr>";}

	}
	tbl += "</table>";
	tbl2 += "</ul></div>";
	tbl3 += "</ul></div>";	

	pP.innerHTML = tbl;


	
	for (i=0;i<userFieldCount;i++) {
//		 document.getElementById(userFields[i][1]).checked = 'true';
		 tbl1+= "<li class='list2' id='li2_" + (i+1) + "'>" + userFields[i] + "</li>";
	}
	tbl1 += "</ul></div>";	
//	alert(displayNewFP)
	if (displayNewFP) pP.innerHTML = "<div style='display:block'>"+tbl1+tbl2+tbl3+"</div>";	

}
function saveFieldPref(fieldName) {
	if (fieldName.checked) {
		checked = 1;
	}else{
		checked = 0;
	}
	x_updateFieldName(userKey,fieldName.name,checked,doNothing2);
}

/* Get and set preferences */

function getPref(name) {
	/* Get preference and adjust radio buttons or checkboxes */
	x_getPrefSajax(name,returnPref);
}

function getPrefSelect(name) {
	/* Get preference and adjust a select */
	x_getPrefSajax(name,returnPrefSelect);
}

function setPref(name,value) {
	x_setPrefSajax(name,value,returnPref);
}

function returnPref(ret) {
	if (ret) updateElementCheck(ret[0],ret[1])
}

function returnPrefSelect(ret) {
//	alert("'"+ret[0]+"' - " +ret[1]);
		
//	 	itemName = document.getElementById('dispBidsLoc');
	
		itemName = document.getElementById(ret[0]);	
		
//		alert(itemName);
		itemName.selectedIndex = ret[1];
//		itemName.selectedIndex = 1;
}






var gnDisplay = 0;
function changeGroupName(g) {
	if (!gnDisplay) {
		gn = document.getElementById('groupName');
		temp = gn.innerText;
		txtInput = "<input type=text size=35 onchange='updateGroupName(this.value,"+g+")' value='"+temp+"'>";
		gn.innerHTML = txtInput;
		gnDisplay = 1;		
	}
}

function updateGroupName(val,g) {
	x_saveGroupName(g,val,doNothing2)
	gn = document.getElementById('groupName');
	gn.innerHTML = val;
	gnDisplay = 0
}

function update_showpage(div,val) {
	setPref(div,val);
}
/*
function nextPage(div,val) {
	
}*/


function save_session(sKey,val) {
	x_save_session(sKey,val,doNothing);
}

function doNothing2(ret) {
	if (ret) alert(ret);
}

var cW; // Client Width
var cH; // Client Height
function getClientWindowSize() {
	if (self.innerHeight) // all except Explorer
	{
		cW = self.innerWidth;
		cH = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		cW = document.documentElement.clientWidth;
		cH = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		cW = document.body.clientWidth;
		cH = document.body.clientHeight;
	}
	w = cW;
}
getClientWindowSize();

function nextPage(div,search,skip,qS) {
	// x_nextPage is often called directly from displayObject
//	alert(div +"\n" + search + "\n" + skip);
	x_nextPage(div,search,skip,qS,displayNextPage);
}


function displayNextPage(ret) {	
	var tmp = ret[0];
//	alert(tmp);
//	tmp = "qsOutputReplace" //document.getElementById('qsOutputReplace').innerHTML;
	document.getElementById(tmp).innerHTML = ret[1];
}

/* End refine_search.sajax.js */

