
var classid=0;
var cartypeid=0;
var startprice=0;
var endprice=0;
var paiqiliang=0;
var zuoweishu=0;

var $ID=function(tagName){return document.getElementById(tagName);}
var oevent=new Function('e','if (!e) e = window.event;return e')

function show_info(page,div,pars)
{
	if(pars)
	{
		pars=pars+'&t='+Math.random();
	}
	//alert(pars);
	var url = page+'.php';
	var myAjax = new Ajax.Updater(
		div, 
		url, 
		{
			evalScripts:true,
			method: 'post', 
			parameters: pars
		});
}

function showclass(id)
{
	classid=id;
	cartypeid=0;
	var pars="d=1&classid="+classid+"&cartypeid="+cartypeid+"&startprice="+startprice+"&endprice="+endprice+"&paiqiliang="+paiqiliang+"&zuoweishu="+zuoweishu;

	
	show_info('ajax_carlist','right',pars);

}

function showcartype(id)
{
	cartypeid=id;
	
	var pars="e=1&classid="+classid+"&cartypeid="+cartypeid+"&startprice="+startprice+"&endprice="+endprice+"&paiqiliang="+paiqiliang+"&zuoweishu="+zuoweishu;

	show_info('ajax_carlist','right',pars);
}

var curid=0;
var curdivid=0;
var curpic='';
var curpic1='';
function showcar(divid,id,pic,pic1)
{	
	$('cont'+divid).innerHTML='';
	
	var pars1="id="+id+"&classid="+classid+"&cartypeid="+cartypeid+"&startprice="+startprice+"&endprice="+endprice+"&paiqiliang="+paiqiliang+"&zuoweishu="+zuoweishu;
	
	
	if(ids)
	{
		pars1=pars1+'&ids='+ids;
	}
	
	if(curid!=id)
	{
		$('cont'+divid).style.display='block';
	}else
	{
		$('cont'+divid).style.display = $('cont'+divid).style.display == "none" ? "" : "none";
	}
	$('cont'+divid).innerHTML='<div style="padding-top:30px;padding-left:100px;"><img src=images/loader.gif>Loading...</div>';
	show_info('ajax_cars','cont'+divid,pars1);

	$('img'+id).src = $('cont'+divid).style.display == "none" ? pic : pic1;
	
	if(curid!=0 && curid!=id)
	{
		$('img'+curid).src =curpic;
	}
	if(curdivid!=0 && curdivid!=divid)
	{
		$('cont'+curdivid).style.display='none';
	}

	curid	=id;
	curpic	=pic;
	curpic1	=pic1;
	curdivid=divid;
}

function checknowleft(z)
{
	
	var price=0;
	if(z<=40) 
	{
		price=0;
	}else
	{
		price=Math.round((120/300*(z-40)));
	}
	return price;
}

function gerstartprice(z)
{
	var price=0;
	if(z>198)
	{
		z=198;
	}
	if(z<=22) 
	{
		price=0;
	}else
	{
		price =Math.round(110/176*(z-22));
	}


	/*else if(z<50)
	{
		price =Math.round((5+5/30*(z-22)));
	}else if(z<78)
	{
		price=Math.round((10+10/28*(z-50)));
	}else
	{
		price=Math.round(20+80/110*(z-78));
	}
	*/
	if(price>120)
	{
		price=120;
	}
	return price;
}

function gerendprice(z)
{
	var price=0;
	var endz =z+16;
	if(z<22) 
	{
		price=0;
	}else
	{
		price =Math.round(120/193*(endz-22));
	}
	
	/*else if(endz<50)
	{
		price =Math.round((5+5/30*(endz-20)));
	}else if(endz<80)
	{
		price=Math.round((10+10/30*(endz-50)));
	}else
	{
		price=Math.round(20+80/111*(endz-78));
	}
	*/
	if(price>120)
	{
		price=120;
	}
	return price;
}

function getpaiqiliang(z)
{	
	var num=0;
	if(z<=22) 
	{
		num=0;
	}else
	{
		num=1+Math.abs(4/193*(z-22));
		if(num>5) num=5;
		num=new String(num);
		num=num.substr(0,3);
	}
	return num;
}

function getzuowei1(z)
{	
	var num=0;
	if(z<=22) 
	{
		num=0;
	}else
	{
		//num=4+Math.round(6/200*(z-22))
		num=4+Math.abs(6/193*(z-22));
		//num=new String(num);
		if(num>=10)
		{
			num=new String(num);
			num=num.substr(0,2);
		}else if(num<5)
		{
			num=5;
		}else if(num<6)
		{
			num=6;
		}else if(num<7)
		{
			num=7;
		}else if(num<8)
		{
			num=8;
		}else if(num>8)
		{
			num=9;
		}
	}
	return num;
}

function getzuowei(z)
{	
	var num=0;
	if(z<=22) 
	{
		num=0;
	}else
	{
		if(z<=86)
		{
			num=5;
		}else if(z<=150)
		{
			num=8;
		}else if(z>=214)
		{
			num=9;
		}
	}
	return num;
}

var z;
var isup=true;
var isup2=true;
var isup3=true;

function move1(obj,len){
	var x,y,drag_=false;
	obj.onmousedown=function(e){
		drag_=true;
		with(this){
			var temp0=style.left.replace("px","")*1;var temp1=offsetLeft;var temp2=offsetTop;
			x=oevent(e).clientX;y=oevent(e).clientY;
			document.onmousemove=function(e){
				if(!drag_)return false;
				with(this){
					z = temp0 + oevent(e).clientX-x;
					if (z<0){z=0;drag_=false;}
					if (z>len){z=len;}
					
					style.left=z+"px";
					curid=0;
					curdivid=0;
					curpic='';
					isup=true;
				}
			}
			document.onmouseup=function(e){
				drag_ = false;
				if(z=="undefined")
				{
					z=style.left.replace("px","")*1;
					alert(z);
				}
				
				startprice = gerstartprice(z);
				endprice   = gerendprice(z);
				
				if(startprice>50)
				{
					//$ID("id2").style.left="53px";
				}else
				{
					//paiqiliang=0;
					//$ID("id2").style.left="0px";
				}

				var showhtml=startprice+"万-"+endprice+"万";
				
				style.left=z+"px";
				if(startprice>=0 && endprice>=10)
				{
					$ID("num1").innerHTML = showhtml;
				}else
				{
					$ID("num1").innerHTML ='';
				}
				
				if(isup)
				{
					$('right').innerHTML='<div style="padding-top:100px;padding-left:100px;"><img src=images/loader.gif>Loading...</div>';
					var pars="a=1&classid="+classid+"&cartypeid="+cartypeid+"&startprice="+startprice+"&endprice="+endprice+"&paiqiliang="+paiqiliang+"&zuoweishu="+zuoweishu;
					show_info('ajax_carlist','right',pars);
					isup=false;
				}
			}
		}
	}
}


function move2(obj,len){
	var x,y,drag_=false;
	obj.onmousedown=function(e){
		drag_=true;
		with(this){
			var temp0=style.left.replace("px","")*1;var temp1=offsetLeft;var temp2=offsetTop;
			x=oevent(e).clientX;y=oevent(e).clientY;
			document.onmousemove=function(e){
				if(!drag_)return false;
				with(this){
					z = temp0 + oevent(e).clientX-x;
					if (z<0){z=0;drag_=false;}
					if (z>len){z=len;}

					if(startprice>50 && z<53)
					{
						//z=53;
					}
					curid=0;
					curdivid=0;
					curpic='';
					isup=true;
					style.left=z+"px";
				}
			}
			document.onmouseup=function(e){
				drag_ = false;
				if(z=="undefined")
				{
					z=style.left.replace("px","")*1;
				}
				paiqiliang = getpaiqiliang(z);
				style.left=z+"px";
				
				var showhtml
				if(paiqiliang<5)
				{
					showhtml='<='+paiqiliang+'L';
				}else
				{
					showhtml='>'+paiqiliang+'L';
				}
				if(paiqiliang>0)
				{
					$ID("num2").innerHTML = showhtml;
				}else
				{
					$ID("num2").innerHTML ='';
				}
				if(isup)
				{
					$('right').innerHTML='<div style="padding-top:100px;padding-left:100px;"><img src=images/loader.gif>Loading...</div>';
					var pars="b=1&classid="+classid+"&cartypeid="+cartypeid+"&startprice="+startprice+"&endprice="+endprice+"&paiqiliang="+paiqiliang+"&zuoweishu="+zuoweishu;
					show_info('ajax_carlist','right',pars);
					isup=false;
				}
			}
		}
	}
}


function move3(obj,len){
	var x,y,drag_=false;
	obj.onmousedown=function(e){
		drag_=true;
		with(this){
			var temp0=style.left.replace("px","")*1;var temp1=offsetLeft;var temp2=offsetTop;
			x=oevent(e).clientX;y=oevent(e).clientY;
			document.onmousemove=function(e){
				if(!drag_)return false;
				with(this){
					z = temp0 + oevent(e).clientX-x;
					if (z<0){z=0;drag_=false;}
					if (z>len){z=len;}
					style.left=z+"px";

					curid=0;
					curdivid=0;
					curpic='';
					isup=true;
				}
			}
			document.onmouseup=function(e){
				drag_ = false;
				if(z=="undefined")
				{
					z=style.left.replace("px","")*1;
				}
				
				//zuoweishu = getzuowei(z);
				
				if(z<=22) 
				{
					num=0;
				}else if(z<=86)
				{
					z=55;
					num=5;
				}else if(z<=150)
				{
					num=8;
					z=150;
				}else if(z>150)
				{
					z=214;
					num=9;
				}
				
				style.left=z+"px";

				var showhtml=zuoweishu+'座';
				if(num==5)
				{
					$ID("num3").innerHTML = '<=5座';
				}else if(num==8)
				{
					$ID("num3").innerHTML = '8座';
				}else if(num==9)
				{
					$ID("num3").innerHTML = '8座以上';
				}else
				{
					$ID("num3").innerHTML ='';
				}
				zuoweishu=num;
				if(isup)
				{
					$('right').innerHTML='<div style="padding-top:100px;padding-left:100px;padding-bottom:40px;"><img src=images/loader.gif>Loading...</div>';
					var pars="c=1&classid="+classid+"&cartypeid="+cartypeid+"&startprice="+startprice+"&endprice="+endprice+"&paiqiliang="+paiqiliang+"&zuoweishu="+zuoweishu;
					show_info('ajax_carlist','right',pars);
					isup=false;
				}
			}
		}
	}
}