var giMatrixVersion;

function __doPostBack(eventTarget, eventArgument) 
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.Form1;
		//alert(eventTarget);
	}
	else 
	{
		theform = document.forms["Form1"];
		//alert(eventTarget);
	} 
	theform = document.forms[0];

    // Matrix ?
    if(giMatrixVersion >= 2)
    {
        // Updates elements (sets true/false value for checkbox)
        for(var i=0; i<document.forms[0].elements.length; i++)
        {
            // Checkbox ?
            if(document.forms[0].elements[i].type == "checkbox")
            {
                // true ?
                if(document.forms[0].elements[i].checked)
                {
                    document.forms[0].elements[i].value = "true";
                }
                else
                {
                    document.forms[0].elements[i].value = "false";
                }
            }
        }

        // Serialize viewstate
        if(Matrix2.goViewState != TOOLS_UNDEFINED_VALUE)
        {
            document.forms[0].elements[MATRIX2_VIEWSTATE_ID].value = json.serialize(Matrix2.goViewState);
        }
    }
    
  if(document.forms[0].elements["__EVENTTARGET"] != null)
  {
	 document.forms[0].elements["__EVENTTARGET"].value   = eventTarget
  }
  if(document.forms[0].elements["EVENTTARGET__"] != null)
  {
	 document.forms[0].elements["EVENTTARGET__"].value   = eventTarget
  }
  
  if(document.forms[0].elements["__EVENTARGUMENT"] != null)
  {
  	document.forms[0].elements["__EVENTARGUMENT"].value = eventArgument
  }
  if(document.forms[0].elements["EVENTARGUMENT__"] != null)
  {
	  document.forms[0].elements["EVENTARGUMENT__"].value = eventArgument
  }
	
	theform.submit();
}
function SaveScrollPosition(id)
{
	document.forms[0].elements["SCROLLPOSITION"].value = id;
}
function LoadScrollPosition()
{
	document.body.scrollTop = document.forms[0].elements["SCROLLPOSITION"].value;	
}

function ConfirmDelete(eventTarget, eventArgument, message)
{
	if(confirm(message) == true) __doPostBack(eventTarget, eventArgument);
}

function openChildWindow(url, name, parameters )
{
	var oWin = window.open(url, name, parameters);
	oWin.focus();
	return false;
}
function SetActiveKey(sKey)
{
	document.forms[0].elements["ActiveField"].value = sKey;
}

function OpenHelp(Link, WindowName)
{
	var Attributes = 'width=440, height=600,alwaysRaised=yes,toolbar=0,directories=0,menubar=0,status=1,resizable=yes,location=0,scrollbars=1,copyhistory=0,';
	
	var PositionAttributes = 'left=' + (screen.width - 440) + ',top=0,screenX=' + (screen.width - 440) + ',screenY=0';
	
	Attributes = Attributes + PositionAttributes;
	
	window.open(Link, WindowName, Attributes);
}

function OpenSaveSearch(Link)
{
	var Attributes = 'width=400, height=180,alwaysRaised=yes,toolbar=0,directories=0,menubar=0,status=1,resizable=no,location=0,scrollbars=0,copyhistory=0';
	
	var PositionAttributes = 'left=' + ((screen.width / 2) - 200) + ',top=' + ((screen.height / 2) - 90) + ',screenX=' + ((screen.width / 2) - 200) + ',screenY=' + ((screen.height / 2) - 90) + '';
	
	Attributes = Attributes + PositionAttributes;
	
	window.open(Link, '', Attributes);
}





function GetSubDivCount(_sTopDivName)
{

    var iMax = null;
    var iDivCount = 0;

    // Get the number of submenu items (childs of link_bottom))
    var aoSubList = document.getElementById(_sTopDivName).childNodes;

    iMax = aoSubList.length;

    return iMax;
}

// Shows a submenu and hide the other sub menus
function ShowSubMenu(_sTopDiv, _sDivToShow)
{
    var iMax = GetSubDivCount(_sTopDiv)

    var aoSubList = document.getElementById(_sTopDiv).childNodes;

    // Loop on sub menus
    for (var idx = 0; idx < iMax; idx++)
    {
        if ( aoSubList[idx].nodeName == 'DIV' )
        {
            // We are not on the submenu to show
            if (aoSubList[idx].id != _sDivToShow)
            {
                  // Hides the sub menu
                  aoSubList[idx].style.display = 'none';
            }
            else
            {
                  // Shows the sub menu
                  aoSubList[idx].style.display = 'block';
            }
        }
    }
}


	function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
	function thisMovie(movieName) {
	    if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};

function ImposeMaxLength(Object, MaxLen)
{   
    if (Object.getAttribute && Object.value.length>MaxLen)
    {
        Object.value=Object.value.substring(0,MaxLen)
    }
}

var goTooltipsOver = new Object();
var goTooltipsSourceOver = new Object();
var msLastTooltip = null;

function CreateTooltip(_sSource, _sTooltip)
{
    var oParent = document.getElementById(_sTooltip);
    
    // create encapsulate
    var oTooltip = document.createElement("div");
    oTooltip.className = "TooltipClass";
    
    var oInnerTooltip = document.createElement("div");
    oInnerTooltip.className="InnerTooltipClass";
    
    oTooltip.appendChild(oInnerTooltip);
    
    var oNodeList = oParent.childNodes;
    
    var iMargin = 0;
    
    while (oParent.firstChild)
    {
        oInnerTooltip.appendChild(oParent.firstChild);        
        iMargin += 13;
    }
    
    oParent.style.marginTop = -iMargin - 45;
    
    oParent.appendChild(oTooltip);
    
    YAHOO.util.Dom.setStyle(oParent, "opacity", "0");
    YAHOO.util.Dom.setStyle(oParent, "display", "none");
    
    AddEvent(_sTooltip, "mouseover", function(event)
    {        
        if (IsMouseLeaveOrEnter(event, _sSource))
        {
            goTooltipsOver[_sTooltip] = true;
        }
    });
    
    AddEvent(_sTooltip, "mouseout", function(event)
    {       
        if (IsMouseLeaveOrEnter(event, _sSource))
        {         
            goTooltipsOver[_sTooltip] = false;
            
            window.setTimeout(function() { HideTooltip(_sTooltip); }, 1000);
        }
    });
    
    AddEvent(_sSource, "mouseover", function(event)
    { 
        if (IsMouseLeaveOrEnter(event, _sTooltip))
        {
            goTooltipsSourceOver[_sTooltip] = true;
            
            ShowTooltip(_sTooltip);
        }
    });
    
    AddEvent(_sSource, "mouseout", function(event)
    {     
        if (IsMouseLeaveOrEnter(event, _sTooltip))
        {          
            goTooltipsSourceOver[_sTooltip] = false;
            
            window.setTimeout(function() { HideTooltip(_sTooltip); }, 1000);
        }
    });
}

function ShowTooltip(_sTooltip)
{
    if (YAHOO.util.Dom.getStyle(_sTooltip, "opacity") == "0")
    {
        if (msLastTooltip)
        {
            YAHOO.util.Dom.setStyle(msLastTooltip, "opacity", "0");
            YAHOO.util.Dom.setStyle(msLastTooltip, "display", "none");
        }
        
        YAHOO.util.Dom.setStyle(_sTooltip, "display", "block");
        
        var myAnim = new YAHOO.util.Anim(_sTooltip, { 
            opacity: { to: 0.9 }  
        }, 0.2, YAHOO.util.Easing.easeOut); 
        
        myAnim.animate();
        
        msLastTooltip = _sTooltip;
    }
}

function HideTooltip(_sTooltip)
{
    if (!goTooltipsSourceOver[_sTooltip] && !goTooltipsOver[_sTooltip])
    {
        var myAnim = new YAHOO.util.Anim(_sTooltip, { 
            opacity: { to: 0 }  
        }, 0.2, YAHOO.util.Easing.easeOut); 
       
        myAnim.onComplete.subscribe(function() {            
            YAHOO.util.Dom.setStyle(_sTooltip, "display", "none");
        });
        
        myAnim.animate();
    }
}

function IsMouseLeaveOrEnter(e, handler) 
{ 
    if (e.type != 'mouseout' && e.type != 'mouseover' && e.type != 'mouseup') return false; 
    
    var reltg;
    
    if (e.relatedTarget)
    {
        reltg = e.relatedTarget;
    }
    else if(e.type == 'mouseout')
    {
        reltg = e.toElement;
    }
    else if(e.type == "mouseover")
    {
        reltg = e.fromElement; 
    }
    else if (e.type == "mouseup")
    {
        reltg = (e.target)? e.target : e.srcElement;
    }
    
    while (reltg && reltg != handler)
    { 
        reltg = reltg.parentNode;
    } 
    
    return (reltg != handler);     
}

function AddEvent(_oObj, _sEvent, _oFn, _oScope, _oArgs)
{
    _oObj = document.getElementById(_oObj);
    
    if (_oObj)
    {        
        if (!_oScope)
        {
            _oScope = _oObj;
        }
        
        var oFn = function(e) {
            return _oFn.call(_oScope, e, _oArgs);
        };
        
        if (window.addEventListener) {        
            _oObj.addEventListener(_sEvent, oFn, false);         
        } else if (window.attachEvent) {        
            _oObj.attachEvent("on" + _sEvent, oFn);         
        }
    }
}
