
// ---------- script properties ----------


var results_location = "search_results.htm";


// ---------- end of script properties ----------


function search_form(jse_Form) {
	if (jse_Form.d.value.length > 2) {
		strSearch = jse_Form.d.value;

		var RegSentence = /\"(.*?)\"/gi;
		strSentence = strSearch.match(RegSentence);
		strSearch	= strSearch.replace(RegSentence, "");								// insert a + if it isnt there

		strSearch =	strSearch.replace(/\s(?!\+|\-|$|\"|\s+)/gi, " +");					// insert a + if it isnt there
		strSearch = strSearch.replace(/(.*?)(\+|\-)/gi,"$1 $2");						// add space before + or -
		strSearch = strSearch.replace(/\s+/gi," ");										// remove multiple spaces
		strSearch = strSearch.replace(/(\+|\-)\s/gi,"$1");								// remove space after + or -
		strSearch = strSearch.replace(/(\+|\-)+/gi,"$1");								// remove multiple + or - 's
		strSearch = strSearch.replace(/(\+|\-)(\s+)?$/gi,"");							// remove + or - if there's nothing after it
		strSearch =	strSearch.replace(/^\s+(\-)+/gi, "-");								// remove space before a starting -
		strSearch =	strSearch.replace(/^\-(.*?)\s(.*?)$/gi, "$2 -$1");					// move a starting NOT claus to the end of the sentence

		strSearch =	strSearch.replace(/(^|\s|\+|\-)([^ ]{1,2})(?:\s|$)/gi, "");			// remove words if less than 3 chars (excluding + or -)
		strSearch =	strSearch.replace(/^(\s+)?(\+|\-)+/gi, "");							// remove starting - or + (invalid)

		
		if (strSentence != null)
		{
			strSearch = strSentence;
			document.cookie = "d=" + escape(strSearch);
			window.location = results_location;

		}
		else if (strSentence == null && strSearch.length > 2)
		{
			document.cookie = "d=" + escape(strSearch);
			window.location = results_location;
		}
		else
		{
			alert("Søgeord skal være minimum 3 tegn.");
		}


	} 
	else 
	{
		alert("Søgeord skal være minimum 3 tegn.");
	}
}

function getFocus() {
	document.getElementById("d").focus();
}
