function print_r(a,depth,al){
	var b = '',i,j,depth=depth?depth:[];
	var tag = '  '
	switch(typeof(a)){
		case 'undefined'	: b = '[undefined]'; break;
		case 'number'		:
		case 'string'		:
		case 'function'		:
		case 'boolean'		: b = a.toString()+'['+typeof(a)+']'; break;
		case 'array'		:
		case 'object'		:
		if(a==null){
			b += 'null['+typeof(a)+']';
		}else{
			b = '['+typeof(a)+']{\n';
			depth.push(tag);
			for(i in a){
				b += depth.join('')+'['+i+' ='+print_r(a[i],depth,true);
			}
			depth.pop(tag);
			b += depth.join('')+'}'
		}
		break;
	}
	b += '\n';
	if(typeof(al)=='undefined'||!al){
		if($ && jQuery){
			if(!$('#print_r_showbox').length){
				$('<div id="print_r_showbox" style="display:none;"><div style="padding:4px;">k</div><a href="#" onclick="$(this).parent().fadeOut();return false;" style="display:block;color:#fff;text-align:right;border-top:1px solid #fff;padding:4px;">关闭</a></div>').appendTo('body');
			}
			$('#print_r_showbox').css({
				width:200,
				'z-index':999,
				overflown:'hidden',
				color:'#ffffff',
				'background-color':'#000000',
				position:'absolute',
				right:'30px',
				top:'0px',
				border:'1px solid #fff'
			}).children().eq(0).html(b.replace(/</ig,'&lt;').replace(/>/ig,'&gt;').replace(/[\r\n]/ig,'<br />').replace(/\t/ig,'&nbsp;&nbsp;'));
			$('#print_r_showbox').fadeIn();
		}else{
			alert(b);
		}
	}else{
		return b;
	}
}
function realhref(a,b,ob){
	var c = window.confirm(a);
	if(c){
		if(typeof(b)=='function'){
			b();
		}else{
			if(ob) ob.href="#";
			gouri(b);
		}
	}
	return false;
}
function realhref_pop(a,b,ob,re,refun){
	if($.popwindow){
		$.extend($.popwindow,{confirmhref:b,confirmfun:(refun?refun:null)});
		if(re&&typeof(b)=='string'){
			$.popwindow.confirm('操作确认',a,function(){
				var b = $.popwindow.confirmhref||'';
				var fun = $.popwindow.confirmfun||$.popwindow.returnshow;
				$.get(b,fun);
			});
		}else{
			$.popwindow.confirm('操作确认',a,function(){
				var b=$.popwindow.confirmhref||'';
				if(typeof(b)=='function'){
					b();
				}else{
					gouri(b);
					$.popwindow.confirmhref=null;
				}
			});
		}
	}else{
		realhref(a,b,ob);
	}
}
function alert_pop(a){
	if($.popwindow){
		switch(typeof(a)){
			case 'undefined'	: a = 'undefined' ; break;
			case 'function'		: a = 'Function' ; break;
			case 'array'		: a = 'Array' ; break;
			case 'object'		: a = 'Object' ; break;
			case 'boolean'		: a = a.toString() ; break;
		}
		$.popwindow.alert(a);
	}else{
		alert(a);
	}
}
function copyToClipboard(txt){        
     if(window.clipboardData){
        window.clipboardData.clearData(); 
        window.clipboardData.setData("Text", txt);
        alert("复制成功！")
     }else if(navigator.userAgent.indexOf("Opera") != -1){
        window.location = txt;
     }else if (window.netscape){
		try{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}catch (e){
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans)  return;
		trans.addDataFlavor('text/unicode');
		var str = {}, len = {};
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext = txt;
		str.data = copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip) return false;      
		clip.setData(trans,null,clipid.kGlobalClipboard); 
		alert("复制成功！") 
     } 
}
function _gel(a){
	return document.getElementById?document.getElementById(a):null;
}
function _gei(a){
	return document.getElementById?document.getElementById(a):null;
}
function _gelstn(a){
	if(a=="*"&&document.all)
	return document.all;
	return document.getElementsByTagName?document.getElementsByTagName(a):[];
}
function _gen(a){
	return document.getElementsByName?document.getElementsByName(a)[0]:'';
}
function _uc(a){
	return a.toUpperCase();
}
function _event() {  
	if(document.all) return window.event;    
	func=_event.caller;        
	while(func!=null){  
		var arg_0=func.arguments[0]; 
		if(arg_0) { 
			if((arg_0.constructor==Event||arg_0.constructor==MouseEvent)||(typeof(arg_0)=="object" && arg_0.preventDefault && arg_0.stopPropagation)) {  
				return arg_0; 
			} 
		} 
		func=func.caller; 
	} 
	return null; 
} 
function reseturl(a,b,c){
		var strre = [],ubox = [];
		if(typeof(a) == 'string'|| typeof(a) == 'number'){
			ubox = [a];
		}else if(typeof(a) == 'object'){
			ubox = a;
		}
		for(var i = 0; i < ubox.length ;i++){
			url = typeof(ubox[i]) == 'undefined'?'':_gel(ubox[i]).href;
			if(url!=''&&url!='#'&&url!='javascript:void(0);'){
				if(url.indexOf('?') == -1){
					url += '?'+b+'='+c;
				}else if(url.indexOf(b+'=') == -1){
					url += '&'+b+'='+c;
					url = url.replace('?&','?');
				}else{
					var re = new RegExp('('+b+'=)\\d+','gi');
					url = url.replace(re,'$1'+c);
				}
			}
			_gel(ubox[i]).href = url;
		}
}
function optional_drop_down_menu(arrow,link,menu,event,arrow_class,arrow_old_class,on_click_callback,off_click_callback,offset_el,offset_info){
	if(menu.style.display=='none'){
		menu.style.display='block';
		if(offset_info&&offset_el){
			for(prop in offset_info){
				switch(prop){
					case'top':
					menu.style.top=(offset_el.offsetTop+offset_info[prop])+'px';
					break;
					case'left':
					menu.style.left=(offset_el.offsetLeft+offset_info[prop])+'px';
					break;
					case'right':
					menu.style.left=(offset_el.offsetLeft+offset_el.offsetWidth-offset_info[prop]-menu.offsetWidth)+'px';
					break;
					case'bottom':
					menu.style.top=(offset_el.offsetTop+offset_el.offsetHeight-offset_info[prop]-menu.offsetHeight)+'px';
					break;
				}
			}
		}
		if(arrow){var old_arrow_classname=arrow_old_class?arrow_old_class:arrow.className;}
		if(link){$(link).addClass('active');}
		if(arrow){arrow.className=arrow_class?arrow_class:'global_menu_arrow_active';}
		var justChanged=true;
		var shim=$('#'+menu.id+'_iframe');
		if(shim){
			$(shim).css({
				left:$(menu).css('left'),
				top:$(menu).css('top'),
				display:'block',
				opacity:0,
				width:$(menu).width()+10,
				height:$(menu).height()+10
			});
		}
		menu.offclick=function (e){
			if(!justChanged){
				$(menu).hide();
				if(link){$(link).removeClass('active');}
				if(arrow){arrow.className=old_arrow_classname; }
				var shim=$('#'+menu.id+'_iframe');
				if(shim){
					$(shim).css({
						display:'none',
						width:$(menu).width(),
						height:$(menu).height()
					});
				}
				if(off_click_callback){
					off_click_callback(e.data);
				}
				$(document).unbind('click',menu.offclick);
			}else{
				justChanged=false;
			}
		};
		$(menu).bind('offclick',menu.offclick);
		if(on_click_callback){
			on_click_callback();
		}
		$(document).bind('click',menu.id,menu.offclick);
	}
	return false;
}
function flextoggle(obj,showclass,closeclass){
	if($(obj).next().css('display') == 'none'){
		$(obj).next().css('display','block');
		$(obj).parent().removeClass(closeclass);
		$(obj).parent().addClass(showclass);
	}else{
		$(obj).next().css('display','none');
		$(obj).parent().removeClass(showclass);
		$(obj).parent().addClass(closeclass);
	}
}
function ge(a){
	return typeof(a)=='string'?(document.getElementById?document.getElementById(a):null):a;
}
function editor_date_month_change(month_el,day_el,year_el){
	var month_el=ge(month_el);
	var day_el=ge(day_el);
	var year_el=year_el?ge(year_el):false;
	var new_num_days=_month_get_num_days(month_el.value,(year_el.value&&year_el.value!=-1?year_el.value:false));
	var b=(day_el.options[0].value==-1||day_el.options[0].value==''||day_el.options[0].value==0)?1:0;
	for(var i=day_el.options.length;i>new_num_days+b;i--){
		$(day_el.options[i-1]).remove();
	}
	for(var i=day_el.options.length;i<new_num_days+b;i++){
		day_el.options[i]=new Option(i+(b?0:1));
	}
}
function _month_get_num_days(month,year){
	var temp_date;
	if(month==-1){
		return 31;
	}
	temp_date=new Date(year?year:1912,month,0);
	return temp_date.getDate();
}
function editor_rel_change(obj,sl){
	var i,v = obj.value;
	for(i=2;i<=6;i++){
		if(v==i)$('#'+sl+'_new_partner_'+i).show();
		else $('#'+sl+'_new_partner_'+i).hide();
	}
	if(v>1)$('#'+sl+'_new_partner').show();
	else $('#'+sl+'_new_partner').hide();
}
function textlimit(textarea,len,msg){
	var value=$('#'+textarea).val();
	if(value.length>len){
		$('#'+textarea).val(value.substr(0,len));
		$('#'+msg).show();
	}
}
function change_work_date(obj,i){
	if(obj.checked){
		$('#work_history_'+i+'_workspan_endspan').hide();
		$('#work_history_'+i+'_workspan_endspan').find('select').val('');
		$('#work_history_'+i+'_workspan_present').show();
	}else{
		$('#work_history_'+i+'_workspan_endspan').show();
		$('#work_history_'+i+'_workspan_present').hide();
	}
}
function education_remove_school(elm,i){
	$('#'+elm+'_'+i).find('input').val('');
	$('#'+elm+'_'+i).find('select').val('');
}
function workhistory_remove_entry(i){
	$('#work_history_'+i).find('input[type*=text]').val('');
	$('#work_history_'+i).find('input[type*=checkbox]').attr('checked','');
	$('#work_history_'+i+'_workspan_endspan').show();
	$('#work_history_'+i+'_workspan_present').hide();
	$('#work_history_'+i).find('select').val('');
	$('#work_history_'+i).find('textarea').val('');
}
function selectlist(obj){
	$(obj).parents('form').find('#edit_status_select').show();
	return false;
}
function set_status(obj,id){
	$(obj).hide();
	$('#'+id).show();
}
function getcity(href,pr,ct){
	ct = ct || 'city';
	pr = pr || 'province';
	$.get(href,function(data){
		$("#"+ct).remove();
		$(data).insertAfter($("#"+pr));
	});
}
function getcollege(href,pr,ct){
	ct = ct || 'college';
	pr = pr || 'province';
	$.get(href,function(data){
		$("#"+ct).remove();
		$(data).insertAfter($("#"+pr));
	});
}
function getassn(href,pr,ct){
	//alert(document.getElementsByName('college')[0].outerHTML);
	ct = ct || 'college';
	pr = pr || 'assnname';
	$.get(href,function(data){
		$("#"+pr).remove();
		$(data).insertAfter($("#"+ct));
	});
}
function gouri(href){
	window.location.href=href;
}
function _tx(str,args){
	if(args){
		if(typeof(args)!='object'){
			return;
		}else {
			for(var key in args){
				var regexp=new RegExp('\{'+key+'\}',"g");
				str=str.replace(regexp,args[key]);
			}
		}
	}
	return str;
}
function submitmsg(obj){
	if(obj){
		obj.form.onsubmit=null;
		obj.form.submit();
		obj.disabled=true
	}
}
var temp = null;
function friendshide(obj,u){
	temp = $(obj).parents('.friend_grid_col').attr('id');
	$.get('/user/findfriends/randone?no='+u,function(data){
		if(data.length > 20 && temp && data.length <1000){
			$('#'+temp).fadeOut('fast',function(){
				$('#'+temp).html(data).fadeIn('fast');
				temp = null;
			});
		}else{
			$('#'+temp).fadeOut('fast');
		}
	});
}
function addfriends(u){
	realhref_pop('你确定马上提交好友申请吗?',function(){
		$.get('/user/findfriends/applyfor?u='+u,function(data){
			$.popwindow.returnshow(data);
		});
	});
}
function ingroups(g,t){
	if(t==1){
		realhref_pop('你确定要加入该群组吗?',function(){
			$.get('/user/groups/goin?tp=1&gid='+g,function(data){
				$.popwindow.returnshow(data);
			});
		});
	}else if(t==2){
		realhref_pop('你确定申请加入该群组吗?',function(){
			$.get('/user/groups/goin?tp=2&gid='+g,function(data){
				$.popwindow.returnshow(data);
			});
		});
	}
}
function show_editor_error(error_text,exp_text){
	$('#editor_error_text').html(error_text);
	$('#editor_error_explanation').html(exp_text);
	$('#error').show();
}
function make_explanation_list(list,num,type){
	var el01 = '{th-1}是必要的';
	var el02 = '{th-2}和{th-1}必填。';
	var el03 = '{th-1}、{th-2}和{th-3}为必需。';
	var el04 = '{th-1}、{th-2}、{th-3}和{th-4}是必须的。';
	var el05 = '必须填写{th-1}、{th-2}、{th-3}以及{num}个其他空缺。';
	var el06 = '{th-1}无效。';
	var el07 = '{th-1}和{th-2}无效。';
	var el08 = '{th-1}、{th-2}和{th-3}不可用。';
	var el09 = '{th-1}、{th-2}、{th-3}和{th-4}看起来无效。';
	var el10 = '{th-1}，{th-2}，{th-3}以及其他{num}个栏无效。';
	var exp='';
	if(type=='missing'){
		if(num==1){exp=_tx(el01,{'th-1':list[0]});}
		else if(num==2){exp=_tx(el02,{'th-1':list[0],'th-2':list[1]});}
		else if(num==3){exp=_tx(el03,{'th-1':list[0],'th-2':list[1],'th-3':list[2]});}
		else if(num==4){exp=_tx(el04,{'th-1':list[0],'th-2':list[1],'th-3':list[2],'th-4':list[3]});}
		else if(num>4){exp=_tx(el05,{'th-1':list[0],'th-2':list[1],'th-3':list[2],'num':num-3});}
	}else if(type=='bad'){
		if(num==1){exp=_tx(el06,{'th-1':list[0]});}
		else if(num==2){exp=_tx(el07,{'th-1':list[0],'th-2':list[1]});}
		else if(num==3){exp=_tx(el08,{'th-1':list[0],'th-2':list[1],'th-3':list[2]});}
		else if(num==4){exp=_tx(el09,{'th-1':list[0],'th-2':list[1],'th-3':list[2],'th-4':list[3]});}
		else if(num>4){exp=_tx(el10,{'th-1':list[0],'th-2':list[1],'th-3':list[2],'num':num-3});}
	}
	return exp;
}
function add_lmsg(a){
	var msg = "";
	if(a.email.value.length!=0){
		if (a.email.value.charAt(0)=="." ||        
         a.email.value.charAt(0)=="@"||       
         a.email.value.indexOf('@', 0) == -1 || 
         a.email.value.indexOf('.', 0) == -1 || 
         a.email.value.lastIndexOf("@")==a.email.value.length-1 || 
         a.email.value.lastIndexOf(".")==a.email.value.length-1){
		 	msg += "Email地址格式不正确\n";
		 }
	}else msg += "Email不能为空\n";
	if(a.name.value==""){
		msg += "请填写您的名字\n";
	}
	if(a.bodymsg.value==""){
		msg += "请填写您的留言内容\n";
	}
	if(a.bodymsg.value.length > 500){
		msg += "留言内容不能超过500\n";
	}
	if(msg!= ''){
		alert(msg);
		return false;
	}else{
		return true;
	}
}
function lchu(){
	ge("yin").style.display="";
}
function lyin(){
	ge("yin").style.display="none";
}
function lchu2(){
	ge("yin").style.display="";
	ge("re2").style.display="none";
	ge("bodymsg").value="";
}
function empty(a){
	if(!a||a=='0'||a=='false'||a==[]){
		return true;
	}else if(a==1||a=='1'||a==true||a=='true'){
		return false;
	}else{
		return 'no check';
	}
}
function story_count_chang(){
	var a = $('#mf_story_count_string').attr('story_count')||0;
	a = parseInt(a)-1;
	a = a<0 ? 0 : a;
	$('#mf_story_count_string').html(a + '条动态');
}
function editor_two_level_change(selector,subtypes_array,sublabels_array){
	selector=ge(selector);
	if(selector.getAttribute("typefor"))
	subselector=ge(selector.getAttribute("typefor"));
	if(selector&&subselector){
		subselector.options.length=1;
		type_value=selector.options[selector.selectedIndex].value;
		if(type_value==""){
			type_value=-1;
			
		}
		index=1;
		suboptions=subtypes_array[type_value];
		if(typeof(suboptions)!="undefined"){
			for(var key=0;key<suboptions.length;key++){
				if(typeof(suboptions[key])!="undefined"){
					subselector.options[index++]=new Option(suboptions[key],key);
				}
			}
		}
		if(sublabels_array){
			if(sublabels_array[type_value]){
				subselector.options[0]=new Option(sublabels_array[type_value],"");
				subselector.options[0].selected=true;
			}else {
				subselector.options[0]=new Option("---","");
				subselector.options[0].selected=true;
			}
		}
		subselector.disabled=subselector.options.length<=1;
	}
}
function editor_two_level_set_subselector(subselector,value){
	subselector=ge(subselector);
	if(subselector){
		opts=subselector.options;
		for(var index=0;index<opts.length;index++){
			if((opts[index].value==value)||(value===null&&opts[index].value=='')){
				subselector.selectedIndex=index;
			}
		}
	}
}
function update_strength(input_field_id, output_display_id) {
    var input_field = ge(input_field_id),output_display = ge(output_display_id),input_str = input_field.value,input_length = input_str.length,strength = 0;
    // increase strength if contains [0-9]
    number_re = new RegExp("[0-9]");
    if (number_re.test(input_str)) {
      strength++;
    }
    // increase strength if contains non alpha
    non_alpha_re = new RegExp("[^A-Za-z0-9]");
    if (non_alpha_re.test(input_str)) {
      strength++;
    }
    // increase strength if contains upper case
    upper_alpha_re = new RegExp("[A-Z]");
    if (upper_alpha_re.test(input_str)) {
      strength++;
    }   
    // increase strength if long enough
    if(input_length >= 8) {
      strength++;
    }    
    var strength_str = '<text>密码强度：</text>'; 
    if (strength <= 1) {
      strength_str = strength_str + '<strong style="color:grey">弱</strong>';
    } else if (strength <= 2) {
      strength_str = strength_str + '<strong style="color:blue">中等</strong>';
    } else {
      strength_str = strength_str + '<strong style="color:green">强</strong>';
    }    
    if(input_str.length < 6) {
      strength_str = '<strong style="color:orange">密码太短</strong>';
    }
    output_display.innerHTML  = strength_str;
}
function addinvite(uid,uname,page){
	$('<li id="p_'+uid+'">\
<div class="name_row"><a href="'+(page?page:'#')+'">'+uname+'</a></div>\
<div><a onclick="removeinvite(\''+uid+'\');return false;">删除</a></div>\
</li>').appendTo('#invitations');
	if($('#invitations').children().length){
		$('#invitation_list').show();
	}
	if(ge('invite_id_list').value==''){
		ge('invite_id_list').value=uid;
	}else{
		ge('invite_id_list').value+=','+uid;
	}
	$('#u_'+uid).attr('fselector',1).hide();
}
function removeinvite(uid){
	$('#p_'+uid).remove();
	if(!$('#invitations').children().length){
		$('#invitation_list').hide();
	}
	if(ge('invite_id_list').value==uid){
		ge('invite_id_list').value='';
	}else{
		var re=new RegExp(','+uid+'(,|$)','ig')
		ge('invite_id_list').value=ge('invite_id_list').value.replace(re,'$1');
	}
	$('#u_'+uid).removeAttr('fselector').show();
}
function friendselector(obj,to){
	var v = obj.value||'';
	$('#'+to).children().each(function(){
		if(!$(this).attr('fselector')){
			if(v==''){
				$(this).show();
			}else{
				var ar = $(this).attr('u_name')||'';
				if(ar.indexOf(v)>=0){
					$(this).show();
				}else{
					$(this).hide();
				}
			}
		}
	});
}
function setformaction(obj,action){
	obj = ge(obj);
	if(obj.getAttributeNode('action')){
		obj.getAttributeNode('action').nodeValue = action;
	}else{
		obj.setAttribute('action',action);
	}
}
function editnote_submit(){
	var msg = "";
	if(ge('title').value == ''){
		msg += "没有标题\n";
	}
	if(ge('note_content').value == ''){
		msg += "没有日志内容";
	}
	if(msg != ''){
		alert(msg);
		return false;
	}else{
		return true;
	}
}
function checkcreatealbum(){
	var msg = "";
	if(ge('name').value == ''){
		msg += "没有名称\n";
	}
	if(msg != ''){
		alert(msg);
		return false;
	}else{
		return true;
	}
}
function do_report(a)
{
	var msg ="";
	if(a.ftitle.value == "")
	msg += "请添加标题\n";
	if(a.fcontent.value == "")
	msg += "请添加内容\n";
	if(a.author.value == "")
	msg += "请添加作者\n";
	if(msg!= ''){
		alert(msg);
		return false;
	}else{
		return true;
	}
}
function imgup(a)
{
 var b = a.src;
 var s = b.split("/");
 var c = s[4].split(".");
 a.src = "http://www.center-science.com/images/"+c[0]+"f.gif"; 
}  
function imgout(a)
{
 var b = a.src;
 var s = b.split("/");
 var c = s[4].split("f");
 a.src = "http://www.center-science.com/images/"+c[0]+".gif"; 
}
function filterchar(obj){
	obj.value = obj.value.replace(/\D/g ,'');
}
