// 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 = 21;
var Server_URL = "http://sgms.internet.gov.sg/search";
var Collections = "";
var SiteSearchItems = "";
var MetaDataFilters = "";
//Specify the Website's Feedback URL here e.g http://www.mywebsite.gov.sg/feedback.htm
//must begin with http://
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/contact.htm
// must begin with http://
var paramContactInfoPageURL="http://sgms-web.internet.gov.sg/UIs/ContactInfo.aspx";
// Specify additional Collection options using the following //
Collections =
[
["Within EnterpriseOne", "EnterpriseOne"],
["Within All Government Websites", "default"],
["Within Business", "within_biz"],
["Within Citizens And Residents", "within_cit_res"],
["Within Non-Residents", "within_non_res"]
]
// Specify within this site (ie. sitesearch) options using the following //
// Only specify the website hosting this script
SiteSearchItems =
[
// ["Results Within This Website", ""]
]
// - - - End - Configuration - - - //
   
function ShowResults()
{
	//document.write("<style type='text/css' media='screen,print'>");
	//document.write("html,input,td{font-family:Arial;font-size:80%;}");
	//document.write("select{font-family:Arial;font-size:90%}");
	//document.write(".fLink{font-family: Arial;font-size: 11px;text-decoration:underline;color:Blue;cursor:hand;}")
	//document.write("</style>");
	//border-collapse:collapse;'
	document.writeln("<form method='GET' target='_blank' name='SearchPlugInfrm' action='" + Server_URL + "' >");
	document.writeln("<DIV style='visibility:hidden; display:none;'>")
	document.writeln("<table border='0' cellspacing='0'cellpadding='0'>");
	document.writeln("<tr><td>Search&nbsp;&nbsp;</td><td align='right'>");
	document.writeln("<input type='text' name='q' size='"+ Search_Text_Box_Size + "'> ");
				
	if (Collections != "")
	{
		var param_site_value = ""; //Do not remove
		document.writeln("<SELECT id='site' name='site' >");
		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' />");
	}
	
	document.writeln("<input type='submit' name='btnG' style='background-color:#c84141;font-size:85%; color:white; border:outset 1px #fff; width:30px; cursor:hand' value='Go' />");
	document.writeln("</td></tr>");
	if(SiteSearchItems != "")
	{
		var param_ssearch_value = ""; //Do not remove
		document.writeln("<tr><td>&nbsp;</td><td align='right'><a href='#' onclick=clearSelectedRadio('sitesearch'); class='fLink'>Clear Site Option</a>");
		for (i = 0; i < SiteSearchItems.length; i++)
		{
			document.writeln("<input type='radio' name='sitesearch' VALUE=" + SiteSearchItems[i][1] +"><span style='font-size:11px'>" + 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></tr>");
	}

	document.writeln("</table>");
	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("</DIV>");
	document.writeln("</form>");
}
    
function clearSelectedRadio(radioId)
{
	var x=document.getElementsByName(radioId);
	for(i=0;i<x.length;i++){x[i].checked=false;}
	document.getElementById('btnG').focus();
}

function changeCollections(i)
{
	document.getElementById('site').selectedIndex = i;
}

function showSearchBox()
{
		document.writeln("<table border=0 cellspacing=0 cellpadding=0> <tr><td nowrap >");
		document.writeln("<input  type=text id =searchTerms name=TextBoxSearch onkeypress='javascript:submitSearchWithEnter(event);' onkeyup='javascript:copydata(this.value);' ></td>");
		
	    /*document.writeln("</tr><tr><td colspan=2><div class=skinned>");*/
		document.writeln("<td><div id=searchMenu>");
		/*document.writeln("<SELECT style='font-size: 15px;' id=site name=site onchange='javascript:return(dochange(this));'>");
		if (Collections != "")
		{
			for (i = 0; i < Collections.length; i++)
				document.writeln("<OPTION VALUE=" + Collections[i][1] +" bgcolor=yellow>" + Collections[i][0]);
		}
		
		document.writeln("</SELECT></div>");
		document.writeln("<div  onchange='javascript:return(dochange(this));'>");*/
		//document.writeln("<div><a onmouseover='mopen(25);' onmouseout='mclosetime();'><img class=searchDropImage src='/images/searchdropdown.jpg'></a><div id=m25 onmouseout='mclosetime()' onmouseover='mcancelclosetime()'>");
		document.writeln("<div><a onclick='mopen(25);' onmouseout='mclosetime();'><img class=searchDropImage src='/images/searchdropdown.jpg'></a><div id=m25 onmouseout='mclosetime()' onmouseover='mcancelclosetime()'>");
		if (Collections != "")
		{
			for (i = 0; i < Collections.length; i++)
			{
				//alert(Collections[i][0])
				var idLabel = "lb"+i;
				document.writeln("<a id="+idLabel+" onclick='changeLabel(this.id)'>" + Collections[i][0])+"</a>";
				//document.writeln("<a href='javascript:void(0)' onclick='changeCollections(" + i + ")'>" + Collections[i][0])+"</a>";
			}
		}
		
		document.writeln("</div></div></div>");

		document.writeln("</td>");
		document.writeln("<td style='vertical-align:top; padding:0; margin:0;'>");
		document.writeln("<a onClick='submitSearch();' ><img src='/Images/Spring/btnSearch.jpg' id='searchBtn' border='0' valign='bottom' style='vertical-align:bottom; padding:0; margin:0;' ></a>");
		document.writeln("</td></tr><tr><td colspan='3' style='text-align:left;'><label id='searchLabel'>"+Collections[0][0]+"</label></td></tr>");
		/*if(SiteSearchItems != "")
		{
			var param_ssearch_value = ""; //Do not remove

			document.writeln("<tr><td align='right' colspan =2><a href='#' onclick=clearSelectedRadio('sitesearch'); class='fLink'>Clear Option</a>");
			for (i = 0; i < SiteSearchItems.length; i++)
			{
				document.writeln("<input type='radio' id='sitesearch' name='sitesearch' VALUE=" + SiteSearchItems[i][1] +" onclick = 'javascript:localsearch()'  ><span style='font-size:11px'>" + 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></tr>");
		}*/
		document.writeln("<tr><td colspan=3 style='visibility:hidden;'><div class=skinned>");
		document.writeln("<SELECT style='font-size: 12px;' id=site name=site onchange='javascript:return(dochange(this));'>");
		if (Collections != "")
		{
			for (i = 0; i < Collections.length; i++)
				document.writeln("<OPTION VALUE=" + Collections[i][1] +" bgcolor=yellow>" + Collections[i][0]);
		}
		
		document.writeln("</SELECT></div>");
		document.writeln("</td></tr>");

		document.writeln("</table>");
}

function showSearchBoxHome()
{
		document.writeln("<table border=0 cellspacing=1 cellpadding=0 height='100%' > <tr><td valign=top style='FONT-SIZE: 10px; COLOR: #294053; FONT-FAMILY: Arial'> SEARCH &nbsp;</td><td nowrap valign=top >");
		document.writeln("<input type=text id =TextBoxSearch name=TextBoxSearch size="+ Search_Text_Box_Size + " onkeypress='javascript:submitSearchWithEnter(event);' onkeyup='javascript:copydata(this.value);' style='FONT-SIZE: 10px; COLOR: #294053; FONT-FAMILY: Trebuchet MS,Arial,Tahoma,sans-serif'>");
		//document.writeln("</td><td valign=top>");
		document.writeln("<br>");
	    //document.writeln("</tr><tr><td>&nbsp;</td><td  valign=top colspan=2>");
		document.writeln("<SELECT id=site name=site style='FONT-SIZE: 10px; COLOR: #294053; FONT-FAMILY: Trebuchet MS,Arial,Tahoma,sans-serif; width:168px' onchange='javascript:return(dochange(this));'>");
		if (Collections != "")
		{
			for (i = 0; i < Collections.length; i++)
				document.writeln("<OPTION VALUE=" + Collections[i][1] +" bgcolor=yellow>" + Collections[i][0]);
		}
		
		document.writeln("</SELECT>");
		document.writeln("</td><td>");
		document.writeln("<a onClick='submitSearch();' ><img src='/EOS/EOSImages/go-button.gif' ></a>");
		document.writeln("</td></tr>");

		/*if(SiteSearchItems != "")
		{
			var param_ssearch_value = ""; //Do not remove

			document.writeln("<tr><td align='right' colspan =2><a href='#' onclick=clearSelectedRadio('sitesearch'); class='fLink'>Clear Option</a>");
			for (i = 0; i < SiteSearchItems.length; i++)
			{
				document.writeln("<input type='radio' id='sitesearch' name='sitesearch' VALUE=" + SiteSearchItems[i][1] +" onclick = 'javascript:localsearch()'  ><span style='font-size:11px'>" + 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></tr>");
		}*/
		document.writeln("</table>");
}

//@ For ENTER detection
function submitSearchWithEnter(e)	
{
	//var e = window.event;
	if ((e.keyCode) && (e.keyCode == 13)) { submitSearch();   return false; }
	else if ((e.which) && (e.which == 13)) { submitSearch(); return false; }
	else return;
}

function submitSearch()
{
	//document.SearchPlugInfrm.site.options.selectedIndex = document.Form.site.options.selectedIndex;
	document.SearchPlugInfrm.submit();
	//submitSearch();
}

function copydata(tmp)
{
	document.SearchPlugInfrm.q.value = tmp;
}

function dochange(tmp)
{
	document.SearchPlugInfrm.site.options.selectedIndex = tmp.options.selectedIndex;
}
function changeLabel(pLabel){
	
	var index = pLabel.substring(2,3)
	document.getElementById('searchLabel').innerHTML = Collections[index][0];
	//document.SearchPlugInfrm.site.options.selectedIndex = Collections[index][0];
	//document.getElementById('site').options.selectedIndex = Collections[index][0];
	document.getElementById('site').options.selectedIndex = index;
	document.SearchPlugInfrm.site.options.selectedIndex = index
	document.getElementById('m25').style.visibility = 'hidden';
}
