﻿APPID = 4008103;
//APPID = 4007203;

function goPage()
{
	window.location.href = "http://huafeng.qq.com/con/doodle/act/list?page="+jQuery("#doodlePage").val();
}

function toDoodle()
{
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(APPID, "http://huafeng.qq.com/con/register/act/todoodleregister");		
	}
	else{	
		jQuery.ajax({
			type: "POST",
			dataType: "json",
			url: '/con/register/act/isreg',
			data: {client:Date()},
			success: function(json){
				if(json.code == 1){
					window.location.href = "http://huafeng.qq.com/con/register/act/list";
				}
				else if(json.code == 2)
				{
					window.location.href = "http://huafeng.qq.com/con/doodle/act/uploadlist";
				}
			}
		});
	}
}

function closeDetail()
{
	$('#blockdiv').unblock().css({"overflow-y":"auto"});	
	$("#doodleDetail").remove();
}

function popupDetail(id)
{
	jQuery('#blockdiv').block({ message: null });
	var container=fetchOpDiv("doodleDetail");
	container.load(
		"/con/doodle/act/detail",
		{clientTime:Date(),id:id},
		function()
		{
			//移动至居中位置	
			var width=container.width();
			var height=container.height();
			var wWidth=jQuery(document).width();
			var wHeight=jQuery(window).height();
			var scrollTop = jQuery(window).scrollTop();
			
			container.css({left:(wWidth-width)/2,top:(wHeight-height)/2+scrollTop,"display":"block", "z-index":90});
		}
	);
}

function goOrder()
{
	var order = jQuery("#Select1").val();
	window.location.href = "http://huafeng.qq.com/con/doodle/act/list?order="+order;
}

function checkQQLogined()
{
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(APPID);	
		jQuery('#login_div').css({"z-index":jQuery('#login_div').css("z-index"),'display':"block"});
	}
	
}

function toSmallGame(url)
{
	url = "http://huafeng.qq.com"+url;
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(APPID,url);	
		//jQuery('#login_div').css({"z-index":jQuery('#login_div').css("z-index"),'display':"block"});
	}
	else{
		window.location.href = url;
	}
}

function sorryAlert()
{
	alert("敬请期待");
}

function qqLogin()
{
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(APPID);	
		//jQuery('#login_div').css({"z-index":jQuery('#login_div').css("z-index"),'display':"block"});
	}
	else{
		alert("您已经登录QQ了");
	}
}

function register()
{
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(APPID, "http://huafeng.qq.com/con/register/act/toregister");
		jQuery('#login_div').css({"z-index":jQuery('#login_div').css("z-index"),'display':"block"});		
	}
	else{	
		jQuery.ajax({
			type: "POST",
			dataType: "json",
			url: '/con/register/act/isreg',
			data: {client:Date()},
			success: function(json){
				if(json.code == 1){
					window.location.href = "http://huafeng.qq.com/con/register/act/list";
				}
				else if(json.code == 2)
				{
					window.location.href = "http://huafeng.qq.com/con/user/act/info";
				}
			}
		});
	}
}

function togame()
{
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(APPID, "http://huafeng.qq.com/con/game/act/list");
		jQuery('#login_div').css({"z-index":jQuery('#login_div').css("z-index"),'display':"block"});		
	}
	else{	
		window.location.href = "http://huafeng.qq.com/con/game/act/list";
	}
}


function registerCheck()
{
	var username = $("#name").val();
	if(username == "")
	{
		alert("请输入您的昵称");
		return false;
	}

	var age = $("#age").val();
	if(age == "")
	{
		alert("请输入您的年龄");
		return false;
	}
	var agePattern = /^[0-9]|[0-9]{2}$/;
	if(!agePattern.test(age))
	{
		alert("您输入的年龄格式不正确！");
		return false;
	}
	
	var email = $("#email").val();
	if(email == "")
	{
		alert("请输入您的电子邮箱");
		return false;
	}
	
	var email_back = $("#email_back").val();
	if(email_back == "")
	{
		alert("请输入您的电子邮箱");
		return false;
	}
	/*
	var emailPattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
	if(!emailPattern.test(email))
	{
		alert("您输入的电子邮箱格式不正确！");
		return false;
	}*/

	if($("#checkbox").attr("checked") == false)
	{
		alert("您没有同意参加协议");
		return false;
	}
	
	$("#province_value").val($("#province option:selected").html());
	$("#city_value").val($("#city option:selected").html());
	
	return true;
}

function   SetImgSize(pimg,iw,ih)   {   
  var   img   =   new   Image(); 
  img.src = pimg.src;   
  var   w   =   iw;   
  var   h   =   ih;   
  
 if(img.width>0 && img.height>0)
  {   
  	if(img.width>iw||img.height>ih)
  	{
		if((iw   /   ih)   >   (img.width   /   img.height))   
		{   
	   		h =  ih;   
	   		w   =   img.width   *   (ih   /   img.height);   
		}   
		else   
		{   
		 	w   =   iw;   
		 	h   =   img.height   *   (iw   /   img.width);   
		}   
   }
   else
  	{
  		w = img.width;
 		 h = img.height;
  	}
  }
 
  
  pimg.style.width=w;   
  pimg.style.height=h;  
  pimg.style.display="";  
}

//获取位于底部的div的ID，如果没有，则创建之
function fetchOpDiv(divName)
{
	if(jQuery("#"+divName).length==0)
	{
		//jQuery('body').block({ message: null });
		jQuery("<div class='op-div' id='"+divName+"'></div>").appendTo("body");
	}
	return jQuery("#"+divName);
}

function openUpload()
{
	var container=fetchOpDiv("useruploadlist");
	container.load(
		"/style/useruploadlist.php",
		{clientTime:Date()},
		function()
		{
			//移动至居中位置	
			var width=container.width();
			var height=container.height();
			var wWidth=jQuery(window).width();
			var wHeight=jQuery(window).height();
			var scrollTop = jQuery(window).scrollTop();
			//jQuery('.yy').block({ message: null }).css({"z-index":jQuery('body').css("z-index")});
			container.css({left:(wWidth-width)/2,top:(wHeight-height)/2+scrollTop,"display":"block"});
		}
	);
}

function closeUpload()
{
	$("#useruploadlist").remove();
}


function uploadImage()
{
	var file_value = $("#pic").val();
	if(file_value == "")
	{
		alert("请选择您要上传的图像文件");
		return false;
	}
	return true;
}

function openInvite(qq)
{
	var container=fetchOpDiv("userinvitelist");
	container.load(
		"/style/con/user/act/invitelist",
		{clientTime:Date(),qq:qq},
		function()
		{
			//移动至居中位置	
			var width=container.width();
			var height=container.height();
			var wWidth=jQuery(window).width();
			var wHeight=jQuery(window).height();
			var scrollTop = jQuery(window).scrollTop();
			//jQuery('.yy').block({ message: null }).css({"z-index":jQuery('body').css("z-index")});
			container.css({left:(wWidth-width)/2,top:(wHeight-height)/2+scrollTop,"display":"block"});
		}
	);
}

function closeInvite()
{
	$("#userinvitelist").remove();
}

function invite()
{
	var url = $("#inviteUrl").val();
	copyToClipboard(url);
}


function userVoteListGoPage(page,type)
{
	$("#votelist").load(
			"/style/con/user/act/votelist",
			{clientTime:Date(),type:type,page:page}
		);
}

function userNewListGoPage(page,type)
{
	$("#newlist").load(
			"/style/con/user/act/newlist",
			{clientTime:Date(),type:type,page:page}
		);
}

function commentGoPage(page)
{
	window.location.href = "http://tonlion.qq.com/style/con/comment/act/list?page="+page;
}

//投票
function vote_ad(_id)
{
	if(!checkqqload())
	{
		openLogin(APPID, window.location.href);
	}
	else
	{	
		id = _id;
		qq_form_ad(APPID, "", "", "", "", 2, "投票"
				, "http://huafeng.qq.com/con/doodle/act/vote", id,true,false,false);
		return;
	}
}

//获取位于底部的div的ID，如果没有，则创建之
function fetchOpDiv(divName)
{
	if(jQuery("#"+divName).length==0)
	{
		//jQuery('body').block({ message: null });
		jQuery("<div class='op-div' id='"+divName+"'></div>").appendTo("body");
	}
	return jQuery("#"+divName);
}


function copyToClipboard(txt) {  
     if(window.clipboardData) {        
		 window.clipboardData.clearData();        
		 window.clipboardData.setData("Text", txt);        
		 alert("链接复制成功，请转帖好友分享!");      
     } else if(navigator.userAgent.indexOf("Opera") != -1) {        
          window.location = txt;
           alert("链接复制成功，请转帖好友分享!");              
     } else if (window.netscape) {        
          try {        
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");        
          } 
		  catch (e) {        
               alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");        
          }        
          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);        
          if (!clip)        
            return;        
          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);        
          if (!trans)        
			return;        
          trans.addDataFlavor('text/unicode');        
          var str = new Object();        
          var len = new Object();        
          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);        
          var copytext = txt;        
          str.data = copytext;        
          trans.setTransferData("text/unicode",str,copytext.length*2);        
          var clipid = Components.interfaces.nsIClipboard;        
          if (!clip)        
            return false;        
          clip.setData(trans,null,clipid.kGlobalClipboard);        
          alert("链接复制成功，请转帖好友分享!");    
     }        
}