// - - - Start - Configuration - Settings the Agency can modify - - - //
var Enable_Search_Within_This_Site = true;
var Enable_Search_Within_Agency = true;
var Results_Per_Page = 10;
var Search_Text_Box_Size = 20;
var Server_URL = "http://sgms.internet.gov.sg/search";
var Server_HomePage = "http://mysearch.internet.gov.sg/";
var Collections = "";
var SiteSearchItems = "";
var MetaDataFilters = "";
var Banner = "";
var AdditionalDropDownItems = "";
var Catalogue = "";

// Change the following paramter manually if its not desirable to get the website domain automatically.
//var URLStr = "http://www.gov.sg";
var URLStr = "http://he.ecitizen.gov.sg/";

//Specify the Website's Feedback URL here e.g. www.mywebsite.gov.sg/feedback.html
var paramFeedbackPageURL ="http://he.ecitizen.gov.sg/hecorp/feedback.aspx";


//Specify the Website's Contact Info URL here e.g. www.mMywebsite.gov.sg/ContactInfo.html
var paramContactInfoPageURL ="http://he.ecitizen.gov.sg/hecorp/contact.aspx";


// Specify additional drop down options using the following //
AdditionalDropDownItems =
[

]

// Specify additional Catalgoue options using the following //
Catalogue =
[
//["Within This Website", "102"]
]


// Specify additional Collection options using the following //
Collections =
[
	["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 =
[
	//["Within This Website", "app.reach.gov.sg"]
]

// - - - 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 SetResultsPerPage()
{
	return Results_Per_Page;
}

var mtr = 0
function checkInputIsEmpty(){
	if (document.all.TextBoxSearch.value.replace(/^(\s+)?(.*\S)(\s+)?$/, '$2') == "") {
		mtr = 1
	}
	else mtr = 0
}

function SetDDValue()
{
	var varCombo = "";
	var combo = document.forms[0].drop
	for ( i=0;i<combo.options.length;i++)
	{
		varCombo = varCombo + "^" + combo.options[i].text + "," + combo.options[i].value + ",";
		if (i == combo.options.selectedIndex)
			varCombo = varCombo + "SELECTED"
		var varTemp = ",";
		for(j=0;j<AdditionalDropDownItems.length;j++)
		{
			if (AdditionalDropDownItems[j][0] == combo.options[i].text)
			varTemp = "," + AdditionalDropDownItems[j][1];
		}
		varCombo = varCombo + varTemp;
		for(j=0;j<Catalogue.length;j++)
		{
			if (Catalogue[j][0] == combo.options[i].text)
				varTemp = "CATalogue";
		}
		varCombo = varCombo + varTemp;
	}
	document.forms[0].iNPUTcombo.value = varCombo;
}


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>");

	document.writeln("<form method='GET' target='_blank' name='SearchPlugInfrm' action='" + Server_URL + "' >");
	document.writeln("<table border='0' style='background:transparent; border-collapse:collapse;' cellspacing='0' cellpadding='0'>");
	//document.writeln("<tr><td>Search&nbsp;&nbsp;</td><td align='right'>");
	document.writeln("<input type='text' id = 'q' name='q' size='"+ Search_Text_Box_Size + "' style='visibility:hidden'> ");
	if (Collections != "")
	{
		var param_site_value = ""; //Do not remove

		document.writeln("<SELECT name='site' style='visibility:hidden'>");
		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>");
		document.writeln("<tr><td>&nbsp;</td><td align='right'>");
		for (i = 0; i < SiteSearchItems.length; i++)
		{
			document.writeln("<input type='radio' id='sitesearch' name='sitesearch' VALUE=" + SiteSearchItems[i][1] +" style='visibility:hidden'>");

			//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' value='" + paramFeedbackPageURL + "' name='paramFeedbackPageURL'  />");
	//document.writeln("<input type='hidden' value='" + paramContactInfoPageURL + "' name='paramContactInfoPageURL' />");
	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("</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 showSearchBox()
{
		document.writeln("<table border=0 cellspacing=1 cellpadding=0 height='100%'> <tr><td nowrap valign=top>");
		document.writeln("<strong>Search</strong> &nbsp; <input type=text id =TextBoxSearch name=TextBoxSearch size="+ Search_Text_Box_Size + " onkeypress='javascript:submitSearchWithEnter(event);' onkeyup='javascript:copydata(this.value);' class=SearchTextBox></td>");
		document.writeln("<td  >");
		document.writeln("<a href='#' onClick='submitSearch2();'><img border=0 src='/hecorp/uploadedimages/_system/btn_go_red.gif'></a>");
		document.writeln("</td>");
	    //document.writeln("<a target=new href=" + Server_HomePage + "><img src='/reach/images/online.gif'  border=0 alt='Singapore Government Online Search Home'></a>");
		document.writeln("</tr><tr><td colspan=2>");
		document.writeln("<SELECT id=site name=site class=SearchTextBox 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></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)) { submitSearch2();   return false; }
	else if ((e.which) && (e.which == 13)) { submitSearch2(); return false; }
	else return;
}

function submitSearch2()
{
	//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 localsearch()
{
		document.SearchPlugInfrm.sitesearch.checked = document.Form.sitesearch.checked;
}