/**
 * 相册 表单验证
 *$Id: checkphoto.js 58415 2010-04-13 10:19:04Z shunyao $
 *
 */
$(document).ready(function (){
	if(typeof(isLogin) != 'undefined' && isLogin == 1)
	{
		//左侧的菜单
		left_toggle_menu();
	}
	
	$('#albumcreateform').submit(function (){
		if(checkablumtitle())
		{
			$('#ablumcreatesubmit').attr("disabled","disabled");
			$('#ablumcreatesubmit').attr("value","正在提交");
			return true;
		}
		else
		{
			return false;
		}
	});
	$('#albumedit').submit(function (){
		if(checkablumtitle())
		{
			$('#ablumedit').attr("disabled","disabled");
			$('#ablumedit').attr("value","正在提交");
			return true;
		}
		else
		{
			return false;
		}
	});
	$("#html_atitle").blur(function (){
		var ishtml_atitle = checkablumtitle();
	})

	function checkablumtitle() //检查专辑名称
	{
		var ablumtitle = $("#html_atitle").val();
		if(ablumtitle == "")
		{
			$("#html_atitleerr").css("color", "red");
			$("#html_atitleerr").html("<img src='" + image_path + "/wrong.gif' />&nbsp;" + errorno['6101']);
			$("#html_atitleerr").show();

			return false;
		}
		else if(!strlen(ablumtitle,1,20))
		{
			$("#html_atitleerr").css("color", "red");
			$("#html_atitleerr").html("<img src='" + image_path + "/wrong.gif' />&nbsp;" + errorno['6102']);
			$("#html_atitleerr").show();
			return false;
		}
		else

		{
			$("#html_atitleerr").html("<img src='" + image_path + "/right.gif' />");
			$("#html_atitleerr").show();
			return true;
		}
	}

// 图片编辑
	$("#imageditform").submit(function (){
		if(checkimagetitle() && checkimagetagtitle() && checkImageType() && checkGalleryType())
		{
			$('#imageeditsubmit').attr("disabled","disabled");
			$('#imageeditsubmit').attr("value","正在提交");
			return true;
		}
		else
		{
			return false;
		}
	});

	$('#html_original_1').click(function(){
		if($(this).val() == 1)
		{
			$('#recomendtogallery').css('display', 'block');	
		}
		else
		{
			$('#recomendtogallery').css('display', 'none');
			$('#html_istatus').attr("checked",'');
			
		}	
	});
	$('#html_original_0').click(function(){
		if($(this).val() == 1)
		{
			$('#recomendtogallery').css('display', 'block');	
		}
		else
		{
			$('#recomendtogallery').css('display', 'none');
			$('#html_istatus').attr("checked",'');
		}	
	});
	
	$('#html_ititle').blur(function (){
		var isititle = checkimagetitle();
	})
	$('#html_ttitle').blur(function (){
		var isttitle = checkimagetagtitle();

	})
	function checkimagetitle()
	{
		var imagetitle = $('#html_ititle').val();
		if(imagetitle == "")
		{
			$("#html_ititleerr").css("color", "red");
			$("#html_ititleerr").html("<img src='" + image_path + "/wrong.gif' />&nbsp;" + errorno['6101']);
			$("#html_ititleerr").show();
			return false;
		}
		else if(!strlen(imagetitle,1,20))
		{
			$("#html_ititleerr").css("color", "red");
			$("#html_ititleerr").html("<img src='" + image_path + "/wrong.gif' />&nbsp;" + errorno['6102']);
			$("#html_ititleerr").show();
			return false;
		}
		else
		{
			$("#html_ititleerr").html("<img src='" + image_path + "/right.gif' />");
			$("#html_ititleerr").show();
			return true;
		}
	}
	
	function checkimagetagtitle()
	{
		var htmlTagTitle = $('#html_ttitle').val();
		var isTagTitle = chk_tag(htmlTagTitle);
		if(isTagTitle === true)
		{
			$("#html_ttitleerr").html("<img src='" + image_path + "/right.gif' />");
			$("#html_ttitleerr").show();
			return true;
		}
		else
		{
			$("#html_ttitleerr").html("<img src='" + image_path + "/wrong.gif' />&nbsp;" + errorno[isTagTitle]);
			$("#html_ttitleerr").show();
			return false;
		}
	}

	function checkImageType()//检查图片的分类
	{
		var html_sgeneraid = $('#html_sgeneraid').val();
		var html_ssubid	= $('#html_ssubid').val();
		if(html_sgeneraid && html_ssubid)
		{
			$("#html_imagetypeerr").html("<img src='" + image_path + "/right.gif' />");
			$("#html_imagetypeerr").show();
			return true;
		}
		else
		{
			$("#html_imagetypeerr").css("color", "red");
			$("#html_imagetypeerr").html("<img src='" + image_path + "/wrong.gif' />&nbsp;" + errorno[6107]);
			$("#html_imagetypeerr").show();
			return false;
		}
	}

	function checkGalleryType()//检查相机信息
	{
		if($('#html_istatus').attr('checked'))
		{
			var select_camera_model = 0; 
			$("[name='select_camera_model_id']:checked").each(function(){ 
			select_camera_model = $(this).val();
			});
			
			if(select_camera_model == 0 && ($('#html_cmt').val() === '' || ($('#html_cmt').val() == 0 && $('#custom_camera_model').val() === '')))
			{
				$("#html_gtypeerr").css("color", "red");
				$('#html_gtypeerr').html("<img src='" + image_path + "/wrong.gif' />&nbsp;" + errorno[6112]);
				$('#html_gtypeerr').show();
				return false;
			}
			else
			{
				$('#html_gtypeerr').html("<img src='" + image_path + "/right.gif' />");
				return true;
			}
		}
		else
		{
			return true;
		}
	}

	$('#html_albumdelform').submit(function(){
		var check = $(":radio:checked").val();
		if(check == '2')
		{//转移相册
			var text = $('#html_atitleselect').val();
			if(text == '')
			{
				$('#error').html("<img src='" + image_path + "/wrong.gif' />&nbsp;" + errorno[6109]);
				$('#error').css('color','red');
				return false;
			}
			$('#error').html("&nbsp;<img src='" + image_path + "/right.gif' />");
		}
		$('#html_albumdelsubmit').attr("disabled","disabled");
		$('#html_albumdelsubmit').attr("value","正在提交");
		return true;
    });

	$('#html_albumdeltrue').click(function(){
		$('#html_atitleselect').attr("disabled",true);
	});//删除相册时，控件不可用
	$('#html_albumdelchange').click(function(){
		$('#html_atitleselect').attr("disabled",false);
	});//删除相册时，控件可用

	$("#firstReplyForm").submit(function ()
	{
		formID = 'firstReplyForm';
	
		if($('#html_upoints').val() == 0 && $('#html_itext').val() == '')
		{
			$("#html_itexterr").css("color", "red");
			$('#html_itexterr').html("<img src='" + image_path + "/wrong.gif' />&nbsp;&nbsp;" + errorno[6111]);
			return false;
		}
		
		if(isLogin == 0)
		{
			openLoginBox();
			return false;
		}

		$('#html_itexterr').html("");
		$('#html_icomment').attr("disabled","disabled");
		$('#html_icomment').attr("value","正在提交");
		return true;
		
	});

	//相机类型品牌型号 联动

	$("#html_cbt").change(function (){
		$.ajax({
		   type: "GET",
		   url:"/ajax/imagecamerachange.php",
		   dataType: "json",
		   data: "job=imagecamerachange&cbtId=" + $('#html_cbt').val() + "&cytId=" + $('#html_cyt').val(),
		   success: function(data) {
				var myjson=eval(data);
				var f = '<option value="">相机型号</option>';
					 $.each(data,function(i,n){
				f += '<option value="' + n.camera_model_id + '">'+ n.camera_model_title + '</option>';
				  });
				f += '<option value=0>其它</option>';
				$("#html_cmt").html(f);
				is_custom_camera_model();
				checkGalleryType();
		   }
		  });
	})

	$("#html_cyt").change(function (){
		$.ajax({
		   type: "GET",
		   url:"/ajax/imagecamerachange.php",
		   dataType: "json",
		   data: "job=imagecamerachange&cbtId=" + $('#html_cbt').val() + "&cytId=" + $('#html_cyt').val(),
		   success: function(data) {
				var myjson=eval(data);
				var f = '<option value="">相机型号</option>';
					 $.each(data,function(i,n){
						f += '<option value="' + n.camera_model_id + '">'+ n.camera_model_title + '</option>';
				  });
				f += '<option value=0>其它</option>';
				$("#html_cmt").html(f);
				checkGalleryType();
		   }
		  });
	})
	$('#html_cmt').change(function (){
		is_custom_camera_model();
		checkGalleryType();
	});

});

function is_custom_camera_model()
{
	var select_camera_model = 0; 
	$("[name='select_camera_model_id']:checked").each(function(){ 
		select_camera_model = $(this).val();
	});
	if(select_camera_model != 0)
	{
		$("#html_show_custom_camera_model").html('');
	}
	else if($('#html_cmt').val() == 0)
	{
		
		$("#html_show_custom_camera_model").html('<br />相机型号: <input type="text" name="custom_camera_model" id="custom_camera_model" value="" size ="10" maxlength="30" />');
	}
	else
	{
		$("#html_show_custom_camera_model").html('');
	}
}	
//new  回复评论
function quote(quote_id, quoteuser, secondquote_id, quteuserid, quteusernick)
{
	var messageseconddiv = '#messageseconddiv' + quote_id;
	if($(messageseconddiv).css('display') == 'none')
	{
		$(messageseconddiv).css('display','block');
	}
	var str = $('#informstr' + quote_id).val();
	var strarray = str.split(',');
	if(quoteuser == '#secondquoteuser')
	{//二级回复
		str = strarray[0] + ',' + strarray[1] + ',' + quteuserid;
		
		if(quteusernick.toString() == $('#sametimeuserid' + quote_id).html().toString())
		{
			$('#sametimeuserid' + quote_id).html('');
		}		
		var informuserarrhtml = "";
		var informuserarr = eval("informuserarr" + quote_id);
		for(i=0 ; i< eval("informuserarrlength" + quote_id); i++)
		{
			var informuseruserid = informuserarr[i].user_id;
			if(informuseruserid != quteuserid && informuseruserid != user_id)
			{
				informuserarrhtml += ' <input type="checkbox" name="checkbox" id="checkbox' + informuserarr[i].user_id + '" value="' + informuserarr[i].user_id + '" >' + informuserarr[i].user_nick;
			}
		}
		
		if(informuserarrhtml)
		{
			$('#downs' + quote_id).html(informuserarrhtml);
			$('#sametime' + quote_id).show();
			$('#informs' + quote_id).show();
		}
		else
		{
			$('#downs' + quote_id).css('display','none');	
			$('#sametime' + quote_id).css('display','none');
		}	
		
	}
	else
	{
		str = strarray[0] + ',' + strarray[1];
		$("#downs" + quote_id + "> input:checkbox").each(function(){
			$(this).attr('checked', false);
		});
		$('#sametime' + quote_id).hide();
		$('#informs' + quote_id).hide();
		$('#downs' + quote_id).hide();
	}

	$('#informstr' + quote_id).val(str);
	$('#html_sictext' + quote_id).focus();
	if(!secondquote_id)
	{
		var quoterusernick = $(quoteuser + quote_id).text();
	}
	else
	{
		var quoterusernick = $(quoteuser + secondquote_id).text();
	}
	$('#html_sictext' + quote_id).val('回复[' + quoterusernick + ']说：');
	$('#html_icusernick' + quote_id).val(quoterusernick);
}


function slidedown(id)
{//下拉列表框
	$('#downs' + id).slideToggle('fast');
}

function informclick(id)
{
	formID = 'secondReplyForm' + id;
	var num = 0;
	$('#informnum' + id).html('');
	var str = $('#informstr' + id).val();
	$("#downs" + id + "> input:checkbox:checked").each(function(){
		str += ',' + $(this).val();
		num = eval(num + 1);
	});
	$('#informstr' + id).val(str);

	var reply = $('#html_sictext' + id).val();
	if(reply)
	{
		var reg = /^回复\[.+\]说\：$/;
		if(reg.test(reply))
		{
			alert('回复不能为空');
			return false;
		}
	}
	else
	{
		alert('回复不能为空');
		return false;
	}
	
	if(isLogin == 0)
	{
		openLoginBox();
		return false;
	}
	
	$('#secondbut' + id).attr("disabled","disabled");
	$('#secondbut' + id).attr("value","正在提交");
	$('#secondReplyForm' + id).submit();
		
	return true;
}

function canclequote(quote_id)
{
	$('#messageseconddiv' + quote_id).css('display','none');
}

function browsephoto(path)
{
	jumpUrl = path;
	if(isLogin == 0)
	{
		openLoginBox();
		return false;
	}
	window.open(path);
}