﻿if(typeof(ychl)=='undefined')
    var ychl=new Object();
ychl.popupdiv=new Object();
ychl.popupdiv.getAbsolutePos=function(el){
    var SL = 0, ST = 0;
    var is_div = /^div$/i.test(el.tagName);
    if (is_div && el.scrollLeft)
        SL = el.scrollLeft;
    if (is_div && el.scrollTop)
        ST = el.scrollTop;
    var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
    if (el.offsetParent){
        var tmp = this.getAbsolutePos(el.offsetParent);
        r.x += tmp.x;
        r.y += tmp.y;
    }
    return r;
}
var DivName='';
var FrameName='';
var Frame='';
ychl.popupdiv.CreateFrame=function(PopDiv,src){
      //marginheight=0 marginwidth=0 hspace=0 vspace=0 
      var ifm=document.createElement("<iframe frameborder=0 src="+src+" onload='setPage()' scrolling=no></iframe>");
      var tipFrameBox=document.getElementById(PopDiv);
      ifm.name=ifm.uniqueID;
      FrameName=ifm.name;
      Frame=ifm;
      tipFrameBox.innerHTML="";   
      tipFrameBox.appendChild(ifm);
      DivName=PopDiv;
}
function setPage(){
      var ifm=document.frames[FrameName];
      var tipFrameBox=document.getElementById(DivName);
      if(typeof(ifm)!='undefined')
      {
      if(Frame.src.toLowerCase()=='/user/framepage/sublist.aspx')
      {
          Frame.style.width="212px";
      }
      else
          Frame.style.width=tipFrameBox.style.width=ifm.document.body.scrollWidth+"px";
      Frame.style.height=tipFrameBox.style.height=ifm.document.body.scrollHeight+"px";
     }
      
}

function RemovePage(){
      if(DivName!='')
      {
        var DivObj=document.getElementById(DivName);
        DivObj.removeChild(DivObj.childNodes[0]);
        DivObj.style.width="0px";
        DivObj.style.heigth="0px";
      }
}

ychl.popupdiv.PopUp=function(objID,src,popUpID,x,y){;
    var Control=document.getElementById(objID);
    ychl.popupdiv.CreateFrame(popUpID,src);
    var ControlPos=ychl.popupdiv.getAbsolutePos(Control);
    if(typeof(x)=='undefined'&&typeof(y)=='undefined')
    {
    document.getElementById(popUpID).style.left=ControlPos.x-50;
    document.getElementById(popUpID).style.top=ControlPos.y;
    }
    else
    {
    document.getElementById(popUpID).style.left=ControlPos.x+parseInt(x);
    document.getElementById(popUpID).style.top=ControlPos.y+parseInt(y);
    }
}

ychl.popupdiv.PopUpCalendar=function(objID,popUpID,x,y){;
    var Control=document.getElementById(objID);
    document.getElementById(popUpID).style.display='';
    var ControlPos=ychl.popupdiv.getAbsolutePos(Control);
    if(typeof(x)=='undefined'&&typeof(y)=='undefined')
    {
        document.getElementById(popUpID).style.left=ControlPos.x;
        document.getElementById(popUpID).style.top=ControlPos.y;
    }
    else
    {
        document.getElementById(popUpID).style.left=ControlPos.x+parseInt(x);
        document.getElementById(popUpID).style.top=ControlPos.y+parseInt(y);
    }
}

//得到页面中间的位置
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//得到页面的大小
function getPageSize(){
	var xScroll, yScroll;	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


var SplitChar=' ';
function Close(Type,Index,value,HiddenInput){
            var obj=document.getElementById('Frameli'+Type+Index);
            var myid=obj.id;
            if(obj.parentNode.childNodes.length>1)
                obj.parentNode.removeChild(obj);
            else
            {
                var myobj=obj.parentNode.parentNode;
                var parentID=myobj.childNodes[0].id;
                myobj.removeChild(myobj.childNodes[0]);
                var myul=document.createElement('ul');
                myul.id=parentID;
                myobj.appendChild(myul);
            }
            var objectID=HiddenInput;
            var MyValue=document.getElementById(objectID).value;
 
            var arr=MyValue.split(SplitChar);
            var innerHTML='';
            for(var i=0;i<arr.length;i++)
            {
             if(arr[i]=='')
                continue;
             if(arr[i]==value)
               {
                 continue;
               }
             if(innerHTML=='')
                innerHTML+=arr[i];
             else
                innerHTML+=SplitChar+arr[i];
            }
            document.getElementById(objectID).value=innerHTML;
}
function GetObject() {
        var elements = new Array();
        for (var i = 0; i < arguments.length; i++) {
                var element = arguments[i];
                if (typeof element == 'string')
                        element = document.getElementById(element);
                if (arguments.length == 1) 
                        return element;
                elements.push(element);
        }
        return elements;
}
//替换回车
function ReplaceBR(replaceHtml) {
        return replaceHtml.replace(/\r\n|\r|\n/g, "<br />");
}
//关闭和清除窗口
function closeInfoWnd(name) {
    try {
        div = GetObject(name);
        if (div) {
            document.body.removeChild(div);
            delete div;
            div = null;
        }
    } catch(E) {}
}
//对话框
function ShowBox(cont) {
    closeInfoWnd('EditSysWnd');
    var div = document.createElement("div");
    div.id = "EditSysWnd";
    div.style.position="absolute";
    div.className="popupDiv";
    var divHtml = "";
    var width = "600";
    divHtml += "<div class=\"Wnd\" style=\"width:" + width + "px;height:auto;\">";
    divHtml += "    <div class=\"WndTop\" style=\"width:" + width + "px;height:auto; text-align:right;\"><img src=\""+homePage+"Images/msg_2.gif\" style=\"cursor:hand;\" onclick=\"closeInfoWnd('EditSysWnd');\" />";
    divHtml += "    </div>";
    divHtml += "    <div class=\"PhotoWndCont\">";
    divHtml += cont;
    divHtml += "    </div>";
    divHtml += "</div>";
    div.innerHTML = divHtml;
    var pa = getPageSize();
    
    var psl = getPageScroll();
    div.style.top =  (pa[3]/2 - 200 + psl[1]) + "px";
    div.style.left =  ((pa[0] - width) / 2) + "px";
    div.getElementsByTagName("div")[0].style.top =  (pa[3]/2 - 500 + psl[1]) + "px";
    div.getElementsByTagName("div")[0].style.left =  ((pa[0] - width) / 2) + "px";
    document.body.appendChild(div);
}

//对话框
function ShowBoxW(cont,width) {
    closeInfoWnd('EditSysWnd');
    var div = document.createElement("div");
    div.id = "EditSysWnd";
    div.style.position="absolute";
    div.className="popupDiv";
    var divHtml = "";
    if(width == "" || width < 0)
        width = "300";
    divHtml += "<div class=\"Wnd\" style=\"width:" + width + "px;height:auto;\">";
    divHtml += "<div class=\"WndTop\" style=\"width:" + width + "px;height:auto;\">";
    divHtml += "</div>";
    divHtml += "<div class=\"PhotoWndCont\">";
    divHtml += cont;
    divHtml += "</div>";
    divHtml += "</div>";
    div.innerHTML = divHtml;
    var pa = getPageSize();
    
    var psl = getPageScroll();
    div.style.top =  (pa[3]/2 - 100 + psl[1]) + "px";
    div.style.left =  ((pa[0] - width) / 2) + "px";
    div.getElementsByTagName("div")[0].style.top =  (pa[3]/2+ psl[1]) + "px";
    div.getElementsByTagName("div")[0].style.left =  ((pa[0] - width) / 2) + "px";
    document.body.appendChild(div);
}