﻿//
// LimitText - limits the amount of text a user can type in a multi-line
//			   asp.net textbox (MaxLength only works for single-line textboxes).
//
// NOTE: This function must be called by both the "onkeydown" and "onkeyup" events
//		 of the asp.net textbox to work properly.
//
// objTextBox = the textbox object whose text should be limited
// iCharLimit = the character limit
//
function LimitText(objTextBox, iCharLimit, bShowAttachFileMessage)
{
	if (!objTextBox) return;
	if (!objTextBox.value) return;
    
	if (objTextBox.value.length > iCharLimit)
	{
		objTextBox.value = objTextBox.value.substring(0, iCharLimit);
		
		var errorMessage = "This field cannot exceed " + iCharLimit + " characters.";
		if (bShowAttachFileMessage) errorMessage += "  If more space is required, please consider attaching a file.  Thank you!";
		
		alert(errorMessage);
	}
}

//************************************
// Script to Change Text Size
function GetBodyCssRule()
{
    var stylesheet = document.styleSheets[0];
    var rules = stylesheet.cssRules ? stylesheet.cssRules : stylesheet.rules;
    var bodyRule;
    var i;
    
    for (i=0; i < rules.length; i++)
    {
        if(rules[i].selectorText.toLowerCase() == "body")
        return rules[i];
    }
}
function IncreaseFont()
{
    var bodyRule = GetBodyCssRule();
    if (!bodyRule) return;
    
    var size = parseInt(bodyRule.style.fontSize);
    var unit = bodyRule.style.fontSize.replace(size, "");
    if (size < 110) { bodyRule.style.fontSize = (size + 10) + unit; SetCookie("FontSize", bodyRule.style.fontSize); }
}
function DecreaseFont()
{
    var bodyRule = GetBodyCssRule();
    if (!bodyRule) return;
    
    var size = parseInt(bodyRule.style.fontSize);
    var unit = bodyRule.style.fontSize.replace(size, "");
    if (size > 70) { bodyRule.style.fontSize = (size - 10) + unit; SetCookie("FontSize", bodyRule.style.fontSize); }
}
function GetCookie(name)
{
    var start = document.cookie.indexOf("; " + name + "=");
	if (start == -1)
	{
	    start = document.cookie.indexOf(name + "=");
	    if (start != 0) return null;
	}
	else start += 2;    // Skip leading semi-colon
	
	var len = start + name.length + 1;
	var end = document.cookie.indexOf(';', len);
	if (end == -1) end = document.cookie.length;
	
	return unescape(document.cookie.substring(len, end));
}
function SetCookie(name, value) 
{
	var expireDate = new Date();
	expireDate.setFullYear(expireDate.getFullYear() + 1);
	
	DeleteCookie(name);
	document.cookie = name + '=' + escape(value) + ';path=;expires=' + expireDate.toGMTString();
}
function DeleteCookie(name) 
{
	if (GetCookie(name)) 
	    document.cookie = name + '=;path=;expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
function LoadFontCookie()
{
    var fontSize = GetCookie("FontSize");
    if (!fontSize) return;
    
    var bodyRule = GetBodyCssRule();
    if (bodyRule) bodyRule.style.fontSize = fontSize;
}
function setFocus() 
{
    document.getElementById('googlesearchtext').focus();
}
// End Text Size Script
//**********************************