﻿var sliderVGrid = null;
var sliderVGridEvent = false;
var GlobalLoadedCarat = 0;
var GlobalLoadedColor = 0;
var GlobalLoadedPrice = 1;
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 divGFirstSliderCut = null;
var divGSecondSliderCut = null;
var varIEVersion = navigator.appVersion;

if (navigator.appName == "Microsoft Internet Explorer")
{
    isIE = true;
}

//Zapatec.Grid.prototype.
getMyColumnRange = function(txtValueRange)
{

    var aKeys = [];

    var elementColors = $GetElementById(txtValueRange).value;
    var arrColor = elementColors.split(',');

    for (var iCol = 0; iCol < arrColor.length; iCol++)
    {
        aKeys.push({
            v: arrColor[iCol],
            c: arrColor[iCol],
            o: arrColor[iCol]
        });
    }

    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)));
}

/**
* Passed to grid through callbackRowOnClick config option and called when grid
* row is clicked.
* @private
*/
function onRowClick(oGrid, oRow)
{
    alert('Left mouse button\nRow id is ' + oGrid.getRowId(oRow) +
	     '\nItem number is ' + oGrid.getCellValueString(oGrid.getCellByRow(oRow, 0)));
};

/**
* Passed to grid through callbackRowOnRightClick config option and called when
* grid row is right clicked.
* @private
*/
function onRowRightClick(oGrid, oRow)
{
    alert('Right mouse button\nRow id is ' + oGrid.getRowId(oRow) +
	     '\nItem number is ' + oGrid.getCellValueString(oGrid.getCellByRow(oRow, 0)));
};


/**
* Holds ids of the fields used for sliders. Gives ability to change them
* dynamically.
* @private
*/
var oSliderFields = {
    rangeOfCarat: 1,
    rangeOfClarity: 2,
    rangeOfColor: 3,
    rangeOfCut: 4,
    rangeOfPrice: 5
};

var oColorRange = null;
var oCutRange = null;
var oClarityRange = null;
var oCaratRange = null;
var oPriceRange = null;


function onRangeOfCaratChange(iMinValue, iMaxValue)
{
    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);
    $GetElementById('txtCaratMin').value = oCaratRange.values[iMinValue].v;
    $GetElementById('txtCaratMax').value = oCaratRange.values[iMaxValue].v;

    //if ((divGFirstSliderCarat == null) || (divGSecondSliderCarat == null)) //This is for one time initialization.
    {
        var divRange = $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 = $GetElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSliderCarat = $GetElementById(divContainer[varCounter].id);
            }
        }
    }
    showSelectedArea("divSACarat", divGFirstSliderCarat, divGSecondSliderCarat);
    ShowSlidingCarat($GetElementById('txtCaratMin').value, $GetElementById('txtCaratMax').value);
}

function onRangeOfCaratDrag(iMinValue, iMaxValue)
{
    //$GetElementById("FlagObject").value = "NO";

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);
    $GetElementById('txtCaratMin').value = oCaratRange.values[iMinValue].v;
    $GetElementById('txtCaratMax').value = oCaratRange.values[iMaxValue].v;

    DoPostBack('btnHidden', '');
    //debugger;
    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
    ResetPriceFlags();
}

function onRangeOfClarityChange(iMinValue, iMaxValue)
{
    resetCaratFlags();
    //$GetElementById("hiddenIsPriceRangeChanged").value = "NO";

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);

    $GetElementById('txtClarityMin').value = oClarityRange.values[iMinValue].v;
    $GetElementById('txtClarityMax').value = oClarityRange.values[iMaxValue].v;

    //if ((divGFirstSliderClarity == null) || (divGSecondSliderClarity == null)) //This is for one time initialization.
    {
        var divRange = $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 = $GetElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSliderClarity = $GetElementById(divContainer[varCounter].id);
            }
        }
    }
    showSelectedArea("divSAClarity", divGFirstSliderClarity, divGSecondSliderClarity);
}

function onRangeOfClarityDrag(iMinValue, iMaxValue)
{
    //$GetElementById("FlagObject").value = "NO";

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);

    $GetElementById('txtClarityMin').value = oClarityRange.values[iMinValue].v;
    $GetElementById('txtClarityMax').value = oClarityRange.values[iMaxValue].v;

    DoPostBack('btnHidden', '');

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position         
    ResetPriceFlags();
}


function onRangeOfColorChange(iMinValue, iMaxValue)
{
    resetCaratFlags();
    //$GetElementById("hiddenIsPriceRangeChanged").value = "NO";

    $GetElementById('txtColorMin').value = oColorRange.values[iMinValue].v;
    $GetElementById('txtColorMax').value = oColorRange.values[iMaxValue].v;

    //if ((divGFirstSliderColor == null) || (divGSecondSliderColor == null)) //This is for one time initialization.
    {
        var divRange = $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 = $GetElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSliderColor = $GetElementById(divContainer[varCounter].id);
            }
        }
    }
    showSelectedArea("divSAColor", divGFirstSliderColor, divGSecondSliderColor);
}

function onRangeOfColorDrag(iMinValue, iMaxValue)
{
    //$GetElementById("FlagObject").value = "NO";
    $GetElementById('txtColorMin').value = oColorRange.values[iMinValue].v;
    $GetElementById('txtColorMax').value = oColorRange.values[iMaxValue].v;

    DoPostBack('btnHidden', '');

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
    ResetPriceFlags();
}

function onRangeOfCutChange(iMinValue, iMaxValue)
{
    resetCaratFlags();
    //$GetElementById("hiddenIsPriceRangeChanged").value = "NO";

    $GetElementById('txtCutMin').value = oCutRange.values[iMinValue].v;
    $GetElementById('txtCutMax').value = oCutRange.values[iMaxValue].v;

    //if ((divGFirstSliderCut == null) || (divGSecondSliderCut == null)) //This is for one time initialization.
    {
        var divRange = $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))
            {
                divGFirstSliderCut = $GetElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSliderCut = $GetElementById(divContainer[varCounter].id);
            }
        }
    }
    showSelectedArea("divSACut", divGFirstSliderCut, divGSecondSliderCut);
}

function onRangeOfCutDrag(iMinValue, iMaxValue)
{
    //$GetElementById("FlagObject").value = "NO";
    $GetElementById('txtCutMin').value = oCutRange.values[iMinValue].v;
    $GetElementById('txtCutMax').value = oCutRange.values[iMaxValue].v;

    DoPostBack('btnHidden', '');

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
    ResetPriceFlags();
}

function onRangeOfPriceChange(iMinValue, iMaxValue)
{
    resetCaratFlags();
    //$GetElementById("hiddenIsPriceRangeChanged").value = "YES";

    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);

    $GetElementById('txtPriceMin').value = oPriceRange.values[iMinValue].v;
    $GetElementById('txtPriceMax').value = oPriceRange.values[iMaxValue].v;

    selectedVal = $GetElementById('txtPriceMin').value;
    selectedValSecondSlider = $GetElementById('txtPriceMax').value;

    //if ((divGFirstSliderPrice == null) || (divGSecondSliderPrice == null)) //This is for one time initialization.
    {
        var divRange = $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 = $GetElementById(divContainer[varCounter].id);
            }
            if ((divContainer[varCounter].id.indexOf("SecondSlider") != -1) && (divContainer[varCounter].id.indexOf("zp") != -1))
            {
                divGSecondSlider = $GetElementById(divContainer[varCounter].id);
            }
        }
    }
    ShowSlidingPrice(selectedVal, selectedValSecondSlider);
}

function onRangeOfPriceDrag(iMinValue, iMaxValue)
{
    resetCaratFlags();
    $GetElementById("hiddenIsPriceRangeChanged").value = "YES";

    //$GetElementById("FlagObject").value = "YES"; 
    iMinValue = Math.round(iMinValue);
    iMaxValue = Math.round(iMaxValue);

    $GetElementById('txtPriceMin').value = oPriceRange.values[iMinValue].v;
    $GetElementById('txtPriceMax').value = oPriceRange.values[iMaxValue].v;

    if ($GetElementById("FlagObject").value == "NO")
    {
        $GetElementById("FlagObject").value = "YES";
    }

    DoPostBack('btnHidden', '');

    sliderVGrid.gotoFirst();
}

function resetGridScrollBar()
{
    //debugger;
    //  appendError("resetGridScrollBar is called");
    //This method resets the range of the grid slider, according to the new number of recordsv fetched.

    var varNumberOfRecords = $GetElementById("txtcountrecord").value;
    var diamondPerPage = parseInt($GetElementById("hiddenDiamondPerPage").value);
    // appendError(" varNumberOfRecords = " + varNumberOfRecords);
    var varNewRangeMaxValue = (parseInt(Math.round(varNumberOfRecords)) / diamondPerPage);
    if ((varNumberOfRecords - (parseInt(Math.round(varNewRangeMaxValue)) * diamondPerPage)) != 0)
    {
        sliderVGrid.setRange(0, parseInt(varNewRangeMaxValue));
        // appendError("Not Zero : varNewRangeMaxValue = " + varNewRangeMaxValue);
    }
    else
    {
        sliderVGrid.setRange(0, parseInt(varNewRangeMaxValue - 1));
        // appendError("Zero : varNewRangeMaxValue = " + varNewRangeMaxValue -1);
    }
    //appendError("New Value : " + varNewRangeMaxValue); 
}


var oCaratSlider;
var oClaritySlider;
var oColorSlider;
var oCutSlider;
var oPriceSlider;
/**
* Passed to the grid through eventListeners config option as 'gridInitialized'
* event listener and called when grid is initialized. Grid object can be
* accessed through "this" because function is called in scope of grid object.
* @private
*/
function onGridInit()
{
    //debugger;

    //if (typeof (DiamondSlider) == 'undefined') { RegisterDiamondSliderWrapper(); }
    RegisterDiamondSliderWrapper();

    var valueSpan = new Array("Carat", "Clarity", "Color", "Cut", "Price");

    createGridNewVGSlider();

    ///
    with (DiamondSlider.Bars.Carat) { Generate(); Set(GetValue()); }

    //debugger;

    oCaratRange = getMyColumnRange('txtCaratRange', 1.00, 1.50);
    oCaratRange.min = 0;
    oCaratRange.max = oCaratRange.values.length - 1;
    if (oCaratRange)
    {
        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
            }
        });
    }

    oClarityRange = getMyColumnRange('txtClarityRange'); //this.getMyColumnRange('txtClarityRange');
    oClarityRange.min = 0;
    oClarityRange.max = oClarityRange.values.length - 1;
    if (oClarityRange)
    {
        //$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"
        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
            }
        });
    }
    //appendError(" oClaritySlider.min :" + oClaritySlider.min + "..." +oClaritySlider.max);

    oColorRange = getMyColumnRange('txtColorRange'); //{column: oSliderFields.rangeOfColor});
    oColorRange.min = 0;
    oColorRange.max = oColorRange.values.length - 1;
    if (oColorRange)
    {
        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
            }
        });
    }
    // appendError(" oColorSlider.min :" + oColorSlider.min + "..." +oColorSlider.max);

    oCutRange = getMyColumnRange('txtCutRange'); //{column: oSliderFields.rangeOfColor});
    oCutRange.min = 0;
    oCutRange.max = oCutRange.values.length - 1;
    if (oCutRange)
    {
        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
            }
        });
    }
    // appendError(" oColorSlider.min :" + oColorSlider.min + "..." +oColorSlider.max);

    //debugger;

    ///
    with (DiamondSlider.Bars.Price) { Generate(); Set(GetValue()); }

    oPriceRange = getMyColumnRange('txtPriceRange'); //this.getMyColumnRange('txtPriceRange');
    oPriceRange.min = 0;
    oPriceRange.max = oPriceRange.values.length - 1;
    if (oPriceRange)
    {
        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
            }
        });
    }
}

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.rangeOfCut = Zapatec.Grid.getNewColumnNumber({
        fieldId: oSliderFields.rangeOfCut,
        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 CheckShapes()
{
    //debugger;
    //appendError("check shapes called");
    //setSelectButtonStatus(true);
    sliderVGridEvent = false;
    var allSahpes;
    allSahpes = "";

    $GetElementById("FlagObject").value = "NO";
    $GetElementById("FlagShapeChange").value = "NO";

    if ($GetElementById('chkRound') != null)
    {
        if ($GetElementById('chkRound').checked)
            allSahpes = "'round',";
    }

    if ($GetElementById('chkOval') != null)
    {
        if ($GetElementById('chkOval').checked)
            allSahpes += "'oval',";
    }

    if ($GetElementById('chkPrincess') != null)
    {
        //appendError("check shapes called..princess clicked...");
        if ($GetElementById('chkPrincess').checked)
            allSahpes += "'princess',";
    }

    if ($GetElementById('chkPear') != null)
    {
        if ($GetElementById('chkPear').checked)
            allSahpes += "'pear',";
    }

    if ($GetElementById('chkMarquise') != null)
    {
        if ($GetElementById('chkMarquise').checked)
            allSahpes += "'marquise',";
    }

    if ($GetElementById('chkHeart') != null)
    {
        if ($GetElementById('chkHeart').checked)
            allSahpes += "'Heart',";
    }
    if ($GetElementById('chkRadiant') != null)
    {
        if ($GetElementById('chkRadiant').checked)
            allSahpes += "'Radiant',";
    }
    if ($GetElementById('chkCushion') != null)
    {
        if ($GetElementById('chkCushion').checked)
            allSahpes += "'Cushion',";
    }
    if ($GetElementById('chkAsscher') != null)
    {
        if ($GetElementById('chkAsscher').checked)
            allSahpes += "'Asscher',";
    }
    if ($GetElementById('chkEmerald') != null)
    {
        if ($GetElementById('chkEmerald').checked)
            allSahpes += "'emerald',";
    }

    if (allSahpes == '')
    {
        //onRangeOfCaratChange(0, 0);
        //onRangeOfPriceChange(0, 0);
        //sliderVGrid.gotoFirst(); //Reset Grid Slider Position
        //ResetPriceFlags();
        //DoPostBack('btnHidden', '');
        //alert(allSahpes);
        //$GetElementById('txtAllShapes').value = "'round',";
        $GetElementById('txtAllShapes').value = '';
        ResetShape();
        ResetAllSliders();
    }
    else
    {
        $GetElementById('txtAllShapes').value = allSahpes;

        if (GlobalLoadedPrice != 0)
        {
            // appendError("check shapes postback to start");
            sliderVGrid.gotoFirst(); //Reset Grid Slider Position
            resetCaratFlags();
            ResetAllSliders();
            //ResetPriceFlags();
            // appendError("price flag reseted");
            $GetElementById("hdnShapeChanged").value = "YES" //reset 
            $GetElementById('hdnConsiderCarat').value = "NO" //reset
            //setSelectButtonStatus(true);
            //DoPostBack('btnHidden', '');
            // appendError("check shapes called..post back done");
        }
        else
        {
            GlobalLoadedPrice = 1;
        }
    }
}

function onRangeOfVGridSliderChange(a)
{
    sliderVGridEvent = true;
    if (isNaN(a))
        $GetElementById("txtTotalrecord").value = "0";
    else
        $GetElementById("txtTotalrecord").value = a;
    //$GetElementById("txtTotalrecord").value = ParseInt(a);
    if (GlobalLoadedRange != 0)
    {
        //setSelectButtonStatus(true);
        DoPostBack('btnHidden', '');
    }
    else
        GlobalLoadedRange = 1;
}

function ReInitializePriceBar(varNewPriceRange)
{
    //debugger;
    //alert("ReInitializePriceBar");
    //setSelectButtonStatus(false);
    if ($GetElementById("hdnShapeChanged").value == "YES")
    {
        reconfig_CaratSlider();
    }

    if (($GetElementById("hdnColorChanged").value == "YES") || ($GetElementById("hdnCutChanged").value == "YES") || ($GetElementById("hdnClarityChanged").value == "YES"))
    {
        // appendError("Result received..callied configure");
        reconfig_CaratSlider();
        $GetElementById("hdnColorChanged").value = "NO";
        $GetElementById("hdnCutChanged").value = "NO";
        $GetElementById("hdnClarityChanged").value = "NO";
        $GetElementById('hdnConsiderCarat').value = "YES" //Need to consider carat, need not to reconfigure the carat slider
    }


    if ($GetElementById("hiddenIsPriceRangeChanged").value == "NO") // Need not to reconfigure if price slider changes
    {
        $GetElementById("txtPriceRange").value = varNewPriceRange;
        if ($GetElementById('hidSortingPostback').value == "NO" && $GetElementById("hiddenIsGridSliderChanged").value == "NO")
        {
            if ($GetElementById("hdnLockPrice").value == "NO")  //#PLock
                reconfig_PriceSlider();
        }
    }
    ResetPriceFlags();
    resetGridScrollBar(); // reset the slider as well.    
}

function ResetPriceFlags()
{
    $GetElementById('hidSortingPostback').value = "NO" //reset
    $GetElementById("hiddenIsGridSliderChanged").value = "NO" //reset
    $GetElementById("hiddenIsPriceRangeChanged").value = "NO"
}

function resetCaratFlags()
{
    $GetElementById('hdnConsiderCarat').value = "YES" //reset
    $GetElementById("hdnShapeChanged").value = "NO" //reset 
}

function UpdateSliders() //This method manages all the updates of the slider on chnage
{
    reconfig_PriceSlider();
}

function reconfig_PriceSlider()
{
    //debugger;
    DiamondSlider.Bars.Price.Generate();

    oPriceRange = getMyColumnRange('txtPriceRange'); //this.getMyColumnRange('txtPriceRange');
    oPriceRange.min = 0;
    oPriceRange.max = oPriceRange.values.length - 1;
    if (oPriceRange)
    {
        if (oPriceSlider)
        {
            //appendError("Reset Started..");
            oPriceSlider.reset(oPriceRange.min, oPriceRange.max);
            //oPriceSlider.setPos(oPriceRange.min, oPriceRange.max);
        }
    }
}

function reconfigPriceSlider(posMin, posMax)
{
    oPriceRange = getMyColumnRange('txtPriceRange'); //this.getMyColumnRange('txtPriceRange');
    oPriceRange.min = 0;
    oPriceRange.max = oPriceRange.values.length - 1;
    if (oPriceRange)
    {
        if (oPriceSlider)
        {
            //appendError("Reset Started..");
            oPriceSlider.reset(oPriceRange.min, oPriceRange.max);
            oPriceSlider.setPos(posMin, posMax);
        }
    }
}



function reconfig_CaratSlider()
{
    DiamondSlider.Bars.Carat.Reset();

    oCaratRange = getMyColumnRange('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 ResetShape()
{
    //Check only round uncheck all other    
    if ($GetElementById('chkRound') != null) $GetElementById('chkRound').checked = true;
    if ($GetElementById('chkOval') != null) $GetElementById('chkOval').checked = false;
    if ($GetElementById('chkPrincess') != null) $GetElementById('chkPrincess').checked = false;
    if ($GetElementById('chkPear') != null) $GetElementById('chkPear').checked = false;
    if ($GetElementById('chkMarquise') != null) $GetElementById('chkMarquise').checked = false;
    if ($GetElementById('chkHeart') != null) $GetElementById('chkHeart').checked = false;
    if ($GetElementById('chkRadiant') != null) $GetElementById('chkRadiant').checked = false;
    if ($GetElementById('chkCushion') != null) $GetElementById('chkCushion').checked = false;
    if ($GetElementById('chkAsscher') != null) $GetElementById('chkAsscher').checked = false;
    if ($GetElementById('chkEmerald') != null) $GetElementById('chkEmerald').checked = false;

    $GetElementById('txtAllShapes').value = "'round',";
}

function ResetAllSliders()
{

    //Check only round uncheck all other    
    //if ($GetElementById('chkRound') != null) $GetElementById('chkRound').checked = true;
    //if ($GetElementById('chkOval') != null) $GetElementById('chkOval').checked = false;
    //if ($GetElementById('chkPrincess') != null) $GetElementById('chkPrincess').checked = false;
    //if ($GetElementById('chkPear') != null) $GetElementById('chkPear').checked = false;
    //if ($GetElementById('chkMarquise') != null) $GetElementById('chkMarquise').checked = false;
    //if ($GetElementById('chkHeart') != null) $GetElementById('chkHeart').checked = false;
    //if ($GetElementById('chkRadiant') != null) $GetElementById('chkRadiant').checked = false;
    //if ($GetElementById('chkCushion') != null) $GetElementById('chkCushion').checked = false;
    //if ($GetElementById('chkAsscher') != null) $GetElementById('chkAsscher').checked = false;
    //if ($GetElementById('chkEmerald') != null) $GetElementById('chkEmerald').checked = false;

    DiamondSlider.Bars.Carat.Reset();
    DiamondSlider.Bars.Price.Reset();
    //$GetElementById('chkRound').checked = true;

    oCaratRange = getMyColumnRange('txtCaratRange'); //this.getMyColumnRange('txtCaratRange');
    oCaratRange.min = 0;
    oCaratRange.max = oCaratRange.values.length - 1;
    if (oCaratSlider)
    {
        oCaratSlider.reset(oCaratRange.min, oCaratRange.max);
    }

    oPriceRange = getMyColumnRange('txtPriceRange'); //this.getMyColumnRange('txtPriceRange');
    //oPriceRange = getMyColumnRange('txtPriceRangeDefault'); //this.getMyColumnRange('txtPriceRange');    
    oPriceRange.min = 0;
    oPriceRange.max = oPriceRange.values.length - 1;
    if (oPriceSlider)
    {
        oPriceSlider.reset(oPriceRange.min, oPriceRange.max);
    }

    oColorRange = getMyColumnRange('txtColorRange');
    oColorRange.min = 0;
    oColorRange.max = oColorRange.values.length - 1;
    if (oColorSlider)
    {
        oColorSlider.reset(oColorRange.min, oColorRange.max);
    }
    oColorRange.max = 0;

    oCutRange = getMyColumnRange('txtCutRange');
    oCutRange.min = 0;
    oCutRange.max = oCutRange.values.length - 1;
    if (oCutSlider)
    {
        oCutSlider.reset(oCutRange.min, oCutRange.max);
    }
    oCutRange.max = 0;

    oClarityRange = getMyColumnRange('txtClarityRange');
    oClarityRange.min = 0;
    oClarityRange.max = oClarityRange.values.length - 1;
    if (oClaritySlider)
    {
        oClaritySlider.reset(oClarityRange.min, oClarityRange.max);
    }
    oClarityRange.max = 0;

    $GetElementById('txtPriceMin').value = '0';
    $GetElementById('txtPriceMax').value = '0';
    $GetElementById('txtColorMin').value = 'D';
    $GetElementById('txtColorMax').value = 'J';
    $GetElementById('txtCutMin').value = 'ID';
    $GetElementById('txtCutMax').value = 'F';
    $GetElementById('txtClarityMin').value = 'IF';
    $GetElementById('txtClarityMax').value = 'I2';

    $GetElementById('FlagObject').value = "NO";

    //debugger;
    //DoPostBack('WebUserControl1$btnHidden', '');
    //DoPostBack(GetServerControlId('btnHidden'), '');
    DoPostBack('btnHidden', '');

    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
    ResetPriceFlags();
}

function createGridNewVGSlider()
{
    totalRecord = parseInt($GetElementById('txtTotalrecord').value);

    sliderVGrid = new Zapatec.Slider({
        div: "VGridSlider",
        length: 310,
        range: [0, 310],
        start: 0,
        orientation: "V",
        step: 1,
        onChange: function(a)
        {
            $GetElementById("hiddenIsGridSliderChanged").value = "YES";
            //$GetElementById("hiddenIsPriceRangeChanged").value = "YES"; //Need to consider as price is chnaged so that after getting output price slider will not get reconfigured
            $GetElementById("txtVGSliderMinPixel").value = a;

            if (isNaN(a))
                $GetElementById("txtTotalrecord").value = "0";
            else
                $GetElementById("txtTotalrecord").value = a;

            if (GlobalLoadedRange != 0)
            {
                // DoPostBack('btnHidden','');
            }
            else
            {
                GlobalLoadedRange = 1;
            }
        },
        newPosition: function(a)
        {
            $GetElementById("hiddenIsGridSliderChanged").value = "YES";
            $GetElementById("txtVGSliderMinPixel").value = a;

            if (isNaN(a))
                $GetElementById("txtTotalrecord").value = "0";
            else
                $GetElementById("txtTotalrecord").value = a;

            //setSelectButtonStatus(true);
            DoPostBack('btnHidden', '');
        }
    });

    setTimeout("resetGridScrollBar();", 100); //For safe this method invocation is delayed, no special reason
}

function createGridNewVGSliderForRestriction()
{
    totalRecord = parseInt($GetElementById('txtTotalrecord').value);

    sliderVGrid = new Zapatec.Slider({
        div: "VGridSlider",
        length: 310,
        range: [0, 670],
        start: 1,
        orientation: "V",
        step: 1,
        onChange: function(a)
        {
            $GetElementById("hiddenIsGridSliderChanged").value = "YES";
            $GetElementById("txtVGSliderMinPixel").value = a;

            if (isNaN(a))
                $GetElementById("txtTotalrecord").value = "0";
            else
                $GetElementById("txtTotalrecord").value = a;

            if (GlobalLoadedRange != 0)
            {
                // DoPostBack('btnHidden','');
            }
            else
            {
                GlobalLoadedRange = 1;
            }
        },
        newPosition: function(a)
        {
            $GetElementById("hiddenIsGridSliderChanged").value = "YES";

            if (isNaN(a))
                $GetElementById("txtTotalrecord").value = "0";
            else
                $GetElementById("txtTotalrecord").value = a;

            $GetElementById("txtVGSliderMinPixel").value = a;
            //setSelectButtonStatus(true);
            DoPostBack('btnHidden', '');
        }
    });

}
//Code For Selection Area Highlighting
function showSelectedArea(varDivSA, objDivFirstSlider, objDivSecondSlider)
{
    //if ((varDivSA == 'divSACut') || (varDivSA == 'divSAColor')) debugger;
    //appendError("showSelectedArea : " + varDivSA);
    if ($GetElementById(varDivSA) != null)
    {
        var objSelDiv = $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";
        }
        //IE 7
        //For IE 7
        if (varIEVersion.indexOf("7") != -1)
        {
            objSelDiv.style.height = "2px";
            objSelDiv.style.top = (parseInt(objDivFirstSlider.style.top) + parseInt(10)) + "px";
        }
        objSelDiv.style.width = "355px";
        objSelDiv.style.left = parseInt(10) + "px";
        varcontSA.appendChild(objSelDiv);
    }
}

//Code for Sliding price

function ShowSlidingPrice(selectedVal1, selectedVal2)
{
    var divSlidingPrice1 = $GetElementById("divPopupFirstSlider");

    if (divSlidingPrice1 != null)
    {
        divSlidingPrice1.style.left = divGFirstSlider.style.left;
        divSlidingPrice1.style.position = divGFirstSlider.style.position;
        divSlidingPrice1.innerHTML = "$" + formatCurrency(selectedVal1);

        var divSlidingPrice2 = $GetElementById("divPopupSecondSlider");
        if (divSlidingPrice2 != null)
        {
            divSlidingPrice2.style.left = divGSecondSlider.style.left;
            divSlidingPrice2.style.position = divGSecondSlider.style.position;
            divSlidingPrice2.innerHTML = "$" + formatCurrency(selectedVal2);
        }
        var varSecondSliderPos = parseInt(divGSecondSlider.style.left);
        var varFirstSliderPos = parseInt(divGFirstSlider.style.left);
        var varDifference = (parseInt(varSecondSliderPos) - parseInt(varFirstSliderPos));

        if (varSecondSliderPos > 330) //Extreme At Slider 2
        {
            divSlidingPrice2.style.left = 313 + "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 ($GetElementById("divSAPrice") != null)
        {
            var objSelDiv = $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";
            }

            //For IE 7
            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);
    }

    //showSelectedArea();	 
}


function SortingStarted()
{
    DiamondSlider.Bars.Carat.Clear();
    DiamondSlider.Bars.Price.Clear();

    //hidSortingPostback
    $GetElementById('hidSortingPostback').value = "YES";
    //$GetElementById("hiddenIsPriceRangeChanged").value = "YES";
    $GetElementById('hdnConsiderCarat').value = "YES" //Need to consider carat, need not to reconfigure the carat slider
    $GetElementById("hdnShapeChanged").value = "NO" //reset 
    sliderVGrid.gotoFirst(); //Reset Grid Slider Position
}

//Code for Sliding Carat

function ShowSlidingCarat(selectedVal1, selectedVal2)
{
    var divSlidingCarat1 = $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 = $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";
            }
        }
        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 ($GetElementById("divSACarat") != null)
        {
            var objSelDiv = $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);
    }
}

function appendError(varErrorInfo)
{
    var varErrorDiv = $GetElementById('divPopupErrInfo');
    if (!(varErrorDiv != null))
    {
        var newdiv12 = document.createElement('div');
        newdiv12.setAttribute('id', 'divPopupErrInfo');
        document.body.appendChild(newdiv12);
        varErrorDiv = $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 + "=" + $GetElementById(allDivs[counter1].id).style.top + "--" + $GetElementById(allDivs[counter1].id).style.left + "--" + $GetElementById(allDivs[counter1].id).style.position + ")";
        }
        catch (e)
        {
        }

    }
}

function ScanMyDiv(varDivId)
{
    var objDiv = $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);
}

//Currency formatting
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)
{
    //return varValueToConvert;
    if (varValueToConvert != "")
    {
        var number = moneyToNumber(varValueToConvert);
        var negative = (number.substr(0, 1) == "-");
        number = number.replace("-", "");
        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;
        }
        return newValue;
    }
}

function setSelectButtonStatus(varVal)
{
    //btnSelect
    if (varVal == false)
    {
        setTimeout("$GetElementById('btnSelect').disabled = false;", 100);
    }
    else
    {
        $GetElementById('btnSelect').disabled = varVal;
    }
}

function creatPreviewToolBar(varErrorInfo)
{
    var varErrorDiv = $GetElementById('divPopupErrInfo');
    if (!(varErrorDiv != null))
    {
        var newdiv12 = document.createElement('div');
        newdiv12.setAttribute('id', 'divPopupErrInfo');

        document.body.appendChild(newdiv12);
        varErrorDiv = $GetElementById('divPopupErrInfo');
    }
    varErrorDiv.innerHTML += "<br>" + varErrorInfo;
}


function previewShapes(varImgURL, varZooomURL)
{
    if (varImgURL != "NotFound")
    {
        $GetElementById("imgMainImage").style.display = "block";
        $GetElementById("hypZoom").style.display = "block";
        $GetElementById("imgMainImage").src = varImgURL;
        $GetElementById("hypZoom").href = "javascript:void(window.open('" + varZooomURL + "','zoomimage','width=550,height=460,scrollbars=no,resizable=no'));"
    }
    else
    {
        $GetElementById("imgMainImage").style.display = "none";
        $GetElementById("hypZoom").style.display = "none";
        //$GetElementById("imgMainImage").style.visible = false;    
        // $GetElementById("hypZoom").href="javascript:void(window.open('"+ varZooomURL +"','zoomimage','width=550,height=460,scrollbars=no,resizable=no'));"

    }
}

function previewClicked(varPreviewImage)
{
    $GetElementById("hidPreviewImage").value = varPreviewImage;
    // setSelectButtonStatus(true);
    DoPostBack('btnHiddenPreview', '');
}

function funcDiamondSelected(objChk, varSelectedDiaCode)
{
    //debugger;
    if (objChk.checked)
    {
        $GetElementById('hiddenNumOfDiaSelected').value = parseInt($GetElementById('hiddenNumOfDiaSelected').value) + parseInt(1);
    }
    else
    {
        $GetElementById('hiddenNumOfDiaSelected').value = parseInt($GetElementById('hiddenNumOfDiaSelected').value) - parseInt(1);
    }

    //alert(objChk.parentNode.productCode);
    if (parseInt($GetElementById('hiddenNumOfDiaSelected').value) == 0)
    {
        //$GetElementById('pnlDetail3').style.display = 'none';
        //$GetElementById('pnlDetail4').style.display = 'none';
        $GetElementById('hidDiamondCode').value = '';
        DoPostBack('btnHiddenForDiamond', '');
    }
    else if (parseInt($GetElementById('hiddenNumOfDiaSelected').value) == 1)
    {
        for (i = 0; i < document.form1.elements.length; i++)
        {
            if (document.form1.elements.item(i).id.indexOf('c_compare') > -1)
            {
                if (document.form1.elements.item(i).checked)
                {
                    //$GetElementById('hidDiamondCode').value = document.form1.elements.item(i).parentNode.productCode;
                    $GetElementById('hidDiamondCode').value = document.form1.elements.item(i).parentNode.attributes.getNamedItem('productCode').nodeValue;
                    $GetElementById('hiddenDiamondSelected').value = "YES";
                    break;
                }
            }
        }


        //        $GetElementById('hidDiamondCode').value = varSelectedDiaCode;
        //        $GetElementById('hiddenDiamondSelected').value = "YES";
        //           setSelectButtonStatus(true);
        DoPostBack('btnHiddenForDiamond', '');
    }
}

function showPopupForDia()
{
    alert("showing");
    DoPostBack('hidBtnDiaDetails', '');
    return;
}

function Reset()
{
    ResetShape();
    ResetAllSliders();
    ResetPriceFlags();
    SetEnableSlider($GetElementById('rangeOfCutScale'), $GetElementById('rangeOfCut'), $GetElementById('imgDisableView').parentNode, true);
}

//------------------------------------------------------------------------------
function SetEnableSlider(slider, text, image, bool)
{
    //debugger;
    if (slider)
    {
        //slider.style.visibility = (bool) ? 'visible' : 'hidden';
        slider.style.display = (bool) ? 'block' : 'none';
        //image.style.visibility = (bool) ? 'hidden' : 'visible';]
        image.style.display = (bool) ? 'none' : 'block';
        //$imgDisableView

        var cells = text.getElementsByTagName('TD');

        for (var i = 0; i < cells.length; i++)
        {
            cells[i].style.color = (bool) ? 'black' : '#c0c0c0';
        }
    }
}

function $GetElementById(id)
{
    var element = document.getElementById(id);

    if (!element)
    {
        element = document.getElementById($NamingContainerID + '_' + id);
    }
    return element;
}

function RegistrationNamingContainerID(id)
{
    //debugger;
    try
    {
        if (id)
        {
            $NamingContainerID = id;

            //            document._getElementById = $GetElementById;
            //            $GetElementById = function(id)
            //            {
            //                var element = document._getElementById(id);

            //                if (!element)
            //                {
            //                    element = document._getElementById($NamingContainerID + '_' + id);
            //                }
            //                return element;
            //            }
        }
    }
    catch (e)
    {
    }
}

function DoPostBack(id, arg)
{
    DiamondSlider.Bars.Carat.Clear();
    DiamondSlider.Bars.Price.Clear();

    if ($NamingContainerID)
    {
        __doPostBack($NamingContainerID + '$' + id, arg);
    }
    else
    {
        __doPostBack(id, arg);
    }
}

function GetServerControlId(id)
{
    return $NamingContainerID + '$' + id;
}

function ShowDiamondDetails(varCertNum, varShape, varCarat, varColor, varClarity, varDepth, varTable, varGirdle, varCulet, varPolish, varSym, varCut, varFluorescence, varMS, varLaboratory, varPrice, varRowId)
{
    //debugger;
    varPolish = funcConvert(varPolish);
    varSym = funcConvert(varSym);

    if (varFluorescence.toLowerCase() == "b")
    {
        varFluorescence = "Blue";
    }
    else if (varFluorescence.toLowerCase() == "w")
    {
        varFluorescence = "White";
    }
    else if (varFluorescence.toLowerCase() == "y")
    {
        varFluorescence = "Yellow";
    }
    else if (varFluorescence.toLowerCase() == "0")
    {
        varFluorescence = "Orange";
    }
    else if (varFluorescence.toLowerCase() == "r")
    {
        varFluorescence = "Red";
    }
    else if (varFluorescence.toLowerCase() == "g")
    {
        varFluorescence = "Green";
    }
    else if ((varFluorescence == "") || (varFluorescence == " "))
    {
        varFluorescence = "None";
    }

    //var divGridContainer = $GetElementById('<%=GridView1.ClientID%>');
    var divGridContainer = $GetElementById('GridView1');
    var IE = document.all ? true : false

    removeRowFormatting();
    $GetElementById(varRowId).style.backgroundColor = "#D0D0D0";

    var objDiaDiv;
    try
    {
        if ($GetElementById("divDiaDetailsPopup") == null)
        {
            objDiaDiv = document.createElement('div');
            objDiaDiv.setAttribute('id', "divDiaDetailsPopup");
            //$GetElementById("diamondGrid").appendChild(objDiaDiv);
            document.body.appendChild(objDiaDiv);
        }
        else
        {
            objDiaDiv = $GetElementById("divDiaDetailsPopup")
        }

        //if ($GetElementById('<%=GridView1.ClientID%>') != null)
        if (null != divGridContainer)
        {
            //$GetElementById('<%=GridView1.ClientID%>').onmouseout = function(e)
            divGridContainer.onmouseout = function(e)
            {
                var ev = (e) ? e : event;

                ev.cancelBubble = true;
            }
        }

        var varCurrentScroll = 0;
        if (self.pageYOffset) // all except Explorer
        {
            varCurrentScroll = self.pageYOffset;
        }
        else if (document.documentElement && document.documentElement.scrollTop)// Explorer 6 Strict		
        {
            varCurrentScroll = document.documentElement.scrollTop;
        }
        else if (document.body) // all other Explorers
        {
            varCurrentScroll = document.body.clientHeight;
        }

        //Get Height Width of the client window 
        var myWidth = 0, myHeight = 0;
        if (typeof (window.innerWidth) == 'number')
        {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
        {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight))
        {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        }
        //end Get height

        objDiaDiv.style.position = "absolute";

        var varHTML = "<table style='font-size:11px; background-color:white; border-collapse:collapse; border-style:solid; border-width:1px; border-color:gray;'>";
        varHTML += "<tr>";
        varHTML += "<td colspan=2 class='bg_blu30' style='padding:2px; text-align:left; color:white; font-size:12px; background-color:rgb(128,128,128)'>";
        varHTML += "<b>DIAMOND DETAILS</b>"
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:5px 5px 0px 5px; text-align:left;'>";
        //                varHTML += "<b>Certificate No. :</b>"
        varHTML += "Serial no.:</b>"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varCertNum;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Shape:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varShape;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Carat weight:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varCarat;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Color:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varColor;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Clarity:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varClarity;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Depth:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varDepth;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Table:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varTable;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Girdle:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varGirdle;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Culet:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varCulet;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Polish:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varPolish;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Symmetry:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varSym;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Cut grade:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varCut;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Fluorescence:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varFluorescence;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Measurements:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varMS;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Diamond certified by:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += varLaboratory;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "<tr>";
        varHTML += "<td style='padding:0px 5px 0px 5px; text-align:left;'>";
        varHTML += "Price:"
        varHTML += "</td>";
        varHTML += "<td style='padding:0px 5px 5px 5px; text-align:left;'> ";
        varHTML += varPrice;
        varHTML += "</td>";
        varHTML += "</tr>";

        varHTML += "</table>";

        objDiaDiv.innerHTML = varHTML;

        //--
        //     debugger;
        objDiaDiv.style.display = "block";
        objDiaDiv.style.zIndex = 99999999;
        //window.setTimeout(function() { objDiaDiv.style.display = 'none'; }, 500);

        if (isIE)
        {
            objDiaDiv.attachEvent('onmouseover', function() { objDiaDiv.style.display = 'none'; });
            //document.body.attachEvent('onmouseover', function() { objDiaDiv.style.display = 'none'; });
        }
        else
        {
            objDiaDiv.addEventListener('mouseover', function() { objDiaDiv.style.display = 'none'; }, true);
            //document.body.AddListener('mouseover', function() { objDiaDiv.style.display = 'none'; }, true);
        }

        //debugger;
        var isIE8 = (window.navigator.userAgent.toLowerCase().indexOf('msie 8') != -1);
        var isFF2 = (window.navigator.userAgent.toLowerCase().indexOf('firefox/2') != -1);
        var distance = (isIE8) ? 106 : -2;
        var gridRect, bodyRect, dialogRect, rowRect;
        var dialogDimension;

        if (isFF2)
        {
            var rect;

            rect = document.getBoxObjectFor($GetElementById('Grid'));
            gridRect = { left: rect.x, top: rect.y, bottom: rect.y + rect.height };

            rect = document.getBoxObjectFor(document.body);
            bodyRect = { left: rect.x, top: rect.y, bottom: rect.y + rect.height };

            rect = document.getBoxObjectFor(objDiaDiv);
            dialogRect = { left: rect.x, top: rect.y, bottom: rect.y + rect.height };

            rect = document.getBoxObjectFor(this);
            rowRect = { left: rect.x, top: rect.y, bottom: rect.y + rect.height };
        }
        else
        {
            gridRect = $GetElementById('Grid').getBoundingClientRect();
            bodyRect = document.body.getBoundingClientRect();
            dialogRect = objDiaDiv.getBoundingClientRect();
            rowRect = this.getBoundingClientRect();
        }
        dialogDimension = { width: objDiaDiv.offsetWidth, height: objDiaDiv.offsetHeight };

        if (!document.body.bottomMargin)
        {
            document.body.bottomMargin = 18;
        }
        if (rowRect.left < (objDiaDiv.offsetWidth + 10))
        {
            var left = (rowRect.left < 2) ? 2 : rowRect.left;

            distance = (bodyRect.left < 0) ? (parseInt(document.body.bottomMargin) - 2) : -2;
            objDiaDiv.style.left = (left - bodyRect.left + 2).toString().concat('px');
            objDiaDiv.style.top = (rowRect.top - bodyRect.top - objDiaDiv.offsetHeight + distance).toString().concat('px');
        }
        else
        {
            //debugger;
            distance = (bodyRect.left < 0) ? 0 : parseInt(document.body.bottomMargin);
            objDiaDiv.style.left = (rowRect.left - bodyRect.left - objDiaDiv.offsetWidth - 10).toString().concat('px');

            if ((rowRect.top - bodyRect.top + dialogDimension.height) > (gridRect.bottom - bodyRect.top))
            {
                objDiaDiv.style.top = (gridRect.bottom - bodyRect.top - dialogDimension.height + distance).toString().concat('px');
            }
            else
            {
                objDiaDiv.style.top = (rowRect.top - bodyRect.top + distance).toString().concat('px');
            }
        }
    }
    catch (e)
    {
        //alert("Error");
        //debugger;
    }
    return objDiaDiv;
}

function funcConvert(varAbrev)
{
    if (varAbrev == "")
        return "None";

    if (varAbrev.toLowerCase() == "i")
    {
        varAbrev = "Ideal";
    }
    else if ((varAbrev.toLowerCase() == "x") || varAbrev.toLowerCase() == "ex")
    {
        varAbrev = "Excellent";
    }
    else if (varAbrev.toLowerCase() == "vg")
    {
        varAbrev = "Very Good";
    }
    else if (varAbrev.toLowerCase() == "g-vg")
    {
        varAbrev = "Good to Very Good";
    }
    else if ((varAbrev.toLowerCase() == "g") || (varAbrev == 'G'))
    {
        varAbrev = "Good";
    }
    else if (varAbrev.toLowerCase() == "f-g")
    {
        varAbrev = "Fair to Good";
    }
    else if (varAbrev.toLowerCase() == "f")
    {
        varAbrev = "Fair";
    }
    else if (varAbrev.toLowerCase() == "p")
    {
        varAbrev = "Poor";
    }

    return varAbrev;
}

function removeRowFormatting()
{
    var i = 0;
    //var table = $GetElementById('<%=GridView1.ClientID%>');
    var table = $GetElementById('GridView1');
    var rows = table.getElementsByTagName("tr");
    for (i = 0; i < rows.length; i++)
    {
        if ((i % 2) == 0)
            $GetElementById("GVRow" + i).style.backgroundColor = "white";
        else
            $GetElementById("GVRow" + i).style.backgroundColor = "whitesmoke";
    }
}


//<script type="text/javascript">
function fnValidateDiamondCompare()
{
    var dimondSelected = false;

    for (i = 0; i < document.form1.elements.length; i++)
    {
        if (document.form1.elements.item(i).id.indexOf('c_compare') > -1)
        {
            if (document.form1.elements.item(i).checked)
            {
                dimondSelected = true;
                break;
            }
        }
    }

    if (!dimondSelected)
    {
        alert('Select diamond to compare.');
        return false;
    }
    return true;
}

function fnValidateDiamondSelect()
{
    var dimondSelected = false;
    var countSelect = 0;
    for (i = 0; i < document.form1.elements.length; i++)
    {
        if (document.form1.elements.item(i).id.indexOf('c_compare') > -1)
        {
            if (document.form1.elements.item(i).checked)
            {
                dimondSelected = true;
                countSelect++;
                if (countSelect > 1)
                {
                    break;
                }
            }
        }
    }

    if (!dimondSelected)
    {
        alert('Select diamond to Continue.');
        return false;
    }
    if (countSelect > 1)
    {
        alert('Select only 1 diamond to Continue.');
        return false;
    }
    return true;
}

function fnUnCheckAllDiamond()
{
    for (i = 0; i < document.form1.elements.length; i++)
    {
        if (document.form1.elements.item(i).id.indexOf('c_compare') > -1)
        {
            if (document.form1.elements.item(i).checked)
            {
                document.form1.elements.item(i).checked = false;
            }
        }
    }
}

function fnVialidateSelected()
{
    var form1 = $get('form1');
    var flag = false;

    for (i = 0; i < form1.elements.length; i++)
    {
        if (form1.elements(i).id.indexOf('rbCompareSelect') > -1)
        {
            if (form1.elements(i).checked)
            {
                flag = true;
                break;
            }
        }
    }
    if (!flag)
    {
        alert('Select diamond to continue.');
        return false;
    }

    return true;
}
function TestProduct()
{
    alert("Yes ...done..");
}
//window.onerror = function supressErr() { return true;}
//</script>
//if (typeof ('Sys') != 'undefined')
//{
//    Sys.Application.notifyScriptLoaded();
//}

function showDiamondDiamensionDetails(varItem)
{
    //var varSelectedShape = $GetElementById('<%=hdnSelectedShapeForDtl.ClientID%>').value;
    var varSelectedShape = $GetElementById('hdnSelectedShapeForDtl').value;
    //alert(varSelectedShape);

    ManagePosition(varSelectedShape);

    if (varItem == 1)
    {
        $GetElementById("divDmDtl1").style.display = "block";
        $GetElementById("divDmDtl2").style.display = "none";
        $GetElementById("divDmDtl3").style.display = "none";
        $GetElementById("divDmDtl4").style.display = "none";
    }
    else if (varItem == 2)
    {
        $GetElementById("divDmDtl1").style.display = "none";
        $GetElementById("divDmDtl2").style.display = "block";
        $GetElementById("divDmDtl3").style.display = "none";
        $GetElementById("divDmDtl4").style.display = "none";
    }
    else if (varItem == 3)
    {
        $GetElementById("divDmDtl1").style.display = "none";
        $GetElementById("divDmDtl2").style.display = "none";
        $GetElementById("divDmDtl3").style.display = "block";
        $GetElementById("divDmDtl4").style.display = "none";
    }
    else if (varItem == 4)
    {
        $GetElementById("divDmDtl1").style.display = "none";
        $GetElementById("divDmDtl2").style.display = "none";
        $GetElementById("divDmDtl3").style.display = "none";
        $GetElementById("divDmDtl4").style.display = "block";
    }
    return false;
}

function ManagePosition(varSelectedShape)
{
    var divLength = $GetElementById("divDMLength");
    var divWidth = $GetElementById("divDMWidth");
    var divTable = $GetElementById("divDMTable");
    var divDepth = $GetElementById("divDMDepth");
    var divGirdle = $GetElementById("divDMGirdle");
    var divCulet = $GetElementById("divDMCulet");
    var divDepthPercent = $GetElementById("divDMDepthPercent");

    if (varSelectedShape == 'BR')
    {
        // alert(varSelectedShape);
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "136px";
        divWidth.style.left = "105px";

        divTable.style.top = "58px";
        divTable.style.left = "100px";
        divTable.style.backgroundColor = "#FFFFFF";
        
        divDepth.style.top = "136px";
        divDepth.style.left = "14px";

        //divGirdle.style.top = "209px";
        //divGirdle.style.left = "24px";
        divCulet.style.top = "217px";
        divCulet.style.left = "0px";
        divCulet.style.width = "105px";
        divGirdle.style.top = "217px";
        divGirdle.style.left = "167px";
        divGirdle.style.width = "100px";
        divDepthPercent.style.top = "136px";
        divDepthPercent.style.left = "203px";
    }
    else if (varSelectedShape == 'AS')
    {
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "136px";
        divWidth.style.left = "105px";

        divTable.style.top = "32px";
        divTable.style.left = "95px";
        divTable.style.backgroundColor = "#FFFFFF";

        divDepth.style.top = "120px";
        divDepth.style.left = "0px";
        divDepth.style.backgroundColor = "#FFFFFF";

        divCulet.style.top = "204px";
        divCulet.style.left = "0px";
        divCulet.style.width = "105px";
        divGirdle.style.top = "204px";
        divGirdle.style.left = "167px";
        divGirdle.style.width = "100px";
        divDepthPercent.style.top = "120px";
        divDepthPercent.style.left = "210px";
        divDepthPercent.style.backgroundColor = "#FFFFFF";
    }
    else if (varSelectedShape == 'CU')
    {
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "136px";
        divWidth.style.left = "105px";

        divTable.style.top = "48px";
        divTable.style.left = "95px";
        divTable.style.backgroundColor = "#FFFFFF";

        divDepth.style.top = "120px";
        divDepth.style.left = "6px";

        divCulet.style.top = "200px";
        divCulet.style.left = "0px";
        divCulet.style.width = "105px";
        divGirdle.style.top = "200px";
        divGirdle.style.left = "167px";
        divGirdle.style.width = "100px";
        divDepthPercent.style.top = "120px";
        divDepthPercent.style.left = "200px";
    }
    else if (varSelectedShape == 'HS')
    {
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "136px";
        divWidth.style.left = "105px";

        divTable.style.top = "70px";
        divTable.style.left = "95px";
        divTable.style.backgroundColor = "#FFFFFF";

        divDepth.style.top = "136px";
        divDepth.style.left = "18px";

        divCulet.style.top = "210px";
        divCulet.style.left = "0px";
        divCulet.style.width = "105px";
        divGirdle.style.top = "210px";
        divGirdle.style.left = "167px";
        divGirdle.style.width = "100px";
        divDepthPercent.style.top = "136px";
        divDepthPercent.style.left = "182px";
    }
    else if (varSelectedShape == 'RN')
    {
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "136px";
        divWidth.style.left = "105px";

        divTable.style.top = "48px";
        divTable.style.left = "95px";
        divTable.style.backgroundColor = "#FFFFFF";

        divDepth.style.top = "147px";
        divDepth.style.left = "6px";

        divCulet.style.top = "225px";
        divCulet.style.left = "0px";
        divCulet.style.width = "105px";
        divGirdle.style.top = "225px";
        divGirdle.style.left = "167px";
        divGirdle.style.width = "100px";
        divDepthPercent.style.top = "147px";
        divDepthPercent.style.left = "204px";
    }
    else if (varSelectedShape == 'PS')
    {
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "136px";
        divWidth.style.left = "105px";

        divTable.style.top = "45px";
        divTable.style.left = "95px";
        divTable.style.backgroundColor = "#FFFFFF";

        divDepth.style.top = "146px";
        divDepth.style.left = "18px";

        divCulet.style.top = "205px";
        divCulet.style.left = "0px";
        divCulet.style.width = "105px";
        divGirdle.style.top = "205px";
        divGirdle.style.left = "167px";
        divGirdle.style.width = "100px";
        divDepthPercent.style.top = "146px";
        divDepthPercent.style.left = "182px";
    }
    else if (varSelectedShape == 'EC')
    {
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "155px";
        divWidth.style.left = "90px";

        divTable.style.top = "70px";
        divTable.style.left = "90px";
        divTable.style.backgroundColor = "#FFFFFF";
        
        divDepth.style.top = "120px";
        divDepth.style.left = "4px";

        //divGirdle.style.top = "190px";
        //divGirdle.style.left = "24px";
        //divCulet.style.top = "190px";
        //divCulet.style.left = "167px";
        divCulet.style.top = "192px";
        divCulet.style.left = "0px";
        divCulet.style.width = "100px";
        divGirdle.style.top = "192px";
        divGirdle.style.left = "162px";
        divGirdle.style.width = "100px";
        divDepthPercent.style.top = "120px";
        divDepthPercent.style.left = "203px";
    }
    else if (varSelectedShape == 'PR')
    {
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "155px";
        divWidth.style.left = "90px";

        divTable.style.top = "59px";
        divTable.style.left = "95px";
        divTable.style.backgroundColor = "#FFFFFF";
        
        divDepth.style.top = "138px";
        divDepth.style.left = "4px";

        divCulet.style.top = "214px";
        divCulet.style.left = "0px";
        divCulet.style.width = "105px";
        divGirdle.style.top = "214px";
        divGirdle.style.left = "167px";
        divGirdle.style.width = "100px";
        divDepthPercent.style.top = "138px";
        divDepthPercent.style.left = "203px";
    }
    else if ((varSelectedShape == 'MQ'))
    {
        divLength.style.top = "95px";
        divLength.style.left = "130px";
        divWidth.style.top = "175px";
        divWidth.style.left = "102px";

        divTable.style.top = "18px";
        divTable.style.left = "97px";
        divDepth.style.top = "127px";
        divDepth.style.left = "20px";

        divGirdle.style.top = "208px";
        divGirdle.style.left = "167px";
        //divGirdle.style.textAlign = "right";

        divGirdle.style.width = "100px";
        divCulet.style.top = "208px";

        divCulet.style.left = "6px";
        divCulet.style.width = "100px";
        //divCulet.style.textAlign = "left";

        divDepthPercent.style.top = "127px";
        divDepthPercent.style.left = "182px";
    }
    else if (varSelectedShape == 'OV')
    {
        divLength.style.top = "115px";
        divLength.style.left = "140px";
        divWidth.style.top = "160px";
        divWidth.style.left = "95px";

        //divTable.style.top = "12px";
        divTable.style.top = "22px";
        divTable.style.left = "95px";
        divTable.style.backgroundColor = "#FFFFFF";
        divDepth.style.top = "100px";
        divDepth.style.left = "20px";

        divGirdle.style.top = "160px";
        divGirdle.style.left = "167px";
        divCulet.style.top = "160px";
        divCulet.style.left = "39px";

        divDepthPercent.style.top = "106px";
        divDepthPercent.style.left = "195px";
    }
}

// [SliderBar]
//#region
SliderBar = function(id)
{
    if (id)
    {
        try
        {
            var element = $GetElementById(id);

            if ((element.tagName.toUpperCase() == 'INPUT') && (element.type.toUpperCase() == 'TEXT'))
            {
                this.GetInstance = function() { return $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('txtCaratRange'),
        CLarity: new SliderBar('txtClarityRange'),
        Color: new SliderBar('txtColorRange'),
        Cut: new SliderBar('txtCutRange'),
        Price: new SliderBar('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
