/*
 *@param strWords   用于敏感字校验的字符串
 *@param arrKeyWord 敏感字数组
 *@return bool      如果校验失败返回false,否则返回true
 *@exception        如果输入参数strWords为空串,返回false
 *                  如果输入参数arrKeyWord数组大小为0,返回true
 */
/*
	使用方法例子如下：校验成功返回true， 校验失败返回false
	var strSrc = "sex,china,sdfsdfsdf,sfkasdfasdfasf@!sdfjslkjfkj^&(())))!@##$$$%%^^&&&**((()skdjfskdjf+_";
	var arrKeyWord = new Array("sex", "china");
	
	if(ValidateWord(strSrc,arrKeyWord) == false)
		alert("OK");
	else
		alert("NO");
		
	var strSrc1 = "sdfsdf,sdsadfasf中文,sdfsdfsdf,sfkasdfasdfasf@!sdfjslkjfkj^&(())))!@##$$$%%^^&&&**((()skdjfskdjf+_";
	if(ValidateWord(strSrc1,arrKeyWord) == true)
		alert("OK");
	else
		alert("NO");
*/
function ValidateWord(strWords, arrKeyWord)
{
    if(strWords == "")
        return false;
    
    if(arrKeyWord == "" || arrKeyWord.length == 0)
        return true;
        
    for(var n = 0; n < arrKeyWord.length; n ++)
    {
        if(strWords.indexOf(arrKeyWord[n]) != -1)
            return false;
    }
    
    return true;
}

<!--去掉字符串前后空格-->

function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

//返回字符串长度 例如：len("a中国")，返回的是5
function len(s) { 
	var len = 0; 
	var a = s.split(""); 
	for (var i=0;i<a.length;i++) { 
		if (a[i].charCodeAt(0)<299) { 
			len++; 
		} else { 
			len+=2; 
		} 
	} 
	return len; 
} 

function replaceAll(text,replacement,target){ 
	if(text==null || text=="") return text;//如果text无内容,返回text 
	if(replacement==null || replacement=="") return text;//如果replacement无内容,返回text 
	if(target==null) target="";//如果target无内容,设置为空串 
	var returnString="";//定义返回值变量,并初始化 
	var index=text.indexOf(replacement);//定义查找replacement的索引下标,并进行第一次查找 
	while(index!=-1) {//直至未找到replacement,要么进行下面的处理 
	returnString+=text.substring(0,index)+target;//如果找到的replacement前有字符,累加到返回值中,并加上target 
	text=text.substring(index+replacement.length);//取掉找到的replacement及前边的字符 
	index=text.indexOf(replacement);//进行查询,准备下一次处理 
	} 
	if(text!="") returnString+=text;//如果找到的最后一个replacement后有字符,累加到返回值中 
	return returnString;//返回 
} 

function replacesearchcode(svalue){
		var rvalue = svalue;
		var rvalue = replaceAll(rvalue,"'","");
		var rvalue = replaceAll(rvalue,'"',"");
		var rvalue = replaceAll(rvalue,"\\","");
		var rvalue = replaceAll(rvalue,"/","");
		return rvalue;
}

String.prototype.trim = function() {   
    //return this.replace(/[(^\s+)(\s+$)]/g,"");//會把字符串中間的空白符也去掉   
    //return this.replace(/^\s+|\s+$/g,""); //   
    return this.replace(/^\s+/g,"").replace(/\s+$/g,"");   
} 
 //检查用户是否投过票  uid：用户ID， ideaid：创意ID，  ownerId：创意发布者ID， e：鼠标事件， 票数用<font></font>标签括起来，numid：font标签的id
function checkvote(e, uid, ideaid, ownerId, numid, operation, iframeHeight, iframeId,nowtime){
	if(nowtime < '2010-03-01'){
		alert("现在是参赛作品提交阶段，暂不接受投票，请继续关注！");
		return false;
	}
	var thistime = new Date();
	var d1 = new Date(2010,2,31,23,59,59);
	var d2 = new Date(thistime);
	if(Date.parse(d2) - Date.parse(d1)>=0)
	{
		alert("投票活动已经结束，感谢您的关注！");
		return false;
	}
	var event = e || window.event;
	if(operation == null || operation == 'rank'){
		if(!showmapdiv(event,uid,operation,iframeHeight)){
			return false;
		}
	}
	
	if(uid == ownerId){
		alert('不能对自己提交的创意进行投票');
		return false;
	}
	var data = {
		'ideaId': ideaid
	}
	jQuery.ajax({
		 type: "POST",
		 url: "game_idea.php?operation=checkvote",
		 data: data,
		 success: function(data){
			if(data == 1){
				alert("您今天已经投过票，一天内不能重复投票");
			}else if(data == 2){
				alert("投票活动已经结束，感谢您的关注！");
			}else{
				var title = '您要给“'+data+'”投上一票吗？';
				var ret = confirm(title);
				if(ret == true){ 
					addVote(ideaid, numid, iframeId, operation);
				}
			}
		 },
		 error: function(){
		 alert('服务器操作失败!');
		 }   
	 });			
	 
}
//投票   
function addVote(ideaid, numid, iframeId, operation){
	var data = {
		'ideaId': ideaid
	}
	jQuery.ajax({
		 type: "POST",
		 url: "game_idea.php?operation=addvote",
		 data: data,
		 success: function(data){
			if(data == 1){
				alert("您今天已经投过票，一天内不能重复投票");
			}else if(data == 2){
				alert("投票活动已经结束，感谢您的关注！");
			}else{
				alert("投票成功！")
				var votearr = data.split("-");
				if(iframeId != null){
					window.frames[iframeId].document.getElementById(numid).innerHTML = votearr[0];
				}else{
					if(operation == 'rank'){
						document.getElementById("rank").innerHTML = votearr[1];
					}
					document.getElementById(numid).innerHTML = votearr[0];
				}
			}
		 },
		 error: function(){
		 alert('服务器操作失败!');
		 }   
	 });			
}
//开发者大赛 ---------张洋
//检查用户是否投过票  uid：用户ID， ideaid：创意ID，  ownerId：创意发布者ID， e：鼠标事件， 票数用<font></font>标签括起来，numid：font标签的id
function checkvotes(e, uid, ideaid, ownerId, numid, operation, iframeHeight, iframeId){
	//alert("现在是参赛作品提交阶段，暂不接受投票，请继续关注！");
	//return false;
	var event = e || window.event;
	if(operation == null || operation == 'rank' || operation == 'locally'){
		if(!showmapdiv(event,uid,operation,iframeHeight)){
			return false;
		}
	}

	if(uid == ownerId){
		alert('不能对自己提交的作品进行投票');
		return false;
	}
	var data = {
		'ideaId': ideaid
	}
	jQuery.ajax({
		 type: "POST",
		 url: "dev_detail.php?operation=checkvote",
		 data: data,
		 success: function(data){
			if(data == "true"){
				alert("您今天已经投过票，一天内不能重复投票");
			}else{
				var title = '您要给“'+data+'”投上一票吗？';
				var ret = confirm(title);
				if(ret == true){ 
					addVote2(ideaid, numid, iframeId, operation);
				}
			}
		 },
		 error: function(){
		 alert('服务器操作失败!');
		 }   
	 });			
	 
}
//开发者大赛 ---------张洋
//投票   
function addVote2(ideaid, numid, iframeId, operation){
	var data = {
		'ideaId': ideaid
	}
	jQuery.ajax({
		 type: "POST",
		 url: "dev_detail.php?operation=addvote",
		 data: data,
		 success: function(data){
			if(data == "true"){
				alert("您今天已经投过票，一天内不能重复投票");
			}else{
				alert("投票成功！")
				var votearr = data.split("-");
				if(iframeId != null){
					window.frames[iframeId].document.getElementById(numid).innerHTML = votearr[0];
				}else{
					if(operation == 'rank'){
						document.getElementById("rank").innerHTML = votearr[1];
					}
					document.getElementById(numid).innerHTML = votearr[0];
				}
			}
		 },
		 error: function(){
		 alert('服务器操作失败!');
		 }   
	 });			
}


(function($){
    $.fn.hoverDelay = function(options){
        var defaults = {
            hoverDuring: 200,
            outDuring: 200,
            hoverEvent: function(){
                $.noop();//这个函数表示什么也不做
            },
            outEvent: function(){
                $.noop();//这个函数表示什么也不做
            }
        };
        var sets = $.extend(defaults,options || {});
        var hoverTimer, outTimer;
        return $(this).each(function(){
        	var t = this;
            $(this).hover(function(){
                clearTimeout(outTimer);
                hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
                hoverTimer = setTimeout(function(){sets.hoverEvent.apply(t);}, sets.hoverDuring);
            },function(){
                clearTimeout(hoverTimer);
                outTimer = setTimeout(sets.outEvent, sets.outDuring);
                outTimer = setTimeout(function(){sets.outEvent.apply(t);}, sets.outDuring);
            });
        });
    };
})(jQuery);
 
/*tab*/
var tab=function(oT,oC,t){
	var a=setTimeout(function(){
		$(oT).bind(t,function(){
			$(oT).removeClass("current");
			$(oC).hide();
			$(this).addClass("current");
			$(oC).eq($(this).index()).fadeIn().show();
		})
	},100);
	clearTimeout(this.a);
}


//隔行变色
//说明：obj对象 
//      t1为颜色值1
//      t2为颜色值2
//      t3为鼠标经过的颜色值
//      n为开始行从0开始
function eoddTble(obj,t1,t2,t3,n){
   	var o=$(obj);
	var m=0;
	var tempBg;
	if(n!=""){m=n;}
	for (i=m;i<o.length;i++) { 
		var bgc= (i%2==0)? t1:t2; 
		o.eq(i).css("background-color",bgc); 
	}
	o.hover(function(){
			tempBg=$(this).css("background-color");
			$(this).css("background-color",t3);
		},function(){
			$(this).css("background-color",tempBg);
	});
}
