﻿function FLX_PreloadImages()
{
	var d=document;
	if(d.images) {
		if(!d.FLX_p) { d.FLX_p=new Array(); }
		var i,j=d.FLX_p.length,a=FLX_PreloadImages.arguments;
		for(i=0; i<a.length; i++) {
			if (a[i].indexOf("#")!=0){ d.FLX_p[j]=new Image; d.FLX_p[j++].src=a[i]; }
		}
	}
}

function FLX_SwapImgRestore()
{
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) { x.src=x.oSrc; }
}

function FLX_SwapImage()
{
	var i,j=0,x,a=FLX_SwapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=$(a[i]))!=null) {
		document.MM_sr[j++]=x;
		x.oSrc = (new RegExp(g_blankSrc).test(x.src) && x.realSrc) ? x.realSrc : x.src;
		x.src=a[i+2];
	}
}

function FLX_EvalOnEnter(e, buttonId)
{
	var evt = window.event || e;
	var keyCode = evt.keyCode;
	if (keyCode == 13) {
		__doPostBack(buttonId,'');
	}
}

function FLX_ParentByTag(node, tagName)
{
	var n = node;
	while (n.tagName != tagName) {
		n = n.parentNode;
	}
	return n;
}

function Widget_UpdateLimiters(increase, drag)
{
	if (drag.element.getAttribute('_needsTallLimiters')) {
		var top = $('WC0_WCT');
		var bot = $('WC0_WCB');
		if (increase) {
			top.setStyle( { height: '100px', margin: '-5px 0px -85px 0px' });
			bot.setStyle( { height: '200px', margin: '-185px 0px -5px 0px' });
		} else {
			top.setStyle( { height: '10px', margin: '0px' });
			bot.setStyle( { height: '10px', margin: '0px' });
		}
	}
}

/* PageHeader Class */
/*TODO: to be deleted after new UI for support/account/widget pages is implemented since it is replaced with titleBar control*/
function PageHeader(expanded, tableHeaderName, headerCollapsedName)
{
	this.isExpanded = expanded;
	this.tableHeader = $(tableHeaderName);
	this.headerCollapsed = $(headerCollapsedName);

	this.expand = function(expanded)
	{
		this.isExpanded = expanded;

		if (expanded) {
			this.headerCollapsed.hide();
			$('content').show();
			$('background').show();
			this.tableHeader.show();
		} else {
			this.headerCollapsed.show();
			$('content').hide();
			$('background').hide();
			this.tableHeader.hide();
		}
		
		this.show();
	};

	this.showExpanded = function()
	{
		$('headerContent').setStyle({
			'height' : $('content').getStyle('height')
		});

		var offset = Position.cumulativeOffset($('headerContent'));

		$('background').setStyle({
			'height': $('content').getStyle('height')
		});
	};

	this.showCollapsed = function()
	{
	};
		
	this.show = function()
	{
		if (this.isExpanded) {
			this.showExpanded();
		} else {
			this.showCollapsed();
		}
	}

	this.expand(this.isExpanded);
}

function textBox_CreateGroup(container)
{
	var boxes = $(container).getElementsByTagName('INPUT');
	for (var i=0; i<boxes.length; i++) {
		var box = boxes[i];
		if (i > 0) box._prev = boxes[i-1];
		if (i < boxes.length - 1) box._next = boxes[i+1];

		box.onkeyup = function(evt) {
			var evt = window.event || evt;
			var c = parseInt(String.fromCharCode(evt.keyCode));

			if (this.value.length == this.getAttribute('maxlength')) {
				if (this._next != null) { this._next.focus(); this._next.select(); }
			} else if (evt.keyCode == 8 && this.value.length == 0) { // backspace
				if (this._prev != null) { this._prev.focus(); this._prev.select(); }
			}
		};
	}
}

function MyDevices_ShowLastOffload(img)
{
	g_LastOffload.innerHTML = img.getAttribute('_LastOffload');
	g_LastOffload.parentNode.parentNode.style.fontWeight = 'bold';
	g_LastOffload.style.fontStyle = 'italic';

	var lbl = $(img.id.replace('_img', '_lbl'));
	lbl.style.fontWeight = 'bold';
	lbl.style.color = '#333333';

	var div = $(img.id.replace('_img', '_div'));
	div.style.fontWeight = 'bold';
	div.style.color = '#333333';
}

function MyDevices_HideLastOffload(img)
{
	g_LastOffload.innerHTML = g_LastOffload.getAttribute('_LastOffload');
	g_LastOffload.parentNode.parentNode.style.fontWeight = 'normal';
	g_LastOffload.style.fontStyle = 'normal';

	var lbl = $(img.id.replace('_img', '_lbl'));
	lbl.style.fontWeight = 'normal';
	lbl.style.color = '#FFFFFF';

	var div = $(img.id.replace('_img', '_div'));
	div.style.fontWeight = 'normal';
	div.style.color = '#FFFFFF';
}

function Home_InfoWindow(btnID, winID, align)
{
	this.Button = $(btnID);
	this.Window = $(winID);
	this.TimerID = 0;
	this.Align = align;

	this.ShowWindow = function()
	{
		var pos = this.Button.cumulativeOffset();

		if (this.Align == "right") {
			pos.left -= (this.Window.getWidth() - this.Button.getWidth() + 1);
		}

		this.Window.style.left = pos.left + 'px';
		this.Window.style.top = pos.top + 'px';
		this.Window.show();
	}

	this.OnMouseOut = function()
	{
		var instance = this;
		this.TimerID = setTimeout(function() { instance.OnTimerElapsed(); }, 5000);
	}

	this.OnMouseOver = function()
	{
		clearTimeout(this.TimerID);
	}

	this.OnTimerElapsed = function()
	{
		this.Window.hide();
	}

	var instance = this;

	this.Button.observe('click', function() { instance.ShowWindow(); });
	this.Window.observe('mouseout', function() { instance.OnMouseOut(); });
	this.Window.observe('mouseover', function() { instance.OnMouseOver(); });
}

function Login_HavingTrouble(userNameTextBoxId)
{
	this.userNameTextBox = $(userNameTextBoxId);
	var instance = this;

	this.Show = function()
	{
		$find('ReminderPasswordDlg').show();
		this.userNameTextBox.focus();
	}

	this.SendPassword = function()
	{
		var instance = this;
		FitLinxx.Web.UserService.SendPassword(this.userNameTextBox.value, 
			function(r) { instance.SendPasswordCallback(r); });
	}

	this.SendPasswordCallback = function(result)
	{
		if (result)
		{
		    if (result.Status == "PasswordSent")
		    {
				$find('ReminderPasswordDlg').hide();
				$find('ReminderPasswordVerifyDlg').show();
			}
			else
			{
				$('HavingTroubleDirectionalText').addClassName('invalid');
			    Event.observe(this.userNameTextBox, 'keyup', this.ClearValidationError );
				AHTextBox_SetInvalidCustomBackgroundClassName(this.userNameTextBox, '#FF4A4A', 'controlInErrorStateStyle2');
				if(!result.Text.blank())
				{
				    $('HavingTroubleValidationErrorsPanel').firstDescendant().update(result.Text);
				    $('HavingTroubleLinkButtons').firstDescendant().update('retry');
				    $('HavingTroubleValidationErrorsPanel').show();
				}
			}
		}
		else 
		{
				$('HavingTroubleDirectionalText').addClassName('invalid');
			    Event.observe(this.userNameTextBox, 'keyup', this.ClearValidationError );
				AHTextBox_SetInvalidCustomBackgroundClassName(this.userNameTextBox, '#FF4A4A', 'controlInErrorStateStyle2');
		}
	}

	this.Reset = function()
	{
	    $('HavingTroubleDirectionalText').removeClassName('invalid');
		AHTextBox_SetValid(this.userNameTextBox);
		$('HavingTroubleLinkButtons').firstDescendant().update('confirm');
		$('HavingTroubleValidationErrorsPanel').hide();
		this.userNameTextBox.value = "";
	}
	
	this.ClearValidationError = function()
	{
	    $('HavingTroubleDirectionalText').removeClassName('invalid');
		AHTextBox_SetValid($(userNameTextBoxId));
		$('HavingTroubleValidationErrorsPanel').hide();
	}

	this.UserNameKeyDown = function(e)
	{
		if (e.keyCode == 13) {
			g_HavingTrouble.SendPassword();
			return false;
		}
		return true;
	}
}

var SelectedCommunityID;
var SelectedCommunityLabelID;
var SelectedCommunityName;

//This method is used to truncate username in greeting panel (if needed)
function InitGreetingPanel()
{
	var userName = $$('#greetingText span')[0];
	var maxWidth = $$('#greetingText')[0].getStyle('width').substr(0, $$('#greetingText')[0].getStyle('width').length - 2)*1; 
	var userNameOriginalText = userName.innerHTML;
	var userNameText = userName.innerHTML;
	var truncated = false;
	var suffix = userNameText.substr(userNameText.length - 1, userNameText.length);;
	var userNameTextWithoutSuffix = userNameText.substr(0, userNameText.length - 1);
	while (userName.getWidth() > maxWidth) {
		userNameTextWithoutSuffix = userNameTextWithoutSuffix.substr(0, userNameTextWithoutSuffix.length - 1);
		userName.innerHTML = "<nobr>" + userNameTextWithoutSuffix + "..." + suffix + "</nobr>";
		truncated = true;
	}
	if(truncated) {
		userName.writeAttribute("title", userNameOriginalText);
	}
}

//This method is used to truncate tab name in activeGoal widget (if needed)
function InitActiveGoal()
{
	var tabnames = document.getElementsByClassName('GoalTabLabel');
	var maxWidth = 90;

	for (var i=0; i < tabnames.length; i++ ) {
		var userNameTextWithoutSuffix = tabnames[i].innerHTML;
		while (tabnames[i].getWidth() > maxWidth) {
			userNameTextWithoutSuffix = userNameTextWithoutSuffix.substr(0, userNameTextWithoutSuffix.length - 1);
			tabnames[i].innerHTML = userNameTextWithoutSuffix + "...";
		}
	}
}

var browser = function() {
	var ua = navigator.userAgent, gecko = /Gecko\//.test(ua) ? ua.match(/; rv:1\.(\d+?)\.(\d)/) : 0,
	webkit = /AppleWebKit/.test(ua), safari = webkit && /Safari\//.test(ua),
	ie = 0 /*@cc_on + @_jscript_version * 10 % 10 @*/;
	return {
		ie: ie >= 5 ? ie : 0,
		gecko: gecko ? '1.' + gecko.slice(1).join('.') : 0,
		firefox: gecko ? (gecko[1] == 9 ? 3 : gecko[1] == 8 && gecko[2] > 0 ? 2 : 0) : 0,
		opera: window.opera && opera.version ? opera.version()[0] : 0,
		webkit: webkit ? ua.match(/AppleWebKit\/(\d+?\.\d+?\s)/)[1] : 0,
		safari: safari && /Version\//.test(ua) ? ua.match(/Version\/(\d{1})/)[1] : 0,
		chrome: safari && /Chrome\//.test(ua) ? ua.match(/Chrome\/(\d+?\.\d)/)[1] : 0
	};
}();

function switchOverflow(oModalDialog)
{
	if(oModalDialog.style.overflow == 'auto') {
		oModalDialog.style.overflow = 'hidden';
	} else {
		oModalDialog.style.overflow = 'auto';
	}
}

function WidgetMenu_Window(btnID, winID, align)
{
	this.Button = $(btnID);
	this.Window = $(winID);
	this.TimerID = 0;
	this.Align = align;
	this.MouseOutFlag = false;

	this.ShowWindow = function()
	{
		if(tempSendPublicMessageControl && tempSendPublicMessageControl != null) {
			tempSendPublicMessageControl.ToggleTextBoxes(false);
		}
		if (this.Window.getStyle('display') == 'block') {
			this.Window.hide();
			this.OnMouseOver();
			Event.stopObserving(document.body, 'click', this.BoundHandleDocumentBodyClick);
		} else {
			this.Window.show();
			this.OnMouseOut();
			Event.observe(document.body, 'click', this.BoundHandleDocumentBodyClick);
		}
	}

	this.OnMouseOut = function()
	{
		this.TimerID = setTimeout(function() { instance.OnTimerElapsed(); }, 5000);
	}

	this.OnMouseOver = function()
	{
		clearTimeout(this.TimerID);
	}

	this.OnTimerElapsed = function()
	{
		this.Window.hide();
	}

	var instance = this;
	this.Button.observe('click', function() { instance.ShowWindow(); });
	this.Window.observe('mouseout', function() { instance.OnMouseOut(); });
	this.Window.observe('mouseover', function() { instance.OnMouseOver(); });

	this.HandleDocumentBodyClick = function(evt)
	{
		evt = evt || window.event;
		var obj = evt.target || evt.srcElement;
		if (this.Window.getStyle('display') == 'block' && !(this.Button == obj || this.Window == obj)) {
			this.Window.hide();
			Event.stopObserving(document.body, 'click', this.BoundHandleDocumentBodyClick);
		}
	}
	this.BoundHandleDocumentBodyClick = this.HandleDocumentBodyClick.bindAsEventListener(this);
}

function WidgetMenu_ChangeThemeName(DropDownId, TextBoxId)
{
	dd = $(DropDownId);
	tb = $(TextBoxId);

	tb.removeClassName(_userThemeMap[tb.value]);
	tb.value = dd.options[dd.selectedIndex].text;
	tb.addClassName(_userThemeMap[tb.value]);
}

function isNonPrintableKeyCode(keyCode)
{
	return _keyCodeToIdentifierMap[keyCode] ? true : false;
}

function DropDownList_SetValid(ddlID)
{
	var ddl = $(ddlID);
	ddl.removeClassName('dropDownInErrorState');
}

function DropDownList_SetValidCustomStyle(ddlID, className)
{
	var ddl = $(ddlID);
	ddl.removeClassName(className);
}

function DropDownList_SetInvalid(ddlID)
{
	var ddl = $(ddlID);
	ddl.addClassName('dropDownInErrorState');
}

function DropDownList_SetInvalidCustomStyle(ddlID, className)
{
	var ddl = $(ddlID);
	ddl.addClassName(className);
}

var TimerID;
var isChangedForm = false;

function validateRegistrationForm(UPClientID)
{
	clearTimeout(TimerID);
	isChangedForm = true;
	TimerID = setTimeout(function() { isChangedForm = false; __doPostBack(UPClientID,'');}, 2000);
}

function showFocusFieldToolTip(id)
{
	$('msgError').hide();
	$(id).show();
}

function hideFocusFieldToolTip(id)
{
	$(id).hide();
}

function findAndHideFocusFieldToolTip(panel_id)
{
	$(panel_id).childElements().each(function(child) {
		Element.hide(child);//child.hide();
	});
}

//Class to manipulate header page tab menu
function TabMenu_Window(btnID, winID)
{
	this.Button = $(btnID);
	this.Window = $(winID);
	this.TimerID = 0;
	this.WindowzIndex = 1500;
	this.WidgetzIndex = 400;

	this.ShowWindow = function()
	{
		if (this.Window.getStyle('display') == 'block') {
			this.SetZIndex('');
			this.Window.hide();
			this.OnMouseOver();
			Event.stopObserving(document.body, 'click', this.BoundHandleDocumentBodyClick);
		} else {
			this.SetZIndex(this.WindowzIndex);
			this.Window.show();
			this.OnMouseOut();
			Event.observe(document.body, 'click', this.BoundHandleDocumentBodyClick);
		}
	}

	this.OnMouseOut = function()
	{
		this.TimerID = setTimeout(function() { instance.OnTimerElapsed(); }, 5000);
	}

	this.OnMouseOver = function()
	{
		clearTimeout(this.TimerID);
	}

	this.OnTimerElapsed = function()
	{
		this.Window.hide();
		this.SetZIndex('');
		opened_tab_menu = null;
	}

	this.SetZIndex = function(val)
	{
		Element.setStyle(this.Window, {zIndex:val});
		if(val == '') {//hide
			$$('.ahc_tabs').invoke('setStyle', {zIndex:''});
            $$('.widget').invoke('setStyle', {zIndex:''});
		} else {//show
			$$('.ahc_tabs').invoke('setStyle', {zIndex:600});
            $$('.widget').invoke('setStyle', {zIndex:this.WidgetzIndex});
		}
	}


	var instance = this;
	this.Button.observe('click', function() { instance.ShowWindow(); });
	this.Window.observe('mouseout', function() { instance.OnMouseOut(); });
	this.Window.observe('mouseover', function() { instance.OnMouseOver(); });

	this.HandleDocumentBodyClick = function(evt)
	{
		evt = evt || window.event;
		var obj = evt.target || evt.srcElement;
		if (this.Window.getStyle('display') == 'block' && !(this.Button == obj || this.Window == obj)) {
			this.Window.hide();
			this.SetZIndex('');
			Event.stopObserving(document.body, 'click', this.BoundHandleDocumentBodyClick);
		}
	}
	this.BoundHandleDocumentBodyClick = this.HandleDocumentBodyClick.bindAsEventListener(this);
}

function __doPostBackWithParameter(ctrId, parameter)
{
	__doPostBack(ctrId, parameter);
}

/* TitleBar Class */
function TitleBar(expanded)
{
	this.isExpanded = expanded;
	this.titleBarLink = $('TitleBarLink');
	this.titleBarContent = $('TitleBarContent');

	this.Toggle = function()
	{
		if (this.isExpanded) {
		    this.titleBarContent.hide();
		    this.titleBarLink.update('Need help?');
		    this.isExpanded = false;
		} else {
		    this.titleBarContent.show();
		    this.titleBarLink.update('hide help'); 
		    this.isExpanded = true;
		}
	};
}

var keyUpTimeoutID;

function AHPanel(fields, tooltipAreaID, navigationAreaID, invalidControlsUpdatedContainerID, relatedFieldGroups)
{
    this.fields = fields;
    this.tooltipArea = tooltipAreaID;
    this.navigationArea = navigationAreaID;
    this.additionalTooltip = '';
    this.relatedFieldGroups = relatedFieldGroups;
    this.Field = null;
    this.invalidControlsUpdatedContainerID = invalidControlsUpdatedContainerID;
    
    this.Init = function()
    {
        $(this.tooltipArea).show();
        $(this.navigationArea).hide();
        this.isDisplayedNavigation = false;
        this.isNotEmptyFields = true;
        this.isValidationBegining = false;
        this.isExistError = false;
    }
    
    this.AddUpdatedInvalidControlID = function(field)
    {
        if(this.invalidControlsUpdatedContainerID)
        {
            if($(this.invalidControlsUpdatedContainerID).value.blank())
            {
                $(this.invalidControlsUpdatedContainerID).value += field.id;
            }
            else
            {
                $(this.invalidControlsUpdatedContainerID).value += "|" + field.id;
            }
        }
    }
    
    this.KeyUpField = function(field)
    {
        if (keyUpTimeoutID) { window.clearTimeout(keyUpTimeoutID); }
        var myContext = this;
        keyUpTimeoutID = window.setTimeout ( function () { myContext.KeyUpFieldFn.call( myContext, field ); }, 500 );    
    }
    

    this.FindRelatedGroupForField = function(field)
    {
        var relatedFields = null;
        if(relatedFieldGroups)
        {
            for (var index2 = 0; index2 < relatedFieldGroups.length; index2++)
            {
                var relatedFieldsTemp = relatedFieldGroups[index2];
                for (var index3 = 0; index3 < relatedFieldsTemp.length; index3++)
                {
                    if(relatedFieldsTemp[index3] == field.id)
                        relatedFields = relatedFieldsTemp;
                }
            }
            if(relatedFields)
            {
                return relatedFields;                
            }
            else
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }
    
    this.KeyUpFieldFn = function(field)
    {
        if(this.isValidationBegining)
        {
            this.BlurField(field);
            if (field.hasAttribute("errorTooltipID"))
            {
                var relatedFields = this.FindRelatedGroupForField(field);
                if(relatedFields)
                {
                    for (var index = 0; index < relatedFields.length; index++)
                    {
                        $(relatedFields[index]).writeAttribute("errorTooltipID","");
                        this.AddUpdatedInvalidControlID($(relatedFields[index]));
                    }
                    
                }
                else
                {
                    field.writeAttribute("errorTooltipID","");
                    this.AddUpdatedInvalidControlID(field);
                }
            }
            if (this.isExistError)
            {
                var is_not_exist_error = true;
                for (var index = 0; index < this.fields.length; index++)
                {
                     is_not_exist_error = is_not_exist_error && (!$(this.fields[index]).hasAttribute("errorTooltipID") || $(this.fields[index]).readAttribute("errorTooltipID") == "")
                     if(!is_not_exist_error)
                        break;
                }
                this.HideNavigationMsg();
                this.isExistError = !is_not_exist_error;
                this.ShowNavigationMsg();
            }
        }
        else
        {
            this.CheckIsNotEmptyFields();
            if (this.isNotEmptyFields)
            {
                this.isDisplayedNavigation = true;
                this.DisplayNavigation();
            }
            else
            {
                this.isDisplayedNavigation = false;
                this.DisplayTooltip();
            }
        }
    }
    
    this.CheckIsNotEmptyFields = function()
    {
        this.isNotEmptyFields = true;
        var relatedFields = null;
        for (var index = 0; index < this.fields.length; index++)
        {
            if($F(this.fields[index]).blank())
            {
                if(!$(this.fields[index]).hasAttribute("required") || $(this.fields[index]).readAttribute("required") == "true")
                {
                    var relatedFields = this.FindRelatedGroupForField($(this.fields[index]));
                    if(relatedFields)
                    {
                        this.isNotEmptyFields = false;
                        for (var index4 = 0; index4 < relatedFields.length; index4++)
                        {
                            if(!$F(relatedFields[index4]).blank())
                                this.isNotEmptyFields = true;
                        }
                        
                    }
                    else
                    {
                        this.isNotEmptyFields = false;
                    }
                }
            }
            if(!this.isNotEmptyFields)
                break;
        }    
    }
    
    this.FocusField = function(field)
    {
        this.hideAdditionalTooltip();
        if (this.isValidationBegining)
        {
            this.HideNavigationMsg();
        }
        else
        {
            $(this.tooltipArea).childElements().each(function(node)
            {
                $(node.id).hide();
            });
        }
        var tid = this.getFieldTooltip(field);
        if (!tid.blank())
        {
            
            $(tid).show();
        }
        else
        {
           if (this.isValidationBegining)
            this.ShowNavigationMsg();
        }
    }
    
    this.BlurField = function(field)
    {
        var tid = this.getFieldTooltip(field);
        if (!tid.blank())
        {
            $(tid).hide();
        }
        if (this.isValidationBegining)
            this.ShowNavigationMsg();
    }
    
    this.ShowNavigationMsg = function()
    {
        if (!this.isExistError)
            this.ShowCompleteMessage();
        else
            this.ShowErrorMessage();
    }
    
    this.HideNavigationMsg = function()
    {
       if (!this.isExistError)
            this.HideCompleteMessage();
        else
            this.HideErrorMessage();
    }
    
    this.DisplayNavigation = function()
    {
        $(this.tooltipArea).hide();
        $(this.navigationArea).show();
        isDisplayedNavigation = true;
        isNotEmptyFields = true;
        this.ShowNavigationMsg();
    }
    
    this.DisplayTooltip = function()
    {
        $(this.tooltipArea).show();
        $(this.navigationArea).hide();
        isNotEmptyFields = false;
    }
    
    this.DisplayDefaultErrorMsg = function()
    {
        this.SetValidationBegining();
        $(this.tooltipArea).hide();
        $(this.navigationArea).show();
        this.isExistError = true;
        this.HideCompleteMessage();
        this.ShowErrorMessage();
    }
    
    this.SetValidationBegining = function()
    {
        this.isValidationBegining = true;
    }
    
    this.ShowErrorMessage = function()
    {
        $('defaultErrorMsg').show();
    }
    
    this.HideErrorMessage = function()
    {
        $('defaultErrorMsg').hide();
    }
    
    this.ShowCompleteMessage = function()
    {
        $('defaultCompleteMsg').show();
    }
    
    this.HideCompleteMessage = function()
    {
        $('defaultCompleteMsg').hide();
    }
    
    this.getFieldTooltip = function(field)
    {
        var tid = "";
        if (this.isValidationBegining)
        {
            if ($(field).hasAttribute("errorTooltipID"))            
                tid = $(field).readAttribute("errorTooltipID");
        }
        else
            tid = $(field).readAttribute("tooltipID");
        return tid;
    }
        
    this.ClearValidationErrors = function()
    {
        this.isExistError = false;
    }
    
    this.showAdditionalTooltip = function(additionalT)
    {
        this.additionalTooltip = additionalT;
        $(this.navigationArea).hide();
        $(this.tooltipArea).childElements().each(function(node)
        {
            $(node.id).hide();
        });
        $(this.additionalTooltip).show();
        $(this.tooltipArea).show();
    }
    
    this.hideAdditionalTooltip = function()
    {
        if (!this.additionalTooltip.blank())
        {
            this.CheckIsNotEmptyFields();
            $(this.additionalTooltip).hide();
            this.additionalTooltip = '';
            if (this.isNotEmptyFields)
            {
                this.isDisplayedNavigation = true;
                this.DisplayNavigation();
            }
            else
            {
                this.isDisplayedNavigation = false;
                this.DisplayTooltip();
            }
        }
    }
}
function clearedPassword(event, id, masked, idFlag)
{
    if ($(idFlag).value !="true")
    {
        $(idFlag).setValue("true");
        $(id).value = "";
        //$(id).value = String.fromCharCode(event.keyCode)
    }
}

var TextAreaResize = Class.create({
    initialize: function(element, expandMin, expandMax, textBoxTextLimit) {
        this.element = $(element);
        if ($(element).nodeName.toLowerCase() != "textarea") return;
        this.element.paddingTop = (this.element.getStyle('paddingTop').substr(0, this.element.getStyle('paddingTop').length - 2)*1);;
        this.element.paddingBottom = (this.element.getStyle('paddingBottom').substr(0, this.element.getStyle('paddingBottom').length - 2)*1);;
        this.nonIEorOpera = !(Prototype.Browser.IE || Prototype.Browser.Opera);
        if(expandMin) { this.element.expandMin = expandMin } else { this.element.expandMin = 0 };
        if(expandMax) { this.element.expandMax = expandMax } else { this.element.expandMax =99999 };
        this.element.textBoxTextLimit = textBoxTextLimit;
        Event.observe(this.element, 'keyup', this.Resize.bindAsEventListener(this));
        this.Resize();
    },

    Resize: function() {
        if(this.element.textBoxTextLimit)
        {
	        if (this.element.value.strip().length > this.element.textBoxTextLimit)
		        this.element.value = this.element.value.substring(0, this.element.textBoxTextLimit);
		}
        if(this.element.scrollHeight != this.element.style.height) {
            this.element.setStyle( { paddingTop: '0px', paddingBottom: '0px' });
            if (this.nonIEorOpera) 
            {
                this.element.style.height = "0px";
            } 
            else 
            { 
                this.element.style.overflow = "hidden";
            }
            var h = Math.max(this.element.expandMin, Math.min(this.element.scrollHeight, this.element.expandMax)); 
            this.element.style.overflow = (this.element.scrollHeight > h ? "auto" : "hidden"); 
            this.element.style.height = h + "px"; 
            this.element.setStyle( { paddingTop: this.element.paddingTop+'px', paddingBottom: this.element.paddingBottom+'px' });
        } 
        return true; 
    }
});

//function expandTextArea(e,id)
//{
//    evt = (e) ? e : (window.event) ? event : null 
//    if (evt.keyCode == 13)
//    {
//        var row = $(id).readAttribute('rows');
//        if (row < 4)
//        {
//            $(id).writeAttribute('rows',row);
//            $(id).setStyle('overflow-y:none');
//        }
//        else
//        {
//            $(id).setStyle('overflow-y:scroll');
//        }
//    }
//}

function TextArea_SetValid(tbID)
{
    var tb = $(tbID);
    tb.removeClassName('textAreaInErrorState');
}

function TextArea_SetInvalid(tbID)
{
    var tb = $(tbID);
    tb.addClassName('textAreaInErrorState');
}

function TextArea_SetValidCustomStyle(tbID, className)
{
    var tb = $(tbID);
    tb.removeClassName(className);
}

function SetCustomClass(ctrID, className)
{
	var ctr = $(ctrID);
	ctr.addClassName(className);
}
function ResetCustomClass(ctrID, className)
{
	var ctr = $(ctrID);
	ctr.removeClassName(className);
}

var selectedIndex = null;

function DropDownOnFocus(control)
{
    selectedIndex = control.selectedIndex;
}

function DropDownOnKeyUp(control)
{
    if(selectedIndex != null)
    {
        if(selectedIndex != control.selectedIndex)
        {
            selectedIndex = control.selectedIndex;
            control.blur();
        }
        else
        {
            selectedIndex = control.selectedIndex;
        }    
    }
    else
    {
        selectedIndex = -1;
    }
}

function SiteTourLinkClick(liID, divID)
{
	var li = $(liID);
	var div = $(divID);
	$$('.ahc_tour_content_col').invoke('setStyle', {display:'none'});
	$$('.siteTourList').invoke('removeClassName', 'active');
	
	li.addClassName('active');
	div.show();
}

function SiteTourDevicesLinkClick(ulID, lbID, classname)
{
	var lb = $(lbID);
	var ul = $(ulID);
	
	$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actiped_description');
	$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actiscale_description');
	$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actipressure_description');
	
	var links = $$('.ahc_devices_view_details')
	
	for ( var i = 0; i < links.length; i++)
	{
		links[i].innerHTML = 'view details';
	}
	
	lb.innerHTML = 'details';
	
	ul.addClassName(classname);
}

function SiteTourDevices(ulID, lbID, liID, classname)
{
	this.lb = $(lbID);
	this.ul = $(ulID);
	this.li = $(liID);
	this.classname = classname;
	
	this.AddClass = function()
	{
		this.ul.addClassName(classname);
	}
	
	this.OnClick = function()
	{
		$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actiped_description');
		$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actiscale_description');
		$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actipressure_description');
		
		$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actiped_description_viewed');
	
		var links = $$('.ahc_devices_view_details');
	
		for ( var i = 0; i < links.length; i++)
		{
			links[i].innerHTML = 'view details';
		}
	
		this.lb.innerHTML = 'details';
		this.ul.addClassName(classname);
		this.ul.removeClassName('ahc_actiped_description_viewed');

		Event.observe(document.body, 'click', this.BoundHandleDocumentBodyClick);
	}

	var instance = this;
	this.lb.observe('click', function() { instance.OnClick(); return false; });
	this.li.observe('click', function() { instance.OnClick(); return false; });

	this.HandleDocumentBodyClick = function(evt)
	{
		evt = evt || window.event;
		var obj = evt.target || evt.srcElement;
		
		var innertag = false;
		if (obj.parentNode != null)
		{
			var parent = obj;
			while (parent.parentNode != null)
			{
				if (parent.tagName == 'LI' && (parent.className == "actipressure" || parent.className == "actiped" || parent.className == "actiscale"))
				{
					innertag = true;
					break;
				}
				if (parent.parentNode == null)
				{
					break;
				}
				parent = parent.parentNode;
			}
		}
		
		
		if (!(this.lb == obj || this.li == obj || innertag)) {
			this.lb.innerHTML = 'view details';
			$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actiped_description');
			$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actiscale_description');
			$$('.ahc_devices_description').invoke('removeClassName', 'ahc_actipressure_description');
			$$('.ahc_devices_description').invoke('addClassName', 'ahc_actiped_description_viewed');
			Event.stopObserving(document.body, 'click', this.BoundHandleDocumentBodyClick);
		}
	}
	this.BoundHandleDocumentBodyClick = this.HandleDocumentBodyClick.bindAsEventListener(this);
}

function SerialNumberLocations(ulID, lbID, liID, classname)
{
	this.lb = $(lbID);
	this.ul = $(ulID);
	this.li = $(liID);
	this.classname = classname;
	
	this.AddClass = function()
	{
		this.ul.addClassName(classname);
	}
	
	this.OnClick = function()
	{
		$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_actiped');
		$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_actilink');
		$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_actiscale');
		$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_actipressure');
		
		$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_description_viewed');
	
		var links = $$('.ahc_sn_locations_view_details');
	
		for ( var i = 0; i < links.length; i++)
		{
			links[i].innerHTML = 'view details';
		}
	
		this.lb.innerHTML = 'details';
		this.ul.addClassName(classname);
		this.ul.removeClassName('ahc_sn_description_viewed');

		Event.observe(document.body, 'click', this.BoundHandleDocumentBodyClick);
	}

	var instance = this;
	this.lb.observe('click', function() { instance.OnClick(); return false; });
	this.li.observe('click', function() { instance.OnClick(); return false; });

	this.HandleDocumentBodyClick = function(evt)
	{
		evt = evt || window.event;
		var obj = evt.target || evt.srcElement;
		
		var innertag = false;
		if (obj.parentNode != null)
		{
			var parent = obj;
			while (parent.parentNode != null)
			{
				if (parent.tagName == 'LI' && (parent.className == "actipressure" || parent.className == "actiped" || parent.className == "actiscale" || parent.className == "actilink"))
				{
					innertag = true;
					break;
				}
				if (parent.parentNode == null)
				{
					break;
				}
				parent = parent.parentNode;
			}
		}
		
		
		if (!(this.lb == obj || this.li == obj || innertag)) {
			this.lb.innerHTML = 'view details';
			$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_actiped');
			$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_actilink');
			$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_actiscale');
			$$('.ahc_sn_locations').invoke('removeClassName', 'ahc_sn_actipressure');
			$$('.ahc_sn_locations').invoke('addClassName', 'ahc_sn_description_viewed');
			Event.stopObserving(document.body, 'click', this.BoundHandleDocumentBodyClick);
		}
	}
	this.BoundHandleDocumentBodyClick = this.HandleDocumentBodyClick.bindAsEventListener(this);
}

function ChallengeDescriptionSelectChanged() {
	var list = document.getElementById("selectChallengeTypeList");
	var val = '.' + list.options[list.selectedIndex].value;
	$$('.default').invoke('setStyle', {display:'none'});
	$$('.ahc_challenge_text').invoke('setStyle', {display:'none'});
	$$('.walk_around_world').invoke('setStyle', {display:'none'});
	
	$$(val)[0].show();
//		var li = $(liID);
//	var div = $(divID);
//	$$('.ahc_tour_content_col').invoke('setStyle', {display:'none'});
//	$$('.siteTourList').invoke('removeClassName', 'active');
//	
//	li.addClassName('active');
//	div.show();
}

function PopupURL(url, height, width) {
	var params = 'height=' + height + ',width=' + width + ',menubar=no,location=no,scrollbars=no,status=no,resizable=no';
	//newwindow=window.open(url,'name','height=500,width=770');
	newwindow=window.open(url,'name',params);
	if (window.focus) {newwindow.focus()}
	return false;
}

function TopmostElementShow(sender, args)
{
	var parent = sender._element;
	while (parent.parentNode != null)
	{
		if (parent.tagName == 'DIV' && Element.hasClassName(parent, 'widget'))
		{
			parent.addClassName('widget_topmost');
			break;
		}
		parent = parent.parentNode;
	}
}

function TopmostElementHide(sender, args)
{
	var parent = sender._element;
	while (parent.parentNode != null)
	{
		if (parent.tagName == 'DIV' && Element.hasClassName(parent, 'widget'))
		{
			parent.removeClassName('widget_topmost');
			break;
		}
		parent = parent.parentNode;
	}
}

function ceFocus(sender, args)
{
    sender._element.focus();
}

function SetTodaysDate(sender, args)
{
    sender.set_todaysDate(new Date(sender._textbox._element.getAttribute('todaysDate')));
    $$('.calendar_inactive').invoke('show');
}