// Global variable.
//#region
var oColorRange = null;
var oClarityRange = null;
var oCaratRange = null;
var oPriceRange = null;
var oCutRange = null;

var oCaratSlider;
var oClaritySlider;
var oColorSlider;
var oPriceSlider;
var oCutSlider;

var sliderVGrid = null;
var sliderVGridEvent = false;
var GlobalLoadedCarat = 0;
var GlobalLoadedColor = 0;
var GlobalLoadedPrice = 0;
var GlobalLoadedCalrity = 0;
var GlobalLoadedRange = 0;
var selectedVal = "";
var selectedValSecondSlider = "";
var isIE = false;
var divGFirstSlider = null;
var divGSecondSlider = null;

var divGFirstSliderCarat = null;
var divGSecondSliderCarat = null;
var divGFirstSliderClarity = null;
var divGSecondSliderClarity = null;
var divGFirstSliderColor = null;
var divGSecondSliderColor = null;
var varIEVersion = navigator.appVersion;
//#endregion

// Browser Validation
//#region
if (navigator.appName == "Microsoft Internet Explorer")
{
    isIE = true;
}
//#endregion

// Zapatec.Grid.prototype
//#region
getMyColumnRange = function(txtValueRange)
{
    //if (txtValueRange == 'ctl00_cphBody_txtPriceRange') { debugger; }

    var aKeys = [];

    var elementColors = document.getElementById(txtValueRange).value;
    var arrColor = elementColors.split(',');
    //alert(arrColor);
    for (var iCol = 0; iCol < arrColor.length; iCol++)
    {
        aKeys.push({
            v: arrColor[iCol],
            c: arrColor[iCol],
            o: arrColor[iCol]
        });
    }
    // Return range of column values
    var iLastKey = aKeys.length - 1;
    return {
        min: aKeys[0].c,
        minValue: aKeys[0].v,
        minOrig: aKeys[0].o,
        max: aKeys[iLastKey].c,
        maxValue: aKeys[iLastKey].v,
        maxOrig: aKeys[iLastKey].o,
        values: aKeys
    };
};


function onCellRightClick(oGrid, oCell)
{
    alert('Right mouse button\nRow id is ' + oGrid.getCellRowId(oCell) +
	 '\nCell id is ' + oGrid.getCellId(oCell) +
	 '\nItem number is ' + oGrid.getCellValueString(oGrid.getCellByRow(
	 oGrid.getRowByCell(oCell), 0)));
}


function onRowClick(oGrid, oRow)
{
    alert('Left mouse button\nRow id is ' + oGrid.getRowId(oRow) +
	 '\nItem number is ' + oGrid.getCellValueString(oGrid.getCellByRow(oRow, 0)));
};

function onRowRightClick(oGrid, oRow)
{
    alert('Right mouse button\nRow id is ' + oGrid.getRowId(oRow) +
	 '\nItem number is ' + oGrid.getCellValueString(oGrid.getCellByRow(oRow, 0)));
};


var oSliderFields = {
    rangeOfCarat: 1,
    rangeOfClarity: 2,
    rangeOfColor: 3,
    rangeOfPrice: 4
};
//#endregion

// Slider Handler
// [Carat]
//#region
function onRangeOfCaratChange(iMinValue, iMaxValue)
{
    //debugger;
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO";

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);
    document.getElementById('ctl00_cphBody_txtCaratMin').value = oCaratRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtCaratMax').value = oCaratRange.values[iMaxValue].v;

    if (GlobalLoadedCarat == 0) { GlobalLoadedCarat = 1; }
    //Initialize price Div Ids 

    if ((divGFirstSliderCarat == null) || (divGSecondSliderCarat == null)) //This is for one time initialization.
    {
        var divRange = document.getElementById("rangeOfCaratScale");

        var divContainer = divRange.getElementsByTagName('div');
        var varCounter = 0;
        for (varCounter = 0; varCounter < divContainer.length; varCounter++)
        {
            if ((divContainer[varCounter].id.indexOf("FirstSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGFirstSliderCarat = document.getElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSliderCarat = document.getElementById(divContainer[varCounter].id);
            }
        }
    }

    //document.getElementById("txtFromCaratSelection").value = oCaratRange.values[iMinValue].v;
    document.getElementById("spFromCaratSelection").firstChild.nodeValue = oCaratRange.values[iMinValue].v;

    document.getElementById("spToCaratSelection").firstChild.nodeValue = oCaratRange.values[iMaxValue].v;
    //document.getElementById("txtToCaratSelection").value = oCaratRange.values[iMaxValue].v;
    showSelectedArea("divSACarat", divGFirstSliderCarat, divGSecondSliderCarat);
    ShowSlidingCarat(document.getElementById('ctl00_cphBody_txtCaratMin').value, document.getElementById('ctl00_cphBody_txtCaratMax').value);
}

function onRangeOfCaratDrag(iMinValue, iMaxValue)
{
    //debugger;
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO";
    document.getElementById("ctl00_cphBody_hdnConsiderCarat").value = "YES";   //This will not reset the carat slider and data will be populated keeping carat in view 

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);
    document.getElementById('ctl00_cphBody_txtCaratMin').value = oCaratRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtCaratMax').value = oCaratRange.values[iMaxValue].v;

    if (GlobalLoadedCarat != 0)
    {
        resetPriceFlags();
        __doPostBackBySlider('ctl00$cphBody$btnHidden', '');
    }
    else
        GlobalLoadedCarat = 1;

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
    resetPriceFlags();
}
//#endregion

// [Clarity]
//#region
function onRangeOfClarityChange(iMinValue, iMaxValue)
{
    //debugger;
    resetCaratFlags();
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO";

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);

    document.getElementById('ctl00_cphBody_txtClarityMin').value = oClarityRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtClarityMax').value = oClarityRange.values[iMaxValue].v;

    if (GlobalLoadedCalrity == 0) { GlobalLoadedCalrity = 1; }

    if ((divGFirstSliderClarity == null) || (divGSecondSliderClarity == null)) //This is for one time initialization.
    {
        var divRange = document.getElementById("rangeOfClarityScale");

        var divContainer = divRange.getElementsByTagName('div');
        var varCounter = 0;
        for (varCounter = 0; varCounter < divContainer.length; varCounter++)
        {
            if ((divContainer[varCounter].id.indexOf("FirstSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGFirstSliderClarity = document.getElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSliderClarity = document.getElementById(divContainer[varCounter].id);
            }
        }
    }
    /*
    document.getElementById("txtFromClaritySelection").value = oClarityRange.values[iMinValue].v;
    document.getElementById("txtToClaritySelection").value = oClarityRange.values[iMaxValue].v;*/

    document.getElementById("spFromClaritySelection").firstChild.nodeValue = oClarityRange.values[iMinValue].v;
    document.getElementById("spToClaritySelection").firstChild.nodeValue = oClarityRange.values[iMaxValue].v;

    showSelectedArea("divSAClarity", divGFirstSliderClarity, divGSecondSliderClarity);
}

function onRangeOfClarityDrag(iMinValue, iMaxValue)
{
    resetCaratFlags();
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO";

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);

    document.getElementById('ctl00_cphBody_txtClarityMin').value = oClarityRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtClarityMax').value = oClarityRange.values[iMaxValue].v;
    if (GlobalLoadedCalrity == 0)
    {
        GlobalLoadedCalrity = 1;
    }
    else
    {
        //debugger;
        resetPriceFlags();
        document.getElementById('ctl00_cphBody_hdnClarityChanged').value = "YES";
        //document.getElementById('hdnConsiderCarat').value = "NO" //Need not  to consider carat, need not to reconfigure the carat slider
        __doPostBackBySlider('ctl00$cphBody$btnHidden', '');
    }

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
    resetPriceFlags();
}
//#endregion

// [Price]
//#region
function onRangeOfPriceChange(iMinValue, iMaxValue)
{
    resetCaratFlags();
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "YES";
    //document.getElementById("hdnLockPrice").value = "YES";  //#PLock	

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);
    document.getElementById('ctl00_cphBody_txtPriceMin').value = oPriceRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtPriceMax').value = oPriceRange.values[iMaxValue].v;

    if (GlobalLoadedPrice == 0) { GlobalLoadedPrice = 1; }

    selectedVal = document.getElementById('ctl00_cphBody_txtPriceMin').value;
    selectedValSecondSlider = document.getElementById('ctl00_cphBody_txtPriceMax').value;

    //Initialize price Div Ids 

    if ((divGFirstSlider == null) || (divGSecondSlider == null)) //This is for one time initialization.
    {
        var divRange = document.getElementById("rangeOfPriceScale");

        var divContainer = divRange.getElementsByTagName('div');
        var varCounter = 0;
        for (varCounter = 0; varCounter < divContainer.length; varCounter++)
        {
            if ((divContainer[varCounter].id.indexOf("FirstSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGFirstSlider = document.getElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSlider = document.getElementById(divContainer[varCounter].id);
            }
        }
    }

    //document.getElementById("txtFromPriceSelection").value = formatCurrency(oPriceRange.values[iMinValue].v);
    //document.getElementById("txtToPriceSelection").value = formatCurrency(oPriceRange.values[iMaxValue].v);

    document.getElementById("spFromPriceSelection").firstChild.nodeValue = formatCurrency(oPriceRange.values[iMinValue].v);
    document.getElementById("spToPriceSelection").firstChild.nodeValue = formatCurrency(oPriceRange.values[iMaxValue].v);
    ShowSlidingPrice(selectedVal, selectedValSecondSlider);
}

function onRangeOfPriceDrag(iMinValue, iMaxValue)
{
    //debugger;
    //appendError("PLOCK 1 Drag Called");
    resetCaratFlags();
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "YES";
    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);
    document.getElementById('ctl00_cphBody_txtPriceMin').value = oPriceRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtPriceMax').value = oPriceRange.values[iMaxValue].v;
    if (GlobalLoadedPrice == 0)
    {
        // appendError("PLOCK 1" + document.getElementById("hdnLockPrice").value);
        GlobalLoadedPrice = 1;
    }
    else
    {
        //resetPriceFlags();
        document.getElementById("ctl00_cphBody_hdnLockPrice").value = "YES";  //#PLock
        //appendError("PLOCK 1" + document.getElementById("hdnLockPrice").value);
        __doPostBackBySlider('ctl00$cphBody$btnHidden', '');
    }

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position  
    //resetPriceFlags();
}
//#endregion

// [Color]
//#region
function onRangeOfColorChange(iMinValue, iMaxValue)
{
    resetCaratFlags();
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO";

    document.getElementById('ctl00_cphBody_txtColorMin').value = oColorRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtColorMax').value = oColorRange.values[iMaxValue].v;

    if (GlobalLoadedColor == 0) { GlobalLoadedColor = 1; }

    if ((divGFirstSliderColor == null) || (divGSecondSliderColor == null)) //This is for one time initialization.
    {
        var divRange = document.getElementById("rangeOfColorScale");

        var divContainer = divRange.getElementsByTagName('div');
        var varCounter = 0;
        for (varCounter = 0; varCounter < divContainer.length; varCounter++)
        {
            if ((divContainer[varCounter].id.indexOf("FirstSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGFirstSliderColor = document.getElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSliderColor = document.getElementById(divContainer[varCounter].id);
            }
        }
    }
    document.getElementById("spFromColorSelection").firstChild.nodeValue = oColorRange.values[iMinValue].v;
    document.getElementById("spToColorSelection").firstChild.nodeValue = oColorRange.values[iMaxValue].v;

    //document.getElementById("txtFromColorSelection").value = oColorRange.values[iMinValue].v;
    //document.getElementById("txtToColorSelection").value = oColorRange.values[iMaxValue].v;

    showSelectedArea("divSAColor", divGFirstSliderColor, divGSecondSliderColor);
}

function onRangeOfColorDrag(iMinValue, iMaxValue)
{
    resetCaratFlags();
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO";
    document.getElementById('ctl00_cphBody_txtColorMin').value = oColorRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtColorMax').value = oColorRange.values[iMaxValue].v;

    if (GlobalLoadedColor == 0)
    {
        GlobalLoadedColor = 1;
    }
    else
    {
        resetPriceFlags();
        document.getElementById('ctl00_cphBody_hdnColorChanged').value = "YES";
        //document.getElementById('hdnConsiderCarat').value = "NO" //Need not to consider carat, need not to reconfigure the carat slider
        __doPostBackBySlider('ctl00$cphBody$btnHidden', '');
    }

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
    resetPriceFlags();
}
//#endregion

// [Cut]
//#region
function onRangeOfCutChange(iMinValue, iMaxValue)
{
    resetCaratFlags();
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO";

    document.getElementById('ctl00_cphBody_txtCutMin').value = oCutRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtCutMax').value = oCutRange.values[iMaxValue].v;

    if (GlobalLoadedColor == 0) { GlobalLoadedColor = 1; }

    //    if ((divGFirstSliderColor == null) || (divGSecondSliderColor == null)) //This is for one time initialization.
    //    {
    //        var divRange = document.getElementById("rangeOfCutScale");

    //        var divContainer = divRange.getElementsByTagName('div');
    //        var varCounter = 0;
    //        for (varCounter = 0; varCounter < divContainer.length; varCounter++) {
    //            if ((divContainer[varCounter].id.indexOf("FirstSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1)) {
    //                divGFirstSliderColor = document.getElementById(divContainer[varCounter].id);
    //            }
    //            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1)) {
    //                divGSecondSliderColor = document.getElementById(divContainer[varCounter].id);
    //            }
    //        }
    //    }
    //    document.getElementById("txtFromCutSelection").value = oCutRange.values[iMinValue].v;
    //    document.getElementById("txtToCutSelection").value = oCutRange.values[iMaxValue].v;
    document.getElementById("spFromCutSelection").firstChild.nodeValue = oCutRange.values[iMinValue].v;
    document.getElementById("spToCutSelection").firstChild.nodeValue = oCutRange.values[iMaxValue].v;

    //
    // showSelectedArea("divSAColor", divGFirstSliderColor, divGSecondSliderColor);
}

function onRangeOfCutDrag(iMinValue, iMaxValue)
{
    resetCaratFlags();
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO";
    document.getElementById('ctl00_cphBody_txtCutMin').value = oCutRange.values[iMinValue].v;
    document.getElementById('ctl00_cphBody_txtCutMax').value = oCutRange.values[iMaxValue].v;
    if (GlobalLoadedColor == 0)
    {
        GlobalLoadedColor = 1;
    }
    else
    {
        resetPriceFlags();
        // document.getElementById('hdnColorChanged').value = "YES";
        __doPostBackBySlider('ctl00$cphBody$btnHidden', '');
    }

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
    resetPriceFlags();
}
//#endregion

// [SliderBar]
//#region
SliderBar = function(id)
{
    if (id)
    {
        try
        {
            var element = document.getElementById(id);

            if ((element.tagName.toUpperCase() == 'INPUT') && (element.type.toUpperCase() == 'TEXT'))
            {
                this.GetInstance = function() { return document.getElementById(id); }
                this.GetId = function() { return id; }
                this.GetValue = function() { return this.GetInstance().value; }
                this.SetValue = function(value) { this.GetInstance().value = value; }
                this.Clear = function() { this.SetValue(''); }
                this.Set = function(value) { this.__value = value; }
                this.Reset = function() { this.SetValue(this.__value); }
                //this.Backup = function(clear) { this.__value = this.GetValue(); if (clear) { this.Clear(); } }
                //this.Restore = function(clear) { this.SetValue(this.__value); if (clear) { this.__value = ''; } }
                //this.Backup = function(clear) { if (this.GetValue() != '') { this.__value = this.GetValue(); if (clear) { this.Clear(); } } }
                //this.Restore = function(clear) { if (this.__value != '') { this.SetValue(this.__value); if (clear) { this.__value = ''; } } }
            }
        }
        catch (e) { }
    }
}
SliderBar.prototype.__value = '';
SliderBar.prototype.__defaultValue = '';
SliderBar.prototype.$Temp$ = '';
SliderBar.prototype.GetInstance = new Function();
SliderBar.prototype.GetId = new Function();
SliderBar.prototype.GetValue = new Function();
SliderBar.prototype.SetValue = new Function();
SliderBar.prototype.Clear = new Function();
SliderBar.prototype.Set = new Function();
SliderBar.prototype.Reset = new Function();
//SliderBar.prototype.Backup = new Function();
//SliderBar.prototype.Restore = new Function();
SliderBar.prototype.Generate = new Function();
//#endregion

// RegisterDiamondSliderWrapper() ***
//#region
function RegisterDiamondSliderWrapper()
{
    DiamondSlider = { Bars: {} };

    DiamondSlider.Bars =
    {
        Carat: new SliderBar('ctl00_cphBody_txtCaratRange'),
        CLarity: new SliderBar('ctl00_cphBody_txtClarityRange'),
        Color: new SliderBar('ctl00_cphBody_txtColorRange'),
        Cut: new SliderBar('ctl00_cphBody_txtCutRange'),
        Price: new SliderBar('ctl00_cphBody_txtPriceRange')
    };

    // [DiamondSlider.Bar.Carat]
    //#region
    DiamondSlider.Bars.Carat.Generate = function()
    {
        var values = this.GetValue().split(',');
        var min = parseFloat(values[0]);
        var max = parseFloat(values[1]);
        var step = 0.01;
        var fraction = 2;
        var ranges = [];

        for (var i = min + step; i < max; i += step)
        {
            ranges.push(i.toFixed(fraction));
        }
        ranges.unshift(min.toFixed(fraction));
        ranges.push(max.toFixed(fraction));

        this.SetValue(ranges.join(','));
    }
    //#endregion

    // [DiamondSlider.Bar.Price]
    //#region
    DiamondSlider.Bars.Price.Generate = function()
    {
        var ranges = [];
        var fraction = 0;
        var partition = 16;
        var min, max, step, value;
        var values = this.GetValue().split(',');

        for (var index = 0; index < values.length; index++)
        {
            min = parseFloat(values[index]);
            max = parseFloat(values[index + 1]);
            step = parseInt((max - min) / partition);

            if (index > 0)
            {
                min += step;
            }
            ranges.push(min.toFixed(fraction));

            for (var i = 1; i < (partition - 2); i++)
            {
                min += step;
                value = (min).toFixed(fraction);
                ranges.push(value);
            }
            ranges.push(max.toFixed(fraction));

            if (index == (values.length - 2))
            {
                break;
            }
        }
        this.SetValue(ranges.join(','));
    }
    //#endregion
}
//#endregion

// Grid [Initial]
//#region
function onGridInit()
{
    //debugger;
    if (typeof (DiamondSlider) == 'undefined') { RegisterDiamondSliderWrapper(); }

    var valueSpan = new Array("Carat", "Clarity", "Color", "Cut", "Price");

    for (var i = 0; i < valueSpan.length; i++)
    {
        document.getElementById("spFrom" + valueSpan[i] + "Selection").appendChild(document.createTextNode(''));
        document.getElementById("spTo" + valueSpan[i] + "Selection").appendChild(document.createTextNode(''));
    }

    createGridNewVGSlider();

    ///
    with (DiamondSlider.Bars.Carat) { Generate(); Set(GetValue()); }

    oCaratRange = getMyColumnRange('ctl00_cphBody_txtCaratRange'); //this.getMyColumnRange('txtCaratrange');
    oCaratRange.min = 0;
    oCaratRange.max = oCaratRange.values.length - 1;
    if (oCaratRange)
    {
        // document.getElementById('rangeOfCarat').innerHTML = "0.5<font color=white>....................</font>1<font color=white>....................</font>1.5<font color=white>....................</font>2<font color=white>....................</font>2.5<font color=white>....................</font>3"
        //document.getElementById('rangeOfCarat').innerHTML = "0.25<font color=white>....</font>0.5<font color=white>.......</font>1<font color=white>........</font>1.5<font color=white>........</font>2<font color=white>........</font>2.5<font color=white>........</font>3<font color=white>........</font>3.5<font color=white>........</font>4<font color=white>........</font>4.5<font color=white>........</font>5";
        document.getElementById('rangeOfCarat').innerHTML = "<font color=white>..........</font>";

        if (oCaratSlider)
        {
            oCaratSlider.reset(oCaratRange.min, oCaratRange.max);
        }
        else
        {
            oCaratSlider = new Zapatec.Slider({
                div: 'rangeOfCaratScale',
                length: 350,
                dual: true,
                orientation: 'H',
                step: 1,
                theme: 'theme4',
                range: [oCaratRange.min, oCaratRange.max],
                eventListeners: {
                    'onChange': onRangeOfCaratChange,
                    'newPosition': onRangeOfCaratDrag
                }
            });
        }
    }

    ///
    with (DiamondSlider.Bars.Price) { Generate(); Set(GetValue()); }

    oPriceRange = getMyColumnRange('ctl00_cphBody_txtPriceRange'); //this.getMyColumnRange('txtPriceRange');
    oPriceRange.min = 0;
    oPriceRange.max = oPriceRange.values.length - 1;
    if (oPriceRange)
    {
        if (oPriceSlider)
        {
            oPriceSlider.reset(oPriceRange.min, oPriceRange.max);
        }
        else
        {
            oPriceSlider = new Zapatec.Slider({
                div: 'rangeOfPriceScale',
                length: 350,
                dual: true,
                orientation: 'H',
                step: 1,
                theme: 'theme4',
                range: [oPriceRange.min, oPriceRange.max],
                eventListeners: {
                    'onChange': onRangeOfPriceChange,
                    'newPosition': onRangeOfPriceDrag
                }
            });
        }
    }

    oColorRange = getMyColumnRange('ctl00_cphBody_txtColorRange'); //{column: oSliderFields.rangeOfColor});
    oColorRange.min = 0;
    oColorRange.max = oColorRange.values.length - 1;
    if (oColorRange)
    {
        //document.getElementById('rangeOfColor').innerHTML = "D<font color=white>.................</font>E<font color=white>.................</font>F<font color=white>...................</font>G<font color=white>...................</font>H<font color=white>..................</font>I<font color=white>................</font>J";
        //document.getElementById('rangeOfColor').innerHTML = "D<font color=white>.................</font>E<font color=white>.................</font>F<font color=white>.................</font>G<font color=white>.................</font>H<font color=white>.................</font>I<font color=white>.................</font>J";
        document.getElementById('rangeOfColor').innerHTML = "D<font color=white>..........</font>E<font color=white>...........</font>F<font color=white>...........</font>G<font color=white>..........</font>H<font color=white>...........</font>I<font color=white>..........</font>J<font color=white>...........</font>K<font color=white>...........</font>L<font color=white>..........</font>M";

        if (oColorSlider)
        {
            oColorSlider.reset(oColorRange.min, oColorRange.max);
        }
        else
        {
            oColorSlider = new Zapatec.Slider(
		                    {
		                        div: 'rangeOfColorScale',
		                        length: 350,
		                        dual: true,
		                        orientation: 'H',
		                        step: 1,
		                        theme: 'theme4',
		                        range: [oColorRange.min, oColorRange.max],
		                        eventListeners:
				                                  {
				                                      'onChange': onRangeOfColorChange,
				                                      'newPosition': onRangeOfColorDrag
				                                  }
		                    }
			);
        }
    }

    oCutRange = getMyColumnRange('ctl00_cphBody_txtCutRange'); //{column: oSliderFields.rangeOfColor});
    oCutRange.min = 0;
    oCutRange.max = oCutRange.values.length - 1;
    if (oCutRange)
    {

        //document.getElementById('rangeOfCut').innerHTML = "ID<font color=white>.........................</font>EX<font color=white>.........................</font>VG<font color=white>...........................</font>G<font color=white>...........................</font>F";
        document.getElementById('rangeOfCut').innerHTML = "ID<font color=white>.........................</font>EX<font color=white>.........................</font>VG<font color=white>.........................</font>G<font color=white>.........................</font>F";

        if (oCutSlider)
        {
            oCutSlider.reset(oCutRange.min, oCutRange.max);
        }
        else
        {
            oCutSlider = new Zapatec.Slider(
			    {
			        div: 'rangeOfCutScale',
			        length: 350,
			        dual: true,
			        orientation: 'H',
			        step: 1,
			        theme: 'theme4',
			        range: [oCutRange.min, oCutRange.max],
			        eventListeners:
			            {
			                'onChange': onRangeOfCutChange,
			                'newPosition': onRangeOfCutDrag
			            }
			    }
			);
        }
    }


    oClarityRange = getMyColumnRange('ctl00_cphBody_txtClarityRange');
    oClarityRange.min = 0;
    oClarityRange.max = oClarityRange.values.length - 1;
    if (oClarityRange)
    {
        //document.getElementById('rangeOfClarity').innerHTML = "IF<font color=white>.......</font>VVS1<font color=white>.......</font>VVS2<font color=white>........</font>VS1<font color=white>........</font>VS2<font color=white>.........</font>SI1<font color=white>.........</font>SI2<font color=white>.........</font>I1<font color=white>.........</font>I2"
        //document.getElementById('rangeOfClarity').innerHTML = "FL<font color=white>......</font>IF<font color=white>.......</font>VVS1<font color=white>.......</font>VVS2<font color=white>.......</font>VS1<font color=white>.......</font>VS2<font color=white>.......</font>SI1<font color=white>.......</font>SI2<font color=white>.......</font>I1<font color=white>......</font>I2"
        document.getElementById('rangeOfClarity').innerHTML = "FL<font color=white>......</font>IF<font color=white>.....</font>VVS1<font color=white>......</font>VVS2<font color=white>.....</font>VS1<font color=white>.....</font>VS2<font color=white>.....</font>SI1<font color=white>.....</font>SI2<font color=white>.....</font>SI3<font color=white>.....</font>I1<font color=white>......</font>I2"
        if (oClaritySlider)
        {
            oClaritySlider.reset(oClarityRange.min, oClarityRange.max);
        }
        else
        {
            oClaritySlider = new Zapatec.Slider({
                div: 'rangeOfClarityScale',
                length: 350,
                dual: true,
                orientation: 'H',
                step: 1,
                theme: 'theme4',
                range: [oClarityRange.min, oClarityRange.max],
                eventListeners: {
                    'onChange': onRangeOfClarityChange,
                    'newPosition': onRangeOfClarityDrag
                }
            });
        }
    }

    setTimeout("InitializeShapeSelection();", 1000);
}
//#endregion

// Grid [Method]
//#region
function onGridMovedColumn(oMove)
{
    // Fix sliders using special static method of the grid

    oSliderFields.rangeOfCarat = Zapatec.Grid.getNewColumnNumber({
        fieldId: oSliderFields.rangeOfCarat,
        move: oMove
    });
    oSliderFields.rangeOfClarity = Zapatec.Grid.getNewColumnNumber({
        fieldId: oSliderFields.rangeOfClarity,
        move: oMove
    });
    oSliderFields.rangeOfColor = Zapatec.Grid.getNewColumnNumber({
        fieldId: oSliderFields.rangeOfColor,
        move: oMove
    });
    oSliderFields.rangeOfPrice = Zapatec.Grid.getNewColumnNumber({
        fieldId: oSliderFields.rangeOfPrice,
        move: oMove
    });
}

function resetControls(oForm)
{
    if (typeof oGrid == 'undefined')
    {
        oGrid = objGrid;
    }
    // Reset form
    oForm.textFilter.value = '';
    // Reset all sliders
    var aWidgets = Zapatec.Widget.all;
    var iWidgets = aWidgets.length;
    var oWidget;
    for (var iWidget = 0; iWidget < iWidgets; iWidget++)
    {
        oWidget = aWidgets[iWidget];
        if (oWidget.constructor == Zapatec.Slider)
        {
            oWidget.setPos(oWidget.config.range[0], oWidget.config.range[1]);
        }
    }
    // Reset filters
    if (oGrid)
    {
        oGrid.resetFilters();
    }
}

function resetGridScrollBar()
{
    //  appendError("resetGridScrollBar is called");
    //This method resets the range of the grid slider, according to the new number of recordsv fetched.

    var varNumberOfRecords = document.getElementById("ctl00_cphBody_txtcountrecord").value;
    // alert(varNumberOfRecords);
    //alert(varNumberOfRecords);
    // appendError(" varNumberOfRecords = " + varNumberOfRecords); 
    var varNewRangeMaxValue = (parseInt(Math.round(varNumberOfRecords)) / 13);
    if ((varNumberOfRecords - (parseInt(Math.round(varNewRangeMaxValue)) * 13)) != 0)
    {
        sliderVGrid.setRange(0, parseInt(varNewRangeMaxValue));
        // appendError("Not Zero : varNewRangeMaxValue = " + varNewRangeMaxValue);
    }
    else
    {
        sliderVGrid.setRange(0, parseInt(varNewRangeMaxValue - 1));
        // appendError("Zero : varNewRangeMaxValue = " + varNewRangeMaxValue -1);
    }
    // alert(varNewRangeMaxValue);
    //appendError("New Value : " + varNewRangeMaxValue); 

}
//#endregion

// Diamond Shape
// CheckShapes()
//#region
function CheckShapes()
{
    sliderVGridEvent = false;
    var allSahpes;
    allSahpes = "";
    var objSpan = document.getElementById("spanShape");
    objSpan.innerHTML = "";
    if (document.getElementById('ctl00_cphBody_chkRound') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkRound').checked)
        {
            allSahpes = "'BR',";
            objSpan.innerHTML += "Round";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkOval') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkOval').checked)
        {
            allSahpes += "'OV',";
            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Oval";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkPrincess') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkPrincess').checked)
        {
            allSahpes += "'PRN',";

            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Princess";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkPear') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkPear').checked)
        {
            allSahpes += "'PS',";
            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Pear";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkMarquise') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkMarquise').checked)
        {
            allSahpes += "'MQ',";
            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Marquise";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkHeart') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkHeart').checked)
        {
            allSahpes += "'HS',";
            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Heart";
        }
    }
    if (document.getElementById('ctl00_cphBody_chkRadiant') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkRadiant').checked)
        {
            allSahpes += "'RAD',";
            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Radiant";
        }
    }
    if (document.getElementById('ctl00_cphBody_chkCushion') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkCushion').checked)
        {
            allSahpes += "'CUS',";
            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Cushion";
        }
    }
    if (document.getElementById('ctl00_cphBody_chkAsscher') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkAsscher').checked)
        {
            allSahpes += "'AS',";
            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Asscher";
        }
    }
    if (document.getElementById('ctl00_cphBody_chkEmerald') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkEmerald').checked)
        {
            allSahpes += "'EM',";
            if (objSpan.innerHTML != "")
            {
                objSpan.innerHTML += ", ";
            }
            objSpan.innerHTML += "Emerald";
        }
    }

    //debugger;
    document.getElementById('ctl00_cphBody_txtAllshapes').value = allSahpes;
    if (GlobalLoadedPrice != 0)
    {
        sliderVGrid.gotoFirst(); //Reset Grid Slider Position	    
        resetPriceFlags();
        document.getElementById("ctl00_cphBody_hdnShapeChanged").value = "YES" //reset 
        //document.getElementById('hdnConsiderCarat').value = "NO" //reset
        __doPostBackBySlider('ctl00$cphBody$btnHidden', '');
    }
    else
    {
        GlobalLoadedPrice = 1;
    }
}
//#endregion

// InitializeShapeSelection()
//#region
function InitializeShapeSelection()
{
    sliderVGridEvent = false;
    var allSahpes;
    allSahpes = "";
    var objSpan = document.getElementById("spanShape");
    objSpan.innerHTML = "";
    if (document.getElementById('ctl00_cphBody_chkRound') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkRound').checked)
        {
            allSahpes = "'BR',";
            objSpan.innerHTML += "Round ";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkOval') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkOval').checked)
        {
            allSahpes += "'OV',";
            objSpan.innerHTML += "Oval ";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkPrincess') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkPrincess').checked)
        {
            allSahpes += "'PRN',";
            objSpan.innerHTML += "Princess ";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkPear') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkPear').checked)
        {
            allSahpes += "'PS',";
            objSpan.innerHTML += "Pear ";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkMarquise') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkMarquise').checked)
        {
            allSahpes += "'MQ',";
            objSpan.innerHTML += "Marquise ";
        }
    }

    if (document.getElementById('ctl00_cphBody_chkHeart') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkHeart').checked)
        {
            allSahpes += "'HS',";
            objSpan.innerHTML += "Heart ";
        }
    }
    if (document.getElementById('ctl00_cphBody_chkRadiant') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkRadiant').checked)
        {
            allSahpes += "'RAD',";
            objSpan.innerHTML += "Radiant ";
        }
    }
    if (document.getElementById('ctl00_cphBody_chkCushion') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkCushion').checked)
        {
            allSahpes += "'CUS',";
            objSpan.innerHTML += "Cushion ";
        }
    }
    if (document.getElementById('ctl00_cphBody_chkAsscher') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkAsscher').checked)
        {
            allSahpes += "'AS',";
            objSpan.innerHTML += "Asscher ";
        }
    }
    if (document.getElementById('ctl00_cphBody_chkEmerald') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkEmerald').checked)
        {
            allSahpes += "'EM',";
            objSpan.innerHTML += "Emerald ";
        }
    }
}
//#endregion

// checkRoundOnly()
//#region
function checkRoundOnly()
{
    //This function is the part of reset functionality.
    var allSahpes;
    allSahpes = "";
    if (document.getElementById('ctl00_cphBody_chkRound') != null)
    {
        if (document.getElementById('ctl00_cphBody_chkRound').checked)
            allSahpes = "'round',";
    }

    if (document.getElementById('ctl00_cphBody_chkOval') != null)
    {
        document.getElementById('ctl00_cphBody_chkOval').checked = false;
    }

    if (document.getElementById('ctl00_cphBody_chkPrincess') != null)
    {
        document.getElementById('ctl00_cphBody_chkPrincess').checked = false;
    }

    if (document.getElementById('ctl00_cphBody_chkPear') != null)
    {
        document.getElementById('ctl00_cphBody_chkPear').checked = false;
    }

    if (document.getElementById('ctl00_cphBody_chkMarquise') != null)
    {
        document.getElementById('ctl00_cphBody_chkMarquise').checked = false;
    }

    if (document.getElementById('ctl00_cphBody_chkHeart') != null)
    {
        document.getElementById('ctl00_cphBody_chkHeart').checked = false;
    }
    if (document.getElementById('ctl00_cphBody_chkRadiant') != null)
    {
        document.getElementById('ctl00_cphBody_chkRadiant').checked = false;
    }
    if (document.getElementById('ctl00_cphBody_chkCushion') != null)
    {
        document.getElementById('ctl00_cphBody_chkCushion').checked = false;
    }
    if (document.getElementById('ctl00_cphBody_chkAsscher') != null)
    {
        document.getElementById('ctl00_cphBody_chkAsscher').checked = false;
    }
    if (document.getElementById('ctl00_cphBody_chkEmerald') != null)
    {
        document.getElementById('ctl00_cphBody_chkEmerald').checked = false;
    }

    document.getElementById('ctl00_cphBody_txtAllshapes').value = allSahpes;

    document.getElementById("ctl00_cphBody_hdnLockPrice").value = "NO";  //#PLock
}
//#endregion

// onRangeOfVGridSliderChange(a)
//#region
function onRangeOfVGridSliderChange(a)
{
    //debugger;
    sliderVGridEvent = true;
    document.getElementById("txtTotalrecord.ClientID").value = ParseInt(a);
    if (GlobalLoadedRange != 0)
    {
        __doPostBackBySlider('ctl00$cphBody$btnHidden', '');
    }
    else
        GlobalLoadedRange = 1;
}
//#endregion

// ReInitializePriceBar(varNewPriceRange)
//#region
function ReInitializePriceBar(varNewPriceRange)
{
    //debugger;
    setSelectButtonStatus(false);
    //appendError("Result received..called configure 0");

    if (document.getElementById("ctl00_cphBody_hdnShapeChanged").value == "YES")
    {
        if (document.getElementById('ctl00_cphBody_hdnConsiderCarat').value == "NO")
        {
            reconfig_CaratSlider();
        }
    }

    if ((document.getElementById("ctl00_cphBody_hdnColorChanged").value == "YES") || (document.getElementById("ctl00_cphBody_hdnClarityChanged").value == "YES"))
    {
        // appendError("Result received..called configure1");
        if (document.getElementById('ctl00_cphBody_hdnConsiderCarat').value == "NO")
        {
            reconfig_CaratSlider();
        }
        document.getElementById("ctl00_cphBody_hdnColorChanged").value = "NO";
        document.getElementById("ctl00_cphBody_hdnClarityChanged").value = "NO";
        // document.getElementById('ctl00_cphBody_hdnConsiderCarat').value = "YES" //Need to consider carat, need not to reconfigure the carat slider
    }

    if (document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value == "NO") // Need not to reconfigure if price slider changes
    {
        //debugger;
        //document.getElementById("ctl00_cphBody_txtPriceRange").value = varNewPriceRange;

        if (document.getElementById('ctl00_cphBody_hidSortingPostback').value == "NO" && document.getElementById("ctl00_cphBody_hiddenIsGridSliderChanged").value == "NO")
        {
            // appendError("Result received..called configure2");
            if (document.getElementById("ctl00_cphBody_hdnLockPrice").value == "NO")  //#PLock
            {
                // appendError("Result received..called configure3");
                //debugger;
                //DiamondSlider.Bars.Price.Generate();
                reconfig_PriceSlider();
            }
        }
    }
    else
    {
        //debugger;
        //DiamondSlider.Bars.Price.Restore();
        DiamondSlider.Bars.Price.Reset();
    }

    resetPriceFlags();
    resetGridScrollBar(); // reset the slider as well.
}
//#endregion

// createGridNewVGSlider()
//#region
function createGridNewVGSlider()
{
    //alert('dff');
    //  appendError("createGridNewVGSlider  is called");
    totalRecord = parseInt(document.getElementById("ctl00_cphBody_txtTotalrecord").value);

    sliderVGrid = new Zapatec.Slider(
        {
            div: "VGridSlider",
            length: 310,
            range: [0, 310],
            start: 0,
            orientation: "V",
            step: 1,
            onChange: function(a)
            {
                // appendError("Change Pos : Value for new position is : " + a);
                document.getElementById("ctl00_cphBody_hiddenIsGridSliderChanged").value = "YES";
                document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "YES"; //Need to consider as price is chnaged so that after getting output price slider will not get reconfigured
                document.getElementById("ctl00_cphBody_txtVGSliderMinPixel").value = a;
                //  document.getElementById("txtTotalrecord").value = a;
                if (isNaN(a))
                    document.getElementById("ctl00_cphBody_txtTotalrecord").value = "0";
                else
                    document.getElementById("ctl00_cphBody_txtTotalrecord").value = a;

                if (GlobalLoadedRange != 0)
                {
                    // __doPostBackBySlider('ctl00$cphBody$btnHidden','');
                }
                else
                {
                    GlobalLoadedRange = 1;
                }

            },
            newPosition: function(a)
            {
                // alert(a);
                document.getElementById("ctl00_cphBody_hiddenIsGridSliderChanged").value = "YES";
                document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "YES"; //Need to consider as price is chnaged so that after getting output price slider will not get reconfigured            
                // document.getElementById("txtTotalrecord").value = a;
                document.getElementById("ctl00_cphBody_txtVGSliderMinPixel").value = a;

                // appendError("New Pos : Value for new position is : " + a);    
                //alert(a);
                if (isNaN(a))
                {
                    document.getElementById("ctl00_cphBody_txtTotalrecord").value = "0";
                }
                else
                {
                    document.getElementById("ctl00_cphBody_txtTotalrecord").value = a;
                }

                __doPostBackBySlider('ctl00$cphBody$btnHidden', '');
            }
        }
       );

    setTimeout("resetGridScrollBar();", 1000); //For safe this method invocation is delayed, no special reason
    // alert('dff');
}
//#endregion

// Reset Slider
//#region
function resetPriceFlags()
{
    document.getElementById('ctl00_cphBody_hidSortingPostback').value = "NO" //reset
    document.getElementById("ctl00_cphBody_hiddenIsGridSliderChanged").value = "NO" //reset
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "NO"
}

function setSelectButtonStatus(varVal)
{
    if (varVal == false)
    {
        setTimeout("document.getElementById('ctl00_cphBody_imgbtnSelectConfirm').disabled = false;", 100);
    }
    else
    {
        document.getElementById('ctl00_cphBody_imgbtnSelectConfirm').disabled = varVal;
    }
}

function reconfig_PriceSlider()
{
    //debugger;
    //appendError("Reconfig price..");
    DiamondSlider.Bars.Price.Generate();

    oPriceRange = getMyColumnRange('ctl00_cphBody_txtPriceRange'); //this.getMyColumnRange('txtPriceRange');
    oPriceRange.min = 0;
    oPriceRange.max = oPriceRange.values.length - 1;
    if (oPriceRange)
    {
        if (oPriceSlider)
        {
            oPriceSlider.reset(oPriceRange.min, oPriceRange.max);
        }
    }
}

function reconfig_CaratSlider()
{
    DiamondSlider.Bars.Carat.Reset();

    oCaratRange = getMyColumnRange('ctl00_cphBody_txtCaratRange'); //this.getMyColumnRange('txtPriceRange');
    oCaratRange.min = 0;
    oCaratRange.max = oCaratRange.values.length - 1;

    if (oCaratRange)
    {
        if (oCaratSlider)
        {
            // appendError("Reset Carat Started..");
            oCaratSlider.reset(oCaratRange.min, oCaratRange.max);
        }
    }
    resetCaratFlags();
}

function resetCaratFlags()
{
    // document.getElementById('ctl00_cphBody_hdnConsiderCarat').value = "YES" //reset
    document.getElementById("ctl00_cphBody_hdnShapeChanged").value = "NO" //reset 
}
//#endregion

// ResetAllSliders()
//#region
function ResetAllSliders()
{
    //debugger;

    //DiamondSlider.Bars.Carat.Restore();
    //DiamondSlider.Bars.Price.Restore();
    DiamondSlider.Bars.Carat.Reset();
    DiamondSlider.Bars.Price.Reset();
    document.getElementById('ctl00_cphBody_chkRound').checked = true;

    oCaratRange = getMyColumnRange('ctl00_cphBody_txtCaratRange');
    oCaratRange.min = 0;
    oCaratRange.max = oCaratRange.values.length - 1;
    //alert(oCaratRange.min + ' : ' + oCaratRange.max);
    if (oCaratSlider)
    {
        oCaratSlider.reset(oCaratRange.min, oCaratRange.max);
    }

    oPriceRange = getMyColumnRange('ctl00_cphBody_txtPriceRange');
    oPriceRange.min = 0;
    oPriceRange.max = oPriceRange.values.length - 1;
    if (oPriceSlider)
    {
        oPriceSlider.reset(oPriceRange.min, oPriceRange.max);
    }

    oColorRange = getMyColumnRange('ctl00_cphBody_txtColorRange');
    oColorRange.min = 0;
    oColorRange.max = oColorRange.values.length - 1;
    if (oColorSlider)
    {
        oColorSlider.reset(oColorRange.min, oColorRange.max);
    }

    oClarityRange = getMyColumnRange('ctl00_cphBody_txtClarityRange');
    oClarityRange.min = 0;
    oClarityRange.max = oClarityRange.values.length - 1;
    if (oClaritySlider)
    {
        oClaritySlider.reset(oClarityRange.min, oClarityRange.max);
    }

    if (oCutSlider)
    {
        oCutSlider.reset(oCutRange.min, oCutRange.max);
    }
    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
}
//#endregion

//Code For Selection Area Highlighting
// showSelectedArea(varDivSA, objDivFirstSlider, objDivSecondSlider)
//#region
function showSelectedArea(varDivSA, objDivFirstSlider, objDivSecondSlider)
{
    if (document.getElementById(varDivSA) != null)
    {
        var objSelDiv = document.getElementById(varDivSA);
        objSelDiv.style.left = parseInt(parseInt(objDivFirstSlider.style.left) + parseInt(10)) + "px";

        if ((parseInt(objDivSecondSlider.style.left) - parseInt(objDivFirstSlider.style.left)) > 9)
        {
            objSelDiv.style.width = parseInt(parseInt(objDivSecondSlider.style.left) - parseInt(objDivFirstSlider.style.left) - parseInt(9)) + "px";
        }
        else
        {
            objSelDiv.style.width = parseInt(parseInt(objDivSecondSlider.style.left) - parseInt(objDivFirstSlider.style.left)) + "px";
        }
    }
    else
    {
        var varcontSA = objDivFirstSlider.parentNode;
        var objSelDiv = document.createElement('div');
        objSelDiv.setAttribute('id', varDivSA);
        objSelDiv.style.top = (parseInt(objDivFirstSlider.style.top) + parseInt(10)) + "px";

        if (isIE)
        {
            var objImage111 = document.createElement("img");
            objImage111.style.height = "3"
            objSelDiv.style.height = objImage111.height + 'px';
            objSelDiv.style.fontSize = '0px';
        }
        else //Mozilla
        {
            objSelDiv.style.height = "2px";
        }
        if (varIEVersion.indexOf("7") != -1)
        {
            objSelDiv.style.height = "2px";
            objSelDiv.style.top = (parseInt(objDivFirstSlider.style.top) + parseInt(10)) + "px";
        }
        //appendError("Left " + varDivSA + " Second :" + objDivSecondSlider.style.left + "<br/> First : " + objDivFirstSlider.style.left);
        // objSelDiv.style.width = parseInt(parseInt(objDivSecondSlider.style.left) - parseInt(objDivFirstSlider.style.left) - parseInt(9)) + "px";		
        objSelDiv.style.width = "355px";
        objSelDiv.style.left = parseInt(10) + "px";
        varcontSA.appendChild(objSelDiv);
    }
}
//#endregion

//Code for Sliding price
// ShowSlidingPrice(selectedVal1, selectedVal2)
//#region
function ShowSlidingPrice(selectedVal1, selectedVal2)
{
    var divSlidingPrice1 = document.getElementById("divPopupFirstSlider");

    if (divSlidingPrice1 != null)
    {
        divSlidingPrice1.style.left = divGFirstSlider.style.left;
        divSlidingPrice1.style.position = divGFirstSlider.style.position;
        divSlidingPrice1.innerHTML = "$" + formatCurrency(selectedVal1);

        var divSlidingPrice2 = document.getElementById("divPopupSecondSlider");
        if (divSlidingPrice2 != null)
        {
            divSlidingPrice2.style.left = divGSecondSlider.style.left;
            divSlidingPrice2.style.position = divGSecondSlider.style.position;

            divSlidingPrice2.innerHTML = "$" + formatCurrency(selectedVal2);
            //  if(selectedVal2 == "9999999")
            //  {
            //	    divSlidingPrice2.innerHTML  = "$9,999,997";
            //	}

        }
        var varSecondSliderPos = parseInt(divGSecondSlider.style.left);
        var varFirstSliderPos = parseInt(divGFirstSlider.style.left);
        var varDifference = (parseInt(varSecondSliderPos) - parseInt(varFirstSliderPos));

        //debugger;

        if (varSecondSliderPos > 330) //Extreme At Slider 2
        {
            //divSlidingPrice2.style.left = 313 + "px";
            //if (parseInt(varDifference) < parseInt(93))
            //{
            //    divSlidingPrice1.style.left = 250 + "px";
            //}
            divSlidingPrice2.style.left = (varSecondSliderPos + (divGSecondSlider.offsetWidth / 2) - (divSlidingPrice2.offsetWidth / 2)).toString() + 'px';
            if (parseInt(varDifference) < parseInt(93))
            {
                divSlidingPrice1.style.left = 250 + "px";
            }
        }
        else if (varFirstSliderPos < 30)
        {
            if (parseInt(varDifference) < parseInt(40))
            {
                divSlidingPrice2.style.left = 55 + "px";
                if (varFirstSliderPos > 6)
                {
                    divSlidingPrice1.style.left = 4 + "px";
                }
            }
        }
        else if (parseInt(varDifference) < parseInt(50))
        {
            divSlidingPrice1.style.left = parseInt(parseInt(varFirstSliderPos) - parseInt("35")) + "px";
            divSlidingPrice2.style.left = parseInt(parseInt(varSecondSliderPos) + parseInt("20")) + "px";
        }

        //divPopupSelectedArea
        if (document.getElementById("divSAPrice") != null)
        {
            var objSelDiv = document.getElementById("divSAPrice");
            objSelDiv.style.left = parseInt(parseInt(divGFirstSlider.style.left) + parseInt(10)) + "px";

            if ((parseInt(divGSecondSlider.style.left) - parseInt(divGFirstSlider.style.left)) > 9)
            {
                objSelDiv.style.width = parseInt(parseInt(divGSecondSlider.style.left) - parseInt(divGFirstSlider.style.left) - parseInt(9)) + "px";
            }
            else
            {
                objSelDiv.style.width = parseInt(parseInt(divGSecondSlider.style.left) - parseInt(divGFirstSlider.style.left)) + "px";
            }
        }
        else
        {
            var varcontSA = divGFirstSlider.parentNode;
            var objSelDiv = document.createElement('div');
            objSelDiv.setAttribute('id', 'divSAPrice');
            objSelDiv.style.top = (parseInt(divGFirstSlider.style.top) + parseInt(10)) + "px";

            if (isIE)
            {
                var objImage111 = document.createElement("img");
                objImage111.style.height = "3"
                objSelDiv.style.height = objImage111.height + 'px';
                objSelDiv.style.fontSize = '0px';
            }
            else //Mozilla
            {
                objSelDiv.style.height = "2px";
            }

            if (varIEVersion.indexOf("7") != -1)
            {
                objSelDiv.style.height = "2px";
                objSelDiv.style.top = (parseInt(divGFirstSlider.style.top) + parseInt(10)) + "px";
            }
            objSelDiv.style.width = parseInt(parseInt(divGSecondSlider.style.left) - parseInt(divGFirstSlider.style.left) - parseInt(9)) + "px";
            objSelDiv.style.left = parseInt(parseInt(divGFirstSlider.style.left) + parseInt(10)) + "px";
            varcontSA.appendChild(objSelDiv);
        }
    }
    else
    {
        var varcont = divGFirstSlider.parentNode;
        var newdiv = document.createElement('div');
        newdiv.setAttribute('id', 'divPopupFirstSlider');
        newdiv.style.top = parseInt(divGFirstSlider.style.top) + parseInt("25");
        if (!isIE)
            newdiv.style.top = "25px";
        newdiv.style.left = divGFirstSlider.style.left;

        newdiv.innerHTML = "$" + formatCurrency(selectedVal1);
        varcont.appendChild(newdiv);

        //Second Slider		
        var newdiv2 = document.createElement('div');
        newdiv2.setAttribute('id', 'divPopupSecondSlider');
        newdiv2.innerHTML = "$" + formatCurrency(selectedVal2);
        newdiv2.style.top = parseInt(divGSecondSlider.style.top) + parseInt("25");
        if (!isIE)
            newdiv2.style.top = "25px";
        newdiv2.style.left = divGSecondSlider.style.left;
        varcont.appendChild(newdiv2);
    }
}
//#endregion

// ShowSlidingCarat(selectedVal1, selectedVal2)
//#region
function ShowSlidingCarat(selectedVal1, selectedVal2)
{
    var divSlidingCarat1 = document.getElementById("divPopupFirstSliderCarat");

    if (divSlidingCarat1 != null)
    {
        divSlidingCarat1.style.position = "absolute";
        divSlidingCarat1.style.left = divGFirstSliderCarat.style.left;
        divSlidingCarat1.style.position = divGFirstSliderCarat.style.position;
        divSlidingCarat1.innerHTML = selectedVal1;

        var divSlidingCarat2 = document.getElementById("divPopupSecondSliderCarat");
        if (divSlidingCarat2 != null)
        {
            divSlidingCarat2.style.position = "absolute";
            divSlidingCarat2.style.left = divGSecondSliderCarat.style.left;
            divSlidingCarat2.style.position = divGSecondSliderCarat.style.position;
            divSlidingCarat2.innerHTML = selectedVal2;
        }
        var varSecondSliderPos = parseInt(divGSecondSliderCarat.style.left);
        var varFirstSliderPos = parseInt(divGFirstSliderCarat.style.left);
        var varDifference = (parseInt(varSecondSliderPos) - parseInt(varFirstSliderPos));

        if (varSecondSliderPos > 330) //Extreme At Slider 2
        {
            //divSlidingCarat2.style.left = 335 + "px";
            //if (parseInt(varDifference) < parseInt(93))
            //{
            //    divSlidingCarat1.style.left = 250 + "px";
            //}
            divSlidingCarat2.style.left = (varSecondSliderPos + (divGSecondSliderCarat.offsetWidth / 2) - (divSlidingCarat2.offsetWidth / 2)).toString() + 'px';
            if (parseInt(varDifference) < parseInt(93))
            {
                divSlidingCarat1.style.left = 250 + "px";
            }
        }
        else if (varFirstSliderPos < 30)
        {
            if (parseInt(varDifference) < parseInt(40))
            {
                divSlidingCarat2.style.left = 55 + "px";
                if (varFirstSliderPos > 6)
                {
                    divSlidingCarat1.style.left = 4 + "px";
                }
            }
        }
        else if (parseInt(varDifference) < parseInt(50))
        {
            divSlidingCarat1.style.left = parseInt(parseInt(varFirstSliderPos) - parseInt("35")) + "px";
            divSlidingCarat2.style.left = parseInt(parseInt(varSecondSliderPos) + parseInt("20")) + "px";
        }

        //	       //divPopupSelectedArea
        if (document.getElementById("divSACarat") != null)
        {
            var objSelDiv = document.getElementById("divSACarat");
            objSelDiv.style.left = parseInt(parseInt(divGFirstSliderCarat.style.left) + parseInt(10)) + "px";

            if ((parseInt(divGSecondSliderCarat.style.left) - parseInt(divGFirstSliderCarat.style.left)) > 9)
            {
                objSelDiv.style.width = parseInt(parseInt(divGSecondSliderCarat.style.left) - parseInt(divGFirstSliderCarat.style.left) - parseInt(9)) + "px";
            }
            else
            {
                objSelDiv.style.width = parseInt(parseInt(divGSecondSliderCarat.style.left) - parseInt(divGFirstSliderCarat.style.left)) + "px";
            }
            objSelDiv.style.position = "absolute";
        }
        else
        {
            var varcontSA = divGFirstSliderCarat.parentNode;
            var objSelDiv = document.createElement('div');
            objSelDiv.setAttribute('id', 'divSACarat');
            objSelDiv.style.top = (parseInt(divGFirstSliderCarat.style.top) + parseInt(10)) + "px";
            objSelDiv.style.position = "absolute";
            if (isIE)
            {
                var objImage111 = document.createElement("img");
                objImage111.style.height = "3"
                objSelDiv.style.height = objImage111.height + 'px';
                objSelDiv.style.fontSize = '0px';
            }
            else //Mozilla
            {
                objSelDiv.style.height = "2px";
            }

            //For IE 7
            if (varIEVersion.indexOf("7") != -1)
            {
                objSelDiv.style.height = "2px";
                objSelDiv.style.top = (parseInt(divGFirstSliderCarat.style.top) + parseInt(10)) + "px";
            }

            objSelDiv.style.width = parseInt(parseInt(divGSecondSliderCarat.style.left) - parseInt(divGFirstSliderCarat.style.left) - parseInt(9)) + "px";
            objSelDiv.style.left = parseInt(parseInt(divGFirstSliderCarat.style.left) + parseInt(10)) + "px";
            varcontSA.appendChild(objSelDiv);
        }
    }
    else
    {
        var varcont = divGFirstSliderCarat.parentNode;
        var newdiv = document.createElement('div');
        newdiv.setAttribute('id', 'divPopupFirstSliderCarat');
        newdiv.style.top = parseInt(divGFirstSliderCarat.style.top) + parseInt("25");
        if (!isIE)
            newdiv.style.top = "25px";
        newdiv.style.left = divGFirstSliderCarat.style.left;
        newdiv.style.position = "absolute";
        newdiv.innerHTML = selectedVal1;
        varcont.appendChild(newdiv);

        //Second Slider		
        var newdiv2 = document.createElement('div');
        newdiv2.setAttribute('id', 'divPopupSecondSliderCarat');
        newdiv2.innerHTML = selectedVal2;
        newdiv2.style.position = "absolute";
        newdiv2.style.top = parseInt(divGSecondSliderCarat.style.top) + parseInt("25");
        if (!isIE)
            newdiv2.style.top = "25px";
        newdiv2.style.left = divGSecondSliderCarat.style.left;
        varcont.appendChild(newdiv2);
    }
}
//#endregion

// Currency formatting
//#region
function addCommas(number)
{
    return ((number.length > 3) ? (addCommas(number.substring(0, number.length - 3)) + "," + number.substring(number.length - 3, number.length)) :
         String(number));
}

function moneyToNumber(money)
{
    var number = money.replace("$", "");
    while (number.indexOf(",") > -1)
    {
        number = number.replace(",", "");
    }
    if ((number.length) < 1) return 0; else return number;
}

function formatCurrency(varValueToConvert)
{
    try
    {
        var number = moneyToNumber(varValueToConvert);
        var negative = (number.substr(0, 1) == "-");
        number = number.replace("-", "");

        //if (number.indexOf(".") == -1)
        //{
        //    number = number + ".00";
        //}

        var floatArray = number.split(".");
        floatArray[0] = "" + parseFloat(floatArray[0]);
        var newValue = addCommas(floatArray[0]);
        if (floatArray[1] != undefined)
        {
            newValue += "." + floatArray[1].substr(0, 2);
        }
        if (negative)
        {
            newValue = "-" + newValue;
        }

        //if (newValue.split(".")[1].length == 1)
        //{
        //    newValue = newValue + "0";
        //}

        return newValue;
    }
    catch (e)
    {
        //debugger; 
    }
}


function previewShapes(varImgURL, varZooomURL)
{
    //    if(varImgURL != "NotFound")
    //    {
    //        document.getElementById("imgMainImage").style.display = "block";
    //        document.getElementById("hypZoom").style.display = "block";
    //        document.getElementById("imgMainImage").src = varImgURL;    
    //        document.getElementById("hypZoom").href="javascript:void(window.open('"+ varZooomURL +"','zoomimage','width=550,height=460,scrollbars=no,resizable=no'));"
    //    }
    //    else
    //    {
    //        document.getElementById("imgMainImage").style.display = "none";
    //        document.getElementById("hypZoom").style.display = "none";
    //        //document.getElementById("imgMainImage").style.visible = false;    
    //       // document.getElementById("hypZoom").href="javascript:void(window.open('"+ varZooomURL +"','zoomimage','width=550,height=460,scrollbars=no,resizable=no'));"

    //    }
}

function previewClicked(varPreviewImage)
{
    //  document.getElementById("hidPreviewImage").value = varPreviewImage;
    //__doPostBackBySlider('ctl00$cphBody$btnHiddenPreview', '');
}

function funcDiamondSelected(objChk, varSelectedDiaCode)
{
    if (objChk.checked)
    {
        //  document.getElementById('hiddenNumOfDiaSelected').value = parseInt(document.getElementById('hiddenNumOfDiaSelected').value) + parseInt(1);
    }
    else
    {
        //  document.getElementById('hiddenNumOfDiaSelected').value = parseInt(document.getElementById('hiddenNumOfDiaSelected').value) - parseInt(1);                
    }

    if ((parseInt(document.getElementById('ctl00_cphBody_hiddenNumOfDiaSelected').value) == 1) && objChk.checked)
    {
        //  document.getElementById('hidDiamondCode').value = varSelectedDiaCode;        
        //  document.getElementById('hiddenDiamondSelected').value = "YES";
        //__doPostBackBySlider('ctl00$cphBody$btnHiddenForDiamond', '');
    }
}
//#endregion

// Utility
//#region
function SortingStarted()
{
    //debugger;
    //if (typeof (DiamondSlider) == 'undefined') { RegisterDiamondSliderWrapper(); }
    //DiamondSlider.Bars.Carat.Backup();
    //DiamondSlider.Bars.Price.Backup();
    DiamondSlider.Bars.Carat.Clear();
    DiamondSlider.Bars.Price.Clear();

    //hidSortingPostback
    document.getElementById('ctl00_cphBody_hidSortingPostback').value = "YES";
    document.getElementById("ctl00_cphBody_hiddenIsPriceRangeChanged").value = "YES";
    //document.getElementById('ctl00_cphBody_hdnConsiderCarat').value = "YES" //Need to consider carat, need not to reconfigure the carat slider
    document.getElementById("ctl00_cphBody_hdnShapeChanged").value = "NO" //reset       
    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
}

function appendError(varErrorInfo)
{
    var varErrorDiv = document.getElementById('divPopupErrInfo');
    if (!(varErrorDiv != null))
    {
        var newdiv12 = document.createElement('div');
        newdiv12.setAttribute('id', 'divPopupErrInfo');
        newdiv12.style.backcolor = "white";
        document.body.appendChild(newdiv12);
        varErrorDiv = document.getElementById('divPopupErrInfo');
    }
    varErrorDiv.innerHTML += "<br>" + varErrorInfo;
}


function GetAllDivs()
{
    var allDivs = document.getElementsByTagName('div');
    var varStr = "";
    var str = "";
    for (counter1 = 0; counter1 < allDivs.length; counter1++)
    {
        if (allDivs[counter1] != null)
            varStr += "  ---  " + allDivs[counter1].id;

        try
        {
            str += "( " + allDivs[counter1].id + "=" + document.getElementById(allDivs[counter1].id).style.top + "--" + document.getElementById(allDivs[counter1].id).style.left + "--" + document.getElementById(allDivs[counter1].id).style.position + ")";
        }
        catch (e)
        {
        }

    }
}

function ScanMyDiv(varDivId)
{
    var objDiv = document.getElementById(varDivId);
    var varDivInfo = "";
    if (objDiv != null)
    {
        varDivInfo = "<br/>This is Div : " + varDivId + "<br/>";
        varDivInfo += "Number Of Divs inside : " + objDiv.getElementsByTagName('div').length + "<br/>";

        varDivInfo += "Child Divs : "
        var objChilds = objDiv.getElementsByTagName('div');
        var varCounter = 0;
        for (varCounter = 0; varCounter < objChilds.length; varCounter++)
        {
            varDivInfo += objChilds[varCounter].id;
            ScanMyDiv(objChilds[varCounter].id);
        }
    }
    appendError(varDivInfo);
}

function __doPostBackBySlider(eventTarget, eventArgument)
{
    //DiamondSlider.Bars.Carat.Backup();
    //DiamondSlider.Bars.Price.Backup();
    DiamondSlider.Bars.Carat.Clear();
    DiamondSlider.Bars.Price.Clear();

    __doPostBack(eventTarget, eventArgument);
}

//window.attachEvent('onload', function()
//{
//    //__doPostBackBySlider = function()
//    //{
//    //    alert('hi');
//    //}

//    theForm = document.forms['aspnetForm'];

//    if (!theForm)
//    {
//        theForm = document.aspnetForm;
//    }

//    __doPostBackBySlider = function(eventTarget, eventArgument)
//    {
//        if (!theForm.onsubmit || (theForm.onsubmit() != false))
//        {
//            theForm.__EVENTTARGET.value = eventTarget;
//            theForm.__EVENTARGUMENT.value = eventArgument;
//            theForm.submit();
//            return false;
//        }
//    }
//});
//#endregion
