//投票
function voteAction(url,id){
	if(window.confirm("是否要投票？")){
     	dojo.xhrPost ({
   			url: url,
   			content:{id:id},
			sync: true,
  				load: function (data) {
  						if('1' == data){
  							alert("投票成功！");
  						}else{
  							alert("您投票太过频繁，请2分钟后再试！");
  						}
				}
		});
    	}
}

//添加评论
function addComment(url,formId,refreshUrl,srcUrl){
	var f = false;
	if(window.confirm("是否要评论？")){
		var nameValue = dojo.byId(formId).name.value;
		var contentValue = dojo.byId(formId).content.value;
		if(nameValue == ''){
			alert('请填写昵称!');
			return false;
		}
		if(contentValue == ''){
			alert('请填写评论!');
			return false;
		}
		
		var keyWordName = keywordFilter(nameValue);
		if(keyWordName != ''){
			alert("昵称包含非法字符【"+keyWordName+"】");
			return false;
		}
		
		var keyWordContent = keywordFilter(contentValue);
		if(keyWordContent != ''){
			alert("评论包含非法字符【"+keyWordContent+"】");
			return false;
		}
		
     	dojo.xhrPost ({
   			url: url,
   			form:dojo.byId(formId),
			sync: true,
 			load: function (data) {
					if('1' == data){
						alert("评论成功,但是需要管理员审核才能可见！");
						f = true;
						//后台需要审核才能看见，所有不需要刷新了
						//dijit.byId('commentDataDiv').setHref(refreshUrl);
					}else{
						alert("验证码不正确！");
					}
			}
		});
		
     }
     
     return f;
}

//删除评论
function deleteComment(url,id){
	if(window.confirm("是否要删除评论？")){
	     	dojo.xhrPost ({
	   			url: url,
	   			content:{id:id},
				sync: true,
	 			load: function (data) {
						if('1' == data){
							alert("删除成功！");
							window.location.reload(); 
						}else{
							alert("删除失败！");
						}
				}
			});
	  }
}

//审核评论
function checkedComment(url,id){
     	dojo.xhrPost ({
   			url: url,
   			content:{id:id},
			sync: true,
 			load: function (data) {
					if('1' == data){
						alert("操作成功！");
						//window.location.reload(); 
					}else{
						alert("操作失败！");
					}
			}
		});
}

//刷新验证码
function refreshPicCode(url,id){
	var t =  new Date().getTime();
	document.getElementById(id).src = url + '?t=' + t;
}

/**
	*根据图片放缩
	*@param {} obj 图片对象
	*@param {} maxWidth 宽
	*@param {} maxHeight 高
	*/
	function changeImage(obj,maxWidth,maxHeight){	
		var imageWidth = obj.width;
		var imageHeight = obj.height;
		
		//不对原图进行放大
		if(obj.width < maxWidth){
			maxWidth = obj.width;
		}
		if(obj.height < maxHeight){
			maxHeight = maxHeight;
		}
			
		var maxRatio = maxWidth/maxHeight;
		var imageRatio = imageWidth/imageHeight;
		if (maxRatio < imageRatio) {
			obj.width=maxWidth;
			obj.height= maxWidth/imageRatio;
		} else {
			obj.width=maxHeight*imageRatio;
			obj.height=maxHeight;
		} 	
	}

function keywordFilter(array){
	var v_data;
	DWREngine.setAsync(false);
	//SQBS 代表关键字过滤（社区标识）
	keywordManage.keywordFilter([array],'SQBS',function(data){
		v_data= data;
	});
	DWREngine.setAsync(true);
	return v_data;
}

function isNumeric(   strValue   )   { 
   var   objExp     =     /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;   
   return   objExp.test(strValue); 
}

function  isInteger(   strValue   )   
{ 
   var   objExp     =   /(^-?\d\d*$)/; 
   return   objExp.test(strValue); 
}
