var foundError=false;var errorMsg="";var changeMessage=true;var response="";var ERROR0="Please enter one or more search terms.";var ERROR1="Missing an open parenthesis.";var ERROR2="Missing a close parenthesis.";var ERROR3="* Can only be used at the end of a word.";var ERROR6="Missing an opening/closing quotation mark.";var ERROR7="Quotation marks used incorrectly.";var ERROR8="Booleans cannot follow an open parenthesis.";var ERROR9="Closing parenthesis cannot follow a boolean. ";var ERROR10="Cannot have empty parenthesis.";var ERROR11="Booleans used incorrectly.";var ERROR12="Single characters are ignored.";var ERROR13="Cannot start with a boolean.";var ERROR14="* Cannot be used inside quotations.";var ERROR15="Booleans are not allowed";var ERROR16="* Cannot be used with single characters";var ERROR17='Please Note:  Single characters return too many hits when searched in PDF and HTML text. However they can return valid hits from Knovel\'s custom-built index. Click "OK" to search the custom index only or "Cancel" to modify your search.';function validate(c,e){errorMsg="";var d="";var a=e!=undefined?e:document.getElementById("topTextInput");var b=a.value;b=b.replace(/<.*?>/g,"");a.value=b;if(b==""){foundError=true;errorMsg=ERROR0}else{b=b.replace(/\n/g,"");b=b.replace(/\r/g,"");d=trimSpaces(b.toLowerCase());checkRemWords(d);d=parensBalance(d)}if(foundError){showError("errorMsg1",errorMsg,"subTabSearchHelpText");foundError=false;a.focus();changeMessage=true;return false}if(e==undefined){b=removeSpacesBetweenHyphens(d);b=removeExtraBooleans(b,d);document.getElementById("topTextInput").value=b}else{b=removeSpacesBetweenHyphens(d);b=removeExtraBooleans(b,d);e.value=b}return true}function validateAdv(a,c,d){errorMsg="";if(c==""&&d){return true}else{if(c==""&&!d){errorMsg=ERROR0;foundError=true;return}else{c=trimSpaces(c);c=parensBalance(c)}}if(!foundError){if(c.match(/\s(and|not|or)(\s|$)/)!=null){errorMsg=ERROR15;foundError=true}}if(foundError){var b="errorMsg"+a;showError(b,errorMsg);foundError=false;return false}return true}function trimSpaces(a){a=a.replace(/\s+/g," ");a=a.replace(/\s\)/g,")");a=a.replace(/\(\s/g,"(");if(a.match(/^\s/)!=null){a=a.substring(1)}if(a.match(/\s$/)!=null){a=a.substring(0,a.length-1)}return a}function parensBalance(c){var b=c.match(/\(/g)!=null?c.match(/\(/g).length:0;var a=c.match(/\)/g)!=null?c.match(/\)/g).length:0;if(b!=a){b-=c.match(/\w\(\w*?\*/g)!=null?c.match(/\w\(\w*?\*/g).length:0;a-=c.match(/\w\)\w*?\*/g)!=null?c.match(/\w\)\w*?\*/g).length:0}if(a>b){errorMsg=ERROR1;foundError=true;return}else{if(b>a){errorMsg=ERROR2;foundError=true;return}}if(c.match(/\(\)/)!=null){errorMsg=ERROR10;foundError=true;return}return checkAsterisk(c)}function checkAsterisk(a){if(a.indexOf("*")!=-1){if(a.match(/^\*/)!=null||a.match(/\S\*[^\s)"]/)!=null||a.match(/\s\(*?\*/)!=null){errorMsg=ERROR3;foundError=true;return}}return checkQuotes(a)}function checkQuotes(d){var a=d.match(/"/g)!=null?d.match(/"/g).length:0;if(a%2!=0){errorMsg=ERROR6;foundError=true;return}if(d.match(/\"\s?\"/)!=null){errorMsg=ERROR7;foundError=true;return}inQuotes=false;var c=0;for(i=0;i<d.length;i++){var b=d.charAt(i);if(b=="*"&&inQuotes){errorMsg=ERROR14;foundError=true;return}if(b=='"'&&!inQuotes){inQuotes=true;continue}else{if(b=="("&&inQuotes){c++;continue}else{if(b==")"&&inQuotes){c--;continue}}}if(b=='"'&&inQuotes){if(c!=0){errorMsg=ERROR7;foundError=true;return}else{inQuotes=false}}}d=checkSpaceBtwQuotes(d);return checkBooleans(d)}function checkSpaceBtwQuotes(c){var b="";inQuotes=false;for(i=0;i<c.length;i++){var a=c.charAt(i);if(a=='"'&&!inQuotes){inQuotes=true}else{if(a=='"'&&inQuotes){inQuotes=false;if(i+1<c.length&&c.charCodeAt(i+1)!=32){b+=a+" ";continue}}}b+=a;if(!inQuotes&&i+1<c.length&&c.charAt(i)!=32&&c.charAt(i+1)=='"'){b+=" "}}return b}function checkBooleans(e){e=e.replace(/\band\snot\b/g,"not");var a=e;a=a.replace(/[^a-zA-Z0-9\s\*]/g," ");a=trimSpaces(a);var d=a.split(" ");var b=false;for(var c=0;c<d.length;c++){if(d[c].length!=0&&d[c]!="and"&&d[c]!="not"&&d[c]!="or"){b=true;break}}if(d[0]=="and"||d[0]=="or"||d[0]=="not"){errorMsg=ERROR13;foundError=true;return}if(!b){errorMsg=ERROR0;foundError=true;return}if(e.match(/\s\((and|not|or)(\s|\))/)!=null){errorMsg=ERROR8;foundError=true}if(e.match(/\s(and|not|or)\)/)!=null){errorMsg=ERROR9;foundError=true;return}return e}function removeSpacesBetweenHyphens(a){a=a.replace(/\s-\s/g," ");a=a.replace(/-\s/g,"-");a=a.replace(/\s-/g,"-");return a}function removeExtraBooleans(f){var d=false;var e="";var c;myList=f.split(" ");for(var b=0;b<myList.length;b++){if(myList[b].length!=0&&myList[b].toLowerCase()!="and"&&myList[b].toLowerCase()!="not"&&myList[b].toLowerCase()!="or"){d=false}if(d){if(myList[b].toLowerCase()=="and"||myList[b].toLowerCase()=="or"){continue}if(myList[b].toLowerCase()=="not"&&c!="and"){continue}}if(!d&&(myList[b].toLowerCase()=="and"||myList[b].toLowerCase()=="not"||myList[b].toLowerCase()=="or")){d=true;c=myList[b].toLowerCase()}e+=myList[b]+" "}var a=trimSpaces(e.toLowerCase());myList=a.split(" ");var g=myList.length-1;if(myList[g]=="not"){e=e.substring(0,e.length-4);if(myList[g-1]=="and"){e=e.substring(0,e.length-4)}}if(myList[g]=="and"){e=e.substring(0,e.length-4)}if(myList[g]=="or"){e=e.substring(0,e.length-3)}return removeSpaceBetweenQoutes(trimSpaces(e))}function removeSpaceBetweenQoutes(d){var c=false;var b="";for(i=0;i<d.length;i++){var a=d.charAt(i);if(!c&&a=='"'){c=true;b+=a;continue}else{if(c&&a=='"'){c=false}}if((c&&a==" "&&i+1<d.length&&d.charAt(i+1)=='"')||(c&&a==" "&&i>0&&d.charAt(i-1)=='"')){continue}b+=a}return b}function resetForm(b){var a=document.MyForm;a.QueryBox.value="";a.SecondSelect1.selectedIndex=0;a.SubSubjectAreaID.selectedIndex=0;a.SubjectAreaID[0].checked=!b?true:false;a.SubjectAreaID[1].checked=b?true:false}function changeOptions(){var a=document.MyForm;if(a.MyBookID!=undefined&&a.MyBookID.value==0){return true}if(a.MyBookID!=undefined){a.BookID.value=a.MyBookID.value}var c=a.SecondSelect1.options;var d=a.SubjectAreaID.length;if(a.SubjectAreaID[d-1].checked){c[1].text="Table of Contents";c[1].value="2";c[2]=null;c[3]=null;c[4]=null;c[2]=null;a.SubSubjectAreaID.disabled=true;a.InBook.value="true"}else{c[1].text="Author";c[1].value="4";var b=new Option("ISBN","5",false,false);c[2]=b;b=new Option("Table of Contents","2",false,false);c[3]=b;b=new Option("Title","3",false,false);c[4]=b;a.SubSubjectAreaID.disabled=false;a.InBook.value="false"}return true}function checkSubjectAreaID(a,b){if(a!=undefined&&a.SubjectAreaID!=undefined&&a.SubSubjectAreaID!=undefined){if(b!=0){a.SubSubjectAreaID.selectedIndex=0;a.SubSubjectAreaID.disabled=true;a.BookID.value=b}else{a.SubjectAreaID[0].disabled=false;a.SubjectAreaID[1].disabled=false}}}function checkAdvancedSearchFields(){var f=document.MyForm;var h=f.SearchTermA1!=undefined?trimSpaces(f.SearchTermA1.value.toLowerCase()):"";var g=f.SearchTermA2!=undefined?trimSpaces(f.SearchTermA2.value.toLowerCase()):"";var e=f.SearchTermB1!=undefined?trimSpaces(f.SearchTermB1.value.toLowerCase()):"";var c=f.SearchTermB2!=undefined?trimSpaces(f.SearchTermB2.value.toLowerCase()):"";var k=f.SearchTermC1!=undefined?trimSpaces(f.SearchTermC1.value.toLowerCase()):"";var j=f.SearchTermC2!=undefined?trimSpaces(f.SearchTermC2.value.toLowerCase()):"";var d=f.OperatorSelect1[f.OperatorSelect1.selectedIndex].value;var b=f.OperatorSelect2[f.OperatorSelect2.selectedIndex].value;var a=f.OperatorSelect3[f.OperatorSelect3.selectedIndex].value;if(d!=1&&h==""&&b!=1&&g==""&&a!=1&&e==""&&c==""&&k==""&&j==""){errorMsg=ERROR0;showError("errorMsg1",errorMsg);f.SearchTermA1.focus();foundError=false;return false}if(d==4&&((h==""&g!="")||(h!=""&g==""))){errorMsg=ERROR0;showError("errorMsg1",errorMsg);if(h==""){f.SearchTermA1.focus()}else{f.SearchTermA2.focus()}foundError=false;return false}if(b==4&&((e==""&c!="")||(e!=""&c==""))){errorMsg=ERROR0;showError("errorMsg2",errorMsg);if(e==""){f.SearchTermB1.focus()}else{f.SearchTermB2.focus()}foundError=false;return false}if(a==4&&((k==""&j!="")||(k!=""&j==""))){errorMsg=ERROR0;showError("errorMsg3",errorMsg);if(k==""){f.SearchTermC1.focus()}else{f.SearchTermC2.focus()}foundError=false;return false}if(d!=1){if(!validateAdv(1,h,true)){f.SearchTermA1.focus();foundError=false;return false}}if(b!=1){if(!validateAdv(2,e,true)){f.SearchTermB1.focus();foundError=false;return false}}if(a!=1){if(!validateAdv(3,k,true)){f.SearchTermC1.focus();foundError=false;return false}}return true}function URLEncode(g){var h="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";var b="0123456789ABCDEF";var e=g;var f="";for(var c=0;c<e.length;c++){var d=e.charAt(c);if(d==" "){f+="+"}else{if(h.indexOf(d)!=-1){f+=d}else{var a=d.charCodeAt(0);if(a>255){f+="+"}else{f+="%";f+=b.charAt((a>>4)&15);f+=b.charAt(a&15)}}}}return f}function showError(b,c,a){if(a){document.getElementById(a).style.display="none"}document.getElementById(b).innerHTML=c;document.getElementById(b).style.display="block"}function checkRemWords(a){if(!(a.length==0)&&a.split(" ").length==1&&stopWordsList.indexOf(a)!=-1){foundError=true;errorMsg="Your search contains a stop word, please try again."}else{if(!(a.length==0)){var c=false;var d=a.split(" ");for(var b=0;b<d.length;b++){if(stopWordsList.indexOf(trimSpaces(d[b]))!=-1){c=true}else{c=false;break}}if(c){foundError=true;errorMsg="Your search contains a stop word, please try again."}}}};
