<!-- 

// Implement a trim function...
String.prototype.trim = function() {
	// skip leading and trailing whitespace
	// and return everything in between
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
}

/* Checks that the main search form is okey and populates the correct fields */
function checkTheForm(theForm){
	if(!checkTheLength(theForm.search_str, false) || !checkTooManyClauses(theForm.search_str)){
		return false;
	} else {
		if (theForm.search_categories.value != -1) {
			theForm.articlequerystring.value = replaceChar(theForm.search_str) + " AND " + addCategoriesToForm(theForm);
		} else {
			theForm.articlequerystring.value = replaceChar(theForm.search_str);
		}
		return true;
	}	
}

function checkThenPost(f) {
	if(checkSmallForm(f)) 
		f.submit();
}

//checks small search form
function checkSmallForm(theForm){
	if(!checkTheLength(theForm.search_str, false) || !checkTooManyClauses(theForm.search_str)){
		return false;
	} else {
		theForm.articlequerystring.value = replaceChar(theForm.search_str);		
		return true;
	}
}

//checks small link search form, found in left column at index pages
function checkSmallLinkForm(theForm){
	theForm.articlequerystring.value = replaceChar(theForm.search_str);
	return true;
}

//checks link search form	
function checkLinkForm(theForm){
	// check the categorysearch
	if (theForm.search_categories) {
		var catval = theForm.search_categories.options[theForm.search_categories.selectedIndex].value;
		if (catval <= 0){
			alert("Välj kategori!");
			return false;		
		} else {
			return (checkTheForm(theForm));
		}
	}
	return true;
}

/* Add the categories to the search */
function addCategoriesToForm(f) {
	var catArray = f.search_categories.value.split("-");
	var strCat = "(";
	for (var i = 0; i < catArray.length; i++) {
		if (i > 0) {
			strCat += " OR ";
		}
		strCat += "indexarticle_categoryid: " + catArray[i];
	}
	strCat += ")";
	return strCat;
}


function replaceChar(theField){
	var tmp = theField.value;
	var newstring = "";
	for(i=0; i<tmp.length;i++) {
		if(tmp.charAt(i)==':') {
			newstring += '\\:';
		} else {
			newstring += tmp.charAt(i);
		}
	}
	return newstring;
}

/* Check if it is at least 2 characters and not a wildcard* */
function checkTooManyClauses(theField){
	if (theField.value.length==2 && theField.value.charAt(1)=='*') {
		alert("Sökningen ger för många träffar!");
		theField.focus();
		return false;
	} else {
		return true;
	}
}

/* At least 2 characters */
function checkTheLength(theField, emptyOK){
	var error = false;
	if(!emptyOK){
		if (theField.value.length < 2) {
			error = true;
		}
	} else {
		if (theField.value.length < 2 && theField.value.length > 0) {
			error = true;
		}
	}

	if(error){
		alert("Minst 2 tkn måste anges!");
		theField.focus();
		return false;
	} else {
		return true;
	}
}

/*
function checkDate(from,to) {
	if (from.value.length > 0) {
		if (from.value.indexOf("-") != -1) {
			alert('Datumet måste vara i formatet: ååååMMdd, ex: 20041019!');
			from.focus();
			from.select();
			return false;
		}
	}
	if (to.value.length > 0) {
		if (to.value.indexOf("-") != -1) {
			alert('Datumet måste vara i formatet: ååååMMdd, ex: 20041019!');
			to.focus();
			to.select();
			return false;
		}
	}
	
	return true;
}
*/

function next(){
	postForm(document.nextform);
}

function prev(){
	postForm(document.prevform);
}

function page(num){
	document.pageform.page.value=num;
	postForm(document.pageform);
}

function thesearchform(){
	postForm(document.thesearchform);
}

function advancedsearchform(){
	postForm(document.advancedsearchform);
}

function changeOrder(theOrder){
	document.sortorderChange.order.value=theOrder;
	postForm(document.sortorderChange);
}

function postForm(theForm){
	theForm.submit();
}

function move(pagenum){
	document.moveform.page.value=pagenum;
	postForm(document.moveform);

}

-->