// JavaScript Document
// qdkj Project 
// Author :karlwu
// created 2009-05-19
/////////////////////////
var APPID=4008401;

//if($app){$app.appid=APPID;}
function login_exchange()
{
	if(!checkQQLoad()){
		openLogin(APPID,'http://qdkj.qq.com/con/info/act/exchange');
		return;
	}else {
		window.open("http://qdkj.qq.com/con/info/act/exchange");
	}
}
function login()
{
	if(!checkQQLoad()){
		openLogin(APPID,'http://qdkj.qq.com/con/login/act/login');
		return;
	}
}
function logintest()
{        
        if(!checkQQLoad()){
                openLogin(APPID,'http://qdkj.qq.com/test4/indextest4.htm');
                return;
        }
}     
function logingame(type)
{
	
	if(!checkQQLoad()){
		openLogin(APPID,'http://qdkj.qq.com/con/login/act/login');
		return;
	}
	if(type==1)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gameone";
	 window.open("http://qdkj.qq.com/con/info/act/gameone");
	return;
	}
	if(type==2)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gametwo";
	 window.open("http://qdkj.qq.com/con/info/act/gametwo");
	return;
	}
	if(type==3)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gamethree";
	 window.open("http://qdkj.qq.com/con/info/act/gamethree");
	return;
	}
	if(type==4)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gamefour";
	 window.open("http://qdkj.qq.com/con/info/act/gamefour");
	return;
	}
	if(type==5)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gamefive";
	 window.open("http://qdkj.qq.com/con/info/act/gamefive");
	return;
	}
	if(type==6)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gamesix";
	 window.open("http://qdkj.qq.com/con/info/act/gamesix");
	return;
	}
	if(type==7)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gameseven";
	 window.open("http://qdkj.qq.com/con/info/act/gameseven");
	return;
	}
}

function logingametest(type)
{
	if(!checkQQLoad()){
		openLogin(APPID,'http://qdkj.qq.com/test4/indextest4.htm');
		return;
	}
	if(type==1)
	{
	
	//window.location.href="http://qdkj.qq.com/con/info/act/gameone";
	 window.open("http://qdkj.qq.com/test4/game/game1.htm");
	return;
	}
	if(type==2)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gametwo";
	 window.open("http://qdkj.qq.com/test4/game/game2.htm");
	return;
	}
	if(type==3)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gamethree";
	 window.open("http://qdkj.qq.com/test4/game/game3.htm");
	return;
	}
	if(type==4)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gamefour";
	 window.open("http://qdkj.qq.com/test4/game/game4.htm");
	return;
	}
	if(type==5)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gamefive";
	 window.open("http://qdkj.qq.com/test4/game/game5.htm");
	return;
	}
	if(type==6)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gamesix";
	 window.open("http://qdkj.qq.com/test4/game/game6.htm");
	return;
	}
	if(type==7)
	{
	//window.location.href="http://qdkj.qq.com/con/info/act/gameseven";
	 window.open("http://qdkj.qq.com/test4/game/game7.htm");
	return;
	}
}


function closeDiv()
{
	$("#Layer1").css("display","none");
}
function exchange_success()
{
	
}
function score_exchange()
{
	var sCode=$("#FCode").val();
	if(sCode==''){
		alert("请输入兑换码!");
		return;
	}
	var sVerifyCode=$("#verifycode").val();
	if(sVerifyCode==''){
		alert("请输入验证码");
		return;
	}
	//$("#form1").submit();
	
	$.ajax({
		   type:"POST",
		   dataType:"json",
		   url: "/con/score/act/exchange?uid="+Date(),
		   data:{
			   FCode:sCode,
			   verifycode:sVerifyCode
		   },
		   success: function(json){
				
				if(json.code==0){//兑换成功
					//alert("success");
					
					var scoreCount=parseInt($('#Layer2').text());
					scoreCount=scoreCount+100;
					alert(scoreCount);
					$("#Layer2").text(scoreCount);
					$("#Layer1").css({"display":"block","top":400,"left":400});
					$("#verifycode").val("");
					$("#FCode").val("");
					nchangeImg();
					
				}else {//可以使用
					alert(json.message);
				}
				
				
			}
		   });
	
}

function callBack(type)
{
	//alert("success");
	if(!checkQQLoad()){
		openLogin(APPID,'http://qdkj.qq.com/con/login/act/login');
		return;
	}
	switch(type){
	case 1:
	
	break;
	case 2:
		alert("非正当来源!");
		break;
	case 3:
		alert("请您选择正确的兑换奖品！");
		break;
	
	case 4:
		alert("请填写注册信息!");
		window.location.href="http://qdkj.qq.com/con/user/act/showregister";
		break;
	
	case 5:
		alert("兑换奖品成功");
		break;
	case 6:
		alert("虚拟奖品一天之内兑换三次！您可以明天继续兑换");
		
	break;
	case 9:
		alert("您的积分不够!");
		break;
	case 8:
		alert("同一类奖品只能兑换一次!");
		break;
	case 7:
		alert("半年内只能兑换黄钻一次!");
		break;
	default:
		alert(type);
		alert("其他");
	break;
	} 
	
}
function qdkj_register()
{
	var sTrueName=$("#FTrueName").val();
	if(sTrueName==''){
		alert("请输入您的真实姓名!");
		return ;
	}
	/*var sTel=$("#FTel").val();
	var telPattern=/^\d{11}$|^\d{3}-\d{7,8}$|^\d{3,4}-\d{7,8}$/;
	if(sTel=='' || !telPattern.test(sTel)){
		alert("请输入正确的电话号码");
		return ;
	} */
	
	var sMobile=$("#FMobile").val();
	var telPattern=/^\d{11}$|^\d{3}-\d{7,8}$|^\d{3,4}-\d{7,8}$/;
	if(sMobile=='' || !telPattern.test(sMobile)){
		alert("请输入正确的手机号码");
		return ;
	}
	
	
	var sAddr=$("#FAddr").val();
	if(sAddr==''){
		alert("请输入详细地址");
		return ;
	}
	
	var sCode=$("#FCode").val();
	var sCodePattern=/\d{6}/;
	if(sCode=='' || !sCodePattern.test(sCode)){
		alert("请输入正确的邮编");
		return ;
	}
	
	
	var sEmail=$("#FEmail").val();
	var emailPattern=/^\s*[\w\~\-\.]+\@[\w\~\-]+(\.[\w\~\-]+)+\s*$/;
	if(sEmail==''||!emailPattern.test(sEmail)){
		alert("请输入正确的Email地址");
		return ;
	}
	
	var sAge=$("#FAge").val();
	var nAge=parseInt(sAge)
	if(sAge=='' || nAge <0 || nAge>100 ){
		alert("请输入正确年龄!");
		return ;
	}
	
	var sDept=$("#FDept").val();
	if(sDept==''){
		alert("请输入单位地址!");
		return ;
	}
	$("#form1").submit();
}

 function nchangeImg()
{
        var img = document.getElementById("imgVerify");
        img.src = "http://ptlogin2.qq.com/getimage?aid=" + APPID + "&" + Math.random();
        var ctrl = document.getElementById("verifycode");
        if (ctrl != null)
        {
                ctrl.value = "";
                ctrl.focus();
        }

}

//
var strUrl="http://qdkj.qq.com/con/score/act/month";
function goPrePage()
{
	var sCurrPage=$("#curr_page").val();
	sCurrPage--;
	
	window.location = strUrl + "?curr_page=" + sCurrPage;
}
function goNextPage()
{
	var sCurrPage=$("#curr_page").val();
	sCurrPage++;
	
	window.location = strUrl + "?curr_page=" + sCurrPage;
}

//更多月积分
function changeMonth()
{
	var sCurrMonth=$("#curr_month").val();
	window.location="http://qdkj.qq.com/con/score/act/month?curr_month="+sCurrMonth;
}
//积分搜索
function score_search()
{
	var sQQ=$("#FQQ").val();
	if(sQQ==''){
		alert("请输入查询的QQ号码!");
		return;
	}
	$("#form1").submit();
}
$().ready(
	function()
	{
		try
		{
			if($app){$app.appid=APPID;}	
			$('.btn_login').css({'cursor':'pointer'}).click(function(){$app.LoginQQ('http://qdkj.qq.com/con/login/act/login')});
			$('.btn_logout').css({'cursor':'pointer'}).click(function(){$app.LogoutQQ('/')});
	
			
			if($app&&$app.IsLogin())	
			{
				$.get('/con/info/act/getmyscore',{clientTime:Date()},function(data){
					$('#myscoreleft').text(data);														  
				});	
				
			}
			if(window.location.href.indexOf('http://qdkj.qq.com/con/default/act/tao')!=-1||window.location.href.indexOf('http://qdkj.qq.com/con/info/act/spikeview')!=-1)
			{
				//alert(window.location.href);
				
				$.getJSON('/con/info/act/getawardleft',{type:$.getURLParam('type'),clientTime:Date()},function(data){
					$('#awardleft').text(data.awardleft);	
					
					if(data.code==-1)
					{
						alert(data.message);	
					}
				});
			}
		}
		catch(e)
		{
			$app=null;	
		}
		
	}
);


$().ready(
	function()
	{
		if($app&&$app.IsLogin())	
		{
			$('#login_loginout').html("<img src=\"images/botton2.jpg\" width=\"75\" height=\"29\" border=\"0\" onclick=\"javascript:$app.LogoutQQ('')\">");
			var uin = $app.GetQQNum();
			$('#qqnumber').html(uin);
		}else
		{
			
			$('#login_loginout').html("<img src=\"images/botton1.jpg\" width=\"75\" height=\"29\" border=\"0\" onclick=\"javascript:$app.LoginQQ('http://qdkj.qq.com/con/login/act/login')\">");
		}
}
);
