function loadPage(){
	//googleSearchHighlight();
	if (getCookie('extra') !== null && getCookie('extra')==='true'){
		toggle('extra', 'span');
	}
	if (getCookie('hilight') !== null && getCookie('hilight')!==''){
		if (getCookie('prevhilight')!== null && getCookie('prevhilight')!=='' && getCookie('prevhilight')===getCookie('hilight')){
			searchHighlight('resultstable', getCookie('hilight'));
		} else {
			setCookie('prevhilight', getCookie('hilight'));
			deleteCookie('hilight');
		}
	}
}

function confirmDelete(){
    var agree=confirm("Are you sure you want to delete?");
    if (agree){
    	return true ;
    }else{
    	return false ;
    }
}
function submitDelete(form){
    if (confirmDelete()){ form.submit();}
}
function validateQuery(query){
	if (query.indexOf("*") === 0  || query.indexOf("?") === 0){
		alert("WARNING: leading wildcards are not supported: " + query + "\nThe query will execute without the leading wildcard.");
		query = query.substring(1, query.length);
	}
	if (query.indexOf("*") === 1){
		alert("WARNING: Please enter at least 2 characters before the * :\nThe query will execute without the *.");
		query = query.substring(0, query.length-1);	
	}
	return query;
}
function searchsubmitValidate(form, queryField){
	queryField.value = validateQuery(queryField.value);
	if (trim(queryField.value)!==""){	
		var sField = document.getElementById("searchfield").value;
		var searchTermField = document.getElementById("searchTerm");
		searchTermField.value = queryField.value; //keep original query
		queryField.value = "(" + sField + queryField.value + ")";
		form.submit();
	}
}
function quote(element, check){
	if (element.value.indexOf("\"")===0 && element.value.lastIndexOf("\"")===element.value.length-1 && !check.checked){
		element.value=element.value.substring(1, element.value.length-1);
	}else if (element.value.length>0 && element.value.charAt(0)!=="\"" && element.value.charAt(element.value.length-1)!=="\"" && check.checked){
		element.value="\"" +  element.value + "\"";
	}
}
function asterisk(element, check){
	var quoted=false;
	if (element.value.lastIndexOf("*")!==element.value.length-1 && check.checked){
		quoted=false;
		//remove final quote if there is one
    	if (element.value.lastIndexOf("\"")===element.value.length-1){
    		element.value=element.value.substring(0, element.value.length-1);
    		quoted=true;
    	}	
		//add *
		element.value=element.value + "*";	
		//requote
		if (quoted){ element.value=element.value + "\"";}
	}else if (!check.checked){
		quoted=false;
		//remove final quote if there is one
    	if (element.value.lastIndexOf("\"")===element.value.length-1 && element.value.length>0){
    		element.value=element.value.substring(0, element.value.length-1);
    		quoted=true;
    	}
		//remove *
		if (element.value.charAt(element.value.length-1)==="*"){ 
			element.value=element.value.substring(0, element.value.length-1);}
		//requote
		if (quoted){ element.value=element.value + "\"";}
	}
}

function openWindow(title, content){
	newWindow = window.open('',title,'width=600,height=400,resizable=yes');
	newWindow.document.write(content); 
	newWindow.document.close();
}

function toggleLayer(whichLayer, displayStyle){
	var style2;
	if (document.getElementById)
	{
		// this is the way the standards work
		style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":displayStyle;

	}
	else if (document.all)
	{
		// this is the way old msie versions work
		style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":displayStyle;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		 style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":displayStyle;
	}
}

function toggle(id, tag){
	objs = document.getElementsByTagName(tag);
	for (var i = 0; i<objs.length;i++){
		if (objs[i].id === id) {
			if (objs[i].style.display===""){ objs[i].style.display="inline";}
			objs[i].style.display = (objs[i].style.display==="inline")? "none":"inline";
		}
	}
}

var MAX_WORD_LENGTH = 27;

function hyphenateSentence(sentence){
	if (sentence.length>MAX_WORD_LENGTH){
		sentence = sentence.replace(/([-;,\.\?:%!=\/\(\)\\])/g, "$1 ");
	}
	var words = sentence.split(" ");
	var hyphSentence = "";
	for (var i = 0; i<words.length; i++){
		hyphSentence += hyphenate(words[i]) + " ";
	}
	return hyphSentence;
}

function hyphenate(word){
	//simple script for hyphenating words
	var MIN_HYPHWORD2_LENGTH = 3;
	var hyphWord1 = word;
	var hyphWord2 = "";
	var words;
	if (word.length>MAX_WORD_LENGTH){
		//split on max word length
		hyphWord1 = word.substring(0, MAX_WORD_LENGTH);
		hyphWord2 = word.substring(MAX_WORD_LENGTH);
		if (hyphWord2.length < MIN_HYPHWORD2_LENGTH) {
			hyphWord1 = word.substring(0, MAX_WORD_LENGTH-MIN_HYPHWORD2_LENGTH+1);
			hyphWord2 = word.substring(MAX_WORD_LENGTH-MIN_HYPHWORD2_LENGTH+1);
		}
		hyphWord2=hyphenate(hyphWord2);
	}
	return hyphWord1 + ((hyphWord2!=="")?"- " + hyphWord2:"");
}