/**
 * 对jquery的默认设置，很重要!（尤其里面的data:''，解决了firefox中post失效的问题）
 */
$.ajaxSetup( {
		type: "POST",
		global: false,
		data: '',
		async: true
        } );
/**
 * 对基本变量的处理和判断
 */
function undef(obj){
	// exception if obj is not an Object
	return (typeof obj == "undefined" || obj == null);
};

function def(obj){
	// exception if obj is not an Object
	return (typeof obj != "undefined" && obj != null);
};

function empty(obj){
	if(typeof(obj) == "undefined" || obj === 0 || obj == "0" || obj == null || obj === false || obj == ""){
		return true;
	}
}
/**
 * 字符串一些基本操作
 */
function left_trim(str){
	return str.replace( /^\s*/, "");
}
function right_trim(str){
	return str.replace( /\s*$/, "");
}
function trim_str(str){
	return right_trim(left_trim(str));
}

/**
 * @return: 返回str的字节数
 */
function bytes(str){
    if(typeof(str)!='string'){
        str = str.value;
    }
    var len = 0;
    for(var i = 0; i < str.length; i++){
        if(str.charCodeAt(i) > 127){
            len++;
        }
        len++;
    }
    return len;
}
/**
 *	判断输入是否是一个数字
 */
function is_numeric( mixed_var ) {
	return !isNaN( mixed_var );
}

function is_int(a){
    var re = /^[0-9]*[1-9][0-9]*$/;
    return re.test(a);
}

/**
 * 获取滚动条的位置等
 */
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}

function mousePos(ev){
  if(ev.pageX || ev.pageY){
    return {x:ev.pageX, y:ev.pageY};
  }
  return {
    x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
    y:ev.clientY + document.body.scrollTop - document.body.clientTop
  };
}

function moveTo( objID, ev ){
    ev = ev || window.event;
    var pos = mousePos(ev);
//    alert(pos.x + " " + pos.y);
    var obj = $('#' + objID);
    var _left = pos.x + 134 - posLeft();
    if(env.xIE) { _left = _left + posLeft(); }
    var _top = pos.y - obj.height() - 4 - posTop();
    if(env.xIE) { _top = _top + posTop(); }
//    alert(_left + " " + _top);
    obj.css("left", _left);
    obj.css("top", _top);
}
/**
 * 对url的处理函数
 */
function gotoURL(url) {
	window.location.href = url;
}
function goURL(url) {
    setTimeout("window.location.href ='"+url+"';", 200);
}
function refreshURL(){
	location.reload();
}
//计算文字字数
function strCount(str){
    str = trim_str(str);
    if(empty(str)){
        return 0;
    }
    str = str.replace(/\s|　/g,'');
    return str.length;
}
function checkSave(){
    var chbox = $("#savepasswd");
    if(chbox.attr("checked") == true){
        alert("温馨提示：选择此项后，下次将自动登录小说阅读网（本机一个月内有效）。\n为了您的信息安全，请不要在网吧或公用电脑上使用。");
    }
}