
//-------------------------------------------------------

//获得X坐标偏移量
function GetOffsetX(evt,Object){
	var evt=((evt)?evt:(window.event)?window.event:"");
	var oNode=GetObj(Object);
	var iSumLeft=0;
	while(oNode.offsetParent&&oNode.tagName.toUpperCase()!="BODY"){
		iSumLeft+=oNode.offsetLeft;
		oNode=oNode.offsetParent     }
      return (evt.clientX-iSumLeft+document.body.scrollLeft)
}
//获得Y坐标偏移量
function GetOffsetY(evt,Object){
	var evt=((evt)?evt:(window.event)?window.event:"");
	var oNode=GetObj(Object);
	var iSumTop=0;
	while(oNode.offsetParent&&oNode.tagName.toUpperCase()!="BODY"){
		iSumTop+=oNode.offsetTop;
		oNode=oNode.offsetParent     }
     
	 return (evt.clientY-iSumTop+document.body.scrollTop)
}

function isIE(){
if (navigator.appName!="Microsoft Internet Explorer") {return false}
return true
}

function checkIsValidDate(str)
{
	if(str == "")
		return false;
    var pattern = /^((\d{4})|(\d{2}))-(\d{1,2})-(\d{1,2})$/g;
    var arrDate = str.split("-");
    if(parseInt(arrDate[0],10) < 100)
        arrDate[0] = 2000 + parseInt(arrDate[0],10)+"";
    var mydate =  new Date(arrDate[0],(parseInt(arrDate[1],10) -1)+"",arrDate[2]);
    if((mydate.getFullYear()==parseInt(arrDate[0],10)) && (mydate.getMonth()==(parseInt(arrDate[1],10) -1)) && (mydate.getDate()==(parseInt(arrDate[2],10))))
        return true;
    else
        return false;
}
function checkEmail(input)
{
	var isEmail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;   
	return isEmail.exec(input);		
}


//-------------------------------------------------------
//获得对象（按三种情况IE，NS）
function GetObj(objName){
	if(document.getElementById){
		return eval('document.getElementById("'+objName+'")')	}
    else if(document.layers){
		return eval("document.layers['"+objName+"']")	}
    else {
		return eval('document.all.'+objName)
	}
}

// ???
function obj(id,doc){
	if(id==""){
		return null
	}
	if(doc==undefined||doc==""){
		return document.getElementById(id)	
	}
     else {
		return doc.getElementById(id)
	}
}
//给url加上时间标签
function request_tag(url){
	var now=new Date();
	var seconds=Math.floor(now.getTime()/1000);
	
	if(url.indexOf("?")==-1){
		return url+"?random_tag_param="+seconds	}
     else {
		return url+"&random_tag_param="+seconds
	}
}

//非常重要的部分，创建连接XMLHTTP对象（异步）
function xmlhttp_async(url,onready,onerror){
	if(url==null||url==""){
		return false
	}
    var xmlhttp;
	if(window.ActiveXObject&&!window.XMLHttpRequest){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")	}
     else {
		xmlhttp = new XMLHttpRequest()
	}
	if(onready != undefined && onready!=""){
		xmlhttp.onreadystatechange = function (){
			if(xmlhttp.readyState==4){
				eval(onready);
				if(xmlhttp.Status==404 && onerror!=undefined && onerror!=""){
					xmlhttp_async(onerror)
				}
			}
		}
	}
	
	xmlhttp.open("GET",request_tag(url),true);
	xmlhttp.setRequestHeader("Contrn-type","text/xml;charset=GB2312"); 
	xmlhttp.responseXML.createProcessingInstruction("xml","version=\"1.0\" encoding=\"gb2312\""); 
	xmlhttp.send(null);
	
	return true
}

var Obj=null;
var oX=0;
var oY=0;

function MDown(Object,evt){
	var evt=((evt)?evt:(window.event)?window.event:"");
	Obj=Object;
	oX=((isIE)?evt.offsetX:GetOffsetX(evt,Obj));
	oY=((isIE)?evt.offsetY:GetOffsetY(evt,Obj));
	document.body.onmousemove=function (event){
		if(Obj!=null){
			var event=((event)?event:(window.event)?window.event:"");
			var posLeft=(document.body.scrollLeft+event.clientX-oX);
			var posTop=(document.body.scrollTop+event.clientY-oY);
			Boundary(Obj,posLeft,posTop);
		}
	};
	document.body.onmouseup=MUp;
}
//鼠标弹起时
function MUp(){
	if(Obj!=null){
		if(Obj=='popbox'){
			curTopReply=parseInt(GetObj(Obj).style.top.replace('px'))-document.body.scrollTop;
			curLeftReply=parseInt(GetObj(Obj).style.left.replace('px'))-document.body.scrollLeft;	}
        else if(Obj=='msgBox'){
			curTopMsgBox=parseInt(GetObj(Obj).style.top.replace('px'))-document.body.scrollTop;
			curLeftMsgBox=parseInt(GetObj(Obj).style.left.replace('px'))-document.body.scrollLeft;
		}
		else if(Obj=='activebox'){
			curTopMsgBox=parseInt(GetObj(Obj).style.top.replace('px'))-document.body.scrollTop;
			curLeftMsgBox=parseInt(GetObj(Obj).style.left.replace('px'))-document.body.scrollLeft;
		}
		Obj=null;
		document.body.onmouseup=null;
		document.body.onmousemove=null;
	}
}
function Boundary(myObj,posLeft,posTop){
	var leftBoundary=document.body.scrollLeft;
	var topBoundary=document.body.scrollTop;
	if( posLeft<leftBoundary )
	{ posLeft=leftBoundary;	}
    if(posTop<topBoundary)
	{ posTop=topBoundary; }
	var rightBoundary=(document.body.clientWidth-GetObj(myObj).offsetWidth+document.body.scrollLeft);
	var bottomBoundary=(document.body.clientHeight-GetObj(myObj).offsetHeight+document.body.scrollTop);
	if(posLeft>rightBoundary)
	{ posLeft=rightBoundary;	}
    if(posTop>bottomBoundary && bottomBoundary>0)
	{ posTop=bottomBoundary;   }
	
	GetObj(myObj).style.left=posLeft+"px";
	GetObj(myObj).style.top=posTop+"px";

	if(Obj=='popbox'){
		curTopReply=posTop;
		curLeftReply=posLeft;	
	} else if(Obj=='msgBox'){
		curTopMsgBox=posTop;
		curLeftMsgBox=posLeft;
	}
	if(myObj=='activebox'){
	//alert('zzzz='+posLeft);
		curTopMsgBox=posTop;
		curLeftMsgBox=posLeft;
	}
}
function FixPos(Obj){
	//alert(document.body.offsetheight);
	GetObj("background").style.height=document.body.scrollHeight+"px";
	GetObj("background").style.width=document.body.scrollWidth+"px";
	var winWidth=document.body.clientWidth;
	var winHeight=document.body.clientHeight;
	var winScrollTop=document.body.scrollTop;
	if(GetObj("popbox")!=undefined){
	if(GetObj("popbox").style.display!="none"){
		curTopReply=(winHeight-GetObj("popbox").offsetHeight)/4;
		curLeftReply=(winWidth-GetObj("popbox").offsetWidth)/2;
		Boundary("popbox",curLeftReply,(winScrollTop+curTopReply))	
	}
	}
	
	if(GetObj("activebox")!=undefined){
	if(GetObj("activebox").style.display!="none"){
		curTopReply=(winHeight-GetObj("activebox").offsetHeight)/8;
		curLeftReply=(winWidth-GetObj("activebox").offsetWidth)/2;
		Boundary("activebox",curLeftReply,(winScrollTop+curTopReply))	
	}
	}
    if(!isIE){
		setTimeout('FixPos(Obj)',500)
	}
}
function hideAllSelect(){
	var obj=document.getElementsByTagName("SELECT");
	var i;
	for(i=0;i<obj.length;i++){
		var z_index = obj[i].style.zIndex ;
	   if(z_index <100 )
	   obj[i].style.visibility="hidden";
	}
}
function showAllSelect(){
	var obj=document.getElementsByTagName("SELECT");
	var i;
	for(i=0;i<obj.length;i++)
	   obj[i].style.visibility="visible";
}
function ShowDiv(myObj,bgFlag){
	hideAllSelect();
    myObj.style.display='block';
	if(bgFlag!=0){
		GetObj("background").style.display=isMoz?'none':'block'
	}
	FixPos(myObj);
}

function HideDiv(myObj,bgFlag){
	myObj.style.display='none';
	if(bgFlag!=0){
		GetObj("background").style.display='none'
	}
	showAllSelect();
}
var isIE=(navigator.appVersion.toLowerCase().indexOf('msie')>=0);
var isMoz=(navigator.userAgent.toLowerCase().indexOf('opera')>=0);
//alert('bbbbbbb');
