window.onerror=function(){ui.box.close();return true;}

var setClipboard=function(data, value){  
    if (window.clipboardData) {  
        window.clipboardData.setData(data,value);  
    } else {
    	$('#flashcopier').html('');  
        var divinfo = '<embed src="/public/home/_clipboard.swf" FlashVars="clipboard='+escape(value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//这里是关键  
        $('#flashcopier').html(divinfo);  
        
    }
    ui.success('复制成功');   
}  


function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

//对选择的行变色
function checkon(o){
    if( o.checked == true ){
        $(o).parents('tr').addClass('bg_on') ;
    }else{
        $(o).parents('tr').removeClass('bg_on') ;
    }
}
//获取已选择的ID数组
function getChecked() {
	var uids = new Array();
	$.each($('table input:checked'), function(i, n){
		uids.push( $(n).val() );
	});
	return uids;
}
//选择全部
function checkAll(o){
	if( o.checked == true ){
		$('input[name="checkbox"]').attr('checked','true');
		$('tr[overstyle="on"]').addClass("bg_on");
	}else{
		$('input[name="checkbox"]').removeAttr('checked');
		$('tr[overstyle="on"]').removeClass("bg_on");
	}
}

var at_select = function(A) {
    if (!A) return;
    this.Menu = $("#" + A);
    if (this.Menu.length != 1) return;
    this.Item = this.Menu.find("a");
    this.Selected = this.Item.filter(".at_selected");
    this.Item = this.Item.not(".at_selected");
    this.Value = this.Menu.find("input");
    this.timer = false;
    this.bindEvent()
};
at_select.prototype = {
    bindEvent: function() {
        var B, A = this;
        this.Menu.hover(function() {
            if (A.timer) return;
            A.timer = window.setTimeout(function() {
                A.setDisplay("show")
            },
            200)
        },
        function() {
            window.clearTimeout(A.timer);
            A.timer = false;
            A.setDisplay("hide")
        });
        this.Item.click(function() {
            A.setSelected($(this));
            A.setDisplay("hide")
        })
    },
    setDisplay: function(A) {
        if (A == "show") this.Item.css("display", "block");
        if (A == "hide") this.Item.css("display", "none")
    },
    setSelected: function(B) {
        var C = B.attr("value");
        this.Selected.html(B.html());
        this.Value.val(C);
        try {
            this.onSelected(C)
        } catch(A) {}
    }
};


//延时刷新
function reload( time ){
	if( time == ''){ time = 2000; }
	setTimeout( function(){
		location.reload();
	}, time);
}
//添加文章
function addfiles( max ){
	var files = $(".upfilesDIV > li").size();
	if( files >= max ){
		ui.error('最多只能上传'+max.toString()+'个附件!');
		return ;
	}
	var rand = Math.round( Math.random()*(1000-100));
	$(".upfilesDIV").append('<li id="'+rand.toString()+'"><input type="file" class="upfiles" name="file_'+rand.toString()+'" id="file_'+rand.toString()+'"> <a href="javascript:void(0);" onclick="$(\'#'+rand.toString()+'\').remove();">取消</a></li>');
}

function addFav(appid, fid, param){
	$.post("/index.php/index/addfav",{appid:appid,fid:fid,param:param},function(data){
		var res = jsonParse( data );
		if(res.status) {
			ui.success('收藏成功!');
		} else {
			if( res.info == 'noLogin' ){
				ui.quicklogin();
			} else {
				ui.error(res.info);
			}
		}
	});
}
//设为首页、加入收藏
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
function SetHome(obj,vrl){
        try{
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
                        } 
                        catch (e)  {
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',vrl);
                 }
        }
}
//控制图片大小函数--只控制宽度
function imgsets(obj,widths,heights){
		var boxWidth=widths;
		var boxHeight=heights;		
		var imgWidth=obj.width();
		var imgHeight=obj.height();
		//比较imgBox的长宽比与img的长宽比大小
		if(imgWidth>boxWidth){
			if((boxWidth/boxHeight)>=(imgWidth/imgHeight))
			{
				//重新设置img的width和height
				obj.width((boxHeight*imgWidth)/imgHeight);
				obj.height(boxHeight);
				//让图片居中显示
				var margin=(boxWidth-obj.width())/2;
				//$(this).css("margin-left",margin);
			}
			else
			{
				//重新设置img的width和height
				obj.width(boxWidth);
				obj.height((boxWidth*imgHeight)/imgWidth);
				//让图片居中显示
				var margin=(boxHeight-obj.height())/2;
				//$(this).css("margin-top",margin);
			}
		}			
	}
	
//控制图片大小函数--宽、高都控制
function imgsetsa(obj,widths,heights){
		var boxWidth=widths;
		var boxHeight=heights;		
		var imgWidth=obj.width();
		var imgHeight=obj.height();
		//比较imgBox的长宽比与img的长宽比大小
		if(imgWidth>boxWidth||imgHeight>boxHeight){
			if((boxWidth/boxHeight)>=(imgWidth/imgHeight))
			{
				//重新设置img的width和height
				obj.width((boxHeight*imgWidth)/imgHeight);
				obj.height(boxHeight);
				//让图片居中显示
				var margin=(boxWidth-obj.width())/2;
				//$(this).css("margin-left",margin);
			}
			else
			{
				//重新设置img的width和height
				obj.width(boxWidth);
				obj.height((boxWidth*imgHeight)/imgWidth);
				//让图片居中显示
				var margin=(boxHeight-obj.height())/2;
				//$(this).css("margin-top",margin);
			}
		}	
	}
//获取网络营销
function getNetworkAd( cid, htmlID ){
	if( cid == 0 || htmlID == '' ) return true;
	
	//获取网络营销数据
	$.get('/index.php/Ajax/networkAd/cid/'+cid+'/_r/'+new Date(),function( data ){
		var html = '<table border="0" cellpadding="0" cellspacing="0"><tr>';
		var res = jsonParse( data );
		for(i=0; i<res.length; i++){
			html = html + '<td style="padding-right:1px;"><a href="'+res[i].url+'" target="_blank"><img src="'+res[i].pic+'" alt="" /></a></td>';
		}
		html = html + '</tr></table>';
		$('#'+htmlID).html( html );
	});
}
//获取最新发布任务
function getNewTask( htmlID ){
	if( htmlID == '' ) return true;
	//获取最新发布任务数据
	$.get('/index.php/Ajax/NewTask/_r/'+new Date(),function( data ){
		var html = '';
		var res = jsonParse( data );
		for(i=0; i<res.length; i++){
			var title = res[i].title;
			var username = res[i].username;
			if(title.length>12){
				title = title.substring(0,12)+"...";
			}
			if(  username == undefined || username==""){
				html = html + "<a href='/index.php/task/view/tid/"+res[i].taskid+"' title='"+res[i].title+"' target='_blank'>最新发布："+title+"</a><br />";
			}else{
				html = html + "<a href='/index.php/task/view/type/item/tid/"+res[i].taskid+"' title='任务编号:"+res[i].taskid+" "+res[i].title+"' target='_blank'>最新中标："+username+" 编号:"+res[i].taskid+"</a><br />";
			}
		}
		html = html + "<div class='clear'></div>";
		$('#'+htmlID).html( html );
		var newtaskss = new Marquee( htmlID );
		newtaskss.Direction = "top"
		newtaskss.Step = 2;
		newtaskss.Width = 226;
		newtaskss.Height = 28;
		newtaskss.Timer = 5;
		newtaskss.DelayTime = 2000;
		newtaskss.WaitTime = 3000;
		newtaskss.ScrollStep = 56;
		newtaskss.Start();
	});
}
//获取案例信息
function getCase( case_cid , htmlID ){
	if(case_cid=='' || htmlID == '' ) return true;
	//判断没有内容时，才获取案例
	if($('#'+htmlID).html().replace(/\s/g,"")==""){
		//获取相关ID案例信息
		$.get('/index.php/Case/getCase/case_cid/'+case_cid+'/_r/'+new Date(),function( data ){
			var html = '';
			var res = jsonParse( data );
			for(i=0; i<res.length; i++){
				html = html + "<li><a href='"+res[i].url+"' title='"+res[i].title+"' target='_blank'><img src='"+res[i].pic+"' /></a></li>";
			}
			html = html + "<div class='clear'></div>";
			$('#'+htmlID).html( html );
		});
	}
}

//获取任务分类下的提示信息
function gettipinfo( cateid , htmlID ){
	if(cateid=='' || htmlID == '' ) return true;	
	//获取任务分类下的提示信息
	$.get('/index.php/Ajax/getTipInfo/cateid/'+cateid+'/_r/'+new Date(),function( data ){
		var html = '';
		var res = jsonParse( data );
		html =  res.tipinfo;
		$('#'+htmlID).html( html );
	});
}
