/*公用JS*/
function killerrors() { 
return true; 
} 
window.onerror = killerrors; 


var path = '';

//取cookies函数，亦可用escape转码
function getCookie(name) {
  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  if (arr != null && arr != false) {
    return decodeURIComponent(arr[2]);
  }
  return false;
}

//两个参数，一个是cookie的名子，一个是值
function setCookie(name, value, time) {
  var cookieEnabled = (typeof navigator.cookieEnabled != 'undefined' && navigator.cookieEnabled) ? true : false;
  if (cookieEnabled == false) {
    alert('您的浏览器未开通cookie，程序无法正常使用！');
    return false;
  }
  if (!time || isNaN(time)) time = 365; //此 cookie 将被保存 365 天
  var expires = new Date();    //new Date("December 31, 9998");
  expires.setTime(expires.getTime() + time * 24 * 60 * 60 * 1000);
  var cookieStr = encodeURIComponent(value);
  /*
  if (cookieStr.length > 3072) {
    //alert('所设置的cookie数据太大，系统将自动缩减');
    cookieStr = cookieStr.substring(0, 3072).replace(/[\|\s]+$/, '');
  }
  */
  document.cookie = name+'='+cookieStr+'; expires='+expires.toGMTString()+'; path=/;';
}

function get_checkbox(id) {
  var allCheckBox = document.getElementsByName(id);
  var article = 0;
  if (allCheckBox != null && allCheckBox.length > 0) {
    for (var i = 0; i < allCheckBox.length; i++) {
      if (allCheckBox[i].checked == true && allCheckBox[i].disabled == false) {
        article++;
        //break;
      }
    }
  }
  return article;
}

function allChoose(v1, v2) {
  var a = document.getElementsByName('id[]');
    for (var i = 0; i < a.length; i++){
      if (a[i].checked == false) a[i].checked = v1;
      else a[i].checked = v2;
  }
}

function chk(form, input, manageType) {
  if (form.action != 'member.php?get=list_edit') {
    oAction = form.action;
  }
  if (get_checkbox('id[]') == 0) {
    alert('数据为空或尚未点选！');
    return false;
  }
  if (confirm('确定'+input.innerHTML.replace(/<[^>]*>/g,'')+'么？')) {
    if(manageType == 'edit'){
      form.action = 'member.php?get=list_edit';
	  form.submit();
	  return;
    }
    form.limit.value = manageType;
    form.action = oAction;
    addSubmitSafe();
    form.submit();
  }
  return false;
}

//取物件
function $(obj) {
  return document.getElementById(obj);
}

//加遮罩
function addSubmitSafe() {
	if ($('submit_safe') == null) {
		var s = document.createElement('DIV');
		s.id = 'submit_safe';
		s.className = 'filter';
		document.body.appendChild(s);
		s.innerHTML = '<table width="100%" height="100%"><tr><td><div id="submit_safe_in">&#x8BF7;&#x7A0D;&#x5019; &#x2026;</div></td></tr></table>';
		if (arguments[0] == 1) {
			return
		}
		s.onmousedown = function() {
			s.innerHTML = '<table width="100%" height="100%"><tr><td><div id="submit_safe_in">&#x6B63;&#x5728;&#x5173;&#x95ED;&#x906E;&#x7F69; &#x2026;</div></td></tr></table>';
			setTimeout('delSubmitSafe();', 3000)
		}
	}
}

function delSubmitSafe() {
	while ($('submit_safe') != null) {
		$('submit_safe').style.display='none';
		document.body.removeChild($('submit_safe'))
	}
}

//截取字串
/*
function cutstr(str, len) {
  str = str.replace(/\s+/g,'').replace(/<[^>]*>/g,'');
  var temp_str = '';
  var num = str.length;
  for (var i = 0; i < len; i++) {
    temp_str += str.charCodeAt[i] > 127 ? str.substr(i,1).str.substr(++i,1).str.substr(++i,1) : str.substr(i,1);
    if (i > num) {
      break;
    }
  }
  if (num > len) {
    temp_str += '…';
  }
  return temp_str;
}
*/
function cutstr(str, len) {
  str = str.replace(/　|[\s\n\r]+|&nbsp;/ig, '').replace(/<[^<>]*>/g, '');
  if (!str || !len) {
    return ''
  }
  var strlen = str.length;
  for (var i = 0; i < strlen; i++) {
    if (str.charCodeAt(i) <= 255) {
      len -= 0.5
    } else {
      len--
    }
    if (len <= -0.5) {
      break
    }
  }
  return str.substr(0, i) + (i < strlen ? '…': '')
};

// 只允许输入数字
function isDigit(obj, starVal, s, t) { //s：0要求大于0，1不必大于0；t：小数点代表货币型数字
  var ye = false;
  var d = r1 = r2 = '';
  if (typeof(s) != 'undefined') {
    if (s == 0) {
    } else {
      ye = true;
      if (obj.value == '0' || obj.value == '') {
        obj.value = '0';
        return;
      }
    }
  }
  if (ye == false) {
    d = '大于0的';
    r1 = ' || obj.value <= 0';
    r2 = '\-?';
  }

  if (typeof(t) != 'undefined' && t == '.') {
    var t = 'isNaN(obj.value)'+r1;
    var b = ''+d+'货币类型数值';
  } else {
    var t = '!/^'+r2+'([1-9]|[1-9][0-9]+)$/.test(obj.value)';
    var b = ''+d+'整数';
  }
  if (eval(t)) {
    alert('你输入的值不对，只允许输入'+b+'！');
    obj.value = starVal;
  }
}

function logoutM(o) {
	var ifr = $('logoutIframe');
	if (ifr == null) {
		ifr = document.createElement('iframe');
		ifr.id = 'logoutIframe';
		document.body.appendChild(ifr);
		//o.target='logoutIframe';
	}
	ifr.style.display = 'none';
	ifr.src = o.href;
	return false;
}

var LSE=false;
var cTimer;
function showLogin(o, forId){
  //<iframe id="addCFrame" name="addCFrame" frameborder="0" scrolling="No"></iframe>
  window.clearTimeout(cTimer);
  var ifr=$('addCFrame');
  if(ifr==null) {
    var ifr=document.createElement("IFRAME");
    ifr.id='addCFrame';
    ifr.name='addCFrame';
    ifr.frameborder=0;
    ifr.scrolling='No';
    o.insertBefore(ifr, null);
  }
  if(forId!=false){
    sei=$(forId);
    sei.className="session_in session_in_";
  }
  ifr.style.display="block";
  if(LSE==false){
    ifr.src="login_.php";
	LSE=true;
  }
  ifr.onmouseout=function(){
    cTimer = setTimeout(function(){
      ifr.style.display='none';
      ifr.parentNode.removeChild(ifr);
      LSE=false;
      if(forId!=false){
        try{
          $(forId).className='session_in';
        }catch(e){}
      }
    }, 3000);
  }
}
function closeLogin(ifr, forId){
}
function toQzoneLogin(v){
  var iW = 900;  var iH = 380;
  var oW = parent.document.documentElement.clientWidth;
  var oH = parent.document.documentElement.clientHeight;
  var oT = window.screen.availHeight - oH;
  var iT = oT+(oH-(iH+58))/2; //获得窗口的垂直位置;
  var iL = (oW-10-iW)/2; //获得窗口的水平位置;
  window.open("login_key/"+v+"/","TencentLogin","width="+iW+",height="+iH+",top="+iT+",left="+iL+",menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");
}
var loginReloadYeNo=false;
function loginReload(){
  if(loginReloadYeNo==true){
	location.reload();
  }
  LSE=false;
}


function goWebmasterCentral(){
  location.href='webmaster_central.php';
}


function addFavor() {
	var sTitle = document.title;
	var sURL = location.href;
	try {
		window.external.addFavorite(sURL, sTitle)
	} catch (e) {
		try {
			window.sidebar.addPanel(sTitle, sURL, '')
		} catch (e) {
			alert('加入收藏失败，请使用Ctrl+D进行添加')
		}
	}
	return false
}
