var rdFilterOldComparisonOptionsArray = new Array();    // Array holds the Analysis Grid Filter Comparison options ('Starts With' and 'Contains') in memory.
var rdFilterNewComparisonOptionsArray = new Array();    // Array holds the Analysis Grid Filter Comparison option ('Date Range') in memory.
// Holding the values in memory seems to be a better option to handle the issues that may raise with internationalization.

function rdAgShowMenuTab(sTabName, bCheckForReset) {

    var bOpen = true
    if (sTabName.length==0){
        bOpen=false
    }else{
        var eleSelectedTab = document.getElementById('col' + sTabName)
        var eleSelectedRow = document.getElementById('row' + sTabName)
        if (eleSelectedTab.className.indexOf('rdAgSelectedTab')!=-1) {
            bOpen = false
        }
        if (bCheckForReset){
            if (location.href.indexOf("rdAgReset")!=-1 || location.href.indexOf("rdAgLoadSaved")!=-1){
                bOpen = false
            }
        }
    }

    document.getElementById('rdAgCurrentOpenPanel').value = ''
    rdSetClassNameById('colCalc','rdAgUnselectedTab')
    rdSetClassNameById('colLayout','rdAgUnselectedTab')
    rdSetClassNameById('colSortOrder','rdAgUnselectedTab')
    rdSetClassNameById('colFilter','rdAgUnselectedTab')
    rdSetClassNameById('colGroup','rdAgUnselectedTab')
    rdSetClassNameById('colAggr','rdAgUnselectedTab')
    rdSetClassNameById('colChart','rdAgUnselectedTab')
    rdSetClassNameById('colCrosstab','rdAgUnselectedTab')
    rdSetClassNameById('colPaging','rdAgUnselectedTab')
    
    rdSetDisplayById('rowCalc','none')
    rdSetDisplayById('rowLayout','none')
    rdSetDisplayById('rowSortOrder','none')
    rdSetDisplayById('rowFilter','none')
    rdSetDisplayById('rowGroup','none')
    rdSetDisplayById('rowAggr','none')
    rdSetDisplayById('rowChart','none')
    rdSetDisplayById('rowCrosstab','none')
    rdSetDisplayById('rowPaging','none')
    
    if (bOpen) {
        document.getElementById('rdAgCurrentOpenPanel').value = sTabName
        eleSelectedTab.className = 'rdAgSelectedTab'
//        ShowElement(this.id,'row' + sTabName,'Show');
        if(!bCheckForReset)     // Avoid flicker/fading effect when Paged/Sorted/Postbacks.
            rdFadeElementIn(eleSelectedRow,250);    //#11723.
        eleSelectedRow.style.display=''
    }
    
    rdSetPanelModifiedClass('Calc')
    rdSetPanelModifiedClass('Layout')
    rdSetPanelModifiedClass('SortOrder')
    rdSetPanelModifiedClass('Filter')
    rdSetPanelModifiedClass('Group')
    rdSetPanelModifiedClass('Aggr')
    rdSetPanelModifiedClass('Chart')
    rdSetPanelModifiedClass('Crosstab')
    rdSetPanelModifiedClass('Paging')

    if (typeof window.rdRepositionSliders != 'undefined') {
		//Move CellColorSliders, if there are any.
		rdRepositionSliders()
	}

    if (sTabName=="Filter") {
        rdAgShowPickDistinctButton()
    }
    
    if (sTabName=="Group") {
        rdAgGetGroupByDateOperatorDiv()
    }
    if (sTabName=="Chart") {
        rdAgGetChartsGroupByDateOperatorDiv()
    }
    if (sTabName=="Crosstab") {
        rdAgGetCrosstabHeaderGroupByDateOperatorDiv()
        rdAgGetCrosstabLabelGroupByDateOperatorDiv()
    }

}

function rdSetClassNameById(sId, sClassName) {
    var ele = document.getElementById(sId)
    if(ele) {
        ele.className = sClassName
    }
}
function rdSetDisplayById(sId, sDisplay) {
    var ele = document.getElementById(sId)
    if(ele) {
        ele.style.display = sDisplay
    }
}

function rdSetPanelModifiedClass(sPanel) {
    var eleImage = document.getElementById("img" + sPanel)
    if (eleImage) {
        if (eleImage.className == "rdHighlightOn") {
            var eleButton = document.getElementById("col" + sPanel)
            eleButton.className = eleButton.className + " " + eleButton.className + "On"
        }
    }
}



//function rdAgShowMenuTab(sTabName) {

//    document.getElementById('colCalc').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//    document.getElementById('colLayout').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//    document.getElementById('colSortOrder').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//    document.getElementById('colFilter').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//    document.getElementById('colGroup').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//    document.getElementById('colAggr').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//    document.getElementById('colChart').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//    document.getElementById('colCrosstab').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//    document.getElementById('colPaging').className = (rowCalc.style.display!='none' ? 'rdAgSelectedTab':'')
//}


function rdAgShowChartAdd(sChartType) {
	document.rdForm.rdAgChartType.value=sChartType;
	ShowElement(this.id,'divChartAdd','Show');
	switch (sChartType) {
			case 'Pie':
			case 'Bar':
				ShowElement(this.id,'lblChartXLabelColumn','Show');
				ShowElement(this.id,'lblChartXAxisColumn','Hide');
				ShowElement(this.id,'lblChartYDataColumn','Show');
				ShowElement(this.id,'lblChartYAxisColumn','Hide');
				ShowElement(this.id,'rdAgChartXLabelColumn','Show');
				ShowElement(this.id,'rdAgChartXDataColumn','Hide');
				ShowElement(this.id,'rdAgChartXNumberColumn','Hide');
				ShowElement(this.id,'rdAgChartYAggrLabel','Show');
				ShowElement(this.id,'rdAgChartYAggrList','Show');
				break;
			case 'Scatter':
				ShowElement(this.id,'lblChartXLabelColumn','Hide');
				ShowElement(this.id,'lblChartXAxisColumn','Show');
				ShowElement(this.id,'lblChartYDataColumn','Hide');
				ShowElement(this.id,'lblChartYAxisColumn','Show');
				ShowElement(this.id,'rdAgChartXLabelColumn','Hide');
				ShowElement(this.id,'rdAgChartXDataColumn','Show');
				ShowElement(this.id,'rdAgChartXNumberColumn','Hide');
				ShowElement(this.id,'rdAgChartYAggrLabel','Hide');
				ShowElement(this.id,'rdAgChartYAggrList','Hide');
				break;
			default:  //Line,Spline
				ShowElement(this.id,'lblChartXLabelColumn','Hide');
				ShowElement(this.id,'lblChartXAxisColumn','Show');
				ShowElement(this.id,'lblChartYDataColumn','Hide');
				ShowElement(this.id,'lblChartYAxisColumn','Show');
				ShowElement(this.id,'rdAgChartXLabelColumn','Hide');
				ShowElement(this.id,'rdAgChartXDataColumn','Show');
				ShowElement(this.id,'rdAgChartXNumberColumn','Hide');
				ShowElement(this.id,'rdAgChartYAggrLabel','Show');
				ShowElement(this.id,'rdAgChartYAggrList','Show');
				break;
	}
	//Highlight the selected chart.
	lblChartAddPie.className = "rdAgCommand"
	lblChartAddBar.className = "rdAgCommand"
	lblChartAddLine.className = "rdAgCommand"
	lblChartAddSpline.className = "rdAgCommand"
	lblChartAddScatter.className = "rdAgCommand"
	var eleSelectedCommand = document.getElementById('lblChartAdd' + sChartType)
	eleSelectedCommand.className = "rdAgCommand rdAgCommandHightlight"
	
	if(sChartType){
	    if(rdAgCheckForElements('divChartsGroupByDateOperator')){
            if ((sChartType != 'Bar') && (sChartType != 'Pie')){
                ShowElement(this.id,'divChartsGroupByDateOperator','Hide');
            }
            else{
                 if((rdForm.rdAgPickDateColumnsInCrossTabForGrouping.value.indexOf(rdForm.rdAgChartXLabelColumn.value + ",")!=-1) && (rdForm.rdAgChartXLabelColumn.value.length != 0))
                    ShowElement(this.id,'divChartsGroupByDateOperator','Show');
            }
        }
    }
}

function rdAgColumnMove(sID, nRow, nDirection) {
	var eleThis = document.getElementById('lblColIndent_Row' + nRow)
	var sThisIndent = eleThis.innerHTML
	var sOtherIndent
	if (nDirection<0) {
		if (sThisIndent.length==0) {
			return
		}
		sOtherIndent = sThisIndent.substr(0,sThisIndent.length-1)  //Take off one ".".
	} else {
		sOtherIndent = sThisIndent + '.'
	}
	//Find the Other column with the new indent.
	var eleOther
	var eleTest
	var i
	for (i=1; i<=100; i++) {
		eleTest = document.getElementById('lblColIndent_Row' + i)
		if (!eleTest) {
			break
		}
		if (eleTest.innerHTML==sOtherIndent) {
			eleOther = eleTest
			break
		}
	}
	
	//Switch indents.
	if (eleOther) {
		var sThis = eleThis.innerHTML 
		var sOther = eleOther.innerHTML 
		eleThis.innerHTML = sOther
		eleOther.innerHTML = sThis
		
		//Save the indent so it goes back to the server.
		var eleColMoves = document.getElementById('rdAgColMoves')
		eleColMoves.value = eleColMoves.value + sID + ',' + nDirection + ';'
	}
	
}

function rdAgShowPickDistinctButton() {       
    // Function gets called for the Filter panel/division.           
    rdAgHideAllFilterDivs()
    rdAgRemoveAllWhiteSpaceNodesFromFilterOperatorDropdown()        // Do this to clear the FilterOparator dropdown off all whitespace/text nodes.
    ShowElement(this.id,'divPickDistinct','Show')                   // Show this with out any DataColumn selection
    var i = 0;
    if (rdForm.rdAgFilterColumn.value!=""){
         //Dates
        if((rdForm.rdAgPickDateColumns.value.indexOf(rdForm.rdAgFilterColumn.value + ",")!=-1) | (rdForm.rdAgPickDateColumns.value.indexOf(rdForm.rdAgFilterColumn.value +"-NoCalendar" + ",")!=-1 )){
            rdAgHideAllFilterDivs()
            if('divPickDate')
                ShowElement(this.id,'divPickDate','Show')
            // Manipulate the DataColumn Dropdown.       
            if(rdForm.rdAgFilterOperator.lastChild.value == 'Date Range'){    // condition specific for a fresh dropdown.
                for(i=1;i<=1;i++){
                    rdFilterNewComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);    // remove the new Comparison option 'Date Range'.
                    rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                }  
                if(rdForm.rdAgFilterOperator.lastChild.value == 'Contains'){    //remove the options 'Starts With' and 'Contains'.
                    for (i=0;i<=1;i++){
                        rdFilterOldComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);
                        rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                    }
                }
                 for(i=1;i<=1;i++){ // Add the new Comparison option 'Date Range' back.
                    rdForm.rdAgFilterOperator.appendChild(rdFilterNewComparisonOptionsArray.pop());
                }  
            }
            else{   // condition specific for an already manipulated dropdown.
               if(rdForm.rdAgFilterOperator.lastChild.value == 'Contains'){    //remove the options 'Starts With' and 'Contains'.
                    for (i=0;i<=1;i++){
                        rdFilterOldComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);
                        rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                    }
                }
                for(i=1;i<=1;i++){ // Add the new Comparison option 'Date Range' back.
                    rdForm.rdAgFilterOperator.appendChild(rdFilterNewComparisonOptionsArray.pop());
                }  
            }
            
            if(rdForm.rdAgFilterOperator.value == 'Date Range'){
                rdAgHideAllFilterDivs()
                if('divPickDateRange')
                    ShowElement(this.id,'divPickDateRange','Show')                
            }
            if(rdForm.rdAgPickDateColumns.value.indexOf(rdForm.rdAgFilterColumn.value +"-NoCalendar" + ",")!=-1){
                if (rdForm.rdAgFilterOperator.value == 'Date Range'){
                    rdAgHideAllFilterDivs()                    
                    ShowElement(this.id,'divPickDistinct','Show')
                    if('divPickDistinctDateRangeEndDate')
                        ShowElement(this.id,'divPickDistinctDateRangeEndDate','Show')
                }
                else{
                        rdAgHideAllFilterDivs()   
                        ShowElement(this.id,'divPickDistinct','Show')    
                    }         
            }  
            
            rdAgManipulateFilterInputTextBoxValuesForDateColumns(rdForm.rdAgCurrentFilterValue.value);
            return;
        }
        // Distinct values popup.
        else if(rdForm.rdAgPickDistinctColumns.value.indexOf(rdForm.rdAgFilterColumn.value + ",")!=-1){
            if(rdForm.rdAgFilterOperator.lastChild.value == 'Date Range'){
                for(i=1;i<=1;i++){
                    rdFilterNewComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);    // remove the new Comparison option.
                    rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                }  
                if(rdForm.rdAgFilterOperator.lastChild.value != 'Contains'){    // condition specific for an already manipulated dropdown.
                    for (i=0;i<=1;i++){
                        rdForm.rdAgFilterOperator.appendChild(rdFilterOldComparisonOptionsArray.pop());
                    }
                }
            }
            var elePopupIFrame = document.getElementById('subPickDistinct')
            var sSrc = elePopupIFrame.getAttribute("HiddenSource")
            //Put the picked column name into the URL.
            var nStart = sSrc.indexOf("&rdAgDataColumn=")
            var nEnd = sSrc.indexOf("&", nStart + 1)
            sSrc = sSrc.substr(0,nStart) + "&rdAgDataColumn=" + encodeURI(rdForm.rdAgFilterColumn.value) + sSrc.substr(nEnd)
            elePopupIFrame.setAttribute("HiddenSource", sSrc)
            //elePopupIFrame.setAttribute("HiddenSource", elePopupIFrame.getAttribute("HiddenSource").replace("rdPickDataColumn",encodeURI(rdForm.rdAgFilterColumn.value)))
            rdAgHideAllFilterDivs()
            ShowElement(this.id,'divPickDistinct','Show')
            ShowElement(this.id,'divPickDistinctPopUpButton','Show')           
            elePopupIFrame.removeAttribute("src") //Clear the list so it's rebuilt when the user clicks.
            rdAgManipulateFilterInputTextBoxValuesForDateColumns(rdForm.rdAgCurrentFilterValue.value);
            return;
        }
        else{                   
            rdAgHideAllFilterDivs()
            ShowElement(this.id,'divPickDistinct','Show')     
            if(rdForm.rdAgFilterOperator.lastChild.value != 'Contains'){
                if(rdForm.rdAgFilterOperator.lastChild.value == 'Date Range'){
                    for(i=1;i<=1;i++){
                    rdFilterNewComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);    // remove the new Comparison option 'Date Range'.
                    rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                    } 
                }
                if(rdFilterOldComparisonOptionsArray[0]){                    
                    for(i=0;i<=1;i++){
                        rdForm.rdAgFilterOperator.appendChild(rdFilterOldComparisonOptionsArray.pop());
                    }
                }
            }            
        }
    }
}
function rdAgSetPickedFilterValue(nPickListRowNr) {
    var fraPopup = document.getElementById("subPickDistinct")
    var eleValue = fraPopup.contentWindow.document.getElementById("lblFilter_Row" + nPickListRowNr)
    var sValue
    if (eleValue.textContent) {
        sValue = eleValue.textContent //Mozilla
    }else{
         sValue = eleValue.innerText  //IE
    }
    rdForm.rdAgFilterValue.value = sValue
}

function rdAgPickDateElementDiv(){
    // Function used to regulate the hiding/unhiding of the Divs containing the InputDate elements.
    if(rdForm.rdAgFilterColumn.value){
        if(rdForm.rdAgPickDateColumns.value.indexOf(rdForm.rdAgFilterColumn.value + ",")!=-1){
            if(rdForm.rdAgFilterOperator.value == 'Date Range'){
                rdAgHideAllFilterDivs()
                if(rdAgCheckForElements('divPickDateRange'))
                    ShowElement(this.id,'divPickDateRange','Show')
            }
            else{
                rdAgHideAllFilterDivs()
                if(rdAgCheckForElements('divPickDate'))
                    ShowElement(this.id,'divPickDate','Show')
            }   
        }
        else if(rdForm.rdAgPickDateColumns.value.indexOf(rdForm.rdAgFilterColumn.value +"-NoCalendar" + ",")!=-1){
            if(rdForm.rdAgFilterOperator.value == 'Date Range'){
                rdAgHideAllFilterDivs()
                ShowElement(this.id,'divPickDistinct','Show')
                if(rdAgCheckForElements('divPickDistinctDateRangeEndDate'))
                    ShowElement(this.id,'divPickDistinctDateRangeEndDate','Show')
            }
            else{
                rdAgHideAllFilterDivs()
                ShowElement(this.id,'divPickDistinct','Show')                
            }
        }
        else
            ShowElement(this.id,'divPickDistinct','Show')     
    } 
}

function rdAgManipulateFilterOptionsDropdownForDateColumns(sDataColumn, sOperator){
    // Function gets called when the filter link (with the filter info displayed above the data table) displayed is clicked to set the drop down values.  
    rdAgRemoveAllWhiteSpaceNodesFromFilterOperatorDropdown();      
    rdForm.rdAgFilterColumn.value = sDataColumn;
    var i = 0;
    if(rdForm.rdAgFilterColumn.value){
        if((rdForm.rdAgPickDateColumns.value.indexOf(rdForm.rdAgFilterColumn.value + ",")!=-1)|(rdForm.rdAgPickDateColumns.value.indexOf(rdForm.rdAgFilterColumn.value +"-NoCalendar" + ",")!=-1)){
            if(rdForm.rdAgFilterOperator.lastChild.value == 'Date Range'){
                for(i=1;i<=1;i++){
                    rdFilterNewComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);    // remove the new Comparison option 'Date Range'.
                    rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                }  
                if(rdForm.rdAgFilterOperator.lastChild.value == 'Contains'){    //remove the options 'Starts With' and 'Contains'.
                    for (i=0;i<=1;i++){
                        rdFilterOldComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);
                        rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                    }
                }
                for(i=1;i<=1;i++){ // Add the new Comparison option 'Date Range' back.
                    rdForm.rdAgFilterOperator.appendChild(rdFilterNewComparisonOptionsArray.pop());
                }  
            }
            else{
               if(rdForm.rdAgFilterOperator.lastChild.value == 'Contains'){    //remove the options 'Starts With' and 'Contains'.
                    for (i=0;i<=1;i++){
                        rdFilterOldComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);
                        rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                    }
                }
                for(i=1;i<=1;i++){ // Add the new Comparison option 'Date Range' back.
                    rdForm.rdAgFilterOperator.appendChild(rdFilterNewComparisonOptionsArray.pop());
                }  
            }
            rdForm.rdAgFilterColumn.value = "Date Range"           
        }
       else if(rdForm.rdAgFilterOperator.lastChild.value != 'Contains'){   // Code path executed for putting the original options back.
            if(rdForm.rdAgFilterOperator.lastChild.value == 'Date Range'){
                for(i=1;i<=1;i++){
                    rdFilterNewComparisonOptionsArray.push(rdForm.rdAgFilterOperator.lastChild);    // remove the new Comparison option.
                    rdForm.rdAgFilterOperator.removeChild(rdForm.rdAgFilterOperator.lastChild); 
                }  
                if(rdForm.rdAgFilterOperator.lastChild.value != 'Contains'){    //Add the original options back.
                    for (i=0;i<=1;i++){
                        rdForm.rdAgFilterOperator.appendChild(rdFilterOldComparisonOptionsArray.pop());
                    }
                }
            }  
        }
        rdAgShowProperFilterPanel(sDataColumn, sOperator)
    }   
}

function rdAgHideAllFilterDivs(){
    // Function hides all the Divs mentioned below used to seperate elements that are used in specific conditions under the Filters section.
    if(divPickDistinct)
        ShowElement(this.id,'divPickDistinct','Hide')                  // Div holds a common TextBox.
    if(divPickDate)
        ShowElement(this.id,'divPickDate','Hide')                      // Div holds an Input Date to pick a single date.
    if(divPickDateRange)
        ShowElement(this.id,'divPickDateRange','Hide')                 // Div holds an Input Date to pick a Date Range.
    if(divPickDistinctPopUpButton)
        ShowElement(this.id,'divPickDistinctPopUpButton','Hide')       // Div holds the popup button that pulls up the list of ID's, like CustomerID, OrderID etc.
                                                                       // This above div is always hidden for Date Time Columns.
    if(divPickDistinctDateRangeEndDate)                                                       
        ShowElement(this.id,'divPickDistinctDateRangeEndDate','Hide')  // Div holds a TextBox used specifically for the Date Range with out a Calendar for Date Time columns.
                                                                       // This above div is only used for Date Time Columns.
}

function rdAgRemoveAllWhiteSpaceNodesFromFilterOperatorDropdown(){
    // Function removes all the unnecessary text/WhiteSpace nodes from the dropdown which cause issues with different browsers.
    var Element = rdForm.rdAgFilterOperator;
    if(Element){
        for(i=0; i<= Element.childNodes.length; i++){
        if(Element.childNodes[i]) 
            if(Element.childNodes[i].nodeName == '#text')
                Element.removeChild(Element.childNodes[i])
        }
    }
}

function rdAgShowProperFilterPanel(sColumn, sOperator){
    // Function runs on clicking the filter link with the filter info to show the proper panel/Div.
    rdAgHideAllFilterDivs()
    if(sColumn){
        if(rdForm.rdAgPickDateColumns.value.indexOf(sColumn + ",")!=-1){
            if(sOperator=='Date Range'){
                if(rdAgCheckForElements('divPickDateRange'))
                    ShowElement(this.id,'divPickDateRange','Show')
            }
            else{
                if(rdAgCheckForElements('divPickDate'))
                    ShowElement(this.id,'divPickDate','Show')
            }
        }
        else if(rdForm.rdAgPickDateColumns.value.indexOf(sColumn +"-NoCalendar" + ",")!=-1){
            if(sOperator=='Date Range'){
                ShowElement(this.id,'divPickDistinct','Show') 
                if(rdAgCheckForElements('divPickDistinctDateRangeEndDate')){
                    ShowElement(this.id,'divPickDistinctDateRangeEndDate','Show')
                }
            }
            else
                ShowElement(this.id,'divPickDistinct','Show') 
        }
        else{
            ShowElement(this.id,'divPickDistinct','Show')
            if(rdForm.rdAgPickDistinctColumns.value.indexOf(sColumn + ",")!=-1) //#11207.
                rdAgShowPickDistinctButton();
        }
    }
}

function rdAgManipulateFilterInputTextBoxValuesForDateColumns(sValue){
    // Function runs to set the values of the filter into the input text boxes.
    if(rdAgCheckForElements('rdAgCurrentFilterValue'))
        rdForm.rdAgCurrentFilterValue.value = sValue;
    if(sValue){
        var sInputElementValue = sValue.split(',')[0];
        document.rdForm.rdAgFilterValue.value = sInputElementValue;
        document.rdForm.rdAgFilterValueDate.value = sInputElementValue;
        document.rdForm.rdAgFilterValueDateRange.value = sInputElementValue;
        document.rdForm.rdAgFilterValueDateRangeEndDate.value = '';
        document.rdForm.rdAgFilterDateRangeEndDateTextBox.value = '';
        if(sValue.split(',')[1]){
            sInputElementValue = sValue.split(',')[1];
            document.rdForm.rdAgFilterValueDateRangeEndDate.value = sInputElementValue;
            document.rdForm.rdAgFilterDateRangeEndDateTextBox.value = sInputElementValue;
        }
    }
}

function rdAgGetGroupByDateOperatorDiv(){
    // Function used by the Grouping division for hiding/unhiding the GroupByOperator Div.
    if((rdForm.rdAgPickDateColumnsForGrouping.value.indexOf(rdForm.rdAgGroupColumn.value + ",")!=-1) && (rdForm.rdAgGroupColumn.value.length != 0)){
        if(rdAgCheckForElements('divGroupByDateOperator'))
            ShowElement(this.id,'divGroupByDateOperator','Show');
    }
    else{
        if(rdAgCheckForElements('divGroupByDateOperator')){
            ShowElement(this.id,'divGroupByDateOperator','Hide');
            rdForm.rdAgDateGroupBy.value='';
        }
    }
}

function rdAgGetChartsGroupByDateOperatorDiv(){
    // Function used by the Charts division for hiding/unhiding the GroupByOperator Div for the Pie and Bar Charts.
    if((rdForm.rdAgPickDateColumnsInChartForGrouping.value.indexOf(rdForm.rdAgChartXLabelColumn.value + ",")!=-1) && (rdForm.rdAgChartXLabelColumn.value.length != 0)){
        if(rdAgCheckForElements('divChartsGroupByDateOperator'))
            ShowElement(this.id,'divChartsGroupByDateOperator','Show');
    }
    else{
        if(rdAgCheckForElements('divChartsGroupByDateOperator')){
            ShowElement(this.id,'divChartsGroupByDateOperator','Hide');
            rdForm.rdAgChartsDateGroupBy.value='';
        }
    }    
}

function rdAgGetCrosstabHeaderGroupByDateOperatorDiv(){
 // Function used by the Crosstabs division for hiding/unhiding the GroupByOperator Div for the header Column dropdown.
    if((rdForm.rdAgPickDateColumnsInCrossTabForGrouping.value.indexOf(rdForm.rdAgCrosstabHeaderColumn.value + ",")!=-1) && (rdForm.rdAgCrosstabHeaderColumn.value.length != 0)){
        if(rdAgCheckForElements('divCrosstabHeaderGroupByDateOperator'))
            ShowElement(this.id,'divCrosstabHeaderGroupByDateOperator','Show');
    }
    else{
        if(rdAgCheckForElements('divCrosstabHeaderGroupByDateOperator')){
            ShowElement(this.id,'divCrosstabHeaderGroupByDateOperator','Hide');
            rdForm.rdAgCrosstabHeaderDateGroupBy.value='';
        }
    }
}

function rdAgGetCrosstabLabelGroupByDateOperatorDiv(){
 // Function used by the Crosstabs division for hiding/unhiding the GroupByOperator Div for the Label Column dropdown.
    if((rdForm.rdAgPickDateColumnsInCrossTabForGrouping.value.indexOf(rdForm.rdAgCrosstabLabelColumn.value + ",")!=-1) && (rdForm.rdAgCrosstabLabelColumn.value.length != 0)){
        if(rdAgCheckForElements('divCrosstabLabelGroupByDateOperator'))
            ShowElement(this.id,'divCrosstabLabelGroupByDateOperator','Show');
    }
    else{
        if(rdAgCheckForElements('divCrosstabLabelGroupByDateOperator')){
            ShowElement(this.id,'divCrosstabLabelGroupByDateOperator','Hide');
            rdForm.rdAgCrosstabLabelDateGroupBy.value='';
        }
    }
}

function rdAgCheckForElements(Element){
    // Function to check if the element exists.
    if (document.getElementById(Element))
        return true;
    else
        return false;
}
