function goSearch() {
	var searchText = document.getElementById("searchText");
	var url = "/find-product?product=" + searchText.value;
	document.location.href = url;
}

function clearSearchField() {
	var theField = document.getElementById('searchText');
	if (theField.value.length > 6 && theField.value.substring(0,6) == "Search")		{
		theField.value = "";
	}
}

function checkForSearchEnter() {
   var theASCIIKey = window.event.keyCode;
   if(theASCIIKey != null) {
	if(theASCIIKey == 13) { //the enter key
	   goSearch();
	}
   }
}

function checkForStoryEnter() {
   var theASCIIKey = window.event.keyCode;
   if(theASCIIKey != null) {
	if(theASCIIKey == 13) { //the enter key
	   goStorySearch();
	}
   }
}

function goStorySearch() {
	var storyText = document.getElementById("storyText");
	var url = "find-stories?story=" + storyText.value;
	document.location.href = url;
}

function clearStoryField() {
	var theField = document.getElementById('storyText');
	if (theField.value.length > 6 && theField.value.substring(0,6) == "Search")		{
		theField.value = "";
	}
}

addEvent(window,'load',initialiseCountrySelectionData,false);

function initialiseCountrySelectionData() {
		populateKukriRegion();
}

function addEvent(elm, evType, fn, useCapture) {
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else {
			elm['on' + evType] = fn;
		}
	}


function populateKukriRegion() {
		SystemLookupService.getForCombo("9KCT", function(iValues) {
			if (iValues) {
				var country = document.getElementById("Country");
				if (country) {
					for (var i = 0; i < iValues.length; i=i+1) {
						var item = iValues[i];
						var opt = new Option(item.description, item.code, false, false);
						country.options[country.options.length] = opt;
				}
			}
		}
	});
}

function getSelectValue(iSelectObj) {
		if (iSelectObj) {
			for (var i = 0; i < iSelectObj.options.length; i=i+1) {
				var opt = iSelectObj.options[i];
				if (opt.selected) {
					return opt.value;
				}
			}
		}
		
		return "";
}

