// For clarifications on the below script, please contact shine_cs@ncs.com.sg
// - - - Start - Configuration - Settings the Agency can modify - - - //
// All values passed to GSA must be URL-encoded. eg. spaces must be replaced by char '+'
var Search_Text_Box_Size = 16;
var Server_URL = "http://sgms.internet.gov.sg/search"; 
var Collections = "";
var SiteSearchItems = "";
var MetaDataFilters = "";
var param_site_value = "";
var param_ssearch_value = "";

//Specify the Website's Feedback URL here e.g. http://www.mywebsite.gov.sg/feedback.html
//must have http:// as the start
var paramFeedbackPageURL ="http://sgms-web.internet.gov.sg/UIs/Feedback.aspx";

//Specify the Website's Contact Info URL here e.g. http://www.mywebsite.gov.sg/ContactInfo.html
var paramContactInfoPageURL ="http://sgms-web.internet.gov.sg/UIs/ContactInfo.aspx";


// Specify additional Collection options using the following //
Collections =
[
	["Within All Singapore Gov Websites", "default"],
	["Within Citizens And Residents", "within_cit_res"],
	["Within Business", "within_biz"],
	["Within Non-Residents", "within_non_res"],
	["Istana","istana"]
]

// Specify within this site (ie. sitesearch) options using the following //
// Only specify the website hosting this script
SiteSearchItems =
[
	["Results Within This Website", "www.istana.gov.sg"]
]
// - - - End - Configuration - - - //

function SetDDValue()
{
	var varCombo = "";
	var combo = document.forms[0].site
	
	for ( i=0;i<combo.options.length;i++)
	{
		//varCombo = varCombo + "^" + combo.options[i].text + "," + combo.options[i].value + ",";
		if (i == combo.options.selectedIndex)
		{
			document.forms[0].site.value = combo.options[i].value;
		}
	}
	
	var checkbox = document.forms[0].sitesearch
	if(checkbox.checked == true)
	{
		document.forms[0].sitesearch.value = SiteSearchItems[0][1];
	} else {
		document.forms[0].sitesearch.value = "";
	}
}

function SearchPainter()
{
	document.writeln("<table border='0' style='background:transparent; border-collapse:collapse;' cellspacing='0' cellpadding='0' width='310'");
	document.writeln("<tr><td align='left'>");
	document.writeln("<table cellspacing='0' cellpadding='0' border='0'>");
	document.writeln("<td style='FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #666666; FONT-FAMILY: Arial;'>Search&nbsp;</td><td align='left'>");
	document.writeln("<input type='text' name='q' size='"+ Search_Text_Box_Size + "' style='font-size:11px' onkeypress='JavaScript:SubmitSearchwtEnter(event)'>");
	document.writeln("</td>");
	if(SiteSearchItems != "")
	{
		var param_ssearch_value = ""; //Do not remove
		document.writeln("<td align='right'>");
		for (i = 0; i < SiteSearchItems.length; i++)
		{
			document.writeln("<input type='checkbox' name='sitesearch' VALUE=" + SiteSearchItems[i][1] +"><span style='font-size:11px;font-family: Arial, Helvetica, sans-serif;'>" + SiteSearchItems[i][0] + "</span>");

			//Do not remove
			param_ssearch_value += SiteSearchItems[i][0] + "#" + SiteSearchItems[i][1] + "|";
		}
		//Do not remove
		document.writeln("<input type='hidden' name='filter_ss' value='" + param_ssearch_value + "' />");
		document.writeln("</td>");
	}
	document.writeln("</tr></table>");
	document.writeln("</td></tr>");
	document.writeln("<tr><td>");
	document.writeln("<table cellspacing='0' cellpadding='0' border='0' align='right'>");
	document.writeln("<td>");
	
	if (Collections != "")
	{
		var param_site_value = ""; //Do not remove

		document.writeln("<SELECT name='site' style=font-size:11px>");
		for (i = 0; i < Collections.length; i++)
		{
			document.writeln("<OPTION VALUE=" + Collections[i][1] +">" + Collections[i][0]);

			//Do not remove
			param_site_value += Collections[i][0] + "#" + Collections[i][1] + '|';
		}
		document.writeln("</SELECT>");

		//Do not remove
		document.writeln("<input type='hidden' name='filter_s' value='" + param_site_value + "' />");
	}
	else
	{
		//Do not remove
		document.writeln("<input type='hidden' name='site' value='default_collection' />");
	}
	
	document.writeln("</td>");
	document.writeln("<td>");
	document.writeln("<input type='image' name='btnG' style='position:relative; top:2' alt=SearchGo src=" + "/istana/images/header-button-go.gif value='Go' align=right/ onclick='JavaScript:SubmitSearch(event)'>");
	document.writeln("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>");
	document.writeln("</tr></table>");
	document.writeln("</td></tr></table>");
}

function ShowResults()
{
	document.writeln("<form method='GET' target='_blank' name='SearchPlugInfrm' action='" + Server_URL + "' onsubmit='SetDDValue();'>");
	document.writeln("<input id='filter_s' type=hidden name='filter_s' value='"+param_site_value+"' />");
	document.writeln("<input type='hidden' name='filter_ss' value='" + param_ssearch_value + "' />");
	document.writeln("<input type='hidden' name='sitesearch' value='' />");
	document.writeln("<input type='hidden' value='" + paramFeedbackPageURL + "' name='feedback_url'  />");
	document.writeln("<input type='hidden' value='" + paramContactInfoPageURL + "' name='contact_url' />");
	document.writeln("<input type='hidden' name='client' value='default' />");
	document.writeln("<input type='hidden' name='proxystylesheet' value='default' />");
	document.writeln("<input type='hidden' name='output' value='xml_no_dtd' />");
	
	document.writeln("<input type=hidden name=SearchSubmit value=Search>");
	//[ TextBoxSearch ] changed: type = hidden
	document.writeln("<input type=hidden name=q size="+ Search_Text_Box_Size + "></td>");
	document.writeln("<input type='hidden' name='btnG' style='background-color:#c84141; font-size:85%; color:white; border:outset 1px #fff; width:30px; cursor:hand' value='Go' onclick='JavaScript:SubmitSearch(event)'/>"); 
	//[ site ] changed: type = hidden
	document.writeln("<input type=hidden name=site value=''>");
	
	document.writeln("</form>");
}

function SubmitSearch(e)	
{
	document.SearchPlugInfrm.q.value = document.Form1.q.value;
	SetDDValue();
	document.SearchPlugInfrm.site.value = document.Form1.site.value;
	document.SearchPlugInfrm.filter_s.value = document.Form1.filter_s.value;
	document.SearchPlugInfrm.filter_ss.value = document.Form1.filter_ss.value;
	document.SearchPlugInfrm.sitesearch.value = document.Form1.sitesearch.value;
	if (navigator.userAgent.indexOf("MSIE") != -1)//IE
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	else//NS, Firefox
	{
		e.preventDefault();
		e.stopPropagation();
	}
	document.SearchPlugInfrm.submit();
}

function SubmitSearchwtEnter(e)	
{
	if (!e) var e = window.event;
	if ((e.keyCode) && (e.keyCode == 13)) SubmitSearch();
	else if ((e.which) && (e.which == 13)) SubmitSearch();
	else return;
}

function clearSelectedRadio(radioId) 
{
    var x=document.getElementsByName(radioId); 
    for(i=0;i<x.length;i++){x[i].checked=false;}
    document.getElementById('btnG').focus();
}