function MqControlsAction(lngLoadAnyIssue, objSL)
{
	var intCurrentPage=0;
	var intCurrentId=0;
	var intTotalRecord=0;
	var arrRecord=new Array(0);
	var m_lngWorkingId=NO_CURRENT_RECORD;
	var m_lngLoadAnyIssue=lngLoadAnyIssue;
	var m_objSL=objSL;
	
	function initialize(lngCurrentPage,lngPageCount,lngTotalRecord){
		
		if (SummaryList.arrRecord){ 
			arrRecord=SummaryList.arrRecord;
		}else {
			return false;
		}
		
		if (!arrRecord.length){
			arrRecord=new Array(0);
			arrRecord[0]=new Array(1);
		}
		
		if (!Number(lngCurrentPage)){
			lngCurrentPage=0;
		}
		if (!Number(lngPageCount)) {
			lngPageCount=0;
		}
		
		intCurrentPage=lngCurrentPage;
		m_objSL.SetPageCount(lngPageCount);
		intTotalRecord=lngTotalRecord;
		
		intCurrentId=objRecord.GetRecordId();
	}
		
	this.initialize=initialize;
	
	function getPosition(){
		var intPosition;
		
		intPosition=0;
		// POSITION_FIRSTPAGE
		if (intCurrentPage==1 || intCurrentPage==0){ 
			intPosition+=POSITION_FIRSTPAGE;
		}
		
		// POSITION_LASTPAGE
		if (intCurrentPage==m_objSL.PageCount()) {
			intPosition+=POSITION_LASTPAGE;
		}
		
		// POSITION_ONEPAGE
		if ((intPosition&POSITION_FIRSTPAGE) && (intPosition&POSITION_LASTPAGE)){
			intPosition+=POSITION_ONEPAGE;
		}
		
		// POSITION_FIRSTONPAGE
		if (arrRecord.length>0){
			if (intCurrentId==arrRecord[0][ARR_RECORD_NUMBER]){
				intPosition+=POSITION_FIRSTONPAGE;
			}
		}

		// POSITION_LASTONPAGE
		if (arrRecord.length>0){
			if (intCurrentId==arrRecord[arrRecord.length-1][ARR_RECORD_NUMBER]){
				intPosition+=POSITION_LASTONPAGE;
			}
		}
		
		// POSITION_FIRSTONRS
		if ((intPosition&POSITION_FIRSTONPAGE) && (intPosition&POSITION_FIRSTPAGE)){
			intPosition+=POSITION_FIRSTONRS;
		}

		// POSITION_LASTONRS
		if ((intPosition&POSITION_LASTONPAGE) && (intPosition&POSITION_LASTPAGE)){
			intPosition+=POSITION_LASTONRS;
		}

		if (!intCurrentId){
			intPosition =POSITION_FIRSTONPAGE;
			intPosition+=POSITION_LASTONPAGE;
			intPosition+=POSITION_FIRSTONRS;
			intPosition+=POSITION_LASTONRS;
			intPosition+=POSITION_FIRSTPAGE;
			intPosition+=POSITION_LASTPAGE;
			intPosition+=POSITION_ONEPAGE;
		}
		
		return intPosition;
	}
	

 
	function getPositionAbs(){
		var intPosition;
		intPosition=intCurrentId;
		return intPosition;
	}	

	


	
	function PageUp(){
		if (OnBeforeAction(SUMMARY_LIST_FRAME_ID)){
			objStatus.cacheStatus();
			if (!(getPosition()&POSITION_LASTPAGE)){
				objStatus.setStatus(STATUS_CHANGEPAGE);
				setPosition(POSITION_PAGEUP);
			}
		}
	}

	function PageDown(){
		if (OnBeforeAction(SUMMARY_LIST_FRAME_ID)){
			objStatus.cacheStatus();
			if (!(getPosition()&POSITION_FIRSTPAGE)){
				objStatus.setStatus(STATUS_CHANGEPAGE);
				setPosition(POSITION_PAGEDOWN);
			}
		}
	}

	function MoveNext(){
		if (OnBeforeAction(SUMMARY_LIST_FRAME_ID)){	
			objStatus.cacheStatus();
			if (!(getPosition()&POSITION_LASTONPAGE)){
				setPositionAbs(getIdForArrayPosition(Number(getArrayPositionForId(getPositionAbs()))+1));
			}
			else{
				if (!(getPosition()&POSITION_LASTONRS)){
					PageUp();
				}
			}
		}
	}

	function MovePrevious(){
		if (OnBeforeAction(SUMMARY_LIST_FRAME_ID)){
			objStatus.cacheStatus();
			if (!(getPosition()&POSITION_FIRSTONPAGE)){
				setPositionAbs(getIdForArrayPosition(Number(getArrayPositionForId(getPositionAbs()))-1));
			}else{
				if (!(getPosition()&POSITION_FIRSTONRS)){
					PageDown();
				}
			}
		}
	}

	function MoveFirst(){
		if (OnBeforeAction(SUMMARY_LIST_FRAME_ID)){
			objStatus.cacheStatus();
			if (!(getPosition()&POSITION_FIRSTPAGE)){
				objStatus.setStatus(STATUS_CHANGEPAGE);
				setPosition(POSITION_FIRSTPAGE);
			}
		}
	}

	function MoveLast(){
		if (OnBeforeAction(SUMMARY_LIST_FRAME_ID)){
			objStatus.cacheStatus();
			if (!(getPosition()&POSITION_LASTPAGE)){
				objStatus.setStatus(STATUS_CHANGEPAGE);
				setPosition(POSITION_LASTPAGE);
			}
		}
	}
	
	function View(strAddQS, lngTabToShowID, bHidden){
		var intTempId;
		var imgtochange;		
		objControlsUi.disableControl(CONTROL_ADDNEW);
		objControlsUi.disableControl(CONTROL_SAVE);
		objControlsUi.disableControl(CONTROL_CANCEL);
		objControlsUi.disableControl(CONTROL_PRINT);

		if (!bHidden)
		{
			objRecord.Show();
		}
		
		intTempId=objRecord.GetRecordId();
		setWorkingId(intTempId);
				
		if (LoadData){			
			SetState(LOADDATA_FRAME_ID,BUSY_STATE);
			
			SetLoadingStatus();
			if(!strAddQS){
				strAddQS="";
			}
			if(typeof(lngTabToShowID)=="undefined"){
				lngTabToShowID="";
			}
			LoadData.location.replace("../html/wcCmdBar.asp?WCI=wciLoadData&nId="+intTempId + "&ldany=" + m_lngLoadAnyIssue + "&Tab=" + lngTabToShowID + strAddQS);
		}
		
		objControlsUi.refreshControlsState();
	
		//moveTabFrame(0);
		if (isRecordInLocalArray(intTempId)){
			intCurrentId=intTempId;
			if (SCROLL_TOP_CURR_REC){			
				ScrollToAnchor(intCurrentId);
			}
		}

	}
	
	function Print(lngRecID){
		var strReportWCASPPath="../../Reports/WCMqWebReport.ASP";
		
		if (lngRecID > 0){
			
			g_VWS.ReportMgr().Report(CURRENT_REC_RPT).ReportGroup=FEATURE_NORMAL_REPORT_VIEWER;
			g_VWS.ReportMgr().Report(CURRENT_REC_RPT).Params=new Array(lngRecID.toString());
			g_VWS.ReportMgr().Report(CURRENT_REC_RPT).QueryValue="[nID][=]"+lngRecID;
			g_VWS.ReportMgr().OpenReport(CURRENT_REC_RPT, strReportWCASPPath);			
		}
	}
	
	
	function getWorkingId(strCommand){
		var lngWorkingId=NO_CURRENT_RECORD;
		
		if (!isRecordInLocalArray(m_lngWorkingId)){
			if (arrRecord[0]){
				if (arrRecord[0][ARR_RECORD_NUMBER]){
					lngWorkingId=arrRecord[0][ARR_RECORD_NUMBER];
				}
			}
			m_lngWorkingId=lngWorkingId;
		}	
	
		return m_lngWorkingId;
	}
	
	function GetCurrentPage()
	{
		return intCurrentPage;
	}
	
	this.getWorkingId=getWorkingId;
	
	
	this.PageUp=PageUp;
	this.PageDown=PageDown;
	this.MovePrevious=MovePrevious;
	this.MoveNext=MoveNext;
	this.MoveFirst=MoveFirst;
	this.MoveLast=MoveLast;
	this.View=View;
	this.Print=Print;
	this.isRecordInLocalArray=isRecordInLocalArray;
	this.getPosition=getPosition;
	this.getPositionAbs=getPositionAbs;
	this.LoadAfterDelete=LoadAfterDelete;
	this.GetCurrentPage=GetCurrentPage;
	this.OnBeforeAction=OnBeforeAction;

	//private methods
	function setPositionAbs(intPosition)
	{		
		if (Number(intPosition)>0){
			if(isRecordInLocalArray(intPosition)){
				objRecord.SetRecordId(intPosition);
				View();
			}else{
				viewSummaryWithParam("nId="+intPosition);
			}
		}
				
		return intPosition;
	}
	function setPosition(intPosition)
	{	
		var intCount;
		if ((intPosition&POSITION_FIRSTONPAGE)&&(!(getPosition&POSITION_FIRSTONPAGE))){
			objRecord.SetRecordId(arrRecord[0][ARR_RECORD_NUMBER]);
			View();
		}
		if ((intPosition&POSITION_LASTONPAGE)&&(!(getPosition&POSITION_LASTONPAGE))){
			objRecord.SetRecordId(arrRecord[arrRecord.length-1][ARR_RECORD_NUMBER]);
			View();
		}
		
		if ((intPosition&POSITION_FIRSTONRS)&&(!(getPosition&POSITION_FIRSTONRS))){
			viewSummaryWithParam("Position=FirstRecord");
		}
		if ((intPosition&POSITION_LASTONRS)&&(!(getPosition&POSITION_LASTONRS))){
			viewSummaryWithParam("Position=LastRecord");
		}

		if ((intPosition&POSITION_FIRSTPAGE)&&(!(getPosition&POSITION_FIRSTPAGE))){
			viewSummaryWithParam("Position=FirstRecord");
		}
		if ((intPosition&POSITION_LASTPAGE)&&(!(getPosition&POSITION_LASTPAGE))){
			viewSummaryWithParam("Position=LastRecord");
		}

		if ((intPosition&POSITION_PAGEDOWN)&&(!(getPosition&POSITION_FIRSTPAGE))){
			viewSummaryWithParam("PageNumber="+(Number(intCurrentPage)-1));
		}
		if ((intPosition&POSITION_PAGEUP)&&(!(getPosition&POSITION_LASTPAGE))){
			viewSummaryWithParam("PageNumber="+(Number(intCurrentPage)+1));
		}
		
		return intPosition;
	}
	function OnBeforeAction(intFrameID)
	{
		var blnReturn=false;		
		if (GetState()==IDLE_STATE){
			blnReturn=true;
			SetState(intFrameID, BUSY_STATE);			
		}
		return blnReturn;
	}

	function setWorkingId(lngWID){
		m_lngWorkingId=lngWID;
	}
	
	// Called by tabs section
	function getPageCaption(){
		var strReturn;
		var intStartRecord;
		var strPageCtrl="";
		
		if (!intCurrentPage && !intTotalRecord){
			strReturn=MSG_NO_ISSUE_IN_QUERY;
		}else{
			intStartRecord=1+(intMaxRecordPerPage*(intCurrentPage-1));
		
			objString.InitializeString(MSG_NUM_ISSUES_IN_QUERY);
			if(m_objSL){
				strPageCtrl=m_objSL.GetPageControlSrc(intCurrentPage);
			}
			strReturn=objString.FormatStringVar(strPageCtrl+";"+m_objSL.PageCount()+";"+intTotalRecord+";",";"); 
		}
		
		return strReturn;
	}
	
	this.getPageCaption=getPageCaption;
	
	// Called by SummaryListLoad
	function isRecordInLocalArray(intId){
		var intCount;
		var blnFound;
		
		blnFound=false;
	
		if (arrRecord){
			for(intCount=0;intCount<arrRecord.length;intCount++){
				
				if (arrRecord[intCount]){
					if(Number(arrRecord[intCount][ARR_RECORD_NUMBER])==Number(intId)){
						blnFound=true;
						intCount=arrRecord.length;
					}
				}
			}
		}
		
		return blnFound;
	}
	
	function MoveFirstOnPage(){
		intCurrentId=0;
		setPositionAbs(arrRecord[0][ARR_RECORD_NUMBER]);
	}

	function LoadAfterDelete(lngIssueDeleted)
	{
		intCurrentId=0;
		var lngRecToLoad=-1;
		if(arrRecord.length>=1){
			if(arrRecord[0][ARR_RECORD_NUMBER]){
				if(lngIssueDeleted==arrRecord[0][ARR_RECORD_NUMBER]){
					if(arrRecord.length>=2){
						if(arrRecord[1][ARR_RECORD_NUMBER]){
							lngRecToLoad=arrRecord[1][ARR_RECORD_NUMBER];
						}
					}
				}else{
					lngRecToLoad=arrRecord[0][ARR_RECORD_NUMBER];
				}
			}
		}
		objRecord.SetRecordId(lngRecToLoad);
		View();
	}

	//Private functions	
	function ScrollToAnchor(nId){
		
		if (navigator.appName == 'Netscape' ){
			var ctrl_anchor = SummaryList.document.anchors["ID"+nId];

			if (parseInt(navigator.appVersion) >= 5){ //NS6+
				if (typeof(document.body.clientWidth) == 'number'){ //NS7+
					if (ctrl_anchor.offsetParent.offsetLeft){
						SummaryList.window.scroll(ctrl_anchor.offsetParent.offsetLeft,ctrl_anchor.offsetParent.offsetTop);
					}
				}else{
					if (ctrl_anchor.offsetLeft){
						//we need the -20 to keep the record from scrolling up too much in the Summary List
						SummaryList.window.scroll(ctrl_anchor.offsetLeft,ctrl_anchor.offsetTop-20);
					}
				} 
			} else {
				if (parseInt(navigator.appVersion) >= 4){ //NS4
					if (ctrl_anchor.x){
						SummaryList.window.scroll(ctrl_anchor.x,ctrl_anchor.y);
					}
				}
			}
		}else {//IE
			SummaryList.document.location.hash='#ID' + nId;
		}
	}
	
	function viewSummaryWithParam(strParam){		
		if(m_objSL){
			m_objSL.Load(strParam);
		}
	}
	
	function getIdForArrayPosition(intArrPos){
		var intId;
		
		intId=0;
		if (arrRecord){
			intId=arrRecord[intArrPos][ARR_RECORD_NUMBER];
		}

		return intId;

	}
	
	function getArrayPositionForId(intId){
		var intCount;
		var intReturn;
		
		intReturn=0;
		if (arrRecord) {
			for(intCount=0;intCount<arrRecord.length;intCount++) {
				if(arrRecord[intCount][ARR_RECORD_NUMBER]==intId) {
					intReturn=intCount;
				}
			}
		}
		return intReturn;
	}
}