document.domain="qq.com"
var divYutingVote = document.createElement('div');
var divYutingNews = document.createElement('div');
var isCreated = false;
var id;
var fileByQQ;
var picType;
var reason;

function alertNews()
{
	$('body').block({ message: null }).css({"overflow-y":"visible"});
	divYutingNews.id = 'yuting_vote';

	divYutingNews.style.visibility = 'hidden';
	//divE.style.filter = 'Alpha(opacity=0)';
	divYutingNews.style.opacity = 1;
	divYutingNews.style.position = 'absolute';

	divYutingNews.style.top = "40%";
	divYutingNews.style.zIndex = "99";
	divYutingNews.style.left = "33%";
	var news_HTML = "";
	
	news_HTML += "<table width='447' height='236' border='0' cellpadding='0' cellspacing='0'>";
  	news_HTML += "<tr>"
    news_HTML += "<td background='images/zhuanpan1.gif'><table width='447' height='200' border='0' cellpadding='0' cellspacing='0'>";
    news_HTML += "<tr>";
    news_HTML += "<td width='402' height='30'>&nbsp;</td>";
    news_HTML += "<td width='45'><img src='images/12.gif' alt='' width='34' height='32' border='0' onClick='closeNews();' style='cursor:pointer;'/></td>";
    news_HTML += "</tr>";
    news_HTML += "<tr>";
    news_HTML += "<td colspan='2'>&nbsp;</td>";
    news_HTML += "</tr>";
    news_HTML += "<tr>";
    news_HTML += "<td colspan='2'>&nbsp;</td>";
    news_HTML += "</tr>";
    news_HTML += "<tr>";
    news_HTML += "<td colspan='2'>&nbsp;</td>";
    news_HTML += "</tr>";
    news_HTML += "<tr>";
    news_HTML += "<td colspan='2'>&nbsp;</td>";
    news_HTML += "</tr>";
    news_HTML += "</table></td>";
    news_HTML += "</tr>";
    news_HTML += "</table>";
	
	divYutingNews.innerHTML = news_HTML;
	    	
	document.body.appendChild(divYutingNews);
	divYutingNews.style.visibility = 'visible';
	
	
}

function timeoutClose()
{
	setTimeout("closeNews()", 5000);
}

function closeNews()
{
	divYutingNews.style.visibility = 'hidden';
	$('body').unblock().css({"overflow-y":"auto"});
	
}

function bodyInit()
{
	if(!checkqqload()){ //qq没有登录，先登录		
		openLogin(4006502);
		alert("请您登录QQ");
		return;
	}
}

function qqLogin()
{
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(4006502);
	}
	else
	{
		alert("您已经登录QQ了");
	}
}

function qqLogout()
{
	if(!checkqqload()){ //qq没有登录，先登录
		alert("您已经退出QQ登录了");
	}
	else
	{
		window.location.href = "http://yuting.qq.com/con/register/act/logout";
	}	
}

function checkQQLogined()
{
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(4006502);
		return false;
	}
	return true;
}

function vote(_id, _fileByQQ, _picType)
{
	var today = new Date();
	var endDay = new Date("2008/11/24");
	
	if(Date.parse(today) >= Date.parse(endDay))
	{
		alert("投票活动已结束，谢谢您的支持");
		return;
	}
	if(!checkqqload())
	{
		openLogin(4006502);
		alert("请您登录QQ");
		return;
	}
	else
	{	
		id = _id;
		fileByQQ = _fileByQQ;
		picType = _picType;
		yutingVote(picType);
		return;
	}
}

function closeFrame()
{
	divYutingVote.style.visibility = 'hidden';
	return;
}

function clickFrame()
{	
	reason =  $(':radio:checked').val();
	if(reason == null)
	{
		alert("请选择您投票的原因");
		return;
	}
	divYutingVote.style.visibility = 'hidden';
	qq_form(4006502, "", "", "", "", 2, "投票"
				, "http://yuting.qq.com/con/vote/act/saveAjax", id,true,false,false
				,fileByQQ,picType,reason);
	return;
}

function registerList()
{
	if(!checkqqload())
	{
		openLogin(4006502,"http://yuting.qq.com/con/register/act/list");
		alert("请先登录QQ");
	}
	else{
		window.location.href = "http://yuting.qq.com/con/register/act/list";
	}
}

function listPerson()
{
	if(!checkqqload())
	{
		openLogin(4006502,"http://yuting.qq.com/con/show/act/listpersonall");
		alert("请先登录QQ");
	}
	else{
		window.location.href = "http://yuting.qq.com/con/show/act/listpersonall";
	}
}

function uploadList()
{
	var today = new Date();
	var endDay = new Date("2008/11/24");
	
	if(Date.parse(today) >= Date.parse(endDay))
	{
		alert("上传活动已结束，谢谢您的支持");
		return;
	}
	if(!checkqqload())
	{
		openLogin(4006502,"http://yuting.qq.com/con/upload/act/list");
		alert("请先登录QQ");
	}
	else{
		window.location.href = "http://yuting.qq.com/con/upload/act/list";
	}
}

function checkRegister()
{
	if(!checkQQLogined())
	{
		alert("请您先登录QQ");
		return false;
	}
	var email = $('#email').val();
	var tel = $('#tel').val();
	var emailPattern = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	if(email.length == 0 || !emailPattern.test(email))
	{
		alert("您输入的邮箱地址格式不正确！");
		return false;
	}
	
	var telPattern = /^\d{11}$|^\d{3}-\d{7,8}$|^\d{4}-\d{7,8}$/;
	if(tel.length == 0 || !telPattern.test(tel))
	{
		alert("您输入的电话格式不正确！应该为手机号码或者xxxx-xxxxxxxx形式");
		return false;
	}
	
	var recommendQQ = $('#recommendQQ').val();
	if(recommendQQ.length != 0 && !/^[1-9][0-9]{4,}$/.test(recommendQQ))
	{
		alert("您输入的QQ号格式不正确！");
		return false;
	}
	return true;
}

function checkUpload()
{
	var today = new Date();
	var endDay = new Date("2008/11/24");
	
	if(Date.parse(today) >= Date.parse(endDay))
	{
		alert("上传活动已结束，谢谢您的支持");
		return false;
	}
	if(!checkQQLogined())
	{
		alert("请您先登录QQ");
		return false;
	}
	var type = $(':radio:checked').val();
	if(type != "1" && type != "2" && type != "3")
	{
		alert("请选择上传作品的类型");
		return false;
	}
	$('#type').val(type);
	
	var name = $('#name').val();
	if(name.length == 0 || name.length > 8)
	{
		alert("请在8个字之内对描述作品的名称");
		return false;
	}
	
	var descriptionText  = $('#descriptionText').val();
	if(descriptionText.length == 0 || descriptionText.length > 100)
	{
		alert("请在100个字之内对作品进行说明");
		return false;
	}
	else{
		$('#description').val(descriptionText);
	}
	
	var length = $(":file").length;
	var sum = 0;
	$('#uploadNumber').val('');
	for(i = 0;i < length;i++)
	{
		if($(":file")[i].value != '')
		{
			var numberValue = $('#uploadNumber').val();
			$('#uploadNumber').val(numberValue+";"+i);
			sum++;
		}
	}
	if(sum != 1 && type != 2)
	{
		alert("请只选择1个文件上传");
		$(':file').val('');
		return false;
	}
	else if(type == 2 && sum > 4)
	{
		alert("你选择了组图上传，请正确选择1-4个文件上传");
		return false;
	}
	
	return true;
}

function pageInit(){
	checkQQLogined();
}


function getValueFromKey(val) {
 var uri = window.location.search;
 var re = new RegExp("" +val+ "\=([^\&\?]*)", "ig");
 return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
}

function goPrePage(e)
{
	var curr_page = eval($('#curr_page').val())-1;
	var FState = $('#FState').val();
	var qq = $('#qq').val();
	var orderby = $('#orderby').val();
	$('#curr_page').val(curr_page);
	if(e != null)
	{
		window.location = strUrl + "&order="+orderby+"&curr_page=" + curr_page+ "&qq=" + qq+"&e="+e;
	}
	else
	{
		window.location = strUrl + "&order="+orderby+"&curr_page=" + curr_page+ "&qq=" + qq;
	}
}
function goNextPage(e)
{
	var curr_page = eval($('#curr_page').val())+1;
	var FState = $('#FState').val();
	var qq = $('#qq').val();
	var orderby = $('#orderby').val();
	$('#curr_page').val(curr_page);
	if(e != null)
	{
		window.location = strUrl + "&order="+orderby+"&curr_page=" + curr_page+ "&qq=" + qq+"&e="+e;
	}
	else
	{
		window.location = strUrl + "&order="+orderby+"&curr_page=" + curr_page+ "&qq=" + qq;
	}
}
function goPage(e)
{
	var curr_page = eval($('#curr_page').val());
	var FState = $('#FState').val();
	var qq = $('#qq').val();
	var orderby = $('#orderby').val();
	if(e != null)
	{
		window.location = strUrl + "&order="+orderby+"&curr_page=" + curr_page+ "&qq=" + qq+"&e="+e;
	}
	else
	{
		window.location = strUrl + "&order="+orderby+"&curr_page=" + curr_page+ "&qq=" + qq;
	}
}

function checkinput()
{
	//alert(0);
	var i = 0;
	$('#FResult').val("");
	for(i = 0;i < g_iNumCount; ++i)
	{
		var ctl1 = $("#FIsCheck" + i + "_1");
		var ctl2 = $("#FIsCheck" + i + "_2");
		//alert("step 2");
		if(ctl1 != null && ctl2 != null)
		{
			if(ctl1.attr("checked") == true)
			{
				//alert("step 3");
				var value = $('#FResult').val();
				$('#FResult').val(value+";"+ctl1.val());
			}
			else if(ctl2.attr("checked") == true)
			{
				//alert("step 4");
				var value = $('#FResult').val();
				$('#FResult').val(value+";"+ctl2.val());
				//alert("step 5");
			}
			else
			{
				alert('请选择每一条记录的审核结果!');
				return false;
			}
		}
	}
	//alert($('#FResult').val());
	return true;
}

function setCheck(isCheck)
{
	var i = 0;
	for(;i < g_iNumCount; ++i)
	{
		var ctl1 = $("#FIsCheck" + i + "_1");
		var ctl2 = $("#FIsCheck" + i + "_2");
		//alert("step 2");
		if(ctl1 != null && ctl2 != null)
		{
			if(isCheck == 1)
			{
				ctl1.attr("checked",true);
				ctl2.attr("checked",false);
			}
			else
			{
				ctl1.attr("checked",false);
				ctl2.attr("checked",true);
			}			
		}
	}
}

function preSubmit()
{
	if(!checkinput())
	{
		return;
	}	
	$('#form1').submit();
}

//-------------
var mousePos = new Array(); 
mousePos["x"] = '';    
mousePos["y"] = ''; 
/*   
    mouseLoc 把获取到的鼠标坐标数据赋值给了   
    mousePos 这个全局数组.   
    mousePos["x"] 的值就是鼠标的 X 轴即横向距页面左边的像素距离   
    mousePos["y"] 的值就是鼠标的 Y 轴即纵向距页面顶部的像素距离   
*/   
function mouseLoc(e){    
  if(document.all){    
    x = event.x + document.body.scrollLeft;    
    y = event.y + document.body.scrollTop; 	
  } else {    
    x = e.pageX;    
    y = e.pageY;    
  }    
  mousePos["x"] = x;    
  mousePos["y"] = y;  
 
  return true;    
}    
/*   
    为了让页面能即时获得鼠标的坐标,我们只能用之类的事件执行这样的函数.   
    在这里使用 document.onmousemove 事件来执行 mouseLoc   
    以不断更新全局数组 mousePos 里的鼠标位置数据   
*/   
if(document.layers){    //NS4    
    document.captureEvents(Event.MOUSEMOVE);    
}    
document.onmousedown = mouseLoc;  

//------------------------------------

//设置图片自动调整
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 = iw;
  h = ih;
  }
  
  pimg.width=w;   
  pimg.height=h;   
  pimg.style.display="";  
}

function onClickTypeRadio()
{
	var type = $(':radio:checked').val();
	if(type != "2")
	{
		$('#pic2').attr('disabled', true);
		$('#pic3').attr('disabled', true);
		$('#pic4').attr('disabled', true);
	}
	else
	{
		$('#pic2').attr('disabled', false);
		$('#pic3').attr('disabled', false);
		$('#pic4').attr('disabled', false);
	}
}
