var BASEURL = '/';

//公司分类联动
function update_companycate(cateid,secid,catetag){

	if(catetag==null){
		catetag = '请选择分类';
	}
	url = BASEURL + 'ajax_updatecompanycatelang';
	$.ajax({
		url : url,
		type : 'post',
		data: {cateid:cateid},
		dataTye : 'json',
		success : function(msg){
			var msg = eval( msg );
			$('#' + secid).empty().addOption(catetag,'-1');
			for(key in msg){
				$('#' + secid).addOption(msg[key].catename,msg[key].cateid);
			}
		}
	});
}
/*-<常用函数-*/
function crossShow(obj,o){
	if(obj.is(':hidden')){
		obj.show();
		$(o).html('－');
	}else{
		obj.hide();
		$(o).html('＋');
	}
}
function changesize(s){
    var fontsize = '12px';
    if (s == 'mid') {
        fontsize = '13px';
    }
    else
        if (s == 'big') {
            fontsize = '15px';
        }
        else
            if (s == 'small') {
                fontsize = '12px';
            }
    $('#newstext').css('font-size', fontsize);
    $('#newstext').find('span').css('font-size', fontsize);
	$('#newstext').find('p').css('font-size', fontsize);
}


function copy_clip(copy){
		if (window.clipboardData){
			 window.clipboardData.setData("Text",copy);
		}
		else{
			 var flashcopier = 'flashcopier';
			 if(!document.getElementById(flashcopier)){
			 var divholder = document.createElement('div');
			 divholder.id = flashcopier;
			 document.body.appendChild(divholder);
			 }
			 document.getElementById(flashcopier).innerHTML = '';
			 var divinfo = '<embed src="'+ BASEURL +'public/img/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//这里是关键
			 document.getElementById(flashcopier).innerHTML = divinfo;
		}
		//alert("已成功复制到剪贴板！");
		return true;
}

function checkemail(email){
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
    if (!myreg.test(email)) {
        return false;
    }
    else {
        return true;
    }

}
function checktel(tel){
	var myreg = /^[\+]?[0-9]{3,4}[\-]?[0-9]{7,8}$/;
	if (!myreg.test(tel)) {
        return false;
    }
    else {
        return true;
    }
}
function checkmob(mobilnum){
	var myreg = /^[1]{1,1}[0-9]{10,10}$/;
	if (!myreg.test(mobilnum)) {
        return false;
    }
    else {
        return true;
    }
}
function getByteLen(str,rate){
	var l = str.length;
	var n = l;
	if( !rate ){
		rate = 3;
	}

	for ( var i=0; i<l; i++ ){
		if ( str.charCodeAt(i)<0 || str.charCodeAt(i)>255 )
		n=n+rate-1;
	}

	return n
}
/**
 *
 * @param {Object} o
 * @param {英文长度} len
 * @param {中英文比率,默认为1比3} rate
 */
function limitLen(o,len,rate){
	if( !rate ){
		rate = 3;
	}

	str = $(o).val();

	var n=str.length;
	var cn=0;
	var cutlen=len;

	for ( var i=0; i<str.length; i++ ){
			if ( str.charCodeAt(i)<0 || str.charCodeAt(i)>255 ){
				n=n+rate-1;
				cn++;
			}
			if(cn*(rate-1)+i+1 <= len){
				cutlen = (i+1);
			}
	}
	newstr = str.substring(0,cutlen);
	$(o).val(newstr);
}

function checkall(form){
	for(var i = 0;i < form.elements.length; i++) {
	        var e = form.elements[i];
	        if(e.type == 'checkbox' && e.name != 'chkall' && e.disabled != true) e.checked = form.chkall.checked;
	}
}
function textcheckall(form){
	if(!$(form).find('#chkall').attr('checked')){
		$(form).find('#chkall').attr('checked','true') ;
		$(form).find('input').each(
			function(i){
				if(this.type == 'checkbox' && this.name != 'chkall' && this.disabled != true)
					$(this).attr('checked','true');
			}
		);
	}else{
		$(form).find('#chkall').removeAttr('checked') ;
		$(form).find('input').each(
			function(i){
				if(this.type == 'checkbox' && this.name != 'chkall' && this.disabled != true)
					$(this).removeAttr('checked');
			}
		);
	}
	return false;
}
function slipShow(a,b){
	$('#'+a).hide();
	$('#'+b).show();
	return false;
}

function copyInviteUrl(o){
	$(o).get(0).select();
	copy_clip($(o).val());
	var pos = $(o).pos();

			$('#copyed_ok').css('position','absolute');
			$('#copyed_ok').css('left',pos.x+204);
			$('#copyed_ok').css('top',pos.y);
			$('#copyed_ok').show().animate({opacity: 1.0}, 2000).fadeOut(500);

}
/*-常用函数>-*/
jQuery.fn.extend({
    pos:function() {
        var o = this[0];
        if(o.offsetParent) {
        for(var posX=0, posY=0; o.offsetParent; o=o.offsetParent){
        posX += o.offsetLeft;
        posY += o.offsetTop;
        }
        return {x:posX, y:posY};
        } else return {x:o.x, y:o.y};
    },
    blur_hide:function(){
	    var s=this,h=function(){return false};
	    s.mousedown(h);
	    $().mousedown(function(){
		    s.hide().unbind('mousedown',h)
		    $().unbind('mousedown',arguments.callee);
	    });

	    return this;
    }
});
jQuery.fn.addOption = function(text,value){jQuery(this).get(0).options.add(new Option(text,value));}

/*-<UI*/
var mydiv = {
	Open : function(obj){
		//遮盖层
		$("body").prepend('<div id="UIWinMask"><div style="position: absolute;z-index: 999;top: 0;left: 0;width: '+ $(document).width() +'px;height: '+ $(document).height() + 'px;opacity: 0.07;filter:alpha(opacity=7);background-color:#000;"><img height="100%" width="100%" src="' + BASEURL + 'public/img/place.gif"/></div></div>');
		//图层对象的位置
		obj.css("left",(($(document).width())/2-(parseInt(obj.width())/2))+"px");
		obj.css("top",(document.documentElement.clientHeight-obj.height()) / 2 + document.documentElement.scrollTop +"px");
		//显示图层
		obj.show();
	},
	Close : function(obj){
		//移除遮盖图层
		$("#UIWinMask").remove();
		//隐藏图层
		obj.hide();
	},
	AutoClose: function(obj){
		$('#UIWinMask').click(
			function(){
			mydiv.Close(obj);
			}
		);
	}
}
/*UI>-*/
/*气泡*/
var Bubble = {
	Show: function(str,obj){
		var position = $(obj).pos();
		$(obj).css('cursor','pointer');
		$(obj).attr('src',BASEURL + 'public/img/faq_pic2.gif');
		$('body').prepend('<div id="UI_Bubble" style="position: absolute;z-index: 1006;left:'+ (position.x+20) +'px;top:'+position.y+'px;width:200px;padding:10px;border:1px solid #fec666;background:#fcfed4"></div>');

		$('#UI_Bubble').html(str);
		$('#UI_Bubble').hover(function(){},function(){
			$(this).hide();
		});
	},
	Close: function(obj){
		$(obj).attr('src',BASEURL + 'public/img/faq_pic1.gif');
		$("#UI_Bubble").remove();
	}
}



function sel_search_type(t){
    $('#head .search .list').hide();
    $('#head .search .select').css('background-position','right 0');

    if(t == 1){
        $('#head .search .select span').html('搜索企业');
        $('#global_search_type').val(1);
    }else if(t == 2){
        $('#head .search .select span').html('搜索会员');
        $('#global_search_type').val(2);
    }else if(t == 3){
        $('#head .search .select span').html('搜索新闻');
        $('#global_search_type').val(3);
    }
}

function init_catetabs(){
    $('#company_category .tabs li').each(function(i){
        this.onmouseover = function(){
             $('#company_category').find(".tabs li").removeClass("tabs_on");
             $(this).addClass("tabs_on");
             $('#company_category .cate_list .cates').each(function(j){
                if(i == j){
                    $(this).show();
                }else{
                    $(this).hide();
                }
             });
        }
    })
}
function init_rank_tabs(){
	$('#hot_ranks .atab li').each(function(i){
		this.onmouseover = function(){
             $('#hot_ranks').find(".atab li").removeClass("current");
             $(this).addClass("current");
             $('#hot_ranks .tabcontent').each(function(j){
                if(i == j){
                    $(this).show();
                }else{
                    $(this).hide();
                }
             });
        }
	});
}
//省市联动
function update_city(provinceid,secid,citytag){

	if(citytag==null){
		citytag = '请选择城市';
	}
	url = BASEURL + 'ajax/updatecity';
	$.ajax({
		url : url,
		type : 'post',
		data: {provinceid:provinceid},
		dataTye : 'json',
		success : function(msg){
			var msg = eval(  msg );
			$('#' + secid).empty().addOption(citytag,'-1');
			for(key in msg){
				$('#' + secid).addOption(msg[key].cityname,msg[key].cityid);
			}
		}
	});
}

//订阅处理
function operatrecruit(status){
	mail = $('#recuitmail').val();
	if(!checkemail(mail)){
		$('#recruiterror').text('请输入正确的 Email');
		return;
	}
	url = BASEURL + "ajax/operatecruit";
	$.ajax({
		url : url,
		type : "post",
		dataType : "json",
		data : {mail:mail,status : status},
		success : function (msg){
			msg = eval(msg);
			$('#recruiterror').text(msg.reason);
		}

	});
}


function plslogin(){
	alert('请先登录!');
	top.location.href=BASEURL+ "login/?flag=1";
	return;
}

function viewmsg(id,replyid){

	if(!document.getElementById('floatMsg')){

		msghtml = '<div id="floatMsg"  style="display:none;"><strong>查看消息:</strong><span id="msgtitle"></span> <div id="msgcontent"> </div>';
		if(replyid != 0){
			msghtml = msghtml + '<input id="msg_reply_button" class="iptsilver f_14" type="button" value="回复" /> ';
		}
		msghtml = msghtml + '<input class="iptsilver f_14" type="button" value="关闭" onclick="mydiv.Close($(\'#floatMsg\'))" /></div>';
		$('body').prepend(msghtml);
	}
	if(replyid != 0){
		$('#msg_reply_button').click(function(){ window.location.href = BASEURL+'message/send/?friends='+replyid });
	}

	url = BASEURL + "ajax/viewmsg";
	$.ajax({
		url : url,
		type : "post",
		dataType : "json",
		data : {msgid:id},
		success : function(msg){
			msg = eval(msg);

			if(msg.status){
				$('#msgtitle').html(msg.title);
				$('#msgcontent').html(msg.content);

				mydiv.Open($('#floatMsg'));
				mydiv.AutoClose($('#floatMsg'));
			}else{
				alert('消息不存在');
				return ;
			}
		}
	});
}
//判断仅可以输入数字
function onlynum(o){
	var str = $(o).val();
	reg = /^\d+$/;
	if(reg.test(str)){
		return;
	}else{
		rep = /\D?/g;
		repstr = str.replace(rep,'');
		$(o).val(repstr);
	}

}



