﻿// JScript File
    //Fires when page opens - Hidden variable is created if JavaScript is enabled.  
    //Check for value in other JS functions.    if (document.all.hidJSEnabled != null)
    document.write('<input type="hidden" id="hidJSEnabled" name="hidJSEnabled" value="true">');


	function ValidateSearch() {
	    document.forms[0].hidJS.value = "T";
		var hidJS;
		hidJS = document.getElementById("hidJSEnabled");
		if (hidJS != null) {
			var hidAction;
			hidAction = document.getElementById("hidAction");
			if (hidAction.value != "Y") {
				//NOT FY change
				var pstrSearchText, hidSearchText;
				var pintSearchTextLen;
				//get Search text
				hidSearchText = document.getElementById("hidSearchText");
				//trim leading & trailing blanks
				pstrSearchText = trim(document.getElementById("txtSearch").value);
				//display text search with blanks removed
				document.forms[0].txtSearch.value = pstrSearchText;
				//get the length of the trimmed search text
				pintSearchTextLen = pstrSearchText.length;
				
				if (pintSearchTextLen < 1) {
					//Minimum of 1 characters for search
					//clear hidden value
					hidSearchText.value = "";
					document.forms[0].txtSearch.focus();
					alert("Search text must be at least 1 character");
					return false;
				}
				else {
					if (pintSearchTextLen > 81) {
						//Maximum of 81 characters for search
						//clear hidden value
						hidSearchText.value = "";
						document.forms[0].txtSearch.focus();
						alert("Search text must be less than 82 characters");
						return false;
					}
					else {
						//Valid length of search  
				        //Check for Special Characters
				        var result2 = ValidateSearchText();
				        if (result2) {
					        //clear hidden value
					        document.forms[0].hidSearchText.value = "";
					        document.forms[0].txtSearch.focus();
					        alert("Invalid character % _  or < entered in search.  Please remove the character and try again.");
					        return false;
				         }
				        else {
							//Valid search, submit request
							hidSearchText.value = pstrSearchText;
							document.forms[0].txtSearch.focus();
							//document.forms[0].submit();
							return true;
						}
					}
				}
			}
		}
	}
	
	
//    function window.onbeforeprint() { >> only works for IE
	function window_onbeforeprint() {
		var hidJS;
		hidJS = document.getElementById("hidJSEnabled");
     	var strLogo, strFund, strExport, strPrint;
		strLogo = document.getElementById("divFixedMenu");
		strFund = document.getElementById("tblFund");
		strExport = document.getElementById("btnExport1");
		strPrint = document.getElementById("btnPrint");
		if (hidJS != null) {
			var hidValue;
			hidValue = document.getElementById("hidBrowser");
			if (hidValue.value.substr(0,1) == "I") {
				//Make sure the browser is IE
				//Before printing document, hide Menu and other objects
				//divMenuOB.style.display = "none";
				if (strLogo != null) {
					//divLogo.style.display = "none";	
					divFixedMenu.className = "fixed_menu2_print";
					divFixedMenu.style.display = "none";
					divScrollable.className = "scrollareaPrint";
					tblBC.style.display = "none";
					tblTabs.style.paddingTop = "5px";
					tblSearch.style.display = "none";
					divSearch.style.display = "none";
					if (strExport != null) {
					    divNotes.style.display = "none";
					    tblNotes.style.display = "none";
						document.all.btnExport1.style.display = "none";	
					}
					if (strPrint != null) {
						document.all.btnPrint.style.display = "none";			
					}
					divResults.className = "divVendPrint2";
				}
			}
        }
    }

//    function window.onafterprint() { >> only works for IE
    function window_onafterprint() {
		var hidJS;
		hidJS = document.getElementById("hidJSEnabled");
     	var strLogo, strFund, strExport, strPrint;
		strLogo = document.getElementById("divFixedMenu");
		strFund = document.getElementById("tblFund");
		strExport = document.getElementById("btnExport1");
		strPrint = document.getElementById("btnPrint");
        if (hidJS != null) {
			var hidValue;
			hidValue = document.getElementById("hidBrowser");
			if (hidValue.value.substr(0,1) == "I") {
				//Make sure the browser is IE
				//After printing document, redisplay Menu and other objects
				//divMenuOB.style.display = "";
				if (strLogo != null) {
					//divLogo.style.display = "";				
					divFixedMenu.style.display = "";
					divFixedMenu.className = "fixed_menu_New";
					divScrollable.className = "scrollarea";
					tblBC.style.display = "";
					tblTabs.style.paddingTop = "";
					tblSearch.style.display = "";
					divSearch.style.display = "";
				if (strExport != null) {
				        divNotes.style.display = "";
					    tblNotes.style.display = "";
						document.all.btnExport1.style.display = "";
					}
					if (strPrint != null) {
						document.all.btnPrint.style.display = "";
					}
					divResults.className = "divVendDisplay2";
				}
			}   
       }
    }
    
    function ValidateSearchText() {
        var strSearch = document.forms[0].txtSearch.value;
        var strChar;
        strSearch = strSearch.toString();
        for (var i = 0; i < strSearch.length; i++) {
            strChar = strSearch.charAt(i).charCodeAt(0);
            if (strChar == 37 || strChar == 60 || strChar == 95)  {
                return true;
            }
        }
   }
