﻿var host = "http://www.2wgame.cn";
var ip;
function get_ip(s)
{
    ip=s;
}

var status_comm=false;

$.getScript(host+"/vote/ip.php");

function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

function copyToClipBoard()
{
    try
    {
        var clipBoardContent="";
        clipBoardContent+=this.location.href;
        window.clipboardData.setData("Text",clipBoardContent);
        alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");
    }
    catch(e){}
}

$.ajax(
{
    type: "POST",
    url: host+'/templets/findgame/comment.php',
    data: 'aid='+aid+'&pg=1',
    success: function(result)
    {
        var arr=result.split('$#@');
        $('#div_comment').html(arr[0]);
        $('#cnum').text(arr[1]);
    }
});

if(typeof(filename)!="undefined"){
	var flashplay = '<div style="text-align:center"><object id="videoPlayer" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" height="400" width="550" align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="sameDomain" name="allowScriptAccess" /><param value="true" name="allowFullScreen" /><param value="'+host+'/templets/flash/videoPlayer.swf" name="movie" /><param value="high" name="quality" /><param value="#000000" name="bgcolor" /><param value="htmlPage=index.html" name="flashvars" /></object></div>';
	$.ajax(
	{
		type: "POST",
		url: host+'/templets/findgame/deploy_xml.php',
		data: 'filename='+filename+'',
		success: function(result)
		{
			$('#flashplay').html(flashplay);
		}
	});
}

function loadComment(page)
{
    $.ajax(
    {
        type: "POST",
        url: host+'/templets/findgame/comment.php',
        data: 'aid='+aid+'&pg='+page,
        success: function(result)
        {
            var arr=result.split('$#@');
            $('#div_comment').html(arr[0]);
            $('#cnum').text(arr[1]);
            location='#a_comment';
        }
    });
}

function addComment()
{
    $('#div_msg').show();
    var msg=$.trim($('#msg').val());
    arctitle=arctitle.replace('《','');
    arctitle=arctitle.replace('》','');
    if(status_comm)
    {
        $('#div_msg').text('您评论的速度过快!');
        return;
    }
    if(msg=='')
    {
        $('#div_msg').text('请输入评论内容!');
        return;
    }
    $('#div_msg').html('正在提交评论...');
    $.ajax(
    {
        type: "POST",
        url: host+'/templets/findgame/comment.php',
        data: 'aid='+aid+'&username='+$('#username').val()
+'&msg='+msg+'&arctitle='+arctitle+'&url='+location.href+'&ip='+ip,
        success: function(result)
        {
            $('#div_msg').hide();
            loadComment(1);
            $('#username').val('');
            $('#msg').val('');
            status_comm=true;
        }
    });
}

$(function()
{
    $('body').keydown(function(e)
    {
        if(e.keyCode==13&&e.ctrlKey)
        {
            addComment();
        }
    });
});