function checkNumeric(stringValue){	
	var strValidChars = "0123456789";
  var strChar;
  var blnResult = true;

	var stringValue = new String(stringValue);
  if (stringValue.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < stringValue.length && blnResult == true; i++){
		strChar = stringValue.charAt(i);
    if (strValidChars.indexOf(strChar) == -1){
      blnResult = false;
		}
   }
   return blnResult;
}

function executeSearch(){	
	document.getElementById("emptySearchText").style.display = "none";
	
	var iBrandId = document.getElementById("selBrand").options[document.getElementById("selBrand").selectedIndex].value;
	var iCategoryId = document.getElementById("selCategory").options[document.getElementById("selCategory").selectedIndex].value;
	var iSubCategoryId = 0;	
	//set the price range
	var sPriceRange = document.getElementById("selPrice").options[document.getElementById("selPrice").selectedIndex].value;
	var aPriceRange = sPriceRange.split(",");	
	var iPriceFrom = aPriceRange[0];
	var iPriceTo = aPriceRange[1];	
	
	if(!checkNumeric(iPriceFrom)){
		return false;
	}
	if(!checkNumeric(iPriceTo)){
		return false;
	}	
	
	var sFreeText = document.getElementById("freeText").value;
	
	if(sFreeText == "TEXT SEARCH..."){
		sFreeText = "";
	}
	if(iCategoryId == "" && iBrandId == "" && sFreeText == ""){
		alert("Please select either a Category or a Brand.");
	}else{		
		//call the ajax function to create the filter in the database
		xajax_createQuickSearchFilter(iCategoryId, iSubCategoryId, iPriceFrom, iPriceTo, sFreeText, iBrandId);
	}
}

function redirectToSearchResultsPage(categoryId){
	window.location = msWebsitePathUrl + "/index.php?main=cat&id=" + categoryId + "&filter=quickSearch";	
}

function retrieveBrands(){	
	var categoryId = document.getElementById("selCategory").options[document.getElementById("selCategory").selectedIndex].value;
	
	if(categoryId != 0){
		emptyDropdown("selBrand")	
		xajax_retrieveBrands(categoryId);
	}
}

function emptyDropdown(controlName){
	var oControl = document.getElementById(controlName);

	if(oControl){
		oControl.innerHTML = "";		
		//now add an ALL options
		var oOption = document.createElement("OPTION");
		oControl.options.add(oOption);			
		oOption.innerHTML = "All Brands";
		oOption.value = "0";
	}
}
function populateDropdown(resultArray, controlName){
	var oControl = document.getElementById(controlName);

	if(oControl){		
		var oOption = document.createElement("OPTION");
		oControl.options.add(oOption);			
		oOption.innerHTML = resultArray[1];
		oOption.value = resultArray[0];
	}
}