// - - - Start - Configuration - Settings the Agency can modify - - - //
var Enable_Search_Within_This_Site = false;
var Enable_Search_Within_Agency = false;
var Results_Per_Page = 10;
var Search_Text_Box_Size = 25;
var Server_URL = "http://mysearch.internet.gov.sg/UIs/Decentralized.aspx";
var Server_HomePage = "http://mysearch.internet.gov.sg/";
var Banner = "";
var AdditionalDropDownItems = "";
var Catalogue = "";

// Change the following paramter manually if its not desirable to get the website domain automatically.
//var URLStr = document.domain;
var URLStr = "http://www.agd.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 =
[
//	["Within Citizens & Residents", 'I80VNN4VY:AUDIENCE_CODES'],
//	["Within Business", "I80Y14E8Z:AUDIENCE_CODES"],
//	["Within Non-Residents", 'I80VOSC4S:AUDIENCE_CODES']
]

// Specify additional Catalgoue options using the following //
Catalogue =
[
	["Within AGD website", "118"]
]
// - - - 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("<form method=post target='new1' onsubmit='SetDDValue(); ' action='"+ Server_URL+ "' name=SearchPlugInfrm style='margin:0' >");	
	document.writeln("<input type=hidden name=XMLFlag value=false >");
	document.writeln("<input type=hidden name=SearchSubmit value=Search>");
	document.writeln("<table border=0 cellspacing=1 cellpadding=0 >");
	document.writeln("<tr>");	
	document.writeln("<td>");
	//document.writeln("<img src='images/icon_search.gif' width='15' height='15'>");
	document.writeln("<input type=text name=TextBoxSearch size="+ Search_Text_Box_Size + ">");
	document.writeln("<input type=image valign='bottom' name=SearchGo id=SearchGo src='" + Server_HomePage + "/images/header-button-go.gif' value='Search' >");
	document.writeln("</td>");
	document.writeln("</tr>");
	document.writeln("<tr><td>");
	document.writeln("<SELECT id=drop name=drop>");

	if(enableSearchWithInSite())
	{
		document.writeln("<OPTION VALUE=SearchWithinThisSite>" + "Within This Website");
	}
	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]);
	}
	if (Catalogue != "")
	{
		for (i = 0; i < Catalogue.length; i++)
			document.writeln("<OPTION VALUE=" + Catalogue[i][1] +" SELECTED>" + Catalogue[i][0]);
	}
	document.writeln("<OPTION VALUE='SearchInAllGovSites'>" + "Within All Singapore Gov Websites"); //new added
	document.writeln("</SELECT>");
	document.writeln("</td></tr></table>");
	if( URLStr.match("https://"))
	{
		URLStr = URLstr.replace("https://","");
	}
	else if (URLStr.match("http://"))
	{
		URLStr = URLStr.replace("http://","");
	}
	SplitResTry = URLStr.split("/");
	SplitResTry = SplitResTry[0].split(":");
	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 />");
	
	//New parameters added for Feedback and ContactInfo page - 23 June 2006
	document.writeln("<input type=hidden value='" + paramFeedbackPageURL + "' name='paramFeedbackPageURL'  />");
	document.writeln("<input type=hidden value='" + paramContactInfoPageURL + "' name='paramContactInfoPageURL' />");
	
	document.writeln("</form>");
}
