String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function GotoSearch(src)
{
	window.location.href ="/en/search/index.aspx?strSearch=" + escape(document.getElementById("searchField").value);
}

// Used for entering and leaving search textbox so the user doesn't have to clear the 'Search' text
function Search_Enter(searchTextbox) {

	if ( searchTextbox.value.toLowerCase() == 'recherche' || searchTextbox.value.toLowerCase() == 'search' )
		searchTextbox.value = '';

}

function Search_Leave(searchTextbox) {

	var url = document.location.href;

	if( url.indexOf("/en/") >= 0 && searchTextbox.value.trim() == '' )
		searchTextbox.value = 'Search';
	
	if( url.indexOf("/fr/") >= 0 && searchTextbox.value.trim() == '' )
		searchTextbox.value = 'Recherche';
	

}

// Hides inputs - This is used for Internet Explorer 6, as they show through the drop-down menu
function HideInputs() {
	
	var ver = navigator.appVersion;
	var isIE6 = ver.indexOf("MSIE 6.0") != -1;
	
	if ( isIE6 ) {
		
		var elements = document.getElementsByTagName("select");
		
		for (var i = 0; i < elements.length; i++) {
			elements[i].style.visibility = 'hidden';
		}		
		
	}

}

// Shows inputs
function ShowInputs() {

	var ver = navigator.appVersion;
	var isIE6 = ver.indexOf("MSIE 6.0") != -1;
	
	if ( isIE6 ) {
		
		var elements = document.getElementsByTagName("select");
		
		for (var i = 0; i < elements.length; i++) {
			elements[i].style.visibility = 'visible';
		}		
		
	}
	
}

function printerFriendly()
{

  if (document.getElementById != null)
  {
  
    var obj = document.getElementById('printArea');
    
    if (obj != null)
    {
      var content = "<html><head>";
      if (document.getElementsByTagName != null)
      {
        var obj_head = document.getElementsByTagName('head');
        if (obj_head != null)
          content += obj_head[0].innerHTML;
      }
      content += "</head><body style='background: none !important; background-color: #ffffff !important;'><table cellpadding='8' cellspacing='0' border='0' width='100%'><tr><td>" + obj.innerHTML + "<br/><a href=\"javascript:window.print()\">Print this page</a></td></tr></table>";
      content += "</body></html>";

      var printWindow = window.open("", "Print", "width=650,height=500,scrollbars=yes");
      printWindow.document.open();
      printWindow.document.write(content);
      printWindow.location.reload();
    }
  }
  else
	alert("You're browser is not capable of performing this operation!");
}

// Takes in a textbox reference, a label ID and the max # of characters that can go into the textbox
// When the input reaches the maxChars limit any further typing is 'cut-off' and the 
// label (displaying the number of characters left) turns red
function Counter(textbox, label, maxChars) {

	lbl = document.getElementById(label);
	
	if (textbox.value.length >= maxChars) {
		lbl.style.color = 'red';
		textbox.value = (textbox.value).substring(0, maxChars);
		textbox.scrollTop = textbox.scrollHeight;		
	}
	
	else {
		lbl.style.color = 'black';
	}
	
	lbl.innerHTML = maxChars - ( textbox.value.length );

}

function mailTo()
{

	var str = document.location.href;
	var lang = "/fr/";
	
	if(str.indexOf("/en/") >= 0)
		lang = "/en/";
	
	if (document.getElementById != null)
	{
	
		var obj = document.getElementById('printArea');
		
		if (obj != null)
		{
		
			var content = "";
			
			if (document.getElementsByTagName != null)
			{
			
				var obj_head = document.getElementsByTagName('head');
				
				if (obj_head != null)
				{
					content += obj_head[0].innerHTML;
				}
				
			}
      
			content += "\n<body style='background-color: #fff;'><div id='searchResults'><table cellpadding='8' cellspacing='0' border='0' width='100%'><tr><td>" + obj.innerHTML + "</td></tr></table></div>";
			content += "</body>";

			document.forms['frmMailTo'].hdnContent.value = content;

			var newWin = window.open(lang + "email/MailTo.aspx", "MailTo", "width=600,height=350,status=yes,menubar=no,location=no,resizable=yes");
			
		}
	}
	
	else
	{
		alert("You're browser is not capable of performing this operation!");
	}
	
}