﻿//럭스틸 마이크로팝업 활성 함수(2012.02.20 손아영)
function OpenWeb(_url, _name, _height, _width, _scrollbars, _resizable, _status, _toolbar, _Menubar, _location) {
        var x = window.screen.availWidth;
        var y = window.screen.availHeight;
        var height = (_height?_height:y);    
        var width = (_width?_width:800);
        var iL = (x - width) / 2;
        var iT = (y > 600 ? (y - height) / 2 : 0);
        var _tarurl = _url ? _url : "about:blank";
        var _tarname = _name ? _name : "newWin";
        var _Opts = '';
        _Opts = _Opts + 'left='+iL;
        _Opts = _Opts + ',top='+iT;
        _Opts = _Opts + ',height='+height;
        _Opts = _Opts + ',width='+width;
        _Opts = _Opts + ',scrollbars='+(_scrollbars?_scrollbars:'no');
        _Opts = _Opts + ',status='+(_status?_status:'no');
        _Opts = _Opts + ',toolbar='+(_toolbar?_toolbar:'no');
        _Opts = _Opts + ',Menubar='+(_Menubar?_Menubar:'no');
        _Opts = _Opts + ',location='+(_location?_location:'no');
        _Opts = _Opts + ',resizable='+(_resizable?_resizable:'no');

        var newWin = window.open(_tarurl, _tarname, _Opts, false);
        newWin.focus();
        return newWin;
}

$(document).ready(function () {
    // 사이트 이동
    $("#goSite").change(function () {
        if ($(this).val()) window.open($(this).val());
    });
    // 페이지 사이즈 변경
    $("#pagesize, #spart, #slang").change(function () {
        js_goSearch();
    });
    $("#searchBtn").click(function () {
        if ($("#stxt").val() == "검색어를 입력하세요") {
            alert("검색어를 입력하세요");
            $("#stxt").val("").focus();
        } else {
            js_goSearch();
        }
    });
    // 검색어 포커스
    $("#stxt").focus(function () {
        js_setSearchTxt();
    });
    if ($("#pagesize[pagesize]").length > 0) $("#pagesize").val($("#pagesize").attr("pagesize"));
    if ($("#spart[spart]").length > 0) $("#spart").val($("#spart").attr("spart"));
    if ($("#sdvn[sdvn]").length > 0) $("#sdvn").val($("#sdvn").attr("sdvn"));
    if ($("#blang[blang]").length > 0) $("#blang").val($("#blang").attr("blang"));
    if ($("#slang[slang]").length > 0) $("#slang").val($("#slang").attr("slang"));
    js_intSearchTxt();
    // 전체 선택
    $("#allSelectBtn").click(function () {
        if ($(this).val() == "전체 선택") {
            $(".idxs").attr("checked", true);
            $(this).val("전체 해제");
        } else {
            $(".idxs").attr("checked", false);
            $(this).val("전체 선택");
        }
    });
    // 숨겨진 필드 필수 빼기
    $(".hide2 .required").removeClass("required");
    $(".hide .required").removeClass("required");
    // 달력
    if ($(".dt").length > 0) {
        $(".dt").datepicker({ dateFormat: 'yy-mm-dd', dayNamesMin: ['일', '월', '화', '수', '목', '금', '토']
            , monthNames: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월']
            , buttonImage: '/_css/themes/base/images/calendar.gif'
            , showOn: "button"
        });
    }
    //재무정보 변경
    $("#bpartcode").change(function () {
        if ($(this).val() == "FNC01") {
            $(".FNC01").show();
            $(".FNC02").hide();
        } else if ($(this).val() == "FNC02") {
            $(".FNC01").hide();
            $(".FNC02").show();
        }
    });
    if ($("#bpartcode[bpartcode]").length > 0) {
        $("#bpartcode").val($("#bpartcode").attr("bpartcode"));
        $("#bpartcode").change();
    }

    $("td.bpartcode").each(function () {
        var bptcd = $(this).attr("bpartcode");
        if (!bptcd) bptcd = $(this).text();
        $(this).text($("option[value=" + bptcd + "]").text());
    });

    // tabMenu
    $("ul.tabMenu1 li .tab a").click(function () {
        $("ul.tabMenu1 li .tab a img").each(function () {
            var THIS_SRC = $(this).attr("src").replace("_on", "_off");
            $(this).attr("src", THIS_SRC);
        });
        $(".lists > div").hide();
        var THIS_SRC = $(this).find("img").attr("src").replace("_off", "_on");
        $(this).find("img").attr("src", THIS_SRC);

        var showClass = $("ul.tabMenu1 li .tab a").index(this) + 1; // $(this).parent().attr("id"); //
        $(".layer" + showClass).show();
        return false;
    });

    // 국내사업장 프린트
    $('.mapPrint').click(function () {
        window.print();
    });


    $("ul.tabMenu1 li .tab a:eq(" + location.hash.substring(1) + ")").click();

    // title 지정하기
    $(document).attr("title", "유니온스틸");
});

function js_setLocation() {
    $("#locationInfor .pageLocation span:eq(0)").text($(".globalNavigation .on").text());
    $("#locationInfor .pageLocation strong:eq(0)").text($("#navigationArea .on").text());
    $("#contentAera h3:eq(0)").text($("#navigationArea .on").text());
}

// 검색어 초기화
function js_setSearchTxt() {
    if ($("#stxt").val() == "검색어를 입력하세요") {
        $("#stxt").val("");
    }
}
function js_intSearchTxt() {
    if ($("#stxt").val() == "") {
        $("#stxt").val("검색어를 입력하세요");
    }
}
// 검색 하기
function js_goSearch() {
    js_setSearchTxt();
    $("#page").val(1);
    document.sfrm1.submit();
}
// 파일 엘리먼트 추가 삭제
function js_addFile(obj) {
    $("li.minusfile:hidden").clone().appendTo($(obj).closest("li").parent()).removeClass("hide2");
    return false;
}
function js_minusObj(obj) {
    $(obj).closest("li").remove();
}
// 전역 파라미터 변수
var PARAMS;
// 파라미터 포함 페이지 이동
function js_movePage(gourl) {
    var rtn = js_setParams();
    location.href = gourl + "?" + rtn;
}
// 전역 파라미터 변수 처리
function js_setParams() {
    var tmp = PARAMS.replace("{", ""), tmp2="", tmparr, tmparr2;
    tmp = tmp.replace("}", "");
    tmparr = tmp.split(",");
    for (i = 0; i < tmparr.length; i++) {
        tmparr2 = tmparr[i].split("=");
        if (tmparr2[1].trim()) {
            tmp2 += "&" + tmparr2[0].trim() + "=" + tmparr2[1].trim();
        }
    }

    return tmp2.substr(1);
}
//전역기능
String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.replaceAll = function (str1, str2) {
    var temp_str = "";

    if (this.trim() != "" && str1 != str2) {
        temp_str = this.trim();

        while (temp_str.indexOf(str1) > -1) {
            temp_str = temp_str.replace(str1, str2);
        }
    }

    return temp_str;
}

// UNIONSTEEL IN LIFE/ 생산공정 팝업 가운데 오픈
function windowopen(href) {
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();

    var top = (windowHeight / 2) - (710 / 2);
    var left = (windowWidth / 2) - (990 / 2);

    window.open(href, 'unionQuick', 'width=990,height=710, top=' + top + ', left=' + left + '');
    return false;
}

// UNIONSTEEL IN LIFE/ 생산공정 팝업 가운데 오픈
function windowfullopen(href) {
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();

    window.open(href, 'Luxteel', 'fullscreen');
    return false;
}


// 상단플레시 메뉴에 따른 리사이즈
function gnbHeight(size) {
    $(".gnb_main").css("height", size);
    $("#flashContent object").attr("height", size);
}
