// - - - Start - Configuration - Settings the Agency can modify - - - //
var Enable_Search_Within_This_Site = false;
var Enable_Search_Within_Agency = false;
var Results_Per_Page = 10;
var Search_Text_Box_Size = 24;
var Server_URL = "http://www.google.com/cse"; 
var Banner = "";
var AdditionalDropDownItems = "";
var Catalogue = "";
var withinMOMSite = ".mom.gov.sg";
var allSporeSite = ".gov.sg";

// Specify additional drop down options using the following //
AdditionalDropDownItems =
[
]

// Specify additional Catalgoue options using the following //
Catalogue =
[
]
// - - - End - Configuration - - - //


// - - - Start - Configuration - Debug Settings - - - //

var SplitResTry;


// - - - End - Configuration - - -//


function enableSearchWithInSite()
{
	return Enable_Search_Within_This_Site;
}

function enableSearchWithInAgency()
{
	return Enable_Search_Within_Agency;
}

function Gsitesearch(curform){
   var selectedSiteSearch =  curform.drop.value;
   if (selectedSiteSearch.match('SearchInAllGovSites'))
      curform.sitesearch.value = allSporeSite;
   else
   	  curform.sitesearch.value = withinMOMSite;

   curform.q.value= curform.TextBoxSearch.value
}

function googleClick(curform)
{
	var w = document.getElementById("drop").selectedIndex;
	var varDrop = document.getElementById("drop").options[w].value;
	//alert(varDrop);
	var selectedSiteSearch =  varDrop;

	document.getElementById("q").value = document.getElementById("TextBoxSearch").value;
   
	//var varXmlFlag = document.getElementById("XMLFlag").value;
	//var varSearchSubmit = document.getElementById("SearchSubmit").value;
	var varq = document.getElementById("q").value;
	//var varSiteSearch = document.getElementById("sitesearch").value;
 	// var varTextBoxSearch = document.getElementById("TextBoxSearch").value;
	//var varSiteSearch = document.getElementById("sitesearch").value;
	
	if (selectedSiteSearch.match('SearchInAllGovSites'))
		
     window.open("http://www.google.com/cse?cx=010148052846547300022%3Afboilxcylwg&ie=UTF-8&q="+varq) ;
    else
	 window.open("http://www.google.com/cse?cx=010148052846547300022%3Asqkujyjy8vw&ie=UTF-8&q="+varq) ;

    //window.open("http://www.google.com/cse?XMLFlag="+ varXmlFlag + "&SearchSubmit=" +varSearchSubmit + "&q="+varq + "&sitesearch=" + varSiteSearch + "&TextBoxSearch="+ varTextBoxSearch +"&SearchGo=Search&drop=" + varDrop) ;
}

function ShowResults()
{   
	//document.writeln("<form method='get' target='new1' action='"+ Server_URL + "' onSubmit='Gsitesearch(this)' name=SearchPlugInfrm style='margin:0' > ");
    document.writeln("<div>");
    document.writeln("<input type=hidden name=XMLFlag value=false >");
    document.writeln("<input type=hidden name=SearchSubmit value=Search>");
    document.writeln("<input name='q' type='hidden' />");
    document.writeln("<input type=hidden name='sitesearch' value='.mom.gov.sg'>");
    
    document.writeln("<input type=text class='searchBox' name=TextBoxSearch size="+ Search_Text_Box_Size + "  class='search-textfield'>");
	document.writeln("<SELECT id='drop' name='drop' class='searchDrop' style='font-size:14px;font-family:Arial;padding-top:5px;' >");
	

	if(enableSearchWithInSite())
	{
		document.writeln("<OPTION VALUE=SearchWithinThisSite SELECTED>" + "Within MOM Website");
	}
    	document.writeln("<OPTION VALUE='SearchInAllGovSites'>" + "Singapore Gov Websites");

	if(enableSearchWithInAgency())
	{
		document.writeln("<OPTION VALUE=SearchWithInAgency>" + "Within This Agency");
	}
	var t = / /g;
	if(AdditionalDropDownItems.length != 0)
	{	for (i = 0; i < AdditionalDropDownItems.length; i++)
			document.writeln("<OPTION VALUE=" + AdditionalDropDownItems[i][0].replace(t, "") +">" + AdditionalDropDownItems[i][0]);
	}
	if (Catalogue != "")
	{	for (i = 0; i < Catalogue.length; i++)
			document.writeln("<OPTION VALUE=" + Catalogue[i][1] +">" + Catalogue[i][0]);
	}
	
	document.writeln("</SELECT>");
	document.writeln("<input type=submit valign='bottom' name=SearchGo id=SearchGo class='searchSubmit' value=' ' onClick='javascript: googleClick(this)' >");
	//document.writeln("</form>");	
	document.writeln("</div>");	
}
