var dragswitch = 0
var ishidden = 0;
function hidden_select(){
    var selects = document.getElementsByTagName("select");
    for (var i = 0; i < selects.length; i++) {
        selects[i].style.display = "none";
    }
}

function stop_dag(){
    dragswitch = 0
}

function show_select(){
    var selects = document.getElementsByTagName("select");
    for (var i = 0; i < selects.length; i++) {
        selects[i].style.display = "";
    }
}


function $(s){
    return document.getElementById(s);
}

var sign = 0;
var tmp_url = "";
var tmp_title = "";
var tmp_msg = "";
function LoadMessageDiv(){
    document.write("<div id=\"hiddenDiv\" style=\"display:block;\"></div>");
    document.write("<div id=\"msgDiv\" style=\"display:none;\">");
    
    // document.write("<table id=\"msgTable\"><tr><td id=\"msgTitle\">title</td></tr><tr><td id=\"msgContent\">content</td></tr><tr><td id=\"btnBar\"></td></tr></table>");
    document.write("</div>");
    document.write();
    //
}

function ShowMessage(width, height){
    hidden_select();
    sign = 1;
    ishidden = 1;
    var hidDiv = document.getElementById("hiddenDiv");
    var messageDiv = document.getElementById("msgDiv");
    
    var bodyWidth = document.body.clientWidth;
    var bodyHeight = document.body.clientHeight;
    var navigatorName = "Microsoft Internet Explorer";
    
    if (navigator.appName == navigatorName) {
        bodyHeight = document.body.scrollHeight - document.body.clientTop;
        bodyHeight1 = document.documentElement.clientHeight + document.documentElement.scrollTop;//这里的是隐藏层的高
    }
    else {
        bodyHeight = document.documentElement.offsetHeight;
    }
    
    var pX = (bodyWidth - width) / 2;
    var pY = (document.body.clientHeight - messageDiv.offsetHeight) / 2 - 100
    
    hidDiv.style.display = "";
    hidDiv.style.height = document.body.clientHeight + document.body.scrollTop//bodyHeight;
    hidDiv.style.width = bodyWidth;
    
    messageDiv.style.height = height + "px";
    messageDiv.style.width = width + "px";
    messageDiv.style.display = "";
    
    messageDiv.style.left = pX;
    messageDiv.style.top = pY;
    //如果创建的窗口过高则需要重新定位
    if (pY + height > document.body.clientHeight) {
        rePos_messageDiv();
    }
    
}

function CloseDialog(){
    ishidden = 0
    var hidDiv = document.getElementById("hiddenDiv");
    var messageDiv = document.getElementById("msgDiv");
    messageDiv.style.display = "none";
    hidDiv.style.display = "none";
    
    var title = document.getElementById("msg_div");
    var p = title.parentNode;
    p.removeChild(title);
    
    show_select();
    //重新初始化类
    init();
}

function GoToUrl(url){
    return function(){
        document.location.href = url;
    }
}

function rePos_messageDiv(){
    if (ishidden == 1) {
		var bodyWidth = document.body.clientWidth;
        var bodyHeight = document.body.clientHeight;
        if (sign == 1 && bodyWidth > 200 && bodyHeight > 200) {
            var hidDiv = document.getElementById("hiddenDiv");
            var messageDiv = document.getElementById("msgDiv");
            
            var bodyWidth = document.body.clientWidth;
            var bodyHeight = document.body.clientHeight;
            var navigatorName = "Microsoft Internet Explorer";
            
            if (navigator.appName == navigatorName) {
                bodyHeight = document.body.scrollHeight - document.body.clientTop;
                bodyHeight1 = document.documentElement.clientHeight + document.documentElement.scrollTop;//这里的是隐藏层的高
            }
            else {
                bodyHeight = document.documentElement.offsetHeight;
            }
            hidDiv.style.display = "";
            hidDiv.style.height = document.body.clientHeight + document.body.scrollTop;//bodyHeight;
            hidDiv.style.width = bodyWidth;
            /*
             * //下面的消息框也会剧中
             *
             *
             var messageDiv = document.getElementById("msgDiv");
             var bodyWidth = document.body.clientWidth;
             
             var msgWidth = parseInt(messageDiv.style.width);
             var msgHeight = parseInt(messageDiv.style.height);
             var url = "";
             var title = "";
             var msg = "";
             
             var pX = (bodyWidth - msgWidth) / 2;
             var pY = document.body.scrollTop + (document.body.clientHeight - messageDiv.offsetHeight) / 2;
             ShowMessage(tmp_url, tmp_title, tmp_msg, msgWidth, msgHeight)
             messageDiv.style.left = pX;
             messageDiv.style.top = pY;
             */
        }
    }
}

function drag(o){

    o.onmousedown = function(a){
        var d = document;
        if (!a) 
            a = window.event;
        var x = a.layerX ? a.layerX : a.offsetX, y = a.layerY ? a.layerY : a.offsetY;
        //alert(x+"=========="+window.event.offsetX);
        if (o.setCapture) 
            o.setCapture();
        else 
            if (window.captureEvents) 
                window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
        //拖动标志
        if (dragswitch == 1) {
            d.onmousemove = function(a){
                if (!a) 
                    a = window.event;
                if (!a.pageX) 
                    a.pageX = a.clientX;
                if (!a.pageY) 
                    a.pageY = a.clientY;
                var tx = a.pageX - x, ty = a.pageY - y;
                o.style.left = tx;
                o.style.top = ty;
            };
        }
        d.onmouseup = function(){
            if (o.releaseCapture) 
                o.releaseCapture();
            else 
                if (window.captureEvents) 
                    window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
            d.onmousemove = null;
            d.onmouseup = null;
        };
    };
}

function start_dag(){
    dragswitch = 1;
    drag(document.getElementById('msgDiv'));
}

window.onscroll = rePos_messageDiv;
window.onresize = rePos_messageDiv;


function showTab(o,num){
	for(var i =1;i<=4;i++){
		document.getElementById("tab"+i).className="li";
		document.getElementById("show"+i).style.display="none";
	}
	document.getElementById("show"+num).style.display="";
	o.className="over";
}
function showBig(msg){
	//window.open("showImage.html");
	window.open ('showImg.htm?showImg='+msg, 'newwindow', 'height=600, width=650, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');
}
function showSelectMenu(){
	
}

