/**
 * [OElove] (C)2010-2099 OELOVE.COM Inc.biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2017/01/19 by CL $
*/
$(function(){
	//选择地区
	$("[f='but_open_citybox']").bind("click", function(){
		if ($(this).parent().hasClass("current")) {
			$(this).parent().removeClass("current");
		}
		else {
			$(this).parent().addClass("current");
		}
	});

	//搜索选择器
	$(document).on("click", "[f='but_selser']", function(){
		$_dd = $(this).next("dd");
		if ($_dd.css("display") == "none") {
			$(this).parent().addClass("current");
			$_dd.show();
		}
		else {
			$(this).parent().removeClass("current");
			$_dd.hide();
		}
	});
	
	//点击空白出隐藏选择器
	$(document).on("click", function(e){
		var target1  = $(e.target);
        if(target1.closest(".oe_index_search dl").length == 0){
			$(".oe_index_search dl dd").hide();
			$(".oe_index_search dl").removeClass("current");
		}
	});

	//下拉选1项 change
	$(document).on("change", "[f='but_sel_one']", function(){
		$_val = $(this).find("option:selected").val();
		$_text = $(this).find("option:selected").text();
		$_tips_text = $(this).attr("data-tips");
		if (typeof($_tips_text) == "undefined") {
			$_tips_text = "不限";
		}
		if ($_text == "=不限=") {
			$_text = $_tips_text;
		}
		$(this).parent().prev().children("em").html($_text);
		$(this).parent().hide();
		$(this).parent().parent().removeClass("current");
	});

	//范围确定选择2项
	$(document).on("click", "[f='but_selrange_confirm']", function(){
	
		$_data_1 = $(this).attr("data-1");
		$_data_2 = $(this).attr("data-2");
		$_data_unit = $(this).attr("data-unit");
		$_data_tips = $(this).attr("data-tips");
		if (typeof($_data_unit) == "undefined") {
			$_data_unit = "";
		}
		if (typeof($_data_tips) == "undefined") {
			$_data_tips = "";
		}
		$_val1 = $("#"+$_data_1).find("option:selected").val();
		$_text1 = $("#"+$_data_1).find("option:selected").text();
		$_val2 = $("#"+$_data_2).find("option:selected").val();
		$_text2 = $("#"+$_data_2).find("option:selected").text();

		if ($_val1 > 0 && $_val2 > 0) {
			$_text = $_text1+$_data_unit+"-"+$_text2+$_data_unit;
		}
		else {
			$_text = $_data_tips;
		}
		$(this).parent().prev().children("em").html($_text);
		$(this).parent().hide();
		$(this).parent().parent().removeClass("current");

	});

	//搜索按钮
	$(document).on("click", "[f='but_confirm_userser']", function(){
		$("#user_form").submit();
	});

	//提交登录
	$("[f='but_submit_login']").bind("click", function(){
		$_loginname = $("#index_loginname").val();
		$_password = $("#index_password").val();
		if ($_loginname.length == 0) {
			ToastShow("请输入用户名/手机号/邮箱");
			return false;
		}
		if ($_password.length == 0) {
			ToastShow("请输入登录密码");
			return false;
		}

		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?c=passport",
			cache: false,
			data: {a:"loginpost", loginname:$_loginname, password:$_password, fromtype:"top", r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") { //成功，返回页面
					$forward = "";
					if ($forward.length == 0) {
						$forward = _ROOT_PATH+"index.php?m=user";
					}
					window.location.href = $forward;					
				}
				else if ($response == "2") { //整合OEmarry
					window.top.location.href = $result;
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("登录失败，请检查帐号密码是否正确");
					}
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});


	});

});