/*Copyright (c) 2005-2006 Ajaxium. Reverse engineering or any attempt to reconstruct or discover any source code or underlying algorithms is prohibited.*/

//gAjaxiumPageUid = _G9a
//gOldContent = _G9b

//gFallbackTimeout = _G9c
//gFallBackTimeoutMessage = _G9d
//gDisableFormWhilePostBack = _G9e
//AjaxiumEnabled
//gReturnFocusElementId = _G9i
//_G9j -- passed during RewriteDocument to launch all AjaxUpdateScripts
//Ajaxium_TimerInterval -- timer interval (seconds)
//_G9k -- AjaxiumLoading panels "div1 div2 div3"

var m_oXmlRequest = null;

var m_aNewContent = null;
var m_NewAjaxiumPageUid = _G9a;
var m_OnAjaxUpdate = null;
var m_aNewHiddens = null;

var m_Requesting = false;
var m_RequestingUrl = null;

var m_Timeout = _G9c;
var m_TimeoutMessage = _G9d;
var m_DisableFormWhilePostBack = _G9e;

var m_TimeoutID = -1;
var m_UserTimerTimeoutID = -1;

var m_hexChars = "0123456789ABCDEF";
var m_BrowserHelperCalled = false;
var m_okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-!'()*-.~";

var m_ex = null;

var m_LastResponseTime = 0;
var m_SessionTimeout = _G9f;
var m_SessionExpirationHandling = _G9g;

var m_DiffList = null;

var m_lastActiveLinkID = null;

var m_DisplayedLoadingPanels = null;

var m_DocumentOnMouseMoveInstalled = false;
var m_DocumentOnMouseMoveLast = null;

var m_DocumentOnMouseMovePanelID = null;

var m_LastMouseDocX = 0;
var m_LastMouseDocY = 0;

var Ajaxium_UncompressedResponseLength = 0;



function __$$doPostBack(p_eventTarget, p_eventArgument) 
{


	f_clearUserTimer();

	var l_performRequest = 0;

	if(typeof(Ajaxium_OnBeforeRequest) != "undefined")
	{
		try
		{
			l_performRequest = Ajaxium_OnBeforeRequest("POST", "");
		}
		catch(m_ex)
		{
			 
			 
		}
	}
				
	if(l_performRequest == 1)
	{
		
		return false;
	} else if (l_performRequest == 2)
	{
		
		return true;
	}
				
    if(!AjaxiumEnabled)
        return false;
             
	if(!f_BrowserHelper())
		return false;  
   
    if((typeof(document.forms)=="undefined") || (document.forms.length == 0))
        return false;
    
    if(typeof(document.forms[0].innerHTML)=="undefined")
        return false;

    if(typeof(document.open)=="undefined")
        return false;

    return f_performPostBack(p_eventTarget, p_eventArgument);
}

function f_performPostBack(p_eventTarget, p_eventArgument) 
{	
	try
	{	
		if(m_Requesting)
			return true;
							
	    if(!f_CheckSession())
			return false;

        m_RequestingUrl = null;

		var l_theform = document.forms[0];
		
		if(typeof(l_theform.__EVENTTARGET)!="undefined")
			l_theform.__EVENTTARGET.value = p_eventTarget; /*  */
			
		if(typeof(l_theform.__EVENTARGUMENT)!="undefined")
			l_theform.__EVENTARGUMENT.value = p_eventArgument;
				
		m_oXmlRequest = f_GetXmlRequestObject();
		
		if(m_oXmlRequest != null)
		{	
		    var l_formAction = l_theform.action;
		
		    if((l_formAction == "") || (l_formAction == null))
		        l_formAction = document.location;
											
			if (typeof(m_oXmlRequest.setRequestHeader) != "undefined") 
			{				
				var l_PostData = f_BuildPostData(l_theform, p_eventTarget);				
			
				setTimeout(f_OnReadyStateChange, 100);
			
				//m_oXmlRequest.onreadystatechange = f_OnReadyStateChange;
				m_oXmlRequest.open("POST", l_formAction, true);
				m_oXmlRequest.setRequestHeader("__ajaxium_G9a", _G9a);
				m_oXmlRequest.setRequestHeader( "If-Modified-Since", "Mon, 01 Jan 1979 00:00:00 GMT" );
				m_oXmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; Charset=utf-8");				
				//m_oXmlRequest.setRequestHeader("Connection", "close");
				
				f_onRequestStart();				
				f_callOnLoadingStateChange(true);
				
				m_oXmlRequest.send(l_PostData);
								
				return true;
			} else 
			{
				
			}					
		} else
		{		
			
		}
	}
	catch(m_ex)
	{		
		 
		 
			
	}
	
	if(m_Requesting)
	{
		f_onRequestFinish(false);//false because postback will be done using standard ASP.NET script		
		f_callOnLoadingStateChange(false);
	}

	return false;
}

function f_NavigateToElement(p_AnchorElement)
{

		
	var l_Call = false;
	var l_Url = "";
		
	try
	{	
		if(typeof(p_AnchorElement)=="string")
		{
			l_Call = true;
			l_Url = p_AnchorElement;
			m_lastActiveLinkID = null;
		} else
		{	
			var l_Target = p_AnchorElement.target;
			
			if((l_Target == "_self")||(l_Target == "")||(l_Target == null))
				l_Call = true;
			else if(l_Target == window.name)
				l_Call = true;
			else if((l_Target == "_top")&&(window.top == window.self))
				l_Call = true;
			else if((l_Target == "_parent")&&(window.parent == window.self))
				l_Call = true;
				
			if(l_Call)
			{
			    l_Url = p_AnchorElement.href;		    
			    m_lastActiveLinkID = p_AnchorElement.id;			
			}
		}
				
		if(l_Call && (l_Url != ""))
		{	       
    		return f_Navigate(l_Url);
    	}
	}
	catch(m_ex)
	{
		 
		 
			
	}
	
	return false;
}

var Ajaxium_Navigate = f_NavigateToElement;

function f_RemoveTailFromUrl(p_Url)
{
    var l_idx = p_Url.indexOf("#");
    if(l_idx<0)
        return p_Url;
    return p_Url.substring(0,l_idx);
}

function f_Navigate(p_Url)
{       
	try
	{
		f_clearUserTimer();
		
		var l_NavigateUrl = f_RemoveTailFromUrl(p_Url);
	
		var l_performRequest = 0;

		if(typeof(Ajaxium_OnBeforeRequest) != "undefined")
		{
			try
			{
				l_performRequest = Ajaxium_OnBeforeRequest("GET", l_NavigateUrl);
			}
			catch(m_ex)
			{
				 
				 
			}
		}
					
		if(l_performRequest == 1)
		{
			
			return false;
		} else if (l_performRequest == 2)
		{
			
			return true;
		}
			
		if(m_Requesting)
			return true;

		if(!f_CheckSession())
			return false;

        m_RequestingUrl = p_Url;

		m_oXmlRequest = f_GetXmlRequestObject();
		
		if(m_oXmlRequest != null)
		{			
			if (typeof(m_oXmlRequest.setRequestHeader) != "undefined") 
			{	
				setTimeout(f_OnReadyStateChange, 100);
				                
				//m_oXmlRequest.onreadystatechange = f_OnReadyStateChange;
				m_oXmlRequest.open("GET", l_NavigateUrl, true);
				m_oXmlRequest.setRequestHeader("__ajaxium_G9a", _G9a);		
				m_oXmlRequest.setRequestHeader( "If-Modified-Since", "Mon, 01 Jan 1979 00:00:00 GMT" );    
				//m_oXmlRequest.setRequestHeader("Connection", "close");
			    
				//TODO: session stateless mode
				//try
				//{
				//	var l_history = document.forms[0].__ajaxium_G9aaa.value;
				//	if(l_history.length>0)
				//		m_oXmlRequest.setRequestHeader("__ajaxium_G9aaa", l_history);
				//}
				//catch(m_ex){}
			    
				f_onRequestStart(); 
				f_callOnLoadingStateChange(true);
			    
				m_oXmlRequest.send(null);
                              
                return true;
            } else
            {
                
            }
        } else
		{
			
		}
    }
    catch(m_ex)
	{			
		 
		 
			
	}    
	
	if(m_Requesting)
	{
		f_onRequestFinish(false);//false -- we have failed to send GET request, GET will be done by browser	
		f_callOnLoadingStateChange(false);
	}

	return false;
}

setTimeout(f_InitSession,10);

function f_InitSession()
{
	if(m_SessionExpirationHandling == 0)//FallbackToAspNet
	{
		m_LastResponseTime = new Date().getTime();
	} else if(m_SessionExpirationHandling == 1)//RewriteContent
	{
		//nothing should be done for this option
	} else if(m_SessionExpirationHandling == 2)//KeepAlive
	{
		//debugger;
	}
}

//returns false if session is timed out and fallback to ASP.NET should be performed.
function f_CheckSession()
{	
	if(m_SessionExpirationHandling == 0)//FallbackToAspNet
	{
		var l_CurrentTime = new Date().getTime();
		if(Math.abs(l_CurrentTime - m_LastResponseTime)>m_SessionTimeout)
		{
			
			return false;	
		}
	}
	
	return true;
}

function f_validateViewState()
{
    //debugger;

    try
    {   
        var l_theform = document.forms[0];
        
        if(typeof(l_theform.__ajaxium_G9aa)!="undefined")
        {
            var l_validateValue = l_theform.__ajaxium_G9aa.value;
            
            if(l_validateValue != m_NewAjaxiumPageUid)
            {
                //viewstate is invalid (back/forward buttons were used), reloading the page				
				
				
				
				
								
                document.location.reload(true);
            }
        }
    }
    catch(m_ex)
    {
    }
}

setTimeout(f_setValidateViewStateAndReturnFocus,300);

function f_setValidateViewStateAndReturnFocus()
{
    //debugger;

    var l_theform = document.forms[0];
    if((typeof(l_theform) != "undefined") && (typeof(l_theform.__ajaxium_G9aa)!="undefined"))
        l_theform.__ajaxium_G9aa.value = m_NewAjaxiumPageUid;
       
    f_setFocus(_G9i);
    _G9i = null;
        
    f_initUserTimer();    
    
    if((typeof(_G9j) != "undefined") && (_G9j != null))
    {	
		var l_OnAjaxUpdate = _G9j;
		_G9j = null;
		
		try{ eval(unescape(l_OnAjaxUpdate)); }
		catch(m_ex){}		
    }   
    
    if(m_DocumentOnMouseMoveInstalled == false)
    {
		m_DocumentOnMouseMoveInstalled = true;
		m_DocumentOnMouseMoveLast = document.onmousemove;
		document.onmousemove = f_onMouseMove;
    }
}

function f_userTimerElapsed()
{
	m_UserTimerTimeoutID = -1;
	
	var l_executePostback = 0;
	
	if(typeof(Ajaxium_OnTimerElapsed) != 'undefined')
	{
		l_executePostback = Ajaxium_OnTimerElapsed();
	}
	
	if(l_executePostback == 0)
		__$$doPostBack("AjaxiumProcessor", "");
	else if(l_executePostback == 1)
		f_initUserTimer();
}

function f_initUserTimer()
{
	if((m_UserTimerTimeoutID == -1) && (Ajaxium_TimerInterval > 0))
	{
		m_UserTimerTimeoutID = setTimeout(f_userTimerElapsed, Ajaxium_TimerInterval*1000);
	}
}

function f_clearUserTimer()
{
	if(m_UserTimerTimeoutID != -1)
	{
		clearTimeout(m_UserTimerTimeoutID);
		m_UserTimerTimeoutID = -1;
	}
}

function f_empty() {}

function f_onRequestStart()
{
	m_Requesting = true;
	Ajaxium_UncompressedResponseLength = 0;
	
	if(m_DisableFormWhilePostBack)
	{
		document.forms[0].disabled = true;
	}    

	m_TimeoutID = setTimeout("if(m_Requesting){f_onRequestFinish(true);f_callOnLoadingStateChange(false);};", m_Timeout);
}

function f_onRequestFinish(p_requestFailed)
{
	if(m_Requesting)
	{
		m_Requesting = false;

		try
		{		
			clearTimeout(m_TimeoutID);
		}
		catch(m_ex) {}
		
		try
		{
			if(m_oXmlRequest != null)
			{
				m_oXmlRequest.onreadystatechange = f_empty;
				m_oXmlRequest.abort();
			}
		}
		catch(m_ex) {}
		
		try
		{
			if(m_DisableFormWhilePostBack)
			{
				document.forms[0].disabled = false;
			}
		}
		catch(m_ex) {}
	}	
		
	if(p_requestFailed)
	{
		
	
	    if((m_TimeoutMessage != null)&&(m_TimeoutMessage != ""))
	    {
		    alert(m_TimeoutMessage);
		}
		
		if(m_RequestingUrl != null)
		{		
		    
		    window.open(m_RequestingUrl, '_self');
		    m_RequestingUrl = null;
		} else
		{
		    var l_theform = document.forms[0];
		    
		    l_theform.submit();
		}
	}
}

function f_onMouseMove(p_mouseArgs)
{
	try
	{
		if(p_mouseArgs)
		{
		  if(typeof(p_mouseArgs.pageX)=="number")
		  {
			 m_LastMouseDocX = p_mouseArgs.pageX;
			 m_LastMouseDocY = p_mouseArgs.pageY;
		  } else
		  {
			 m_LastMouseDocX = p_mouseArgs.clientX;
			 m_LastMouseDocY = p_mouseArgs.clientY;
		  }
		} else
		{
		  var l_mouseArgs = window.event;
		  m_LastMouseDocX = l_mouseArgs.clientX + f_GetScrollLeft();
		  m_LastMouseDocY = l_mouseArgs.clientY + f_GetScrollTop();	  
		}

		f_callMoveLoadingPanel();
    }
    catch(m_ex){};
		
	try
	{
		if((m_DocumentOnMouseMoveLast != null) && (typeof(m_DocumentOnMouseMoveLast) != "undefined"))
			m_DocumentOnMouseMoveLast(p_mouseArgs);
	}catch(m_ex){};
}

function f_moveLoadingPanel(p_ElementID, p_MouseX, p_MouseY)
{
	f_moveElement(p_ElementID, p_MouseX+5, p_MouseY+5);
}

function f_callMoveLoadingPanel()
{
	if(m_DocumentOnMouseMovePanelID != null)
	{
		if((typeof(Ajaxium_OnMoveLoadingPanel) == "undefined") || (Ajaxium_OnMoveLoadingPanel == null))
			Ajaxium_OnMoveLoadingPanel = f_moveLoadingPanel;
		
		Ajaxium_OnMoveLoadingPanel(m_DocumentOnMouseMovePanelID, m_LastMouseDocX, m_LastMouseDocY);		
	}
}

function f_showHideLoadingPanels(p_Requesting)
{
	if((_G9k==null)||(_G9k==""))
		return;
		
	if(p_Requesting)
	{
		m_DisplayedLoadingPanels = _G9k.split(" ");
		
		for(var l_idx=0;l_idx<m_DisplayedLoadingPanels.length;l_idx++)
		{
			var l_name = m_DisplayedLoadingPanels[l_idx];
			if((l_name != null)&&(l_name != ""))
			{
				var l_type = l_name.charAt(0);
				l_name = l_name.substring(1, l_name.length);
				
				if(l_type == '*')
				{
					if(m_DocumentOnMouseMovePanelID == null)
					{				
					    m_DocumentOnMouseMovePanelID = l_name;
					    f_callMoveLoadingPanel();
					}
				} else if(l_type == '+')
				{					
				}
				
				f_showElement(l_name, true);
			}
		}
	} else
	{
		if(m_DisplayedLoadingPanels != null)
		{
			for(var l_idx=0;l_idx<m_DisplayedLoadingPanels.length;l_idx++)
			{
				var l_name = m_DisplayedLoadingPanels[l_idx];
				if((l_name != null)&&(l_name != ""))
				{
					var l_type = l_name.charAt(0);
					l_name = l_name.substring(1, l_name.length);				
					f_showElement(l_name, false);					
				}
			}

			if(m_DocumentOnMouseMovePanelID != null)
				m_DocumentOnMouseMovePanelID = null;
			
			m_DisplayedLoadingPanels = null;
		}
	}
}

//warning: the code of this function can also be called explicitly
function f_callOnLoadingStateChange(p_Requesting)
{
		try
		{
			f_showHideLoadingPanels(p_Requesting);
		}
		catch(m_ex) { alert(m_ex); alert(m_ex.Message); }
		
		try
        {	
	        if(typeof(Ajaxium_OnLoadingStateChange) != 'undefined')
	            Ajaxium_OnLoadingStateChange(p_Requesting);
		}
		catch(m_ex) {}
}

function f_showForm(p_Form, p_Title) 
{
	var l_idx;
	var l_text = p_Title + ' ';
	l_text += 'form.elements[] has ' + p_Form.elements.length + ' items:\n\n';
	for (l_idx=0; l_idx<p_Form.elements.length; l_idx++) 
	{
	    if((p_Form.elements[l_idx].name != "__VIEWSTATE") && (p_Form.elements[l_idx].name != "__ZIPSTATE"))
	    {
		    l_text += p_Form.elements[l_idx].type + ' ' + p_Form.elements[l_idx].name + ' = "' + p_Form.elements[l_idx].value + '"\n';
		}
	}
	
	
}

function f_BuildPostData(p_Form, p_Target)
{
    //f_showForm(p_Form, "before sending");

    var l_PostData="";
    var l_Elements=p_Form.elements;

    //Safari QuickFix for MedRespond
    //if many elements with the same name are in the elements list
    //set name of all of them except last one to ""
    //since ASP.NET doesn't allow for multiply elements to 
    //have the same name, it should work for all ASP.NET projects well.
    
    var l_ElementName;
    var l_ElementId;
    var l_ElementIndex;
    var l_ElementIndex2;
    
    for(var l_ElementIndex=l_Elements.length-1;l_ElementIndex>=0;l_ElementIndex--)
    {
        l_ElementName = l_Elements[l_ElementIndex].name;
        l_ElementId = l_Elements[l_ElementIndex].id;
        
        if((l_ElementName == "")||(l_ElementName == null))
            continue;
    
        for(var l_ElementIndex2=l_ElementIndex-1; l_ElementIndex2>=0; l_ElementIndex2--)
        {
            var l_ElementName2 = l_Elements[l_ElementIndex2].name;
            
            if(l_ElementName == l_ElementName2)
            {
                var l_ElementId2 = l_Elements[l_ElementIndex2].id;
                
                if(l_ElementId == l_ElementId2)
                    l_Elements[l_ElementIndex2].name = "";
            }
        }
    }

    for(var l_ElementIndex=0;l_ElementIndex<l_Elements.length;l_ElementIndex++)
    {
        var l_Element=l_Elements[l_ElementIndex];
        var l_Value=l_Element.value;
        var l_Checked=l_Element.checked;
        var l_Type=l_Element.type;
        var l_ElementName1 = l_Element.name;
        
        if((l_ElementName1 == "")||(l_ElementName1 == null))
            continue;
        
        if(typeof(l_Type)!="undefined")
			l_Type = l_Type.toLowerCase();
        
        if(((l_Type=="submit")||(l_Type=="button"))&&((l_Element.id!=p_Target)&&(l_Element.name!=p_Target)))
        {
            continue;
        }

        if((l_Type=="checkbox")||(l_Type=="radio"))
        {
            if(!l_Checked)continue;
        }
        
        var l_ElemName=encodeURIComponent(l_ElementName1);
        
        if((l_Type=="select-one") || (l_Type=="select-multiple") || (l_Type=="select"))
        {
			var l_selectCount = l_Element.options.length;
            for (var l_optionIdx = 0; l_optionIdx < l_selectCount; l_optionIdx++) 
            {
                var l_selectChild = l_Element.options[l_optionIdx];
                if (l_selectChild.selected == true) 
                {
					l_Value=encodeURIComponent(l_selectChild.value);
                
                    l_PostData+=(l_PostData?"&":"")+l_ElemName+"="+l_Value;
                }
            }	
			
			continue;
        }
                
		l_Value=encodeURIComponent(l_Value);
			        
		l_PostData+=(l_PostData?"&":"")+l_ElemName+"="+l_Value;
    }
        
    l_PostData+=(l_PostData?"&":"")+"__ajaxium_G9a="+_G9a;
    
    return l_PostData;
}

function f_OnReadyStateChange()
{
	if((m_oXmlRequest.readyState==4)&&(m_Requesting))
	{
		var l_requestFailed = true;
				
		try
		{
			if(m_Requesting)
			{			
				var l_responseText = m_oXmlRequest.responseText;

				if((m_oXmlRequest.status == 200)||(m_oXmlRequest.status == 304)||(m_oXmlRequest.status == 100))
				{					
					m_NewAjaxiumPageUid = _G9a;
				
					var l_cmd = f_ParseResponse(l_responseText);

					if(l_cmd != "")
					{
						if(_G9a != m_NewAjaxiumPageUid)
						{
							Ajaxium_UncompressedResponseLength = l_responseText.length;
					
							m_LastResponseTime = new Date().getTime();
						
        					setTimeout(l_cmd, 10);
        					l_requestFailed = false;
        				
        							
						} else
						{
							
						}					
					}
					else
					{
					    if((l_responseText != "") && (l_responseText != null))
					    {
					        l_cmd = "f_ReplaceContent();";				    
					        m_aNewContent = l_responseText;
					        
					        setTimeout(l_cmd, 10);
					        l_requestFailed = false;
    					    
    					    
						    
						    
						    
						}
					}
				} else if(m_oXmlRequest.status == 500)
				{
				    
				} else
				{
					
				}
			} else
			{
			    
			}			
		}
		catch(m_ex)
		{
			 
			 
			
		}		
		
		if(l_requestFailed)
		{
			f_onRequestFinish(true);
			f_callOnLoadingStateChange(false);
		}
	} else
	{
		if(m_Requesting)
			setTimeout(f_OnReadyStateChange, 100);			
		// 	
	}
}

//function f_debugShowContent()
//{
//    var l_textBox = f_getElement("Ajaxium_DebugTextBox");
//    if(l_textBox != null)
//    {
//        l_textBox.value = "";
//        l_textBox.value = document.body.innerHTML;
//    }
//}

function f_GetWindowWidth()
{
	var l_width = 0;
	
    if(typeof(window.innerWidth) != 'undefined')
        l_width = window.innerWidth;
        
    if(l_width > 0) return l_width;
        
    if(typeof(document.documentElement) != 'undefined')
    {
		if(typeof(document.documentElement.clientWidth)!='undefined')
			l_width = document.documentElement.clientWidth;
		
		if(l_width > 0) return l_width;
			
		if(typeof(document.documentElement.offsetWidth)!='undefined')
			l_width = document.documentElement.offsetWidth;
			
		if(l_width > 0) return l_width;
			
		if(typeof(document.documentElement.scrollWidth)!='undefined')
			l_width = document.documentElement.scrollWidth;
			
		if(l_width > 0) return l_width;
	}
  
    if(typeof(document.body) != 'undefined')
        l_width = document.body.clientWidth;
    
    return l_width;
}
function f_GetWindowHeight()
{
	var l_height = 0;

    if(typeof(window.innerHeight)!='undefined')
        l_height = window.innerHeight;
     
    if(l_height > 0) return l_height;
        
    if(typeof(document.documentElement) != 'undefined')
    {
		if(typeof(document.documentElement.clientHeight)!='undefined')
			l_height = document.documentElement.clientHeight;
			
		if(l_height > 0) return l_height;
		
		if(typeof(document.documentElement.offsetHeight)!='undefined')
			l_height = document.documentElement.offsetHeight;
			
		if(l_height > 0) return l_height;
			
		if(typeof(document.documentElement.scrollHeight)!='undefined')
			l_height = document.documentElement.scrollHeight;
			
		if(l_height > 0) return l_height;
    }
        
    if(typeof(document.body)!='undefined')
        l_height = document.body.clientHeight;
        
    return l_height;
}
function f_GetScrollLeft() 
{
	var l_scrollLeft = 0;

    if(typeof(window.pageXOffset) != 'undefined')
		l_scrollLeft = window.pageXOffset;
		
	if(l_scrollLeft > 0) return l_scrollLeft;
		
    if(typeof(document.documentElement.scrollLeft) != 'undefined')
        l_scrollLeft = document.documentElement.scrollLeft;
        
    if(l_scrollLeft > 0) return l_scrollLeft;        
        
    if(typeof(document.body) != 'undefined')
        l_scrollLeft = document.body.scrollLeft;
    
    return l_scrollLeft;
}
function f_GetScrollTop() 
{
	var l_scrollTop = 0;

    if(typeof(window.pageYOffset) != 'undefined')
        l_scrollTop = window.pageYOffset;
        
    if(l_scrollTop > 0) return l_scrollTop;
        
    if(typeof(document.documentElement.scrollTop) != 'undefined')
        l_scrollTop = document.documentElement.scrollTop;
     
    if(l_scrollTop > 0) return l_scrollTop;
        
    if(typeof(document.body) != 'undefined')
        l_scrollTop = document.body.scrollTop;
        
    return l_scrollTop;
}

function f_getElementLeft(p_Element)
{
	var l_curleft = 0;
	if (p_Element.offsetParent)
	{
		while (p_Element.offsetParent)
		{
			l_curleft += p_Element.offsetLeft;
			p_Element = p_Element.offsetParent;
		}
	} else
	{
		if (p_Element.x)
			l_curleft += p_Element.x;
	}
	return l_curleft;
}

function f_getElementTop(p_Element)
{
	var l_curtop = 0;
	if (p_Element.offsetParent)
	{
		while (p_Element.offsetParent)
		{
			l_curtop += p_Element.offsetTop;
			p_Element = p_Element.offsetParent;
		}
	} else
	{
		if (p_Element.y)
			l_curtop += p_Element.y;
	}
	return l_curtop;
}

function f_moveElement(p_ElementID, p_Left, p_Top)
{
	var l_Element = f_getElement(p_ElementID);    
	if(l_Element)
	{
		if(typeof(p_Left) == "number")
			p_Left = p_Left + "px";
		if(typeof(p_Top) == "number")
			p_Top = p_Top + "px";
			
		l_Element.style.left = p_Left;
		l_Element.style.top = p_Top;
	} 
}

var Ajaxium_GetWindowWidth = f_GetWindowWidth;
var Ajaxium_GetWindowHeight = f_GetWindowHeight;
var Ajaxium_GetScrollLeft = f_GetScrollLeft;
var Ajaxium_GetScrollTop = f_GetScrollTop;
var Ajaxium_ShowElement = f_showElement;
var Ajaxium_MoveElement = f_moveElement;
var Ajaxium_GetElementLeft = f_getElementLeft;
var Ajaxium_GetElementTop = f_getElementTop;

function f_ReplaceDocument()
{
	var l_requestFailed = true;
	//debugger;
	try
	{    
		//

		var l_lastFocus = f_getFocus();
		if(l_lastFocus == null) l_lastFocus = '';
		
		if(_G9k == null) _G9k = "";
	
		var l_regrep = new RegExp("\\/\\*AJAXIUM\\.COM\\*\\/.*\\/\\*AJAXIUM\\.COM\\*\\/", "g");
		var l_NewGs = "/*AJAXIUM.COM*/var AjaxiumEnabled=true;var _G9c="+_G9c+";var _G9d=\""+_G9d+"\";var _G9e="+_G9e+";var _G9f="+_G9f+";var _G9g="+_G9g+";var _G9i='"+l_lastFocus+"';var _G9j='"+m_OnAjaxUpdate+"';var Ajaxium_TimerInterval="+Ajaxium_TimerInterval+";var _G9k='"+_G9k+"';var _G9a='"+m_NewAjaxiumPageUid+"';var _G9b=new Array(";
	    
		for(var l_idx=0; l_idx<m_aNewContent.length; l_idx++)
		{
			l_NewGs += "\""+m_aNewContent[l_idx]+"\", ";
		};
	    
		l_NewGs += "\"\");/*AJAXIUM.COM*/";
	    
		var l_NewContent = "";
	    
		for(var l_idx=0; l_idx<m_aNewContent.length; l_idx++)
		{
			var l_str = m_aNewContent[l_idx];
			l_str = unescape(l_str);
			l_NewContent += l_str;		
		};
	    	    
		l_NewContent = l_NewContent.replace(l_regrep, l_NewGs);				
		l_NewContent = f_RewriteHiddens(l_NewContent);
	        	    
	    var l_scrollX = f_GetScrollLeft();
	    var l_scrollY = f_GetScrollTop();
	 	  	
		f_onRequestFinish(false);
	 	 	 	 
	    if(typeof(document.clear) != "undefined")
		    document.clear();
		       
		var l_oNewDoc = document.open("text/html", "replace");   
		if(typeof(l_oNewDoc)=="undefined")//konqueror & safari returns nothing in document.open
		    l_oNewDoc = window.document;
		
		l_oNewDoc.write(l_NewContent);
		
		if(typeof(l_oNewDoc.close)!="undefined")
			l_oNewDoc.close();
	
		//f_debugShowContent();
		l_requestFailed = false;

		//m_OnAjaxUpdate -- will be launched after document reload thru _G9j variable								

		//ERROR! There is no such function in the document context, since document is rewritten
		//==== f_callOnLoadingStateChange(false);
		try
        {	
	        if(typeof(Ajaxium_OnLoadingStateChange) != 'undefined')
	            Ajaxium_OnLoadingStateChange(false);
		}
		catch(m_ex) 
		{
			 
			 
		}
		//==== end of call
						
		//we do not use f_ScrollTo because it doesn't exists after document rewrite
	    if((l_scrollX != 0) || (l_scrollY != 0))
	    {    
		    window.scrollTo(l_scrollX, l_scrollY);	    
		    //the line below is for FireFox and other Gecko-based browsers
			setTimeout("window.scrollTo("+l_scrollX+", "+l_scrollY+");", 100);		
		}		
	}
	catch(m_ex)
	{
		 
		 
	}	
	
	if(l_requestFailed)
	{
	    f_onRequestFinish(true);
	    f_callOnLoadingStateChange(false);
	}
}

function f_ScrollTo(p_scrollX, p_scrollY)
{
    if(typeof(window.scrollTo) != "undefined")
    {
        window.scrollTo(p_scrollX, p_scrollY);
    }
}

var Ajaxium_ScrollTo = f_ScrollTo;

function f_ReplaceContent()
{
	var l_requestFailed = true;
	
    try
    {   
        var l_NewContent = m_aNewContent;
            
        f_onRequestFinish(false);        
    
		document.clear();
		var l_oNewDoc = document.open("text/html", "replace");   
		if(typeof(l_oNewDoc)=="undefined")//konqueror & safari returns nothing in document.open
		    l_oNewDoc = window.document;	
		l_oNewDoc.write(l_NewContent);

		if(typeof(l_oNewDoc.close)!="undefined")
			l_oNewDoc.close();

        l_requestFailed = false;		
		//f_debugShowContent();
    }
    catch(m_ex)
	{
		 
		 
	}
	
	if(l_requestFailed)
	{
	    f_onRequestFinish(true);
	}
}

function f_RewriteHiddens(p_pageContent)
{
	//debugger;
	for(var l_idx=0; l_idx<m_aNewHiddens.length; l_idx++)
	{
	    var l_value = unescape(m_aNewHiddens[l_idx][1]);
	    	    
	    if(l_value != "")
	    {	    	    
	        var l_name = unescape(m_aNewHiddens[l_idx][0]);    	    	               	       	       
	        	        	        
            var l_regrep = new RegExp("(<input\\s+type=\"hidden\"\\s*)(name=\"[^\"]*\"\\s*)?(id=\""+l_name+"\"\\s*)?(value=\"[^\"]*\")([^>]*)", "gi");
			                            	    
            p_pageContent = p_pageContent.replace(l_regrep, "$1$2$3 value=\""+l_value+"\"$5");	                           
	    }	    
    }
        
    return p_pageContent;
}

function f_UpdateHiddens()
{
	for(var l_idx=0; l_idx<m_aNewHiddens.length; l_idx++)
	{
	    var l_name = unescape(m_aNewHiddens[l_idx][0]);
	    var l_value = unescape(m_aNewHiddens[l_idx][1]);
	
	    try
	    {
	   	    var l_element = f_getElement(l_name);
	   	    
            if(typeof(l_element) != "undefined")    
            {
                l_element.value = l_value;
            } else
            {
                 
            }
	    }
	    catch(m_ex)
	    {
//there is a bug in ASP.NET 2.0, id cane come with the bogus newline: id="\r\n__VIEWSTATE"
			 
			 
			 			
	    }
	}									
}

function f_UpdateScriptObjects(p_pageContent)
{
	return p_pageContent;	
	//debugger;
	//var l_regrep = new RegExp("(<\\s*script)([^\\>]*)(>)", "gim");
	//return p_pageContent.replace(l_regrep, "$1 DEFER=\"true\" $2$3");
}

function f_getElement(p_ElementID,p_Parent)
{
    var l_elem = null;
	
	if(document.layers)
	{
		p_Parent=(p_Parent)?p_Parent:self;
		var l_Layers=p_Parent.document.layers;
		if(l_Layers[p_ElementID])
			return l_Layers[p_ElementID];
		for(var l_idx=0;l_idx<l_Layers.length;)
			l_elem=f_getElement(p_ElementID,l_Layers[l_idx++]);
		return l_elem;
	}

	if(document.all)
		return document.all[p_ElementID];
   
    if(typeof(document.getElementById)!="undefined")
	    l_elem = document.getElementById(p_ElementID);

	if(l_elem != null)
		return l_elem;

	var l_elems = null;
	
	if(typeof(document.getElementsByName)!="undefined")
	    l_elems = document.getElementsByName(p_ElementID);

	if((l_elems != null) && (l_elems.length))
		l_elem = l_elems[0];
	
	return l_elem;
}

function f_writeHTML(p_Element, p_Html)
{
	if(document.layers)
	{
	    
		var l_Layer=p_Element.document;
		l_Layer.open();
		l_Layer.write(p_Html);
		l_Layer.close();
	}
	
	var l_tagName = p_Element.tagName;
		
	if((typeof(l_tagName)!="undefined") && (l_tagName.toLowerCase() == "table"))
	{
		p_Element = p_Element.rows[0].cells[0];
	}
	
	if(typeof(p_Element.innerHTML) != 'undefined')
		p_Element.innerHTML=p_Html;
}

function f_showElement(p_ElementID, p_Show)
{
    var l_Element = f_getElement(p_ElementID);
    
    if(l_Element)
    {
        if(document.layers)
            l_Element.visibility=p_Show?'show':'hide';
        else
            l_Element.style.visibility=p_Show?'visible':'hidden';
    }
}

function Ajaxium_GetElementById(p_ElementID)
{
    return f_getElement(p_ElementID, null);
}

function f_ReplaceForm(p_startLine, p_endLine)
{	
	var l_requestFailed = true;
	
	try
	{
		var l_NewContent = "";
		
		for(var l_idx=p_startLine; l_idx<=p_endLine; l_idx++)
		{
			l_NewContent += unescape(m_aNewContent[l_idx]);	
		}
	    
		_G9i = f_getFocus();
			    
		l_NewContent = f_RewriteHiddens(l_NewContent);
		l_NewContent = f_UpdateScriptObjects(l_NewContent);
						
		var l_theform = document.forms[0];	
		f_writeHTML(l_theform, l_NewContent);
							
		_G9b = m_aNewContent;
		_G9a = m_NewAjaxiumPageUid;
		
		setTimeout(f_setValidateViewStateAndReturnFocus, 10);
		
		//f_debugShowContent();
		l_requestFailed = false;

		if(m_OnAjaxUpdate != null)
		    eval(unescape(m_OnAjaxUpdate));		
	}
	catch(m_ex)
	{
		 
		 
	}
	
	f_onRequestFinish(l_requestFailed);
	f_callOnLoadingStateChange(false);
}

function f_ReplaceDiv(p_startLine, p_endLine, p_ClientID)
{
	var l_requestFailed = true;
	
	try
	{
	    //debugger;
	    //f_showForm(document.forms[0], "f_ReplaceDiv start"); 

		var l_NewContent = "";
		
		for(var l_idx=p_startLine; l_idx<=p_endLine; l_idx++)
		{
			l_NewContent += unescape(m_aNewContent[l_idx]);	
		}
	
		_G9i = f_getFocus();
																					
		var l_thediv = f_getElement(p_ClientID);
		f_writeHTML(l_thediv, l_NewContent);
		
	    f_UpdateHiddens();
		
		_G9b = m_aNewContent;
		_G9a = m_NewAjaxiumPageUid;
							
		setTimeout(f_setValidateViewStateAndReturnFocus, 10);
				
		if(m_OnAjaxUpdate != null)
		    eval(unescape(m_OnAjaxUpdate));
		    
		//f_debugShowContent();
		
		//f_showForm(document.forms[0], "f_ReplaceDiv finish"); 
		l_requestFailed = false;
	}
	catch(m_ex)
	{
		 
		 
	}
	
	f_onRequestFinish(l_requestFailed);
	f_callOnLoadingStateChange(false);
}

function f_ReplaceDives(p_DivList)
{
	var l_requestFailed = true;
	
    try    
    {  
        _G9i = f_getFocus();
                        
        for(var l_div=0; l_div<p_DivList.length; l_div+=3)
        {
            var l_startLine = p_DivList[l_div];
            var l_endLine = p_DivList[l_div+1];
            var l_ClientID = p_DivList[l_div+2];            
            var l_NewContent = "";
                        
		    for(var l_idx=l_startLine; l_idx<=l_endLine; l_idx++)
		    {
			    l_NewContent += unescape(m_aNewContent[l_idx]);
		    }
		    
		    var l_thediv = f_getElement(l_ClientID);
		    f_writeHTML(l_thediv, l_NewContent);		    
        }       
        
	    f_UpdateHiddens();
		
		_G9b = m_aNewContent;
		_G9a = m_NewAjaxiumPageUid;
					
		setTimeout(f_setValidateViewStateAndReturnFocus, 10);
			
		if(m_OnAjaxUpdate != null)
		    eval(unescape(m_OnAjaxUpdate));
		    
		//f_debugShowContent();        
		l_requestFailed = false;
    }
    catch(m_ex)
    {
		 
		 
    }
    
    f_onRequestFinish(l_requestFailed);
    f_callOnLoadingStateChange(false);
}

function f_ReplaceNothing()
{
	var l_requestFailed = true;
	
    try
    {
        f_UpdateHiddens();
    
   		_G9b = m_aNewContent;
		_G9a = m_NewAjaxiumPageUid;

		_G9i = null;       
        f_setValidateViewStateAndReturnFocus();
        
		if(m_OnAjaxUpdate != null)
		    eval(unescape(m_OnAjaxUpdate));
		
		//f_debugShowContent();
		l_requestFailed = false;
	}
    catch(m_ex)
	{
		 
		 
	}
	
	f_onRequestFinish(l_requestFailed);
	f_callOnLoadingStateChange(false);
}

function f_ParseResponse(p_responseText)
{
//    debugger;

	m_aNewContent = new Array();
	m_aNewHiddens = new Array();
	
	var l_UpdateMethod = "";
	
	var l_profile = (typeof(_G9pf)!='undefined');
	var l_profileCurPos = 0;
		
	//try
	{
		var l_splittedText = p_responseText.split("\n");
				
		for(var l_idx=0; l_idx<l_splittedText.length; l_idx++)
		{
			var l_line = l_splittedText[l_idx];
			
			if(l_line.length<2)
				continue;
			
			if((l_line.charAt(1)!=' ')&&(l_line.charAt(2)!=' '))
				continue;
								
			var l_firstChar = l_line.charAt(0);
			
			if(l_firstChar=='=')
			{			
				var l_data = l_line.split(" ");
				
				var l_startLine = parseInt(l_data[1]);
				var l_endLine = parseInt(l_data[2]);
				
				if(_G9b != null)			
				{
					for(var l_oldLine=l_startLine; l_oldLine<=l_endLine; l_oldLine++)
					{
						var l_str = _G9b[l_oldLine];
						m_aNewContent[m_aNewContent.length] = l_str;
					}				
				} else
				{
					for(var l_oldLine=l_startLine; l_oldLine<=l_endLine; l_oldLine++)
					{
						m_aNewContent[m_aNewContent.length] = null;
					}
				}
			} else if (l_firstChar=='+')
			{			
				var l_data = l_line.split(" ");
				var l_str = l_data[1];			
				m_aNewContent[m_aNewContent.length] = l_str;
			} else if (l_firstChar=='s')
			{
				var l_data = l_line.split(" ");
				var l_pos = m_aNewHiddens.length;

				if(l_data.length == 3)
				    m_aNewHiddens[l_pos] = new Array(l_data[1], l_data[2]);
				else
			        m_aNewHiddens[l_pos] = new Array(l_data[1], "");
				
			} else if (l_firstChar==':') 
			{
				var l_data = l_line.split(" ");
				var l_cmd = l_data[1];
				
				if(l_cmd == "f")
				{
					var l_startLine = parseInt(l_data[2]);
					var l_endLine = parseInt(l_data[3]);
					
					l_UpdateMethod = "f_ReplaceForm("+l_startLine+","+l_endLine+");";					
				} else if (l_cmd == "b")
				{
					l_UpdateMethod = "f_ReplaceDocument();";					
				} else if (l_cmd == "s")
				{
					l_UpdateMethod = "f_ReplaceDocument();";
				} else if (l_cmd == "d")
				{
					var l_startLine = parseInt(l_data[2]);
					var l_endLine = parseInt(l_data[3]);
					var l_clientid = l_data[4];
//-------------					
					for(var l_idxTest=l_startLine; l_idxTest<=l_endLine; l_idxTest++)
					{
						if(m_aNewContent[l_idxTest]==null)
							throw "arr["+l_idxTest+"]=null";
					}	
//-------------					
					l_UpdateMethod = "f_ReplaceDiv("+l_startLine+","+l_endLine+",\""+l_clientid+"\");";					
				} else if(l_cmd == "n")
				{
				    l_UpdateMethod = "f_ReplaceNothing();";
				} else if(l_cmd == "l")
				{
				    var l_arrayDecl = "new Array(";
				
				    for(var l_parseIdx = 2; l_parseIdx+2<l_data.length; l_parseIdx+=3)
				    {
				        if(l_arrayDecl.length>11)
				            l_arrayDecl += ",";
				    
				        l_arrayDecl += l_data[l_parseIdx] + ",";
				        l_arrayDecl += l_data[l_parseIdx+1] + ",";
				        l_arrayDecl += "\""+l_data[l_parseIdx+2] + "\"";
//-------------				        
						for(var l_idxTest=l_data[l_parseIdx]; l_idxTest<=l_data[l_parseIdx+1]; l_idxTest++)
						{
							if(m_aNewContent[l_idxTest]==null)
								throw "arr["+l_idxTest+"]=null";
						}	        
//-------------						
				    }
				
				    l_arrayDecl += ")";
				    l_UpdateMethod = "f_ReplaceDives("+l_arrayDecl+");";
				}
			} else if (l_firstChar=='_')
			{
				var l_data = l_line.split(" ");
				if(l_data[1] == "uua")
				{
					m_NewAjaxiumPageUid = l_data[2];
				} else if(l_data[1] == "scr")
				{
				    if(l_data.length > 1)
				        m_OnAjaxUpdate = l_data[2];
				    else
				        m_OnAjaxUpdate = null;
				} else if(l_data[1] == "adv")
				{
					var l_section = l_data[2];
					var l_color = l_data[3];					
					var l_head = unescape(l_data[4]);
					var l_text = unescape(l_data[5]);
					
					
				} else if(l_data[1] == "ldp")
				{
					_G9k = "";
					for(var l_panelIdx=2; l_panelIdx<l_data.length; l_panelIdx++)
					{
						_G9k = _G9k+l_data[l_panelIdx]+" ";
					}
				}
			} else if(l_firstChar=='V')
			{
							
			}
		}
	}
	
	
	
	return l_UpdateMethod;
}

function f_GetActiveX(p_ActiveXName)
{
    return new ActiveXObject(p_ActiveXName);
}

function f_GetXmlRequestActiveX() 
{
  var l_supported = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];

  var l_returnValue = null;  
  for (var l_idx = 0; l_idx < l_supported.length; l_idx++) {
    try {
      l_returnValue = f_GetActiveX(l_supported[l_idx]);
      break;
    }
    catch (m_ex) {
    }
  }
  return l_returnValue;
}

function f_GetXmlRequestObject()
{
	var l_returnValue = null;  
	// Get setup for XMLHttpRequest if possible
	if (window.XMLHttpRequest)
	{
		l_returnValue = new XMLHttpRequest();
	} else 
	{// IE5 for the mac claims to support window.ActiveXObject, but throws an error when it's used
		if (window.ActiveXObject && !(navigator.userAgent.indexOf('Mac') >= 0 && navigator.userAgent.indexOf("MSIE") >= 0))
		{
      			l_returnValue = f_GetXmlRequestActiveX();
		}
	}

	return  l_returnValue;
}

function f_utf8(p_wide) {
  var l_utf8_c;
  var l_utf8_s;
  p_wide = "" + p_wide; // Make sure it is a string
  var l_enc_res = "";
  var l_utf8_i = 0;
  while(l_utf8_i<p_wide.length) {
    l_utf8_c= p_wide.charCodeAt(l_utf8_i++);
    // handle UTF-16 surrogates
    if (l_utf8_c>=0xDC00 && l_utf8_c<0xE000) continue;
    if (l_utf8_c>=0xD800 && l_utf8_c<0xDC00) {
      if (l_utf8_i>=p_wide.length) continue;
      l_utf8_s= p_wide.charCodeAt(l_utf8_i++);
      if (l_utf8_s<0xDC00 || l_utf8_c>=0xDE00) continue;
      l_utf8_c= ((l_utf8_c-0xD800)<<10)+(l_utf8_s-0xDC00)+0x10000;
    }
    // output value
    if (l_utf8_c<0x80) l_enc_res += String.fromCharCode(l_utf8_c);
    else if (l_utf8_c<0x800) l_enc_res += String.fromCharCode(0xC0+(l_utf8_c>>6),0x80+(l_utf8_c&0x3F));
    else if (l_utf8_c<0x10000) l_enc_res += String.fromCharCode(0xE0+(l_utf8_c>>12),0x80+(l_utf8_c>>6&0x3F),0x80+(l_utf8_c&0x3F));
    else l_enc_res += String.fromCharCode(0xF0+(l_utf8_c>>18),0x80+(l_utf8_c>>12&0x3F),0x80+(l_utf8_c>>6&0x3F),0x80+(l_utf8_c&0x3F));
  }
  return l_enc_res;
}

function f_toHex(p_number) {
  return m_hexChars.charAt(p_number>>4)+m_hexChars.charAt(p_number & 0xF);
}

function f_encodeURIComponent(p_str) {
  var l_enc_s = f_utf8(p_str);
  var l_enc_c;
  var l_enc_res = "";
  for (var l_enc_i= 0; l_enc_i<l_enc_s.length; l_enc_i++) {
    if (m_okURIchars.indexOf(l_enc_s.charAt(l_enc_i))==-1)
      l_enc_res += "%"+f_toHex(l_enc_s.charCodeAt(l_enc_i));
    else
      l_enc_res += l_enc_s.charAt(l_enc_i);
  }
  return l_enc_res;
}

//throws error if browser is known as unsupported
function f_BrowserHelper()
{
	if(m_BrowserHelperCalled)
		return true;
	
//	if((typeof(document)=="undefined")||(typeof(document.readyState)=="undefined"))
//	{
//	    alert("typeof(document)=="+typeof(document));
//	    alert("typeof(document.readyState)=="+typeof(document.readyState));
//	    alert("document.readyState="+document.readyState);
//	    return false;   
//	}
	
	//there is not encodeURIComponent in IE 5.0
	if (typeof window.encodeURIComponent === 'undefined')
		window.encodeURIComponent = f_encodeURIComponent;

	m_BrowserHelperCalled = true;
	
	return true;
}

// F O C U S
function f_isFocusableTag(p_tagName) 
{
    return (p_tagName == "input" || p_tagName == "textarea" || p_tagName == "select" || p_tagName == "button" || tagName == "a");
}

function f_IsInVisibleContainer(p_Element) 
{
    var l_Current = p_Element;
    while((typeof(l_Current) != "undefined") && (l_Current != null)) 
    {
        if (l_Current.disabled ||
            ( typeof(l_Current.style) != "undefined" &&
            ( ( typeof(l_Current.style.display) != "undefined" &&
                l_Current.style.display == "none") ||
                ( typeof(l_Current.style.visibility) != "undefined" &&
                l_Current.style.visibility == "hidden") ) ) ) 
        {
            return false;
        }
        
        if (typeof(l_Current.parentNode) != "undefined" &&
                l_Current.parentNode != null &&
                l_Current.parentNode != l_Current &&
                l_Current.parentNode.tagName.toLowerCase() != "body") 
        {
            l_Current = l_Current.parentNode;
        }
        else 
        {
            return true;
        }
    }
    return true;
}

function f_CanFocus(p_Element) 
{
    if ((p_Element==null) || (p_Element.tagName == null)) 
		return false;
		
    var l_tagName = p_Element.l_tagName.toLowerCase();
    
    if(p_Element.tagName == "undefined")
		return false;
    
    return (!(p_Element.disabled) &&
            (!(p_Element.type) || p_Element.type.toLowerCase() != "hidden") &&
            f_isFocusableTag(l_tagName) &&
            f_IsInVisibleContainer(p_Element)
            );
}

function f_FindFirstFocusableChild(p_Control) 
{
    if(!p_Control || !(p_Control.tagName))
        return null;
    
    var l_tagName = p_Control.tagName.toLowerCase();
    if(l_tagName == "undefined")
        return null;
        
    var l_Children = p_Control.childNodes;
    if(l_Children) 
    {
        for(var l_idx = 0; l_idx < l_Children.length; l_idx++) 
        {
            try 
            {
                if(f_CanFocus(l_Children[l_idx]))
                {
                    return l_Children[l_idx];
                } else 
                {
                    var l_Focused = f_FindFirstFocusableChild(l_Children[l_idx]);
                    if(f_CanFocus(l_Focused)) 
                    {
                        return l_Focused;
                    }
                }
            }
            catch (m_ex) {}
        }
    }
    return null;
}

function f_setFocus(p_ElementID)
{
	if((p_ElementID == null) || (p_ElementID == ""))
		return;

    var l_Element = f_getElement(p_ElementID);
    
    if(l_Element == null)
		return;
    
    try
    {
		if(typeof(l_Element.focus) != "undefined")
		{
				l_Element.focus();        
				//if(l_Element.scrollIntoView)
		} else
		{
			var l_Focused = null;
			if (!f_CanFocus(l_Element))
			{
				l_Focused = f_FindFirstFocusableChild(targetControl);
			}
		
			if (l_Focused) 
			{
				l_Focused.focus();            
				//focused.scrollIntoView(false);        
			}
		}     
    } catch(m_ex)       
    {
    }
}

function f_getFocus()
{
	var l_ElementId = null;
	
	try
	{
		var l_Active = null;
		
		if(typeof(document.activeElement) != "undefined")
			l_Active = document.activeElement;		
		else if(typeof(document.currentFocus) != "undefined")
			l_Active = document.currentFocus;
		else
		{
			var l_theform = document.forms[0];
						
			if(typeof(l_theform.__LASTFOCUS) != "undefined")
				l_ElementId = l_theform.__LASTFOCUS.value;
			
			if(((l_ElementId == null) || (l_ElementId.length == 0)) && (typeof(l_theform.__EVENTTARGET) != "undefined"))
				l_ElementId = l_theform.__EVENTTARGET.value.split(":").join("$");

			if(((l_ElementId == null) || (l_ElementId.length == 0)) && (m_lastActiveLinkID != null))
			{
				l_ElementId = m_lastActiveLinkID;
				m_lastActiveLinkID = null;
			}
			
			if(l_ElementId == "") 
				l_ElementId = null;		
		}
			
		if ((l_ElementId == null) && (typeof(l_Active) != "undefined") && (l_Active != null)) 
		{
			if ((typeof(l_Active.id) != "undefined") && (l_Active.id != null) && (l_Active.id.length > 0)) 
				l_ElementId = l_Active.id;
			else if (typeof(l_Active.name) != "undefined") 
				l_ElementId = l_Active.name;
		}		
    } catch(m_ex)       
    {
    }
    
    return l_ElementId;
}

var Ajaxium_SetFocus = f_setFocus;
/*end*/