// JavaScript Document
/// <reference path="jQuery.js" />
var I_Blur = "blur"
var I_Focus = "focus"
var I_Change = "change"
////////////////////////////////////////////////////////
function JS_CheckInput_Search(obj, action) {
    switch (action) {
        case I_Blur:
            obj.style.borderColor = "#cccccc"
            if (trim(obj.value) == "") {
                obj.style.backgroundImage = "url(Statics/Images/UI.gif)"
            }
            break
        case I_Focus:
            obj.style.borderColor = "#ff0084"
            obj.style.backgroundImage = "none"
            break
        case I_Change:
            break
        default:
            alert("default");
    }
}
////////////////////////////////////////////////////////
//首页  循环显示图片JS  与 图片专辑交互特效//////////////////
////////////////////////////////////////////////////////
function ShowMoreAlbum(obj, switchID) {  //显示更多推荐的图标
    if (switchID == 1) {
        $(obj).css({ "background": "url(Statics/Images/UI.gif) 0px -30px", "color": "#0066cc" })
    } else {
        $(obj).css({ "background": "url(Statics/Images/UI.gif) -18px -30px", "color": "#cacaca" })
    }
}
function FocusItem(obj, id, count, switchID, ATitle) {  //淡化不在鼠标范围的职业专辑
    if (switchID == 1) {
        for (j = 1; j <= count; j++) {
            if (j == id) {
                $("#" + obj + j).stop().fadeTo(300, 1)
                $("#" + ATitle + j + " a").css({ "color": "#0066cc" })
            } else {
                $("#" + obj + j).stop().fadeTo(300, .2)
                $("#" + ATitle + j + " a").css({ "color": "#666666" })
            }
        }
    } else {
        for (j = 1; j <= count; j++) {
            $("#" + obj + j).stop().fadeTo(600, 1)
            $("#" + ATitle + j + " a").css({ "color": "#666666" })
        }
    }
}
//循环显示图片JS  与 图片专辑交互特效
var t = n = 0, count;
function RotateStyle() {
    $("#ThumbList li:first").css({ "background": "url(Statics/Images/UI.gif) 0 -23px" })
    count = $("#ImgList a").length;
    if (count > 1) {
        $("#ImgList a:not(:first-child)").hide();
        $("#TitleList a:not(:first-child)").hide();
        $("#ThumbList li").click(function () {
            var i = $(this).text() - 1;
            n = i;
            if (i >= count) return;
            $("#ImgList a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
            $("#TitleList a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
            $(this).css({ "background": "url(Statics/Images/UI.gif) 0 -23px" }).siblings().css({ "background": "url(Statics/Images/UI.gif) -6px -23px" });
        });
        t = setInterval("showAuto()", 5000);
        $("#ImgList").hover(function () { clearInterval(t) }, function () { t = setInterval("showAuto()", 5000); });
        $("#TitleList").hover(function () { clearInterval(t) }, function () { t = setInterval("showAuto()", 5000); });
        $("#ThumbList li").hover(function () { clearInterval(t) }, function () { t = setInterval("showAuto()", 5000); });

        $('#Member .GrounpItem ul.ThumbList li').Zoomer({ speedView: 100, speedRemove: 300, debug: false, animSwitch: true, marginTop: 65, marginLeft: 65, ZoomWidth: 100, ZoomHeight: 100, width: 80, height: 80, padding: 15 });
        //推荐专辑动作特效
        $("#FAI1").mouseover(function () { FocusItem("FAI", 1, 3, 1, "FATitle") });
        $("#FAI2").mouseover(function () { FocusItem("FAI", 2, 3, 1, "FATitle") });
        $("#FAI3").mouseover(function () { FocusItem("FAI", 3, 3, 1, "FATitle") });
        $("#FAI1").mouseout(function () { FocusItem("FAI", 1, 3, 0, "FATitle") });
        $("#FAI2").mouseout(function () { FocusItem("FAI", 2, 3, 0, "FATitle") });
        $("#FAI3").mouseout(function () { FocusItem("FAI", 3, 3, 0, "FATitle") });
        //普通专辑动作特效
        $("#AI1").mouseover(function () { FocusItem("AI", 1, 6, 1, "ATitle") });
        $("#AI2").mouseover(function () { FocusItem("AI", 2, 6, 1, "ATitle") });
        $("#AI3").mouseover(function () { FocusItem("AI", 3, 6, 1, "ATitle") });
        $("#AI4").mouseover(function () { FocusItem("AI", 4, 6, 1, "ATitle") });
        $("#AI5").mouseover(function () { FocusItem("AI", 5, 6, 1, "ATitle") });
        $("#AI6").mouseover(function () { FocusItem("AI", 6, 6, 1, "ATitle") });
        $("#AI1").mouseout(function () { FocusItem("AI", 1, 6, 0, "ATitle") });
        $("#AI2").mouseout(function () { FocusItem("AI", 2, 6, 0, "ATitle") });
        $("#AI3").mouseout(function () { FocusItem("AI", 3, 6, 0, "ATitle") });
        $("#AI4").mouseout(function () { FocusItem("AI", 4, 6, 0, "ATitle") });
        $("#AI5").mouseout(function () { FocusItem("AI", 5, 6, 0, "ATitle") });
        $("#AI6").mouseout(function () { FocusItem("AI", 6, 6, 0, "ATitle") });
    } else {
        
        $("#ThumbList").remove()
    }
}

function showAuto() { //自动循环显示图片JS
    n = n >= (count - 1) ? 0 : ++n;
    $("#ThumbList li").eq(n).trigger('click');
}

function ScrollPage(id) {
    var target = $('#' + id);
    target.get(0) ? $(document.body).animate({ scrollTop: target.offset().top }, 1000) : null;
    return false;
}

function SetCookie() {
    if (document.SignInForm.CookieSwitch.value == 0) {
        document.SignInForm.CookieSwitch.value = 1
        $("#CookieSwitchIcon").css({ "background": "url(Statics/Images/UI.gif) -443px -209px" })
        $("#CookieSwitchText").css({ "color": "#666666" })
    } else {
        document.SignInForm.CookieSwitch.value = 0
        $("#CookieSwitchIcon").css({ "background": "url(Statics/Images/UI.gif) -443px -200px" })
        $("#CookieSwitchText").css({ "color": "#999999" })
    }
}

function CheckAccountIDInput(obj) {
    if (event.keyCode == 32) {
        return false; //
    } else {
        //正则表达式
    }
}


function AllCheck(obj) {
    //将全角转换为半角//////////////////////////////////////////////////////////////////////////////////////////////
    var str = obj.value;
    var result = "";
    for (var i = 0; i < str.length; i++) {
        code = str.charCodeAt(i); //获取当前字符的unicode编码
        if (code >= 65281 && code <= 65373)//在这个unicode编码范围中的是所有的英文字母已经各种字符
        {
            var d = str.charCodeAt(i) - 65248;
            result += String.fromCharCode(d); //把全角字符的unicode编码转换为对应半角字符的unicode码
        }
        else if (code == 12288)//空格
        {
            var d = str.charCodeAt(i) - 12288 + 32;
            result += String.fromCharCode(d);
        }
        else {
            result += str.charAt(i);
        }
    }
    obj.value = result;
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    //判断是否输入中文//////////////////////////////////////////////////////////////////////////////////////////////
    if (/.*[\u4e00-\u9fa5]+.*$/.test(obj.value)) {
        obj.value = obj.value.replace(/[\u4e00-\u9fa5]/g, '')
        document.SignInForm.AccountID.focus();
        $(".Notice_ac").css({ "height": "0px", "display": "block" })
        $(".Notice_ac").animate({ "height": "25px" }, 500);
        $(".Notice_pw").animate({ "height": "0px" }, 500);
        $(".Notice_ac").html("不能输入中文字符!")
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    //判断是否特殊符号//////////////////////////////////////////////////////////////////////////////////////////////
    var s = obj.value;
    var pattern = new RegExp("[\\\\`~!#$%^&*()=|{}':;',\\[\\]<>/?+~！#￥……&%*（）——|{}【】'；：“”'。，、？、‘\"·]");
    var rs = "";
    if (pattern.test(s)) {
        for (var i = 0; i < s.length; i++) {
            rs = rs + s.substr(i, 1).replace(pattern, '');
        }
        obj.value = rs;
        document.SignInForm.AccountID.focus();
        $(".Notice_ac").css({ "height": "0px", "display": "block" })
        $(".Notice_ac").animate({ "height": "25px" }, 500);
        $(".Notice_pw").animate({ "height": "0px" }, 500);
        $(".Notice_ac").html("不能输入@_-.以外的特殊符号!")
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
////////////身高/重量单位转换///////////////////////////////////////////////////////////////////////////////////////
function turn_H() {
    var num = document.getElementById("detailed_H").innerHTML;
    if (num == "&nbsp;" || num == " " || num == "") {
        alert("没有数据转换！");
    } else {
        itum = num.split(" ");
        if (itum[1] == "cm") {
            newNum = itum[0] * (50 / 127);
            document.getElementById("detailed_H").innerHTML = parseInt(newNum) + " 英寸";
        } else if (itum[1] == "英寸") {
            newNum = itum[0] * 2.54;
            document.getElementById("detailed_H").innerHTML = parseInt(newNum) + " cm";
        }
    }
}
function turn_W() {
    var num = document.getElementById("detailed_W").innerHTML;
    if (num == "&nbsp;" || num == " " || num == "") {
        alert("没有数据转换！");
    } else {
        itum = num.split(" ");
        if (itum[1] == "kg") {
            newNum = itum[0] * (20 / 9);parseInt
            document.getElementById("detailed_W").innerHTML = parseInt(newNum) + " 磅";
        } else if (itum[1] == "磅") {
            newNum = itum[0] * 0.45;
            document.getElementById("detailed_W").innerHTML = parseInt(newNum) + " kg";
        }
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////l_signup_page.html改变背景位置/////////////////////////////////////////////////////////////////////
function EnglishName(obj, state) {
    if (state == "onclick") {
        if (obj.value == "") {
            $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -378px" })
        }
    } else if (state == "onkeydown") {
        $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -460px" })
    } else if (state == "onblur") {
        if (obj.value == "") {
            $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -351px" })
        }
    }
}

function Email(obj, state) {
    if (state == "onclick") {
        if (obj.value == "") {
            $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -429px" })
        }
    } else if (state == "onkeydown") {
        $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -460px" })
    } else if (state == "onblur") {
        if (obj.value == "") {
            $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -404px" })
        }
    }
}

function PWinput(obj, state) {
    if (state == "onclick") {
        if (obj.value == "") {
            $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -131px" })
        }
    } else if (state == "onkeydown") {
        $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -231px" })
    } else if (state == "onblur") {
        if (obj.value == "") {
            $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -156px" })
        }
    }
}

function CPWinput(obj, state) {
    if (state == "onclick") {
        if (obj.value == "") {
            $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -181px" })
        }
    } else if (state == "onkeydown") {
        $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -231px" })
    } else if (state == "onblur") {
        if (obj.value == "") {
            $(obj).css({ "background": "url(Statics/Images/Login/UI.gif) 0 -206px" })
        }
    }
}
//////////////////////
/// 改变背景图片位置
/// obj:触发对象
/// event:触发事件
/// position:重置位置
//////////////////////
function change(obj, event, position) {
    var error = { color: 'red', 'font-weight': 'bold' };
    switch (event) {
        case 'click':
            if (obj.value == '') obj.style.backgroundPosition = '0px ' + position + 'px';
            break;
        case 'keydown':
            obj.style.backgroundPosition = '0px ' + position + 'px';
            break;
        case 'blur':
            if (obj.value == '') obj.style.backgroundPosition = '0px ' + position + 'px';
            else if (obj.value != '' && obj.name == 'LoginName') {
                //登录名必须为字母开头，有中划线，字母，数字
                if (/^[a-zA-Z][A-Za-z0-9]{4,11}$/.test(obj.value)) {
                    $.ajax({
                        type: "POST",
                        url: "L_SignUp.aspx/ExistsName",
                        data: "{'loginName':'" + obj.value + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if (data.d) {
                                $('div.Free:eq(0)').css(error).text('*用户名已存在,请重新输入');
                                obj.value = '';
                            } else {
                                $('div.Free:eq(0)').css({ color: 'green', 'font-weight': 'bold' }).text('*√');
                            }
                        }
                    });
                } else {
                    obj.value = '';
                    obj.focus();
                    $('div.Free:eq(0)').css(error).text('*请输入合法的用户名');
                }
            } else if (obj.value != '' && obj.name == 'Email') {
                if (/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(obj.value)) {
                    $.ajax({
                        type: "POST",
                        url: "L_SignUp.aspx/ExistsEmail",
                        data: "{'email':'" + obj.value + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if (data.d) {
                                $('div.Free:eq(1)').css(error).text('*邮箱已注册,请重新输入');
                                obj.value = '';
                            } else {
                                $('div.Free:eq(1)').css({ color: 'green', 'font-weight': 'bold' }).text('*√');
                            }
                        }
                    });
                } else {
                    obj.value = '';
                    obj.focus();
                    $('div.Free:eq(1)').css(error).text('*请输入合法的邮箱');
                }
            } else if (obj.value != '' && obj.id == 'ConfirmPassword') {
                if (obj.value != document.getElementById('Password').value) {
                    obj.value = '';
                    obj.focus();
                    $('div.Free:eq(2)').css(error).text('*两次输入密码不一致');
                } else {
                    $('div.Free:eq(2)').css({ color: 'green', 'font-weight': 'bold' }).text('*√');
                }
            }
        default:
            break;
    }
}
// 验证用户输入是否合法
function valid_reg() {
    var account = $('#txtLoginName');
    var error = { color: 'red', 'font-weight': 'bold' };
    if (!/^[a-zA-Z]+[0-9]*/.test(account.val())) {
        account.val('');
        account.focus();
        $('div.Free:eq(0)').css(error).text('*请输入用户名');
        return false;
    }
    var email = $('#txtEmail');
    if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
        email.val('');
        email.focus();
        $('div.Free:eq(1)').css(error).text('*请输入邮箱');
        return false;
    }
    var password = $('#Password');
    var repwd = $('#ConfirmPassword');
    if (password.val() == '') {
        $('div.Free:eq(2)').css(error).text('*密码不能为空,请重新输入');
        return false;
    } else if (password.val() != repwd.val()) {
        $('div.Free:eq(2)').css(error).text('*两次输入密码不一致,请重新输入');
        password.val('');
        repwd.val('');
        return false;
    }
    return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////



//注册时获取最新信息
function SignUp_GetNews() {
    if (document.SignUpForm.GetNews.value == 0) {
        document.SignUpForm.GetNews.value = 1
        $("#GetNewsIcon").css({ "background": "url(Statics/Images/UI.gif) -443px -209px" })
        $("#GetNewsText").css({ "color": "#666666" })
    } else {
        document.SignUpForm.GetNews.value = 0
        $("#GetNewsIcon").css({ "background": "url(Statics/Images/UI.gif) -443px -200px" })
        $("#GetNewsText").css({ "color": "#999999" })
    }
}

function SubmitLogin() {
    if (trim(document.SignInForm.AccountID.value) == "") {
        document.SignInForm.AccountID.focus();
        $(".Notice_ac").css({ "height": "0px", "display": "block" })
        $(".Notice_ac").animate({ "height": "25px" }, 500);
        $(".Notice_pw").animate({ "height": "0px" }, 500);
        $(".Notice_ac").html("请输入用户名或电子邮件地址!")
    } else {
        if (trim(document.SignInForm.AccountID.value).length < 3) {
            $(".Notice_ac").css({ "height": "0px", "display": "block" })
            $(".Notice_ac").animate({ "height": "25px" }, 500);
            $(".Notice_pw").animate({ "height": "0px" }, 500);
            $(".Notice_ac").html("不存在的用户名或电子邮件地址!")
        } else {
            if (trim(document.SignInForm.Password.value) == "") {
                document.SignInForm.Password.focus();
                $(".Notice_ac").html("正确的输入!")
                $(".Notice_ac").animate({ "height": "0px" }, 500);
                $(".Notice_pw").css({ "height": "0px", "display": "block" })
                $(".Notice_pw").animate({ "height": "25px" }, 500);
                $(".Notice_pw").html("请输入6-12位密码!")
            } else {
                if (trim(document.SignInForm.Password.value).length < 6) {
                    document.SignInForm.Password.focus();
                    $(".Notice_ac").animate({ "height": "0px" }, 500);
                    $(".Notice_pw").animate({ "height": "25px" }, 500);
                    $(".Notice_pw").html("位数不足,请输入6-12位密码!")
                } else {
                    $(".Notice_ac").html("正确的输入!")
                    $(".Notice_pw").html("正确的输入!")
                    $(".Notice_pw").animate({ "height": "0px" }, 500);
                    $(".Notice_ac").animate({ "height": "0px" }, 500);
                    alert("ok")
                    document.SignInForm.AccountID.disabled = true;
                    document.SignInForm.Password.disabled = true;
                }
            }
        }
    }
}

//验证合法输入
function valid_login() {
    var form = document.SignInForm;
    var accountId = form.AccountID;
    var password = form.Password;
    var account = trim(accountId.value);
    var pwd = trim(password.value);
    if (account == '' || account.length < 3) {
        accountId.focus();
        $('div.Notice_ac').css({ 'height': '0px', 'display': 'block' }).animate({ 'height': '25px' }, 500).html('请输入合法的用户名或邮箱地址!');
        $('div.Notice_pw').animate({ 'height': '0px' }, 500);
        return false;
    } else if (pwd == '' || pwd.length < 6) {
        password.focus();
        $('div.Notice_pw').css({ 'height': '0px', 'display': 'block' }).animate({ 'height': '25px' }, 500).html('请输入6-12位密码!');
        $('div.Notice_ac').animate({ 'height': '0px' }, 500);
        return false;
    } else {
        $('div.Notice_ac').animate({ 'height': '0px' }, 500);
        $('div.Notice_pw').animate({ 'height': '0px' }, 500);
        return true;
    }
}

//获取.设置 浏览记录
function footprint() {
    var footprint = $.cookie('FOOTPRINT');
    var json = footprint ? $.parseJSON(footprint) : '';
    var title = document.title;
    var href = window.location.href;
    //window.console.log(footprint);
    if (!footprint) {
        footprint = '[{"title":"' + title + '","href":"' + href + '"}]';
        json = $.parseJSON(footprint);
    } else if (footprint.match(document.title) != null) {
        for (i in json) {
            if (json[i].title == title) {
                var temp = json[0];
                json[i].href = href;
                json[0] = json[i];
                for (j = 1; j <= i; j++) {
                    next = json[j];
                    json[j] = temp;
                    temp = next;
                }
                break;
            }
        }
    } else if (json.length == 5) {
        temp = { title: '', href: '' };
        for (i = 0; i < 5; i++) {
            next = json[i];
            json[i] = temp;
            temp = next;
        }
        json[0].title = title;
        json[0].href = href;
    } else if (json.length < 5) {
        footprint = '[{"title":"' + title + '","href":"' + href + '"},';
        for (i in json) {
            if (i != json.length - 1) {
                footprint += '{"title":"' + json[i].title + '","href":"' + json[i].href + '"},';
            } else {
                footprint += '{"title":"' + json[i].title + '","href":"' + json[i].href + '"}]';
            }
        }
        json = $.parseJSON(footprint);
    }
    footprint = '[';
    var foot_string;
    for (i in json) {
        if (i != json.length - 1) {
            footprint += '{"title":"' + json[i].title + '","href":"' + json[i].href + '"},';
        } else {
            footprint += '{"title":"' + json[i].title + '","href":"' + json[i].href + '"}]';
        }
        foot_string += '<a href="' + json[i].href + '">' + json[i].title + '</a><span>|</span>';
    }
    $("#spnFootprint").append($(foot_string));
    $.cookie('FOOTPRINT', footprint, { path: '/' });
}

//11-11-08 allen 增加-------
//职业选择下列菜单-------
function Cat_SelectBoxInit() {
    var PopWin = document.getElementById("SelectBox_PopWin");
    $(PopWin).remove();
    var title = $('#J_VSort>ul>li>a[class$="_ed"]').text();
    PopWin = "<div id='SelectBox_PopWin'>"
    PopWin += "<div class='topNotice' id='topNotice'><img src='Statics/Images/uro.gif' align='absmiddle' />" + title + "</div>"
    PopWin += "<div class='contentBox' id='contentBox'>"
    PopWin += "<ul id='contentBoxUL'>"
    var fatherLink = $('ul.VSortBox>li>a[class$="_ed"]').attr('href');
    for (i in ProfessionArray) {
        //console ? console.log(ProfessionArray[i][0] + '_' + ProfessionArray[i][1]) : null;
        PopWin += "<li id='contentBoxLI'><span>&#8226; </span><a href='" + fatherLink +"&childName="+ ProfessionArray[i][2] + "'>" + ProfessionArray[i][1] + "</a></li>";
    }
    PopWin += "</ul></div></div>"
    _PopWin = $(PopWin);
    var selectBox = $('div.SelectBox');
    _PopWin.css({ left: selectBox.offset().left - 292, top: selectBox.offset().top });
    $("#lemo-ta-cc").append(_PopWin);
    $(document).click(function (event) {
        if ((event.target.id) != "SelectBox_PopWin" && event.target.id != "SelectBox" && event.target.id != "contentBox" && event.target.id != "topNotice" && event.target.id != "contentBoxUL" && event.target.id != "contentBoxLI") {
            _PopWin.remove();
        }
    });
}
//异步加载数据
function push_data(u, p, id, d) {
    $.ajax({
        type: 'post',
        url: u,
        data: p,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            switch (d) { case 0: $('#' + id).append(data.d); break; case 1: $('#' + id).prepend(data.d); break; case 2: $('#' + id).after(data.d); break; case 3: $('#' + id).before(data.d); break; default: break; }
        }
    });
}
//异步加载数据
function ajax_request(u, p, fn) {
    $.ajax({
        type: 'post',
        url: u,
        data: p,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) { fn(data.d); }
    });
}
