﻿/// <reference path="jquery-1.6.4-vsdoc.js"/>


$(document).ready(function ()
{

   // RightBottomAD();

});



function RightBottomAD()
{
    /// <summary>右下角广告</summary>

    var ADobj = "";
    ADobj += '<div style="border: 1px solid Silver; width: 155px; height: 17px; position: fixed;';
    ADobj += '    right: 0; bottom: 0; background-color: #FFFF99;">';
    ADobj += '    招商热线：0595-22987777';
    ADobj += '</div>';
    $(form1).append(ADobj);
}





//------------------------------------------------------------------------------------------------------------------------------------
///发表评论
function PostComment()
{
    var comment = '{ "vComment": { "ID": "", "Title": "' + $("#textfield").val() + '", "Content": "' + $("#textarea").val() + '", "Guest": "' + $("#textfield2").val() + '", "Email": "' + $("#textfield3").val() + '", "Telephone": "' + $("#textfield4").val() + '", "Handphone": "' + $("#textfield5").val() + '", "ValidCode": "' + $("#textfield6").val() + '"} }';

    $.ajax({
        type: 'Post',
        url: 'PageService.svc/GuestComment',
        contentType: 'text/json',
        data: comment,
        success: function (msg)
        {
            alert(msg.d);
            ResetValidCode();
        },
        error: function (e)
        {
            alert("系统出错,请稍后再试.");
        }
    });
}

///重置评论
function ResetComment()
{
    $("#textfield").val("");
    $("#textarea").val("");
    $("#textfield2").val("");
    $("#textfield5").val("");
    $("#textfield4").val("");
    $("#textfield6").val("");
    $("#textfield3").val("");
    ResetValidCode();
}
///重置验证码
function ResetValidCode(sender)
{
    $(sender).attr("src", "../PageService.svc/ValidCode?" + Math.random());
}

///图片有关的.还不知什么作用.
function fixPNG(sender)
{

}

//焦点新闻
function FocuseNews(ImgList)
{

    ///大小
    var focus_width = 242
    var focus_height = 204
    var text_height = 24
    var swf_height = focus_height + text_height

    //新闻有关.
    var pics = "";
    var links = "";
    var texts = "";

    for (var i = 0; i < ImgList.length; i++)
    {
        var imgTmp = ImgList[i];
        if (pics)
        {
            pics += "|";
        }
        if (links)
        {
            links += "|";
        }
        if (texts)
        {
            texts += "|";
        }
        pics += imgTmp.ImgURL;
        links += imgTmp.Link;
        texts += imgTmp.Text;

    }

    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + focus_width + '" height="' + swf_height + '">');
    document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="images/focus2.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">');
    document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
    document.write('<param name="FlashVars" value="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '">');
    document.write('</object>');
}

///对选手进行投票
function VoteSinger(SingerID)
{
    /// <summary>对选手进行投票</summary>
    /// <param name="Singer" type="String">选手ID Guid格式</param>
    var parms = '{ "SingerID": "' + SingerID + '" }';
    $.ajax({
        type: 'Post',
        url: 'PageService.svc/VoteSinger',
        contentType: 'text/json',
        data: parms,
        success: function (msg)
        {
            alert(msg.d);
        },
        error: function (e)
        {
            alert("系统出错,请稍后再试.");
        }
    });

}


///对歌曲进行投票
function VoteSong(SongID)
{
    /// <summary>对歌曲进行投票</summary>
    /// <param name="SongID" type="String">歌曲ID Guid格式</param>
    var parms = '{ "SongID": "' + SongID + '" }';
    $.ajax({
        type: 'Post',
        url: 'PageService.svc/VoteSong',
        contentType: 'text/json',
        data: parms,
        success: function (msg)
        {
            alert(msg.d);
        },
        error: function (e)
        {
            alert("系统出错,请稍后再试.");
        }
    });

}
///获取腾讯微博信息
function GetTencentMicroBlogsInfo()
{/// <summary>获取腾讯微博信息</summary>

    $.ajax({
        type: 'Post',
        url: 'PageService.svc/TencentMicroBlosgFocus',
        contentType: "text/json; charset=utf-8",
        data: null,
        success: function (msg)
        {
            var obj = (eval("[" + msg.d + "]"))[0];
            if (obj.ret == 0 && obj.msg == "ok")
            {
                ///获取成功
                var infos = obj.data.info;
                for (var i = 0; i < infos.length; i++)
                {
                    var info = infos[i];


                    Math.random()


                    var htm = "";
                    htm += '<table width="88%" border="0" align="center" cellpadding="0" cellspacing="0" style="line-height: 17px;border-bottom: 1px #ccc dashed; margin-top: 8px; margin-bottom: 5px; padding-bottom: 4px;">';
                    htm += '    <tr>';
                    htm += '        <td colspan="2">';
                    htm += '            <img src="' + info.head + '/50" width="50" height="49" align="left" style="padding-right: 5px;" /><span';
                    htm += '                class="red12"><a href="http://t.qq.com/' + info.name + '" target="_blank">' + info.nick + '</a>：</span>' + info.text;
                    htm += '        </td>';
                    htm += '    </tr>';
                    htm += '    <tr>';
                    htm += '        <td width="63%">';
                    htm += '            ' + new Date(info.timestamp * 1000).toLocaleString();
                    htm += '        </td>';
                    htm += '        <td width="37%" align="right" class="red12">';
                    htm += '            <a href="http://t.qq.com/p/t/' + info.id + '" target="_blank">评论</a>';
                    htm += '        </td>';
                    htm += '    </tr>';
                    htm += '</table>';
                    $("#TencentMicroBlogsArea").append(htm);
                }
            }
        },
        error: function (e)
        {
            alert("获取腾讯微博出错.");

        }
    });
}
///验证 在确认验证通过后提交form
function ValidateAndConfirm(form)
{
    /// <summary>验证 在确认验证通过后提交form</summary>
    /// <param name="form" type="Form">要验证并提交的表单</param>
    var result = $("#form1").validationEngine("validate");
    if (result)
    {
        form.submit();
    }
}


///检查选手后台登陆名是否可用.
function CheckLoginName(field, rules, i, options)
{
    /// <summary>检查选手后台登陆名是否可用</summary>
    /// <returns type="bool"/>


    var loName = field[0].value;
    var parms = '{ "LoginName": "' + loName + '" }';
    var result;
    $.ajax({
        type: 'Post',
        url: 'PageService.svc/CheckLoginName',
        contentType: 'text/json',
        data: parms,
        async: false,
        success: function (msg)
        {
            result = msg.d;
        },
        error: function (e)
        {
            result = false;
            alert("系统出错,请稍后再试.");
        }
    });
    options.isError = !result;
    if (options.isError)
    {
        return "* 登陆名不可用.";
    }

}

function CheckPassportNoIsOnly(field, rules, i, options)
{
    /// <summary>检查身份证唯一</summary>

    var psNo = field[0].value;
    var parms = '{ "PassportNo": "' + psNo + '" }';
    var result;
    $.ajax({
        type: 'Post',
        url: 'PageService.svc/CheckPassportNoIsOnly',
        contentType: 'text/json',
        data: parms,
        async: false,
        success: function (msg)
        {
            result = msg.d;
        },
        error: function (e)
        {
            result = false;
            alert("系统出错,请稍后再试.");
        }
    });
    options.isError = !result;
    if (options.isError)
    {
        return "* 身份证重复.";
    }


}


function RegistTwo()
{
    /// <summary>注册按钮二.</summary>



    var result = jQuery('#form1').validationEngine('validate');
    if (result)
    {
        var login = '{ "LoginName": "' + $("#LoginName").val() + '", "Password": "' + $("#Password").val() + '" }';
        var participant = '{ "Address": "' + $("#Address").val() + '", "Birthday": "' + $("#Birthday").val() + '", "ChineseZodiac": "' + $("#ChineseZodiac").val() + '", "Constellation": "' + $("#Constellation").val() + '", "EducationBackground": "' + $("#EducationBackground").val() + '", "Email": "' + $("#Email").val() + '", "Handphone": "' + $("#Handphone").val() + '", "HeadPortraitURL": "",  "Location": "' + $("#Location").val() + '", "Name": "' + $("#ParticipantName").val() + '", "Nationality": "' + $("#Nationality").val() + '", "NativePlace": "' + $("#NativePlace").val() + '", "Organizer": "' + $("#Organizer").val() + '", "PassportNo": "' + $("#PassportNo").val() + '", "PostCode": "' + $("#PostCode").val() + '", "QQOrMSN": "' + $("#QQOrMSN").val() + '", "RaceArea": "' + $("#RaceArea").val() + '", "SerialNumber": "' + $("#SerialNumber").val() + '", "Sex": "' + $("#Sex").val() + '", "Telephone": "' + $("#Telephone").val() + '", "TencentMicroBlog": "' + $("#TencentMicroBlog").val() + '" }';
        var participantRaceInfo = '{ "AuditionsWay": "' + $('[name="AuditionsWay"][checked=true]:radio').val() + '", "HobbyOrTalent": "' + $("#HobbyOrTalent").val() + '", "LikeFastMusicOrSlowSong": "' + $('[name="LikeFastMusicOrSlowSong"][checked=true]:radio').val() + '", "LikeMinNanSongType": "' + $("#LikeMinNanSongType").val() + '", "Linkman": "' + $("#relativeName").val() + '", "LinkmanPhone": "' + $("#relativePhone").val() + '", "MinNanSongTutor": "' + $("#MinNanSongTutor").val() + '", "MostFavoriteMinNanSingerAndSong": "' + $("#MostFavoriteMinNanSingerAndSong").val() + '", "OtherPreviousEntryExperience": "' + $("#OtherPreviousEntryExperience").val() + '", "PreviousEntryExperience": "' + $("#PreviousEntryExperience").val() + '", "Slogan": "' + $("#Slogan").val() + '", "StudyMinNanSongTime": "' + $("#StudyMinNanSongTime").val() + '", "TencentMicroBlogNickname": "' + $("#TencentMicroBlogNickname").val() + '", "Remark": "' + $("#Remark").val() + '" }';

        var parms = '{ "login":' + login + ', "participant": ' + participant + ', "RaceInfo":' + participantRaceInfo + ' }';

        $.ajax({
            type: 'Post',
            url: 'PageService.svc/RegisterParticipant',
            contentType: 'text/json',
            data: parms,
            async: false,
            success: function (msg)
            {
                if (msg.d)
                {
                    alert("注册成功.");
                    window.open("ParticipantBackground/ParticipantLogin.aspx");
                }
                else
                {
                    alert("注册失败请重试.");
                }
            },
            error: function (e)
            {
                result = false;
                alert("系统出错,请稍后再试.");
            }
        });

    }
}


