var ua = navigator.userAgent.toLowerCase();
var isIE = (ua.indexOf("msie") > -1),isIE7 = (ua.indexOf("msie 7") > -1),isOpera = (ua.indexOf("opera") > -1),isSafari = (ua.indexOf("webkit") != -1 || ua.indexOf("khtml") != -1),isGecko = (!isSafari && ua.indexOf("gecko") > -1);
var integral = '';
var gameType = '';
var games = ['playgame', 'dbq', 'fp', 'ddp', 'mfs', 'qjs', 'xss', 'pt', 'ttt'];
var download_key = '';
var calendar_id = 1;

//错误信息定义
var error = 
{
    'NOT_LOGIN': '您还没有登录，请登录后再进行奖品的兑换',
    'BAD_WARE': '您输入的物品编号不正确，请确认后再进行购买！',
    'SELL_OUT': '该奖品已兑换空，试试其它的吧！',
    'OUT_POINT': '很抱歉，您的积分还不够兑换该奖品，试试其它的吧！',
    'DB_ERROR': '很抱歉，我们在处理兑换时发生了错误，请与我们的客服联系！'
};

function mousePosition(e)
{
    var posx=0,posy=0;
    if(e==null) e=window.event;
    if(e.pageX || e.pageY)
    {
        posx=e.pageX; posy=e.pageY;
        }
    else if(e.clientX || e.clientY)
    {
        if(document.documentElement.scrollTop)
        {
            posx=e.clientX+document.documentElement.scrollLeft;
            posy=e.clientY+document.documentElement.scrollTop;
        }
        else
        {
            posx=e.clientX+document.body.scrollLeft;
            posy=e.clientY+document.body.scrollTop;
        }
    }
	
	return {
	 		x:posx,         
	   		y:posy		
		};
}


function mouseMove(ev)
{
    ev = ev || window.event;
    mousePos = mousePosition(ev);
}

document.onmousemove = mouseMove;


//document.getElementById
function _(element) 
{
    if (arguments.length > 1) 
    {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++)
          elements.push($(arguments[i]));
        return elements;
    }
    else
        return document.getElementById(element);
}

//登录处理
function doLogin()
{
    if ( _('account').value == '')
        alert('登录账号名称不能为空，请重新填写！');
    else if ( _('passwd').value == '')
        alert('登录密码不能为空，请重新填写！');
    else if ( _('code').value == '')
        alert('验证码不能为空，请重新填写！'); 
    else
	{
		$.post
		(
		    'index.php?do=Login',
			{
				account:_('account').value,
				passwd:_('passwd').value,
				code:_('code').value
			}, 
		    function(data)
		    {
				if (data == 'OK')
				{
					alert('登录成功！');
					top.location.reload();
				}
				else
					alert(data); 
		    } 
		);		
	}
}	


//下载日历处理函数
function doCalendar(type)
{
	if (type > 0 && type <= 12)
	{
		calendar_id = type;
		$('#calendar_img').html('<img src="' + calendars[type] + '" width="229" height="171" />');
	}
	else
		download((21 + calendar_id ) + '_1');
}


window.onload = function ()
{
	try
	{
		$.get('index.php?do=UserStat', function (data){ $('#user_stats').html(data);});
		
		try{_('_flash_').SetVariable('cookies',unescape(document.cookie));}catch(e){}
	
		//_('_flash_').sCookie(document.cookie);
		
		$.post
		(
		    'integral.php?do=Top10', 
		    function(data)
		    {
				$('#rank_title').html($('#rank_title').html() + data);
		    } 
		);
	}catch(e){}	
}


//用户玩游戏积分处理
function doIntegral(type)
{
	if (type == 'login')
	{
	     var param = 
	     {
	          account: _('account').value,
	          passwd: _('passwd').value,
	          code: _('code').value,
			  type:type,
			  gameType:gameType,
			  integral:integral
	     } 
	        
	     if ( param['account'] == '' || param['code'] == '' || param['passwd'] == '')
	     {
	         alert('您必须填写所有信息，以便于我们投递奖品！');
	         return false;
	     }
	 }
	 else if (type == 'info')
	 {
	     var param = 
	     {
	          mobile: _('mobile').value,
	          mail: _('mail').value,
	          qq: _('qq').value,
	          address: _('address').value,
	          real_name: _('real_name').value,
			  type:type,
			  gameType:gameType,
			  integral:integral
	     } 
	        
	     if ( _('mobile').value != '' && !/^[0-9]{3,8}\-?[0-9]{3,8}$/.test( _('mobile').value ))
	     {
	         alert('您填写的手机电话格式不正确，请重新填写！');
	         return false;
	     }
	        
	     if ( _('qq').value != '' && !/^[0-9]{5,15}$/.test( _('qq').value ))
	     {
	         alert('您填写的QQ号码格式不正确，请重新填写！');
	         return false;
	     }   
	        
	     if ( param['qq'] == '' || param['real_name'] == ''
		 	 || param['address'] == '' || param['mobile'] == '')
	     {
	         alert('您必须填写所有信息，以便于我们投递奖品！');
	         return false;
	     }
		 
		 if ( _('mail').value != '' && ! /^[\w\-]+(\.[\w\-]+)*@[\w-]+(\.[\w\-]+)+$/.test(_('mail').value))
		 {
	         alert('您填写的邮件地址格式不正确，请重新填写！');
	         return false;
		 }	 
	 }
	 else
	 {
	 	var param = 
		{
			type:type,
			integral:integral,
			gameType:gameType
		};
	 }
	 	 	 	
     
    $.post
    (
        'integral.php?do=integral', 
        param,
        function(data)
        {
			
			if (data == 'OK')	//积分提交成功
			{
				alert('积分记录成功！');
				_('allbg').style.display = 'none';
				top.location.reload();
			}
			else if ( data == 'INTEGRAL' )
			{
				alert('感谢您的参与，游戏积分记录成功，同时您已获得500开心积分，重新登陆您的帐号即可查询！');
				_('allbg').style.display = 'none';	
				top.location.reload();			
			}
			else if ( data.length <= 50 )
			{
				alert(data);
				try
				{
					_('code').value = '';
					_('_code').src='index.php?do=code&'+Math.random();					
				}catch(e){}
			}
			else
			{
				$('#information').html(data);
				$('#information').fadeIn();	
			}
        } 
    );
}

//供Flash调用的函数
function end_game(num)
{
	integral = num;
	//doIntegral('show');
}

function download(key)
{
	download_key = key;
	doDownload('post');
}

//下载处理
function doDownload(type)
{
	if (type == 'login')
	{
	     var param = 
	     {
	          account: _('account').value,
	          passwd: _('passwd').value,
	          code: _('code').value,
			  type:type,
			  img:download_key
	     } 
	        
	     if ( param['account'] == '' || param['code'] == '' || param['passwd'] == '')
	     {
	         alert('您必须填写所有信息，以便于我们投递奖品！');
	         return false;
	     }
	 }
	 else if (type == 'info')
	 {
	     var param = 
	     {
	          mobile: _('mobile').value,
	          mail: _('mail').value,
	          qq: _('qq').value,
	          address: _('address').value,
	          real_name: _('real_name').value,
			  type:type,
			  img:download_key
	     } 
	        
	     if ( _('mobile').value != '' && !/^[0-9]{3,8}\-?[0-9]{3,8}$/.test( _('mobile').value ))
	     {
	         alert('您填写的手机电话格式不正确，请重新填写！');
	         return false;
	     }
	        
	     if ( _('qq').value != '' && !/^[0-9]{5,15}$/.test( _('qq').value ))
	     {
	         alert('您填写的QQ号码格式不正确，请重新填写！');
	         return false;
	     }   
	        
	     if ( param['qq'] == '' || param['real_name'] == ''
		 	 || param['address'] == '' || param['mobile'] == '')
	     {
	         alert('您必须填写所有信息，以便于我们投递奖品！');
	         return false;
	     }
		 
		 if ( _('mail').value != '' && ! /^[\w\-]+(\.[\w\-]+)*@[\w-]+(\.[\w\-]+)+$/.test(_('mail').value))
		 {
	         alert('您填写的邮件地址格式不正确，请重新填写！');
	         return false;
		 }	 
	 }
	 else
	 {
	 	var param = 
		{
			type:type,
			img:download_key
		};
	 }
	 	 	 	
     
    $.post
    (
        'index.php?do=download', 
        param,
        function(data)
        {
			
			if (data == 'OK')	//积分提交成功
			{
				_('allbg').style.display = 'none';
				top.location.href = "index.php?do=download";
				setTimeout(function(){top.location.reload();}, 2000);
				//window.open('index.php?do=download');
				//top.location.reload();
			}
			else if ( data == 'INTEGRAL' )
			{
				alert('感谢您的参与，游戏积分记录成功，同时您已获得500开心积分，重新登陆您的帐号即可查询。！');
				_('allbg').style.display = 'none';	
				top.location.href = "index.php?do=download";
				setTimeout(function(){top.location.reload();}, 2000);
				//window.open('index.php?do=download');
			}
			else if ( data.length <= 50 )
			{
				alert(data);
				try
				{
					_('code').value = '';
					_('_code').src='index.php?do=code&'+Math.random();					
				}catch(e){}
			}
			else
			{
				$('#information').html(data);
				$('#information').fadeIn();	
			}
        } 
    );
}

//重置Flash
function flashout(swf)
{
	//var games = ['playgame', 'dbq', 'fp', 'ddp', 'mfs', 'qjs', 'xss', 'pt', 'ttt'];
	if (swf == 'playgame')
		gameType = 0;
	else if (swf == 'dbq')
	 	gameType = 1;
	else if (swf == 'fp')
		gameType = 2;
	else if (swf == 'ddp')
		gameType = 3;
	else if (swf == 'mfs')
		gameType = 4;
	else if (swf == 'qjs')
		gameType = 5;
	else if (swf == 'xss')
		gameType = 6;								
	else if (swf == 'pt')
		gameType = 7;	
	else if (swf == 'ttt')
		gameType = 8;
								
	_('flasharea').innerHTML = "<object name=\"_flash_\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=9,0,28,0\" width=\"600\" height=\"500\"><param name=\"movie\" value=\"flash\/" + swf + ".swf\"><param name=\"wmode\" value=\"opaque\" \/><param name=\"quality\" value=\"high\"><embed src=\"flash\/" + swf + ".swf\" quality=\"high\" pluginspage=\"http:\/\/www.adobe.com\/shockwave\/download\/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application\/x-shockwave-flash\" width=\"600\" height=\"500\" wmode=\"transparent\" id=\"_flash_\" name=\"_flash_\" /><\/object>";
}

function top_lzs(qq){
document.writeln("    <div style=\"position:absolute; left: 68px; top: 39px;\"><a href=\"http:\/\/g2.91.com\/V3\/NewGG\/Transfer\/Hit.aspx?BillId=1655&TargetUrl=http:\/\/club.kx.91.com\/\" target=\"_blank\"><img src=\"http:\/\/club.kx.91.com\/images\/top_lzs_1.gif\" border=\"0\"><\/a><\/div>");
document.writeln("    <div style=\"position:absolute; left: 184px; top: 28px;\"><a href=\"http:\/\/g2.91.com\/V3\/NewGG\/Transfer\/Hit.aspx?BillId=1659&TargetUrl=http:\/\/club.kx.91.com\/game.php\" target=\"_blank\"><img src=\"http:\/\/club.kx.91.com\/images\/top_lzs_2.gif\" border=\"0\"><\/a><\/div>");
document.writeln("    <div style=\"position:absolute; left: 302px; top: 24px;\"><a href=\"http:\/\/g2.91.com\/V3\/NewGG\/Transfer\/Hit.aspx?BillId=1662&TargetUrl=http:\/\/club.kx.91.com\/wallpaper.php\" target=\"_blank\"><img src=\"http:\/\/club.kx.91.com\/images\/top_lzs_6.gif\" border=\"0\"><\/a><\/div>");
document.writeln("    <div style=\"position:absolute; left: 392px; top: 42px;\"><a href=\"http:\/\/g2.91.com\/V3\/NewGG\/Transfer\/Hit.aspx?BillId=1663&TargetUrl=http:\/\/club.kx.91.com\/desktop.php\" target=\"_blank\"><img src=\"http:\/\/club.kx.91.com\/images\/top_lzs_7.gif\" border=\"0\"><\/a><\/div>");
document.writeln("    <div style=\"position:absolute; left: 515px; top: 29px;\"><a href=\"http:\/\/g2.91.com\/V3\/NewGG\/Transfer\/Hit.aspx?BillId=1664&TargetUrl=http:\/\/club.kx.91.com\/sign.php\" target=\"_blank\"><img src=\"http:\/\/club.kx.91.com\/images\/top_lzs_5.gif\" border=\"0\"><\/a><\/div>");
document.writeln("    <div style=\"position:absolute; left: 642px; top: 40px;\"><a href=\"http:\/\/club.kx.91.com\/calendar.php\" target=\"_blank\"><img src=\"http:\/\/club.kx.91.com\/images\/top_lzs_3.gif\" border=\"0\"><\/a><\/div>");
document.writeln("    <div style=\"position:absolute; left:529px; top:48px; color:#FF4A83\"><\/div>");
document.writeln("        <div style=\"position:absolute; left:409px; top:60px; color:#FF4A83\"><\/div>");
document.writeln("");
document.writeln("        <div style=\"position:absolute; left:318px; top:43px; color:#FF4A83\"><\/div>");
document.writeln("");
document.writeln("<div style=\"position:absolute; left:747px; top:26px; color:#FF4A83\"><\/div>");
document.writeln("<div style=\"position:absolute; left: 734px; top: 7px;\"><a href=\"http:\/\/club.kx.91.com\/qq.php\" target=\"_blank\"><img src=\"http:\/\/club.kx.91.com\/images\/top_lzs_4.gif\" border=\"0\"><\/a><\/div>");
document.writeln("    <div style=\"position:absolute; left:192px; top:48px; color:#FF4A83\">开心冲浪<img src=\"http:\/\/club.kx.91.com\/images\/new.gif\" border=\"0\"><\/div>");
document.writeln("");
}

function mianfei(qq){
document.writeln("<table width=\"503\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
document.writeln("              <tr>");
document.writeln("                <td background=\"images\/kxly_182.gif\" class=\"free\"><table width=\"70%\" border=\"0\" align=\"right\" cellpadding=\"0\" cellspacing=\"0\">");
document.writeln("                  <tr>");
document.writeln("                    <td width=\"45%\" height=\"10\">10000套开心QQ秀<\/td>");
document.writeln("                    <td width=\"30%\">&nbsp;<\/td>");
document.writeln("                    <td width=\"25%\">&nbsp;<\/td>");
document.writeln("                  <\/tr>");
document.writeln("                  <tr>");
document.writeln("                    <td height=\"10\">10000套开心QQ魔法秀<\/td>");
document.writeln("                    <td>&nbsp;<\/td>");
document.writeln("                    <td>&nbsp;<\/td>");
document.writeln("                  <\/tr>");
document.writeln("                  <tr>");
document.writeln("                    <td height=\"10\">1000只可爱<a href=\"http:\/\/photo.news.91.com\/picfile\/2008-01-08\/c1bv2k6420dh7uv.shtml\" target=\"_blank\">狐狸毛绒<\/a><\/td>");
document.writeln("                    <td>&nbsp;<\/td>");
document.writeln("                    <td>&nbsp;<\/td>");
document.writeln("                  <\/tr>");
document.writeln("                  <tr>");
document.writeln("                    <td height=\"10\">数万件精美周边免费下载<\/td>");
document.writeln("                    <td>&nbsp;<\/td>");
document.writeln("                    <td>&nbsp;<\/td>");
document.writeln("                  <\/tr>");
document.writeln("                  <tr>");
document.writeln("                    <td height=\"10\">3000万《开心》积分<\/td>");
document.writeln("                    <td>&nbsp;<\/td>");
document.writeln("                    <td>&nbsp;<\/td>");
document.writeln("                  <\/tr>");
document.writeln("                <\/table><\/td>");
document.writeln("              <\/tr>");
document.writeln("          <\/table>");
document.writeln("");
}

var lunbo = function(i){return document.getElementById(i);}
var ua = navigator.userAgent.toLowerCase();
var isIE = (ua.indexOf("msie") > -1),isIE7 = (ua.indexOf("msie 7") > -1),isOpera = (ua.indexOf("opera") > -1),isSafari = (ua.indexOf("webkit") != -1 || ua.indexOf("khtml") != -1),isGecko = (!isSafari && ua.indexOf("gecko") > -1);
function switchmenu(obj){
        if(document.getElementById){
		
        var el = document.getElementById(obj);
        
		var em = document.getElementById("maindiv").getElementsByTagName("em"); 
		                for (var i=0; i<em.length; i++){
                        em[i].innerHTML='<img src="images/jia.gif" width="16" height="16" align="absmiddle">';
                        }
		var ar = document.getElementById("maindiv").getElementsByTagName("div"); 				
                if(el.style.display != "block"){
                        for (var i=0; i<ar.length; i++){
                                if (ar[i].className=="menus") 
                                ar[i].style.display = "none";
                        }
                        el.style.display = "block";
                }else{
                        el.style.display = "none";
                }
        }
		document.getElementById("img_"+obj).innerHTML='<img src="images/j.gif" width="16" height="16" align="absmiddle">';
}
function showoutqq(id){
lunbo(id).style.display = "none"
lunbo(id+'_show').style.display = ""
}

function showoff(id){
lunbo(id).style.display = ""
lunbo(id+'_show').style.display = "none"
}
