﻿// JScript File
//http://dotnetslackers.com/articles/aspnet/Implementing-Search-in-ASP-NET-with-Google-Custom-Search.aspx

// Function retrieved from: http://cass- hacks.com/articles/code/js_url_encode_decode/  
function URLEncode (clearString) {  
  var output = '';  
  var x = 0;  
  clearString = clearString.toString();  
  var regex = /(^[a-zA-Z0-9_.]*)/;  
 while (x < clearString.length) {  
    var match = regex.exec(clearString.substr(x));  
    if (match != null && match.length > 1 && match[1] != '') {  
       output += match[1];  
     x += match[1].length;  
   } else {  
     if (clearString[x] == ' ')  
       output += '+';  
     else {  
       var charCode = clearString.charCodeAt(x);  
       var hexVal = charCode.toString(16);  
       output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();  
     }  
     x++;  
   }  
 }  
 return output;  
}  

// Retrieved from: http://www.htmlcodetutorial.com/forms/index_famsupp_157.html  
function SubmitOnEnter(myfield, e)  
{  
   var keycode;  
   if (window.event)  
       keycode = window.event.keyCode;  
   else if (e)  
       keycode = e.which;  
   else  
       return true;  
   if (keycode == 13)  
   {  
       SearchSite();  
       return false;  
   }  
   else  
       return true;  
}  

function SearchSite()  
{      
    document.location.href='http://www.castledawsongac.com/search/default.aspx?cx=partner-pub-5293990409486694%3Afnctl2-k8cn&cof=FORID%3A10&ie=ISO-8859-1&q=' +   
    URLEncode(document.getElementById('q').value) + '&sa=Search';                         
    
    /*

    <form action="http://www.castledawsongac.com/search/default.aspx" id="cse-search-box">
      <div>
        <input type="hidden" name="cx" value="partner-pub-5293990409486694:fnctl2-k8cn" />
        <input type="hidden" name="cof" value="FORID:10" />
        <input type="hidden" name="ie" value="ISO-8859-1" />
        <input type="text" name="q" size="31" />
        <input type="submit" name="sa" value="Search" />

      </div>
    </form>

    <script type="text/javascript" src="http://www.google.ie/coop/cse/brand?form=cse-search-box&amp;lang=en"></script>


    */
    
    //http://www.castledawsongac.com/search/default.aspx?cx=partner-pub-5293990409486694%3Afnctl2-k8cn&cof=FORID%3A10&ie=ISO-8859-1&q=seamus&sa=Search#918
    //http://www.castledawsongac.com/search/default.aspx?cx=partner-pub-5293990409486694:fnctl2-k8cn&cof=FORID:10&ie=ISO-8859-1=seamus&sa=Search#19
    //http://www.castledawsongac.com/search/default.aspx?cx=partner-pub-5293990409486694%3Afnctl2-k8cn&cof=FORID%3A10&ie=ISO-8859-1&q=seamus&sa=Search#19
}  
