String.format = function( text )
{
	//check if there are two arguments in the arguments list
	if ( arguments.length <= 1 )
	{
		//if there are not 2 or more arguments there?s nothing to replace
		//just return the original text
		return text;
	}
	//decrement to move to the second argument in the array
	var tokenCount = arguments.length - 2;
	for( var token = 0; token <= tokenCount; token++ )
	{
		//iterate through the tokens and replace their placeholders from the original text in order
		text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ), arguments[ token + 1 ] );
	}
	return text;
};			

var strcxcode = "";
var strresultpage = "";
var strcofcode = "";
var striecode = "";
var strsite = "";
var strlan = "";
var strsearchbutton = "Search";
var boxid = "cse-search-local";

function RenderGoogleSearchBox(siteName){
	switch(siteName){
		case "67": //News
			strresultpage = "/Search/Results";
			strcxcode = "017366314259320392759:ob-iyuorrpk";
			strcofcode = "FORID:11";
			striecode = "ISO-8859-1";
			strsite = "67";
			strlan = "en";
			strsearchbutton = "News Search";
			boxid = "cse-search-local";
		break;
		
		case "70": // Games
			strresultpage = "/Search/Results";
			strcxcode = "017366314259320392759:pmvyu1dfp-m";
			strcofcode = "FORID:11";
			striecode = "ISO-8859-1";
			strsite = "70";
			strlan = "en";
		break;
		
		case "72": // Xuan
			strresultpage = "/Search/Results";
			strcxcode = "017366314259320392759:im5zeujuvu4";
			strcofcode = "FORID:11";
			striecode = "UTF-8";
			strsite = "72";
			strlan = "en";
			strsearchbutton = "";
		break;

		
	}
	
	var scriptStr = "<script type='text/javascript'>" + 
				  "google.load('search', '1');" + 
				  "google.setOnLoadCallback(function() {" + 
					"google.search.CustomSearchControl.attachAutoCompletion(" + 
					  "'{0}'," + 
					  "document.getElementById('q')," + 
					  "'{6}');" + 
				  "});" + 
				"</script>" + 
				"<form name='google_search' action='{1}' id='{6}'>" + 
				  "<div>" + 
					"<input type='hidden' name='cx' value='{0}' />" + 
					"<input type='hidden' name='cof' value='{2}' />" + 
					"<input type='hidden' name='ie' value='{3}' />" + 
					"<input type='text' name='q' id='q' autocomplete='off' /> " + 
					"<input type='submit' name='sa' value='{5}' />" + 
				  "</div>" + 
				"</form>" + 
				"<script type='text/javascript' src='http://www.google.com/cse/brand?form={6}&lang={4}'></script>";

	scriptStr = String.format(scriptStr, strcxcode, strresultpage, strcofcode, striecode, strlan, strsearchbutton, boxid);
	document.write(scriptStr);
}

function ShowMessage(message)
{
	alert(message);
}
