var idarr = new Array(), displayL, frameL, backgroundL, imageL, previewSL = false, iE = false;

/*@cc_on
    @if(@_jscript) {iE = @_jscript_build;}
@end @*/

if(iE) {
    function getActiveX() {
        try {var aX = new ActiveXObject('Shell.UIHelper');} catch(e) {return false;}
        return true;
    }
}

function removeDouble(arr) {
    var newarr = new Array();
    var exist  = false;
    var i, j;
    for(i = 0; i < arr.length; i++) {
        exist = false;
        for(j = 0; j < newarr.length; j++) {
            if(arr[i] == newarr[j]) {exist = true;}
        }
        if(exist == false) {newarr.push(arr[i]);}
    }
    return newarr;
}

function numSort(i,j) {
    return i-j;
}

function remove(arr) {
    var inarr = 'no';
    var i;
    for(i = 0; i < idarr.length; i++) {
        if(idarr[i] == arr) {inarr = i;}
    }
    if(inarr != 'no') {idarr.splice(inarr, 1);}
}

function actionView() {
    var i, j;
    var divL = document.getElementsByTagName('div');
    var liL = document.getElementsByTagName('li');
    if(!idarr.length) {
        for(i = 0; i < divL.length; i++) {
            if(divL[i].className == 'action-select-active') {
                divL[i].className = 'action-select-off';
                for(j = 0; j < divL[i].childNodes.length; j++) {
                    if(divL[i].childNodes[j].tagName == 'SELECT') {divL[i].childNodes[j].disabled = 'disabled';}
                    if(divL[i].childNodes[j].className == 'btn')  {imgOff(divL[i].childNodes[j].firstChild);}                    
                }
            }
        }
        for(i = 0; i < liL.length; i++) {
            if(liL[i].className == 'min1' || liL[i].className == 'jus1') {liL[i].style.display = 'none';}             
            if(liL[i].className == 'min1-off' || liL[i].className == 'jus1-off') {liL[i].style.display = 'block';}            
        }        
    } else {
        for(i = 0; i < divL.length; i++) {
            if(divL[i].className == 'action-select-off') {
                divL[i].className = 'action-select-active';
                for(j = 0; j < divL[i].childNodes.length; j++) {
                    if(divL[i].childNodes[j].tagName == 'SELECT') {divL[i].childNodes[j].disabled = '';}
                    if(divL[i].childNodes[j].className == 'btn')  {imgOn(divL[i].childNodes[j].firstChild);}
                }
            }
        }
        for(i = 0; i < liL.length; i++) {
            if(idarr.length > 1) {
                if(liL[i].className == 'jus1' || liL[i].className == 'min1-off') {liL[i].style.display = 'none';}
                if(liL[i].className == 'min1' || liL[i].className == 'jus1-off') {liL[i].style.display = 'block';}        
            } else {
                if(liL[i].className == 'jus1-off' || liL[i].className == 'min1-off') {liL[i].style.display = 'none';}
                if(liL[i].className == 'jus1' || liL[i].className == 'min1') {liL[i].style.display = 'block';}             
            }
        }
    }
}

function selectOver(ref) {
    ref.className = 'checkbox hover';
}

function selectOut(ref) {
    ref.className = 'checkbox';
}

function itemOver(ref) {
    var i;
    if(ref.className != 'selected') {
        for(i = 0; i < ref.childNodes.length; i++) {
            if(ref.childNodes[i].tagName == 'DIV') {ref.childNodes[i].className = 'select-show';}
        }
    }
}

function itemOut(ref) {
    var i;
    if(ref.className != 'selected') {
        for(i = 0; i < ref.childNodes.length; i++) {
            if(ref.childNodes[i].tagName == 'DIV') {ref.childNodes[i].className = '';}
        }
    }
}

function selectOne(ref, inputId) {
    var i;
    var li = document.getElementById(ref);
    var id = li.id + '-';
    var ul = li.parentNode;
    idarr = [];
    id = id.substring(id.indexOf('-') + 1, id.lastIndexOf('-'));
    id = parseInt(id);
    idarr.push(id);
    for(i = 0; i < ul.childNodes.length; i++) {
        if(ul.childNodes[i].tagName == 'LI') {
            if(ul.childNodes[i].id == li.id) {li.className = 'selected';}
                                        else {ul.childNodes[i].className = '';}
        }
    }
    if(inputId) {document.getElementById(inputId).value = id;}
}

function selectSome(ref) {
    var li = ref.parentNode;
    var id = li.id + '-';
    id = id.substring(id.indexOf('-') + 1, id.lastIndexOf('-'));
    id = parseInt(id);
    idarr.push(id);
    idarr = removeDouble(idarr);
    if(li.className == '') {li.className = 'selected';}
    else {
        li.className = '';
        remove(id);
    }
    actionView();
}

function selectAll(ul) {
    var id;
    idarr = [];
    ul = document.getElementById(ul);
    for(var i = 0; i < ul.childNodes.length; i++) {
        if(ul.childNodes[i].tagName == 'LI') {
            id = ul.childNodes[i].id + '-';
            id = id.substring(id.indexOf('-') + 1, id.lastIndexOf('-'));
            id = parseInt(id);
            idarr.push(id);
            ul.childNodes[i].className = 'selected';
        }
    }
    actionView();
}

function selectNone(ul) {
    var i;
    idarr = [];
    ul    = document.getElementById(ul);
    for(i = 0; i < ul.childNodes.length; i++) {
        if(ul.childNodes[i].tagName == 'LI') {ul.childNodes[i].className = '';}
    }
    actionView();
}

function copySelected(idprefix, id, sendTo) {
    var data = '';
    var li, i;
    var numberofselected = 0;
    idarr.sort(numSort);
    for(i = 0; i < idarr.length; i++) {
        if(document.getElementById(idprefix + idarr[i]).className == 'selected') {
            if (numberofselected > 0) {data += ';';}
            data += idarr[i];
            numberofselected++;
        }
    }
    if(data != '') {document.getElementById(id).value = data;}
    if(sendTo)     {document.getElementById(sendTo).submit();}
}


function readCookie(cValue) {
    var cookies   = '' + document.cookie;
    var cookiePos = cookies.indexOf(cValue);
    var cookieStr = '';
    if(cookiePos != -1) {
        var cookieStart = cookiePos + cValue.length;
        var cookieEnd   = cookies.indexOf(';', cookieStart);
        if(cookieEnd == -1) {cookieEnd = cookies.length;}
        cookieStr = cookies.substring(cookieStart, cookieEnd);
        return cookies.substring(cookieStart, cookieEnd);
    } else {return '';}
}

function writeCookie(cValue, cContent, cExpire) {
    if(cExpire) {
        var nextYear = new Date();
        nextYear.setFullYear(nextYear.getFullYear() + 1);
        document.cookie = cValue + cContent + '; expires=' + nextYear.toGMTString();
    } else {document.cookie = cValue + cContent + ';';}
}

function imagePreview(styleId, imgSrc, node) {
    var omg = document.getElementById(styleId);
    var img;
    if(omg) {omg.parentNode.removeChild(omg);}
    if(imgSrc) {
        img = document.createElement('img');
        img.id  = styleId;
        img.src = imgSrc;
        if(node && !document.all) {node.appendChild(img);}
                             else {document.body.appendChild(img);}
        if(document.all) {
            img.style.position = 'absolute';
            img.style.left     = (event.clientX + 15) + 'px';
            img.style.top	   = (event.clientY - 65) + 'px';
        }
    } else {
        img = document.getElementById(styleId);
        if(img) {img.parentNode.removeChild(img);}
    }
}

function imgOver(img) {
    _imgSwitch(img, /_up./, '_over.');
}

function imgOut(img) {
    _imgSwitch(img, /_over./, '_up.');
}

function imgOn(img) {
    _imgSwitch(img, /_off./, '_up.');
    img.className = img.className.replace(' cursor-default', '');
    img.className = img.className.replace('cursor-default', '');
}

function imgOff(img) {
    _imgSwitch(img, /_up./, '_off.');
    img.className += ' cursor-default';
}

function _imgSwitch(img, oPsx, nPsx) {
    if(img.src.search(/blank.gif/) > 0) {img.style.filter = img.style.filter.replace(oPsx, nPsx);}
                                   else {img.src = img.src.replace(oPsx, nPsx);}
}

function imgFitResizeById(imgId, w, h, c, outerElemId, rot) {
    var tW, tH, mL, mT;
    var img = document.getElementById(imgId);
    var out = document.getElementById(outerElemId);
    if(rot == 90 || rot == 270) {
        t = w;
        w = h;
        h = t;
    }    
    if(img) {
        if(h > w) {
            if(c) {
                if((w / h) <= (maxCP[0] / maxCP[1])) {
                    tH = maxCP[1];
                    tW = w / (h / maxCP[1]);
                    mL = (maxCP[0] - tW.toFixed(0)) / 2 + 'px';
                } else {
                    tW = maxCP[0];
                    tH = h / (w / maxCP[0]);
                    mT = (maxCP[1] - tH.toFixed(0)) / 2 + 'px';
                }
            } else {
                if((w / h) <= (maxIP[0] / maxIP[1])) {
                    tH = maxIP[1];
                    tW = w / (h / maxIP[1]);
                    mL = (maxIP[0] - tW.toFixed(0)) / 2 + 'px';
                } else {
                    tW = maxIP[0];
                    tH = h / (w / maxIP[0]);
                    mT = (maxIP[1] - tH.toFixed(0)) / 2 + 'px';
                }
            }
        } else {
            if(c) {
                if((w / h) >= (maxCL[0] / maxCL[1])) {
                    tW = maxCL[0];
                    tH = h / (w / maxCL[0]);
                    mT = (maxCL[1] - tH.toFixed(0)) / 2 + 'px';
                } else {
                    tH = maxCL[1];
                    tW = w / (h / maxCL[1]);
                    mL = (maxCL[0] - tW.toFixed(0)) / 2 + 'px';
                }
            } else {
                if((w / h) >= (maxIL[0] / maxIL[1])) {
                    tW = maxIL[0];
                    tH = h / (w / maxIL[0]);
                    mT = (maxIL[1] - tH.toFixed(0)) / 2 + 'px';
                } else {
                    tH = maxIL[1];
                    tW = w / (h / maxIL[1]);
                    mL = (maxIL[0] - tW.toFixed(0)) / 2 + 'px';
                }
            }
        }
        img.style.width = tW.toFixed(0) + 'px';
        img.style.height = tH.toFixed(0) + 'px';
        if(out) {img = out;}
        if(mL)  {img.style.marginLeft = mL;}
        if(mT)  {img.style.marginTop  = mT;}
    }
}


if(iE >= 8513) {
    var fixADoneC = 0;
    var fixAIntvl = setInterval('fixAlphaPNG()', 10);

    function fixAlphaPNG() {
        var i, w, h, tempImgCount = document.images.length;
        for(i = fixADoneC; i < tempImgCount; i++) {
            fixADoneC = tempImgCount;
            var img = document.images[i];
            var imgName = img.src.toUpperCase();
            if(imgName.substring(imgName.length - 3, imgName.length) == 'PNG' && img.className.search('noAlpha') < 0) {
                if(img.width > 0 || img.height > 0) {
                    w = img.width;
                    h = img.height;
                }
                img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'  + img.src + '", sizingMethod="scale")';
                img.src = blankGIF;
                if(img.width > 0 || img.height > 0) {
                    img.width = w;
                    img.height = h;
                }
            }
        }
    }

    function completeFixAlphaPNG() {
        clearInterval(fixAIntvl);
        fixADoneC = 0;
        fixAlphaPNG();
    }

    window.attachEvent('onload', completeFixAlphaPNG);
}

function imgReplace(id, prx, diff, psx) {
    var img  = document.getElementById(id);
    var imgS = img.src;
    if(iE >= 8513) {imgS = img.style.filter;}
    img.src = imgS.substring(0, imgS.lastIndexOf(prx) + prx.length) + diff + psx;
    if(iE >= 8513) {
        img.style.filter = img.src;
        img.src = blankGIF;
    }
}