var txt_change = "";


var price_range = max_price - min_price;
var ct_range = max_ct - min_ct;


var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var j,x,y,z,k=100;
var dobj;
var check_it;
var ord = 'price';
var sc = 'ASC';
var imgsrc='DEC';
var ttison = 1;
var ttison2 = 1;
/*
var color_scale=new Array("D","E","F","G","H","I","J","K","L","M");
var color_place=new Array(0,28,56,84,112,140,168,196,224,252);
var color_place_down=new Array(16,44,72,100,128,156,184,212,240,268);
var clarity_scale=new Array("IF","VVS1","VVS2","VS1","VS2","SI1","SI2","SI3","I1","I2","I3");
var clarity_place=new Array(0,26,52,78,104,130,156,182,208,234,252);
var clarity_place_down=new Array(16,42,68,94,120,146,172,198,224,250,268);
*/

/* ------------------------ */

var xmlHttp







var clarity=new Array();
var color=new Array();
var cut=new Array();



function clicked(elem,i)
{

if (clarity[i]) 
{
elem.style.background="url('') no-repeat";
elem.style.background="url('notpushed.jpg') no-repeat";
elem.style.backgroundColor='#626262';
elem.style.paddingTop = 2;

elem.style.fontWeight = 'normal';
elem.style.color='#ffffff';
clarity[i] = false;
}
else 
{
//elem.style.backgroundColor='#ffffff'; 

elem.style.background="url('pushed.jpg') no-repeat";

elem.style.paddingTop = 4;

elem.style.fontWeight = 'bold';
elem.style.color='#000000'; 
clarity[i] = true;

}

showUser('0')
}


function clicked2(elem,i)
{

if (color[i]) 
{
elem.style.background="url('') no-repeat";
elem.style.background="url('notpushed.jpg') no-repeat";

elem.style.backgroundColor='#626262';
elem.style.paddingTop = 2;
elem.style.fontWeight = 'normal';
elem.style.color='#ffffff';
color[i] = false;
}
else 
{
elem.style.background="url('pushed.jpg') no-repeat";

elem.style.paddingTop = 4;
elem.style.fontWeight = 'bold';
elem.style.color='#000000'; 
color[i] = true;

}

showUser('0')
}

function clicked3(elem,i)
{

if (cut[i]) 
{
elem.style.background="url('') no-repeat";
elem.style.background="url('notpushed.jpg') no-repeat";

elem.style.backgroundColor='#626262';
elem.style.paddingTop = 2;
elem.style.fontWeight = 'normal';
elem.style.color='#ffffff';
cut[i] = false;
}
else 
{
elem.style.background="url('pushed.jpg') no-repeat";
elem.style.paddingTop = 4;
elem.style.fontWeight = 'bold';
elem.style.color='#4a4a4a'; 
cut[i] = true;

}
showUser('0')
}





function getY(oElement,oColor,oClarity,oPrice,oShape,oCut,oCert,oCarat,oShop)
{
var iY = 0;
var iX = 0;
while( oElement != null ) {
iY += oElement.offsetTop;
iX += oElement.offsetLeft;
oElement = oElement.offsetParent;
}
//alert(iY+' '+iX);

document.getElementById("DiamondToolTip").style.left = iX - 9;
document.getElementById("DiamondToolTip").style.top = iY;

document.getElementById("DiamondToolTip2").style.left = iX - 156;


//alert(oClarity + "," + oShape);

document.getElementById("DiamondToolTip").style.display = '';
document.getElementById("DiamondToolTip2").style.display = '';

document.getElementById("ttclarity").innerHTML = oClarity;
document.getElementById("ttcolor").innerHTML = oColor;
document.getElementById("ttprice").innerHTML = oPrice;
document.getElementById("ttshape").innerHTML = oShape;
document.getElementById("ttcut").innerHTML = oCut;
document.getElementById("ttcert").innerHTML = oCert;
document.getElementById("ttcarat").innerHTML = oCarat;

iShop = "dis/" + oShop + ".jpg";

document.getElementById("ttshop").src = "dis/tt" + oShop + ".jpg";

document.getElementById("ttstars").src = "dis/stars" + oShop + ".jpg";

ttison = 1;

}


function ttud()
{
t = setTimeout("ttud2()",500);
//if (ttison2 == 0)
ttison = 0;
}


function ttud2()
{
if (ttison == 0) {
document.getElementById("DiamondToolTip").style.display = 'none';
document.getElementById("DiamondToolTip2").style.display = 'none';
}
}




function check_click(icheck, ielement)
{
 if (document.getElementById("check"+icheck).checked)
{
ielement.style.backgroundColor='#84DFC1';
document.getElementById("check"+icheck).click();
}
else
{
ielement.style.backgroundColor='#ffffff';
document.getElementById("check"+icheck).click();
}
}



function check_over(icheck, ielement)
{
if (document.getElementById("check"+icheck).checked)
{
ielement.style.backgroundColor='#84DFC1';
}
else
{
ielement.style.backgroundColor='#ffffff';
}
}


function OrderBy1(ordering)
{ 
if (sc=='DESC')
{
sc='ASC'
ord=ordering
imgsrc='DEC'
showUser('0')
}
else if (sc=='ASC')
{
imgsrc='ASC'
ord=ordering
sc='DESC'
showUser('0')
}
}


function showUser(page)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }



var url=edit_url('results16-b.php',page,ord,sc);




document.getElementById('ajax').style.display = '';
document.getElementById('txtHint').style.opacity = 0.5;
document.getElementById('txtHint').style.filter = 'alpha(opacity=' + 50 + ')';

xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}



function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
document.getElementById('ajax').style.display = 'none';
document.getElementById('txtHint').style.opacity = 1;
document.getElementById('txtHint').style.filter = 'alpha(opacity=' + 100 + ')';
 } 
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


/* ------------------------ */


function changed(e)
{
txt_change = e;
}


function edit_url(get_url,page,ord,sc)
{
var url1;
url1 = get_url;
url1 = url1 + "?";


for (ishape=0;ishape<document.a.shape.length;ishape++) 
{ 
      if (document.a.shape[ishape].checked) 
      { 
             shape_value = document.a.shape[ishape].value; 
      } 
} 

url1 = url1 + "sh1=" + shape_value + "&";

url1 = url1 + "cl=zz";

if (!clarity[1] && !clarity[2] && !clarity[3] && !clarity[4] && !clarity[5] && !clarity[6] && !clarity[7] && !clarity[8] && !clarity[9])
 url1 = url1 + "bcdefghij";
 else
 {

if (clarity[1] == true) url1 = url1 + "b";
if (clarity[2] == true == true) url1 = url1 + "c";
if (clarity[3] == true == true) url1 = url1 + "d";
if (clarity[4] == true == true) url1 = url1 + "e";
if (clarity[5] == true == true) url1 = url1 + "f";
if (clarity[6] == true == true) url1 = url1 + "g";
if (clarity[7] == true == true) url1 = url1 + "h";
if (clarity[8] == true == true) url1 = url1 + "i";
if (clarity[9] == true == true) url1 = url1 + "j";

}

url1 = url1 + "&cr=zz";

if (!color[1] && !color[2] && !color[3] && !color[4] && !color[5] && !color[6] && !color[7] && !color[8] && !color[9] && !color[10] && !color[11])
 url1 = url1 + "defghijklmn";
 else
 {
if (color[1] == true) url1 = url1 + "d";
if (color[2] == true) url1 = url1 + "e";
if (color[3] == true) url1 = url1 + "f";
if (color[4] == true) url1 = url1 + "g";
if (color[5] == true) url1 = url1 + "h";
if (color[6] == true) url1 = url1 + "i";
if (color[7] == true) url1 = url1 + "j";
if (color[8] == true) url1 = url1 + "k";
if (color[9] == true) url1 = url1 + "l";
if (color[10] == true) url1 = url1 + "m";
if (color[11] == true) url1 = url1 + "n";
}


url1 = url1 + "&cu=zz";

if (!cut[4] && !cut[3] && !cut[2] && !cut[1])
 url1 = url1 + "abcd";
 else
 {
if (cut[4] == true) url1 = url1 + "a";
if (cut[3] == true) url1 = url1 + "b";
if (cut[2] == true) url1 = url1 + "c";
if (cut[1] == true) url1 = url1 + "d";
}


url1 = url1 + "&";



url1 = url1 + "c1=" + document.a.uptext2.value + "&";
url1 = url1 + "c2=" + document.a.downtext2.value + "&";

url1 = url1 + "cost1=" + parseInt(document.a.uptext1.value) + "&";
url1 = url1 + "cost2=" + parseInt(document.a.downtext1.value) + "&";

EventValue = "";
EventValue = EventValue + "c1=" + document.a.uptext2.value + "_";
EventValue = EventValue + "c2=" + document.a.downtext2.value + "_";

EventValue = EventValue + "cost1=" + parseInt(document.a.uptext1.value) + "_";
EventValue = EventValue + "cost2=" + parseInt(document.a.downtext1.value);


pageTracker._trackEvent('Diamond Search','Loaded',EventValue,1);



<!---here---!> 

url1 = url1 + "ord=" + ord;
url1 = url1 + "&sc=" + sc;

url1 = url1 + "&arrow1=" + imgsrc;


url1 = url1 + "&page=" + page;

return (url1);
}





function isCarat(e,v,which) {
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;

if (which == 'min' && code == 13 && v) 
{
update_min_ct(v);
showUser('0');

}
if (which == 'max' && code == 13 && v)
{
update_max_ct(v);
showUser('0');

}

if (code == 8 || code == 9 || code == 13 || code == 190) return true;
var character = String.fromCharCode (code);
return '0' <= character && character <= '9'; 
}



function isPrice(e,v,which) {
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;


if (which == 'min' && code == 13 && v) {
update_min_price(v);
showUser('0');
}

if (which == 'max' && code == 13 && v)
{
update_max_price(v);
showUser('0');
}

if (code == 8 || code == 9 || code == 13) return true;
var character = String.fromCharCode (code);
return '0' <= character && character <= '9'; 
}



function onEnterpress(evt)
{
var keyCode = null;

if( evt.which ) {
keyCode = evt.which;
} else if( evt.keyCode ) {
keyCode = evt.keyCode;
}
if( 13 == keyCode ) {
return true;
}
return false;

}


function update_max_ct(ct)
{
if (parseFloat(ct) == parseFloat(txt_change))
{

}
else if (parseFloat(document.a.downtext2.value) <= min_ct) {
document.a.downtext2.value = max_ct;
alert('This number should be higher than the minimum carat!');
document.a.downtext2.select();
return false;
}
else{
txt_change = false;
max_ct = parseFloat(ct);
document.down2.style.left = 268;
document.a.uptext2.value = min_ct;
document.up2.style.left = 0;
ct_range = max_ct - min_ct;
}
}

function update_min_ct(ct)
{
if (parseFloat(ct) == parseFloat(txt_change))
{

}
else if (parseInt(document.a.uptext2.value) >= max_ct) {
document.a.uptext2.value = min_ct;
alert('This number should be higher than the minimum carat!');
document.a.uptext2.select();
return false;
}
else{
txt_change = false;
min_ct = parseFloat(ct);
document.down2.style.left = 268;
document.a.downtext2.value = max_ct;
document.up2.style.left = 0;
ct_range = max_ct - min_ct;
}
}


function update_max_price(price)
{
if (parseInt(price) == parseInt(txt_change))
{

}
else if (parseInt(document.a.downtext1.value) <= min_price) {
document.a.downtext1.value = max_price;
alert('This number should be higher than the minimum price!');
document.a.downtext1.select();
return false;
}
else{
max_price = parseFloat(price);
document.down1.style.left = 268;
document.a.uptext1.value = min_price;
document.up1.style.left = 0;
price_range = max_price - min_price;
}
}

function update_min_price(price)
{
if (parseInt(price) == parseInt(txt_change))
{

}
else if (parseInt(document.a.uptext1.value) >= max_price) {
document.a.uptext1.value = min_price;
alert('This number should be higher than the minimum price!');
document.a.uptext1.select();
return false;
}
else{
min_price = parseFloat(price);
document.down1.style.left = 268;
document.a.downtext1.value = max_price;
document.up1.style.left = 0;
price_range = max_price - min_price;
}
}





function move_it(name, position)
{
the_element = document.getElementById(name);
the_element.style.left = position;
 

}


function view()
{

document.up1.style.left=0;
document.up1.style.top=4;
document.up1.style.display = 'inline';
document.down1.style.left=268;
document.down1.style.top=4;
document.down1.style.display = 'inline';
document.up2.style.left=0;
document.up2.style.top=4;
document.up2.style.display = 'inline';
document.down2.style.left=268;
document.down2.style.top=4;
document.down2.style.display = 'inline';


document.a.uptext1.value = min_price;
document.a.downtext1.value = max_price;
document.a.uptext2.value = min_ct;
document.a.downtext2.value = max_ct;


}


function movemouse(e)
{


  if (isdrag)
  {

k6 = nn6 ? e.clientX : event.clientX;
//document.a.test1.value = dobj.name.substr(0,4);
    if (dobj.name.substr(0,2) == 'up') {
num = dobj.name.substr(2,1);
up_text = document.getElementById('uptext' + num);
down_text = document.getElementById('downtext' + num);
up_elem = document.getElementById('up' + num);
down_elem = document.getElementById('down' + num);

	if (z < 0 && k6 < k)
	{
	
	    if (num == 3) 
		{
			up_text.value = 'D';
			z = 0;

	   	}
	    else if (num == 4)
		{
			up_text.value = 'IF';
			z = 0;

		}
	    else if (num == 1)
		{
			up_text.value = min_price;
			z = 0;

		}
	    else if (num == 2)
		{
			up_text.value = min_ct;
			z = 0;

		}
	    dobj.style.left = 0;
	    isdrag=false;
	    showUser(0);
	}
	else if (z > (parseInt(down_elem.style.left)-16) && k6 > k)
	{
		/* if (num != 3 && num != 4){

	     up_text.value = (parseInt(down_elem.style.left)-1); 
	    
	    } */
		up_text.value = down_text.value;

	    dobj.style.left = (parseInt(down_elem.style.left)-16);
	    isdrag=false;
	    showUser(0);
		z = z - 100;
		
	}
	else
	{
	    z = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
		if(num == 3) {
		check_it = Math.round(z/28);		
		dobj.style.left = color_place[check_it];
		up_text.value = color_scale[check_it];
		}
		else if(num == 4) {
		check_it = Math.round(z/26);		
		dobj.style.left = clarity_place[check_it];
		up_text.value = clarity_scale[check_it];
		
	
		}
		
		else if(num == 1) {

		check_it = min_price + (z * (price_range / 254));		
		dobj.style.left = z;
		up_text.value = Math.round(check_it);

	
		}
		else if(num == 2) {

		check_it = min_ct + (z * (ct_range / 254));		
		dobj.style.left = z;
		up_text.value = (Math.round(check_it * 100)) / 100;
		// up_text.value = check_it;
		
	
		}

		else
		{
	        dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
		f = z;
	        f = f + 15
	        up_text.value = f;

		}
	    k = nn6 ? e.clientX : event.clientX;

	    
	
	    return false;
	}
    }


/*  the right part calculations */


    else if (dobj.name.substr(0,4) == 'down') {
num = dobj.name.substr(4,1);
down_text = document.getElementById('downtext' + num);
up_text = document.getElementById('uptext' + num);
up_elem = document.getElementById('up' + num);
down_elem = document.getElementById('down' + num);

	if (z > 268 && k6 > k)
	{
	    if (num == 3) 
		{
			down_text.value = 'M';
			z = 268;
	   	}
	    else if (num == 4)
		{
			down_text.value = 'I3';
			z = 268;

		}
	    else if (num == 1)
		{
			down_text.value = max_price;
			z = 268;

		}
	    else if (num == 2)
		{
			down_text.value = max_ct;
			z = 268;

		}

	    
	    
	    dobj.style.left = 268;
	    isdrag=false;
	    showUser(0);
	}
	else if (z < (parseInt(up_elem.style.left)+16) && k6 < k)
	{
		if (check_it < 0) check_it = 0;
		if (num == 4) {down_text.value = clarity_scale[check_it];}
		else if (num == 3){down_text.value = color_scale[check_it];}
		/* else if (num == 1)
		{
		down_text.value = up_text.value;
		down_text.value = (parseInt(up_elem.style.left)+16); 
		}
		else if (num == 2)
		{
		down_text.value = (parseInt(up_elem.style.left)+16); 
		down_text.value = up_text.value;
		} */
		down_text.value = up_text.value;

	    dobj.style.left = (parseInt(up_elem.style.left)+16);
	    isdrag=false;
	    z = z + 100;
	    showUser(0);
	}
	else
	{
	    z = nn6 ? tx + e.clientX - x : tx + event.clientX - x;


		if(num == 3) {
		check_it = Math.round((z-13)/28);		
		dobj.style.left = (color_place_down[check_it]);
		down_text.value = color_scale[check_it];
		}
		else if(num == 4) {
		check_it = Math.round((z-13)/26);		
		dobj.style.left = (clarity_place_down[check_it]);
		down_text.value = clarity_scale[check_it];
		}
		else if(num == 1) {

		check_it = min_price + ((z - 16) * (price_range / 254));		
		dobj.style.left = z;
		down_text.value = Math.round(check_it);
		if (parseInt(down_text.value) < parseInt(up_text.value)) {down_text.value = up_text.value;}
		}
		else if(num == 2) {

		check_it = min_ct + ((z - 16) * (ct_range / 254));		
		dobj.style.left = z;
		down_text.value = (Math.round(check_it * 100)) / 100;

		if (parseInt(down_text.value) < parseInt(up_text.value)) {down_text.value = up_text.value;}
		
	
		}

		else
		{
	    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
	    down_text.value = z;
		
		}
	    k = nn6 ? e.clientX : event.clientX;

	    
	
	    return false;
	}
    }



  }
}

function selectmouse(e) 
{
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";

  while (fobj.tagName != topelement && fobj.className != "dragme")
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }

  if (fobj.className=="dragme")
  {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}

document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");

//-->
