// ********************************************************************
// Copyright (C) 2001 Microsoft Corporation. All rights reserved.
//
//	IMPORTANT.  Please read the legal.txt file, located in the 
//	"<CMS Install Directory>\Server\httpexec\WBC\Internals" 
//	directory, governing the use of this internal file."
// ********************************************************************

// Filter state value
var IDS_CHK_NONE = "0";
var IDS_CHK_RESOURCE = "1";
var IDS_CHK_POSTING = "4";
var IDS_CHK_ALL = "7";
var IDS_INVALID_STATE = "Invalid state of filter";

// define a set of URL for image which is same the one using in ASP file (i.e, ProgrammingConstants.inc )
var IDS_PATH_IMAGES_COMMON = "/NR/System/WBC/Internals/WBCFuncPages/CommonImages/"
var IDS_IMG_BTN_APPLY_GIF = "Buttons/btnApply.gif"
var IDS_IMG_BTN_APPLY_OFF_GIF = "Buttons/btnApplyOff.gif"

// define same constant value in PageRevisionServer.inc
var g_pFormPageRevisionInfo;

// error message for the invalid selection
var IDS_UI_ALERT_LESS_SELECTED_MESSAGE = "Two revisions must be chosen for comparison.\nChoose two revisions by selecting two check\nboxes in the lists.";


// intial the UI for PagRevisionInfo.asp
function WBC_onLoadRevisionInfo( strPageHistoryURL ) {
		
	// get the "WBC_formPageRevisionInfo" form object for Infomation Page (i.e., the form object at the upper part of the frame)
	g_pFormPageRevisionInfo = window.document.WBC_formPageRevisionInfo;
	
	// update check box state
	WBC_updateFilterCheckBoxUI();
	
	// update the revision history list
	window.parent.frames.WBC_framePageRevisionHistory.location = strPageHistoryURL;
	
	// update the compare field
	var strCompareFormType = "";
	var strCompareToType = "";
	
	// construct the name of revision type for "Compare From" page
	if (g_pFormPageRevisionInfo.WBC_inhidCompareFromType.value != "") {
		strCompareFormType = "(" + g_pFormPageRevisionInfo.WBC_inhidCompareFromType.value + ")";
	}
	
	// construct the name of revision type for "Compare To" page
	if (g_pFormPageRevisionInfo.WBC_inhidCompareToType.value != "") {
		strCompareToType = "(" + g_pFormPageRevisionInfo.WBC_inhidCompareToType.value + ")";
	}
	
	g_pFormPageRevisionInfo.WBC_intxtCompareFrom.value = WBC_getDateValue( g_pFormPageRevisionInfo.WBC_inhidCompareFrom.value ) + " " + strCompareFormType;
	g_pFormPageRevisionInfo.WBC_intxtCompareTo.value = WBC_getDateValue( g_pFormPageRevisionInfo.WBC_inhidCompareTo.value ) + " " + strCompareToType;
}


// update the revision history list view
function WBC_updateRevisionHistoryList() {
	// udpate hidden field for check box state
	g_pFormPageRevisionInfo.WBC_inhidFilterState.value = WBC_getCurrentState();

	// update the revision history list
	g_pFormPageRevisionInfo.target = "_self";
	g_pFormPageRevisionInfo.action = g_pFormPageRevisionInfo.WBC_inhidFilterURL.value;
	g_pFormPageRevisionInfo.submit();
}


// update the Revision list report base on the current user configuration
function WBC_onClickApplyButton() {

	if (WBC_getCurrentState() != g_pFormPageRevisionInfo.WBC_inhidFilterState.value) {
		WBC_updateRevisionHistoryList();
	}
}


// open the Compare dialog for the revision Page
function WBC_openCompareDlg( strCompareURL ) {
	
	if ((g_pFormPageRevisionInfo.WBC_inhidCompareTo.value == "") || (g_pFormPageRevisionInfo.WBC_inhidCompareFrom.value == "")) {
		alert( IDS_UI_ALERT_LESS_SELECTED_MESSAGE );
		return;
	}
	
	WBC_openWindowOnFocus("about:blank", IDS_WIN_PAGEREVISION_COMPARE_NAME, WBC_getPoppedUpWindowFeatures(IDS_WIN_PAGEREVISION_COMPARE_FEATURES, window.top));
	g_pFormPageRevisionInfo.target = IDS_WIN_PAGEREVISION_COMPARE_NAME;
	g_pFormPageRevisionInfo.action = strCompareURL;
	g_pFormPageRevisionInfo.submit();
}


// clear all the selected revision
function WBC_onClickClearBtn() {
	// update the compare field
	g_pFormPageRevisionInfo.WBC_inhidCompareFrom.value = "";
	g_pFormPageRevisionInfo.WBC_inhidCompareTo.value = "";
	g_pFormPageRevisionInfo.WBC_inhidCompareFromType.value = "";
	g_pFormPageRevisionInfo.WBC_inhidCompareToType.value = "";
	g_pFormPageRevisionInfo.WBC_intxtCompareFrom.value = WBC_getDateValue( g_pFormPageRevisionInfo.WBC_inhidCompareFrom.value );
	g_pFormPageRevisionInfo.WBC_intxtCompareTo.value = WBC_getDateValue( g_pFormPageRevisionInfo.WBC_inhidCompareTo.value );
	
	WBC_updateRevisionHistoryList();
}


// retreive the current state
function WBC_getCurrentState() {
	var bPageChk = g_pFormPageRevisionInfo.WBC_inchkPage.checked;
	var bSrcChk = g_pFormPageRevisionInfo.WBC_inchkResource.checked;
	
	if (!bPageChk && !bSrcChk) {
		return IDS_CHK_NONE;
	} else if(!bPageChk && bSrcChk) {
		return IDS_CHK_RESOURCE;
	} else if(bPageChk && !bSrcChk) {
		return IDS_CHK_POSTING;
	} else if(bPageChk && bSrcChk) {
		return IDS_CHK_ALL;
	} else {
		alert( IDS_INVALID_STATE );
		return;
	}
}


// update the filtering check box
function WBC_updateFilterCheckBoxUI() {
	var nFilterCurrentState = g_pFormPageRevisionInfo.WBC_inhidFilterState.value;
	
	g_pFormPageRevisionInfo.WBC_inchkPage.checked = ( ( nFilterCurrentState &  IDS_CHK_POSTING ) == IDS_CHK_POSTING );
	g_pFormPageRevisionInfo.WBC_inchkResource.checked = ( ( nFilterCurrentState &  IDS_CHK_RESOURCE ) == IDS_CHK_RESOURCE );
}


// update the apply button
function WBC_onClickFilter() {
	if (WBC_getCurrentState() != g_pFormPageRevisionInfo.WBC_inhidFilterState.value) {
		g_pFormPageRevisionInfo.WBC_imgApply.src = IDS_PATH_IMAGES_COMMON + IDS_IMG_BTN_APPLY_GIF
	} else {
		g_pFormPageRevisionInfo.WBC_imgApply.src = IDS_PATH_IMAGES_COMMON + IDS_IMG_BTN_APPLY_OFF_GIF
	}
	return true;
}




