/**
**通用函数库
**以下的js基于jquery
**/

/**
 * 页面载入就要加载的
 */
(function(){
	$(window).load(function(){
		//验证码
		var refreshScode = function(e){
			e.preventDefault(); // stop normal link click
			var imgObj = document.getElementById('changeScodeImg');
			if(imgObj) {
				var url = imgObj.src;
				var urlArr = url.split('?');
				imgObj.src = urlArr[0] + '/?' + Math.random();
			}
		};
		$('#changeScodeImg').hover(function(){$(this).css({"cursor":"pointer"})}, null);
		$('#changeScodeLink, #changeScodeImg').bind('click', refreshScode);
		
		//图像域
		var filenamePlus = '_hover';
		var imgBtn = $(":image");
		var urlExcludeArr = [
		  'http://img.xoyo.com/publish/jxsj/zt/2009/06/08/images/kingsoft_pass.gif',
		  'http://pic.xoyo.com/cms/www/foot/search-btn.png',
		  'http://pic.xoyo.com/cms/cw/2009/08/13/sub-btn-reg.jpg',
		  'http://mynew.xoyo.com/application/my/view/images/jx3client/j3_btn1.jpg',
		  'http://my.xoyo.com/application/my/view/images/jx3client/j3_btn1.jpg',
		  'http://mynew.xoyo.com/application/my/view/images/hd51/reg-btn.png',
		  'http://my.xoyo.com/application/my/view/images/hd51/reg-btn.png',
		  'http://pic.xoyo.com/cms/ft/2009/12/15/reg-btn.gif'
		];//不加效果 的图片
		jQuery.each(imgBtn, function(i, obj) {
		  var s = obj.src;
		  if(-1 == jQuery.inArray(s, urlExcludeArr)) {
			  $(obj).hover(
				function(){
					var lastDotIndex = s.lastIndexOf('.');
					this.src = s.substr(0, lastDotIndex) + filenamePlus + s.substr(lastDotIndex);
				},
				function(){
					var lastDotIndex = s.lastIndexOf('.');
					this.src = s;
				}
			  );
		  }
		});
		
		//网页title
		var rootTitle = '金山逍遥Xoyo.com';
		var defaultTitle = '金山逍遥Xoyo.com';
		var crumbs = $("div").filter(".crumbs");
		if(crumbs.length > 0) {
			crumbs = crumbs[0].innerHTML.replace(/<[^>]*?>/g, '').split(/：|:/)[1];
			crumbs = crumbs.split(/›|>/).reverse();//注意分隔符
			crumbs.pop();
			crumbs.push(rootTitle);
			for(i=0,len=crumbs.length; i<len; i++) {
				crumbs[i] = $.trim(crumbs[i]);
			}
			var t = crumbs.join('_');
			document.title = t;
		} else {
			document.title = defaultTitle; //默认的
		}
		
	});
})();

/**
 * 如果输入框为非汉字，使刚才的输入失效
 * onkeypress="checkChinese(event);"
 * @param event
 * @return
 */
function checkChinese(event) {
	var code = window.event ? event.keyCode : event.which;
	var is_ie = false;
	if ((navigator.userAgent.indexOf("MSIE") != -1) && (parseInt(navigator.appVersion) >= 4))
		is_ie = true;
	if (code >= 33 && code <= 126) {
		if (is_ie) {
			event.returnValue = false;
		} else {
			event.preventDefault();
		}
	}
}