window.onerror = function(){return true;}
ajax = {
  createObject : function(){
   var ajax = null;
	if(window.XMLHttpRequest){
	  ajax = new XMLHttpRequest();
	  if(ajax.overrideMimeType){
			ajax.overrideMimeType("text/xml");
		}
	}else if(window.ActiveXObject){
	   try{
	      ajax = new ActiveXObject("Microsoft.XMLHTTP");
	   }catch(e){
	      try{
		     ajax = new ActiveXObject("Msxml2.XMLHTTP");
		  }catch(e2){
		    for(var i=3;i<=5;i++){
			   ajax = new ActiveXObject("Msxml2.XMLHTTP."+i+".0");
			   if(ajax){
			     break;
			   }
			}
		  }
	   }
	}
	if(!ajax){
	   alert('Not xmlHttpRequest Object.');return null;
	}
   return ajax;
 },
  response : function(ajax,Url,readyStateChange){
    ajax.open('POST',Url,true);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(null);
	if(readyStateChange!=null) ajax.onreadystatechange = readyStateChange;
  },
  request : function(ajax){
	 var read = ajax.readyState;
	 if(read==4||read=='complate'){
		var html = ajax.responseText;
			return html;
	   }else{
		  var Loading = 'Loading..'+read+'0%';
              return Loading;  
		 }
	 }
};
var xml = ajax.createObject();

//鼠标移动事件
document.onmousemove = ousemove;
document.onmouseout = mouseout;
function ousemove(){
  if(event.srcElement.className=='TextBorder') event.srcElement.className = 'TextBorderFocus';
  if(event.srcElement.className=='btnBorder') event.srcElement.className = 'btnBorderFocus';
  showImage();
}

function mouseout(){
 if(event.srcElement.className=='TextBorderFocus') event.srcElement.className = 'TextBorder';
 if(event.srcElement.className=='btnBorderFocus') event.srcElement.className = 'btnBorder';
}

//放大缩略图
function showImage(){
 var ev = window.event || event;
 var mousePos = mouseCoords(ev);
 if(ev.srcElement.lang=='image'){
    var img = $createElement('img');
	img.src = ev.srcElement.src;
	img.width = 100;img.height = 100;
	$id('image').innerHTML = '';
	$id('image').appendChild(img);
	$id('image').style.left = mousePos.x + 13;
	$id('image').style.top = mousePos.y - 50;
	$id('image').style.zIndex = max_zIndex();
	$id('image').style.display = 'block';
 }else{
    $id('image').style.display = 'none';
	$id('image').innerHTML = '';
 }
}

//DOM操作
function $id(e){
  return document.getElementById(e);
}
function $name(e){
  return document.getElementsByName(e);
}
function $tag(obj,e){
  return obj.getElementsByTagName(e); //返回DOM集合
}
function $createElement(e){
  return document.createElement(e);
}

//获取最大zIndex
function max_zIndex(){
  var div = $tag(document,'div');
  var MaxZindex = div[0].style.zIndex;
  var MaxIndex = 1;
  for(var i=MaxIndex;i<div.length;i++){
    if(MaxZindex<div[i].style.zIndex){
	   MaxZindex = div[i].style.zIndex;MaxIndex = i;
	}
  }
  return MaxZindex+1;
}

//字符串操作
function IsEmail(Email){  //是否是Email
      var  pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
　　　var flag = pattern.test(Email);  
　　　return flag;
}
function IsNumeric(number){
   if(IsNull(number)) return false;
   var pattern  =  /^[0-9]*$/;
　 flag = pattern.test(number); 
   return flag;
}
function IsNull(str){
   var num = '';
   for(var i=0;i<str.length;i++){
	     num+=' ';
	   }
	  return (str==num);
}
function SetLinkTitle(){   //链接标题
	var LinkCount = $tag(document,'A');
	 for(i=0;i<LinkCount.length;i++){
		    LinkCount[i].title = LinkCount[i].innerHTML;
		 }
}
//获取字符串内数字
function getNumber(str){
var num = '';
for(var i=0;i<str.length;i++){
   if(IsNumeric(str.charAt(i))){
      num += str.charAt(i);
   }
  }
  return (IsNumeric(num)) ? parseInt(num) : num.length;
}
//Trim函数
String.prototype.trim = function(){
  return this.replace(/(^\s*)|(\s*$)/g, '');
}
//替换非法字符
function regExp(str){
 str = str.replace(/'/g,"＇");
 str = str.replace(/%/g,"％");
 str = str.replace(/#/g,"＃");
 str = str.replace(/&/g,"＆");
 return(str);
}

//鼠标坐标
function mouseCoords(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 getPos(e){
 var y=e.offsetTop;
 var x=e.offsetLeft;
 while(e=e.offsetParent){
 y+=e.offsetTop;
 x+=e.offsetLeft;
 this.y = y;
 this.x = x;
 }
}

//锁屏
function showbg(obj,top){
   if(!obj) return;
   var Select = $tag(document,'select');
   for(var i=0;i<Select.length;i++){
	      Select[i].style.visibility = 'hidden';
	}
   if($id('Editor')) SetVisibility('Editor','hidden');
   if($id('SelectPage')) SetVisibility('SelectPage','hidden');
   var BG = $createElement('div');
   BG.id = 'BG';
   BG.style.width=document.body.clientWidth;
   BG.style.height=document.body.clientHeight + document.body.scrollTop;
   BG.style.left=0;BG.style.top=0;
   BG.style.zIndex = max_zIndex();
   BG.className='Alpha';
   document.body.appendChild(BG);
   $id(obj).style.position = 'absolute';
   $id(obj).style.display = 'block';
   $id(obj).style.zIndex = max_zIndex();
   if(!top) top = document.body.scrollTop + 150;
   $id(obj).style.top = top;
   $id(obj).style.left = (document.body.clientWidth / 2) - ($id(obj).offsetWidth / 2);
   window.onscroll = function(){
	   $id(obj).style.top = document.body.scrollTop + top;
	   if($id('BG')) BG.style.height = document.body.clientHeight + document.body.scrollTop;
   }
   initDrag();
}

//解屏
function hidebg(obj){
   if(!obj) return;
   var Select = $tag(document,'select');
   for(var i=0;i<Select.length;i++){
	      Select[i].style.visibility = 'visible';
	}
   if($id('Editor')) SetVisibility('Editor','visible');
   if($id('SelectPage')) SetVisibility('SelectPage','visible');
   $id(obj).style.top = 0;$id(obj).style.left = 0;
   $id(obj).style.display = 'none';
   if($id('BG')) document.body.removeChild($id('BG'));
   window.onscroll = function(){ return true;}
}

//页面跳转
function goUrl(Url){
  window.location = Url;
}

//重新载入DOM
function winreload(){
  window.location.reload();
}

//获取浏览器参数 get
function get(item){
  var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
  return svalue ? svalue[1] : svalue;
}

//选中或者取消checkbox选择状态
function CheckAll(){
  var IDs = $tag($id('IDs'),'input');
  for(var i=0;i<IDs.length;i++){
      IDs[i].checked = $id('chkAll').checked;
    }
}
function IsCheckAll(){
  var IDs = $tag($id('IDs'),'input');
  var e;
  for(var i=0;i<IDs.length;i++){
      e = IDs[i].checked;
	  e = (e) ? e : e;
	  if(!e) break;
    }
  $id('chkAll').checked = e;
}

//删除选中checkbox数据
function del(Url,IDs){
  if(!IDs) IDs = SelectAll();
  if(IDs=='') return;
  Url = Url+'&page='+get('page');
  resultCount = IDs.split(',');
  if(confirm('你确定删除选中的 '+resultCount.length+' 项资料吗?')) goUrl(Url+'&IDs='+IDs+'&Action=del');
}

//选中当前页面所有checkbox返回选中值以,分隔
function SelectAll(){
   var IDs = $tag($id('IDs'),'input');
   var UserID = '';
   for(var i=0;i<IDs.length;i++){
	if(IDs[i].type=='checkbox'&&IDs[i].checked==true&&IDs[i].className=='IDs'){
	    if(!getNumber(IDs[i].value)) continue;
		UserID += IDs[i].value+',';
	  }
	}
	 IDs = '';
	for(var i=0;i<UserID.length-1;i++){
	   IDs += UserID.charAt(i);
	}
  return IDs;	
}

//显示文件上传层
function ShowUpLoadFileBox(){
  with($id('UpLoadFileBox').style){
	  top = document.body.scrollTop+200;
	  left = document.body.clientWidth / 3;
	  display = 'block';
   }
}

//提示消息
function showmsg(obj,className,innerHTML){
	$id(obj).className = className;$id(obj).innerHTML = innerHTML;
}

//关键词搜索
function Search(key,Url){
	if(IsNull(key)) return;
	window.location = Url+'&key='+key;
}
//类搜索
function SearchClass(key,Url){
	var ClassID = $id('list').value;
    goUrl(Url+'&ClassID='+ClassID+'&key='+key);
}

//设置数据属性
function SetAttribute(obj,pid,Attribute,status,table,oCol){
   if($id(obj).className==''){
	 $id(obj).className = status;
	 $id(obj).disabled = false;
  }else{
     $id(obj).className = '';
	 $id(obj).disabled = true;
   }
   ($id(obj).disabled) ? status = 0 : status = 1;
   var Url = 'ajax.asp?obj='+table+'&pid='+oCol+'&id='+pid+'&Attribute='+Attribute+'&status='+status+'&Action=SetAttribute';
   ajax.response(xml,Url,null);
}

//更新数据
function Update(table,oCol,pid,Attribute,status){
   (status) ? status = 1 : status = 0;
   var Url = 'ajax.asp?obj='+table+'&pid='+oCol+'&id='+pid+'&Attribute='+Attribute+'&status='+status+'&Action=SetAttribute';
   ajax.response(xml,Url,null);
}
//设置显示|隐藏
function SetDisplay(obj,display){
  $id(obj).style.display = display;	
}
function SetVisibility(obj,visibility){
  $id(obj).style.visibility = visibility;	
}

//系统提示Alert(msg)
function Alert(msg){
  $id('alertmsg').innerHTML = msg;
  showbg('alert');
}

//拖拽
function initDrag(){
  var dragObjs = $tag(document,'div');
  for(i=0;i<dragObjs.length;i++){
    if(dragObjs[i].lang=='drag'){
	   Drag.init(dragObjs[i],dragObjs[i].parentNode);
	}
  }
}

//是否是日期格式
function IsDate(sDate){
	var iYear, iMonth, iDay, iIndex
    var	reg
	reg = new RegExp('[^0-9-]','')
	if (sDate.search(reg) >= 0)
		return false;
	iIndex = sDate.indexOf('-');
	if ( iIndex == -1 )
		return false;
	else {
		iYear = parseFloat(sDate.substr(0, iIndex));
		if ( isNaN(iYear) || iYear < 1900 || iYear > 2099 )
			return false;
		else
			sDate = sDate.substring(iIndex + 1, sDate.length);
	}
	iIndex = sDate.indexOf('-');
	if ( iIndex == -1 )
		return false;
	else {
		iMonth = parseFloat(sDate.substr(0, iIndex));
		if ( isNaN(iMonth) || iMonth < 1 || iMonth > 12 )
			return false;
		else
			sDate = sDate.substring(iIndex + 1, sDate.length);
	}
	iIndex = sDate.indexOf('-');
	if ( iIndex >= 0 )
		return false;
	else {
		iDay = parseFloat(sDate);
		if ( isNaN(iDay) || iDay < 1 || iDay > 31 )
			return false;
	}
	switch(iMonth) {
		case 4:
		case 6:
		case 9:
		case 11:
			if ( iDay > 30 )
				return false;
			else
				break;
		case 2:
			if ( ( ( iYear % 4 == 0 && iYear % 100 != 0 ) || iYear % 400 == 0 ) && iDay > 29 )
				return false;
			else if ( (iYear % 4 != 0 || (iYear % 100 == 0 && iYear % 400 != 0)) && iDay > 28 )
				return false;
			else
				break;
		default:
	}
	return true;
}

function showhide(obj){
  ($id(obj).style.display=='none') ? SetDisplay(obj,'block') : SetDisplay(obj,'none');
}

//设置层样式
function showdiv(obj,classname,position,display,width,height,top,left,html){
	with($id(obj)){
	  	className = classname;
		style.position = position;
		style.display = display;
		style.width = width;
		style.height = height;
		style.top = top;
		style.left = left;
		if(html)innerHTML = html;
 }
}
