// - - - 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 = 15;
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 = "http://www.scdf.gov.sg/";


//Specify the Website's Feedback URL here e.g. www.mywebsite.gov.sg/feedback.html
var paramFeedbackPageURL="http://www.scdf.gov.sg/feedback.html";

//Specify the Website's Contact Info URL here e.g. www.mMywebsite.gov.sg/ContactInfo.html
var paramContactInfoPageURL="http://www.scdf.gov.sg/contact.html";

// 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 =
[
]
// - - - 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 ShowResults1()
{
	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> <tr><td style='font-family:arial;font-size:11pt;color:#000000;'><b>Search</b></td><td nowrap>");
	//document.writeln("<input type=text name=TextBoxSearch size="+ Search_Text_Box_Size + "></td>");
	//document.writeln("<td  valign='bottom'>");
	
	//document.writeln("<a href='#' onclick='submitSearch()'><img name=SearchGo id=SearchGo src='" + Server_HomePage + "/images/header-button-go.gif'  value='Search' 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 + ">");
	//document.writeln("</td></tr><tr><td>&nbsp;</td><td colspan=3>");
	//document.writeln("<SELECT id=drop name=drop>");
	//if(enableSearchWithInSite())
	//{
	//	document.writeln("<OPTION VALUE=SearchWithinThisSite SELECTED>" + "Within AGC Website");
	//}	
	//document.writeln("<OPTION VALUE='SearchInAllGovSites'>" + "Within All Singapore Gov Websites");
	
	//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] +">" + Catalogue[i][0]);
	//}
	//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>");
}


function ShowResults()
{
	document.writeln("<form method=post target='_blank' 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("<input type=hidden name=TextBoxSearch size="+ Search_Text_Box_Size + "></td>");
	document.writeln("<input type=hidden valign='bottom' name=SearchGo id=SearchGo src='" + Server_HomePage + "/images/header-button-go.gif' value='Search' >");	
	document.writeln("<input type=hidden id=drop name=drop>");	
	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>");
}

function ShowForm()
{
	//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 align='right'> <tr><td></td><td nowrap>");
	document.writeln("<b><font face=Arial size=2 color=#000000>Search</font></b>&nbsp;<input type=text name=TextBoxSearch size="+ Search_Text_Box_Size + "></td>");
	document.writeln("<td  valign='bottom'>");
	document.writeln("<a href='#' onclick='submitSearch()'><img name=SearchGo id=SearchGo src='" + Server_HomePage + "/images/header-button-go.gif'  value='Search' border='0' /></a>");	document.writeln("</td><td>");
    document.writeln("<a target=new href=" + Server_HomePage + ">");
	document.writeln("</td></tr><tr><td>&nbsp;</td><td colspan=3>");
	document.writeln("<SELECT id=drop name=drop>");
	document.writeln("<OPTION VALUE='SearchInAllGovSites' SELECTED>" + "Within All Local Gov Websites");

	if(enableSearchWithInSite())
	{
		document.writeln("<OPTION VALUE=SearchWithinThisSite>" + "Within SCDF 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] +">" + Catalogue[i][0]);
	}
	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>");
}




function submitSearch()
{
	document.SearchPlugInfrm.TextBoxSearch.value = document.forms[0].TextBoxSearch.value;
	SetDDValue();
	document.SearchPlugInfrm.drop.value = document.forms[0].drop.value;
	document.SearchPlugInfrm.iNPUTcombo.value = document.forms[0].iNPUTcombo.value;	
	document.SearchPlugInfrm.submit();
}


