$(function(){

	/*
		点击取车城市/还车城市， 显示城市列表
	*/
	var getCarCityLists = $('#getCarCityLists');						//城市列表对象
	var getCarCity = $('input[name="getCarCity"]');					//取车城市输入框
	var retCarCity = $('input[name="retCarCity"]');					//还车城市输入框
	var getCarCityMenDian = $('input[name="getCarCityMenDian"]');		//取车门店输入框
	var retCarCityMenDian = $('input[name="retCarCityMenDian"]');		//还车门店输入框
	var getCarMenDianList = $('#getCarMenDianList');					//取车门店列表
	var retCarMenDianList = $('#retCarMenDianList');					//还车门店列表
	var gett = $('#gett');												//取车门店列表
	var rett = $('#rett');												//还车门店列表
	
	var getCityListsSH = false;										//城市列表显示/隐藏 标志位
	var getMendianListSH = false;										//取车门店列表显示/隐藏 标志位
	var retMendianListSH = false;										//还车门店列表显示/隐藏 标志位
	var wnh1 = false;
	var wnh2 = false;
	
	var district1 = false; 
	var district2 = false;
	
	var checkeds = [false, false];
	//2009-11-12
	var selecteds = [0, 0];
	
	//点击取车城市输入框
	getCarCity.click(function(){
		ehaiYDK.cites.show(this, getCarCityLists);
		getCarMenDianList.hide();
		retCarMenDianList.hide();
		$(this).focus();
		
	});
	
	//点击还车城市输入框
	retCarCity.click(function(){
		ehaiYDK.cites.show(this, getCarCityLists);
		getCarMenDianList.hide();
		retCarMenDianList.hide();
		$(this).focus();
	});
	
	//点击取车门店输入框
	$('#getMendianBox').click(function(){
		retCarMenDianList.hide();							   
		var value = getCarCityMenDian.val();
		ehaiYDK.cites.mendian('get', this, getCarMenDianList);
		ehaiYDK.ajax('get', getCarCity.val(), 'city', ehaiYDK.fnO);
		//ehaiYDK.fnO.city(test(),"get");
		ehaiYDK.hbh_fun();
		//getCarMenDianList.find('.list-box li strong[rel="' + value + '"]').parent().addClass('wjl');
	});
	
	//点击还车门店输入框
	$('#retMendianBox').click(function(){
		getCarMenDianList.hide();							   
		var value = retCarCityMenDian.val();
		ehaiYDK.cites.mendian('ret', this, retCarMenDianList);
		ehaiYDK.ajax('ret', retCarCity.val(), 'city', ehaiYDK.fnO);
		//ehaiYDK.fnO.city(test(),"ret");
		//retCarMenDianList.find('li .swfulds[rel="' + value + '"]').addClass('selected_city');
	});
	//这边是JASON 测试用...
	/*function test(){
				var testdata= {
			"storehouses": [{
				"district": "徐汇区",
				"storedetail": [{
					"briefname": "徐家汇店1",
					"id": "3",
					"to_time": "22",
					"disturbance":"教堂",
					"recommendlog":"y"
				}, {
					"briefname": "徐家汇店2",
					"id": "185",
					"disturbance":"",
					"recommendlog":"n"
				},{
					"to_time": "20",
					"briefname": "徐家汇店3",
					"id": "185",
					"to_time": "20",
					"disturbance":"",
					"recommendlog":"y"
				},{
					"briefname": "徐家汇店4",
					"id": "185",
					"to_time": "20",
					"disturbance":"",
					"recommendlog":"n"
				}]
			}, {
				"district": "闵行区",
				"storedetail": [{
					"briefname": "七宝1",
					"id": "3",
					"to_time": "22",
					"disturbance":"闵行区",
					"recommendlog":"y"
				}, {
					"briefname": "七宝2",
					"id": "185",
					"to_time": "20",
					"disturbance":"闵行区",
					"recommendlog":"n"
				}]
			}, {
				"district": "普陀区",
				"storedetail": [{
					"briefname": "普陀门店1",
					"id": "3",
					"to_time": "22",
					"disturbance":"普陀区1",
					"recommendlog":"y"
				}, {
					"briefname": "普陀门店2",
					"id": "185",
					"to_time": "23",
					"disturbance":"普陀区2",
					"recommendlog":"n"
				}]
			}, {
				"district": "机场",
				"storedetail": [{
					"briefname": "浦东机场",
					"id": "3",
					"to_time": "22",
					"disturbance":"浦东机场",
					"recommendlog":"y"
				}, {
					"briefname": "虹桥机场",
					"id": "185",
					"to_time": "23",
					"disturbance":"虹桥机场",
					"recommendlog":"n"
				}]
			}],
			"city_get": "Y"
		}
		var testdata = eval(testdata);
		return testdata;		
		}*/
	
	//选择城市
	$('.city-list li span, .city-list02 li div span').hover(function(){$(this).addClass('current_city');}, function(){$(this).removeClass('current_city');}).click(function(){
		var type = ehaiYDK.cites._cs == 'getCarCity'?'get' :'ret';
		$('input[name="' + ehaiYDK.cites._cs + '"]').val($(this).text());
		$('input[name="'+type+'CarCityMenDian"]').val('请选择'+(type == 'get'?'取车' :'还车')+'城市对应的门店');
		$('#getWNH,#retWNH').val('请选择...');
		
		if(type == 'get'){
			$('.quick-order input[type="checkbox"]').each(function(i){this.checked = false;});
			$('input[name="retCarCity"]').val($(this).text());
			retCarCityMenDian.val('请选择还车城市对应的门店');
			$('.wnh').hide();			
			$('.mendianGet').show();
			ehaiYDK.hbh_fun();
		}else{
			$('.quick-order input[type="checkbox"]').each(function(i){if(i==1){this.checked = false;}});
			$('#retMendianBox').parent().show();
			$('.r').hide();
		}
		ehaiYDK.cites.hide(getCarCityLists);
	});
	
	 getCarCityLists.mouseover(function(){getCityListsSH = true;}).mouseout(function(){getCityListsSH = false;}); 
	
	$('#getCarCityLists ul.city-cat>li').click(function(){
		ehaiYDK.cites.changeCat(this);
	});
	
	$('.quick-order input[type="checkbox"]').each(function(i){
		$(this).click(function(){ 
		    var inputVal = i==0 ? getCarCity.val() : retCarCity.val();
		    var sourceV = i==0 ? getCarCity : retCarCity;
		    var type = i==0 ? 'get' : 'ret';
			if(this.checked) {
				$('.wnh:eq(' +i+')').show();
				$('.mendianGet:eq(' +i+')').hide();
				checkeds[i] = true;
				ehaiYDK.ajax(type, inputVal, 'service', ehaiYDK.fnO, sourceV);
			}else{
				$('.wnh:eq(' +i+')').hide();
				$('.mendianGet:eq(' +i+')').show();
				checkeds[i] = false;
			}
		});
	});
	
	$('#wnhget').click(function(){
		ehaiYDK.ajax('get', getCarCity.val(), 'area', ehaiYDK.fnO, $('#wnh1'));
		ehaiYDK.cites.area('get', this, $('#wnh1'));
		$('#wnh1').find('li[rel="'+$('input[name="getWNH"]').val()+'"]').addClass('selected_city');
	});
	
	$('#wnhret').click(function(){
		ehaiYDK.ajax('ret', retCarCity.val(), 'area', ehaiYDK.fnO, $('#wnh2'));
		ehaiYDK.cites.area('ret', this, $('#wnh2'));
		$('#wnh2').find('li[rel="'+$('input[name="retWNH"]').val()+'"]').addClass('selected_city');
	});
	
	$('#wnh1').hover(function(){wnh1 = true}, function(){wnh1 = false;});
	$('#wnh2').hover(function(){wnh2 = true}, function(){wnh2 = false;});
	

	$('#listDistrict1').hover(function(){district1 = true}, function(){district1 = false;});
    $('#listDistrict2').hover(function(){district2 = true}, function(){district2 = false;});
	
	$('#divdistrict1').click(function(){
	    ehaiYDK.ajax('get', getCarCity.val(), 'district', ehaiYDK.fnO, $('#listDistrict1'));
	    ehaiYDK.cites.district('get', this, $('#listDistrict1'));
	    $('#listDistrict1').find('li').addClass('selected_city');
	    $('#listDistrict1').show();
	});
	
	$('#divdistrict2').click(function(){
	    ehaiYDK.ajax('ret', getCarCity.val(), 'district', ehaiYDK.fnO, $('#listDistrict2'));
	    ehaiYDK.cites.district('ret', this, $('#listDistrict2'));
	    $('#listDistrict2').find('li').addClass('selected_city');
	    $('#listDistrict2').show();
	});
	
	$('#txtGetCarAddress,#txtDropCarAddress').click(function(){
	    if($(this).val().indexOf('输入您的')>-1) $(this).val('');
	}).blur(function(){
	    if($(this).val()=='') $(this).val('输入您的具体地址...');
	});
	
	$('#getTime, #retTime').each(function(i){$(this).change(function(){	
		selecteds[i] = this.selectedIndex;
	})});
	
	//一嗨预定框 "预定框" 对象
	var ehaiYDK = {
		version : 1.2,
		cites : {
			show : function(source, target){
				var type = source.name == 'getCarCity' ? 'get' : 'ret';
				this.position(type, source, 'city');
				var selected = false;
				if(!this._cs){
					target.css(this.xyOpts[type+'city']).show();
					this._cs = source.name;
					selected = true;
				}else{
					if(this._cs == source.name){
						target.toggle();
					}else{
						target.css(this.xyOpts[type+'city']).show();
						selected = true;
					}
					this._cs = undefined;
				}
				if(selected) this.select($(source).val(), ['.city-list li span', '.city-list02 li div span'], 'selected_city');
			},
			hide : function(target){
				target.hide();
				this._cs = undefined;
			},
			select : function(value, target, className){
				$(target[0] + '.' + className + ',' + target[1] + '.' + className).removeClass(className);
				$(target[0] + '[rel="' + value + '"]' + ', ' + target[1] + '[rel="' + value + '"]').addClass(className);
				$(target[0] + '.' + 'current_city' + ',' + target[1] + '.' + 'current_city').removeClass('current_city');
			},
			reset : function(fbID){
				this.changeCat($('#' + fbID)[0]);
			},
			changeCat : function(target){
				if($(target).hasClass('curr-cat')) return;
				$('.city-cat li.curr-cat').removeClass('curr-cat');
				$(target).addClass('curr-cat');
				var id = target.id == 'clr' ? 'cll' : 'clr';
				$(target).removeClass(target.id);
				$('#' + id).addClass(id);
				$('.city-list').toggle();
				$('.city-list02').toggle();
				return false;
			},
			xyOpts : {},
			position: function(type, source, cma){
				var xy = $(source).position();
				
				if(!this.xyOpts[type+cma]){
					
					this.xyOpts[type+cma] = {
						left : xy.left  + 'px',
						top : xy.top + 24 + 'px',
						position: 'absolute'
					}
					
				}
			},
			mendian : function(type, source, target){ 
				this.position(type, source, 'mendian');
				target.css(this.xyOpts[type+'mendian']).toggle();
			},
			timeSelect : function(type, time){
				var t = $('#' + type + 'Time option:last').val();
				var o = $('#' + type + 'Time');
				var i = null;
				if(time == t) return;
				else if(time < t){
					i = t - time;
					for(var j=0; j<i; j++){
						o.find('option').remove('option:last-child');
					}
				}else if(time > t){
					i = time - t;
					for(var j=0; j<i; j++){
						o.append('<option value="'+ (Number(t)+j+1) +'">' +(Number(t)+j+1)+'点</option>');
					}
				}

			},
			area : function(type, source, target){
				this.position(type, source, 'area');
				target.css(this.xyOpts[type+'area']).toggle();
			},
			district : function(type, source, target){
			    this.position(type, source, 'district');
			    target.css(this.xyOpts[type+'district']).toggle(); 
			}
		},
		fnO : {
			city : function(data, type){
				var mendian = type == 'get' ? 'getCarMenDianList' : 'retCarMenDianList';
				var cityName = type == 'get' ? getCarCity : retCarCity;
				$('#' + mendian).html('');
				var bg_g = 'nameb-cur';
				var bg_g1 = 'nameb-cur1';
					
				//上海 北京 start
				if($('#'+type+'CarCity').val()=='上海'||$('#'+type+'CarCity').val()=='北京'){
					var a1='<div class="wrap-sto1 clear-float">'
								+'<h4 class="odk-tit">'
									+'<strong>所有门店</strong>'
									+'<img src="images/od-close.png" title="关闭" />'
								+'</h4>'
							+'<ul class="area-box1">';
							+'</ul></div>';
					$('#' + mendian).html(a1);					
					var i = 0;					
					while(data.storehouses[i]){
					var cont1="",cont2="",cont3=""	  
					for (var j = 0,_c = data.storehouses[i].storedetail.length; j < _c; j++){	
						c1=(data.storehouses[i]['storedetail'][j]['disturbance']!=""? '<span class="name-b" title="点击选择">'+data.storehouses[i]['storedetail'][j]['disturbance']+'</span>':'')
						d1='<li number="1" disturbance="'+data.storehouses[i]['storedetail'][j]['disturbance']+'">'
                                                        +'<strong rel="'+data.storehouses[i]['storedetail'][j]['briefname']+'" _id="'+data.storehouses[i]['storedetail'][j]['id']+'" time="'+data.storehouses[i]['storedetail'][j]['to_time']+'">'+data.storehouses[i]['storedetail'][j]['briefname']+'</strong>'
                                                        +'<div class="con">'
                                                            +'<span>08:00-20:00</span>'
                                                            +'<p>数据加载中...</p>'
                                                            +'<a href='+ehaiYDK.urls['zhinan']+'sid='+data.storehouses[i]['storedetail'][j]['id']+'&c='+cityName.val()+'  target="_self">查看地图和路线</a>'
                                                        +'</div>'
                                                    +'</li>';
						e1="";							
						cont3=cont3+d1;
						if(cont2.indexOf(c1)<0){cont2=cont2+c1;}					
					}
					//(o.data[0]['weekdayPrice']>0?'<li class="price-zj">周中<span>'+o.data[0]['weekdayPrice']+'</span>元/天</li>':'')
					b1= '<li number="0">'

                             +'<div class="clear-float k">'
                               		+'<strong class="name-q">'+data.storehouses[i]['district']+'</strong>'
                                    +'<div class="box-b">'
									+cont2
									+'</div>'
                        		+'</div>'
                        		+'<ul class="list-box1">'
								+cont3
						        + '</ul>'
                          +'</li>';
					cont1=cont1+b1;	
					$('#' + mendian + ' div.wrap-sto1 .area-box1').append(cont1);					
					i++;
				}
				var j = 0;				
				/*add bg*/

				
				$('#' + mendian + ' .area-box1 li').hover(function(){
					$(this).addClass('cur21');
				}, function(){
					$(this).removeClass('cur21');					
					$('#' + mendian + ' .area-box1 .list-box1').removeClass('mm');	
				})
				$('#' + mendian + ' .area-box1 .box-b span').hoverIntent(
						function(){$(this).addClass(bg_g1);
						//##    Added by yang   2010-11-18  Start
					    $(this).parents(".cur21").children(".list-box1").addClass('mm');
					    $('#' + mendian + ' .area-box1 .box-b').find('.'+bg_g).removeClass(bg_g);											
					    if($(this).hasClass(bg_g)) return;
					    $(this).parent().find(bg_g).removeClass(bg_g);
					    $(this).addClass(bg_g);
					    checkdistrict = $(this).text();					
					    $('#' + mendian + ' .area-box1 .list-box1 li').each(function(j){
						    var dt = $(this).attr('disturbance');
						    var none = $(this).hasClass('none');						
						    if(dt.indexOf(checkdistrict) < 0 && $(this).parent().hasClass("mm")){
							     if(!none) $(this).addClass('none');
							     return;						
						    }
						    if(none) {$(this).removeClass('none');}
					    });																  
						//##    Added by yang   2010-11-18  End
					},
					function(){$(this).removeClass(bg_g1);})

				//筛选 start
				$('#' + mendian + ' .area-box1 .box-b span').click(function(){	 	
					$(this).parents(".cur21").children(".list-box1").addClass('mm');
					$('#' + mendian + ' .area-box1 .box-b').find('.'+bg_g).removeClass(bg_g);											
					if($(this).hasClass(bg_g)) return;
					$(this).parent().find(bg_g).removeClass(bg_g);
					$(this).addClass(bg_g);
					checkdistrict = $(this).text();					
					$('#' + mendian + ' .area-box1 .list-box1 li').each(function(j){
						var dt = $(this).attr('disturbance');
						var none = $(this).hasClass('none');						
						if(dt.indexOf(checkdistrict) < 0 && $(this).parent().hasClass("mm")){
							 if(!none) $(this).addClass('none');
							 return;						
						}
						if(none) {$(this).removeClass('none');}
					});																  
				})
				$('#' + mendian + ' .area-box1 li div strong').click(function(){
					$(this).parents("li").children("ul").find(".none")	.removeClass("none");
					$(this).next(".box-b").find(".nameb-cur").removeClass("nameb-cur");																			
				})
				//筛选 over		
				$(".odk-tit img").click(function(){
					$('#'+mendian).hide();										 
				})

				$('#' + mendian + ' div.wrap-sto1 .list-box1 li strong').mousedown(function(event){										  
				 	$('#'+mendian).hide();
					var value = $(this).attr('rel');
					var time = $(this).attr('time');
					$('input[name="'+type+'CarCityMenDian"]').val(value);
					ehaiYDK.cites.timeSelect(type, Number(time));
					if(type == 'get' && getCarCity.val() == retCarCity.val()){
						$('input[name="retCarCityMenDian"]').val(value);
						ehaiYDK.cites.timeSelect('ret', Number(time));
						ehaiYDK.hbh_fun();
					}
				}).parent().hover(function(){
					if($(this).attr('number')==0){						
						$(this).addClass('cur')
						}
					else {						
						$(this).addClass('cur31')
						}
					if(type=='get') $('#hbh-box').hide();
					var id = $(this).find('strong').attr('_id');						
					ehaiYDK.ajax(type, id, 'mendian', ehaiYDK.fnO, this);
				}, function(){
					$(this).removeClass('cur');
					$(this).removeClass('cur31');
					//$(this).find('.swfulds').removeClass('sw_current').css('margin-bottom', '0px');
					//$(this).find('.swfuldd').hide();
					ehaiYDK.hbh_fun();
				}).find('.con').mousedown(function(event){
					event = window.event || event;
					var target = event.target || event.srcElement;					
					if(target.nodeName == 'A' && j==0){
						window.open(target.href,"mendianzhinan");
						j++;
					}else {return false;}
				});	
				//上海 北京	 over
}
//非北京上海的状况
else{			

				var m1='<div class="wrap-sto clear-float">'
                                    +'<div class="all-sto">'
                                    	+'<h4><strong class="allm-t">所有门店</strong><img class="i-close" src="images/od-close.png" title="关闭" /></h4>'
                                        +'<ul class="area-box">'
										
                                        +'</ul>'
                                    +'</div>'
                               +'</div>';
				$('#' + mendian).html(m1);
				var i=0;
				while(data.storehouses[i]){				
					var cont1="";
					var ha='<li class="distri"><strong style="">'+data.storehouses[i]['district']+'</strong><ul class="list-box">';					
					for (var j = 0,_c = data.storehouses[i].storedetail.length; j < _c; j++){	
					var h1='<li number="1">'
								+'<strong rel="'+data.storehouses[i]['storedetail'][j]['briefname']+'" _id="'+data.storehouses[i]['storedetail'][j]['id']+'" time="'+data.storehouses[i]['storedetail'][j]['to_time']+'">'+data.storehouses[i]['storedetail'][j]['briefname']+'</strong>'
								+'<div class="con"><span>08:00-20:00</span><p>数据加载中...</p><a href='+ehaiYDK.urls['zhinan']+'sid='+data.storehouses[i]['storedetail'][j]['id']+'&c='+cityName.val()+' target="_self">查看地图和路线</a></div></li>';							
					var cont1=cont1+h1;			
						}	
					var hb='</ul></li>';
					$('#' + mendian + ' .all-sto .area-box').append(ha+cont1+hb);
					i++;
				}
				var j = 0;
				
				$('#' + mendian + ' ul li.distri').hover(function(){
					$(this).addClass('cur2');
				}, function(){
					$(this).removeClass('cur2');
				})
				$(".wrap-sto .i-close").click(function(){
					$('#'+mendian).hide();										 
				})

	
				$('#' + mendian + ' div.wrap-sto .list-box li strong').mousedown(function(event){
																						  
				 	$('#'+mendian).hide();
					var value = $(this).attr('rel');
					var time = $(this).attr('time');
					$('input[name="'+type+'CarCityMenDian"]').val(value);
					ehaiYDK.cites.timeSelect(type, Number(time));
					if(type == 'get' && getCarCity.val() == retCarCity.val()){
						$('input[name="retCarCityMenDian"]').val(value);
						ehaiYDK.cites.timeSelect('ret', Number(time));
						ehaiYDK.hbh_fun();
					}
				}).parent().hover(function(){
					if($(this).attr('number')==0){						
						$(this).addClass('cur')
						}
					else {						
						$(this).addClass('cur3')
						}					
					//$(this).find('.swfulds').addClass('sw_current').css('margin-bottom', ($.browser.version=='6.0' || $.browser.version =='7.0' ? '-4px' : 0));
					//$(this).find('.swfuldd').show();
					if(type=='get') $('#hbh-box').hide();
					var id = $(this).find('strong').attr('_id');						
					ehaiYDK.ajax(type, id, 'mendian', ehaiYDK.fnO, this);
				}, function(){
					$(this).removeClass('cur');
					$(this).removeClass('cur3');
					ehaiYDK.hbh_fun();
				}).find('.con').mousedown(function(event){
					event = window.event || event;
					var target = event.target || event.srcElement;					
					if(target.nodeName == 'A' && j==0){
						window.open(target.href,"mendianzhinan");
						j++;
					}else {return false;}
				});
}
			},
			mendian : function(data, type, o){
				$(o).find('.con p').html(data.storehouses[0]['complete_name']);
				$(o).find('.con span').html(data.storehouses[0]['from_time'] + '-' + data.storehouses[0]['to_time']);
				//$(o).find('.swfulddd p:last a').attr('href', 'http://www.baidu.com/');
			},
			area : function(data, type, o){
				$(o).find('ul').html('');
				var m = type == 'get' ? 1 : 2;
				var i = 0;
				while(data.areas[i]){
					$(o).find('ul').append('<li value="'+ data.areas[i]['price'].toString() +'" rel="'+data.areas[i]['area_name']+'">' +data.areas[i]['area_name']+'</li>').find('li').hover(function(){$(this).addClass('current_city');}, function(){$(this).removeClass('current_city');}).click(function(){
						$('input[name="'+type+'WNH"]').val($(this).html());
						$('input[name="'+type+'Price"]').val($(this).attr('value'));
						$('#wnh' + m).hide();
					});
					i++;
				}
			},
			district : function(data, type, o){
			    $(o).find('ul').html('');
			    var m = type == 'get' ? 1 : 2;
				var i = 0;
				while(data.districts[i]){
				    $(o).find('ul').append('<li sid='+data.districts[i]['sid'].toString()+'>'+data.districts[i]['title'].toString()+'</li>').find('li').hover(function(){$(this).addClass('current_city');}, function(){$(this).removeClass('current_city');}).click(function(){
				           $('#txtdistrict' + m).val($(this).html());
				           $('#districtSId' + m).val($(this).attr('sid'));
				           $('#listDistrict' + m).hide();
				    });
				    i++;
				}
			},
			service : function (data, type, o){
			    var i = type=="get" ? 0 : 1;
			    if (data == 'Y'){
			        $('.wnh:eq('+i+') div').show();
			        $('#sc-note'+i).hide();
			        if( o.val() == '上海') $('#divdistrict'+(i+1)).show();
				    else $('#divdistrict'+(i+1)).hide();
			    }else{
			        $('.wnh:eq('+i+') div').hide();
			        $('#sc-note'+i).show();
			    }
			}
			
		},
		//ehaiYDK.ajax('get', getCarCity.val(), 'area', ehaiYDK.fnO, $('#wnh1'));type, id, 'mendian', ehaiYDK.fnO, this
		ajax : function(type, value, urlType, fnO, v){
			value = escape(value);
			//1 3 4 2
			var _self = this;
			var mendian = (type == 'get' ? 'getCarMenDianList' : 'retCarMenDianList');
			var area = (type == 'get' ?  1 : 2);
			var district = (type == 'get' ? 1 : 2);
			if(value in _self.data[urlType]){
				fnO[urlType].call(_self, _self.data[urlType][value], type, v);
			}
			else {
				$.ajax({
					url : _self.urls[urlType] + value,
					type : 'get',
					beforeSend : function(data){
						if(urlType == 'city') $('#' + mendian + ' div.wrap-sto .tj-sto .list-box').html('<p><span class="liouter">Loading...</span></p>');
						else if(urlType == 'mendian') $(v).find('.list-box').html('<div class="mm">数据加载中...</div>');
						else if(urlType == 'area') $('#wnh' + area + ' .wrap-sto').html('<p class="liouterarea">Loading...</p>');
						else if(urlType == 'district') $('#listDistrict' + district + ' ul').html('<li><span class="liouterarea">Loading...</span></li>');
					},
					success : function(data){						
						_self.data[urlType][value] = eval('(' + data + ')');
						fnO[urlType].call(_self, _self.data[urlType][value], type, v);
					}	
				});
			}
			
		},
		data : {
			city : {},
			mendian : {},
			area : {},
			district : {},
			service : {}
		},
		urls : {   
			city : ' AsyncData.aspx?action=getbstore1&city=',
			mendian : 'AsyncData.aspx?action=getcstore&cityid=',
			area : 'AsyncData.aspx?action=getarea&city=',
			district : 'AsyncData.aspx?action=getdistrict&city=',
			service : 'AsyncData.aspx?action=service&city=',    //是否有送车上门，上门取车服务
			images : '',
			/* 2009-12-3 */
			zhinan : 'storeguide.aspx?'
		},
		hbh_fun : function(){
			var xy = $('#getMendianBox').position();
			var width = $('input[name="getCarCityMenDian"]').width();
			if($.trim($('input[name="getCarCityMenDian"]').val()).search(/机场/g) >-1){
				$('#hbh-box').css({left: width + xy.left + 28 + 'px', top: xy.top + 'px','z-index': 1}).show();
				$('#hbh-box input').focus(function(){
					var val = $.trim($(this).val());
					if(val == '请在此输入航班号'){
						$(this).val('');
					}
				}).blur(function(){
					if($.trim($(this).val()) == ''){
						$(this).val('请在此输入航班号')
					 alert('请填写航班号(如果您没有航班号，可以填写0001)');
					}
				});
			} else {
				$('#hbh-box').hide();
			}
		}
	}
	
	
	
	$(document).mousedown(function(event){
		event = window.event || event;
		var target = event.target || event.srcElement;
		if(!getCityListsSH && target != getCarCity[0] && target != retCarCity[0]){
			ehaiYDK.cites.hide(getCarCityLists);
		}
		
/*		if(!getMendianListSH && target != getCarCityMenDian[0] && target != gett[0]){
			getCarMenDianList.hide();
		}*/
/*		if(!retMendianListSH && target != retCarCityMenDian[0] && target != rett[0]){
			retCarMenDianList.hide();
		}*/
		
		if(!wnh1) $('#wnh1').hide();
		if(!wnh2) $('#wnh2').hide();
		
		if(!district1) $('#listDistrict1').hide();
		if(!district2) $('#listDistrict2').hide();
		
		//2009-11-17 ehaiYDK.hbh_fun();
	});
	
	/*
		首页  日期控件
	*/
	var checkedCarType = null;
	$('#txtBookingDateTimeStart_btnCalendar').bind('click',function(){checkedCarType = true;});
	$('#txtBookingDateTimeStart_txtDate').bind('click',function(){checkedCarType = true;})[0].readOnly = true;
	$('#txtBookingDateTimeEnd_txtDate').bind('click',function(){checkedCarType = false;})[0].readOnly = true;
	$('#txtBookingDateTimeEnd_btnCalendar').bind('click', function(){checkedCarType = false;});
	$('#calendar td').bind('click', function(){
		if($.trim($(this).text()) != ''){
			if(checkedCarType){
				var vl = $('#txtBookingDateTimeStart_txtDate').val().split('-');
				var dateObj = new Date(vl[0], vl[1]-1, vl[2])
				dateObj.setDate(dateObj.getDate()+2);
				var m = Number(dateObj.getMonth()) + 1;
				var month = m < 10 ? '0' + m  : m ;
				var date = dateObj.getDate() < 10? '0' + dateObj.getDate() : dateObj.getDate();
				vl = [dateObj.getFullYear(), month, date];
				$('#txtBookingDateTimeEnd_txtDate').val(vl.join('-'));
			}
		}
	});
	$('#calendar').attr('onmouseup', '');
	
	//2009-11-17 window.onresize = function(){ehaiYDK.hbh_fun();}

});


function showtab(btnid,tabid,tabnumber){
	for (i = 1;i<=tabnumber;i++){
		document.getElementById(tabid+"_btn"+i).className = "title_after";
		document.getElementById(tabid+"_sub"+i).style.display = "none";
	}
	document.getElementById(tabid+"_btn"+btnid).className = "title_now";
	document.getElementById(tabid+"_sub"+btnid).style.display = "block";
}
