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)
    }
}
