﻿// JScript 文件

var IMGPATH = '/';
var form = '';
var php_bgPicture = "orangebg.gif";
var php_arrow = "01.gif";
var php_bgColor = "#FF831F";
var objX = 0;
var objY = 0;
var bodyScrollWidth = 0;
var bodyScrollHeight = 0;
var screenAvailWidth = window.screen.availWidth;
var screenAvailHeight = window.screen.availHeight;

var bdMvEvt;
var bdUpEvt;

function recoverBodyEvent() {
    document.body.onmousemove = bdMvEvt;
    document.body.onmouseup = bdUpEvt;
}

if (navigator.appName.indexOf("Explorer") > -1) {//ie
    var exp = 1;
}
else {//for ff
    var exp = 2;
}
var layer = new Array();
var dragObj = new Array();
var dragObjId = new Array();

reCalBodySize();

function reCalBodySize() {
    bodyScrollWidth = document.documentElement.scrollWidth;
    bodyScrollHeight = document.documentElement.scrollHeight;
}
function checkAndResetStyleTop(obj) {
    var clientHeight = obj.firstChild.clientHeight;
    var styleTop = parseInt(obj.style.top.substring(0, obj.style.top.length - 2));
    if (clientHeight + styleTop > bodyScrollHeight) {
        obj.style.top = (bodyScrollHeight - clientHeight) + 'px';
    }
}


function set_div_style(obj, id, top, left, width, height, position, border, cursor, background) {
    var obj = obj;
    obj.id = id ? id : null;
    obj.style.top = top ? top : '0px';
    obj.style.left = left ? left : '0px';
    obj.style.width = width ? width : '0px';
    obj.style.height = height ? height : '0px';
    obj.style.position = position ? position : "static";
    obj.style.border = border ? border : "1px #000 solid";
    obj.style.cursor = cursor ? cursor : "default";
    obj.style.background = background ? background : "";
    return obj
}

function drag_mouse_down(event, obj) {
    var obj_left = obj.style.left;
    var obj_top = obj.style.top;
    var obj_left = obj_left.replace(/p|x/g, "");
    var obj_top = obj_top.replace(/p|x/g, "");
    if (event == null) {//IE必须
        event = window.event;
    }
    var clientX = String(event.clientX).replace(/p|x/g, "");
    var clientY = String(event.clientY).replace(/p|x/g, "");
    objX = clientX - obj_left;
    objY = clientY - obj_top;
}

function drag(event, obj) {
    if (objX != 0 && objY != 0) {
        if (event == null) {//IE必须
            event = window.event;
        }
        if (event.button == 1 || event.button == 0) {
            var objWidth = obj.firstChild.clientWidth;
            var objHeight = obj.firstChild.clientHeight;
            reCalBodySize();

            var leftPo = event.clientX - objX;
            if (leftPo < 0) {
                leftPo = 0;
            }
            if (leftPo > bodyScrollWidth - objWidth) {
                leftPo = bodyScrollWidth - objWidth;
            }

            var topPo = event.clientY - objY;
            if (topPo < 0) {
                topPo = 0;
            }
            if (topPo > bodyScrollHeight - objHeight) {
                topPo = bodyScrollHeight - objHeight;
            }
            obj.style.left = leftPo + 'px';
            obj.style.top = topPo + 'px';
        }
    }
}

function GetLength(strTemp) {
    var i, sum;
    sum = 0;
    for (i = 0; i < strTemp.length; i++) {
        if ((strTemp.charCodeAt(i) >= 0) && (strTemp.charCodeAt(i) <= 255))
            sum = sum + 1;
        else
            sum = sum + 2;
    }
    return sum;
}

function subStringPro(str, length) {
    var stri = '';
    for (i = 0, j = 0; j < length; ) {
        if ((str.charCodeAt(i) >= 0) && (str.charCodeAt(i) <= 255)) {
            stri += str.charAt(i);
            j++;
        } else {
            stri += str.charAt(i);
            j += 2;
        }
        i++;
    }
    return stri;
}

//*********************
//隐藏元素
function HideElement(strElementTagName) {
    try {
        for (i = 0; i < window.document.all.tags(strElementTagName).length; i++) {
            var objTemp = window.document.all.tags(strElementTagName)[i];
            objTemp.style.visibility = "hidden";
        }
    } catch (e) {
        alert(e.message);
    }
}

//显示元素
function ShowElement(strElementTagName) {
    try {
        for (i = 0; i < window.document.all.tags(strElementTagName).length; i++) {
            var objTemp = window.document.all.tags(strElementTagName)[i];
            objTemp.style.visibility = "visible";
        }
    } catch (e) {
        alert(e.message);
    }
}

function hideElementAll() {
    HideElement("SELECT");
    HideElement("OBJECT");
    HideElement("IFRAME");
}

function showElementAll() {
    ShowElement("SELECT");
    ShowElement("OBJECT");
    ShowElement("IFRAME");
}
//滤镜效果
function hide() {
    synSizeByBody("globalDiv");
    document.getElementById("globalDiv").style.display = "block";
    if (1 == exp) {
        hideElementAll();
    }
}

function cancel() {
    document.getElementById("globalDiv").style.display = "none";
    if (1 == exp) {
        showElementAll();
    }

    recoverBodyEvent();
}
function buildGlobalDiv() {
    var globalDiv = document.createElement('div');
    globalDiv.id = 'globalDiv';
    globalDiv.style.display = 'none';
    globalDiv.style.zIndex = '98';
    globalDiv = set_div_style(globalDiv, 'globalDiv', '0px', '0px', bodyScrollWidth + 'px', bodyScrollHeight + 'px', "absolute", " #333333 0px solid", "default", "darkgray");

    if (1 == exp) {
        globalDiv.style.filter = "alpha(opacity=30)";
    }
    else {
        globalDiv.style.opacity = 30 / 100;
    }
    document.body.appendChild(globalDiv);
}
function synSizeByBody() {
    reCalBodySize();
    var argArr = synSizeByBody.arguments;
    for (var i = 0; i < argArr.length; i++) {
        if (document.getElementById(argArr[i]) != null) {
            document.getElementById(argArr[i]).style.width = (bodyScrollWidth) + 'px';
            document.getElementById(argArr[i]).style.height = (bodyScrollHeight) + 'px';
        }
    }
}
//将悬浮层的位置定位在body可见区域中央
function GetCenterXY_ForLayer(objdiv) {
    objdiv.style.display = 'block';
    var styleWidth = objdiv.style.width.substring(0, objdiv.style.width.length - 2);
    var clientHeight = objdiv.firstChild.clientHeight;
    var objLeft = parseInt(document.documentElement.scrollLeft + (document.documentElement.clientWidth - styleWidth) / 2) + 'px';
    var relTop = (document.documentElement.clientHeight - clientHeight) / 2 > 0 ? (document.documentElement.clientHeight - clientHeight) / 2 : 0;
    var objTop = parseInt(document.documentElement.scrollTop + relTop) + 'px';
    objdiv.style.top = objTop;
    objdiv.style.left = objLeft;
    checkAndResetStyleTop(objdiv);
}
//************************************************************
function $(str) {//通过对象ID返回对象
    if (typeof str == 'string' && document.getElementById(str) != null) {
        return document.getElementById(str);
    }
    return false;
}

function buildDiv() {
    var argArr = buildDiv.arguments;

    //定义层需要的初始字串变量
    var mainTable = '';

    for (var i = 0; i < argArr.length; i++) {
        //求出其相应的TABLE
        switch (argArr[i]) {
            case 'divCircle': mainTable = iniCircle(); break;
            case 'divCosrType': mainTable = iniCosrType(); break;
            case 'divCosrType1': mainTable = iniCosrType1(); break;
            case 'divRegion': mainTable = iniRegion(); break;
            case 'divRegion1': mainTable = iniRegion1(); break;
            case 'divPosType': mainTable = iniPosType(); break;
            case 'divPosType1': mainTable = iniPosType1(); break;
            case 'divPosMult': mainTable = iniPosMult(); break;
            case 'divCosrMult': mainTable = iniCosrMult(); break;
            case 'divRegionMult': mainTable = iniRegionMult(); break;
            default: return false;
        }
        dragObjId[i] = argArr[i];
        layer[i] = document.createElement("div");
        layer[i].style.visibility = 'hidden';
        layer[i].style.zIndex = '999';
        layer[i].innerHTML += mainTable;
        document.body.appendChild(layer[i]);

        var styleWidth = layer[i].firstChild.width + 'px';
        var styleHeight = layer[i].firstChild.firstChild.clientHeight + 'px';
        var layerId = argArr[i];

        layer[i] = set_div_style(layer[i], layerId, '0px', '0px', styleWidth, '0px', "absolute", "0px solid #c0d4db", "default", "#fff");
        dragObj[i] = layer[i].firstChild.firstChild.firstChild.firstChild;
        dragObj[i].style.cursor = 'move';

        dragObj[i].onmousedown = function(event) { drag_mouse_down(event, this.parentNode.parentNode.parentNode.parentNode) };

        layer[i].onselectstart = function() { return false };

        if (1 == exp) {
            layer[i].firstChild.onresize = function() { checkAndResetStyleTop(this.parentNode) };
        }
        else {
            layer[i].firstChild.onclick = function() { checkAndResetStyleTop(this.parentNode) };
        }
    }
}

function hiddenLayerOther(layerID) {
    for (var i = 0; i < dragObjId.length; i++) {
        if (dragObjId[i] != layerID && document.getElementById(dragObjId[i]) != null) {
            hiddenLayer(dragObjId[i]);
        }
    }
}

function displayLayer(layerID) {
    if (document.getElementById(layerID) != null) {
        var dv = document.getElementById(layerID);
        hiddenLayerOther(layerID);
        if (dv.style.visibility == "hidden") {
            GetCenterXY_ForLayer(dv);
            dv.style.visibility = "visible";
        }
        document.body.onmousemove = function(event) { drag(event, dv) };
        document.body.onmouseup = function() { objX = 0; objY = 0 };
    }
    return false;
}

function hiddenLayer() {
    var argArr = hiddenLayer.arguments;
    for (var i = 0; i < argArr.length; i++) {
        if (document.getElementById(argArr[i]) != null) {
            document.getElementById(argArr[i]).style.visibility = "hidden";
        }
    }
}
