﻿jQuery(function($) {
    hoverImg_mom();
    $(".form_text").bind("focus", form_text_focus);
    $(".inputtip").bind("click", from_tip_focus);
    $(".form_text").bind("blur", form_text_blur);
    $(".form_bog").css({ backgroundPosition: "-20px 35px" })
	.mouseover(function() {
	    $(this).stop().animate({ backgroundPosition: "(-20px 94px)" }, { duration: 500 })
	})
	.mouseout(function() {
	    $(this).stop().animate({ backgroundPosition: "(40px 35px)" }, { duration: 200, complete: function() {
	        $(this).css({ backgroundPosition: "-20px 35px" })
	    }
	    })
	});
    $('#reg_bt').bind("click", function() {
        window.location.href = "Register.aspx?url=Home.aspx";
    });
    $("#cls").bind("click", tipClose);
    $.ajax({
        url: "Home.aspx/CookieLogin",
        data: "{}",
        success: CookieLogin
    });
    $("#lg_bt").bind("click", Login)

    $("#ad_turnuser").bind("click", turnUser);
    $("#sh_bt").bind("click", reSearch);

    $("#n_more,#h_more").hover(
      function() { $("#h_more").show(); },
      function() { $("#h_more").hide(); }
    );
    $("body>a[href='http://www.51.la/?002328652']").hide();
});

var username = "";

var reSearch = function(){
    var st_id = $("#ctl00_Dp_StartId").get(0).selectedIndex+1;
    var query = $("#ads_search").val();
    location.href = "/SearchList.aspx?query="+query+"&sdd="+st_id;
}

var Login = function(){
    loginstr = $('#lg_name').val();
    if($('#lg_fav').attr("value")){
        var iscookie = 1;
    } else {
        var iscookie = 0;
    }
    pwd = $('#lg_pwd').val();
    $.ajax({
        url: "Home.aspx/SubLogin",
        data: "{'loginstr':'" + loginstr + "','pwd':'" + pwd + "','iscookie':'" + iscookie + "'}",
        success: se_Login
    });
}
var se_Login = function(m){
    if(m.d == "0"){
        //TurnAdminBox(true);
        tipdiv("用户或密码错误");
    } else {
        $("#huname").text(m.d);
        TurnAdminBox(false);
    }
}
var haduser = 0;
var CookieLogin = function(m){
    if(m.d == "0"){
        TurnAdminBox(true);
    } else {
        $("#huname").text(m.d);
        TurnAdminBox(false);
        haduser = 1;
    }
}
var turnUser = function(){
    TurnAdminBox(true);
    $.ajax({
        url: "Home.aspx/Logout",
        data: "{}"
    });
}
function hoverImg_mom() {
    $('.from_bt').hover(
      function() {$(this).addClass("from_bt_hover");},
      function() {$(this).removeClass("from_bt_hover");}
    );
}

var from_tip_focus = function() {
    $(this).hide();
    $(this).prev(".form_text").addClass("form_text_focus").focus();
}
var form_text_focus = function() {
    $(this).next(".inputtip").hide();
    $(this).addClass("form_text_focus");
    var id = $(this).attr("id");
    if (id == "lg_name" || id == "lg_pwd") {
        $(this).bind('keydown', 'return', function() {
            Login();
        });
    }
}
var form_text_blur = function() {
    if ($(this).val() == "") {
        $(this).next(".inputtip").show();
        $(this).removeClass("form_text_focus");
    }
}
var initcaptcha = true;
//var TurnAdminBar = function() {
//    if (initcaptcha) {
//        $(".ajax-fc-container").captcha();
//        initcaptcha = false;
//    }
//    if ($("#admin_box").css("top") == "0px") {
//        if (window.XMLHttpRequest) {
//            $("#admin_box").animate({
//                top: "-215px"
//            }, 1000);
//        } else {
//            $("#admin_box").animate({
//                top: "-220px"
//            }, 1000);
//        }
//        $('#reg_bt').text("注 册");
//    } else {
//        $("#admin_box").animate({
//            top: "0px"
//        }, 1000);
//        $('#reg_bt').text("↑ 关闭 ↑");
//    }
//}
var TurnAdminBox = function(x){
    if(x){
        $("#unUser").show();
        $("#hasUser").hide();
    } else {
        $("#unUser").hide();
        $("#hasUser").show();
    }
}

$.ajaxSetup({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    async: false
});
var ConvertJson = function(m) {
    var json = m.d;
    var value = eval("(" + json + ")");
    return value;
}

var checkFram = function (title,mouseX,mouseY){
    $("#checkFram").css({ display: "block", top: mouseY+14, left: mouseX-70 });
    $("#ckf_title").text(title);
    $("#ckf_yes").unbind();
}
var tipdiv = function(text){
    $("#st-con").empty().text(text);
    $("#s-tip").show();
    var timer = setTimeout(tipClose,2000);
}
var tipClose = function (){
    $("#s-tip").fadeOut("slow");
}

function request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
}