//Copyright (c) 2000 Microsoft Corporation.  All rights reserved.
//<script>
var m_objRowLastSelected = null;
var m_objContextMenu = null;
var m_szXSLSRC=null;//internal variable that holds the path to the XSL page to be used
var m_objXML = null;
var m_objCurrentXML=null;//XML object returned by m_objMSHTTP_Request, set in event_onreadystatechange_listenXML()
var m_icurGrpLevel = 1;
var m_objXSLNodes = null;
var m_objSearchNodes = null;
var m_iStoreType = 0;   //storeType property 0 = private 1 = public
var m_objMSHTTP_Request=null;
var m_szURL = null;
var m_objHTMLTarget = this;
var m_objTopRow = null;
var m_objBottomRow = null;
var m_objStartRow = null;
var m_rowColor = "";
var m_rowBackGroundColor = "";
var m_szLinkSpec = null;  //Supports linkSpec Property
var m_szAcceptLang = "";
var m_szTarget   = null;  //Supports target Property
var m_objAnchor  = null;  //Anchor to implement linkSpec functionality
var m_szViewType = "table"  //This variable is set to 'card' if card node exists in view descriptor
var UP = 0;
var DOWN = 1;
var m_iMaxCols = 3;
//Paging variables
var m_iCurrentGoToPage=1;
var m_iCurrentPageNumber=0;
var m_iMaxPageNumber=0;
var m_iCurrentStartRange=0;
var m_iCurrentRowsNumber=25;
var m_imaxRows;
var m_obj_onHTTPOperationElement = null;
var m_objLastDraggedElements = null;
var m_szEmptyURL="about:blank";

var m_currentSelectionType = null;
var m_objRowRange = null;

var m_objViewXML; //Contains all xsl nodes for groups and content views
var m_objViewDescription; //Contains main view description
var m_objQueries;
var m_objAnchorsSelected = null;
var m_rgszOpenMessageCommands = new Array();
var m_gobjHTTPSpecialFolders;
var m_rgSpecialFolderURL = new Array();
var m_gCallBack;

var m_szViewClassURL = "";
var m_objTransFormXSL = null; //XSL for view class
var m_rgszPropertySynonyms = new Array();
var m_szNormalizedSubject = "http://schemas.microsoft.com/mapi/proptag/x0e1d001f"
m_rgszPropertySynonyms["urn:schemas:httpmail:subject"]  = m_szNormalizedSubject
m_rgszPropertySynonyms["urn:schemas:mailheader:subject"] = m_szNormalizedSubject
m_rgszPropertySynonyms["http://schemas.microsoft.com/mapi/subject"] = m_szNormalizedSubject


m_rgszOpenMessageCommands[0] = "open";
m_rgszOpenMessageCommands[1] = "reply";
m_rgszOpenMessageCommands[2] = "replyall";
m_rgszOpenMessageCommands[3] = "forward";

function RowRange(objStartRow, objEndRow)
{
	var iDelta = objStartRow.sourceIndex - objEndRow.sourceIndex
	var objNextRow;
	
	this.rangeDirection = 0;
	
	if (iDelta == 0)
	{
		mf_selectRecord(objStartRow, true)
	}
	else
	{
		this.rangeDirection = (iDelta < 0)?DOWN:UP;
		mf_selectRecord(objStartRow, true)
		objNextRow = mf_getNextRow(objStartRow,this.rangeDirection)

		for( ;objNextRow.uniqueID != objEndRow.uniqueID &&
			  mf_selectRecord(objNextRow);)
		{
			objNextRow = mf_getNextRow(objNextRow,this.rangeDirection)
		}
		mf_selectRecord(objEndRow)
	}
	this.startRow = objStartRow;
	this.tempEndRow = objEndRow;
	this.endRow   = objEndRow;

	this.trimRange = mf_trimRowRange;
	this.expandRange = mf_expandRange;
	this.update =  mf_updateRowRange;

}




function QueryCollection(xmlViewDescription)
{
	this.xmlDescription  = xmlViewDescription;
	this.scope           = "FROM Scope('SHALLOW TRAVERSAL OF \"\"')";
	this.queryCollection = new Array();
	this.defaultRestriction = "";

	var filterNode = xmlViewDescription.selectSingleNode("view/filter")

	if (filterNode != null)
	{
		if (filterNode.text != "")
		{
			this.defaultRestriction = filterNode.text
		}
	}

	this.createQueryObjects = createQueryObjects;

	return(this.createQueryObjects(this.xmlDescription));

}

function QueryObject(parentObj, szType, xmlObj, iChildNumber)
{

	this.parentObject = parentObj;
	this.columunPropNodes = null;
	this.selectString  = "";
	this.groupByNodes  = null;
	this.groupByString = "";

	this.orderByPropNodes = null;
	this.orderByString = "";
	this.type = szType;
	this.restriction = "";
	switch(szType)
	{
		case "content":
			 //Set column prop
			var queryNodes        = xmlObj.selectNodes("view/column/prop");
			this.columunPropNodes = queryNodes;
			this.selectString     = createSelectSQL(queryNodes);
			this.defaultProps     = '"urn:schemas:httpmail:read" as read,"http://schemas.microsoft.com/mapi/proptag/x001a001f" as contentclass';
			//Set order by node
			var orderbyNodes      = xmlObj.selectNodes("view/orderby/order");
			this.orderByPropNodes = orderbyNodes;
			this.orderByString    = createOrderBySQL(orderbyNodes);

			break;
		case "categorized":

			this.defaultProps     = '"DAV:visiblecount","urn:schemas:httpmail:unreadcount"';
			var objPropNodes      = xmlObj.selectNodes("order/prop")

			var objOrderNodes     = xmlObj.selectNodes("order")
			this.orderByString    = createOrderBySQL(objOrderNodes);
			var szSQL = "";
			var szProp = "";
			for(x=0;x < objPropNodes.length;x++)
			{
				szProp = objPropNodes.item(x).text;
				if (m_rgszPropertySynonyms[objPropNodes.item(x).text] != null)
				{
				   szSQL += '"' + m_rgszPropertySynonyms[szProp] + '",';
				   objPropNodes.item(x).text = m_rgszPropertySynonyms[objPropNodes.item(x).text];
				}
				else
				{
					szSQL += '"' + szProp + '",';
				}
			}
			szSQL = szSQL.substring(0,szSQL.length -1) + ' ';
			this.groupByString = szSQL;
			this.selectString     = createSelectSQL(objPropNodes, iChildNumber);
			break;
		default:
			break;
	}


	this.searchRequest = createSearchRequest;

	return(this)

}

//fXMLStream - If true then the sql query is encapsulated in xml
//           - If false then just the sql statement is returned.
function createSearchRequest(fXMLStream)
{
	var szCRLF = "\r\n";
	var szSQL = "SELECT " + this.selectString + this.defaultProps + szCRLF +
				this.parentObject.scope + szCRLF;
	var szRestriction;

	if(this.defaultRestriction !="")
	{
		szRestriction = this.parentObject.defaultRestriction;
		fRestriction = true;

	}
	if (this.restriction != "")
	{
	   if (fRestriction = true)
	   {
		szRestriction += " AND ";
	   }
	   szRestriction += this.restriction;
	   fRestriction = true;
	}
	if(fRestriction)
	{
		szSQL += "WHERE " + szRestriction + szCRLF;
	}


	if(this.type == "categorized")
	{
		szSQL += "GROUP BY " + this.groupByString + szCRLF;
	}
	if (this.orderByString != "")
	{
		szSQL += "ORDER BY " + this.orderByString;  
	}
	
	if(fXMLStream)
	{
		szSQL = mf_createSearchRequestXML(szSQL);
	}
	
	return(szSQL);
}



function createQueryObjects(xmlViewObject)
{
	
	//Swap message class prop for the icon property
	var szSmallIconProp     = "http://schemas.microsoft.com/exchange/smallicon";
	var objCollMsgClass  = xmlViewObject.selectNodes("view/column[bitmap = '1']/prop[.='http://schemas.microsoft.com/exchange/outlookmessageclass']") 
	var x;
	if(objCollMsgClass != null)
	{
		for(x=0; x < objCollMsgClass.length; x++)
		{
			objCollMsgClass.item(x).text = szSmallIconProp;
		}
	}
	
	var groupbyNodes = xmlViewObject.selectNodes("view/groupby");
	if (groupbyNodes != null)
	{
		var i=0;

		for (i=0; i < groupbyNodes.length; i++)
		{
			var queryObject = new QueryObject(this, "categorized", groupbyNodes.item(i), i+ 1);
			this.queryCollection[i] = queryObject;
		}

		var contentQueryObject = new QueryObject(this, "content", xmlViewObject)

		this.queryCollection[i] = contentQueryObject;

	}
	return(this.queryCollection);
}


/*************************BEGIN PROPERTY ACCESS FUNCTIONS********************************/

function get_iStoreType(iStore)
{
	return (m_iStoreType);

}


function put_iStoreType(iStore)
{
	m_iStoreType = iStore;
	return(true);

}

function get_AcceptLang()
{
	return(m_szAcceptLang)
}

function put_AcceptLang(szAcceptLang)
{
	m_szAcceptLang = szAcceptLang;
}

function put_szURL(szURL)
{
	m_szURL = szURL;
}
function get_szURL()
{
	return(m_szURL)
}
function get_xslSrc()
{
	return(m_szXSLSRC);
}

function get_rowsPerPage()
{
	return(m_iCurrentRowsNumber)
}
function put_rowsPerPage(iNum)
{
	var num = parseInt(iNum);
	if(isNaN(num) != true)
	{
		m_iCurrentRowsNumber = num;
		return(true)
	}
	else
	{
		return(false)
	}

}

function put_xslSrc(szXSLPath)
{
	m_icurGrpLevel = 1;
	m_objRowRange = null;
	m_szXSLSRC =  szXSLPath;
	mf_getViewDescriptor( m_szXSLSRC)

	m_objQueries = new QueryCollection(m_objViewDescription)

}

function put_szViewClass(szViewClassURL)
{
	m_szViewClassURL = szViewClassURL;
	
	if(m_szViewClassURL != "auto")
	{
		m_objTransFormXSL = new ActiveXObject("Microsoft.XMLDOM");
		m_objTransFormXSL.async = false;
		m_objTransFormXSL.load(m_szViewClassURL);
	}
	

}

function get_szViewClass(szViewClassURL)
{
	return(m_szViewClassURL);

}

function put_linkSpec(szLinkSpec)
{
	m_szLinkSpec = szLinkSpec;
	if( null != m_szLinkSpec && m_szLinkSpec.length )
	{
		if( !put_linkSpec._fAttached )
		{
			put_linkSpec._fAttached = this.attachEvent("onSelectItem", event_doLinkAction)
		}

		if( null != m_objRowLastSelected )
		{
			var objEvent = createEventObject();
			objEvent.contentClass = m_objRowLastSelected.contentClass;
			objEvent._href        = m_objRowLastSelected._href
			objEvent.row          = m_objRowLastSelected;
			event_doLinkAction(objEvent);
		}
		else
		{
			event_doLinkAction(null);
		}
	}
	else if( put_linkSpec._fAttached )
	{
		this.detachEvent("onSelectItem", event_doLinkAction);
		put_linkSpec._fAttached = false;
		m_szLinkSpec = null;
	}
}
put_linkSpec._fAttached = false;
function get_Query()
{
	if( m_objQueries[0] != null)
	{
		//Call searchRequest with false parameter to return sql only
		return(m_objQueries[0].searchRequest(false))
	}
	else
	{
		return(null);
	}	
}
function get_linkSpec()
{
	return(m_szLinkSpec)
}

function put_target(szTarget)
{
	m_szTarget = szTarget;
}

function get_target()
{
	return(m_szTarget)
}

function put_emptyURL( szURL )
{
	m_szEmptyURL = szURL;
}

function get_emptyURL()
{
	return( m_szEmptyURL );
}

/*************************END PROPERTY ACCESS FUNCTIONS********************************/

/*************************BEGIN EVENT HANDLER FUNCTIONS********************************/


function expandGroup(objElement)
{


	var objTR = objElement.parentElement;
	var objTable = objTR.parentElement;
	objNextTR = objTable.rows(objTR.rowIndex + 1);
	objNextTR.style.display = ( objNextTR.style.display=="")?"none":"";
	if (objNextTR.style.display == "")
	{
		mf_getNodeData(objNextTR.children(0),objElement);
	}
}


function event_doLinkAction(objEvent)
{
	if( null == m_szLinkSpec )
	{
		return;
	}

	var szHREF = ( null == objEvent ) ? m_szEmptyURL : m_szLinkSpec.replace(/%DataUrl%/gi,objEvent._href)
	if( m_objAnchor == null)
	{
		m_objAnchor = document.createElement("A")
		m_objAnchor.style.display = "none"
		this.insertAdjacentElement("afterEnd", m_objAnchor) 
	}
	if(null != m_szTarget)
	{
		m_objAnchor.href = szHREF;
		m_objAnchor.target = m_szTarget;
		m_objAnchor.click();
	}		
	if( null != objEvent )
	{
		mf_unboldRow(objEvent.row)
	}
}

function event_getspecialfolderscompleted()
{
	if(m_gobjHTTPSpecialFolders != null && m_gobjHTTPSpecialFolders.readyState == 4)
	{
		var xmlResponseXML = m_gobjHTTPSpecialFolders.responseXML;

		m_gobjHTTPSpecialFolders = null

		var xmlNodes = xmlResponseXML.selectNodes("a:multistatus/a:response/a:propstat/a:prop/*");
		var szURLNode = xmlResponseXML.selectNodes("a:multistatus/a:response/a:href");;
		var i;
		if(szURLNode[0] != null)
		{
			szURLNode = szURLNode[0].text;
			m_szCurrentPrivURL = szURLNode;
		}
		for(i=0;i <= xmlNodes.length - 1; i++)
		{
		   m_rgSpecialFolderURL[xmlNodes.item(i).baseName] = xmlNodes.item(i).text;
		}
		m_gCallBack();
	}
}

function event_ondocumentready()
{
	if (m_szURL == null || m_szURL =="")
	{
		m_szURL = window.location.protocol + "//" +  window.location.hostname + window.location.pathname;
	}
	
	if(m_szViewClassURL != "auto")
	{
		m_objViewXML    = createViewXML(m_objViewDescription,m_objTransFormXSL);
	}   
	m_objXSLNodes = m_objViewXML.selectNodes("view/group/xsl:template");
	m_icurGrpLevel =    1;
	szSearchXML = m_objQueries[0].searchRequest(true);
	m_gCallBack = mf_fireOnPageRefresh;

	var iEndRange     = m_iCurrentRowsNumber-1;
	mf_getXML( m_szURL, szSearchXML,m_iCurrentStartRange, iEndRange );

}


function event_onkeydown()
{

	event.cancelBubble = true;
	event.returnValue = false
	var sc;
	var objRow;

	try
	{
		switch(event.keyCode)
		{
			
			case 39: //right
			case 40: //down
				if(!event.shiftKey)
				{
					objRow = m_objRowLastSelected;
					m_objRowRange = null;

					var objNextRow = mf_getNextRow(objRow,  DOWN)
					if (objNextRow != false)
					{
							mf_unselectAll();
							mf_selectRecord(objNextRow, true);
							mf_scrollIntoView(objNextRow);
							m_objRowLastSelected = objNextRow;
					}
				}
				else
				{
					if (m_objRowRange == null)
					{
						var objAnchor = m_objRowLastSelected
						objAnchor.id = "rowSelectedException";
						mf_unselectAll();
						objAnchor.id = "selected"
						objEndRow = mf_getNextRow(m_objRowLastSelected, DOWN)
						if(objEndRow != false )
						{
							m_objRowRange = new RowRange(m_objRowLastSelected, objEndRow);
						}
						mf_scrollIntoView(objEndRow);
					}
					else
					{
						objEndRow = mf_getNextRow(m_objRowLastSelected, DOWN)
						if(objEndRow)
						{
							m_objRowRange.endRow = objEndRow;
							m_objRowRange.update()
							m_objRowLastSelected = objEndRow;
							mf_scrollIntoView(objEndRow);
						}
						
					}
				
				}

			break;
			case 37: //left
			case 38: //up
				if(!event.shiftKey)
				{
					objRow = m_objRowLastSelected;
					m_objRowRange = null;

					var objNextRow = mf_getNextRow(objRow,  UP)

					if (objNextRow != false)
					{
						mf_unselectAll();
						mf_selectRecord(objNextRow, true);
						mf_scrollIntoView(objNextRow);
						m_objRowLastSelected = objNextRow;
					}
				}
				else
				{
					objRow = m_objRowLastSelected;
					if (m_objRowRange == null)
					{
						var objAnchor = m_objRowLastSelected
						objAnchor.id = "rowSelectedException";
						mf_unselectAll();
						objAnchor.id = "selected"
						objEndRow = mf_getNextRow(m_objRowLastSelected, UP)
						if(objEndRow)
						{
							m_objRowRange = new RowRange(m_objRowLastSelected, objEndRow);
						}

					}
					else
					{
						objEndRow = mf_getNextRow(m_objRowLastSelected, UP)
						if(objEndRow)
						{
							m_objRowRange.endRow = objEndRow;
							m_objRowRange.update(objEndRow);
							m_objRowLastSelected = objEndRow;
						}
					}

				}

				event.returnValue=false;
			break;
			case 13: //enter
				//Open all items
				var objAnchors = this.all("selected");

				if (typeof(objAnchors) == "object" && objAnchors != null )
				{
					var objRow;
					if (objAnchors.length != null)
					{
						var i = 0;
						for(i=0; i < objAnchors.length; i++)
						{
							objRow = objAnchors(i)
							mf_openMessage(objRow._href, objRow.contentClass,    "open")
							mf_unboldRow(objRow)
						}
					}
					else
					{
						objRow = objAnchors
						mf_openMessage(objRow._href, objRow.contentClass,    "open");
						mf_unboldRow(objRow)
					}
				}

			break;
			case 46://delete
				f_deleteSelectedItems();
			break;
		}
		
	} //End Try block
	catch(e)
	{
		
	}

}


function event_ondblclick()
{

	var objRow = event.returnValue;
	if(objRow != null)
	{
		mf_openMessage(objRow._href, objRow.contentClass,    "open");
		mf_unboldRow(objRow);
	}
	event.cancelBubble = true;
	event.returnValue = false;


}

function event_onmouseup()
{

	var xSum=0;
	var tempEl=0;
	var objCol;
	var fCtrlKey = event.ctrlKey;
	var objRow = event.returnValue
	if(objRow != null)
	{       
//		event.cancelBubble = true;
		
		if (objRow.id == "tdColumn")
		{   
			if (objRow.prop == "http://schemas.microsoft.com/mapi/subject")
			{
				mf_changeSortOrder(objRow,  fCtrlKey)

			}
			else if(objRow.sortable == 1)
			{
				mf_changeSortOrder(objRow,  fCtrlKey)
			}
		}
		else if(objRow.id == "selected")
		{
			if (event_onmouseup.bToggleSelection == true)
			{
					if (event.ctrlKey == true)
					{
							mf_unselectRecord(objRow);
							event_onmouseup.bToggleSelection =  false;
					}
			}
			else if (event_onmouseup.bSelectRow)
			{
				m_objRowRange = null;
				mf_unselectAll();
				mf_selectRecord(objRow, true);
				event_onmouseup.bSelectRow = false;
			}
		}
	}       
}
//Function properties
event_onmouseup.bSelectRow = false;
event_onmouseup.bToggleSelection = false;

function event_onmousedown()
{
	
	event_onmouseup.bToggleSelection =  false;
	event_onmouseup.bSelectRow = false;

	var sc = false;
	if (window.event.srcElement.id  == "grpHdrActivator")
	{
	   expandGroup(window.event.srcElement.parentElement);
	}
	else
	{

		var objContentRow = event.returnValue
		

		if (objContentRow != null)
		{

			if(event.ctrlKey == true)
			{

				m_objRowRange = null;
				var fFire = false;
				if (m_objRowLastSelected == null)
				{
					fFire = true

				}
				else
				{
					m_objRowLastSelected = null;

				}
												
				if (objContentRow.id == "selected")
				{
					event_onmouseup.bToggleSelection =  true;
				}
				else
				{

					event_onmouseup.bToggleSelection =  false;

					sc = mf_selectRecord(objContentRow, fFire);
					if (sc)
					{
						m_objLastRowSelected = objContentRow;
					}
				}
			}
			else if(event.shiftKey)
			{
				 if (m_objRowRange == null)
				 {
					if (m_objRowLastSelected != null)
					{
						mf_unselectAll();
						m_objRowRange = new RowRange(m_objRowLastSelected, objContentRow)
					}
					else
					{
						m_objRowRange = new RowRange(objContentRow, objContentRow)
					}
				 }
				 else
				 {
					m_objRowRange.endRow = objContentRow;
					m_objRowRange.update()
					m_objRowLastSelected = objContentRow;
				}

			}
			else
			{
				if (objContentRow.id == "selected")
				{
					event_onmouseup.bSelectRow = true;
				}
				else
				{
				   m_objRowRange = null;
				   mf_unselectAll();
				   sc =  mf_selectRecord(objContentRow, true);
				}
			}
		}
	}

}



function event_ondragstart()
{


	var tempElement = window.event.srcElement;
	var tempElementParent;
	var szSRCURL="";
	var URLSplit = null;
	var folderPath = null;
	var folderType = null;
	var folderName = null;
	var dropType = null;
	var dataString = "";
	var i=0;

	dataString = f_getSelectedCollection();

	if(dataString != "")
	{
		window.event.dataTransfer.effectAllowed = "all";
		window.event.dataTransfer.setData("Text", dataString);
	}
}

function event_ongetxmlcomplete()
{
	if (m_objMSHTTP_Request != null && m_objMSHTTP_Request.readyState == 4)
	{
		m_objXML =  m_objMSHTTP_Request.responseXML;
		
		var sz= m_objMSHTTP_Request.getResponseHeader("content-range");
		var iStatus = m_objMSHTTP_Request.status
		m_objMSHTTP_Request = null

		if (mf_checkStatus(iStatus))
		{
			if (sz != null && sz!= "")
			{
				mf_updatePageInfo(sz);
			}

			try
			{
				m_gCallBack(iStatus);

			}
			catch(e)
			{
				m_gCallBack = null;
			}
		}
		else
		{
			mf_renderErrorMessage(L_errCriticalError_ErrorMessage)
		}
	}
}

function createSelectSQL(objColProps, iChildNumber)
{
	var szSQL = "";
	var PropNum = 1;
	if (iChildNumber != null)
	{
		PropNum = iChildNumber;
	}

	for (i= 0; i < objColProps.length; i++)
	{
		//Should coerce to string
		szSQL += ' "' + objColProps.item(i).text + '" as prop' + PropNum + ",";
		PropNum++;
	}

	return(szSQL);

}


function createOrderBySQL(objOrderByNodes)
{
	var szSQLFragment = "";
	if (objOrderByNodes != null)
	{
		var szProp = "";
		if (objOrderByNodes.length != 0)
		{
			for (i=0; i < objOrderByNodes.length; i++)
			{
				szProp = objOrderByNodes.item(i).selectSingleNode("prop").text;
				if (m_rgszPropertySynonyms[szProp] != null)
				{
				   szSQLFragment += '"' + m_rgszPropertySynonyms[szProp] + '" ';
				}
				else
				{
					szSQLFragment += '"' +  szProp + '" ';
				}
				 szSQLFragment += objOrderByNodes.item(i).selectSingleNode("sort").text + ',';
			}
			szSQLFragment = szSQLFragment.substring(0,szSQLFragment.length -1) + ' ';
		}
	}
	return(szSQLFragment);
}



function createViewXML(objViewXML, objTransFormXSL)
{

	try
	{

		var objXML = new ActiveXObject("Microsoft.xmldom")
		objViewXML.transformNodeToObject(objTransFormXSL.documentElement, objXML)

	}
	catch (e)
	{
		alert(e.description);
		return(false);
	}
	return(objXML);

}

//---------------- End


function event_ondeleterequest()
{
	if(m_objMSHTTP_Request != null && m_objMSHTTP_Request.readyState == 4)
	{
		var szStatus = m_objMSHTTP_Request.status;
		var szStatusText = m_objMSHTTP_Request.statusText;
		var responseXML = m_objMSHTTP_Request.responseXML;
		
		m_objMSHTTP_Request = null

		switch(szStatus)
		{
			case 200:
			case 201:
			case 204:
			case 207:
				if (szStatus == 207)
				{
					var nodeStatus = responseXML.selectSingleNode("a:multistatus/a:response[a:status $ge$ 'HTTP/1.1 4']");
			
					if (nodeStatus != null) {
						mf_fireOnError(szStatus, szStatusText,  responseXML, event_ondeleterequest.szCommand);
					}
				}
			
				this.refreshPage();
		
				break;
			default:
				mf_fireOnError(szStatus, szStatusText,  responseXML, event_ondeleterequest.szCommand);
		
				this.refreshPage();
		}
	}
}
//Function property
event_ondeleterequest.szCommand;

/*************************END EVENT HANDLER FUNCTIONS********************************/

/*************************BEGIN PUBLIC METHOD FUNCTIONS********************************/
function f_Update()
{
	this.innerHTML = "";
	m_objHTMLTarget = this;
	
	m_objViewXML = createViewXML(m_objViewDescription,m_objTransFormXSL);

	m_objXSLNodes = m_objViewXML.selectNodes("view/group/xsl:template");

	m_icurGrpLevel = 1;
	m_objQueries = new QueryCollection(m_objViewDescription)

	szSearchXML = m_objQueries[0].searchRequest(true);
	m_objRowRange = null;
	m_objRowLastSelected = null;
	m_iCurrentStartRange = 0;
	m_gCallBack = mf_fireOnPageRefresh;
	mf_getXML(  m_szURL, szSearchXML,m_iCurrentStartRange, m_iCurrentRowsNumber-1);
		
	
}


function f_getSelectedCollection()
{
	var szDataString="";
	var szFolderPath;
	var szFolderType;
	var szFolderName;
	var szDropType;
	var URLSplit;
	var tempElementParent;
	var m_bstrXML = '<transferdata xmlns:a="DAV:">' +
						'<item>' +
							'<objectname></objectname>' +
							'<objectid></objectid>' +
							'<content-class></content-class>' +
							'<a:href></a:href>' +
						'</item>' +
					'</transferdata>';

	var objXML = new ActiveXObject("Microsoft.xmldom");
	objXML.loadXML(m_bstrXML);
	var objRootNode = objXML.documentElement;
	var objItemNode = objRootNode.selectSingleNode("item");
	var objAnchors = this.all("selected")
	var szURL = ""
	var objItemCloneNode;
	var node;
	if (objAnchors != null)
	{
		if (objAnchors.length != null)
		{
			for(i=0; i < objAnchors.length; i++)
			{
				tempElementParent = objAnchors(i);
				if(!tempElementParent)
				{
					continue;
				}
				szURL = tempElementParent._href;
				URLSplit        =   szURL.split("/");
				objItemCloneNode = objItemNode.cloneNode(true);
				node = objItemCloneNode.selectSingleNode("objectid");
				node.text = szURL;
				node = objItemCloneNode.selectSingleNode("content-class");
				node.text = tempElementParent.contentClass;
				node = objItemCloneNode.selectSingleNode("a:href");
				node.text = szURL;
				node = objItemCloneNode.selectSingleNode("objectname");
				node.text = URLSplit[URLSplit.length-1];
				objRootNode.appendChild(objItemCloneNode);

			}
		}
		else
		{
				tempElementParent = objAnchors;
				szURL = tempElementParent._href;
				URLSplit        =   szURL.split("/");
				objItemCloneNode = objItemNode.cloneNode(true);
				node = objItemCloneNode.selectSingleNode("objectid");
				node.text = szURL;
				node = objItemCloneNode.selectSingleNode("content-class");
				node.text = tempElementParent.contentClass;
				node = objItemCloneNode.selectSingleNode("a:href");
				node.text = szURL;
				node = objItemCloneNode.selectSingleNode("objectname");
				node.text = URLSplit[URLSplit.length-1];
				objRootNode.appendChild(objItemCloneNode);
		}
		objRootNode.removeChild(objItemNode);
		szDataString = objRootNode.xml;

		return(szDataString);
	}
	else //Bail out if the no rows are selected
	{
		return("")
	}
}

function f_OpenMessage(mode)
{
	if(mode > m_rgszOpenMessageCommands.length-1)
	{
		return(false);
	}
	var retval;
	var objAnchors = this.all("selected")
	var objRow;
	if (objAnchors != null)
	{
		objRow = (objAnchors.length != null)?objAnchors.item(0):objAnchors;

		if (objRow!= false)
		{
			mf_openMessage(objRow._href,objRow.contentClass, m_rgszOpenMessageCommands[mode]);
			mf_unboldRow(objRow)
			retval = true
		}
		else
		{

			retval = false
		}
	}
	else
	{
		retval = false;
	}
	return (retval);
}




function f_nextPage()
{
	var iTempStartRange = m_iCurrentStartRange;
	iTempStartRange  += m_iCurrentRowsNumber;
	if (iTempStartRange < m_imaxRows)
	{
		iEndRange  = iTempStartRange + m_iCurrentRowsNumber;
		m_gCallBack = mf__fireOnPageChange
		m_objHTMLTarget = this;
		m_icurGrpLevel  = 1;
		m_objRowRange = null;
		m_objRowLastSelected = null;
		m_iCurrentStartRange = iTempStartRange;
		mf_getXML(  m_szURL, szSearchXML,m_iCurrentStartRange, iEndRange );
		
	}
}

function f_previousPage()
{
	var iTempStartRange = m_iCurrentStartRange;
	iTempStartRange  = iTempStartRange - m_iCurrentRowsNumber;
	if(iTempStartRange >= 0)
	{
		iEndRange  = iTempStartRange + m_iCurrentRowsNumber;
		m_gCallBack = mf__fireOnPageChange
		m_objHTMLTarget = this;
		m_icurGrpLevel = 1;
		m_objRowRange = null;
		m_objRowLastSelected = null;
		m_iCurrentStartRange = iTempStartRange
		mf_getXML(  m_szURL, szSearchXML, m_iCurrentStartRange, iEndRange );
	
		return(true)
	}
	else
	{
		return(false)
	}
}
function f_gotoPage(varPage)
{
	 var iPage = 1;
	 var iTemp = 0;
	 if (varPage != null )
	 {
		if (typeof(varPage) == "string")
		{
			iPage = parseInt(varPage)
		}
		iTemp = (iPage*m_iCurrentRowsNumber) - m_iCurrentRowsNumber
		if (iTemp < m_imaxRows && iTemp >= 0)
		{
			m_iCurrentStartRange = iTemp;

			iEndRange  = m_iCurrentStartRange + m_iCurrentRowsNumber;

			m_gCallBack = mf__fireOnPageChange
			m_objHTMLTarget = this;
			m_icurGrpLevel = 1;
			m_objRowRange = null;
			m_objRowLastSelected = null;
			mf_getXML( m_szURL,  szSearchXML,m_iCurrentStartRange, iEndRange );
			
		}
	 }

}
function f_deleteSelectedItems()
{
	m_objAnchorsSelected = this.all("selected");
	m_objRowRange = null;
	mf_HTTPCallDelete();
}

function f_refreshPage()
{
	szSearchXML = m_objQueries[0].searchRequest(true);
	m_objHTMLTarget = this;
	m_icurGrpLevel  = 1;
	m_gCallBack = mf_fireOnPageRefresh;
	m_objRowRange = null;
	m_objRowLastSelected = null;
	mf_getXML( m_szURL,  szSearchXML, m_iCurrentStartRange, m_iCurrentStartRange + m_iCurrentRowsNumber -1);
}
/*************************END PUBLIC METHOD FUNCTIONS********************************/
/*************************BEGIN PRIVATE FUNCTIONS********************************/
function mf_scrollIntoView(objRow)
{

	if ((objRow.offsetTop + objRow.offsetHeight - this.scrollTop) > this.clientHeight)
	{
		objRow.scrollIntoView(false);
	}
	else if(objRow.offsetTop < this.scrollTop)
	{
		objRow.scrollIntoView(true);
	}
}

function mf_fireOnSelectItem(objRow)
{
	var objEvent = createEventObject();
	objEvent.contentClass = objRow.contentClass;
	objEvent._href         = objRow._href
	objEvent.row          = objRow;
	_ideventOnSelectItem.fire(objEvent)
}

function mf_getNodeData(objDest,objElement)
{
	m_icurGrpLevel      = parseInt(objElement.groupLevel) + 1;
	if(m_icurGrpLevel > 2)
	{
		var objParentGroup = objElement.parentGroup
		if (objParentGroup == null)
		{
			//Todo: Need better way of discovering parent group
			objParentGroup = objElement.parentElement.parentElement.parentElement.parentElement.parentGroup
			objElement.parentGroup = objParentGroup;
		}
		//get previous group criteria
		var objQueryObject   = m_objQueries[m_icurGrpLevel -1]
		var objTemp = objElement;
		objQueryObject.restriction = "";
		var icount = 0;
		while (objTemp != null)
		{
			if(icount > 0)
			{
				objQueryObject.restriction += ' AND '
			}

			objQueryObject.restriction += mf_formatRestriction(objTemp.propValue, objTemp.dataType, objTemp.propName)
			objTemp = objTemp.parentGroup
			icount ++;
		}
		objDest.parentGroup = objElement;
	}
	else
	{
		var objQueryObject   = m_objQueries[m_icurGrpLevel - 1]

		var objTemp = objElement;
		objQueryObject.restriction = "";
		//Todo:Need to add casting code here for the data type
		//Currently the view descriptor does not have the data type attribute on the prop node

		objQueryObject.restriction += mf_formatRestriction(objTemp.propValue, objTemp.dataType, objTemp.propName)
		objElement.parentGroup = null;
		objDest.parentGroup = objElement
	}

	szRequestXML = objQueryObject.searchRequest(true);

	m_objHTMLTarget = objDest;
	m_gCallBack = mf_fireOnExpandNode;
	mf_getXML(m_szURL,  szRequestXML);

}

function mf_fireOnExpandNode()
{
	mf_renderHTML();
	var objEvent = createEventObject();
	objEvent.container = m_objHTMLTarget;
	_ideventonExpandGroup.fire(objEvent)
}

function mf_fireOnError(statusCode, statusText, responseXML, szCommand)
{
	var objEvent        =   createEventObject();
	objEvent.status     =   statusCode;
	objEvent.statusText =   statusText;
	objEvent.responseXML = responseXML;
	objEvent.command    =   szCommand;
	__ideventonError.fire(objEvent);
}

function mf_formatRestriction(szPropValue,  szDataType, szPropName)
{
	var szRestriction = "";

	switch(szDataType)
	{

		case "i4":
		case "int":
			szRestriction = '"' + szPropName + '" = ' + szPropValue
			break;
		case "dateTime.tz":
		case "date":
			szRestriction = '"' + szPropName + '" = ' + 'CAST("' + szPropValue + '" AS "dateTime.tz")'
			break;
		case "string":
		default:
			if (szPropValue != null)
			{
			
				var re = /'/g;
				szPropValue = szPropValue.replace(re, "''") //Escape single quotes
				szRestriction = '"' + szPropName + '" = ' + '\'' + szPropValue + '\'';
			}
			else
			{
				szRestriction = '"' + szPropName + '" IS NULL ';
			}
			
			break;
	}
	return(szRestriction)

}

function mf_createSearchRequestXML(szSQL)
{
	var szxml = '<searchrequest xmlns="DAV:" ><sql></sql></searchrequest>';
	var objSearchXML = new ActiveXObject("Microsoft.xmldom");
	objSearchXML.loadXML(szxml);
	var objNode = objSearchXML.selectSingleNode("searchrequest/sql");
	objNode.text = szSQL;
	return(objSearchXML.xml);
}

function mf_HTTPCallDelete()
{
	var szBatchString="";
	var szOpenURL = m_szURL;
	var szCommand = "";
	var szXMLBatchString = "";
	var rgTempSZ = null;
	var szDestURL = "";
	var isCollection = false;
	var szSampleURL = "";
	
	if(m_iStoreType == 0)
	{
		var szDeletedItemsURL = "";
		if (m_rgSpecialFolderURL["deleteditems"] != null)
		{
			
			
			
			szDeletedItemsURL = m_rgSpecialFolderURL["deleteditems"]
			
		}
		else 
		{
			//Call the server to get it with this function as the callback
			m_gCallBack = mf_HTTPCallDelete; 
			mf_getSpecialFolders(m_szURL)
			return(false)
		}
	}

	if(!m_objMSHTTP_Request)
	{
		m_objMSHTTP_Request = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (m_objAnchorsSelected != null )
	{
	
		if( m_szTarget && m_szTarget.length )
		{
			event_doLinkAction(null);
		}

		if (m_objAnchorsSelected.length != null)
		{
			isCollection = true;
			szSampleURL = m_objAnchorsSelected(0)._href
		}
		else
		{
			isCollection = false;
			szSampleURL  = m_objAnchorsSelected._href
		}

		if (m_iStoreType == 0)
		{
			if(szSampleURL.toUpperCase().indexOf(szDeletedItemsURL.toUpperCase()) == -1 )  
			{
				szCommand = "BMOVE";
				szXMLCommand = "move"
			}
			else
			{
				szCommand = "BDELETE";
				szXMLCommand = "delete";
				var oEvent = createEventObject();
				_ideventonBeforeDelete.fire(oEvent);
				if(false == oEvent.returnValue)
				{
					return(false)
				}
			}
		}
		else
		{
				szCommand = "BDELETE";
				szXMLCommand = "delete";
				var oEvent = createEventObject();
				_ideventonBeforeDelete.fire(oEvent);
				if(false == oEvent.returnValue)
				{
					return(false)
				}
		}

		szXMLBatchString = "<?xml version='1.0'?><D:" + szXMLCommand + " xmlns:D='DAV:'><D:target>";
		if(isCollection == true)
		{
			for(i=0; i < m_objAnchorsSelected.length; i++)
			{
				rgTempSZ = m_objAnchorsSelected(i)._href.split("/");
				szXMLBatchString += "<D:href>" +rgTempSZ[rgTempSZ.length-1] + "</D:href>";
			}
		}
		else
		{
			 rgTempSZ = m_objAnchorsSelected._href.split("/");
			 szXMLBatchString += "<D:href>" +rgTempSZ[rgTempSZ.length-1] + "</D:href>";
		}
		szXMLBatchString += "</D:target></D:" + szXMLCommand + ">";
		m_szLastVerb = szCommand;

		szOpenURL = mf_addEndWhack(szOpenURL);

		m_objMSHTTP_Request.open(m_szLastVerb, szOpenURL, true);
		m_objMSHTTP_Request.setRequestHeader( "Content-type:", "text/xml");
		m_objMSHTTP_Request.setRequestHeader( "Translate:", "f");
		if (szCommand != "BDELETE")
		{
			m_objMSHTTP_Request.setRequestHeader( "Allow-rename:", "t");
			m_objMSHTTP_Request.setRequestHeader( "Overwrite:", "f");
			m_objMSHTTP_Request.setRequestHeader( "Destination:", szDeletedItemsURL);
		}
		m_objMSHTTP_Request.onreadystatechange = event_ondeleterequest;
		event_ondeleterequest.szCommand = szCommand;
		m_objMSHTTP_Request.send(szXMLBatchString);
		return(true);
	}
	else
	{
		return(false)
	}
}

function mf_addEndWhack(szURL)
{
	if(szURL.charAt(szURL.length - 1) != "/")
	{
		return(szURL + "/");
	}
	else
	{
		return(szURL);
	}
}

function mf_getSpecialFolders(szSearchURL)
{
	var retval = false;
	if (szSearchURL != null)
	{
		m_gobjHTTPSpecialFolders = new ActiveXObject("Microsoft.XMLHTTP");
		var szPropfind = '<?xml version="1.0"?>' +
							'<a:propfind xmlns:a="DAV:" xmlns:b="urn:schemas:httpmail:">' +
							'<a:prop><b:inbox/><b:calendar/><b:sentitems/><b:deleteditems/><b:contacts/><b:drafts/><b:outbox/><b:sendmsg/><b:msgfolderroot/>' +
						  '</></>';
		m_gobjHTTPSpecialFolders.open( "PROPFIND", szSearchURL,true);
		m_gobjHTTPSpecialFolders.setRequestHeader( "Depth:", "0");
		m_gobjHTTPSpecialFolders.setRequestHeader( "Content-type:", "text/xml");
		m_gobjHTTPSpecialFolders.onreadystatechange = event_getspecialfolderscompleted;
		m_gobjHTTPSpecialFolders.send(szPropfind);
		retval = true;
	}
	return(retval);
}

function mf_selectAllRows()
{
	var objTempRow;
	var objSelectors = this.all("unSelected")
	
	if (objSelectors != null)
	{
		if (objSelectors.length != null)
		{
			do
			{
				objRow = objSelectors.item(0);
				mf_selectRecord(objRow, i==0?true:false);
			} while (objRow != null)
		}
	}
}

function mf_unselectAll()
{
	var i = 0;
	var objTemp
	var objRow;
	
	m_objAnchorsSelected = this.all("selected");

	if (m_objAnchorsSelected != null )
	{
	   if (m_objAnchorsSelected.length != null)
	   {
		  objTemp = m_objAnchorsSelected.item(0)
		  while (objTemp != null)
		  {
			   mf_unselectRecord(objTemp)
			   objTemp = m_objAnchorsSelected.item(0)
		  }
	   }
	   else
	   {
		   mf_unselectRecord(m_objAnchorsSelected);
	   }

	}
}

function mf_changeSortOrder(objCol, fAppend)
{
		var szsortDir = ""
		var i, szProp;
		var objOrderByNode = null;
		if(objCol.dataType != "date")
		{
			
			//If the data type is date then Default is DESC
			szsortDir = (objCol.sortdir == "ASC")?"DESC":"ASC";
		}
		else
		{
			szsortDir = (objCol.sortdir == "DESC")?"ASC":"DESC";
		}   

		var objOrderNodes = m_objViewDescription.selectNodes("view/orderby/order");
		objOrderByNode = m_objViewDescription.selectSingleNode("view/orderby");
		
		//If no order nodes exist then we'll have to create it from scratch
		if (objOrderByNode == null)
		{
			objOrderByNode = m_objViewDescription.createElement("orderby")
			objOrderByNode = m_objViewDescription.documentElement.appendChild(objOrderByNode)
		}
							
		szProp = objCol.prop;
		
		var objNode
		var objPropNode
		var objSortNOde;
		var fFound = false
				
		//XQL query would be better here
		for (i=0;i < objOrderNodes.length ; i++ )
		{
			objNOde = objOrderNodes.item(i) 
			objPropNode = objNOde.selectSingleNode("prop")
			if (objPropNode.text == szProp)
			{
				objSortNode = objNOde.selectSingleNode("sort");
				objSortNode.text = szsortDir;
				fFound = true;
			}
			else if(fAppend == false)
			{
				objOrderByNode.removeChild(objNOde)
			}

		}
		
		if (fFound == false)
		{
			//Create node and append
			var objNewOrderNode = m_objViewDescription.createElement("order")
			var objNewPropNode  = m_objViewDescription.createElement("prop")
			var objNewSortNode  = m_objViewDescription.createElement("sort")
			objNewOrderNode = objOrderByNode.appendChild(objNewOrderNode)
			objNewPropNode = objNewOrderNode.appendChild(objNewPropNode);
			objNewSortNode = objNewOrderNode.appendChild(objNewSortNode);
			objNewPropNode.text = szProp;
			objNewSortNode.text = szsortDir;
			
		}

		this.update()
		
		//Fire onChangeSort to notify external scripts
		var objEvent = createEventObject();
		objEvent.col = objCol;
		objEvent.sortDir = szsortDir;
		_ideventonChangeSort.fire(objEvent)
					
		return(true);
}

function mf_unselectRecord(objRecord)
{
		
		var retval = false;
		if(objRecord != null)
		{
			objRecord.id =  "unSelected"
			var obj;
			if (m_szViewType == "card")
			{
				obj = objRecord.all("crdHeader")
			}
			else
			{
				obj = objRecord;
			}
			obj.runtimeStyle.backgroundColor=m_rowBackGroundColor;
			obj.runtimeStyle.color=m_rowColor;
			retval = true
		}

		return(retval);
}


function mf_selectRecord(objRecord, fFireEvent)
{

	var retval = true;
	if (objRecord != null && objRecord !=   false)
	{
		
		if (objRecord.id  != "selected")
		{
			m_objRowLastSelected = objRecord;
			objRecord.id =  "selected"
			
			if (m_szViewType == "card")
			{
				obj = objRecord.all("crdHeader") 
			}
			else
			{
				obj = objRecord
			}
		
			m_rowBackGroundColor = obj.style.backgroundColor
			m_rowColor = obj.runtimeStyle.color;
			obj.runtimeStyle.backgroundColor= "HIGHLIGHT";
			obj.runtimeStyle.color="HIGHLIGHTTEXT";
		
			
			if(fFireEvent)
			{
				mf_fireOnSelectItem(objRecord);
			}
		}
	}
	else
	{
		retval = false
	}

	return(retval);
}

function mf_getViewDescriptor(szXMLPath)
{

   var fisObject = false;
	//check to see if the string is an id to am xml data island
   var objXML = window.document.all(szXMLPath)
   try
   {
		if(objXML.tagName == "XML")
		{
			fisObject = true;
			if(objXML.documentElement != null)
			{
				
				m_objViewDescription = objXML;
				
			}
			else
			{
				
				//Workaround for IE5.01 issue with xml data islands on slow links
				objXML.loadXML(objXML.innerHTML)
				m_objViewDescription = objXML;
				
			}   
		}

   }
   catch(e)
   {
		fisObject = false;
   }
   if (fisObject == false)
   {
		var objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP"); 
		objXMLHTTP.open("GET", szXMLPath, false )
		if(m_szAcceptLang != "" )
		{
			objXMLHTTP.setRequestHeader("Accept-Language:",m_szAcceptLang);
		}
		objXMLHTTP.send();
		var iStatus = objXMLHTTP.status;
		if(200 == iStatus )
		{
			m_objViewDescription = objXMLHTTP.responseXML;
		}
		else
		{
			return;
		}	
		
		
	}
	if(this.viewClass == "auto")
	{
		//Determine which xsl file to load
		var objNode = m_objViewDescription.selectSingleNode("view/card")
		var szViewClassURL = "";
		if(objNode != null)
		{
			//Load cardview.xsl
			szViewClassURL = "/exchweb/views/cardview.xsl"
			m_szViewType   = "card"
		}
		else
		{
			//Load standardview.xsl
			szViewClassURL = "/exchweb/views/standardview.xsl"
			m_szViewType   = "table"
		}
		m_objTransFormXSL = new ActiveXObject("Microsoft.xmldom")
		m_objTransFormXSL.async = false;
		m_objTransFormXSL.load(szViewClassURL)
		m_objViewXML    = createViewXML(m_objViewDescription,m_objTransFormXSL);
	}   

}

function mf_openMessage(szHref,szContentClass,  szCommand)
{
	var szDefaultCommand = "open";
	var windowName = new String(Math.round(Math.random() * 100000));
	var fFreeDoc = (0 == szContentClass.search(/ipm.document/i));
	if( false == fFreeDoc )
	{

		if (szCommand != null)
		{
			szDefaultCommand = szCommand;
		}
		var oDate = new Date();
		szDefaultCommand += "&tzoffset=" + oDate.getTimezoneOffset();

		var szFeatures = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=480"

		var objNewMsgWindow = window.open(szHref + "?Cmd=" + szDefaultCommand,windowName,szFeatures);
	}
	else
	{
		var szFeatures = "toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1"
		var objNewMsgWindow = window.open(szHref,windowName,szFeatures);
	}
}

function mf_unboldRow(objRow)
{
	var retval =false;
	if (objRow != null)
	{
		objRow.style.fontWeight = "normal"
		retval = true
	}
	return(retval)

}


function mf_fireOnPageRefresh(iStatus)
{
	if(iStatus == 416)
	{
		if(this.currentPage > 1)
		{
			this.previousPage();
		}
		else
		{

			mf_renderHTML();
			mf_renderErrorMessage(L_errNoItemsInView_ErrorMessage)
			_ideventonRefreshPage.fire();
		}
	}
	else
	{
		mf_renderHTML();
		_ideventonRefreshPage.fire();
	}
	//Todo: Need to select next item in view
}

function mf__fireOnPageChange(iStatus)
{
	mf_renderHTML();
	_ideventonPageChange.fire();
	//Todo:Need to select next item in view here
}

function mf_renderErrorMessage(szErrorMessage)
{
	m_objHTMLTarget.insertAdjacentHTML("beforeEnd","<DIV style='width:100%;text-align:center;'>" + szErrorMessage + "</DIV>")
}

function mf_updatePageInfo(szRangeHeader)
{

	var i = szRangeHeader.indexOf("=");
	var j = szRangeHeader.indexOf("-");
	m_iStartRange = new Number(szRangeHeader.substring(4, j));
	m_imaxRows = new Number(szRangeHeader.substr(i+1, szRangeHeader.length-i));
	this.itemCount = m_imaxRows;
	m_iMaxPageNumber = new Number(m_imaxRows/m_iCurrentRowsNumber);
	this.pageCount = Math.ceil(m_iMaxPageNumber);
	var num  = Math.ceil((m_iStartRange + m_iCurrentRowsNumber)/m_iCurrentRowsNumber);
	this.currentPage = num;

}

function mf_checkStatus(iStatus)
{
	var retval = false;
	switch(iStatus)
	{

		case 500:
		case 501:
		case 502:
		case 503:

		break;

		default:
			retval = true;
		break;

	}
	return(retval)
}

function mf_getXML(szURL, szXMLSearch,  iStartRange, iEndRange)
{
	var szRowRange = "";
	if(!m_objMSHTTP_Request)
	{
		m_objMSHTTP_Request = new ActiveXObject("Microsoft.XMLhttp");
	}
	if (iStartRange != null && iEndRange != null)
	{
		szRowRange = "rows=" + iStartRange.toString() + "-" +  iEndRange.toString()
	}
	try
	{
		m_objMSHTTP_Request.open("SEARCH", szURL, true);
		m_objMSHTTP_Request.setRequestHeader("content-type", "text/xml");
		if(m_szAcceptLang == "" )
		{
			m_objMSHTTP_Request.setRequestHeader("Accept-Language:",window.clientInformation.userLanguage);			
		}
		else
		{
			m_objMSHTTP_Request.setRequestHeader("Accept-Language:",m_szAcceptLang);
		}	
		m_objMSHTTP_Request.setRequestHeader("Brief", "t")

		if (szRowRange != "")
		{
			m_objMSHTTP_Request.setRequestHeader("range", szRowRange);
		}
		m_objMSHTTP_Request.onreadystatechange = event_ongetxmlcomplete;
		m_objMSHTTP_Request.send(szXMLSearch);
	}
	catch(e)
	{
		alert(e.description);
		return(false);
	}
}

function mf_renderHTML()
{
		var szHTML = "";
		var i = 0;
		var j = 0;
		var objItem;
		var inumItems = 0;
		var k=0;
		var szCellHTML = "";
		if(null != m_objXML)
		{
			//XML will strip leading and trailing whitepace if this property is not set to true
			m_objXML.preserveWhiteSpace = true;
		
			szHTML = m_objXML.transformNode(m_objXSLNodes.item(m_icurGrpLevel - 1));
			if(m_szViewType == "card")
			{
				var iRecsPerCol = Math.round(m_iCurrentRowsNumber/m_iMaxCols)
				for(y=0; y < m_iMaxCols; y++)
				{
					szCellHTML += '<td id="col'+ y + '" style="vertical-align:top;width:33%">';
						
				} 
					
				m_objHTMLTarget.innerHTML = '<table cols=' + m_iMaxCols +' border="1" style="border-collapse:collapse;table-layout:fixed;display:none;" width="100%"><tr>' + szCellHTML + '</tr></table>';
				var objTable = this.children(0);
				objCol = objTable.rows(0).cells(0)
				objCol.innerHTML = szHTML;

				objItem = 1;
				var objAllItems = objCol.children;          
				for(i=1;  i <= m_iMaxCols && objItem != null; i++)
				{
					objNewCol = objTable.rows(0).cells(i)
					for(k=0; k <= iRecsPerCol ; k++)
					{
						objItem = objAllItems(iRecsPerCol);
						if(objItem == null)
						{
							break;
						}
						objNewCol.insertAdjacentElement("beforeEnd", objItem)
					}
				}
									
				objTable.style.display = "";
					
					
			}
			else
			{
				m_objHTMLTarget.innerHTML = szHTML;
			}   
		}
		
}
//***********   Private Row Range Method function  ********
//  Note:These function can only be use through the row range object

function mf_updateRowRange()
{
		var objNextRow;
		var iTempDir = 0;
		var iDelta = this.startRow.sourceIndex - this.endRow.sourceIndex

		if(iDelta < 0)
		{
			iTempDir = DOWN;
		}
		else if(iDelta > 0)
		{
			iTempDir = UP;
		}
		else if(iDelta == 0)
		{
			mf_unselectRecord(this.tempEndRow)
			this.tempEndRow = this.endRow
			this.rangeDirection = null;
			return(true)
		}
		if (this.rangeDirection == null)
		{
			this.rangeDirection = iTempDir
		}
		if(iTempDir == this.rangeDirection)
		{
			 //Either add or remove rows based on the endRow
			var iEndDelta = this.tempEndRow.sourceIndex - this.endRow.sourceIndex;
			if(iEndDelta > 0 )
			{
				if(this.rangeDirection == DOWN)
				 {
					//remove rows
					this.trimRange(UP)
				 }
				else
				{
					//add rows
					this.expandRange(this.tempEndRow);
				}
			}
			if(iEndDelta < 0)
			{
				 if(this.rangeDirection == UP)
				 {
					//remove rows
					this.trimRange(DOWN)
				 }
				 else
				 {
					//add rows
					this.expandRange(this.tempEndRow);

				 }
			}
		}
		else
		{
			//Unselect all rows except the start row
			this.rangeDirection = iTempDir
			var objSelector = this.startRow
			objSelector.id = "rowSelectedException"
			mf_unselectAll()
			objSelector.id = "selected"
			//add rows in range
			this.expandRange(this.startRow);
		}
}
function mf_expandRange(objStartRow)
{
	var objTempRow;
	objTempRow = mf_getNextRow(objStartRow, this.rangeDirection)
	mf_selectRecord(this.endRow, false)
	if (mf_selectRecord(objTempRow))
	{
		for(;objTempRow.uniqueID != this.endRow.uniqueID &&
			mf_selectRecord(objTempRow, false) ;)
		{
			objTempRow = mf_getNextRow(objTempRow,  this.rangeDirection)

		}
		this.tempEndRow = this.endRow;
	}
}

function mf_trimRowRange(iDirection)
{
	//remove rows
	mf_unselectRecord(this.tempEndRow)
	var objTempRow;
	objTempRow = mf_getNextRow(this.tempEndRow, iDirection)
	if(objTempRow)
	{
		for(;objTempRow.uniqueID != this.endRow.uniqueID &&
			mf_unselectRecord(objTempRow);)
		{

			objTempRow = mf_getNextRow(objTempRow,  iDirection)

		}
		this.tempEndRow = this.endRow;
	}
}

function mf_getNextRow(objRow,  iDirection)
{
	var objNextRow = null;
	var retval = false;
	if (objRow != null)
	{
		if(iDirection == UP)
		{
			objNextRow = objRow.previousSibling;
		}
		else
		{
			objNextRow = objRow.nextSibling;
		}
		if(objNextRow != null && objNextRow.id != "tblHeader")
		{
			retval = objNextRow;
		}
		else if(objNextRow == null && m_szViewType == "card")
		{
			var objCol = null;
			if(iDirection == UP)
			{
				objCol = objRow.parentElement.previousSibling
				objNextRow = objCol.children[objCol.children.length -1]
			}               
			else
			{
				objCol = objRow.parentElement.nextSibling
				objNextRow = objCol.children[0]
			}
			if(objNextRow != null)
			{
				retval = objNextRow;
			}   
		}
	}
	return(retval);
}
/***************   End Private Row Range Function ****************************/
/*************************END PRIVATE FUNCTIONS********************************/