function doSearch(path) {
	var searchCategory = document.getElementById("searchCategory").value;
	var searchValue = document.getElementById("searchValue").value;
	searchValue = replace(searchValue,"&","µ");
	
	var cboCategory = document.getElementById("searchCategory");
	var categoryName = cboCategory.options[cboCategory.options.selectedIndex].text;
	createPostForm('filter=true&searchCategory='+searchCategory+'&searchValue='+searchValue+'&categoryName='+categoryName,path+'/ItemServlet');	
}

function replace(text,s1,s2){
	return text.split(s1).join(s2);
}

function checkValue(txtValue){
	if (txtValue.value=="Enter Keyword"){
		txtValue.value='';
	}
}

//submits Form on Enter
function submitForm(myfield,e,path){
	var keycode;
	if (window.event){
		keycode = window.event.keyCode;
	}else if (e){ 
		keycode = e.which;
	}
	if (keycode == 13){
	   doSearch(path);
	}
}

function createPostForm(params,URL,newWindowParams){

	// DB doesnt like % signs generated by browsers html escaped strings.
	var htmlSpacesRegExp = /%20/g;
	var htmlSlashRegExp = /%2F/g;
	var htmlAmpersandRegExp = /%26/g;
	params = params.replace(htmlSpacesRegExp," ");
	params = params.replace(htmlSlashRegExp, "/");

	// Ok we gotta work around it	
	var paramList = params.split("&");
	
	if (paramList.length==0){
		return ; // nothing to do.
	}
	
	var formURL = URL;

	// Find or create the form and set some defaults
	var hForm = document.getElementById("helperForm");
	if (hForm==null) {
		hForm = document.createElement("form");
		hForm.setAttribute("name","helperForm");
		hForm.setAttribute("id","helperForm");
      	hForm.setAttribute("method","POST");
	}
	if (newWindowParams!=null) {
		// Holder var for new window
		var newW = window.open("","newWindow",newWindowParams);
		hForm.target = "newWindow";
	}
	// Clear anything we may have from a previous call.
	hForm.innerHTML=""; 
    hForm.setAttribute("action",formURL);
	document.body.appendChild(hForm);

	// Attach input elems, we know they are divided by &'s. First part is the name, then value.	
	for(i in paramList){
		var currElem = paramList[i].replace(htmlAmpersandRegExp,"&").split("=");
		var element = document.createElement("input");
		var useTextArea = false;
		if (currElem[0]=="htmlPreview"){
			useTextArea = true;
			element = document.createElement("TEXTAREA");
		    currElem[1] = replace(currElem[1],"Ø","=");
		    currElem[1] = replace(currElem[1],"µ","&");
		} else if (currElem[0]=="searchValue"){
			currElem[1]=replace(currElem[1],"µ","&");
		}	
		element.setAttribute("name",currElem[0]);
		if (useTextArea) {
			//similar to textarea.innerHtml = value
			element.appendChild(document.createTextNode(currElem[1]));
			element.style.display = "none";
		} else {
			element.setAttribute("value",currElem[1]);
			element.setAttribute("type","hidden");
		}
		hForm.appendChild(element);
	}
	// There they go!
	hForm.submit();	
}