<!-- Begin
function elemCheck(elemNam,chkVal) {
	var elemID = document.getElementById(elemNam);
	elemID.checked = chkVal;
}

function elemDisAbl(elemNam,disVal) {
	var elemID = document.getElementById(elemNam);
	elemID.disabled = disVal;
}

function elemSetVal(elemNam,elemVal) {
	var elemID = document.getElementById(elemNam);
	elemID.value = elemVal;
}

function setLegends(theCookie) {
	var theLegend = document.getElementById('cs1');
	var theObj= (navigator.product == 'Gecko' || navigator.userAgent.indexOf("Opera") != -1 || navigator.userAgent.indexOf("Netscape") != -1) ? theLegend.firstChild.nextSibling.nextSibling.nextSibling : theLegend.firstChild.nextSibling.nextSibling;
	theObj.nodeValue= "Search for items that include the " + (inspectCookie(theCookie)=='n' ? "word" : "string") + " or phrase...";
	var theLegend = document.getElementById('critLabel');
	theLegend.firstChild.nodeValue= "not ...the " +  (inspectCookie(theCookie)=='n' ? "word" : "string") + " or phrase...";
}

function fillSearch() {
	checkNFill("H","criteria2"); checkNFill("G","criteria1");
	elemCheck((inspectCookie(253)<'b') ? 'criteriaAnd' : ((inspectCookie(253)=='b') ? 'criteriaOr' : 'criteriaNot'),true);
	elemCheck("noteBox",(inspectCookie(251)=="y") ? true : false); elemCheck("siteBox",(inspectCookie(252)=="y") ? true : false);
	elemCheck("lyrBox",(inspectCookie(250)=="y") ? true : false);
	elemCheck("allBox",("yyy"==inspectCookie(250) + inspectCookie(251) + inspectCookie(252)) ? true : false);
	elemCheck((inspectCookie(254)!="y") ? "linksDestThis" : "linksDestNew",true);
	elemCheck((inspectCookie(255)!="y") ? "searchWords" : "searchStrings",true);
	setLegends(255);
	OnlyLyricsChecked();
}

function setCookieNELem(cookieNum,cookieChar,boxID) {
	graftCookie(cookieNum, cookieChar, 1);
	elemCheck(boxID,(cookieChar=="y") ? true : false);
}

function checkNFill(strCookieName, strElmID) {
	var strTxt = getCookieString(strCookieName);
	if ( (strTxt!=dummyCookie(100)) && (strTxt!=null)) {
		elemSetVal(strElmID,decodeURI(strTxt));
		return 1;
	}
	return 0;
}

function OnlyLyricsChecked() {
	if ((!(document.getElementById("noteBox")).checked && !(document.getElementById("siteBox")).checked)) {
		graftCookie(250, "y", 1);
		elemDisAbl("lyrBox",true);
		elemCheck("lyrBox",true);
	} else {
		elemCheck("lyrBox",(inspectCookie(250)=="y") ? true : false)
		elemDisAbl("lyrBox",false);
	}
}

function ltrim (s) {
	return s.replace( /^\s*/, "" )
}

function rtrim (s) {
	return s.replace( /\s*$/, "" );
}

function saveNPost() {
	var txt1ID = document.getElementById("criteria1");
	strTxt1 = encodeURI(ltrim(rtrim(txt1ID.value)));
	var txt2ID = document.getElementById("criteria2");
	strTxt2 = encodeURI(ltrim(rtrim(txt2ID.value)));
	if ( (strTxt1) || (strTxt2)) {
		var strAllSettings="";
		for (var ctr=250; ctr<256; ctr++) {
			cVal = inspectCookie(ctr);
			graftCookie(ctr+6,cVal, ctr<255 ? 0 : 1);
			strAllSettings+=cVal;
		} 
		elemSetVal("allSettings",strAllSettings);
		saveTmpOrPerm((inspectCookie(20)=="y") ? 20 : 201,"D", (strTxt1) ? strTxt1 : dummyCookie(100));
		saveTmpOrPerm((inspectCookie(20)=="y") ? 20 : 201,"E", (strTxt2) ? strTxt2 : dummyCookie(100));    
		document.forms[0].submit();
	} else {
		elemSetVal("criteria1","");
		elemSetVal("criteria2","");
	}
}

function setSettings(cookieNum) {
	graftCookie( cookieNum, ( (inspectCookie(cookieNum)!='y') ? 'y' : 'n'), 1);
	elemCheck("allBox",("yyy"==inspectCookie(250) + inspectCookie(251) + inspectCookie(252)) ? true : false);
	OnlyLyricsChecked();
}

function setItemSettings() {
	var cChar = ((document.getElementById("allBox")).checked) ? "y" : "n";
	setCookieNELem(250,cChar,"lyrBox"); setCookieNELem(251,cChar,"noteBox"); setCookieNELem(252,cChar,"siteBox");
	OnlyLyricsChecked();
}

function updateCookie() {
	setCookieString( "G", (encodeURI((document.getElementById("criteria1")).value)).substring(0,100) );
	setCookieString( "H", (encodeURI((document.getElementById("criteria2")).value)).substring(0,100) );
}

function clearCriteria() {
	elemSetVal('criteria1',"");
	elemSetVal('criteria2',"");
	setCookieString("G", dummyCookie(100)); setCookieString("H", dummyCookie(100));
}

function resetAll() {
	clearCriteria();
	elemCheck("allBox",false);
	setItemSettings();
	graftCookie(253,"a",1);
	elemCheck("criteriaAnd",true);
	graftCookie(254,"n",1);
	elemCheck("linksDestThis",true);
	graftCookie(255,"n",1);
	elemCheck("searchWords",true);
}

function checkWriteResultLink(strMnuNum,strDiv) {
	var stringD = getCookieString("D"); var stringE = getCookieString("E");
	if ( (stringD!=null && stringD!=dummyCookie(100)) || (stringE!=null && stringE!=dummyCookie(100))) {
		//	For some reason (because of underscore?) 'document.getElementById("lnksrc_Search"' does not work in Opera and Netscape 8.0, hence:
		var aSearch = document.getElementById("pgheads").lastChild.previousSibling;
		if (aSearch.nodeName!="A") {aSearch=aSearch.previousSibling}; // these two lines always get last "A" element. So this func can be modified to also write Link-In link
		aResult = aSearch.cloneNode(true);
		aResult.firstChild.nodeValue = "Result";
		aResult.href="search.php?" + strMnuNum + "C";
		var theDiv = document.getElementById(strDiv);
		theDiv.appendChild((document.createTextNode(aSearch.previousSibling.nodeValue)));
		theDiv.appendChild(aResult);
	}
}

function fillOldCriteria() {
	if (checkNFill("D", "criteria1") + checkNFill("E", "criteria2")>=1) {
		elemSetVal("allSettings",inspectCookie(256)+inspectCookie(257)+inspectCookie(258)+inspectCookie(259)+inspectCookie(260)+inspectCookie(261));
		return true;
	} else {
		return false;
	}
}
// End -->
