//window.onerror=function(){return true;};
/**
 * Youkia 公用js
 * @created 200908261206 liurw
 */
function youkiaPublicModel()
{
	var _this = this;

	var init = function()
	{
		//加载公用css
		_this.loadCss('/public/c/popDiv.css');
		_this.loadCss('/public/c/popCard.css');
		_this.loadCss('/css/attach/jquery.autocomplete.css');
		_this.loadCss('/share/css/btnShare.css');
		_this.loadCss('/share/css/message.css');

		//加载公用js
document.write(unescape('%3Cscript type="text/javascript" src="/scripts/youkia-nav.js"%3E%3C/script%3E'));
		/*_this.loadJs('/scripts/jquery.bgiframe.js');
		_this.loadJs('/scripts/jquery.cookie.js');
		_this.loadJs('/scripts/jquery.autocomplete.js');
		_this.loadJs('/scripts/jquery.pngFix.js');
		_this.loadJs('/scripts/base64.js');
		_this.loadJs('/scripts/common.js');
		_this.loadJs('/scripts/filtration.js');
		_this.loadJs('/scripts/prompt.js');
		_this.loadJs('/scripts/namecard.js');
		_this.loadJs('/scripts/activationstatus.js');
		_this.loadJs('/scripts/share.js');
		_this.loadJs('/scripts/help.js');
		_this.loadJs('/scripts/jquery-ui-1.7.1.custom.min.js');*/
		_this.loadJs('/scripts/youkia_lib_cache.js');

		$(document).ready(function()
		{
			$('body').append('<div id="bubble" class="bubble" style="position:absolute; display:none;z-index:10001"><blockquote><p><span id="hint"></span></p></blockquote></div>');//插入冒泡提示
			var url = location.href;
			if( !url.match(/(\/digg)/) )
			{
				$(document).pngFix();//页面内png图片ie6下设置透明
			}
			/*$.getScript("/php/new.php?act=get"); */
			
			$('#headerkeyword').autocomplete('/index.php/home/nickname',{
				extraParams:{
					nickname: function(){if($('#headerselect').val()=='nickname') var keyword=$('#headerkeyword').val();else var keyword=false; return keyword }
				}
				}
			);
		});
	};

	//加载js文件
	this.loadJs=function(js_url)
	{
		document.write(unescape('%3Cscript type="text/javascript" src="' + escape(js_url) + '"%3E%3C/script%3E'));
	};

	//加载css文件
	this.loadCss=function(css_url)
	{
		document.write(unescape('%3Cstyle type="text/css">@import url("' + escape(css_url) + '");%3C/style%3E'));
	}

	//设置浮动层坐标
	this.setPopXY=function(obj,x,y)
	{
		if(typeof(x)=='undefined' || typeof(y)=='undefined')
		{
			return;
		}

		$(obj).css({top:y+'px',left:x+'px'});
	};

	//获取对象的页面坐标
	this.getObjXY=function(obj)
	{
		if(typeof(obj)=='undefined')
		{
			return {'x':0, 'y':0};
		}

		return {'x':$(obj).offset().left, 'y':$(obj).offset().top};
	};

	//关闭对象
	this.closeDiv=function(obj)
	{
		$(obj).fadeOut('slow');
		$('#PageDisabled').remove();
	};

	//设置html对象页面居中
	this.setCenter=function(obj)
	{
		var mainMarginTop = Math.max(($(window).height()-obj.height())/2+$(document).scrollTop(), 10);
		var mainMarginLeft = Math.max(($(window).width()-obj.width())/2, 10);
		obj.css({'left':mainMarginLeft+'px', 'top':mainMarginTop+'px'}).bgiframe();
	};

	//设置页面蒙板层
	this.setPageDisabled=function()
	{
		if ($('#PageDisabled').length>0){return;}
		var TXnewMask = document.createElement("DIV");
		TXnewMask.id = 'PageDisabled';
		var height= Math.max($(document).height(),$(window).height())+'px';
		$(TXnewMask).css({"height":height,"width":"100%","z-index":60,"position":"absolute","top":"0px","left":"0px","display":"none","background":"#000","filter":"alpha(opacity=30)","opacity":"0.30"});
		document.body.appendChild(TXnewMask);
		$(TXnewMask).fadeIn('slow');
	};

	//冒泡提示
	this.inputNotice=function(obj,str,top,left)
	{
		$('#hint').html(str);	
		var offset=obj.offset();
		var width=obj.width();
		if(typeof(left)=='undefined')
			var left=offset.left+width-20;
		else
			left=offset.left+width+left;
		if(typeof(top)=='undefined')
			var top=offset.top-40;
		else
			top=offset.top+top;
		obj.focus();	
		$('#bubble').css({top:top,left:left,display:''}).bgIframe();
		setTimeout("$('#bubble').fadeOut('slow');",5000);
	}

	//社区消息提示
	this.showMsg=function(str,time)
	{
		if ($('#popdiv').length==0)
		{
			$('body').append('<div id="popdiv" class="popdiv" style="display:none; position:absolute;"><div class="popdivTop"></div><div class="popdivBody" id="popdiv_body"></div><div class="popdivBot"><a href="javascript:void(0);" onclick="youkiaPublic.closeDiv($(\'#popdiv\'))" class="bClose"></a></div></div>');
		}

		$('#popdiv_body').html(str);
		this.setCenter($('#popdiv'));

		if ($('#popdiv').css('display')=='none')
		{
			this.setPageDisabled();
			$('#popdiv').fadeIn('slow').bgiframe();
		}

		if (typeof(time)!='number') time=2000;
		if (time>0) setTimeout(function(){_this.closeDiv($('#popdiv'));}, time);
	}

	//进入flash游戏
	this.showDialog=function(url, id, width , height )
	{
        if( !width ) { width = 1024 }
        if( !height ) { height = 700 }
        //游客模式
        if (!$.cookie('youkia')){
            visitor();
            return;
        }
		var userAgent = navigator.userAgent.toLowerCase();
		var browser = {
			version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
			safari: /webkit/.test( userAgent ),
			opera: /opera/.test( userAgent ),
			maxthon: /maxthon/.test( userAgent ),
			msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
			mozilla: /mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)
		};
		if (browser.maxthon) {
			showModalDialog(url, id, 'dialogWidth:'+width+'px;dialogHeight:'+height+'px;dialogLeft:200px;dialogTop:50px;center:yes;help:no;resizable:no;status:no;scroll:no');
		} else {
			window.open(url, id, "height="+height+", width="+width+", top=50, left=200,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
		}
	}

	//老应用激活
	this.yksetuser=function(uid)
	{
		if(typeof(uid)=='undefined'){return false;}
		$.get('/app/data/Session',{uid:uid,random:Math.random()});
	}

	//数据校验
	this.verify={
		isEmail : function(email)
		{
			email=$.trim(email);
			var re=/^[\w-]+(\.*[\w-]+)*@([0-9a-z]+(([0-9a-z]*)|([0-9a-z-]*[0-9a-z]))+\.)+[a-z]{2,3}$/i;
			return re.test(email);
		}
	};
	
	this.strLength = function (str)
	{
		return typeof(str)=='undefined' ? 0 : str.replace(/[^\x00-\xff]/g, 'aa').length;
	}
	
	this.closeNew = function(obj,str)
	{
		$(obj).remove();
		$.getScript("/php/new.php?act=do&url="+str);
	}
	
	this.headersearch=function ()
	{
		var keyword=$.trim($('#headerkeyword').val());
		if(keyword=='')
		{
			inputnotice($('#headerkeyword'),'请输入搜索内容');
			$('#headerkeyword').focus();
			return false;
		}
		var searchname=$('#headerselect').val();
		if(searchname==0)
		{
			inputnotice($('#headerselect'),'请选择搜索分类');
			$('#headerselect').focus();
			return false;
		}
	
		$('#headerform').attr('action','/index.php/search/'+searchname)
		$('#headerform').submit();	
		return false;
	}
	init();
}

var youkiaPublic = new youkiaPublicModel();

//////////////////////common.js部分内容/////////////////////////////////////
function checktext(objid,total,type)
{
	var yktotal='yktotal'+objid;
	if(type=='output')
	{
		document.write('你还可以输入<font id='+yktotal+'>'+total+' </font>个字');
	}
	else if(type=='input')
	{
		var str='';
		str=$('#'+objid).val().substr(0,total);
		/*$('#'+objid).val(str);
		$('#'+objid).scrollTop(1000);*/
		var len=str.length;
		$('#'+yktotal).html((total-len)+'');
		
	}
	else if(type=='fixed')
	{
		while($('#'+objid).scrollTop()>0)
		{
			var str=$('#'+objid).val();
			str=str.substr(0,str.length-1);
			$('#'+objid).val(str);
		}
	}
	
}