﻿// JavaScript Document
var tbPlaySlider = false;
	
	function ChangePicture()
	{
		PictureIndex++;
		if (PictureIndex >= tnPictureCount)
		{
			PictureIndex = 0;
		}
		
		var GamePicture = document.getElementById("ctrl_img_GamePicture")
		GamePicture.style.filter = arrFilters[Math.round(Math.random() * (12))];
		
		GamePicture.filters[0].apply();
		GamePicture.setAttribute("src", arrPictures[PictureIndex]);
		GamePicture.filters[0].play();
		
		document.getElementById("ctrl_label_PicTitle").innerText = arrPictureTitle[PictureIndex];
		document.getElementById("ctrl_lable_PicturesIndex").innerText = PictureIndex + 1;
		
		if (tbPlaySlider == true)
		{
			setTimeout(ChangePicture, 5000, "JavaScript");
		}
	}
	
	var arrFilters = new Array(13);
	arrFilters[0] = "RevealTrans(duration=2,transition=23)";
	arrFilters[1] = "BlendTrans(duration=2)";
	arrFilters[2] = "progid:DXImageTransform.Microsoft.Pixelate(,enabled=false,duration=2,maxSquare=25)";
	arrFilters[3] = "progid:DXImageTransform.Microsoft.Fade(duration=2,overlap=0)";
	arrFilters[4] = "progid:DXImageTransform.Microsoft.GradientWipe(duration=2,gradientSize=0.25,motion=forward)";
	arrFilters[5] = "progid:DXImageTransform.Microsoft.Stretch(duration=2,stretchStyle=PUSH)";
	arrFilters[6] = "progid:DXImageTransform.Microsoft.Wheel(duration=2,spokes=16)";
	arrFilters[7] = "progid:DXImageTransform.Microsoft.RandomDissolve(duration=2)";
	arrFilters[8] = "progid:DXImageTransform.Microsoft.Spiral(duration=2,gridSizeX=50,gridSizeY=50)";
	arrFilters[9] = "progid:DXImageTransform.Microsoft.Slide(duration=2,bands=1,slideStyle=SWAP)";
	arrFilters[10] = "progid:DXImageTransform.Microsoft.RadialWipe(duration=2,wipeStyle=CLOCK)";
	arrFilters[11] = "progid:DXImageTransform.Microsoft.Pixelate(MaxSquare=15,Duration=1)";
	arrFilters[12] = "progid:DXImageTransform.Microsoft.Wipe(duration=3,gradientsize=0.25,motion=reverse)";

	function InitialFunction()
	{
		if (tnPictureCount != 1)
		{
			var tGamePicture = document.getElementById("ctrl_img_GamePicture");
			tGamePicture.style.filter = arrFilters[Math.round(Math.random() * (12))];;//"progid:DXImageTransform.Microsoft.GradientWipe(duration=2,gradientSize=0.25,motion=forward)";
			
			tnTimerID = setTimeout(ChangePicture, 5000, "JavaScript");
			tbPlaySlider = true;
		}
		
		// 分割cookies
		extractCookies();

		// 发表帖子的类型
		TopicGameTypeChanged();
	}
	
	function SwitchSlider()
	{
		if (tbPlaySlider == false)
		{
			document.getElementById("ctrl_ib_SwitchSlider").setAttribute("src", "../image/Stop.png");
			setTimeout(ChangePicture, 5000, "JavaScript");
			tbPlaySlider = true;
		}
		else
		{
			document.getElementById("ctrl_ib_SwitchSlider").setAttribute("src", "../image/Play.png");
			tbPlaySlider = false;
		}
	}
	
	function addFavourte_CallBack_Preview(response)
	{
		//if the server side code threw an exception
		if (response.error != null)
		{    
			alert(response.error); //we should probably do better than this
			return;
		}  

		if (response.value == true)
		{
			alert("添加成功！在你的个人空间里边可以直接看到它了。");
		}
		else
		{
			alert("该游戏已经在你的收藏里边了。");
		}
	}
	
	function addGameToFavourite_Preview()
	{
		// 如果没有注册
		if (cookies["UserID"] == null)
		{
			alert("对不起！你还没有注册或登陆！");
			return;
		}
		
		SingleGame.AddToFavourite(document.Form1.action.substring(document.Form1.action.indexOf("=") + 1), 
			cookies["UserID"], addFavourte_CallBack_Preview);
	}

	function SubmitScore_CallBack(response)
	{

	}
	
	function SubmitRemark_CallBack(response)
	{
		//if the server side code threw an exception
		if (response.error != null)
		{    
			alert(response.error); //we should probably do better than this
			return;
		}
		
		var ds = response.value; 
		if (ds == null)
		{
			alert("不能发表重复的评论！");
			return;
		}

		if (typeof(ds) == "object" && ds.Tables != null) 
		{
			var s = new Array();
			s[s.length] = "<table width=\"100%\" align=\"center\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"maintext\">"; 
			
			for(var i = 0;i < ds.Tables[0].Rows.length; i++) 
			{
				s[s.length] = "<tr><td colspan=\"2\">&nbsp;</td></tr>";
				s[s.length] = "<tr><td align=\"left\" bgcolor=\"ScrollBar\">";
				s[s.length] = ds.Tables[0].Rows[i].NickName;
				s[s.length] = "&nbsp;<i>(";
				s[s.length] = ds.Tables[0].Rows[i].RemarkTime.toLocaleString();
				s[s.length] = ")</i></td><td align=\"center\" width=\"150\" rowspan=\"2\" style=\"FONT-SIZE: 16px\"><b>";
				s[s.length] = (ds.Tables[0].Rows[i].GameScore == "0") ? "-</b></td></tr>" : ds.Tables[0].Rows[i].GameScore + "分</b></td></tr>";
				s[s.length] = "<tr bgcolor=\"#e4f3fe\"><td>" + ds.Tables[0].Rows[i].UserRemark + "</td></tr>"; 
			}
			s[s.length] = "</table>"; 
			
			document.getElementById("span_UserRemark").innerHTML = s.join("");
		}
		
		document.getElementById("ctrl_tb_Remark").innerText = "";
		
		document.getElementById("ctrl_btn_SubmitRemark").disabled = false;
	}
	
	// 提交评论
	function SubmitRemark()
	{
		// 如果没有注册
		if (cookies["UserID"] == null)
		{
			alert("对不起！你还没有注册或登陆！");
			return;
		}
		
		var tstrRemark = document.getElementById("ctrl_tb_Remark").innerText;
		if (tstrRemark.length == 0)
		{
			alert("评论内容不能为空！");
			return;
		}

		// 如果同时进行了评分
		var tScore = "0";
		if (document.Form1.GameRemarkScore[0].checked == false)
		{
			if (document.Form1.GameRemarkScore[1].checked)
			{
				tScore = "1";
			}
			else if (document.Form1.GameRemarkScore[2].checked)
			{
				tScore = "2";
			}
			else if (document.Form1.GameRemarkScore[3].checked)
			{
				tScore = "3";
			}
			else if (document.Form1.GameRemarkScore[4].checked)
			{
				tScore = "4";
			}
			else if (document.Form1.GameRemarkScore[5].checked)
			{
				tScore = "5";
			}
			
			// 写分数数据库
			SingleGame.WriteGameScore(
				document.Form1.action.substring(document.Form1.action.indexOf("=") + 1), 
				tScore, SubmitScore_CallBack);
		}
		
		document.getElementById("ctrl_btn_SubmitRemark").disabled = true;
		
		SingleGame.WriteRemark(document.Form1.action.substring(document.Form1.action.indexOf("=") + 1), 
			cookies["UserID"], tstrRemark, tScore, SubmitRemark_CallBack);
	}
