// - - - Start - Configuration - Settings the Agency can modify - - - //
var Enable_Search_Within_This_Site = true;
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_MasterPagePhase2()
{   	
    //document.writeln("<form method='get' target='new1' action='"+ Server_URL + "' onSubmit='Gsitesearch(this)' name=SearchPlugInfrm style='margin:0' > ");
    document.writeln("<input type=hidden id=XMLFlag name=XMLFlag value=false >");
    document.writeln("<input type=hidden id=SearchSubmit name=SearchSubmit value=Search>");
    document.writeln("<input name='q' id=q type='hidden' />");
    document.writeln("<input type=hidden id=sitesearch name='sitesearch' value='.mom.gov.sg'>");
	document.writeln("<input type='text' id=TextBoxSearch name=TextBoxSearch class='textfield' size='20' />");
	document.writeln("<select id='drop' name='drop'>");
    //document.writeln("<tr><td ><div align='right'><img src='" + spacer + "' width='5' height='5px' border='0'></div></td></tr>");
	//document.writeln("<tr>");
	//document.writeln("<td align='center' valign='baseline'>");
	//document.writeln("<div align='right'>");
    //document.writeln("<img src='" + magGlass + "' width='15' height='15'>");
	//document.writeln("<input type=text name=TextBoxSearch size="+ Search_Text_Box_Size + "  class='search-textfield'><input type=submit valign='bottom' name=SearchGo id=SearchGo class='search-button' value='Search' onClick='javascript: googleClick(this)' >");
    //document.writeln("<img src='" + googleSearchIcon + "' border='0' align='absbottom' >");
    //document.writeln("<img src='" + spacer + "' height='5'>");	
    ////document.writeln("<a target=new href=" + Server_HomePage + ">");
	//document.writeln("</div>");
	//document.writeln("</td>");
	//document.writeln("</tr>");
	//document.writeln("<tr><td><div align='right'><img src='" + spacer + "' width='5' height='4px' border='0'></div></td></tr>");
	//document.writeln("<tr>");
	//document.writeln("<td width='40%' align='right' class='sitesearch'>");
    //	document.writeln("<SELECT class='search-dropdown' id='drop' name='drop'>");
	if(enableSearchWithInSite())
	{
		document.writeln("<OPTION VALUE=SearchWithinThisSite SELECTED>" + "Within MOM Website");
	}
    	document.writeln("<OPTION VALUE='SearchInAllGovSites'>" + "Within All 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("</SELECT><img src='" + spacer + "' height='5'>");
	//document.writeln("</td>");
	//document.writeln("</tr>");
	document.writeln("<input type='submit' name=SearchGo id=SearchGo class='button' value='Search' size='20' onClick='javascript: googleClick(this)' />");
	//document.writeln("</form>");
}


function ShowResults_MasterPage(magGlass, spacer, googleSearchIcon)
{   	
    //document.writeln("<form method='get' target='new1' action='"+ Server_URL + "' onSubmit='Gsitesearch(this)' name=SearchPlugInfrm style='margin:0' > ");
    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("<tr><td ><div align='right'><img src='" + spacer + "' width='5' height='5px' border='0'></div></td></tr>");
	document.writeln("<tr>");
	document.writeln("<td align='center' valign='baseline'>");
	document.writeln("<div align='right'>");
    document.writeln("<img src='" + magGlass + "' width='15' height='15'>");
	document.writeln("<input type=text name=TextBoxSearch size="+ Search_Text_Box_Size + "  class='search-textfield'><input type=submit valign='bottom' name=SearchGo id=SearchGo class='search-button' value='Search' onClick='javascript: googleClick(this)' >");
    document.writeln("<img src='" + googleSearchIcon + "' border='0' align='absbottom' >");
    document.writeln("<img src='" + spacer + "' height='5'>");	
    ////document.writeln("<a target=new href=" + Server_HomePage + ">");
	document.writeln("</div>");
	document.writeln("</td>");
	document.writeln("</tr>");
	document.writeln("<tr><td><div align='right'><img src='" + spacer + "' width='5' height='4px' border='0'></div></td></tr>");
	document.writeln("<tr>");
	document.writeln("<td width='40%' align='right' class='sitesearch'>");
    	document.writeln("<SELECT class='search-dropdown' id='drop' name='drop'>");

	if(enableSearchWithInSite())
	{
		document.writeln("<OPTION VALUE=SearchWithinThisSite SELECTED>" + "Within MOM Website");
	}
    	document.writeln("<OPTION VALUE='SearchInAllGovSites'>" + "Within All 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><img src='" + spacer + "' height='5'>");
	document.writeln("</td>");
	document.writeln("</tr>");
	
	//document.writeln("</form>");
}

function ShowResults(magGlass, spacer, googleSearchIcon)
{   	
    document.writeln("<form method='get' target='new1' action='"+ Server_URL + "' onSubmit='Gsitesearch(this)' name=SearchPlugInfrm style='margin:0' > ");
    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("<tr><td ><div align='right'><img src='" + spacer + "' width='5' height='5px' border='0'></div></td></tr>");
	document.writeln("<tr>");
	document.writeln("<td align='center' valign='baseline'>");
	document.writeln("<div align='right'>");
    document.writeln("<img src='" + magGlass + "' width='15' height='15'>");
	document.writeln("<input type=text name=TextBoxSearch size="+ Search_Text_Box_Size + "  class='search-textfield'><input type=submit valign='bottom' name=SearchGo id=SearchGo class='search-button' value='Search' >");
    document.writeln("<img src='" + googleSearchIcon + "' border='0' align='absbottom' >");
    document.writeln("<img src='" + spacer + "' height='5'>");	
    ////document.writeln("<a target=new href=" + Server_HomePage + ">");
	document.writeln("</div>");
	document.writeln("</td>");
	document.writeln("</tr>");
	document.writeln("<tr><td><div align='right'><img src='" + spacer + "' width='5' height='4px' border='0'></div></td></tr>");
	document.writeln("<tr>");
	document.writeln("<td width='40%' align='right' class='sitesearch'>");
    	document.writeln("<SELECT class='search-dropdown' id='drop' name='drop'>");

	if(enableSearchWithInSite())
	{
		document.writeln("<OPTION VALUE=SearchWithinThisSite SELECTED>" + "Within MOM Website");
	}
    	document.writeln("<OPTION VALUE='SearchInAllGovSites'>" + "Within All 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><img src='" + spacer + "' height='5'>");
	document.writeln("</td>");
	document.writeln("</tr>");
	
	document.writeln("</form>");
}
