﻿function ShowuploadPic(obj){
    Mask();
    var strBuf = document.getElementById(obj).innerHTML;
    CreateWindow(obj, 600, 200, strBuf);
}

function hideAllSelect()
{
	var selects = document.getElementsByTagName("SELECT");
	for(var i = 0; i < selects.length; i++)
	{
		selects[i].style.display = "none";
	}
}

function showAllSelect() 
{ 
	var selects = document.getElementsByTagName("SELECT");
	for(var i = 0; i < selects.length; i++)
	{
		selects[i].style.display = "";
	}
}

function Mask ( ) 
{
	var sWidth,sHeight;
   	sHeight = screen.height * 2;
   	sWidth = screen.width;
	document.documentElement.style.overflow="hidden";
	hideAllSelect();
	var bgObj = document.createElement("div");
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top=0;
	bgObj.style.background="#000000";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=30,finishOpacity=100)";
	bgObj.style.opacity="0.6";
	bgObj.style.left=0;
	bgObj.style.width=sWidth+"px";
	bgObj.style.height=sHeight+"px";
	bgObj.style.zIndex = 100;	
	document.body.appendChild(bgObj);
}

function CreateWindow (obj, w, h, title) 
{
	var sWidth,sHeight;
	mLeft = document.documentElement.scrollLeft + (document.documentElement.clientWidth - 400) / 2
	mTop = 	document.documentElement.scrollTop + (document.documentElement.clientHeight - 200) / 2
	var oDiv = document.getElementById(obj);		
	oDiv.style.position = 'absolute';	
	oDiv.style.zIndex = 1100;	
	oDiv.style.display = "";
}

function closeWindow(obj) {
    document.getElementById(obj).style.display = "none";
    var obj2 = document.getElementById("bgDiv");
	document.body.removeChild(obj2);	
	document.documentElement.style.overflow="";
	showAllSelect();
}

function drag(wrapId){
    var getAbsoluteCoords = function (e) {
        var width = e.offsetWidth;
        var height = e.offsetHeight;
        var left = e.offsetLeft;
        var top = e.offsetTop;
        while (e=e.offsetParent) {
            left += e.offsetLeft;
            top  += e.offsetTop;
        };
        var right = left+width;
        var bottom = top+height;
        return {
            'width': width,
            'height': height,
            'left': left,
            'top': top,
            'right': right,
            'bottom': bottom
        };
    };

    var getElementById = function (sId) {
        return document.getElementById(String(sId));
    };
    
    var wrap = document.getElementById(wrapId); 
    var isChangeLayout;
    wrap.onmouseover = function () {    
        isChangeLayout = true;
        wrap.style.cursor = isChangeLayout?"default":"se-resize";
        if (window.ActiveXObject) 
            wrap.onselectstart = function () { event.returnValue = false; }
        
        document.onmousedown = function (evt) {            
            evt = window.event||evt; var a=getAbsoluteCoords(wrap);
            wrap.cx=evt.clientX-(isChangeLayout?a.left:a.width); 
            wrap.cy=evt.clientY-(isChangeLayout?a.top:a.height);
            document.onmousemove = function (evt) {                                
                evt = window.event||evt; 
                try {
                    if (isChangeLayout) {
                        wrap.style.left = (evt.clientX-wrap.cx)+"px";
                        wrap.style.top = (evt.clientY-wrap.cy)+"px";
                    } 
                    else {
                        wrap.style.width = (evt.clientX-wrap.cx)+"px";
                        wrap.style.height = (evt.clientY-wrap.cy)+"px";
                    }
                }catch (ex) {};             
            };
        
            document.onmouseup = function () {
			document.onmousemove = null;
			document.onmouseup = null;
			wrap.style.cursor="default";
            };
        };
    }
}
