function setTab(area,id) {
	var tabArea=document.getElementById(area);

	var contents=tabArea.childNodes;
	for(var i=0; i<contents.length; i++) {

		if(contents[i].className=='tabCnt') {
			contents[i].style.display='none';

		}
	}
	document.getElementById(id).style.display='';

	var tabs=document.getElementById('tabs').getElementsByTagName('a');
	for(i=0; i<tabs.length; i++) { tabs[i].className='tab'; }
	document.getElementById(id+'tab').className='tab curtab';

	document.getElementById(id+'tab').blur();
}
//-----------------------------------cansxx---------------------------------------//
function resetImg(){
	$("#leftbar_cansxx a.csgz").css("background","url(images/game/cansxx_07.gif)");
	$("#leftbar_cansxx a.cslc").css("background","url(images/game/cansxx_02_03.gif)");
	$("#leftbar_cansxx a.jpsz").css("background","url(images/game/cansxx_02_06.gif)");
	$("#leftbar_cansxx a.zysx").css("background","url(images/game/cansxx_02_08.gif)");
	$("#leftbar_cansxx a.zjpw").css("background","url(images/game/cansxx_02_10.gif)");
}
function play(num){
	if(num == 1) {
		$("#leftbar_cansxx a.csgz").css("background","url(images/game/cansxx_01_07.gif)");
		$("#contents").load("index.php?op=game&do=game&part=rule");
	} else if(num == 2) {
		$("#leftbar_cansxx a.cslc").css("background","url(images/game/cansxx_10.gif)");
		$("#contents").load("index.php?op=game&do=game&part=flow");
	} else if(num == 3) {
		$("#leftbar_cansxx a.jpsz").css("background","url(images/game/cansxx_12.gif)");
		$("#contents").load("index.php?op=game&do=game&part=award");
	} else if(num == 4) {
		$("#leftbar_cansxx a.zysx").css("background","url(images/game/cansxx_14.gif)");
		$("#contents").load("index.php?op=game&do=game&part=attention");
	} else if(num == 5) {
		$("#leftbar_cansxx a.zjpw").css("background","url(images/game/cansxx_16.gif)");
		$("#contents").load("index.php?op=game&do=game&part=winner");
	}
}
function cansxx(){
	resetImg();
	$("#leftbar_cansxx a.csgz").click(function(){
		resetImg();
		play(1);
	});
	$("#leftbar_cansxx a.cslc").click(function(){
		resetImg();
		play(2);
	});
	$("#leftbar_cansxx a.jpsz").click(function(){
		resetImg();
		play(3);
	});
	$("#leftbar_cansxx a.zysx").click(function(){
		resetImg();
		play(4);
	});
	$("#leftbar_cansxx a.zjpw").click(function(){
		resetImg();
		play(5);
	});
}
//-----------------------------------index---------------------------------------//
function index(){
	$("#newPhoto").load("index.php?do=photolist");
	$("#seaButton").click(function(){
		var seaText = $("#seaText").val();
		var condition = $('input[@name=type][@checked]').val();
		if(seaText.length>100) {
			alert('查询字符串不能太长！');
			return false;
		}
		if(condition==null) {
			alert('请选择查询方式！');
			return false;
		}
		//$("#newPhoto").load('index.php?do=photolist',{condition:condition,seaText:seaText});
		document.seaForm.submit();
	});
	$("#HotLabel").find("a").click(function(){
		searchTag($(this).attr("title"));
	});
}
function searchTag(tag){
	$("#seaText").val(tag);
	$("input[@type=radio][@value=tag]").attr("checked","checked");//
	document.seaForm.submit();
	$("#seaText").val("");
	$("input[@type=radio][@value=productName]").attr("checked","checked");//
}
//-----------------------------------cszp---------------------------------------//
function cszp(){
	$("#seaButton").click(function(){
		seaTextP = $("#seaText").val();
		conditionP = $('input[@name=type][@checked]').val();
		if(seaTextP.length>100) {
			alert('查询字符串不能太长！');
			return false;
		}
		if(conditionP==null) {
			alert('请选择查询方式！');
			return false;
		}
		seaText = seaTextP;
		condition = conditionP;
		page = 1;
		cszpView();
	});
	colorDefault();
}
function cszpView() {
	$("#cszpList").load('index.php?op=photo&do=productlist',{condition:condition,seaText:seaText,page:page,type:type,order:order});
}
function setAtten() {
	clearorderstyle();
	if(atten==1) {
		$("#atten").html("评论数↓").css("color","red");
		atten = 0;
		order = 3;
	} else {
		$("#atten").html("评论数↑").css("color","red");
		atten = 1;
		order = 4;
	}
	cszpView();
}
function clearorderstyle(){
	$("#atten").css("color","").html("评论数");
	$("#createTime").css("color","").html("上传时间");
	$("#productname").css("color","").html("名称");
    $("#heat").css("color","").html("点击");
    $("#lastmark").css("color","").html("分数");
}
function colorDefault(){
	$("#atten").css("color","");
	$("#createTime").css("color","red");
	$("#productname").css("color","");
    $("#heat").css("color","");
    $("#lastmark").css("color","");
	$("#type0").css("color","red");
	$("#type1").css("color","");
	$("#type2").css("color","");
	$("#type3").css("color","");
}
function cleartypestyle(){
	$("a[id*=type]").css("color","");
}
function setCreatTime() {
	clearorderstyle();
	if(creatTime==1) {
		$("#createTime").html("上传时间↓").css("color","red");
		creatTime = 0;
		order = 1;
	} else {
		$("#createTime").html("上传时间↑").css("color","red");
		creatTime = 1;
		order = 2;
	}
	cszpView();
}
function setproductName() {
	clearorderstyle();
	if(productname==1) {
		$("#productname").html("名称↓").css("color","red");
		productname = 0;
		order = 5;
	} else {
		$("#productname").html("名称↑").css("color","red");
		productname = 1;
		order = 6;
	}
	cszpView();
}
function cszpPage(value) {
	page = value;
	cszpView();
}
function setType(value) {
	cleartypestyle();
	$("#type"+value).css("color","red");
	type = value;
	page=1;
	cszpView();
}

function setHeat() {
	clearorderstyle();
	if(heat==1) {
		$("#heat").html("点击↓").css("color","red");
		heat = 0;
		order = 7;
	} else {
		$("#heat").html("点击↑").css("color","red");
		heat = 1;
		order = 8;
	}
	cszpView();
}
function setLastmark() {
	clearorderstyle();
	if(lastmark==1) {
		$("#lastmark").html("分数↓").css("color","red");
		lastmark = 0;
		order = 9;
	} else {
		$("#lastmark").html("分数↑").css("color","red");
		lastmark = 1;
		order = 10;
	}
	cszpView();
}
//-----------------------------------up2---------------------------------------//
function up2(type){
	if(type != 'edit'){
		textMessage($('input[@name=productname]'),"[标题不能超过20个字！]");
		textMessage($('textarea[@name=remark]'),"[描述不能超过50个字！]");
		textMessage($('input[@name=producttitle]'),"[标签不能超过50个字符，请用空格隔开！]");
	}
	$("#upBut").click(function(){
		var productname = $('input[@name=productname]').val();
		var remark = $('textarea[@name=remark]').val();
		var type = $('input[@name=type][@checked]').val();
		var producttitle = $('input[@name=producttitle]').val();
		if(productname.trim() == '') {
			alert("标题必须填写！");
			return false;
		}
		if(productname.trim() == '[标题不能超过20个字！]') {
			alert("标题必须填写！");
			return false;
		}
		if(productname.length > 20) {
			alert("标题不能多于20个字！");
			return false;
		}
		if(remark.length > 50) {
			alert("描述不能多于50个字！");
			return false;
		}
		if(producttitle.length > 50) {
			alert("标签不能超过50个字符，请用空格隔开！");
			return false;
		}
		if(id == "") {
			alert("请先预览后上传图片！");
			return false;
		}
		if(remark.trim() == '[描述不能超过50个字！]') {
			$('textarea[@name=remark]').val("");
		}
		if(producttitle.trim() == '[标签不能超过50个字符，请用空格隔开！]') {
			$('input[@name=producttitle]').val("");
		}
		document.prodcutform.submit();

	});
	$("#returnBut").click(function(){
		window.location="index.php?op=space";
	});
	$("#delBut").click(function(){
		if(confirm("你确定要删除此作品吗？")){
			$.ajax({
				   type: "POST",
				   url: "index.php?op=space&do=delphoto",
				   data: {id:id},
				   success: function(msg){
					   alert("删除成功！");
					   window.location="index.php?op=space";
				   }
			});
		}

	});
}
function textMessage(obj,msg){
	obj.focus(function(){
		if(obj.val().trim()==msg){
			obj.val('');
			obj.css("color","");
			obj.css("fontStyle","");
		}
	});
	obj.blur(function(){
		if(obj.val().trim()==''){
			obj.val(msg);
			textStyle(obj);
		}
	});
	obj.val(msg);
	textStyle(obj);
}
function textStyle(obj){
	obj.css("color","#808080");
	obj.css("fontStyle","italic");
}
function show(message){
    
	if(message == "3") {
		alert("文件大小超出！");
	} else {
		id = message.split("-")[0];
		$("#id").val(id);
		picname = message.split("-")[1];
		width_orig = message.split("-")[2];
		height_orig = message.split("-")[3];
		var width = 300,height = 200;
		if (width_orig/width < height_orig/height) {
		    width = (height / height_orig) * width_orig;
		} else {
		    height = (width / width_orig) * height_orig;
		}
		//$("#picPreview").css("height",height).css("width",width);
		$("#picPreview").find("td").html("");
		$("#picPreview").animate( {height:height,width:width} , 500,"",function(){
			$("#picPreview").html("<img src='"+url+picname+"' height='"+height+"' width='"+width+"'  alt='照片' />");
		});
	}
}
function waitting(){
	$("#picPreview").append("<table bgcolor='#FDFDFD' width='100%' height='100%'><tr><td valign='center' align='center'></td></tr></table>");
	$("#picPreview").find("td").html("<img src='images/loading.gif'  alt='请等待...' />");
}
//-----------------------------------zhuce---------------------------------------//
function zjkj(){
	$("#dpfzp").load("index.php?op=space&do=imglist",{listname:"notaudit"});
	$("#ypfzp").load("index.php?op=space&do=imglist",{listname:"audited"});
	$("#seaButton").click(function(){
		seaTextP = $("#seaText").val();
		conditionP = $('input[@name=type][@checked]').val();
		if(seaTextP.length>100) {
			alert('查询字符串不能太长！');
			return false;
		}
		if(conditionP==null) {
			alert('请选择查询方式！');
			return false;
		}
		seaText = seaTextP;
		condition = conditionP;
		$("#dpfzp").load('index.php?op=space&do=imglist',{condition:condition,seaText:seaText,listname:"notaudit"});
		$("#ypfzp").load('index.php?op=space&do=imglist',{condition:condition,seaText:seaText,listname:"audited"});
	});
}
function notaudit(page) {
	$("#dpfzp").load('index.php?op=space&do=imglist',{condition:condition,seaText:seaText,listname:"notaudit",page:page});
}
function audited(page) {
	$("#ypfzp").load('index.php?op=space&do=imglist',{condition:condition,seaText:seaText,listname:"audited",page:page});
}
//-----------------------------------zhuce---------------------------------------//
function zhuce(){
	$("input").keydown(function(event){
		if(event.keyCode == 13) login();
	});
	$("#loginBut").click(login);
}
function login(){
	var username,password,datasource,remember;
	username = $("input[name='username']").val();
	password = $("input[name='password']").val();
	if($("#remember").attr("checked")){
		remember = 1;
	} else {
		remember = 0;
	}
	if(username.trim()==""){
		fadeshow("用户名不能为空！");
		$("input[name='username']").focus();
		return false;
	} else if(password.trim()=="") {
		fadeshow("密码不能为空！");
		$("input[name='password']").focus();
		return false;
	}
	datasource = $("select[name='datasource']").val();
	$.post("index.php?op=space&do=login",{username:username,password:password,datasource:datasource,remember:remember}, function(data){
		  if(data == '0') {
			  fadeshow("用户名密码错误！");
			  return false;
		  } else {
			  window.location="index.php?op=space&do=spaceview";
		  }
		});
}
function fadeshow(msg){
	$("#msg").hide();
	$("#msg").html(msg);
	$("#msg").fadeIn("fast");
}
//-----------------------------------up---------------------------------------//
function up(){
	$("#wdzp").load("index.php?op=space&do=imglist",{listname:"myproduct"},titleClick);
	$("#plgzp").load("index.php?op=space&do=imglist",{listname:"commendedproduct"});
	$("#seaButton").click(function(){
		seaTextP = $("#seaText").val();
		conditionP = $('input[@name=type][@checked]').val();
		if(seaTextP.length>100) {
			alert('查询字符串不能太长！');
			return false;
		}
		if(conditionP==null) {
			alert('请选择查询方式！');
			return false;
		}
		seaText = seaTextP;
		condition = conditionP;
		$("#wdzp").load('index.php?op=space&do=imglist',{condition:condition,seaText:seaText,listname:"myproduct"},titleClick);
		$("#plgzp").load('index.php?op=space&do=imglist',{condition:condition,seaText:seaText,listname:"commendedproduct"});
	});
}
function myproduct(page) {
	$("#wdzp").load('index.php?op=space&do=imglist',{condition:condition,seaText:seaText,listname:"myproduct",page:page},titleClick);
}
function changepsw() {
	var password1 = $("#password1").val();
	var password2 = $("#password2").val();
	var password3 = $("#password3").val();
	if(password2 != password3){
		passwordmsg("两次输入密码不一致！");
		return false;
	}
	if(password2.length > 10){
		passwordmsg("密码长度不能超过10位！");
		return false;
	}
	if(password2.trim().length <= 0){
		passwordmsg("新密码不能为空！");
		return false;
	}
	if(password1.trim() == password2.trim()){
		passwordmsg("新密码与原密码一致！");
		return false;
	}
	$.post("index.php?op=space&do=confirmpsw",{password1:password1,password2:password2,password3:password3},function(msg){
		if(msg == 0) {
			passwordmsg('原密码不正确！');
			return false;
		} else {
			alert(msg);
			tb_remove();
		}
	});
}
function passwordmsg(msg){
	$("#message").html(msg).fadeIn("slow");
}
function commendedproduct(page) {
	$("#plgzp").load('index.php?op=space&do=imglist',{condition:condition,seaText:seaText,listname:"commendedproduct",page:page});
}
function numMessage(num){
	alert("最多只能上传"+num+"幅作品！");
}
function timeMessage(num){
	switch (num) {
	case 1:alert("比赛尚未开始！");break;
	case 2:alert("比赛已经结束！");break;
	case 3:alert("上传作品时间已截止！");break;
	default:break;
	}
}
function editMessage(){
	alert("已审核通过的作品不能修改！");
}
function delMessage(){
	alert("已审核通过的作品不能删除！");
}
var inedit = false;
function titleClick(){
	$("span.title").click(function(){
		//var classname = $(this).parent().parent().find("a:first-child").attr("class");
		var titlestr = $(this).parent().find("font").html();
		if(titlestr != "状态：已审核") {
			if(!inedit) {
				inedit = !inedit;
				var tmp = $(this).html();
				var id = $(this).parent().find("input").val();
				$(this).html("<input id='edittext' type='text'");
				$("#edittext").val(tmp);
				$("#edittext").select();
				$("#edittext").blur(function(){
					var title = $(this).val();
					if(title.trim() == '') {
						alert("标题必须填写！");
						$(this).parent().html(tmp);
						inedit = !inedit;
						return false;
					}
					if(title.length > 20) {
						alert("标题不能多于20个字！");
						$("#edittext").select();
						return false;
					}
					$.post("index.php?op=space&do=savetitle",{title:title,id:id});
					$(this).parent().html(title);
					inedit = !inedit;
				});
			}
		}
	});
}
function delPhoto(id){
	if(confirm("你确定要删除此作品吗？")){
		$.ajax({
			   type: "POST",
			   url: "index.php?op=space&do=delphoto",
			   data: {id:id},
			   success: function(msg){
				   alert("删除成功！");
				   up();
			   }
		});
	}
}
//-----------------------------------photoview---------------------------------------//
function loadComm(page){
	$("#comments").load("index.php?op=photo&do=comments",{type:1,id:id,page:page},JT_init);
}
function delComm(id){
	if(confirm("确定要删除吗？")){
		$.post("index.php?op=photo&do=delcomments",{id:id},function(msg){
			if(msg=='0'){
				alert("删除失败！");
			} else {
				//alert("删除成功！");
			}
			loadComm(1);
		});
	}
}

function photopageinit(){
	$('#showimage').onmousemove = function(ev){
		showPageFlag(ev)
	}
	$('#showimage').onclick = function(ev){
		pageByFlag(ev);
	}
}

function showPageFlag(ev){
	var cur_pix = $('#showimage');

	var pix_width = parseInt(cur_pix.attr('width'));
	var middle = Math.floor(pix_width / 2);
	var event = ev || window.event;
	if(is_firefox){
		mouse_x = event.layerX;
	}else{
		mouse_x = event.offsetX;
	}
	//alert (middle);
	if(mouse_x < middle){
		cur_pix.css('cursor','../images/prev.ani');
		cur_pix.attr('title','点击到上一张');
		return -1;
	}else if(mouse_x>=middle){
		cur_pix.css('cursor','../images/next.ani');
		cur_pix.attr('title','点击到下一张');
		return 1;
	}else{
		cur_pix.addClass('defaultcursor');
		cur_pix.attr('title','');
		return 1;
	}
}

function pageByFlag(ev){
	var prev_url = $('#previmg').val();
	var next_url = $('#nextimg').val();
	var is_left = (showPageFlag(ev)==-1) ? true : false;
	if(is_left){
		img_url = prev_url;
	}else{
		img_url = next_url;
	}
	window.location.href = img_url;
}

function photoview(){
	//photopageinit();
	var productid = $("productid").val();
	loadComm(1);
	$("#addbut").click(function(){
		var msg = $("#msg").val();
		if(msg.trim().length==0) {
			alert("留言不能为空！");
			return false;
		}
		if(msg.length>100) {
			alert("留言不能超过过100个字！");
			return false;
		}
		$.ajax({
			   type: "POST",
			   url: "index.php?op=photo&do=comments",
			   data: {type:2,msg:msg,id:id},
			   success: function(msg){
				   alert("留言成功！");
				   $("#msg").val("");
				   loadComm(1);
			   }
		});
	});
}
//-----------------------------------loginsmall---------------------------------------//
function loginsmall(){
	$("#userPanel a[title='我要参赛']").click(function(){
		//$("#loginPanel").load("index.php?op=space&do=loginsmall");
		$.post("index.php?op=space&do=loginsmall",{},function(msg){
			$("#loginPanel").html(msg);
			   $("#username").focus();
			   $("#username")[0].focus();
			   $("#button1").click(loginaction);
			   $("#username").keydown(function(event){
					if(event.keyCode == 13) loginaction();
				});
			   $("#password").keydown(function(event){
					if(event.keyCode == 13) loginaction();
				});
			   $("#button2").click(function(){
				   $("#username").val("");
				   $("#password").val("");
			   });
		});
	});
}
function loginaction(){
	var username,password,remember;
	username = $("#username").val();
	password = $("#password").val();
	if($("#remember").attr("checked")){
		remember = 1;
	} else {
		remember = 0;
	}
	if(username.trim()=='') return false;
	if(password.trim()=='') return false;
	$.post("index.php?op=space&do=login",{username:username,password:password,datasource:0,remember:remember}, function(data){
		  if(data != '1') {
			  document.loginsmallform.submit();
		  } else {
			  //alert('登陆成功！');
			  $("#loginPanel").load("index.php?op=space&do=userpannel");

		  }
		});
}
function logouturl(){
	$.post("index.php?op=space&do=logoutsmall",function(){
			alert("退出成功！");
			$("#loginPanel").html('<div id="userPanel" class="join"><a href="javascript:;" title="我要参赛">我要参赛</a></div>');
			loginsmall();
		});
}

