﻿// JScript File

        function keydownhandler(event,btn)
        {
            if(event && event.which) 
            {
                var e=event;
                var charCode=e.which;
            } 
            else 
            {
                var e=window.event;
                var charCode=e.keyCode;
            }
            // process only the Enter key
            if (charCode == 13)
            { 
                // cancel the default submit
                e.returnValue=false;
                e.cancel = true;        
                // submit the form by programmatically clicking the specified button
                var btn = document.getElementById(btn);
                // finding the browser, and changing action according to that
                if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))                
                    btn.click();        
                else        
                    btn.focus();
            }
        }
    
        function pagingfirst()
        {
            var currindex=document.getElementById("hideCurrIndex");
            var pgno = document.getElementById("hidepgno");
            currindex.value=0;
            pgno.value=0;
            document.form1.action=window.location;
            document.form1.submit();
        }
        
        function paginglast()
        {
            var currindex=document.getElementById("hideCurrIndex");
            var pgno = document.getElementById("hidepgno");
            var count = document.getElementById("hideRecordCount");
            
            pgno.value=count.value -1;
            currindex.value=(count.value -1) * 12;
            document.form1.action=window.location;
            document.form1.submit();
        }
        
        function pagingnext()
        {
            var currindex=document.getElementById("hideCurrIndex");
            var pgno = document.getElementById("hidepgno");
            start = parseInt(currindex.value);
            page = parseInt(pgno.value);
            page=page+1;
            currindex.value=start+12;
            pgno.value=page;
            document.form1.action=window.location;
            document.form1.submit();
        }
        
        function pagingprevious()
        {
            var currindex=document.getElementById("hideCurrIndex");
            var pgno = document.getElementById("hidepgno");
            start = parseInt(currindex.value);
            page = parseInt(pgno.value);
            page=page-1;
            currindex.value=start-12;
            pgno.value=page;
            document.form1.action=window.location;
            document.form1.submit();
        }
        
        function ltrim (s)
        {
            return s.replace( /^\s*/, "" );
        }
        
        function bookvalidation()
        {
            var key=document.getElementById("txtbookkey");
            var bctg = document.getElementById("ddbooksearch");
            if (ltrim(key.value)=="")
            { alert("Please enter Keyword to Search"); key.value=""; key.focus(); return false; }
            window.location.href="/searchbooks.aspx?key=" + key.value + "&bctg=" + bctg.value;  
        }
        
        function perfumevalidation()
        {
            var key=document.getElementById("txtperfumekey");
            var range = document.getElementById("ddperfumesearch");
            if(range.value==0)
            { alert("Please specify price range"); range.focus(); return false; }
            if (ltrim(key.value)=="")
            { alert("Please enter Keyword to Search"); key.value=""; key.focus(); return false; }
            window.location="/searchperfumes.aspx?key=" + key.value + "&range=" + range.value;  
        }
