/*------------------------------------------------------------

cga.js

author: Sing Chan
last modified: July 6, 2007

Dependencies:
    global.js (event handling functionality)

------------------------------------------------------------*/

/*------------------------------------------------------------
name.dll override 
------------------------------------------------------------*/
// Please leave this comment in place
// Created by: Randy Drisgill (The Mossman)
// August 17, 2007
//
// THIS OVERRIDES THE OOTB SHAREPOINT FUNCTION WHICH CAUSES ACTIVEX INSTALL ISSUES
//
// Essentially it overrides the ootb sharepoint function which calls the activex object
// See http://support.microsoft.com/default.aspx/kb/931509 for info on the issue
//
// To use in masterpage use this syntax in the <head>:
//  	<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
//   	<script type="text/javascript" src="/_catalogs/masterpage/custom_activex_override.js"></script>


	function ProcessDefaultOnLoad(onLoadFunctionNames)
	{
		//** Uncomment this to see when this runs
		//alert('Fixing the Issue');
		
		ProcessPNGImages();
		UpdateAccessibilityUI();
		
		//** We comment out the offending ootb function
		//** and leave the rest of the functions as they were
		//ProcessImn();
		for (var i=0; i < onLoadFunctionNames.length; i++)
		{
			var expr="if(typeof("+onLoadFunctionNames[i]+")=='function'){"+onLoadFunctionNames[i]+"();}";
			eval(expr);
		}
		if (typeof(_spUseDefaultFocus)!="undefined")
			DefaultFocus();
	}	


/*------------------------------------------------------------

Associations DDL

------------------------------------------------------------*/

function OpenAssociation(el) {
	var url = el.options[el.selectedIndex].value;
	if (url != "") {
		window.open(url);
		el.selectedIndex = 0;
	}
}





/*------------------------------------------------------------

search

------------------------------------------------------------*/

function GetCGASearchKeyword() {
	var keyword = GetQueryStringVar("k");

	return (keyword);
}

function FormatCGASearchStats() {
	var keyword =  " <em>" + GetCGASearchKeyword() + "</em>";
	var isFrench = (location.href.toLowerCase().indexOf("fr-ca") != -1);

	var wordsEn = ["You searched for:", "for:", "Results", "of about", "of"]; //array of English words to replace
	var wordsFr = ["You searched for (fr):", "pour :", "R&#233;sultats", "de", "de"]; //array of replacement french words
	
	var divs = document.getElementsByTagName("div"); // search stats elements to target
	var tmp;
	var statsCount = 0; // search stats elements found
	
	
	for (var i = 0; i < divs.length; i++) {
		if (divs[i].className == "srch-stats") {
			// if we're second instance of search stats, display keyword only.
			if (statsCount > 0) {
				tmp = wordsEn[0] + keyword;
			} else {
				tmp = divs[i].innerHTML;

				// strip b tags
				tmp = tmp.replace("<B>", "");
				tmp = tmp.replace("</B>", "");
				tmp = tmp.replace("<b>", "");
				tmp = tmp.replace("</b>", "");

				// append keyword string
				tmp = tmp.substring(0, tmp.length - 1) + " " + wordsEn[1] + keyword;
			}

			// if french, localise strings
			if (isFrench) {
				for (var j = 0; j < wordsEn.length; j++) {
					tmp = tmp.replace(wordsEn[j], wordsFr[j]);
				}
			}

			divs[i].innerHTML = tmp;
			statsCount++;
		}
	}

}

function FormatCGASearchActionLinks() {
	var isFrench = (location.href.toLowerCase().indexOf("fr-ca") != -1);

	var wordsEn = ["Results by Relevance", "View by Modified Date", "View by Relevance", "Results by Modified Date"]; //array of English words to replace
	var wordsFr = ["R&#233;sultats par pertinence", "Afficher par date de derni&#232;re mise &#224; jour", "Afficher par pertinence", "R&#233;sultats par date de derni&#232;re mise &#224; jour"]; //array of replacement french words

	var divs = document.getElementsByTagName("div"); // search stats elements to target
	var tmp;

	for (var i = 0; i < divs.length; i++) {
		if (divs[i].className == "srch-sort-right") {
			if (isFrench) {
				tmp = divs[i].innerHTML;
				tmp = String(tmp);
	
				for (var j = 0; j < wordsEn.length; j++) {
					tmp = tmp.replace(wordsEn[j], wordsFr[j]);
					tmp = tmp.replace(wordsEn[j], wordsFr[j]);
				}

				divs[i].innerHTML = tmp;

			}
		}
	}
}

function FormatCGASearchCoreResults() {
	var ol = document.getElementById("cga-SearchCoreResults");
	var startNum = GetQueryStringVar("start1");

	if (startNum != "") ol.start = startNum;
}

function FormatCGASearch() {
	if (document.getElementById) {
		FormatCGASearchStats();
		FormatCGASearchActionLinks();
		FormatCGASearchCoreResults();
	}
}


AddEvent(window, "load", FormatCGASearch, false);

