var ar_egg = new Array("蛋愿人长久?",
"我最讨厌你们这些扔蛋的了，一点技术含量都没有！",
"谢谢!我们是为人民服务的！",
"幸亏我拼命的护住了脸,英俊的相貌才得以保全！",
"曾经有一颗完整的蛋放在你面前,你没有珍惜....",
"早知道伤心总是难免的，你又何苦一网情深",
"浪费是极大的犯罪！",
"呜呜,真扔啊,哭了！",
"臭,你真坏！",
"砸得人家好疼啊！",
"哼,扔我鸡蛋,改天有你好看！",
"不喜欢我我还不喜欢你呢,讨厌！",
"为了胜利，向我扔蛋！",
"你这纯属道德问题！",
"让鸡蛋来的更猛烈些吧！");
var ar_flower = new Array("送人玫瑰,手有余香。",
"美貌诚可贵,鲜花价更高。",
"一束花，万份情，无偿献花最光荣！",
"如果，我再多一朵花，你会不会跟我一起走？",
"生活就像一束鲜花，你永远不知道你会得到什么。",
"花花世界耶~鸳鸯蝴蝶耶~",
"好一朵美丽的茉莉花~",
"花谢花会开~",
"羞答答的玫瑰静悄悄的开~",
"感谢客官,花儿我收了！",
"好漂亮的花啊!谢过了哈！",
"要浪漫,先浪费啦");
var tp_flower = new Array("投票成功,谢谢对我的支持。",
"谢谢投票啊,我也会支持你的",
"看来我也挺有魅力啊,谢谢你投我票",
"投成功了,你真有眼光!");
var eflash = new Array("http://www.4368.net/tool/score/egg01.swf",
"http://www.4368.net/tool/score/egg02.swf",
"http://www.4368.net/tool/score/egg04.swf");
var fflash = new Array("http://www.4368.net/tool/score/flower01.swf",
"http://www.4368.net/tool/score/flower02.swf",
"http://www.4368.net/tool/score/flower03.swf",
"http://www.4368.net/tool/score/flower04.swf");
function getHost(url)
{
	var host = "null";
	if(typeof url == "undefined" || null == url)
		url = window.location.href;
	return url;
}

function get_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else
	{
		return null;
	}
}

function coordX(cdname) //取left
{
	var xx;
	xx = lib.x(cdname);
	return xx;
}

function coordY(cdname) //取top
{
	var yy;
	yy = lib.y(cdname);
	return yy;
}

function showLoginForm()
{
	try {
		QuickLoginForm.width = 250;
		QuickLoginForm.height = 126;
		QuickLoginForm.url = "/quick_login/index.php";
		QuickLoginForm.id = "login";
		QuickLoginForm.msg = "砸人是要登录的哦！";
		QuickLoginForm.show();
	} catch (e) {
		alert(e.message);
	}
}

function giveLoginForm()
{
	QuickLoginForm.width = 250;
	QuickLoginForm.height = 126;
	QuickLoginForm.url = "/quick_login/index.php";
	QuickLoginForm.id = "login";
	QuickLoginForm.msg = "送花是要登录的哦！";
	QuickLoginForm.show();
}

//取得最近送过花的银
function getPropLog(object, propName, sourceId, typeId, size)
{
	var x = lib.x(object);
	var y = lib.y(object) + 30;
	var div = document.getElementById("propLogDiv");
	if (!div)
	{
		div = document.createElement("DIV");
		document.body.appendChild(div);
		div.id = "propLogDiv";
	}
	div.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px;width:100px;height:100px;color:white";
	div.innerHTML = "数据加载中，请稍候";
	var req = new Request(function()
				{
					if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
					{
						var text = req.xmlhttp.responseText;
						div.innerHTML = text;
					}
				}
			);
	req.get("/action/score.php?p=log&propName=" + propName + "&sourceId=" + sourceId + "&typeId=" + typeId + "&size=" + size);
	return false;
}

//关闭最近记录
function removePropLog()
{
	var div = document.getElementById("propLogDiv");
	if (div)
	{
		document.body.removeChild(div);
	}
}

//设置可用的鸡蛋个数
function setPropEggNum(o)
{
		var req = new Request(function()
		  {
		  		if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
		  		{
		  			o.title = "您还有" + req.xmlhttp.responseText + "颗鸡蛋可以扔！";
		  		}
		  });
		req.get("/action/score.php?p=getEggNum");
}


//oX 对象 x 坐标 oY 对象 坐标
var propObjectX = 0, propObjectY = 0;
function ToLoad(sourceId,typeId, pid, oX, oY)
{
	if (oX) propObjectX = lib.intval(oX);
	if (oY) propObjectY = lib.intval(oY);
	var req = new Request(function()
	  {
	  		if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
	  		{

	  			if (req.xmlhttp.responseText == 102)//没有登陆
	  			{
	  				showLoginForm();
				}
				else
				{
					var s,always;
	  				always = req.xmlhttp.responseText;
	  				s = always.split(",");
	  				var eggs = s[0];
	  				var flowers = s[1];
	  				//一共有几次鸡蛋和花
	  				//ducument.write();
	  				document.getElementById("egg").innerHTML = eggs;
	  				document.getElementById("flower").innerHTML = flowers;
				}
	  		}
	  });
	req.get("/action/score.php?p=Default&sourceId=" + sourceId + "&typeId=" + typeId + "&sourcePid=" + pid);
	return false;
}

//加载效果
var propFlashDiv;
function propLoadFlash(swf)
{
	//加载扔鸡蛋页面 falsh
	var w = 450;
	var h = 360;
	var propX = propObjectX;
	var propY = propObjectY;
	var body = lib.getBody();

	propFlashDiv = document.createElement("DIV");
	document.body.appendChild(propFlashDiv);
	propFlashDiv.style.cssText = "position:absolute;z-index:99999;left:" + propX + "px;top:" + propY + "px;width:" + w + "px;height:" + h + "px";
	propFlashDiv.innerHTML = "<embed src=\"" + swf + "\"" + swf + " width=\"" + w + "\" height=\"" + h + "\" wmode=transparent></embed>";
	setTimeout("propFlashDiv.innerHTML='';document.body.removeChild(propFlashDiv);", 5000);
}

function egg(sourceId,typeId,sourcePid,obj)
{
if (!obj) obj='egg';
	var eventX = lib.x(window.event.srcElement);
	var eventY = lib.y(window.event.srcElement);

	var current_url=getHost();
	if (confirm("扔鸡蛋可能会伤害主人的心,确定继续扔吗?"))
	{
		var req = new Request(function()
		  {
		  		if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
		  		{
		  			if (req.xmlhttp.responseText == 102)//没有登陆
		  			{
		  				alert("请登陆后再进行操作吧");
					}
					else if (req.xmlhttp.responseText == 101)//查询错误
		  			{
						alert("查询错误");
					}
		  			else if(req.xmlhttp.responseText == 302)
		  			{
		  				alert("客官,你的M币不够啦,购买点吧！");
		  			}
			  		else if (req.xmlhttp.responseText == 201)
			  		{
			  			alert("今天送过花或者扔过鸡蛋了,对我就别那么狠了吧！");
			  		}
			  		else if (req.xmlhttp.responseText == 202)
		  			{
		  				alert("都扔过了还扔啊,欺负人啊!明天再来吧!");
		  			}
		  			else if (req.xmlhttp.responseText == 301)
		  			{
		  				alert("客官,不要自己扔自己鸡蛋吧!");
		  			}
		  			else if (req.xmlhttp.responseText == 300)//扔完了
		  			{
						var numbers = Math.round(Math.random()*11);
		  				alert(ar_egg[numbers]);
		  				var number = Math.round(Math.random()*2);
		  				//加载效果
		  				propLoadFlash(eflash[number]);
		  				var x = document.getElementById(obj).innerHTML;
		  				var y = parseInt(x);
		  				y = y+1;
		  				document.getElementById(obj).innerHTML = y;
		  			}
		  			else //鸡蛋的数目
		  			{
						alert(req.xmlhttp.responseText);
		  			}
		  		}
		  });
		req.get("/score.asp?p=Egg&sourceId=" + sourceId + "&typeId=" + typeId + "&sourcePid=" + sourcePid);
		return false;
	}
}
function flower(sourceId,typeId,sourcePid,obj)
{
	if (!obj) obj='flower';
	var eventX = lib.x(window.event.srcElement);
	var eventY = lib.y(window.event.srcElement);
	if (confirm("送一朵鲜花给TA么,确定赠送吗?"))
	{
	var current_url=getHost();
		var req = new Request(function()
		  {
		  		if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
		  		{
		  			if (req.xmlhttp.responseText == 102)//没有登陆
		  			{
						alert("请登陆后再进行操作吧");
					}
					else if (req.xmlhttp.responseText == 101)//查询错误
		  			{
						alert("查询错误");
					}
					else if (req.xmlhttp.responseText == 201)//送过花
		  			{
		  				alert("客官,今天送过花了,明天再来看偶吧!");
		  			}
		  			else if (req.xmlhttp.responseText == 202)//送过花
		  			{
		  				alert("扔过鸡蛋就别再送花了吧？！");
		  			}
		  			else if(req.xmlhttp.responseText == 301)
		  			{
		  				alert("客官,不要给自己送花吧！");
		  			}
		  			else if(req.xmlhttp.responseText == 302)
		  			{
		  				alert("客官,你的M币不够啦,购买点吧！");
		  			}
		  			else if (req.xmlhttp.responseText == 300)//没有送过，送
		  			{
						var numbers = Math.round(Math.random()*11);
		  				alert(ar_flower[numbers]);
		  				var number = Math.round(Math.random()*2);
		  				//加载效果
		  				propLoadFlash(fflash[number]);
		  				var x = document.getElementById(obj).innerHTML;
		  				var y = parseInt(x);
		  				y = y+1;
		  				document.getElementById(obj).innerHTML = y;
		  			}
		  			else
		  			{
						alert(req.xmlhttp.responseText);
		  			}
		  		}
		  });

		req.get("/score.asp?p=Flower&sourceId=" + sourceId + "&typeId=" + typeId + "&sourcePid=" + sourcePid);
		return false;
	}
}
function toupiao(sourceId,typeId,sourcePid,obj)
{
	if (!obj) obj='egg';
	var eventX = lib.x(window.event.srcElement);
	var eventY = lib.y(window.event.srcElement);
	if (confirm("投一票给TA么,确定要投票吗?"))
	{
	var current_url=getHost();
		var req = new Request(function()
		  {
		  		if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
		  		{
		  			if (req.xmlhttp.responseText == 102)//没有登陆
		  			{
						alert("请登陆后再进行操作吧");
					}
					else if (req.xmlhttp.responseText == 101)//查询错误
		  			{
						alert("查询错误");
					}
					else if (req.xmlhttp.responseText == 201)//送过花
		  			{
		  				alert("客官,今天投过票了,明天再来投吧!");
		  			}
		  			else if (req.xmlhttp.responseText == 202)//送过花
		  			{
		  				alert("扔过鸡蛋就别再送花了吧？！");
		  			}
		  			else if(req.xmlhttp.responseText == 301)
		  			{
		  				alert("客官,不要给自己投票吧！");
		  			}
		  			else if(req.xmlhttp.responseText == 302)
		  			{
		  				alert("客官,你的M币不够啦,购买点吧！");
		  			}
		  			else if (req.xmlhttp.responseText == 300)//没有送过，送
		  			{
						var numbers = Math.round(Math.random()*3);
		  				alert(tp_flower[numbers]);
		  				var number = Math.round(Math.random()*2);
		  				//加载效果
		  				propLoadFlash(fflash[number]);
		  				var x = document.getElementById(obj).innerHTML;
		  				var y = parseInt(x);
		  				y = y+1;
		  				document.getElementById(obj).innerHTML = y;
		  			}
		  			else
		  			{
						alert(req.xmlhttp.responseText);
		  			}
		  		}
		  });

		req.get("/score.asp?p=Egg&sourceId=" + sourceId + "&typeId=" + typeId + "&sourcePid=" + sourcePid);
		return false;
	}
}
function buy(buy_egg,flowers,typeId)
{
	if(document.postform.buy_egg.value == "")
	{
		alert("请输入购买鸡蛋数目！");
		document.postform.buy_egg.focus();
		return false;
	}

	var x,y;
	x = flowers - (buy_egg*5);
	y = Math.floor(x/5);
	if((buy_egg*5) >flowers)
	{
		alert("鲜花数不够！");
		return false;
	}
	var req = new Request(function()
	  {
	  		if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
	  		{
	  			if (req.xmlhttp.responseText == 102)//没有登陆
	  			{
	  				//showLoginForm();
					window.location = "http://passport.wangyou.com/login.php?go_to=" + current_url;
				}
				else if (req.xmlhttp.responseText == 501)
	  			{
					alert("鲜花数不够。");
	  			}
	  			else if (req.xmlhttp.responseText == 502)
	  			{
					alert("购买失败！");
	  			}
		  		else if (req.xmlhttp.responseText == 500)
		  		{
		  			alert("购买成功！");
	  				document.getElementById("flower_number").innerHTML = x;
	  				document.getElementById("egg_number").innerHTML = y;
	  				document.getElementById("buy_egg").value = "";
		  		}
	  			else
	  			{

	  			}
	  		}
	  });
	req.get("/action/score.php?p=Buy&buy_egg=" + buy_egg + "&flower=" + flowers + "&typeId=" + typeId);
	return false;
}