	var xmlFeed = "interactiveControl_test.asp?"; // xml data feed link
	var sortObj=new Object(); // grid sorting state 
	sortObj.col=14;    		  // Price
	sortObj.dir='ASC'; 		  // ASC grid sorting by default
	var slHeight=135;         // Height of the slider
    var slRange = slHeight-6; // height correction
	var shadowoffset = 16;    // shadow offset for FF
	var tipTimeout = new Array(); // Array of tooltips
	var isIE;
	if (navigator.appName == "Microsoft Internet Explorer"){isIE = true;shadowoffset=0;}
	var sl = new Array();     // Array of all sliders
	
    var gmincarat,gmaxcarat, gmincut,gmaxcut, gmincolor,gmaxcolor, gminclarity,gmaxclarity, gminprice, gmaxprice;
    var gminpolish, gmaxpolish, gminsymmetry, gmaxsymmetry, gmindepth,gmaxdepth, gmintable,gmaxtable, gminratio, gmaxratio, gminfluorescence,gmaxfluorescence;
	
	var minCut = 1;
	var maxCut = 5;
	
	var minColor = 1;
	var maxColor = 10 //parseInt(strHighColor);
	
	var minClarity = 1;
	var maxClarity = 10 //parseInt(strHighClarity);
	
	var minPolish = 1;
	var maxPolish = 4;
	
	var minSymmetry = 1;
	var maxSymmetry = 4;
	
	var minFluorescence=1;
	var maxFluorescence=5;
	
    var mygrid; // Object for ajax datatable
    var resultsTimer = 0;

function getposOffset(what, offsettype)
{
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function showtip2(obj,tip)
{
	var tipNumber = parseInt( tip.replace('htip','') );		
	if ( tipTimeout[tipNumber]  == 0 )
	{
		showToolTip(obj,tip);
	}
	else
	{
		window.clearTimeout(tipTimeout[tipNumber] );
		showToolTip(obj,tip);				
	}	
}

function showToolTip(obj,tip)
{
	tipToShow = $(tip);
	visibility = tipToShow.style.visibility;
	if ( tipToShow && (visibility == 'hidden' || visibility == ''))
	{
		document.getElementById(tip).style.top = getposOffset(obj, "top")-30;
		document.getElementById(tip).style.left = getposOffset(obj, "left")-15;
		document.getElementById(tip).style.visibility = 'visible';
	}
}

function hidetip2(tip)
{
	var tipNumber = parseInt( tip.replace('htip','') );
	
	window.clearTimeout( tipTimeout[tipNumber] );
	tipTimeout[tipNumber]=window.setTimeout("hideTooltip("+tip+")", 100);					
}

function hideTooltip(tipToHide)
{
	tip = $(tipToHide);	
	if (tip) tip.style.visibility = 'hidden';
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
}


//-------------------oxi code for ajax----------------------------------------
isIE=document.all;
var isNN=!document.all&&document.getElementById;
var isN4=document.layers;
var isHot=false;
var requestcounter = 0;

var c_timeout=0,c_timeout2=0;
self.onerror = function() { return true; }

function htmlTest()
{
	var frm = document.frmPost;
	generateList(frm.mincarat.value, frm.maxcarat.value, frm.mincolor.value, frm.maxcolor.value, frm.mincut.value, frm.maxcut.value, frm.minclarity.value, frm.maxclarity.value, frm.minprice.value, frm.maxprice.value);
}


function changeShape()
{
	getresults();
}

function IE()
{
	return !!(window.attachEvent && !window.opera);
}

function adjustHolderWidth()
{
	var holder = (document.getElementsByClassName('holder'))[0];
    var holderWidth = holder.clientWidth; 	
	holder.style.width=(holderWidth+100)+'px';	
	var gridContainer = $('gridbox');
	var gridWidth = gridContainer.clientWidth;
	gridContainer.style.width=(gridWidth-9) +'px';	
}

function disableCheckboxes( disableSwitch )
{
	var checkboxes = document.getElementsByClassName('check');
	for ( var i=0; i<checkboxes.length; i++)
	{
		checkboxes[i].disabled = disableSwitch;		
	}
}
	
function bodyOnLoad()
{

	disableCheckboxes("disabled");
	if (!IE()) adjustHolderWidth();	
	//******* Cookie part Viktar ***************	
	if (minPrice <= 0)  minPrice = 260;
	var elem = $('backTraker');
	if (elem.value=='On') elem.value='';
	else
	{		
		RestoreFromCookies();
	}
	// Init basic sliders at page load
		
	var requestParams = new Array();
	var ctr = 0
	for(sh=0;sh<shapeArr.length;sh++)
	{
		if(shapeArr[sh].checked)
		{
			requestParams[ctr]='shape='+shapeArr[sh].value;
			ctr++;
		}
	}	
	// grid init
	mygrid = new dhtmlXGridObject('gridbox');	
	var gridWidth;		
	var compareStr='Compare&nbsp;,' ;
	var shapeStr='Shape&nbsp;<span class="spn"><img id=\"1img\" src=\"images/sliders/arrow_down.gif\"/></span>,' ;
	var caratStr='Carat&nbsp;<span class="spn"><img id=\"2img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var cutStr='Cut&nbsp;<span class="spn"><img id=\"3img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var colorStr='Color&nbsp;<span class="spn"><img id=\"4img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var clarityStr='Clarity&nbsp;<span class="spn"><img id=\"5img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var reportStr='Report&nbsp;<span class="spn"><img id=\"6img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var polishStr='Polish&nbsp;<span class="spn"><img id=\"7img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var symmetryStr='Symmetry&nbsp;<span class="spn"><img id=\"8img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var depthStr='Depth %&nbsp;<span class="spn"><img id=\"9img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var tableStr='Table %&nbsp;<span class="spn"><img id=\"10img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var fluorescenceStr='Fluorescence<span class="spn"><img id=\"11img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var ratioStr='L/W Ratio&nbsp;<span class="spn"><img id=\"12img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var culetStr='Culet&nbsp;<span class="spn"><img id=\"13img\" src=\"images/sliders/arrow_down.gif\"/></span>,';
	var priceStr='Price&nbsp;<span class="spn"><img id=\"14img\" src=\"images/sliders/arrow_up.gif\"/></span>,';
	var detailsStr='View Details';
	
	mygrid.setHeader(compareStr+shapeStr+caratStr+cutStr+colorStr+clarityStr+reportStr+polishStr+symmetryStr+depthStr+tableStr+fluorescenceStr+ratioStr+culetStr+priceStr+detailsStr);
	mygrid.setInitWidths("70,85,55,70,55,65,65,60,90,85,80,110,85,55,80,90");
	mygrid.setColAlign("center,left,center,center,center,center,center,center,center,center,center,center,center,center,center,center");
	mygrid.setColTypes("ch,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,img");
	mygrid.enableResizing("false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false");
	mygrid.imgURL = "dhtmlxGrid/codebase/imgs/";
	mygrid.setSkin("light");
	
	mygrid.setOnRowSelectHandler(function(id, index)
	{
		var gotoURL="/store/pc/viewPrd.asp?idProduct="+id + "&dd="+dreamdesign;
		if ( index != 6 && index != 0) window.location = gotoURL;
	});
	
	mygrid.attachEvent("onMouseOver",function(id){
		if (sav_callxml!='1')
		{
	     sav_callxml='1';
	     runXML1(id);
	    }
		return false;
	});
	
	//set onLoadingStart event handler
    mygrid.attachEvent("onXLS",function()
    {		
		makeCentered('populating');
        $('noresults').style.visibility ='hidden';		
		$('populating').style.visibility='visible';
		sav_callxml=''; hidetip();
	});
	
     // Called after loading is finished, updates header and centers noresults message
    mygrid.attachEvent("onXLE", function()
	{  // Update header
        var recordcount = this.getRowsNum();
        if (recordcount == 0)
		{
			makeCentered('noresults');
			$('noresults').style.visibility = 'visible';        
		}             
        if (recordcount > 1000) 
            recordcount = recordcount * 3;
        $('bookmark').innerHTML = recordcount;
        $('populating').style.visibility = 'hidden';
		mygrid.forEachRow(function(id)
		{
	       dhtmlxEvent(mygrid.rowsAr[id],"mouseout",function()
		   {   	   
			   sav_callxml=''; hidetip();
	        }) })
		sav_callxml=''; hidetip();
    });
	
	mygrid.init();
	getresults();
    mygrid.enableSmartRendering(true,null,20,20);
	mygrid.setAwaitedRowHeight(25);
    mygrid.enableRowsHover(true,"hoover");	
	setTimeout("restoreSlider();",1500);	
	setColumnsHidden(); // Hide non-standard columns
    //Save SortPosition
    mygrid.attachEvent("onScroll", function(x, y){
        Cookie.set('SortPosition', mygrid.objBox.scrollTop, 1);
    });
    attachHeaderEvents();		
	initShapes();		
    initCarat();
    initCut();
    initColor();
    initClarity();
    initPrice();	
	initRatio();	
    initAdditionalSliders() ;			
	if (!roundSelected() && !sl[1].restricted ) // Adjust CUT slider based on selected shape
	{						
		//window.setTimeout('lockCutSlider()',2000) ;						
	}
		
} //********************** end of body on load ********************************

/*
 * Centers message boxes inside the datagrid
 */
function makeCentered(elementId)
{
	var gridWidth = $('gridbox').style.width.replace('px','') ;
	var popWidth = $(elementId).style.width.replace('px','') ;		
	var offset = parseInt(gridWidth/2) - parseInt(popWidth/2);
	$(elementId).style.left = offset +'px';
}

function setColumnsHidden()
{
	for (var j = 7; j<14;j++)
	{
		if (j != 12) mygrid.setColumnHidden(j,"true");
	} 
}

function attachHeaderEvents()
{   // Sort columns when header is clicked
    mygrid.attachEvent("onHeaderClick",function(ind){
    if (ind != undefined || ind !=0 || ind !=15) sortIt(ind);
    return true;
    });

    mygrid.setOnRowSelectHandler(function(id,ind)
    {
    if (ind == 6){ return; }  // Don't open details page when GIA link is clicked
    });

    var allNodes = document.getElementsByClassName("hdrcell");	    
	allNodes[0].parentNode.onmouseover=function(){showtip2(this,'htip0') };
    allNodes[0].parentNode.onmouseout=function(){hidetip2('htip0');};
	
	allNodes[1].parentNode.onmouseover=function(){showtip2(this,'htip1') };
    allNodes[1].parentNode.onmouseout=function(){hidetip2('htip1');};
	
    allNodes[2].parentNode.onmouseover=function(){showtip2(this,'htip2') };
    allNodes[2].parentNode.onmouseout=function(){hidetip2('htip2')};
	
    allNodes[3].parentNode.onmouseover=function(){showtip2(this,'htip3'); };
    allNodes[3].parentNode.onmouseout=function(){hidetip2('htip3') };
	
	allNodes[4].parentNode.onmouseover=function(){showtip2(this,'htip4'); };
    allNodes[4].parentNode.onmouseout=function(){hidetip2('htip4') };
	
	allNodes[5].parentNode.onmouseover=function(){showtip2(this,'htip5'); };
    allNodes[5].parentNode.onmouseout=function(){ hidetip2('htip5'); };
	
	allNodes[6].parentNode.onmouseover=function(){showtip2(this,'htip6'); };
    allNodes[6].parentNode.onmouseout=function(){ hidetip2('htip6'); };
	
	allNodes[7].parentNode.onmouseover=function(){showtip2(this,'htip7'); };
    allNodes[7].parentNode.onmouseout=function(){ hidetip2('htip7'); };
	
	allNodes[8].parentNode.onmouseover=function(){showtip2(this,'htip8'); };
    allNodes[8].parentNode.onmouseout=function(){hidetip2('htip8');};

	allNodes[9].parentNode.onmouseover=function(){showtip2(this,'htip9'); };
    allNodes[9].parentNode.onmouseout=function(){hidetip2('htip9'); };
	
	allNodes[10].parentNode.onmouseover=function(){showtip2(this,'htip10'); };
    allNodes[10].parentNode.onmouseout=function(){ hidetip2('htip10') ;};
	
	allNodes[11].parentNode.onmouseover=function(){showtip2(this,'htip11'); };
    allNodes[11].parentNode.onmouseout=function(){hidetip2('htip11')};
	
	allNodes[12].parentNode.onmouseover=function(){showtip2(this,'htip12'); };
    allNodes[12].parentNode.onmouseout=function(){hidetip2('htip12') ;};
	
	allNodes[13].parentNode.onmouseover=function(){showtip2(this,'htip13'); };
    allNodes[13].parentNode.onmouseout=function(){ hidetip2('htip13');};

}

function restoreSlider()
{
	var chk ; // 'Fake' checkbox object passed to hideCol function
	var col = sortObj.col;
	var dir = sortObj.dir;
	var prevImg= col + 'img';
	$(prevImg).setAttribute('src','images/sliders/arrow_down.gif');			
	if (dir.toLowerCase() == "asc" ) $(col+'img').setAttribute('src','images/sliders/arrow_up.gif');
		else $(col+'img').setAttribute('src','images/sliders/arrow_down.gif');
	var chks = document.getElementsByClassName("checkbox");
	for (i=0;i<chks.length;i++)
	{		
		if (chks[i].checked)
			hideCol(chks[i]);
	}
	// Hide/Show L/W Ratio slider    
    if (onlyRoundSelected()) 
	{
        chk = new Object();
        chk.checked = false;
        chk.value = '12';
        hideCol(chk);
		gminratio = strLowLWRatio = minRatio;
		gmaxratio = strHighLWRatio = maxRatio;		
    }
    else {
        var ratioIsHidden = ($('ratio').style.display == 'none');
        if (ratioIsHidden) {
            chk = new Object();
            //chk.checked = true; // set to true to make it visible by L/W ratio by default
            chk.checked = false;
            chk.value = '12';
            hideCol(chk);
        }
    }
	mygrid.objBox.scrollTop = Cookie.get('SortPosition');	
	disableCheckboxes(false);							  	    	
}
	
function RestoreFromCookies()
{
	if (Cookie.get('dmincarat') != undefined) 
		gmincarat = lowcarats = Cookie.get('dmincarat');
	if (Cookie.get('dmaxcarat') != undefined) 
		gmaxcarat = highcarats = Cookie.get('dmaxcarat');
	if (Cookie.get('dmincut') != undefined) 
		strLowCut = Cookie.get('dmincut');
	if (Cookie.get('dmaxcut') != undefined) 
		strHighCut = Cookie.get('dmaxcut');
	
	if (Cookie.get('dmaxcolor') != undefined) 
		gmaxcolor = strHighColor = Cookie.get('dmaxcolor');
	if (Cookie.get('dmincolor') != undefined) 
		gmincolor = strLowColor = Cookie.get('dmincolor');
	
	if (Cookie.get('dmaxclarity') != undefined) 
		gmaxclarity = strHighClarity = Cookie.get('dmaxclarity');
	if (Cookie.get('dminclarity') != undefined) 
		gminclarity = strLowClarity = Cookie.get('dminclarity');
	
	if (Cookie.get('dminprice') != undefined) 
		gminprice = lowprice = Cookie.get('dminprice');
	if (Cookie.get('dmaxprice') != undefined) 
		gmaxprice = highprice = Cookie.get('dmaxprice');
	
	if (Cookie.get('dminpolish') != undefined) 
		gminpolish = strLowPolish = Cookie.get('dminpolish');
	if (Cookie.get('dmaxpolish') != undefined) 
		gmaxpolish = strHighPolish = Cookie.get('dmaxpolish');
	if (Cookie.get('dminsymmetry') != undefined) 
		gminsymmetry = strLowSymmetry = Cookie.get('dminsymmetry');
	if (Cookie.get('dmaxsymmetry') != undefined) 
		gmaxsymmetry = strHighSymmetry = Cookie.get('dmaxsymmetry');
		
	if (Cookie.get('dmindepth') != undefined) 
	{
		strLowDepth = Cookie.get('dmindepth');
		if ( strLowDepth == '' || isNaN(strLowDepth) ) gmindepth = strLowDepth = minDepth;
		if ( parseFloat(strLowDepth) <= parseFloat(minDepth) || parseFloat(strLowDepth) > parseFloat(maxDepth) ) gmindepth = strLowDepth = minDepth;
	}			  
	if (Cookie.get('dmaxdepth')!=undefined)
	{
		strHighDepth = Cookie.get('dmaxdepth');
		if ( strHighDepth == '' || isNaN(strHighDepth) ) gmaxdepth=strHighDepth = maxDepth;
		if ( parseFloat(strHighDepth) < parseFloat(minDepth) || parseFloat(strHighDepth) > parseFloat(maxDepth) ) gmaxdepth=strHighDepth = maxDepth;		
	}		  
		  		  
	if (Cookie.get('dmintable')!=undefined)
	{
		strLowTable = Cookie.get('dmintable');
		if ( strLowTable == '' || isNaN(strLowTable) ) gmintable=strLowTable=minTable;
		if ( parseFloat(strLowTable) <= parseFloat(minTable) || parseFloat(strLowTable) > parseFloat(maxTable) ) gmintable=strLowTable=minTable;				
	}		  
	if (Cookie.get('dmaxtable')!=undefined)
	{
		strHighTable = Cookie.get('dmaxtable');
		if ( strHighTable == '' || isNaN(strHighTable) ) gmaxtable=strHighTable=maxTable;
		if ( parseFloat(strHighTable) < parseFloat(minTable) || parseFloat(strHighTable) >= parseFloat(maxTable) ) gmaxtable=strHighTable=maxTable;				
	}
			  
	if (Cookie.get('dminfluorescence')!=undefined)
		  gminfluorescence=strLowFluorescence = Cookie.get('dminfluorescence');			  
	if (Cookie.get('dmaxfluorescence')!=undefined)
		  gmaxfluorescence=strHighFluorescence = Cookie.get('dmaxfluorescence');	
		  
	if (Cookie.get('dminratio')!=undefined)
	{
		strLowLWRatio = Cookie.get('dminratio');
		if (strLowLWRatio == '' || isNaN(strLowLWRatio) ) strLowLWRatio=gminratio=minRatio;
		if ( parseFloat(strLowLWRatio) <= parseFloat(minRatio) || parseFloat(strLowLWRatio) > parseFloat(maxRatio)) gminratio=strLowLWRatio=minRatio;
	}		  			  
	if (Cookie.get('dmaxratio')!=undefined || isNaN)
	{
		strtHighLWRatio = Cookie.get('dmaxratio');
		if ( strtHighLWRatio == '') gmaxratio=strtHighLWRatio=maxRatio;
		if ( parseFloat(strtHighLWRatio) >= parseFloat(maxRatio) || parseFloat(strtHighLWRatio) < parseFloat(minRatio) ) gmaxratio=strtHighLWRatio=maxRatio;				
	}				
	if (Cookie.get('SortOrder')!=undefined) sortObj.col =  parseInt(Cookie.get('SortOrder'));	
	if (Cookie.get('SortDirection')!=undefined) sortObj.dir = Cookie.get('SortDirection');	
	restoreShapes(); //"hidden col" error when grid is not yet initialized	
			
}

function restoreShapes()
{
	var enabledShapes=Cookie.get('enabledShapes') ;	
	if (enabledShapes != undefined && enabledShapes !='')
	{
		var enabledArray = enabledShapes.split(',');
		for (var i=0;i<enabledArray.length;i++)
		{
			//addShape( parseInt(enabledArray[i]) );
			var	shp = parseInt(enabledArray[i]);
			var image = $(shapeArr[shp].imgId);
			shapeArr[shp].checked=true;
			changeShapeImage(image,true);						
		}			
	}	
}

function initShapes()
{
	// Hide shapes that are not compatible with custom setting
	if ( dreamdesign != '' && dreamdesign != undefined )
	{
		if (diamondShapeFilter != '' && diamondShapeFilter != undefined )
		{
			var shapesToDisplay = diamondShapeFilter.split("||");
			for (var i=0; i<10; i++)
			{
				if (shapesToDisplay.indexOf(i+1) == -1 ) $('shape'+i).style.display="none";
			}			
		}					
	}	
	if ( strShape != '' && strShape != undefined && strShape != '-1') 
	{
		var shapesFromQuery = strShape.split(',');
		for(var i=0; i<shapesFromQuery.length; i++ )
		{
			var shId = (shapesFromQuery[i]).replace(' ','');
			shId = parseInt(shId)-1;  // In database shapes are 1-based. On a page shapeArr is zero-based !!!!
			var image = $(shapeArr[shId].imgId);
			shapeArr[shId].checked=true;
			changeShapeImage(image,true);					
		} 		
	}
}

// Display additional sliders based on passed parameters

function initAdditionalSliders()
{
	if ( strSlider != '' && strSlider != undefined && strSlider != '-1') 
	{
		var slidersFromQuery = strSlider.split(',');
		for(var i=0; i<slidersFromQuery.length; i++ )
		{
			var slId = (slidersFromQuery[i]).replace(' ','');
			slId = parseInt(slId);  
			if (slId >= 7 && slId <= 11)
			{
				var checkBox = $('chk'+ slId );				
				checkBox.checked = true;
				//hideCol(checkBox);
			}			
		} 		
	}
}

/********** Sliders functions ******************/

	/* Variables to fix a bug with programmatic slider movement SetMin */
	var cmin=0; // Pixel offsets from top for carat
	var cmax=slHeight;
	var rmin=0; // Pixel offsets from top for ratio
	var rmax=slHeight;
	var pmin=0; // Pixel offset from top for price
	var pmax=slHeight; 
	var dmin=0;
	var dmax=slHeight;
	var tmin=0;
	var tmax=slHeight;

function setShadow(topId, bottomId, min,max)
{	
	YAHOO.util.Dom.setStyle($(topId),'height', min + 'px');
	YAHOO.util.Dom.setStyle($(bottomId),'height',  (slHeight-max) + 'px');
	YAHOO.util.Dom.setStyle($(bottomId),'top', (max-min+shadowoffset+ieshadowoffset(min)) + 'px');
}

function setShadow2(topId, bottomId, min,max)
{
	YAHOO.util.Dom.setStyle($(topId),'height', min + 'px');
	YAHOO.util.Dom.setStyle($(bottomId),'height',  (slHeight-max) + 'px');
	YAHOO.util.Dom.setStyle($(bottomId),'top', (max + 16) + 'px');
}

    function bottomYchange()
    {
		var offset;
        var bottomY = $('txtCaratMin');
		var caratVal = $F('txtCaratMin');
		if ( caratVal.length > 0 && !isNaN(caratVal) )
		{
			if ( parseFloat(caratVal) < parseFloat(gmaxcarat)) // Check if lower slider is smaller than upper
			{
				offset=slHeight-caratToOffset(caratVal);
				(sl[0]).setMaxValue(offset, true,true, true); 
				gmincarat=caratVal;
				cmax=offset;
			}
			else 
			{
				offset=slHeight-caratToOffset(gmaxcarat);
				(sl[0]).setMaxValue(offset, true,true,true); 
				gmincarat=gmaxcarat;
				cmax=offset;
			}			
			setShadow2('top_darkCarat','bottom_darkCarat',cmin,cmax);
			getresults();			
		}
	  	else 
		{
			sl[0].setMaxValue(slHeight, true, true, true); 
			gmincarat = minCarat;
			cmax=slHeight;			
			setShadow2('top_darkCarat','bottom_darkCarat',cmin, cmax);
		}		
    }
    
    function topYchange()
    { 
	  var offset;  
	  var topY=$('txtCaratMax') ;
	  var caratVal=$F('txtCaratMax');
	  if (caratVal.length > 0 && !isNaN(caratVal)) 
	  {
	  	if (parseFloat(caratVal) >= parseFloat(gmincarat)) 
		{	  		
			offset = slRange - caratToOffset(caratVal);
	  		sl[0].setMinValue(offset, true, true, true);
	  		gmaxcarat = caratVal;
	  		cmin = offset;
	  	}
	  	else 
		{
			offset = slRange - caratToOffset(gmincarat);
	  		sl[0].setMinValue(offset, true, true, true);
	  		gmaxcarat = gmincarat;
	  		cmin = offset;
	  	}
		setShadow2('top_darkCarat','bottom_darkCarat',cmin, cmax);		
	  	getresults();
	  }
	  else 
	  {
	  	offset = 0;
	  	sl[0].setMinValue(offset, true,true, true);
		cmin=offset;
		setShadow2('top_darkCarat','bottom_darkCarat',cmin, cmax);		
	  }
    }
	
	function caratMinBlur()
	{
		txtMin=$('txtCaratMin');
		minValue=parseFloat(txtMin.value);
		maxValue=parseFloat( $F('txtCaratMax') );
		if ($F('txtCaratMin').length == 0 || isNaN(txtMin.value)) 
		{
			gmincarat = txtMin.value = minCarat;
			getresults();
			return;
		}
		else 
		{
			if (minValue > maxValue) 
			{   
				gmincarat=txtMin.value = maxValue.toFixed(2);
				getresults();		
			}
			else 
			{
				if ( minValue > minCarat ) gmincarat=txtMin.value=minValue.toFixed(2);
					else gmincarat=txtMin.value=minCarat.toFixed(2);							
			}
			
		}		
		
	}
	
	function caratMaxBlur()
	{
		txtMax=$('txtCaratMax');
		maxValue=parseFloat(txtMax.value); 
		minValue=parseFloat($F('txtCaratMin')); 		
		
		if ($F('txtCaratMax').length == 0 || isNaN(txtMax.value)) {
			gmaxcarat=txtMax.value = maxCarat;
			return;
		}
		else
		{
			if (maxValue < minValue ) gmaxcarat=txtMax.value = minValue.toFixed(2);
			else 
			{
				if (maxValue > maxCarat ) gmaxcarat=txtMax.value=maxCarat.toFixed(2);
					else gmaxcarat=txtMax.value=maxValue.toFixed(2);
			}			
			getresults();			
		}				
	}

	function setCarat()
	{
		if (lowcarats != minCarat && highcarats != maxCarat)
		  sl[0].setValues(slRange-caratToOffset(highcarats),slHeight-caratToOffset(lowcarats),true,false,false);
	    else
	  	  if (lowcarats != minCarat)		  	
			sl[0].setMaxValue(slHeight-caratToOffset(lowcarats),true,true,false);
		  else
		    if (highcarats != maxCarat)
				sl[0].setMinValue(slRange-caratToOffset(highcarats),true,true,false);
		$('txtCaratMax').value=gmaxcarat = highcarats;
	    $('txtCaratMin').value=gmincarat = lowcarats;		
	}

   function initCarat()
   {
      if ( lowcarats == minCarat && highcarats == maxCarat) setTimeout("animate('sliderCaratTop','sliderCaratBottom');",100);
      sl[0]= YAHOO.widget.Slider.getVertDualSlider("sliderCarat","sliderCaratTop","sliderCaratBottom",slHeight,1,[0,slHeight] );	  
	  sl[0].minRange=-80;
	  sl[0].minSlider.animate = false ;
	  sl[0].maxSlider.animate = false ;	  	  
      sl[0].subscribe("change", function (offsetFromStart) 
	  {        
		var caratMax = $('txtCaratMax');
        var caratMin = $('txtCaratMin');
		cmin = this.minVal;
		cmax = this.maxVal;
		if (this.activeSlider == this.minSlider) 
		{
			maxcarat = offsetToCarat(slRange - this.minVal);
			if ( parseFloat(maxcarat) < parseFloat(gmincarat) ) gmaxcarat = caratMax.value = gmincarat;
				else gmaxcarat = caratMax.value = maxcarat;
		}
		else
		{
			gmincarat = caratMin.value = offsetToCarat(slHeight - this.maxVal);			
		} 
		YAHOO.util.Dom.setStyle($('top_darkCarat'),'height', this.minVal + 'px');
		YAHOO.util.Dom.setStyle($('bottom_darkCarat'),'height',  (slHeight-this.maxVal) + 'px');
		//var topValue = (this.maxVal-(this.minVal)+shadowoffset+ieshadowoffset(this.minVal)) ;
		var topValue = this.maxVal + 16; // temp fix
		YAHOO.util.Dom.setStyle($('bottom_darkCarat'),'top',  topValue + 'px');
		getresults();
	});
	sl[0].subscribe("ready", function (){ setCarat() });
	//window.setTimeout('setCarat()',50);		
   }

   function offsetToCarat(offset)
   {
        var caratRange = maxCarat - minCarat ;
	    var range1 = 0.85; // percent  of the slider height
	    var range2 = 0.95;
	    var range3 = 1; 
	
	    var offset0 = 0 ;
	    var offset1 = parseInt(slRange * range1);
	    var offset2 = parseInt(slRange * range2);
	    var offset3 = slRange  ;
	
	    var carat0 = minCarat ;
	    var carat1 = carat0 + caratRange * (0.4 );
	    var carat2 = carat1 + caratRange * (0.6 ) ;
	    var carat3 = maxCarat ;
	
	    var step1 = (carat1 - carat0) / (offset1 - offset0) ;
	    var step2 = (carat2 - carat1) / (offset2 - offset1) ;
	    var step3 = (carat3 - carat2) / (offset3 - offset2) ;
	
	    if (offset <= 0) return minCarat;
	    if (offset >= slRange) return maxCarat;
	    if (offset <= offset1) return (minCarat + offset * step1).toFixed(2); //    range 1
	    if (offset <= offset2) return (carat1 + (offset - offset1) * step2).toFixed(2);
	    if (offset <= offset3) return (carat2 + (offset - offset2) * step3).toFixed(2);	
   }
   
   function caratToOffset(carat)
   {
   		var caratRange = maxCarat - minCarat ;
		var range1 = 0.85;  // length as a percent  of the slider height
		var range2 = 0.95;
		var range3 = 1;
		  
		var offset0 = 0 ;
		var offset1 = parseInt(slRange * range1 );
		var offset2 = parseInt(slRange * range2 );	  
		var offset3 = slRange  ;
		
		var carat0 = minCarat ;
		var carat1 = carat0 + caratRange * (0.4 );
		var carat2 = carat0 + caratRange * (0.6 ) ;
		var carat3 = maxCarat ;
		  
		var step1 = (carat1 - carat0)/(offset1 - offset0) ;
		var step2 = (carat2 - carat1)/(offset2 - offset1) ;
		var step3 = (carat3 - carat2)/(offset3 - offset2) ;
		  
		if (isNaN(carat)) return;
		if ( carat  <= carat0 )  return 0;
		if ( carat >= carat3 )  return slRange;
		if ( carat <= carat1 )  return ( Math.round( (carat - carat0) / step1 ) ) ;
		if ( carat <= carat2 )  return ( Math.round(offset1 + (carat - carat1) / step2 ) ) ;
		if ( carat <= carat3 )  return ( Math.round(offset2 + (carat-carat2) / step3 ) );
   }

   function initCut()
   {
       if (parseInt(strLowCut) == minCut && parseInt(strHighCut) == maxCut) 
           setTimeout("animate('sliderCutTop','sliderCutBottom');", 100);
       var stepCut = Math.floor(slHeight / 5);
       sl[1] = YAHOO.widget.Slider.getVertDualSlider("sliderCut", "sliderCutTop", "sliderCutBottom", slHeight, stepCut, [0, slHeight]);
       if (parseInt(strLowCut) != minCut && parseInt(strHighCut) != maxCut) 
           sl[1].setValues((strLowCut - 1) * stepCut, strHighCut * stepCut, false, false, false);
       else 
           if (parseInt(strLowCut) != minCut) 
               sl[1].setMinValue((strLowCut - 1) * stepCut, false, false, false);
           else 
               if (parseInt(strHighCut) != maxCut) 
                   sl[1].setMaxValue(strHighCut * stepCut, false, false, false);
       sl[1].minRange = -65;
       
       sl[1].subscribe("change", function(offsetFromStart){
           gmaxcut = Math.round(this.maxVal / stepCut);
           gmincut = Math.round(this.minVal / stepCut) + 1;
           YAHOO.util.Dom.setStyle($('top_darkCut'), 'height', this.minVal + 'px');
           YAHOO.util.Dom.setStyle($('bottom_darkCut'), 'height', (slHeight - this.maxVal) + 'px');
           YAHOO.util.Dom.setStyle($('bottom_darkCut'), 'top', (this.maxVal - this.minVal + shadowoffset + ieshadowoffset(this.minVal)) + 'px');
           getresults();
       });       
   }

function setColor()
{
    var stepColor = Math.ceil(slHeight / 8);
    if (parseInt(strLowColor) != minColor && parseInt(strHighColor) != maxColor) 
        sl[2].setValues((strLowColor - 1) * stepColor, strHighColor * stepColor, false, true, false);
    else 
        if (parseInt(strLowColor) != minColor) 
            sl[2].setMinValue((strLowColor - 1) * stepColor, false, true, false);
        else 
            if (parseInt(strHighColor) != maxColor) 
                sl[2].setMaxValue(strHighColor * stepColor, false, true, false);
}

   function initColor()
   {
   	   //trace( "strLowColor=" +strLowColor + ", minColor= " + minColor);
	   //trace( "strHighColor" +strHighColor + ", maxColor= " + maxColor);
       if (parseInt(strLowColor) == minColor && parseInt(strHighColor) == maxColor) setTimeout("animate('sliderColorTop','sliderColorBottom' );", 100);
       var stepColor = Math.ceil(slHeight / 8);
	   var offset;
       sl[2] = YAHOO.widget.Slider.getVertDualSlider("sliderColor", "sliderColorTop", "sliderColorBottom", slHeight + 1, stepColor, [0,slHeight]);	   
       sl[2].minRange = -75;       
       sl[2].subscribe("change", function(offsetFromStart){
           YAHOO.util.Dom.setStyle($('top_darkColor'), 'height', this.minVal + 'px');
           YAHOO.util.Dom.setStyle($('bottom_darkColor'), 'height', (slHeight + 1 - this.maxVal) + 'px');
           YAHOO.util.Dom.setStyle($('bottom_darkColor'), 'top', (this.maxVal - this.minVal + shadowoffset + ieshadowoffset(this.minVal)) + 'px');
           gmaxcolor = Math.round(this.maxVal / stepColor);
           gmincolor = Math.round(this.minVal / stepColor) + 1;
           //trace(gmincolor + '  ' + gmaxcolor);
           getresults();
       });
	   window.setTimeout('setColor()', 50);       
   }
   
   function setClarity()
   {
   	var stepClarity = Math.ceil(slHeight / 8);
   	if (parseInt(strLowClarity) != minClarity && parseInt(strHighClarity) != maxClarity)
	   {
	   	var minOffset = (strLowClarity - 1) * stepClarity;
		var maxOffset = strHighClarity * stepClarity - 1;
	   	sl[3].setValues(minOffset, maxOffset, false, false, false);	   			   	
	   }            
       else 
           if (parseInt(strLowClarity) != minClarity) 
               sl[3].setMinValue((strLowClarity - 1) * stepClarity, false, false, false);
           else 
               if (parseInt(strHighClarity) != maxClarity) 
                   sl[3].setMaxValue(parseInt(strHighClarity) * stepClarity - 1, false, false, false);   		
   }

   function initClarity()
   {   		
       if (parseInt(strLowClarity) == minClarity && parseInt(strHighClarity) == maxClarity) setTimeout("animate('sliderClarityTop','sliderClarityBottom');", 150);
       var stepClarity = Math.ceil(slHeight / 8);
       sl[3] = YAHOO.widget.Slider.getVertDualSlider("sliderClarity", "sliderClarityTop", "sliderClarityBottom", slHeight + 1, stepClarity, [0, slHeight]);       	   
       sl[3].minRange = -75;	
       sl[3].subscribe("change", function(offsetFromStart){
           YAHOO.util.Dom.setStyle($('top_darkClarity'), 'height', this.minVal + 'px');
           YAHOO.util.Dom.setStyle($('bottom_darkClarity'), 'height', (slHeight + 1 - this.maxVal) + 'px');
           YAHOO.util.Dom.setStyle($('bottom_darkClarity'), 'top', (this.maxVal - this.minVal + shadowoffset + ieshadowoffset(this.minVal)) + 'px');
           gmaxclarity = Math.round(this.maxVal / stepClarity);
           gminclarity = Math.round(this.minVal / stepClarity) + 1;
           getresults();
       });       
      window.setTimeout('setClarity()',50); 
   }

function setPrice()
{
	if ( parseInt(lowprice) != minPrice && parseInt(highprice) != maxPrice)
		  sl[10].setValues(slRange-priceToOffset(parseInt(highprice)),slHeight-priceToOffset(parseInt(lowprice)),true,true,false);
		  else
			  if (parseInt(lowprice) != minPrice)
		  		sl[10].setMaxValue(slHeight-priceToOffset(parseInt(lowprice)),true,true,false);
			  else
			  if (parseInt(highprice) != maxPrice)
			  	  sl[10].setMinValue(slRange-priceToOffset(parseInt(highprice)),true,true,false);	
	$('txtPriceMax').value=formatCurrency(highprice);
	$('txtPriceMin').value=formatCurrency(lowprice);
	gmaxprice = highprice ;
	gminprice = lowprice ;
}

   function initPrice()
   {   		
	   	if ( parseInt(lowprice) == minPrice && parseInt(highprice) == maxPrice) setTimeout("animate('sliderPriceTop','sliderPriceBottom');",100);
	    sl[10]= YAHOO.widget.Slider.getVertDualSlider("sliderPrice", "sliderPriceTop","sliderPriceBottom", slHeight, 1, [0,slHeight] );					  
		sl[10].minRange=-80;
		sl[10].minSlider.animate = false ;
	    sl[10].maxSlider.animate = false ;
		$("txtPriceMax").value=formatCurrency(highprice);
		$("txtPriceMin").value=formatCurrency(lowprice);
 	   	sl[10].subscribe("change", function ()
		{
			var maxprice ;
			var minprice ;
			pmin = this.minVal;
			pmax = this.maxVal;
			setShadow2('top_darkPrice','bottom_darkPrice', pmin, pmax );		
			if (this.activeSlider == this.minSlider) 
			{
				maxprice=offsetToPrice(slRange-this.minVal) ;
				if ( parseInt(maxprice) < parseInt(gminprice) ) gmaxprice = gminprice
					else gmaxprice = maxprice;
				$('txtPriceMax').value=formatCurrency(gmaxprice);								
			}
			else
			{
				gminprice = minprice=offsetToPrice(slHeight-this.maxVal);	
				$('txtPriceMin').value=formatCurrency(gminprice);				
			}		
		getresults();
		});
		sl[10].subscribe("ready", function (){ setPrice();  });
		//window.setTimeout('setPrice()',50);			      
   }
   
	function priceToOffset( price )
	{
		var priceRange = maxPrice - minPrice ;
		var range1 = 0.85; // length as a percent  of the slider height
		var range2 = 0.95;
		var range3 = 1;
		  
		var offset0 = 0 ;
		var offset1 = parseInt(129 * range1 );
		var offset2 = parseInt(129 * range2 );	  
		var offset3 = slRange  ;
		
		var price0 = minPrice ;
		var price1 = price0 + priceRange * (0.08 );
		var price2 = price0 + priceRange * (0.6 ) ;
		var price3 = maxPrice ;
		  
		var step1 = (price1 - price0)/(offset1 - offset0) ;
		var step2 = (price2 - price1)/(offset2 - offset1) ;
		var step3 = (price3 - price2)/(offset3 - offset2) ;
		  
		if (isNaN(price)) return;
		if ( price  <= price0 )  return 0;
		if ( price >= price3 )  return slRange;
		if ( price <= price1 )  return ( Math.round( (price - minPrice) / step1 ) ) ;
		if ( price <= price2 )  return ( Math.round(offset1 + (price - price1) / step2 ) ) ;
		if ( price <= price3 )  return ( Math.round(offset2 + (price-price2) / step3 ) );
	}
	
	function offsetToPrice(offset)
	{
	    var priceRange = maxPrice - minPrice ;
	    var range1 = 0.85; // percent  of the slider height
	    var range2 = 0.95;
	    var range3 = 1;
	
	    var offset0 = 0 ;
	    var offset1 = parseInt(129 * range1);
	    var offset2 = parseInt(129 * range2);
	    var offset3 = slRange  ;
	
	    var price0 = minPrice ;
	    var price1 = price0 + priceRange * (0.08 );
	    var price2 = price0 + priceRange * (0.6 ) ;
	    var price3 = maxPrice ;
	
	    var step1 = (price1 - price0) / (offset1 - offset0) ;
	    var step2 = (price2 - price1) / (offset2 - offset1) ;
	    var step3 = (price3 - price2) / (offset3 - offset2) ;
	
	    if (offset <= 0) return minPrice;
	    if (offset >= slRange) return maxPrice;
	    if (offset <= offset1) return Math.round(minPrice + offset * step1); //   price range 1
	    if (offset <= offset2) return Math.round(price1 + (offset - offset1) * step2);
	    if (offset <= offset3) return Math.round(price2 + (offset - offset2) * step3);	
	}
		   
   function priceKeyUpMax()
	{
	  var topY=$('txtPriceMax') ;
	  var priceIn=$F('txtPriceMax').replace(/\$|\,|\-/g,'');
	  var txtPrice=$F('txtPriceMin').replace(/\$|\,|\-/g,'');
	  var offset ;
	  if (priceIn.length >= 3 && !isNaN(priceIn)) 
	  {
		  	if (parseInt(priceIn) >= parseInt(txtPrice)) 
			{
		  		offset = Math.round(slRange - priceToOffset(priceIn));
		  		sl[10].setMinValue(offset, true, true, true);
				gmaxprice = priceIn;
		  	}
		  	else 
			{
				offset = Math.round(slRange - priceToOffset(gminprice));
		  		sl[10].setMinValue(offset, true, true, true);
				gmaxprice = gminprice;
		  		//gmaxprice=topY.value=txtPrice;  
			}			
			pmin = offset;
			setShadow2('top_darkPrice', 'bottom_darkPrice', pmin, pmax);
			getresults();
		}
		else 
		{
			pmin=0;
			sl[10].setMinValue(0, true,true, true);
			setShadow2('top_darkPrice', 'bottom_darkPrice', pmin, pmax);
		}
	}

	function priceKeyUpMin()
	{
	  var topY=$('txtPriceMin') ;
	  var priceIn=$F('txtPriceMin').replace(/\$|\,|\-/g,'');
	  var curMaxPrice=$F('txtPriceMax').replace(/\$|\,|\-/g,'');
	  var offset ;
	  if (priceIn.length >= 3 && !isNaN(priceIn)) 
	  {
	  	if (parseInt(priceIn) <= parseInt(gmaxprice)) 
		{
	  		offset = slHeight - priceToOffset(priceIn);
	  		sl[10].setMaxValue(offset, true, true, true);
			gminprice = priceIn;
	  	}
	  	else 
		{
	  		offset = slHeight - priceToOffset(gmaxprice);
	  		sl[10].setMaxValue(offset, true, true, true);
			gminprice = gmaxprice;
	  	}
	  	
	  	pmax = offset;
	  	setShadow2('top_darkPrice', 'bottom_darkPrice', pmin, pmax);
	  	getresults();
	  }
	  else 
	  {
	  	pmax = slHeight;
	  	sl[10].setMaxValue(slHeight,true,true,true);
		setShadow2('top_darkPrice', 'bottom_darkPrice', pmin, pmax);
	  }
	}
	
	function priceMaxBlur()
	{
		var topTxt = $('txtPriceMax');
		var topTxtValue = parseInt($F('txtPriceMax').replace(/\$|\,|\-/g,''));
		var bottomTxtValue = parseInt($F('txtPriceMin').replace(/\$|\,|\-/g,''));
		if ( topTxtValue.length == 0 || isNaN(topTxtValue) )
		{
			topTxt.value = formatCurrency(maxPrice);
			gmaxprice = maxPrice;
		}
		else
		{
			if (parseInt(topTxt.value) < bottomTxtValue ) 
			{
				topTxt.value = formatCurrency(bottomTxtValue);
				gmaxprice=gminprice;
				getresults();
			}
			else topTxt.value=formatCurrency(topTxt.value);				
		}			
	}
	
	function priceMinBlur()
	{
		var bottomTxt = $('txtPriceMin');
		var bottomTxtValue=parseInt($F('txtPriceMin').replace(/\$|\,|\-/g,''));
		var topTxtValue = parseInt($F('txtPriceMax').replace(/\$|\,|\-/g,''));
		if ( bottomTxtValue.length < 3 || isNaN(bottomTxtValue) )
		{
			bottomTxt.value = formatCurrency(minPrice);
			gminprice=minPrice;
		}
		else 
		{
			if ( bottomTxtValue >= topTxtValue ) 
			{
				bottomTxt.value = formatCurrency(topTxtValue);
				gminprice=gmaxprice;
				getresults();
			}
			else
			{			
				if (bottomTxtValue < parseInt(minPrice)) 
				{
					bottomTxt.value = formatCurrency(minPrice);
					gminprice = minPrice;
				}
				else 
				{
					bottomTxt.value = formatCurrency(bottomTxtValue);
					gminprice = bottomTxtValue;
				}
			getresults();			
			}			
		}				
	}

    function initPolish()
    {
        var stepPolish = Math.ceil(slHeight / 4);
        if (parseInt(strLowPolish) == minPolish && parseInt(strHighPolish) == maxPolish && sl[4] == undefined) 
            setTimeout("animate('polishTop','polishBottom' );", 100);
        if (sl[4] == undefined) 
		{
            sl[4] = YAHOO.widget.Slider.getVertDualSlider("sliderPolish", "polishTop", "polishBottom", slHeight + 1, stepPolish, [0, slHeight]);
            if (parseInt(strLowPolish) != minPolish && parseInt(strHighPolish) != maxPolish) 
                sl[4].setValues((strLowPolish - 1) * stepPolish, strHighPolish * stepPolish, false, false, false);
            else 
                if (parseInt(strLowPolish) != minPolish) 
                    sl[4].setMinValue((strLowPolish - 1) * stepPolish, false, false, false);
                else 
                    if (parseInt(strHighPolish) != maxPolish) 
                        sl[4].setMaxValue(strHighPolish * stepPolish, false, false, false);
            sl[4].minRange = -55;
            sl[4].subscribe("change", function(offsetFromStart){
                YAHOO.util.Dom.setStyle($('top_darkPolish'), 'height', this.minVal + 'px');
                YAHOO.util.Dom.setStyle($('bottom_darkPolish'), 'height', (slHeight + 1 - this.maxVal) + 'px');
                YAHOO.util.Dom.setStyle($('bottom_darkPolish'), 'top', (this.maxVal - this.minVal + shadowoffset + ieshadowoffset(this.minVal)) + 'px');
                gmaxpolish = Math.round(this.maxVal / stepPolish);
                gminpolish = Math.round(this.minVal / stepPolish) + 1;
                getresults();
            });
        }
    }

   function initSymmetry()
   {	  
      var stepSymmetry = Math.ceil(slHeight/4);
      if (sl[5] == undefined)
      {
	  	if ( parseInt(strLowSymmetry) == minSymmetry && parseInt(strHighSymmetry) == maxSymmetry) setTimeout("animate('symmetryTop','symmetryBottom');",100);         
        sl[5]= YAHOO.widget.Slider.getVertDualSlider("slyderSymmetry", "symmetryTop", "symmetryBottom", slHeight+1, stepSymmetry, [0,slHeight] );
		if (parseInt(strLowSymmetry) != minSymmetry && parseInt(strHighSymmetry) != maxSymmetry)
		  sl[5].setValues((strLowSymmetry-1)*stepSymmetry,strHighSymmetry*stepSymmetry,false,false,false);
		  else
		  	if (parseInt(strLowSymmetry) != minSymmetry)
			  sl[5].setMinValue((strLowSymmetry-1)*stepSymmetry,false,false,false);
			else
				if (parseInt(strHighSymmetry) != maxSymmetry)
				  sl[5].setMaxValue(strHighSymmetry*stepSymmetry,false,false,false);
         sl[5].minRange=-55;
		 sl[5].subscribe("change", function (offsetFromStart) {
		 YAHOO.util.Dom.setStyle($('top_darkSymmetry'),'height', this.minVal + 'px'); 
		 YAHOO.util.Dom.setStyle($('bottom_darkSymmetry'),'height', (slHeight+1-this.maxVal) + 'px'); 
		 YAHOO.util.Dom.setStyle($('bottom_darkSymmetry'),'top', (this.maxVal-this.minVal+shadowoffset+ieshadowoffset(this.minVal)) + 'px'); 								  	
		 gmaxsymmetry=Math.round(this.maxVal/stepSymmetry);
			gminsymmetry=Math.round(this.minVal/stepSymmetry)+1;
			getresults();
	  });		 
      }
   }

   function setDepth()
   {
   		if ( strLowDepth != minDepth && strHighDepth != maxDepth)
		  sl[6].setValues(slHeight-depthToOffset(strHighDepth),slHeight-depthToOffset(strLowDepth),true,false,false);
		  else
		  if ( strLowDepth != minDepth)
			  sl[6].setMaxValue(slHeight-depthToOffset(strLowDepth),true,false,false);
			  else
			  	if (strHighDepth != maxDepth)
				  sl[6].setMinValue(slHeight-depthToOffset(strHighDepth),true,false,false);
	  var depthMax = $('txtDepthMax');
      var depthMin = $('txtDepthMin');
	  gmaxdepth=depthMax.value=parseFloat(strHighDepth).toFixed(1);
	  gmindepth=depthMin.value=parseFloat(strLowDepth).toFixed(1);	  		  	
   }

   function initDepth()
   {
      if (sl[6] == undefined)
      {
			if ( strLowDepth == minDepth && strHighDepth == maxDepth) setTimeout("animate('depthTop','depthBottom');",100);
			sl[6]= YAHOO.widget.Slider.getVertDualSlider("sliderDepth", "depthTop", "depthBottom", slHeight, 1, [0,slHeight] );		
			sl[6].minRange=-80;
			sl[6].minSlider.animate = false ;
		    sl[6].maxSlider.animate = false ;	  
			var factor=(slRange)/(maxDepth-minDepth);
				  
		  sl[6].subscribe("change", function (offsetFromStart) 
		  {
		  	var depthMax = $('txtDepthMax');
      		var depthMin = $('txtDepthMin');
		  	dmin=this.minVal;
			dmax=this.maxVal; 
			if (this.activeSlider.valueChangeSource == 1) 
			{
				if (this.activeSlider == this.minSlider) 
					gmaxdepth = depthMax.value = (maxDepth - this.minVal / factor).toFixed(1);
				else 
					gmindepth = depthMin.value = (minDepth + (slRange - this.maxVal) / factor).toFixed(1);
			}
			setShadow2('top_darkDepth','bottom_darkDepth', dmin, dmax );
			getresults();
		  });
		  //sl[6].subscribe("ready", function (){ setDepth(); });	
		 window.setTimeout( 'setDepth()',100);  
	  }
   }


   function depthToOffset(depth)
   {
	    if (isNaN(depth)) return;        
        var range=maxDepth-minDepth;
		if (depth <= minDepth) return 0;
        if (depth >= maxDepth) return slHeight;
        var factor=slRange/range;		
        return parseInt((depth-minDepth)*factor);
   }

   function depthKeyUpMin()
   {
       var txtBottom = $('txtDepthMin');
	   var txtDepth=$F('txtDepthMin');
       var minDepthVal = parseFloat(txtDepth);
	   var maxDepthVal = parseFloat($F('txtDepthMax'));
	   var offset;
       if (txtDepth.length > 1 && !isNaN(txtDepth)) 
	   {
	   		if ( minDepthVal <= maxDepthVal) 
			{
				offset = slHeight - depthToOffset(minDepthVal);
				sl[6].setMaxValue(offset, true, true, true);
				gmindepth = parseFloat(maxDepthVal).toFixed(1);				
			}
			else
			{
				offset = slHeight - depthToOffset(gmaxdepth);
				sl[6].setMaxValue(offset, true, true, true);				
				gmindepth = parseFloat(gmaxdepth).toFixed(1);
			}
			dmax = offset;							
			setShadow2('top_darkDepth','bottom_darkDepth', dmin, dmax );
			getresults();           
       }
       else 
	   {
	   		dmax = slHeight;
	   		sl[6].setMaxValue(slHeight, true, true, true);
			gmindepth=minDepth;
			setShadow2('top_darkDepth','bottom_darkDepth', dmin, dmax );
	   }	              
   }

   function depthKeyUpMax()
   {
       var txtTop = $('txtDepthMax');
       var txtTopVal = $F('txtDepthMax');
       var maxDepthVal = parseFloat($F('txtDepthMax'));
       var minDepthVal = parseFloat($F('txtDepthMin'));
	   var offset ;
       if (txtTopVal.length > 1 && !isNaN(txtTopVal)) 
	   {
	   		if ( maxDepthVal >= minDepthVal )
			{
				if ( maxDepthVal <= parseFloat(maxDepth))
				{
					offset = slRange-depthToOffset(maxDepthVal);
					sl[6].setMinValue(offset, true, true, true);
					gmaxdepth = parseFloat(maxDepthVal).toFixed(1);					
				}
				else 
				{
					offset = slHeight-depthToOffset(maxDepth);
					sl[6].setMinValue(offset, true, true, true);
					gmaxdepth = parseFloat(maxDepth).toFixed(1);						
				}					        	
			}
			else 
			{
				offset = slRange - depthToOffset(minDepthVal);
				sl[6].setMinValue(offset, true, true, true);
				gmaxdepth = parseFloat(minDepth).toFixed(1);								
			} 
			dmin = offset;
			setShadow2('top_darkDepth','bottom_darkDepth', dmin, dmax );			
			getresults();			          
       }
       else 
	   {
	   	   dmin = 0 ;
	   	   sl[6].setMinValue(0, true, true, true);
		   gmaxdepth=maxDepth;
   		   setShadow2('top_darkDepth','bottom_darkDepth', dmin, dmax );
	   }        
   }

   function depthMaxBlur()
   {	   	 		
   		txtMax=$('txtDepthMax');
		if ($F('txtDepthMax').length == 0 || isNaN(txtMax.value)) 
		{
			txtMax.value = maxDepth;
			getresults();
			return;
		}
		else
		{
			var maxValue=parseFloat(txtMax.value); 
			var minValue=parseFloat($F('txtDepthMin'));
			if (maxValue <= minValue) gmaxdepth = txtMax.value = minValue.toFixed(1);
			else 
			{
				if (maxValue <= maxDepth) 
					gmaxdepth = txtMax.value = maxValue.toFixed(1);
				else 
				{
					gmaxdepth = txtMax.value = maxDepth.toFixed(1);
					getresults();	   				
				}
			}			
		}		
   }
   
   function depthMinBlur()
   {
   		txtMin=$('txtDepthMin');
		minValue=parseFloat(txtMin.value);
		maxValue=parseFloat( $F('txtDepthMax') );		
		
		if ($F('txtDepthMin').length == 0 || isNaN(txtMin.value)) 
		{
			txtMin.value = minDepth;
			getresults();
			return;
		}
		else 
		{
			if (minValue >= maxValue) 
			{
				gmindepth = txtMin.value = maxValue.toFixed(1);
				getresults();				
			}
			else 
			{
				if ( minValue >= minDepth) gmindepth = txtMin.value = minValue.toFixed(1);
				else 
				{
					gmindepth = txtMin.value = minDepth.toFixed(1);
					getresults();
				}
			}
						   	
		}		
   }

   function setTable()
   {
   		if (strLowTable!=minTable && strHighTable!=maxTable)
			 sl[7].setValues(slHeight-tableToOffset(strHighTable),slHeight-tableToOffset(strLowTable),true,false,false);
		 else	
		  	if (strLowTable!=minTable)
			  sl[7].setMaxValue(slHeight-tableToOffset(strLowTable),true,false,false);
			else
				if (strHighTable!=maxTable)
				  sl[7].setMinValue(slHeight-tableToOffset(strHighTable),true,false,false);
		var tableMax = $('txtTableMax');
	    var tableMin = $('txtTableMin');
		gmaxtable = tableMax.value=parseFloat(strHighTable).toFixed(1);
		gmintable = tableMin.value=parseFloat(strLowTable).toFixed(1);   	
   }
   
   function initTable()
   {  	
      if (sl[7] == undefined)
      {
		 if ( strLowTable==minTable && strHighTable==maxTable) setTimeout("animate('tableTop','tableBottom');",100);       
	     sl[7]= YAHOO.widget.Slider.getVertDualSlider("sliderTable", "tableTop", "tableBottom", slHeight, 1, [0,slHeight] );
		 sl[7].minRange=-80;
		 sl[7].minSlider.animate = false ;
   		 sl[7].maxSlider.animate = false ;	     
		 var tableMax = $('txtTableMax');
	     var tableMin = $('txtTableMin');
		 tableMax.value=maxTable.toFixed(1);
		 tableMin.value=minTable.toFixed(1);
		 var factor=(slHeight-6)/(maxTable-minTable);
		 sl[7].subscribe("change", function (offsetFromStart) 
		 {
		 	var factor=(slHeight-6)/(maxTable-minTable);
		 	tmin = this.minVal;
			tmax = this.maxVal;
			if (this.activeSlider.valueChangeSource == 1) 
			{
				if (this.activeSlider == this.minSlider) 
					gmaxtable = tableMax.value = (Math.round(10 * (maxTable - this.minVal / factor)) / 10).toFixed(1);
				else 
					gmintable = tableMin.value = (Math.round(10 * (minTable + (slHeight - this.maxVal) / factor)) / 10).toFixed(1);
			}
			setShadow2('top_darkTable', 'bottom_darkTable', tmin, tmax);
			getresults();
		 });
		 //sl[7].subscribe("ready", function (){ setTable(); });
		window.setTimeout('setTable()',100); 	 
      }
   } 

   function tableToOffset(table)
   {
	    if (isNaN(table)) return;        
        var range=maxTable-minTable;
		if (table < minTable) return 0;
        if (table > maxTable) return slHeight;
        var factor=(slHeight)/range;		
        return parseInt((table-minTable)*factor);
   }

   function tableKeyUpMin()
   {
	   var txtBottom = $('txtTableMin');
	   var txtTable = txtBottom.value;       
	   var offset ;
       if (txtTable.length > 1 && !isNaN(txtTable)) 
	   {
		   	var minTableVal = parseFloat(txtTable);
		    var maxTableVal = parseFloat($F('txtTableMax'));			
	   		if ( minTableVal <= maxTableVal) 
			{
				offset = slHeight - tableToOffset(minTableVal);
				sl[7].setMaxValue(offset, true, true, true);								
				gmintable = parseFloat(minTableVal).toFixed(1);
			}
			else
			{		
				offset = slHeight+ 6 - tableToOffset(maxTableVal);
				sl[7].setMaxValue(offset, true, true, true);			
				gmintable = txtBottom.value = parseFloat(maxTableVal).toFixed(1);
			}
			tmax = offset;
			setShadow2('top_darkTable', 'bottom_darkTable', tmin, tmax);			
			getresults();           
       }
       else 
	   {
	   		tmax = slHeight
	   		sl[7].setMaxValue(slHeight, true, true, true);
			gmintable=minTable;
			setShadow2('top_darkTable', 'bottom_darkTable', tmin, tmax);
	   }
   }

   function tableKeyUpMax(){
       var txtTop = $('txtTableMax');
       var txtTopVal = $F('txtTableMax');
       var maxTableVal = parseFloat($F('txtTableMax'));
       var minTableVal = parseFloat($F('txtTableMin'));
	   var offset;
       if (txtTopVal.length > 1 && !isNaN(txtTopVal)) 
	   {
           if (maxTableVal >= minTableVal) 
		   {
               offset = slRange - tableToOffset(maxTableVal);
               sl[7].setMinValue(offset, true, true, true);
			   gmaxtable = parseFloat(maxTableVal).toFixed(1);               
           }
           else 
		   {
               offset = slRange - tableToOffset(gminTable);
               sl[7].setMinValue(offset,true,true,true);
               gmaxtable = parseFloat(gmintable).toFixed(1);
           }
		   tmin = offset ;
		   setShadow2('top_darkTable', 'bottom_darkTable', tmin, tmax);		   
           getresults();		   
       }
       else 
	   {
	   	   tmin = 0 ;
           sl[7].setMinValue(0, true, true, true);
		   setShadow2('top_darkTable', 'bottom_darkTable', tmin, tmax);
           gmaxtable = maxTable;
       }
   }

   function tableMaxBlur()
   {
   		txtMax=$('txtTableMax');
		if ($F('txtTableMax').length == 0 || isNaN(txtMax.value)) 
		{
			gmaxtable= txtMax.value = maxTable.toFixed(1);
			return;
		}
		var maxValue=parseFloat(txtMax.value); 
		var minValue=parseFloat($F('txtTableMin')); 		
		
		if (maxValue <= minValue) 
		{
			gmaxtable = txtMax.value = minValue.toFixed(1);
		}
		else 
		{
			if ( maxValue >= maxTable )
			{
				gmaxtable=txtMax.value=maxTable.toFixed(1);
			}
			else 
			{
				gmaxtable=txtMax.value=maxValue.toFixed(1);
			}
		}
		getresults();   	
   }
   
   function tableMinBlur()
   {
   		txtMin=$('txtTableMin');
		minValue=parseFloat(txtMin.value);
		maxValue=parseFloat( $F('txtTableMax') );		
		
		if ($F('txtTableMin').length == 0 || isNaN(txtMin.value)) 
		{
			txtMin.value = minTable.toFixed(1);
			gmintable = minTable;
			return;
		}
		else 
		{
			if (minValue >= maxValue) 
			{
				gmindtable = txtMin.value = maxValue.toFixed(1);
				getresults();				
			}
			else 
			{
				if (minValue < minTable) 
					gmintable = txtMin.value = minTable.toFixed(1);
				else 
				{
					txtMin.value = minValue.toFixed(1);					
					gmintable = txtMin.value ;
				}
			}						   	
		}  	
   }
   
   function initFluorescence(){
       var stepFluor = slHeight / 5;
       if (sl[8] == undefined) {
           if (parseInt(strLowFluorescence) == minFluorescence && parseInt(strHighFluorescence) == maxFluorescence) 
               setTimeout("animate('fluorescenceTop','fluorescenceBottom');", 100);
           sl[8] = YAHOO.widget.Slider.getVertDualSlider("sliderFluorescence", "fluorescenceTop", "fluorescenceBottom", slHeight + 1, stepFluor, [0, slHeight]);
           if (parseInt(strLowFluorescence) != minFluorescence && parseInt(strHighFluorescence) != maxFluorescence) 
               sl[8].setValues((strLowFluorescence - 1) * stepFluor, strHighFluorescence * stepFluor, false, false, false);
           else 
               if (parseInt(strLowFluorescence) != minFluorescence) 
                   sl[8].setMinValue((strLowFluorescence - 1) * stepFluor, false, false, false);
               else 
                   if (parseInt(strHighFluorescence) != maxFluorescence) 
                       sl[8].setMaxValue(strHighFluorescence * stepFluor, false, false, false);
           sl[8].minRange = -65;
           sl[8].subscribe("change", function(offsetFromStart){
               YAHOO.util.Dom.setStyle($('top_darkFluorescence'), 'height', this.minVal + 'px');
               YAHOO.util.Dom.setStyle($('bottom_darkFluorescence'), 'height', (slHeight - this.maxVal) + 'px');
               YAHOO.util.Dom.setStyle($('bottom_darkFluorescence'), 'top', (this.maxVal - this.minVal + shadowoffset + ieshadowoffset(this.minVal)) + 'px');
               gmaxfluorescence = Math.round(this.maxVal / stepFluor);
               gminfluorescence = Math.round(this.minVal / stepFluor) + 1;
               getresults();
           });
       }
   }

	function setRatio()
	{
		if ( strLowLWRatio != minRatio && strtHighLWRatio != maxRatio )
		  sl[9].setValues(slRange-ratioToOffset(strtHighLWRatio),slHeight-ratioToOffset(strLowLWRatio),true,false,false);
		  else
		  	if (strLowLWRatio != minRatio)
			  sl[9].setMaxValue(slHeight-ratioToOffset(strLowLWRatio),true,false,false);
			else
				if (strtHighLWRatio != maxRatio)
				  sl[9].setMinValue(slRange-ratioToOffset(strtHighLWRatio),true,false,false);
		var ratioMax = $('txtRatioMax');
        var ratioMin = $('txtRatioMin');
	    ratioMax.value=gmaxratio = parseFloat(strtHighLWRatio).toFixed(2) ;
	    ratioMin.value=gminratio = parseFloat(strLowLWRatio).toFixed(2);						
	}	

   function initRatio()
   {	  
      if (sl[9] == undefined)
      {
	  	var factor=(slHeight-6)/(maxRatio-minRatio);	  	
	  	if (strLowLWRatio == minRatio && strtHighLWRatio == maxRatio) setTimeout("animate('ratioTop','ratioBottom');",100);
        sl[9]= YAHOO.widget.Slider.getVertDualSlider("sliderRatio", "ratioTop", "ratioBottom", slHeight, 1, [0,slHeight] );		
		sl[9].minRange=-80;
		sl[9].minSlider.animate = false ;
	    sl[9].maxSlider.animate = false ;
		var ratioMax = $('txtRatioMax');
        var ratioMin = $('txtRatioMin');	    
		sl[9].subscribe("change", function (offsetFromStart) 
		{
			if (this.activeSlider == this.minSlider) gmaxratio = ratioMax.value=Math.round(100*(maxRatio-this.minVal/factor))/100;
				else gminratio = ratioMin.value=Math.round(100*(minRatio+(slHeight-this.maxVal)/factor))/100;
			rmin = this.minVal; // Set offsets for the shadow
			rmax = this.maxVal;
			setShadow2('top_darkRatio','bottom_darkRatio',rmin,rmax);			
			getresults();
	    });
		sl[9].subscribe("ready", function () 
		  {
		  	setRatio();
		  });
		//window.setTimeout('setRatio()',90);			
      }
   }

   function ratioToOffset(ratio)
   {
   		if (isNaN(ratio)) return;        
	    var range=maxRatio-minRatio;
		if (ratio <= minRatio) return 0;
		if (ratio >= maxRatio) return slRange ;
        var factor=(slRange)/range;		
        return parseInt((ratio-minRatio)*factor);
   }
     

   function ratioKeyUpMin()
   {
	    var bottomY = $('txtRatioMin');
		var ratioVal = $F('txtRatioMin');
		var txtMaxRatio = $F('txtRatioMax');
		var offset;
		if (ratioVal.length >= 1 && !isNaN(ratioVal)) 
		{
			if (parseFloat(ratioVal) < parseFloat(txtMaxRatio)) 
			{
				offset = slHeight - ratioToOffset(ratioVal);
				sl[9].setMaxValue(offset, true, true, true);				
			}
			else 
			{
				offset = slHeight - ratioToOffset(txtMaxRatio);
				sl[9].setMaxValue(offset, true, true, true);
			}
			rmax = offset;
			gminratio = parseFloat(ratioVal);
			setShadow2('top_darkRatio', 'bottom_darkRatio',rmin,rmax);
			getresults();						
		}
		else {
			sl[9].setMaxValue(slHeight, true, true, true);
			setShadow2('top_darkRatio', 'bottom_darkRatio',rmin,slHeight);
		}
	}

   function ratioKeyUpMax()
   {
	    var topY = $('txtRatioMax');
		var ratioVal = $F('txtRatioMax');
		var txtMinRatio = $F('txtRatioMin');
		var offset;
		if ( ratioVal.length >= 1 && !isNaN(ratioVal)) // Can we parse the input ?
		{
			if ( parseFloat(ratioVal) > parseFloat(txtMinRatio) ) // Is it greater than the min ?
			{
				if (parseFloat(ratioVal) < parseFloat(maxRatio))
				{
					offset = slRange-ratioToOffset(ratioVal);
					rmin = offset;
					sl[9].setMinValue(offset,true,true, true);
					gmaxratio=parseFloat(ratioVal);
					
				}
				else 
				{
					gmaxratio = parseFloat(maxRatio);
					rmin = 0;
					sl[9].setMinValue(0, true, true, true);											
				}				
				setShadow2('top_darkRatio', 'bottom_darkRatio',rmin,rmax);
				getresults();
			}
			else 
			{
				offset = slRange-ratioToOffset(txtMinRatio);
				rmin = offset;
				sl[9].setMinValue(offset,true,true, true);
				gmaxratio=parseFloat(ratioVal);
				setShadow2('top_darkRatio', 'bottom_darkRatio',rmin,rmax);
				getresults();
			}			
		}
		else 
		{
			rmin = 0;
			sl[9].setMinValue(0, false,false, true);	
			setShadow2('top_darkRatio', 'bottom_darkRatio',rmin,rmax);
		}			
	}
	
	function ratioMaxBlur()
	{
		txtMax=$('txtRatioMax');
		if ($F('txtRatioMax').length == 0 || isNaN(txtMax.value)) 
		{
			gmaxratio = txtMax.value = maxRatio;
			return;
		}
		var maxValue=parseFloat(txtMax.value); 
		var minValue=parseFloat($F('txtRatioMin')); 		
		if (maxValue <= minValue ) gmaxratio = txtMax.value = parseFloat(gminratio).toFixed(2);
		else 
		{
			if (maxValue <= parseFloat(maxRatio) )	gmaxratio=txtMax.value=maxValue.toFixed(2);				
			else gmaxratio = txtMax.value = parseFloat(maxRatio).toFixed(2);
		}			
		getresults();		
	}
	
	function ratioMinBlur()
	{
		txtMin=$('txtRatioMin');
		if ($F('txtRatioMin').length == 0 || isNaN(txtMin.value)) 
		{
			gminratio = txtMin.value = minRatio;
			return;
		}
		var minValue=parseFloat(txtMin.value); 
		var maxValue=parseFloat($F('txtRatioMax')); 		
		if ( minValue <= maxValue  ) 
		{
			if (minValue >= parseFloat(minRatio) )	gminratio=txtMin.value=minValue.toFixed(2);				
				else gminratio = txtMin.value = parseFloat(minRatio).toFixed(2);
		}
		else 
		{
			gminratio = txtMin.value = maxValue.toFixed(2) ;
		}					
		getresults();			
	}
   
   // Hiding or showing additional sliders and colomns 
   function hideCol(chk)
   {   	   
       var sWidth = 91; // Width of the slider   
       var extraslider = null;
       var grid_container = $('gridbox');
       var intwidth = parseInt(grid_container.style.width.replace("px", ""));
       
       var holder = (document.getElementsByClassName('holder'))[0];
       var holderWidth = parseInt(holder.style.width.replace("px", ""));
       holderWidth = isNaN(holderWidth) ? 796 : holderWidth;
       
       var drSlider = $('dreamSlider');
       var drSliderWidth = parseInt(drSlider.style.width.replace("px", ""));
       drSliderWidth = isNaN(drSliderWidth) ? 697 : drSliderWidth;
       switch (chk.value) {
           case '7':
               extraslider = $('polish');
               break;
           case '8':
               extraslider = $('symmetry');
               break;
           case '9':
               extraslider = $('depth');
               break;
           case '10':
               extraslider = $('table');
               break;
           case '11':
               extraslider = $('fluorescence');
               break;
           case '12':
               extraslider = $('ratio');
               break;
       }
       if (chk.checked == true) // Add slider
	   {
           mygrid.setColumnHidden(chk.value, 0);
           if (chk.value != '13') {
               extraslider.style.display = "block";
               // holders width correction			
               drSliderWidth += sWidth;
               drSlider.style.width = drSliderWidth + 'px';
           }
           intwidth += mygrid.getColWidth(chk.value);
           grid_container.style.width = intwidth + 'px';
           holderWidth += mygrid.getColWidth(chk.value);
           holder.style.width = holderWidth + 'px';
           if (chk.value == '7') 
               initPolish();
           if (chk.value == '8') 
               initSymmetry();
           if (chk.value == '9') 
               initDepth();
           if (chk.value == '10') 
               initTable();
           if (chk.value == '11') 
               initFluorescence();
           if (chk.value == '12') 
               initRatio();
       }
       else // Remove slider, adjust width of the grid, sliders and holder
	   {
	   	   var colWidth = mygrid.getColWidth(chk.value);
		   var sub = 240 ; // temp fix (sWidth > colWidth) ? colWidth : sWidth ; 		              	
           mygrid.setColumnHidden(chk.value, true);
           if (chk.value != '13')// not for culet 
		   {
               extraslider.style.display = "none";
               drSliderWidth -= sWidth;
               
               if (drSliderWidth >= 606)  // 677 - width of dreamslider
                   drSlider.style.width = drSliderWidth + 'px';
      }
		   intwidth -= colWidth ; //sWidth;		   
           grid_container.style.width = intwidth + 'px';
           holderWidth = intwidth + sub;
           if (holderWidth > 796) 
               holder.style.width = holderWidth + 'px';
       }
   }
   
   	 function getresults()
	 {
		
	 	 if (resultsTimer == 0) {		 	
		 	resultsTimer = window.setTimeout("generateList(gmincarat, gmaxcarat, gmincolor, gmaxcolor, gmaxcut, gmincut, gmaxclarity, gminclarity, gminprice, gmaxprice, gminpolish, gmaxpolish, gminsymmetry, gmaxsymmetry, gmindepth, gmaxdepth, gmintable, gmaxtable, gminfluorescence, gmaxfluorescence, gminratio, gmaxratio)",1200);
		 }
		 else
		 {
		 	window.clearTimeout(resultsTimer);	
		 	resultsTimer = window.setTimeout("generateList(gmincarat, gmaxcarat, gmincolor, gmaxcolor, gmaxcut, gmincut, gmaxclarity, gminclarity, gminprice, gmaxprice, gminpolish, gmaxpolish, gminsymmetry, gmaxsymmetry, gmindepth, gmaxdepth, gmintable, gmaxtable, gminfluorescence, gmaxfluorescence, gminratio, gmaxratio)",1200);
		 }
	  }
    
	 // Generates new request and assigns it as a datasource
    function generateList(mincarat, maxcarat, mincolor, maxcolor, maxcut, mincut, maxclarity, minclarity, minprice, maxprice, minpolish,maxpolish,minsymmetry,maxsymmetry, mindepth,maxdepth,mintable,maxtable, minfluorescence, maxfluorescence, minratio, maxratio)
    {   
        // setting variables for cut
        if(maxcut == '' || IsNumeric(maxcut)!= true)
	        maxcut = 5;
        maxcut = parseInt(maxcut);
        gmaxcut = maxcut;

        if(mincut == '' || IsNumeric(mincut)!= true)
	        mincut = 1;
        mincut = parseInt(mincut);
        gmincut = mincut;
    		
        // setting variables for color
        if(maxcolor == ''  || IsNumeric(maxcolor)!= true)
	        maxcolor = 8;
        maxcolor = parseInt(maxcolor);
        gmaxcolor = maxcolor;

        if(mincolor == ''  || IsNumeric(mincolor)!= true)
	        mincolor = 1;
        mincolor = parseInt(mincolor);
        gmincolor = mincolor;
    	
        // setting variables for clarity
        if(maxclarity == '' || IsNumeric(maxclarity)!= true)
	        maxclarity = 8;
        maxclarity = parseInt(maxclarity);
        gmaxclarity = maxclarity;

        if(minclarity == '' || IsNumeric(minclarity)!= true)
	        minclarity = 1;
        minclarity = parseInt(minclarity);
        gminclarity = minclarity;
     		
        // setting variables for carat
        if(maxcarat == '' || IsNumeric(maxcarat)!= true)
	        maxcarat = maxCarat;
        maxcarat = parseFloat(maxcarat);
        gmaxcarat = maxcarat;

        if(mincarat == ''  || IsNumeric(mincarat)!= true)
	        mincarat = minCarat;
        mincarat = parseFloat(mincarat);
        gmincarat = mincarat;
    	
        if(maxprice == ''  || IsNumeric(maxprice)!= true)
	        maxprice = maxPrice ;
        maxprice = parseFloat(maxprice);
        gmaxprice = maxprice;
    	
        if(minprice == ''  || IsNumeric(minprice)!= true)
	        minprice = minPrice;
        minprice = parseFloat(minprice);
        gminprice = minprice;
		
		if (!IsNumeric(maxpolish) || maxpolish == undefined) maxpolish = '';
		if (!IsNumeric(minpolish)|| minpolish == undefined) minpolish = '';
		
		if (!IsNumeric(minsymmetry) || minsymmetry == undefined) minsymmetry = '';
		if (!IsNumeric(maxsymmetry) || maxsymmetry == undefined) maxsymmetry = '';
        
		if (!IsNumeric(mindepth) || mindepth == undefined) mindepth = '';
		if (!IsNumeric(maxdepth) || maxdepth == undefined) maxdepth = '';
		
		if (!IsNumeric(mintable) || mintable == undefined) mintable = '';
		if (!IsNumeric(maxtable)  || maxtable == undefined) maxtable = '';
		
		if (!IsNumeric(minfluorescence) || minfluorescence == undefined) minfluorescence = '';
		if (!IsNumeric(maxfluorescence) || maxfluorescence == undefined) maxfluorescence = '';
		
		if ( !IsNumeric(minratio) || minratio == undefined) gminratio = minratio = minRatio;
		if ( !IsNumeric(maxratio) || maxratio == undefined) gmaxratio = maxratio = maxRatio;
		
		// New functionality copy Viktar
		Cookie.set('dmincarat',mincarat,1);
		Cookie.set('dmaxcarat',maxcarat,1);
		Cookie.set('dmincut',mincut,1);
		Cookie.set('dmaxcut',maxcut,1);
		Cookie.set('dmaxcolor',maxcolor,1);
		Cookie.set('dmincolor',mincolor,1);
		Cookie.set('dmaxclarity',maxclarity,1);
		Cookie.set('dminclarity',minclarity,1);
		Cookie.set('dminprice',minprice,1);
		Cookie.set('dmaxprice',maxprice,1);					
		Cookie.set('dminpolish',minpolish,1);
		Cookie.set('dmaxpolish',maxpolish,1);					
		Cookie.set('dminsymmetry',minsymmetry,1);
		Cookie.set('dmaxsymmetry',maxsymmetry,1);					
		Cookie.set('dmindepth',mindepth,1);
		Cookie.set('dmaxdepth',maxdepth,1);							
		Cookie.set('dmintable',mintable,1);
		Cookie.set('dmaxtable',maxtable,1);					
		Cookie.set('dminfluorescence',minfluorescence,1);
		Cookie.set('dmaxfluorescence',maxfluorescence,1);					
		Cookie.set('dminratio',minratio,1);
		Cookie.set('dmaxratio',maxratio,1);
		
		//********** save shapes to cookie:  *********
		var enabledShapes='';
		for (var i=0;i<10;i++) 
		{			
			if (shapeArr[i].checked) 
			{
				if (enabledShapes != '') enabledShapes+=',' ;
				enabledShapes = enabledShapes + i ;
			}
		}
		Cookie.set('enabledShapes',enabledShapes,1);							
		// ********************************************        
        var querylist;
        querylist = buildUrl(mincarat, maxcarat, maxcolor, mincolor, maxcut, mincut, maxclarity, minclarity, minprice, maxprice, minpolish,maxpolish,minsymmetry,maxsymmetry, mindepth,maxdepth,mintable,maxtable, minfluorescence, maxfluorescence, minratio, maxratio,getColNameById(sortObj.col), sortObj.dir);
        mygrid.clearAll(false);
        if(document.getElementById("chkGIA").checked ) 
        querylist=querylist+"&Report=GIA"
        //alert(querylist);
        mygrid.loadXML(querylist);    
    };	
	

    // Change img src dynamically 
	function changeShapeImage(imgObj,flag)
	{
		var oldSrc = imgObj.getAttribute('src');
		var ftype, newSrc  ;
		if (flag) 
		{
			if ( oldSrc.lastIndexOf('_o') < 0 )
			{
				ftype=oldSrc.substring(oldSrc.lastIndexOf('.'), oldSrc.length);
				newSrc=oldSrc.replace(ftype, '_o'+ftype);				
			}
			else newSrc = oldSrc;			
		}
		else 
		{
			newSrc=oldSrc.replace('_o','');
		}
		imgObj.setAttribute('src', newSrc);
	};
	
	/*
	 * Returns true if Round Shape is selected or if no shape is selected 
	 */
	function roundSelected()
	{
		var count=0;
		for(var i=0;i<shapeArr.length;i++)
		{
			if (shapeArr[i].checked) count+=1;
		}
		return shapeArr[0].checked || count == 0;
	}
	
	function onlyRoundSelected()
	{	
		var count=0;
		for(var i=0;i<shapeArr.length;i++)
		{
			if (shapeArr[i].checked) count+=1;
		}
		return ( shapeArr[0].checked && count == 1)
	}
	
	// Change image and create request based on selected shapes, then update grid
	function addShape(shp)
	{
		var chk=new Object(); // fake checkbox for L/W slider 
		var image = $(shapeArr[shp].imgId);
		if (shapeArr[shp].checked == false)
		{
			shapeArr[shp].checked=true;
			changeShapeImage(image,true);			
		}
		else 
		{	
			shapeArr[shp].checked=false;						
			changeShapeImage(image,false);					
		}
		if ( onlyRoundSelected() ) 
		{			
			gminratio = strLowLWRatio = minRatio;
			gmaxratio = strHighLWRatio = maxRatio;
			rmin=0; rmax=slHeight;
			setShadow('top_darkRatio', 'bottom_darkRatio',rmin,rmax);
			sl[9].setValues(ratioToOffset(gminratio),ratioToOffset(gmaxratio),true,false,false);
			chk.checked=false;
			chk.value='12';
			//hideCol(chk);			
		}
		else 
		{
			var ratioIsHidden = ($('ratio').style.display == 'none');
			if (ratioIsHidden)
			{				
				//chk.checked = true; // set to true to make it visible by L/W ratio by default
                chk.checked = false;
				chk.value='12';
				//hideCol(chk);
				setRatio();				
			}						
		}
		if (!roundSelected() && !sl[1].restricted ) // Adjust CUT slider based on selected shape
		{						
			//lockCutSlider() ;						
		}
		if ( roundSelected() && sl[1].restricted) // Re-enable cut slider for a full range.
		{
			unlockCutSlider() ;			
		}	
		getresults();
	}
	
	function lockCutSlider()
	{
		sl[1].minSlider.thumb.initPageY+= Math.floor(slHeight / 5);
		var bottomConstr = sl[1].minSlider.thumb.bottomConstraint - Math.floor(slHeight / 5);
		sl[1].minSlider.thumb.setYConstraint(0, bottomConstr, Math.floor(slHeight / 5) );			
		sl[1].minRange = -55;
		if ( sl[1].minSlider.getYValue() == 0)	sl[1].setMinValue(0,true,true,false); // set new zero position
		if ( sl[1].maxSlider.getYValue() == slHeight / 5 ) sl[1].setMaxValue(slHeight/5,true,true,false)
		sl[1].restricted = true;
	}
	
	function unlockCutSlider()
	{
		var slStep = Math.floor(slHeight / 5);
		sl[1].minSlider.thumb.initPageY -= slStep ;
		var bottomConstr = sl[1].minSlider.thumb.bottomConstraint + slStep ;
		sl[1].minSlider.thumb.setYConstraint(0, bottomConstr, slStep );			
		sl[1].minRange = -65 ; 
		if ( sl[1].minSlider.getYValue() == slStep)	sl[1].setMinValue(0,true,false,false);
		sl[1].restricted = false;
	}	

	// mouse over effect
	function shapeOver(shp)
	{
		if (shapeArr[shp].checked) return;
		else 
		{
			var image = $(shapeArr[shp].imgId);
			changeShapeImage(image,true);
		}		
	};
    // Mouse out effect
	function shapeOut(shp)
	{
		var image = $(shapeArr[shp].imgId);
		if (shapeArr[shp].checked) return;
		else 
		{			
			changeShapeImage(image,false);
		}
	};
	
	function sliderMouseOut(slId)
	{
		var newSrc;		
		var curImgTop = $('s'+slId+'t');
		var oldSrcTop = curImgTop.getAttribute('src');
		
		var curImgBottom = $('s'+slId+'b');
		var oldSrcBottom = curImgBottom.getAttribute('src');		
		
		newSrc=oldSrcTop.replace('_o','');		
		curImgTop.setAttribute('src', newSrc);
		
		newSrc = oldSrcBottom.replace('_o','');
		curImgBottom.setAttribute('src', newSrc);
	}
	
	function sliderMouseOver(slId)
	{
		var newSrc  ;		
		var curImgTop = $('s'+slId+'t');		
		var curImgBottom = $('s'+slId+'b');
		newSrc='images/sliders/slider_top_o.png'; 
		curImgTop.setAttribute('src', newSrc);		
		newSrc = 'images/sliders/slider_bottom_o.png'; 
		curImgBottom.setAttribute('src', newSrc);		
	}
	
	function ieshadowoffset(n)
   {	   
	   if (isIE && n>0)
	   {
	   	 return 12;
	   }
	   else
	   	 return 0;
   }

    // slider animation
    function animate(sl1,sl2)
    {	  
      var attributes1 = {top: {from: 65, to:0}};
      var anim1 = new YAHOO.util.Anim(sl1, attributes1,1);
      anim1.animate();

      var attributes2 = {top: {from: 70, to:135}};
      var anim2 = new YAHOO.util.Anim(sl2, attributes2,1);
      anim2.animate();	  
    }
	
	function showFeedbackForm()
	{
		window.open('customerFeedback.asp', '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=yes, width=650, height=500');
	}


