my website uses a javascript file to load a common header for all the pages. I would like to add a custom search box to my header. There's a code given by google for adding custom search but this code works in HTML pages. My header file is a .js file. Need help in modifying this code so that the same can be used in js file.

Code provided by google:
Code:
<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
  google.load('search', '1', {language : 'en'});
  google.setOnLoadCallback(function() {
    var customSearchControl = new google.search.CustomSearchControl('0135638010087:ab1xoe7erpy');
    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.draw('cse');
  }, true);
</script>

I tried modifying like this, but its not working:

Code:
	document.write("<div id='cse' style='width: 100%;'>Loading</div>");
	document.write("<script src='http://www.google.com/jsapi' type='text/javascript'></script>");
	document.write("<script type='text/javascript'>");
	document.write("google.load('search', '1', {language : 'en'});");
	document.write("google.setOnLoadCallback(function() { var customSearchControl = new google.search.CustomSearchControl('001356680356738010084:ab1f807erpy');");
	document.write("customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);");
	document.write("customSearchControl.draw('cse');");
	document.write("}, true);");
	document.write("</script>");
Abhijit