/***
 * create by lucas.z.liu
 * OYESGO all rights reserved.
 */
/**
function addToBookmark(title, url) {
	title = title || document.title;
	url = url || window.document.location.href;
	if (window.side=bar) {
		window.sidebar.addPanel(title, url, "");
	} else if (document.all) {
		window.external.AddFavorite(url, title);
	} else if (window.opera && window.print) {
		return true;
	}
};
var loc_map = {"www.oyesgo.com":0,"flights.oyesgo.com":1,"hotels.oyesgo.com":2,"visas.oyesgo.com":3,"vacations.oyesgo.com":4,"bbs.oyesgo.com":5};
var LocString = new String(window.document.location.href);
var loc_flag = 0;
for(var loc_key in loc_map){
	if(LocString.indexOf(loc_key)>-1){
		loc_flag = loc_map[loc_key];
		break;
	}
}



//var right_ad_temp = '<li><a href="#link" target="_blank"><img src="#img" width="148" height="58" alt="#title" /></a></li>';
//var middle_ad_temp = '<a href="#link" target="_blank"><img src="#img" width="690" height="90" alt="#title" /></a>';
function get_ad(link,img,title,temp,type){
	title = title || "";
	link = link || "http://visas.oyesgo.com/";
	if(type=="mid"){
		img = img || "images/visa.jpg";
	}else{
		img = img || "images/img03.gif";
	}
	return temp.replace("#link", link).replace("#img", img).replace("#title", title);
}
*/
$(function(){
	//$(".navigation>ul>li").eq(loc_flag).addClass("on");
	//var html = [];
	//html.push(get_ad("http://shanwan.oyesgo.com/", "images/ad/shanwan.jpg", "闪玩社区",right_ad_temp));
	//html.push(get_ad(null, null, null,right_ad_temp));
	//html.push(get_ad(null, null, null,right_ad_temp));
	//$(".coop_holder>ul").html(html.join(""));
	$(".coop_holder").show();
	$(".navigation ul li a").each(function(){
		$(this).attr("target","_self");
	});
	$(".top_link a").each(function(){
		$(this).attr("target","_self");
	});
	
//	$(".index_visa_ads").html(get_ad("http://extend.oyesgo.com/?ref=airchina_2&url=http://www.airchina.com.cn/cn/deals/ticket/qlzl.shtml?cid=qxcj",
//			"images/ad/airchina.jpg", "国航官方特价促销-春游计划", middle_ad_temp)).show();
});
/*
jQuery.extend(
  jQuery.expr[ ":" ], 
  { reallyvisible : function (a) { return !(jQuery(a).is(':hidden') || jQuery(a).parents(':hidden').length); }}
);
*/
var LocString = new String(window.document.location.href);
function stopBubble(e) {
	if (e && e.stopPropagation) {
		e.stopPropagation();
	} else {
		window.event.cancelBubble = true;
	}
};
function getParamValue(str) {
	var rs = new RegExp("(^|)" + str + "=([^\&]*)(\&|$)", "gi").exec(LocString), tmp;
	if (tmp = rs) {
		return tmp[2];
	}
	return "";
};
var type = getParamValue("type");

var phone_tmp = '<tr class="tel"><td colspan="9"><span>所需资料请拨打电话咨询~ 谢谢！</span><strong>#phone <em>(普通市话)</em></strong></td></tr>';
$(document).ready(function(){
	//var flag = "visas";
	//if(LocString.indexOf("visas.oyesgo.com")>-1){
		//flag = "visas";
		//addToBookmark("OYESGO_签证", "http://visas.oyesgo.com/");
	//}
	/*
	$(".navigation>ul>li").hover(function() {
				var alink = $("a",$(this)).attr("href");
				if(alink.indexOf(flag)==-1)$(this).addClass("on");
			}, function() {
				var alink = $("a",$(this)).attr("href");
				if(alink.indexOf(flag)==-1)$(this).removeClass("on");
			}); 
	*/
	//修正度假接口的电话数据
	$(".line_css_for_j").html("010-59059157转6");
	/*
	 * class: JAutoComplete author: rock.z.luo version: 1.0 date: 2009-08-01
	 * 
	 * summary: 基于jQuery的自动完成提示
	 * 
	 * use class: jQuery, JAutoComplete_Hotels use global ver: none
	 * 
	 * updated: ver, name, date, summary.
	 */
	function JAutoComplete(class_s) {
		switch (class_s) {
		case 'visas':
			return new JAutoComplete_Flights();
		default:
			return new JAutoComplete_Flights();
		}
	}
	/* function JAutoComplete(class_s) */

	/* 转参数为Asc编码 */
	function strEncode(str) {
		var returnStr = "";
		var leng = str.length;
		for ( var i = 0; i < leng; i++) {
			returnStr += str.charCodeAt(i) + "--";
		}
		return returnStr;
	}

	//---------------------------------------------------------------------------------------

	/* 
	 class: JAutoComplete_Flights
	 author: rock.z.luo
	 version: 1.0
	 date: 2009-08-01

	 summary: 基于jQuery的自动完成提示

	 use class: jQuery
	 use global ver: none

	 updated: ver, name, date, summary.
	 updated: ver, name, date, summary.
	 */

	JAutoComplete_Flights.prototype.main = JAutoComplete_Flights_main;

	function JAutoComplete_Flights() {
		var this_ = this;

		//required
		this_.request_path = ''; //files.ext?path=<value>

		this_.ele_o = {};
		this_.ele_o.tbx_e = undefined;

		//optional
		this_.ele_o.popup_e = undefined;
		this_.var_name = 'autocomplete_countrys';
		this_.popup_class_name = 'JAutoComplete_Flights_popup_';
		this_.popup_width = 0;
		this_.offset_o = {
			left : 0,
			top : 0
		};

		this_.submit_callback_f = undefined;

		this_.x_o = {};
		this_.x_o.temp_result = [];
		this_.x_o.dom_items_s = [];
		this_.x_o.dom_tbx_e = [];
		this_.x_o.current_index = -1;

		this_.x_o.prev_data = [];

	}
	/* function JAutoComplete_Flights() */

	/*  
	 版本：2008-9-11
	 作用：类的入口函数
	 必填参数：none
	 */
	function JAutoComplete_Flights_main() {
		var this_ = this;

		this_.offset_o.left = this_.offset_o.left || 0;
		this_.offset_o.top = this_.offset_o.top || 0;

		this_.ele_o.popup_e = $('<dl class="' + this_.popup_class_name + '"></dl>')
				.appendTo('body').css( {
					display : 'none',
					position : 'absolute'
				});

		this_.x_o.dom_tbx_e = this_.ele_o.tbx_e.get(0);

		var script_e = document.createElement('script');
		script_e.id = this_.x_o.dom_tbx_e.id + '_cross_domain_e';
		document.body.appendChild(script_e);

		this_.ele_o.tbx_e.attr('autocomplete', 'off');

		$(window).resize(
				function() {
					var left_top_o = this_.ele_o.tbx_e.offset();
					this_.ele_o.popup_e.css( {
						left : left_top_o.left + this_.offset_o.left + 'px',
						top : left_top_o.top + this_.offset_o.top
								+ this_.ele_o.tbx_e.height() + 'px'
					});
				});

		//捕捉全局的点击事件
		$(document).click(function(evt) {
			var evt_e = evt.target || evt.srcElement;
			if (evt_e.id == this_.ele_o.tbx_e.id) {
				return true;
			}

			this_.ele_o.popup_e.css('display', 'none');
			JAutoComplete_Flights_reset(this_);

		});

		//捕捉全局的上下键
		$(document)
				.keydown(
						function(evt) {
							if ((evt.keyCode === 37 || evt.keyCode === 38
									|| evt.keyCode === 39 || evt.keyCode === 40)
									&& this_.ele_o.popup_e.css('display') == 'block') {
								//this_.x_o.dom_tbx_e.blur();
								this_.ele_o.popup_e.find('dd').removeClass(
										'current_');
								var total_i = this_.x_o.dom_items_s.length;

								//向上移动
								if (evt.keyCode === 37 || evt.keyCode === 38) {
									if (this_.x_o.current_index > 0) {
										this_.x_o.current_index--;
									} else {
										this_.x_o.current_index = total_i - 1;
									}
								}//向下移动
								else {
									if (this_.x_o.current_index >= (total_i - 1)) {
										this_.x_o.current_index = 0;
									} else {
										this_.x_o.current_index++;
									}
								}
								/* if(evt.keyCode===37||evt.keyCode===38) */
								curr_i = this_.x_o.current_index;
								var current_e = this_.x_o.dom_items_s[this_.x_o.current_index];
								if (current_e) {
									current_e.onmouseover();
								}

								this_.ele_o.popup_e.find('dd.current_')
										.each(function() {
											o_areaID = this.getAttribute('id'); //attrr('value',o_areaID);
												this_.ele_o.tbx_e.attr('aid',
														o_areaID);
												this_.ele_o.tbx_e.val(this
														.getAttribute('value'));
												
											});

							}
							/* end if */

							if (evt.keyCode === 13
									&& this_.ele_o.popup_e.css('display') == 'block') {
								this_.ele_o.popup_e
										.find('dd.current_')
										.each(
												function() {
													o_areaID = this
															.getAttribute('id');
													this_.ele_o.tbx_e.attr('aid',
															o_areaID);
													dyncById(o_areaID);
													this_.ele_o.tbx_e.val(this
															.getAttribute('value'));
													this_.ele_o.popup_e.css( {
														display : 'none'
													});
													JAutoComplete_Flights_reset(this_);
												});
							}

							return true;
						});
		//响应文本框的回车事件
		this_.ele_o.tbx_e.keydown(function(evt) {
			if (evt.keyCode === 13) {
				if (this_.ele_o.popup_e.css('display') == 'block') {
					evt.preventDefault();

					return true;
				} else if (this_.ele_o.popup_e.css('display') == 'none') {
					if ($.isFunction(this_.submit_callback_f)) {
						return this_.submit_callback_f(this_.x_o.dom_tbx_e,
								this_.ele_o.popup_e);
					}
				}
			}

		});

		//响应用户输入
		this_.ele_o.tbx_e.keyup(inner_f);

		this_.ele_o.tbx_e.click(inner_f);

		curr_i = 0;
		function inner_f(evt) {
			if (evt.keyCode === 13) {
				return true;
			}

			if ((evt.keyCode === 37 || evt.keyCode === 38 || evt.keyCode === 39 || evt.keyCode === 40)) {
				return true;
			}

			var tbx_value = this.value.replace(/^\s*|\s*$/g, '');
			var flag = (this.id == "city") ? true : false;
			var is_chinese_b = /[\u4e00-\u9fa5]/.test(tbx_value);
			var request_value = strEncode(tbx_value);//$.browser.msie?encodeURIComponent(tbx_value):tbx_value;
			if (tbx_value.length === 0) {
				this_.ele_o.popup_e.css('display', 'none');
				JAutoComplete_Flights_reset(this_);
				return true;

			}

			script_cross_domain_f(
					false,
					this_.request_path.replace(/<value>/gi, request_value
							+ '&sq_x=' + Math.random()),
					function(evt) {
						if (typeof window[this_.var_name] == 'undefined') {
							this_.ele_o.popup_e.css('display', 'none');

							JAutoComplete_Flights_reset(this_);

							return true;
						}

						var left_top_o = this_.ele_o.tbx_e.offset();
						this_.ele_o.popup_e.html('');
						this_.ele_o.popup_e.css( {
							display : 'block',
							left : left_top_o.left + this_.offset_o.left + 'px',
							top : left_top_o.top + this_.offset_o.top
									+ this_.ele_o.tbx_e.height() + 'px'
						});

						this_.ele_o.popup_e.html('');
						this_.ele_o.popup_e
								.append(format_f("<dd class='title_ is_not_item_'>输入中文|拼音或↑↓选择</dd>"));
						//update 0831
						all_j = window[this_.var_name];
						//没有返回数据
						if (all_j["city"] == undefined
								|| window[this_.var_name].city.length <= 0) {
							this_.ele_o.popup_e.css('display', 'block');
							JAutoComplete_Flights_reset(this_);
							if (this_.ele_o.tbx_e.val() != "") {

								this_.ele_o.popup_e
										.append(format_f(flag ? "<dd class='no_items_'>抱歉，没找到相关城市</dd>"
												: "<dd class='no_items_'>抱歉，没找到相关关键字</dd>"));
							}
							return true;
						}
						//for(var i=0, j=window[this_.var_name].city.length; i<j; i++)
						if (window[this_.var_name].city.length > 10) {
							for ( var i = 0, j = 10; i < j; i++) {
								var items_ = window[this_.var_name].city[i];
								this_.x_o.temp_result = items_.areaID;
								var external_airport_s = 'no_class_';//items_.ischina?'no_class_':'external_';
								this_.ele_o.popup_e.append(
								//<dd class="no_class_ cursor_" value="兴义" style="width: 180px;">
										format_f(
												"<dd id='{0}' class='{1}' value='{2}'><span>{3}{4}</span></dd>",
												items_.areaID,
												external_airport_s,
												(items_.cityName.indexOf('(') == -1) ? items_.cityName
														: items_.cityName
																.substring(
																		0,
																		items_.cityName
																				.indexOf('(')),
												JAutoComplete_Flights_make_highlight_alphabet(
														items_, tbx_value),
												JAutoComplete_Flights_make_highlight(
														items_.cityName,
														is_chinese_b, false,
														items_, tbx_value)));
							}
						} else {
							var _keyReLeng;
							if (this_.ele_o.tbx_e.attr("id") == 'keyword') {
								if ($.browser.msie) {
									_keyReLeng = window[this_.var_name].city.length - 1;
								} else {
									_keyReLeng = window[this_.var_name].city.length;
								}
							} else {
								_keyReLeng = window[this_.var_name].city.length;
							}

							for ( var i = 0, j = _keyReLeng; i < j; i++) {
								var items_ = window[this_.var_name].city[i];
								this_.x_o.temp_result = items_.areaID;
								var external_airport_s = 'no_class_';//items_.ischina?'no_class_':'external_';
								this_.ele_o.popup_e.append(
								//<dd class="no_class_ cursor_" value="兴义" style="width: 180px;">
										format_f(
												"<dd id='{0}' class='{1}' value='{2}'><span>{3}{4}</span></dd>",
												items_.areaID,
												external_airport_s,
												(items_.cityName.indexOf('(') > -1 && this_.ele_o.tbx_e
														.attr("id") == 'city') ? items_.cityName
														.substring(
																0,
																items_.cityName
																		.indexOf('('))
														: items_.cityName,
												JAutoComplete_Flights_make_highlight_alphabet(
														items_, tbx_value),
												JAutoComplete_Flights_make_highlight(
														items_.cityName,
														is_chinese_b, false,
														items_, tbx_value)));
							}

						}
						// 默认值

						var index_count = 0;
						this_.x_o.dom_items_s = [];

						var new_a = this_.ele_o.popup_e.find("dd").not(
								'.is_not_item_').each(
								function() {
									var this__ = this;
									this__.index_count = index_count++;
									this_.x_o.dom_items_s.push(this__);

									$(this).addClass('cursor_');

									this.onmouseover = function() {
										this_.ele_o.popup_e.find('dd').removeClass(
												'current_');
										$(this).addClass('current_');
										this_.x_o.current_index = this.index_count;
										curr_i = this.index_count;
									};

									this.onmouseout = function() {
										//$(this).removeClass('current_');
									};

									this.onclick = function(evt, arg_e) {
										var this__ = arg_e || this;
										this_.ele_o.popup_e.css('display', 'none');
										
										o_areaID = this
										.getAttribute('id');
								this_.ele_o.tbx_e.attr('aid',
										o_areaID);
										dyncById(o_areaID);
										
										this_.ele_o.tbx_e.val(this
												.getAttribute('value'));
										JAutoComplete_Flights_reset(this_);
									};
								});

						if (this_.popup_width) {
							this_.ele_o.popup_e.find("dd").each(function() {
								this.style.width = this_.popup_width + 'px';
							});
						}
						/* if( this_.popup_width ) */

						if (this_.x_o.dom_items_s[0]) {
							this_.ele_o.popup_e.find('dd').removeClass('current_');
							this_.x_o.dom_items_s[0].onmouseover();
						}

						this_.x_o.prev_data = window[this_.var_name];
						window[this_.var_name] = undefined;
						return true;
					}/* function() */
			);
			/* script_cross_domain_f */

		}

		/* function inner_f(evt) */

		return;
	}
	/* function JAutoComplete_Flights_main() */

	function JAutoComplete_Flights_reset(this_) {
		this_.x_o.temp_result = [];
		this_.x_o.dom_items_s = [];
		this_.x_o.current_index = -1;
	}

	function JAutoComplete_Flights_make_highlight(city_s, is_chinese_b,
			no_airport_b, items_, tbx_value) {
		if (is_chinese_b) {
			city_s = city_s.replace(tbx_value,
					'<label class="highlight_">' + tbx_value + '</label>');
			return city_s;
		} else {
			return '';
		}
	}

	function JAutoComplete_Flights_make_highlight_alphabet(items_, tbx_value_s) {
		var result_s = [];

		if ((!/[\u4e00-\u9fa5]/.test(tbx_value_s)) && items_.cityName) {
			var temp_re = new RegExp('(' + tbx_value_s + ')', 'i');

			result_s.push(items_.cityName.replace(temp_re,
					'<label class="highlight_">$1</label>'));
		}

		return result_s.join('');
	}

	/*  
	 版本: 2009-08-01
	 作用: 脚本跨域函数
	 必填参数: script_e, path_s, callback_f
	 */
	function script_cross_domain_f(script_e, path_s, callback_f) {/* rock.z.luo，void return，func:none */
		var remove_tag_b = false;
		if (typeof script_e === 'string') {
			script_e = document.getElementById(script_e);
		}
		if (!script_e) {
			document.body.appendChild(script_e = document.createElement('script'));
			remove_tag_b = true;
		}
		if (!callback_f) {
			callback_f = function() {
			}
		}
		;
		script_e.onload = function() {
			callback_f();
			if (remove_tag_b) {
				script_e.parentNode.removeChild(script_e);
			}
		};
		script_e.onreadystatechange = function() {
			if (script_e.readyState == 'loaded') {
				callback_f();
				if (remove_tag_b) {
					script_e.parentNode.removeChild(script_e);
				}
			}
		};
		script_e.src = path_s;
	}
	/* function script_cross_domain_f(script_e, path_s, callback_f) */

	function format_f(str_) {/* rock.z.luo code, return string, func:none */
		var len_ = arguments.length, re_ = null, arg_o = arguments;
		switch (len_) {
		case 0:
			return "";
		case 1:
			return str_;
		}
		for ( var i = 1, j = 0; i < len_; i++, j++) {
			re_ = new RegExp( [ "\\{", j, "(\\:[a-zA-Z]|)}" ].join(""), "g");
			str_ = str_.replace(re_, function($0, $1) {
				var result_a = [ arg_o[i] ];

				switch ($1) {
				case ":C":
				case ":c":
					result_a.unshift('¥');
					break;
				}

				return result_a.join('');
			});
		}
		/* for(var i=1, j=0; i<len_; i++, j++) */
		return str_;
	}
	/* function format_f(str_) */


	//end
	
	function isList(){
		var flag = false;
		var ipts = $(".visa_type input");
		if(ipts.get(0)!=undefined && $(".country_list").get(0)==undefined){
			flag =  true;
		}
		return flag;
	}
	
	function dyncTypes(ts,spell){
		var ret = [];
		var t_t = '<li key="#spell.html?type=#id">#name</li>';
		if(isList()){
			ret.push('<li class="on" key="./../#spell.html">查看全部签证</li>'.replace("#spell", spell));
			t_t = '<li key="./../#spell.html?type=#id">#name</li>';
		}else{
			ret.push('<li class="on" key="#spell.html">查看全部签证</li>'.replace("#spell", spell));
		}
		for(var i = 0 ;i<ts.length;i++){
			ret.push(t_t.replace("#id", ts[i]).replace("#name",types[ts[i]] ).replace("#spell", spell));
		}
		$(".visa_type_avil").html(ret.join(""));
		$(".visa_type_avil>li").click(function(e){
			$(this).siblings(".on").removeClass("on");
			$(this).addClass("on");
			if(isList()){
				$(".pop_keyword").hide();
			}
		});
	}
	
	$(".search_btn input").click(function(){
		if($(".visa_type_avil>li").size() <= 1)return;
		var link = $(".visa_type_avil>li").filter(".on");
		var vlink = link.attr("key");
		var visas_type='';   
		          $(".visa_type_avil li").each(function() {     
		           	   class_on = $(this).attr("class");
		           	   if(class_on=='on'){
		           		   if($(this).text().indexOf('--')=='-1'){
		           			   visas_type = $(this).text();
		           		   }else{
		           			   var intro = $(this).text().split("--");
		           			   visas_type = intro[1];
		           		   }
		           	   }
		          });
		var visas_country = $("#txtCountry").val();
		var intro = visas_country.split(" ");
		visas_country = intro[0];
		try{
			link_type_country = visas_country+'@'+visas_type+'@'+vlink ;
			if(vlink==undefined){
			}else{
				_oyesgo_search_log('visa',link_type_country);
			}
		}catch (e) {
			//避免接口异常,影响搜索
		}
		if(vlink==undefined){
			$("#txtCountry").css("border","2px solid #FF0000");
			setTimeout(function(){
				$("#txtCountry").css("border","0 none");
			}, 2000);
		}else{
			location.href = vlink;
		}
	});
	
	function dyncById(id){
		if(!cym[id]){
			$(".visa_type>input").val("暂无签证信息").css("background-color","red");
			$(".visa_type_avil").html('<li class="on">暂无签证信息</li>');
			return;
		}
		var ts = cym[id].s;
		var p = cym[id].p;
		if(p && ts && ts.length>0){
			$(".visa_type>input").val('--全部签证类型--').css("background-color","transparent");
			dyncTypes(ts,p);
		}else{
			$(".visa_type>input").val("暂无签证信息").css("background-color","red");
			$(".visa_type_avil").html('<li class="on">暂无签证信息</li>');
		}
	}
	
	$(".pop_key").click(function(e){
		var key = $(this).text();
		$("#txtCountry").val(key);
		$("#pop_hot_visa").hide();
		var id = $(this).attr("key");
		dyncById(id);
		e.stopPropagation();
		return false;
	});
	
	$(".title_tabs>ul>li").each(function(i){
		$(this).hover(function(){
			$(this).addClass("on");
			$(this).siblings("li").removeClass("on");
			$(".index_content_one ul").eq(i).show();
			$(".index_content_one ul").eq(i).siblings("ul").hide();
			$(".index_content_two ul").eq(i).show();
			$(".index_content_two ul").eq(i).siblings("ul").hide();
			$(".index_visa_box ul").eq(i).show();
			$(".index_visa_box ul").eq(i).siblings("ul").hide();
		});
	});
	
	$("#txtCountry").focus(function(){
		$(this).css("border","0 none");
		var def = "请输入国家名";
		if($(this).val()==def){
			$(this).val("");
		}
	}).blur(function(){
		var def = "请输入国家名";
		if($(this).val()==""){
			$(this).val(def);
		}
		$(".JAutoComplete_Flights_popup_").eq(0).hide();
		var fefefe=$(".current_").eq(0).removeClass("current_");
		var text=fefefe.attr("value");
		var id = fefefe.attr("id");
		if(id){
			$(this).val(text);
			dyncById(id);
		}
	});
	
	$(".title_tabs>ul>li>a").click(function(){
		return false;
	});

	
    function submitSearch() {
        
    }

    var JAutoComplete_keyword = new JAutoComplete();
    with (JAutoComplete_keyword) {
        request_path = 'http://oyesgocity.oyesgo.com/getCountry.html?keyWord=<value>';
        ele_o.tbx_e = $('#txtCountry');
        popup_width = $("#txtCountry").width()+25;
        offset_o = {
            left : -4,
            top : 5
        };
        submit_callback_f = submitSearch;
        main();
    }
	
	$("#pop_hot_visa .btn_close").click(function(){
		$("#pop_hot_visa").hide();
		return false;
	});
	$("#country_a").click(function(e){
		$(".JAutoComplete_Flights_popup_").hide();
		$("#pop_hot_visa").css({ left:$("#txtCountry").offset().left -4, top:$("#txtCountry").offset().top +20 });
		$("#pop_hot_visa").show();
		e.stopPropagation();
		return false;
	});
    $(document).click(function(oevent){
    	$(".pop_keyword").hide();
    	$("#pop_hot_visa").hide();
    });
    
    //====================list======================//
	$(".toggle_fold").toggle(function(){
		$(this).text("展示报价");
		$(this).parents(".visa_every_title").siblings("table").hide();
	},function(){
		$(this).text("折叠报价");
		$(this).parents(".visa_every_title").siblings("table").show();
	});
	
	function handleVisaType(){
		var isNoneChecked = true;
		var checked = $(".vias_type_for_j").each(function(){
			if(this.checked){
				isNoneChecked = false;
				return;
			}
		});

		var flag = false;
		
		$(".vias_type_for_j").each(function(){
			var vflag = false;
			if(this.checked){
				flag = true;
				vflag = true;
			}
				var val = this.value;
				var cur=$(".visa_type_"+val);
				var all = $("tbody>tr.filterable",cur);				
				if(vflag || isNoneChecked){
					cur.insertAfter(".filter_panel").children("table").show();		
				}
				//var vis = $("tbody>tr.filterable:visible",cur);
				var vis = $("tbody>tr.filterable:not(:hidden)",cur);
				var count = vis.size();
				
				if($.browser.msie){
					count = 0 ;
					var fffs = $("tbody>tr.filterable",cur);
					var sz = fffs.size();
					for(var i = 0 ; i < sz ;i++){
						if(fffs.get(i).style.display != 'none'){
							count++;
						}
					}
				}
				$(".g_n",cur).html("共搜索到（"+count+"）个报价").show();
				if(!vflag){
					cur.children("table").hide();
					$(".g_n",cur).hide();
					$(".title_shop",cur).hide();
				}else{
					cur.children("table").show();
					$(".g_n",cur).show();
					$(".title_shop",cur).show();
				}
				var min_price = 99999;
				if(vis.size()>0){
					vis.each(function(){
						var pr = $(".p_r_i",$(this)).html();
						var p = parseInt(pr.slice(1), 10);
						if(p<min_price){
							min_price = p;
						}
					});
				}
				if(min_price==99999){
					$(".m_p",cur).parent("b").hide();
				}else{
					$(".m_p",cur).text("¥"+min_price).parent("b").show();
				}
				
				if(count==0){
					$("table",cur).hide();
				}else{
					$("table",cur).show();
				}
		});
		if(!flag){
			//$(".visa_every").children("table").show();
			$(".g_n").show();
			$(".title_shop").show();
		}
	}
	
	$(".visa_type>.more").click(function(e){
		var ipt1 = $(".visa_type>input");
		var ipt2 = $(".visa_type>.more");
		var offset = $(this).offset();
		$(".pop_keyword").css("top", offset.top + 22).css("left",
                        offset.left - ipt1.width()-13).css("width",ipt1.width()+ipt2.width()+14).slideDown();
		$('.visa_type_avil>li').click(function(e){
			ipt1.val($(this).text());
			$(this).addClass("on");
			$(this).siblings('.on').removeClass('on');
			$(".pop_keyword").hide();
		});
		stopBubble(e);
		return false;
	});
	
//	,function(e){
//		$(".pop_keyword").slideUp();
//		stopBubble(e);
//	}
	
	$(".show_more_for_j").hover(function(){
		var offset = $(this).parent("td").offset();
		var html = $(this).siblings("span").html();
		$('<div class="pop_take_address"></div>').appendTo(document.body);
		$(".pop_take_address").css("left",offset.left).css("top",offset.top).html(html);
	},function(){
		$(".pop_take_address").remove();
	});
	
	$(".vias_type_for_j").click(function(){
		$(".visa_every").children("table").hide();
		handleVisaType();
		if(this.checked){
			var val = this.value;
			var cur=$(".visa_type_"+val);
			cur.insertAfter(".filter_panel").children("table").show();
		}
		
	});
	
	if(type && type.match(/\d+/)){
		var resu = $(".vias_type_for_j").filter('[value*='+type+']');
		resu.attr("checked","checked");
		resu.trigger("click");
		resu.attr("checked","checked");
	}else{
		//$(".vias_type_for_j").attr("checked","checked");
	}
	
//	$(".by_phone").click(function(e){
//		$("tr.tel").remove();
//		var temp = $(this).parent().parent().parent();
//		var czz = temp.attr("class");
//		if(czz && czz.indexOf("on")>-1){
//			temp.removeClass("on");
//		}else{
//			temp.addClass("on");
//			var cur = $(this).parent().parent().parent();
//			var phone = $(this).attr("val");
//			$(phone_tmp.replace("#phone", phone)).insertAfter(cur);
//		}
//		return false;
//	});
	
	$(".by_phone").toggle(function(e){
		var tttt = $(this);
		var temp = tttt.parent().parent().parent();
		$("tr.tel").remove();
		temp.siblings(".on").removeClass("on");
		temp.addClass("on");
		var cur = temp;
		var phone = tttt.attr("val");
		$(phone_tmp.replace("#phone", phone)).insertAfter(cur);
		try {
			var re_pro = $(this).attr("title").replace(/查看(.*?)咨询电话/g, "$1");
			var re_phone = $(this).attr("val");
			_oyesgo_order_log("visa","by_phone",tttt.attr("log"));
		} catch (e) {
			//避免接口出错
		}
		stopBubble(e);
	},function(e){
		$("tr.tel").remove();
		stopBubble(e);
	});
	
	$(".by_url").click(function(){
		var jump = $(this).attr("val");
		var link = $(this).attr("link");
		link = jump + "&l="+ link.replace("\?","@");
		window.open(link, "_blank");
		try {
			_oyesgo_order_log("visa","by_url",$(this).attr("log"));
		} catch (e) {
			//避免接口出错
		}
		return false;
	});
	
	function buildFilterRegex(clazz){
		var ret = "(";
		var bak = "(";
		var flag = false;
		$(clazz).each(function(){
			var val = this.value;
			bak += val+"|";
			if(this.checked){
				flag = true;
				ret += val+"|";
			}
		});
		if(!flag){
			if(bak.lastIndexOf("\|")>0){
				bak =bak.substring(0, bak.lastIndexOf("\|"));
			} 
			return bak+")";
		}
		if(ret.lastIndexOf("\|")>0){
			ret =ret.substring(0, ret.lastIndexOf("\|"));
		} 
		return ret+")";
	}
	
	$(".filterable").click(function(){
		//$(this).siblings(".on").removeClass("on");
		//$(this).addClass("on");
	});
	
	$(".check_interview_for_j,.check_invit_for_j,.check_city_for_j").click(function(){
		var reg = buildFilterRegex(".check_interview_for_j")+buildFilterRegex(".check_invit_for_j")+".*?"+buildFilterRegex(".check_city_for_j");
		//alert(reg);
		var regex = new RegExp(reg);
		$(".filterable").each(function(){
			var key = $(this).attr("key");
			if(!key.match(regex)){
				$(this).hide();
			}else{
				$(this).show();
			}
		});
		handleVisaType();
	});
    
});

function c_type(e, t) {
	stopBubble(e);
	if(t.prev().attr("checked")){
		//相邻的上一个元素
		t.prev().removeAttr("checked");  
		t.prev().trigger("click");
		t.prev().removeAttr("checked");  
	}else {
		t.prev().attr("checked","checked");
		t.prev().trigger("click"); 
		t.prev().attr("checked","checked");
	}
}
