﻿$(document).ready(function() {

    $('div[id^=Err]').hide();
    InputCustomEmail();
    InputCustomEmail2();

    $('tr[id*=Down').hide();
    $('#tr_Down').hide();
    $('#tr_Down2').hide();
    $('#tr_Result').hide();


    //$('div[id^=Err]').css("color", "red");

});

function ChkApply() {  //신청서 유효성

    //약관동의
    var chkAgree = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_chkAgree');

    if (chkAgree.checked == false) {

        $('#Err_Agreement').fadeIn(1000);
        $('#Err_Agreement').fadeOut(1000);
        return false;
    }
    //회사명
    var txtCompany = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtCompany').val();

    if (txtCompany.length == 0) {

        $('#Err_Company').fadeIn(1000);
        $('#Err_Company').fadeOut(1000);
        return false;
    }
    //사업자번호
    var BusinessNo1 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo1').val();
    var BusinessNo2 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo2').val();
    var BusinessNo3 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo3').val();

    if (BusinessNo1.length != 3 || BusinessNo2.length != 2 || BusinessNo3.length != 5 || isNaN(BusinessNo1) || isNaN(BusinessNo2) || isNaN(BusinessNo3)) {
        $('#Err_BusinessNo').fadeIn('slow');
        $('#Err_BusinessNo').fadeOut('slow');
        return false;
    }
    var regnum = BusinessNo1 + BusinessNo2 + BusinessNo3;
    if (!Check_Busino(regnum)) {
        $('#Err_BusinessNo').fadeIn('slow');
        $('#Err_BusinessNo').fadeOut('slow');
        return false;
    }
    
    //대표자
    var txtPresident = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtPresident').val();

    if (txtPresident.length == 0) {

        $('#Err_President').fadeIn(1000);
        $('#Err_President').fadeOut(1000);
        return false;
    }
    //업태
    var txtStatus = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtStatus').val();

    if (txtStatus.length == 0) {

        $('#Err_Status').fadeIn(1000);
        $('#Err_Status').fadeOut(1000);
        return false;
    }
    //종목
    var txtType = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtType').val();

    if (txtType.length == 0) {

        $('#Err_Type').fadeIn(1000);
        $('#Err_Type').fadeOut(1000);
        return false;
    }
    //소재지
    var txtAddress = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtAddress').val();

    if (txtAddress.length == 0) {

        $('#Err_Address').fadeIn(1000);
        $('#Err_Address').fadeOut(1000);
        return false;
    }
    //전화번호
    var txtTel1 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtTel1').val();
    var txtTel2 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtTel2').val();
    var txtTel3 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtTel3').val();

    if (txtTel1.length == 0 || txtTel1 < 0 || txtTel1.length > 4 || txtTel1.length < 2 || txtTel2.length == 0 || txtTel2 < 0 || txtTel2.length > 4 || txtTel2.length < 3 || txtTel3.length == 0 || txtTel3.length != 4 || isNaN(txtTel1) || isNaN(txtTel2) || isNaN(txtTel3)) {

        $('#Err_Tel').fadeIn('slow');
        $('#Err_Tel').fadeOut('slow');

        return false;
    }
    //담당자
    var txtName = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtName').val();

    if (txtName.length == 0) {

        $('#Err_Name').fadeIn(1000);
        $('#Err_Name').fadeOut(1000);
        return false;
    }
    //휴대폰
    var txtCp2 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtCp2').val();
    var txtCp3 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtCp3').val();

    if (txtCp2.length == 0 || txtCp2.length > 4 || txtCp2.length < 3 || txtCp3.length == 0 || txtCp3.length != 4 || isNaN(txtCp2) || isNaN(txtCp3)) {

        $('#Err_CellPhone').fadeIn('slow');
        $('#Err_CellPhone').fadeOut('slow');

        return false;
    }
    //이메일
    var txtEmail = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtEmail').val();
    var txtEmailInput = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtEmailInput').val();
    var drEmail = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_drEmail').val();

    if (txtEmail.length == 0) {

        $('#Err_Email').fadeIn(1000);
        $('#Err_Email').fadeOut(1000);
        return false;
    }

    if (drEmail == "Input") {

        if (txtEmailInput.length == 0) {

            $('#Err_Email').fadeIn(1000);
            $('#Err_Email').fadeOut(1000);
            return false;
        }
    }

    //이메일 체크
    if (drEmail == "Input") {
        var Eamil = txtEmail + "@" + txtEmailInput;
    } else {
        var Eamil = txtEmail + "@" + drEmail;
    }

    if (email_chk(Eamil) == false) {
        $('#Err_Email').fadeIn(1000);
        $('#Err_Email').fadeOut(1000);
        return false;
    }

}
//사업자 번호 중복 확인시 체크
function CheckBusinessNo() {
    var BusinessNo1 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo1').val();
    var BusinessNo2 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo2').val();
    var BusinessNo3 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo3').val();

    if (BusinessNo1.length != 3 || BusinessNo2.length != 2 || BusinessNo3.length != 5 || isNaN(BusinessNo1) || isNaN(BusinessNo2) || isNaN(BusinessNo3)) {
        $('#Err_BusinessNo').fadeIn('slow');
        $('#Err_BusinessNo').fadeOut('slow');
        return false;
    }
    var regnum = BusinessNo1 + BusinessNo2 + BusinessNo3;
    if (!Check_Busino(regnum)) {
        $('#Err_BusinessNo').fadeIn('slow');
        $('#Err_BusinessNo').fadeOut('slow');
        return false;
    }
}
//신청시 이메일 직접 입력
function InputCustomEmail() {
    var drEmail = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_drEmail').val();

    if (drEmail == "Input") {
        $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtEmailInput').show();
    } else {
        $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtEmailInput').hide();
    }
}
//다운로드 및 계약서 프린트시
function ChkAgreement() {
    //약관
    var chkAgree = document.getElementById('ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_chkAgree');

    if (chkAgree.checked == false) {

        $('#Err_Agreement').fadeIn(1000);
        $('#Err_Agreement').fadeOut(1000);
        return false;
    }
    //사업자 번호
    var BusinessNo1 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo4').val();
    var BusinessNo2 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo5').val();
    var BusinessNo3 = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtBusinessNo6').val();

    if (BusinessNo1.length != 3 || BusinessNo2.length != 2 || BusinessNo3.length != 5 || isNaN(BusinessNo1) || isNaN(BusinessNo2) || isNaN(BusinessNo3)) {
        $('#Err_BusinessNo').fadeIn('slow');
        $('#Err_BusinessNo').fadeOut('slow');
        return false;
    }
    //이메일
    var txtEmail = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtEmail2').val();

    if (txtEmail.length == 0) {

        $('#Err_Email').fadeIn(1000);
        $('#Err_Email').fadeOut(1000);
        return false;
    }

    var drEmail = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_drEmail2').val();

    if (drEmail == "Input") {
        var txtEmailInput = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtEmailInput2').val();

        if (txtEmailInput.length == 0) {

            $('#Err_Email').fadeIn(1000);
            $('#Err_Email').fadeOut(1000);
            return false;
        }
    }

    //이메일 체크
    if (drEmail == "Input") {
        var Eamil = txtEmail + "@" + txtEmailInput;
    } else {
        var Eamil = txtEmail + "@" + drEmail;
    }

    if (email_chk(Eamil) == false) {
        $('#Err_Email').fadeIn(1000);
        $('#Err_Email').fadeOut(1000);
        return false;
    }
}
//폰트 다운로드시 이메일 직접 입력
function InputCustomEmail2() {
    var drEmail = $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_drEmail2').val();

    if (drEmail == "Input") {
        $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtEmailInput2').show();
    } else {
        $('#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_txtEmailInput2').hide();
    }
}

//이메일 유효성 검사
function email_chk(obj) {
    var regExp = /[a-z0-9]{2,}@[a-z0-9-]{2,}\.[a-z0-9]{2,}/i;

    if (!regExp.test(obj)) {

        return false;
    }
}

/*PrintContract*/
function fnPostBackPopUp(windowName, actionUrl, vWidth, vHeight) {
    var wForm = ViewCenterPop(actionUrl, windowName, vWidth, vHeight, 'yes', 'no', 'no', 'no', 'no');
    wForm.focus();

    return false;
}

function ViewCenterPop(url, pn, w, h, s, r, tb, mb, st) {
    window.status = '';
    var winleft = (screen.width - w) / 2;
    var wintop = (screen.height - h) / 2;
    var wForm = window.open(url, pn, 'toolbar=' + tb + ',menubar=' + mb + ',scrollbars=' + s + ',top=' + wintop + ',left=' + winleft + ',width=' + w + ',height=' + h + ',status=yes,resizable=' + r + '');
    return wForm;
}

/*DownLoad.aspx*/
function chkValue() {
    document.getElementById("btnDownload").style.display = "none";
    try {
        var val = opener.document.getElementById("ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_hdNum").value;

        if (val != null) {
            document.getElementById("btnDownload").style.display = "inline";
        }
    } catch (e) {
        alert("잘못된 접근입니다.");
    }
}
/*DistributeExt.aspx*/
function Close() {
    window.close();
}

function FontDownLoad() {
    var SendValue = $("#ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_hd_authorization").val();

    fnPostBackPopUp('download', 'DownLoad.aspx?authorization=' + SendValue, '680', '372')
}

/*웹페이지 프린트 관련*/
var initBody;
function beforePrint() {
    boxes = document.body.innerHTML;
    document.body.innerHTML = box.innerHTML;
}

function afterPrint() {
    document.body.innerHTML = boxes;
}

function Print() {
    window.print();
}

window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;

