function textarealength(intLength, obj)
{
	if (obj.value.length > intLength-2)
	{
		alert("You have reached the maximum characters allowed for this field.");
		obj.value = obj.value.substring (0, intLength-1)
	}
}

function encodeProblemCharacters(str) 
{
      if (str.indexOf('&') > - 1) str = encodeCharacter(str, "&", "0026;");
      if (str.indexOf('#') > - 1) str = encodeCharacter(str, "#", "0023;");
      if (str.indexOf('+') > - 1) str = encodeCharacter(str, "+", "002B;");
      if (str.indexOf("'") > - 1) str = encodeCharacter(str, "'", "0060;");
      if (str.indexOf('%') > - 1) str = encodeCharacter(str, "%", "0025;");
      if (str.indexOf('=') > - 1) str = encodeCharacter(str, "=", "003D;");
      if (str.indexOf('|') > - 1) str = encodeCharacter(str, "|", "007C;");
      if (str.indexOf(' ') > - 1) str = encodeCharacter(str, " ", "0020;");
      return str;
}

function encodeCharacter(str, chr, encStr) 
{
	n = str.indexOf(chr);
	nlen = n;
	count = 0;
	while (n > - 1) {
		str = str.substring(0, nlen) + encStr + str.substring(nlen + chr.length, str.length);
		n = str.substring(nlen+encStr.length + chr.length, str.length).indexOf(chr);
		nlen += encStr.length + n + chr.length;
	}
	return str;
}
/*function encodeCharacter(str, chr, encStr) {
	var n = str.indexOf(chr);
	while (n > - 1) {
		str = str.substring(0, n) + encStr + str.substring(n+1, str.length);
		n = str.indexOf(chr);
	}
	return str;
}*/

function returnTop(el,start) {
	var t = 0;
	while (el) {
		t += el.offsetTop;
		el = el.offsetParent;
		if (el.tagName == "BODY" || el.tagName == "HTML") break;
	}
	return t;
}

String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}

// jyang: add default enter key pressed for search textbox
function enterKey(e, buttonid)
{ 
	var bt = document.getElementById(buttonid); 
  if (typeof bt == 'object'){ 
		if(navigator.userAgent.indexOf("Firefox") != -1)
    { 
			var versionindex = navigator.userAgent.indexOf("Firefox") + 8;
			if (parseInt(navigator.userAgent.charAt(versionindex)) >= 1)
			{
				if (e.which == 13)
				{ 
					//bt.click(); 
					redirectSearch();
					return false; 
				}
      } 
    } 
    if(navigator.appName.indexOf("Netscape")>(-1))
    { 
      if (e.keyCode == 13)
      { 
        redirectSearch();
        return false; 
      } 
    } 
    if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
    { 
      if (event.keyCode == 13)
      { 
        redirectSearch();
        return false; 
      } 
    } 
  }
} 

// jyang: client dropdown in day of month for event cast yearly event
function ValidateMonthDays(month)
{
	var x = document.getElementById(month.id);
	var y = null;
	if (month.id == 'EventCastYearly1_drpStartMonth')
	{
		y = document.getElementById('EventCastYearly1_drpStartDay');
	}
	else
	{
		y = document.getElementById('EventCastYearly1_drpEndDay');
	}
	var m = x.options[x.selectedIndex].value;
	// februrary, it will not have 29 as for leap year
	if (m == 2)
	{
		if (y.options[30] != null)	// day 31
		{
			y.options[30] = null;
		}
		if (y.options[29] != null)	// day 30
		{
			y.options[29] = null;
		}
		if (y.options[28] != null)	// day 29
		{
			y.options[28] = null;
		}
	}
	// 30-day months
	else if (m == 4 || m == 6 || m == 9 || m == 11)
	{
		if (y.options[30] != null)	// day 31
		{
			y.options[30] = null;
		}
		if (y.options[28] == null)	// day 29
		{
			y.options[28] = new Option(29, 29);
		}
		if (y.options[29] == null)	// day 30
		{
			y.options[29] = new Option(30, 30);
		}
	}
	// 31-day month
	else
	{
		if (y.options[28] == null)	// day 29
		{
			y.options[28] = new Option(29, 29);
		}
		if (y.options[29] == null)	// day 30
		{
			y.options[29] = new Option(30, 30);
		}
		if (y.options[30] == null)	// day 31
		{
			y.options[30] = new Option(31, 31);
		}
	}
}

function redirectSearch()
{
	var str = '/uppercanada/SPSSearchResult.aspx?searchText=' + encodeProblemCharacters(document.getElementById('txtSearchWords').value);
	location.href = str;
}