// - - - 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 = 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";
//var URLStr = "http://app-stg.supremecourt.gov.sg";

//Specify the Website's Feedback URL here e.g. www.mywebsite.gov.sg/feedback.html
var paramFeedbackPageURL ="http://app-stg.supremecourt.gov.sg/default.aspx?pgID=25";


//Specify the Website's Contact Info URL here e.g. www.mMywebsite.gov.sg/ContactInfo.html
var paramContactInfoPageURL ="http://app-stg.supremecourt.gov.sg/default.aspx?pgID=47";


// 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 Supreme Court Website", "supcourt"],
	["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.supcourt.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.writeln("<div style='height:0px'><form style='display:inline;MARGIN-LEFT: 0pt; MARGIN-RIGHT: 0pt; MARGIN-TOP: 0pt; MARGIN-BOTTOM: 0pt;' method='GET' target='_blank' name='SearchPlugInfrm' action='" + Server_URL + "' >");
	document.writeln("<input type='hidden' id = 'q' name='q' size='"+ Search_Text_Box_Size + "'>");
	
	if (Collections != "")
	{
		var param_site_value = ""; //Do not remove
		document.writeln("<SELECT name='site' style='display:none'>");
		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='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("</form></div>");
}

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("<img border=0 src='http://internet-stg.supremecourt.gov.sg/static/images/common/search.gif' align=absmiddle alt=Search> <input style='font-size: 88%; width: 155px' 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='http://internet-stg.supremecourt.gov.sg/static/images/common/go.gif'></a>");
		document.writeln("</td>");
		document.writeln("</tr><tr><td colspan=2>");
		document.writeln("<SELECT id=site name=site style='font-size: 88%; margin-left: 45px; margin-bottom: 5px' 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>");
}


function showSearchBoxCN()
{
		document.writeln("<table border=0 cellspacing=1 cellpadding=0 height='100%'> <tr><td nowrap valign=top>");
		document.writeln("<img border=0 src='http://internet-stg.supremecourt.gov.sg/static/images/common/searchCN.gif' align=absmiddle alt=Search> <input style='font-size: 88%; width: 155px; margin-bottom: 3px; margin-right: 2px' 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='http://internet-stg.supremecourt.gov.sg/static/images/common/goCN.gif'></a>");
		document.writeln("</td>");
		document.writeln("</tr><tr><td colspan=2>");
		document.writeln("<SELECT id=site name=site  style='font-size: 88%; margin-left: 62px; margin-bottom: 5px; margin-right: 2px' 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)) { submitSearch(); 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;
}
