// JScript File

var x0=0,y0=0,x1=0,y1=0;
var offx=6,offy=6;
var moveable=false;
var hover='orange',normal='slategray';
var index=10000;

//开始拖动;

function startDrag(obj)
{
//锁定标题栏;

obj.setCapture();

//定义对象;

var win = obj.parentNode;

//记录鼠标和层位置;

x0 = event.clientX;
y0 = event.clientY;
x1 = parseInt(win.style.left);
y1 = parseInt(win.style.top);

//记录颜色;

normal = obj.style.backgroundColor;

//改变风格;

obj.style.backgroundColor = hover;
win.style.borderColor = hover;
//obj.nextSibling.style.color = hover;


moveable = true;
}
//拖动;

function drag(obj)
{
    var win = obj.parentNode;
    var sWidth = window.screen.availWidth;
    if(moveable)
    {
        win.style.left = x1 + event.clientX - x0;
        win.style.top = y1 + event.clientY - y0;
    }
    
   
    if(event.clientY<10)
    {
        win.style.top=15;
        stopDrag(obj);
    }
    if(event.clientX<10)
    {
        win.style.left=15;
        stopDrag(obj);
    }
 
    if (parseInt(win.style.left) + parseInt(win.style.width) > sWidth)
    {
        win.style.left = sWidth - parseInt(win.style.width)-25;
        stopDrag(obj);
    }
}

//停止拖动;

function stopDrag(obj)
{
var win = obj.parentNode;
var sha = win.nextSibling;
win.style.borderColor = normal;
obj.style.backgroundColor = normal;


//放开标题栏;

obj.releaseCapture();
moveable = false;
}

//获得焦点;

function getFocus(obj)
{
index = index + 2;
var idx = index;
obj.style.zIndex=idx;
}

function max(obj)
{
    var win = obj.parentNode.parentNode;
    var tit = obj.parentNode;
    var msg = tit.nextSibling;
    var flg = obj.innerHTML == "1";
    if(flg)
    {
        win.style.height = parseInt(win.style.height)/2 ;
        win.style.width = parseInt(win.style.width)/2;
        win.style.left=(document.body.offsetWidth-win.offsetWidth-20)/2 ;
        win.style.top="200px";
        tit.style.width="100%";
        msg.style.height="100%";

        obj.innerHTML = "2";
    }
    else
    {
        win.style.height = parseInt(win.style.height)*2;
        win.style.width = parseInt(win.style.width)*2;
        win.style.left=(document.body.offsetWidth-win.offsetWidth-20)/2 ;
        win.style.top="200px";
        tit.style.width="100%";
        msg.style.height="100%";
        obj.innerHTML = "1";

    }
    if(msg.style.display == "none")
    {
        win.style.height = parseInt(win.style.height);
        win.style.left=(document.body.offsetWidth-win.offsetWidth-20)/2 ;
        win.style.top="200px";
        msg.style.display = "block";

    }
}

function min(obj)
{
    var win = obj.parentNode.parentNode;
    var tit = obj.parentNode;
    var msg = tit.nextSibling;
    var flg = msg.style.display == "none";
    if(flg)
    {
        win.style.height = parseInt(msg.style.height)+parseInt(tit.style.height);
        win.style.left=(document.body.offsetWidth-win.offsetWidth-20)/2 ;
        win.style.top="200px";
        msg.style.display = "block";
    }
    else
    {
        win.style.height =parseInt(tit.style.height);
        win.style.left="0px";
        win.style.top=document.body.offsetHeight-30;
        msg.style.display = "none";
    }
}

function cls(obj)
{
    var win = obj.parentNode.parentNode;
    win.style.visibility = "hidden";
}

function sett()
{
    setTimeout("sett()",500);
}

function setWH(w,h)
{
    
}

function showPopUp(obj)
{
        var sWidth,sHeight;
		sWidth = window.screen.availWidth;
		if(window.screen.availHeight > document.body.scrollHeight){ 

			sHeight = window.screen.availHeight;  
		}else{

			sHeight = document.body.scrollHeight;   
		}
		//divPopup
		var divPopup =document.getElementById(obj);
		var divPopup_w = getStyle(divPopup,"width");
		var divPopup_h = getStyle(divPopup,"height");
		if(divPopup_w=='auto')
		{
		    divPopup_w=700;
		}
		if(divPopup_h=='auto')
		{
		    divPopup_h=400;
		}
		divPopup_w = parseInt(divPopup_w); 
		divPopup_h = parseInt(divPopup_h);
		var width = pageWidth(); 
		var height = pageHeight();
		var left = leftPosition();
		var top = topPosition();
		var Div_topposition = top + (height / 2) - (divPopup_h / 2); 
		var Div_leftposition = left + (width / 2) - (divPopup_w / 2); 
		
        divPopup.style.width = "0px";
        divPopup.style.height = "0px";
        movement = setTimeout("setOpenSize('"+obj+"','"+divPopup_w+"','"+divPopup_h+"')",0)
		
		divPopup.style.left = Div_leftposition + "px";  
		divPopup.style.top =  Div_topposition + "px";
		divPopup.style.display = "block";
        divPopup.style.position = "absolute";
        divPopup.style.zIndex = "1000";
		//maskDiv
		var maskDiv = document.createElement("div");
		maskDiv.setAttribute('id','maskDiv');
		maskDiv.style.position = "absolute";
		maskDiv.style.top = "0";
		maskDiv.style.left = "0";
		maskDiv.style.background = "#000000";
		maskDiv.style.filter = "Alpha(opacity=40);";
		maskDiv.style.opacity = "0.40";
		maskDiv.style.width = sWidth + "px";
		maskDiv.style.height = sHeight + "px";
		maskDiv.style.zIndex = "999";
		document.body.appendChild(maskDiv);
		//maskIFrame
		var maskIFrame=document.createElement("iframe");
		maskIFrame.setAttribute('id','maskIFrame');
        maskIFrame.style.display="";
        maskIFrame.style.position = "absolute";
        maskIFrame.style.visibility = "inherit";
        maskIFrame.style.top = "0px";
        maskIFrame.style.left = "0px";
        maskIFrame.style.width = sWidth + "px";
        maskIFrame.style.height = sHeight + "px";
        maskIFrame.style.zIndex = "-1";
        maskIFrame.style.background = "#000000";
        maskIFrame.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
        maskDiv.appendChild(maskIFrame)
        return false;
}






function closePopUp(obj) {
        var divPopup =document.getElementById(obj);
		var divPopup_w = getStyle(divPopup,"width");
		var divPopup_h = getStyle(divPopup, "height");
		if (divPopup_w == 'auto') {
		    divPopup_w = 700;
		}
		if (divPopup_h == 'auto') {
		    divPopup_h = 400;
		}
		divPopup_w = parseInt(divPopup_w); 
		divPopup_h = parseInt(divPopup_h);
		movement = setTimeout("setCloseSize('"+obj+"','"+divPopup_w+"','"+divPopup_h+"')",0);
	}

function getStyle(elem, name){

	if(elem.style[name])
		return elem.style[name];
	else if(elem.currentStyle)	//ie
		return elem.currentStyle[name];
	else if(document.defaultView && document.defaultView.getComputedStyle){	//w3c
		name = name.replace(/([A-Z])/g,"-$1");
		name = name.toLowerCase();
		
		var s = document.defaultView.getComputedStyle(elem,"");
		return s && s.getPropertyValue(name);
	} else
		return null
}

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 topPosition(){
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function leftPosition(){
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}


function setOpenSize(obj,w,h)
{

    var show = document.getElementById(obj);
    var xpos = show.style.width != '' ? parseInt(show.style.width) : 700;
    var ypos = show.style.height != '' ? parseInt(show.style.height) : 400;
    if (xpos == w && ypos == h){
    return true;
    }
    if (xpos < w){

    xpos+=w/20;
    }
    if (xpos > w){
    xpos=w;
    }
    if (ypos < h){
    ypos+=h/20;
    }
    if (ypos > h){
    ypos=h;
    }
    show.style.width = xpos + "px";
    show.style.height = ypos + "px";
    movement = setTimeout("setOpenSize('"+obj+"','"+w+"','"+h+"')",0);
}

function setCloseSize(obj, w, h) {

    var show = document.getElementById(obj);
    var xpos = show.style.width != '' ? parseInt(show.style.width) : 700;
    var ypos = show.style.height != '' ? parseInt(show.style.height) : 400;
    if (xpos == 0 && ypos == 0){
        var maskDiv = document.getElementById("maskDiv");
		document.body.removeChild(maskDiv); 
		show.style.display="none";
		show.style.width=w+"px";
		show.style.height=h+"px";
    return true;
}

if (xpos < 0 || xpos == null || xpos == NaN) {
    xpos=0;
    }
    if (xpos > 0){
    xpos-=xpos/20;
    }
    if (ypos <= 0 || ypos == null || ypos == NaN) {
    	
    ypos=0;
    }
    if (ypos > 0){
    ypos-=ypos/20;
    }
    show.style.width = xpos + "px";
    show.style.height = ypos + "px";
    movement = setTimeout("setCloseSize('"+obj+"','"+w+"','"+h+"')",0);
} 

