// - - - 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 = 45;
var Option_Drop_Down_Size = 30;
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";

//Specify the Website's Feedback URL here e.g. www.mywebsite.gov.sg/feedback.html
var paramFeedbackPageURL="";

//Specify the Website's Contact Info URL here e.g. www.mMywebsite.gov.sg/ContactInfo.html
var paramContactInfoPageURL="";


// 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 =
[
	["SG Customs", "www.customs.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 clearSelectedRadio(radioId) 
{
    var x=document.getElementsByName(radioId); 
    for(i=0;i<x.length;i++){x[i].checked=false;}
    document.getElementById('btnG').focus();
}


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 style = 'visibility:hidden' 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='hidden' name='q' size='"+ Search_Text_Box_Size + "'> ");
	//document.writeln("<input type=hidden name=TextBoxSearch size="+ Search_Text_Box_Size + "></td>");
	//document.writeln("<input type=hidden id=drop name=drop>");
	//document.writeln("<input type=hidden id=site name=site>");
	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_collection' />");
	}

	//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("<td align='right'><a href='#' style = 'visibility:hidden' onclick=clearSelectedRadio('sitesearch'); class='fLink'>Clear</a>");
			for (i = 0; i < SiteSearchItems.length; i++)
			{
				document.writeln("<input type='radio' style = 'visibility:hidden' 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("<input id=ResultsPerPage type=hidden value=" + SetResultsPerPage() + " name=ResultsPerPage>");

	document.writeln("<input id=currentURL type=hidden value=" + SplitResTry + " name=currentURL>");
	document.writeln("<input id='iNPUTcombo' type=hidden name='iNPUTcombo' />");
	document.writeln("<input id=inputBanner type=hidden style='display:none' value=" + Banner + " name=inputBanner />");
	document.writeln("<input type=hidden value='DecentralizedInternet' name=EntryPage />");
	

	document.writeln("</form>");

}


function showSearchBox()
{
		document.writeln("<table border=0 width='100%' border=0 cellspacing=0 cellpadding=0> <tr><td class='search'>Search&nbsp;</td><td nowrap>");
			document.writeln("<input type=text name=TextBoxSearch size="+ Search_Text_Box_Size + " onkeypress='javascript:submitSearchWithEnter(event);' onkeyup='javascript:copydata(this.value);' class='search'></td>");
			document.writeln("<td  valign='bottom'>");
			document.writeln("<a href='javascript:void(0);' onclick='submitSearch()'><img src='" + strCodeBase + "static/images/common/go_button.gif' border=0></a>");	
			//document.writeln("<input type=image valign='bottom' name=SearchGo id=SearchGo src='" + Server_HomePage + "/images/header-button-go.gif' value='Search' >");
			//document.writeln("</td><td>");
		    //document.writeln("<a target=new href=" + Server_HomePage + "><img src=" + Server_HomePage + "/images/Dconlinesearch.gif  border=0 alt='Singapore Government Online Search Home'>");
	document.writeln("</td></tr><tr><td align=right colspan=5>")
	
		if(SiteSearchItems != "")
			{
				document.writeln("<a href='#' onclick=clearSelectedRadio('stesearch'); class='fLink'>Clear</a>");
				for (i = 0; i < SiteSearchItems.length; i++)
					document.writeln("<input id=stesearch type=radio name=stesearch VALUE=" + SiteSearchItems[i][0] + " >" + SiteSearchItems[i][0]);
		
		}
		
		document.writeln("&nbsp;<SELECT id=drop name=drop  style='FONT-SIZE: 8.6pt;' 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]);
		}
		
		/*if(enableSearchWithInSite())
		{
			document.writeln("<OPTION VALUE=SearchWithinThisSite>" + "Within This Website");
		}*/
		
		//document.writeln("<OPTION VALUE='SearchInAllGovSites'>" + "Within All Singapore Gov Websites");
		document.writeln("<!--<OPTION VALUE='DNNSearch'>" + "Within This Website (secured)-->");
	
		/*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]);
		}*/
		
		document.writeln("</SELECT>");	
		
		//document.writeln("<input id='iNPUTcombo' type=hidden name='iNPUTcombo' />");
		document.writeln("</td></tr></table>");
}


//@ To submit Search Keyword to dedicated URL
//@ All input captured will be passed to the hidden form, and submit.
function submitSearch()
{
	//document.SearchPlugInfrm.TextBoxSearch.value = document.Form1.TextBoxSearch.value;
	//SetDDValue();
	//document.SearchPlugInfrm.drop.value = document.Form1.drop.value;
	//document.SearchPlugInfrm.iNPUTcombo.value = document.Form1.iNPUTcombo.value;	
	//document.SearchPlugInfrm.site.options.selectedIndex = document.Form1.options.selectedIndex;	
	document.SearchPlugInfrm.q.value = document.Form1.TextBoxSearch.value;
	document.SearchPlugInfrm.site.options.selectedIndex = document.Form1.drop.options.selectedIndex;
	document.SearchPlugInfrm.sitesearch.checked = document.Form1.stesearch.checked;
	document.SearchPlugInfrm.submit();
}



//@ 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 copydata(tmp)
{
	document.SearchPlugInfrm.q.value = tmp;
	//document.SearchPlugInfrm.TextBoxSearch.value = tmp;
}
function dochange(tmp)
{
	//alert(tmp.options.selectedIndex);

	document.SearchPlugInfrm.site.options.selectedIndex = tmp.options.selectedIndex;
}

function clearSelectedRadio(radioId) 
{
    var x=document.getElementsByName(radioId); 
    for(i=0;i<x.length;i++){x[i].checked=false;}
    document.getElementById('btnG').focus();
}

 