﻿// JScript File
// D.Darkhanbaatar 2008.01.23

var CalcControl;
var Disable;
var _TabIndex = 4;
var StepIndex = ""; //Card сунгах дээр давхрагын нэр
var Step1 = "";
var Step2 = "";
var Step3 = "";
var StepHome = "";
var StepPost = "";
var StepSalbar = "";
var StepBack = "";
var StepNext = "";
var StepFinish = "";
var OptPost = "";
var OptHome = "";
var OptSalbar = "";
var OptAgree = "";


/* Үсэг солих*/
var Ansii = new Array(229, 249, 244, 246, 243, 230, 253, 237, 227, 248, 191, 231, 234, 250, 233, 251, 225, 186,
                         224, 245, 240, 238, 235, 228, 239, 255, 247, 184, 241, 236, 232, 242, 252, 226, 254,
                         197, 217, 212, 214, 211, 198, 221, 205, 195, 216, 175, 199, 202, 218, 201, 219, 193, 170,
                         192, 213, 208, 206, 203, 196, 207, 223, 215, 168, 209, 204, 200, 210, 220, 194, 222,
                         1198, 1199, 1256, 1257);
var UniCode = new Array(1077, 1097, 1092, 1094, 1091, 1078, 1101, 1085, 1075, 1096, 118, 1079, 1082, 1098, 1081, 1099, 1073, 1108,
                           1072, 1093, 1088, 1086, 1083, 1076, 1087, 1103, 1095, 1105, 1089, 1084, 1080, 1090, 1100, 1074, 1102,
                           1045, 1065, 1060, 1062, 1059, 1046, 1069, 1053, 1043, 1064, 86, 1047, 1050, 1066, 1049, 1067, 1041, 1028,
                           1040, 1061, 1056, 1054, 1051, 1044, 1055, 1071, 1063, 1025, 1057, 1052, 1048, 1058, 1068, 1042, 1070,
                           86, 118, 1028, 1108);

function Keys(e) {

    if (window.event) // IE
    {
        for (i = 0; i < Ansii.length; i++)
            if (Ansii[i] == e.keyCode) {
            e.keyCode = UniCode[i];
        }
        e.returnValue = true;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        for (i = 0; i < Ansii.length; i++)
            if (Ansii[i] == e.which) {
            var elem = e.srcElement || e.target;
            elem.value = elem.value + String.fromCharCode(UniCode[i]);
            return (false);
        }
    }
}



/*-------------------
* Картны хугацаа сунгах
--------------------*/
function Visible(pStep, pValue) {
    var tmp = $get(pStep);
    if (tmp != null) {
        if (!pValue) {
            tmp.style.visibility = "hidden";
            tmp.style.height = 0;
            tmp.style.width = 0;
        }
        else {
            tmp.style.visibility = "visible";
            tmp.style.height = "";
            tmp.style.width = "";
        }
    }
}
function StepShow(pStep) {
    Visible(Step1, false);
    Visible(Step2, false);
    Visible(Step3, false);
    Visible(StepHome, false);
    Visible(StepPost, false);
    Visible(StepSalbar, false);

    StepIndex = pStep;
    Visible(pStep, true);
}
function StepNextFunc() {
    Visible(StepBack, true);
    Visible(StepNext, true);
    Visible(StepFinish, false);

    if (StepIndex == Step1)
        StepShow(Step2);
    else if (StepIndex == Step2) {
        var tmp = $get(OptAgree);

        if (tmp != null) {
            if (!tmp.checked) {
                alert('Сонго');
                return;
            }
        }
        else return;
        StepShow(Step3);
    }
    else if (StepIndex == Step3) {
        var tmpPost = $get(OptPost);
        var tmpHome = $get(OptHome);
        var tmpSalbar = $get(OptSalbar);

        Visible(StepBack, true);
        Visible(StepNext, false);
        Visible(StepFinish, true);

        if (tmpPost != null & tmpHome != null & tmpSalbar != null) {
            if (tmpPost.checked)
                StepShow(StepPost);
            else if (tmpHome.checked)
                StepShow(StepHome);
            else if (tmpSalbar.checked)
                StepShow(StepSalbar);
        }


    }
    else if (StepIndex == StepHome) {
        Visible(StepBack, true);
        Visible(StepNext, false);
        Visible(StepFinish, true);
        StepShow(StepPost);
    }
    else if (StepIndex == StepPost) {
        Visible(StepBack, true);
        Visible(StepNext, false);
        Visible(StepFinish, true);
        StepShow(StepSalbar);
    }

}
function StepBackFunc() {
    Visible(StepBack, true);
    Visible(StepNext, true);
    Visible(StepFinish, false);

    if (StepIndex == StepHome || StepIndex == StepPost || StepIndex == StepSalbar)
        StepShow(Step3);
    else if (StepIndex == Step3)
        StepShow(Step2);
    else if (StepIndex == Step2) {
        Visible(StepBack, false);
        StepShow(Step1);
    }

}
/*-------------------
* Тооны машин дуудах
--------------------*/
function showCalc(Amount, unitID) {

    CalcControl = Amount;
    var txtSource = $get("_calculator1_txtSource");
    var txtOutput = $get("_calculator1_txtOutput");
    var txtUnitID = $get("_calculator1_txtUnitID");

    if (txtSource != null && txtUnitID != null && txtOutput != null) {
        var txt = $get(Amount);
        var unit = $get(unitID);
        txtSource.value = txt.value;
        txtOutput.value = txt.value;
        txtUnitID.value = unit.innerText;
    }
    var modal = $find('mdlCalc');
    Disable = true;

    modal.add_showing(DisableSelect);
    modal.add_hiding(EnableSelect);

    modal.show();

}

function setCalc() {
    var txt = $get(CalcControl);
    var val = $get("_calculator1_txtOutput");

    if (txt != null) {
        txt.value = val.value;
        $find('mdlCalc').hide();
    }
}


/*-------------------
* Menu дархад
--------------------*/

function MenuClick(tab, txt) {

}

function MenuBack() {
    var txt = $get("Trans" + _TabIndex);
    var tc = $find("TabMain");
    var title = $get("txtTitle");

    if (title != null && txt != null) {
        title.innerHTML = txt.innerHTML;
    }

    if (tc != null) {
        tc.get_tabs()[_TabIndex].set_enabled(true);
        tc.set_activeTabIndex(_TabIndex);
    }
}
function MenuGadaaBack() {
    var txt = $get("Trans7");
    var tc = $find("TabMain");
    var title = $get("txtTitle");

    if (title != null && txt != null) {
        title.innerHTML = txt.innerHTML;
    }

    if (tc != null) {
        tc.get_tabs()[7].set_enabled(true);
        tc.set_activeTabIndex(7);
    }
}
/*-------------------
* Huudas ачааллахад
--------------------*/

function refresh() {
    window.location.href = "pageLogin.aspx";
}
function pageLoad(sender, args) {
    //setTimeout("refresh()", 5*1000 )
    if (!args.get_isPartialLoad()) {
        Disable = false;

    }

    if (Disable) {
        var tagElements = document.getElementsByTagName('SELECT');

        for (var k = 0; k < tagElements.length; k++) {
            len = tagElements[k].id.length;
            if (tagElements[k].id.substr(len - 3, 3) != 'dlg') {
                tagElements[k].style.visibility = 'hidden';
            }
        }
    }
}

/*-------------------
* DropDownList iexplore 6.0- д 
* ontop байдаг тул 
* наана давхрага гаргахдаа 
* нуух функц
* dlg  гэсэн нэрээр төгссөн бол
* нуухгүй
--------------------*/
function DisableSelect() { Disable = true; }

function EnableSelect() {
    var tagElements = document.getElementsByTagName('SELECT');

    for (var k = 0; k < tagElements.length; k++) {
        len = tagElements[k].id.length;
        if (tagElements[k].id.substr(len - 3, 3) != 'dlg') {
            tagElements[k].style.visibility = 'inherit';
        }
    }

    Disable = false;
}

/*-------------------
* Progress-н гар ирэх хаах үед
--------------------*/
function beginRequest(sender, args) {
    var pro = $find('progress');
    if (pro != null) pro.show();

}

function endRequest(sender, args) {
    var pro = $find('progress');
    if (pro != null) pro.hide();

    $(".tool").tooltip({
        position: "bottom right",
        offset: [-2, 10],
        effect: "fade",
        opacity: 0.9

    });

}

/*-------------------
* Жижиг detail цонхыг нээхэд 
* ашиглах функц
--------------------*/



/*-------------------
* Хүснэгтийг хэвлэхэд 
* ашиглах функц
--------------------*/

function tblPrint(table_name) {
    tblPrint(table_name, 600, 600)
}

function tblPrint(table_name, w, h) {
    var tbl = $get(table_name);
    if (tbl != null) {

        var winPrint = window.open('', 'Print', 'height=' + h + ',width=' + w + ',scrollbars=1,resizable=1');

        winPrint.document.write('<html><head><title>Print</title>');
        winPrint.document.write('<link href="/__Style/StyleSheet.css" rel="stylesheet" type="text/css" />');
        winPrint.document.write('<link href="__Style/StyleSheet.css" rel="stylesheet" type="text/css" />');
        winPrint.document.write('<script language="javascript" type="text/javascript">');
        winPrint.document.write('setTimeout("window.print();",2000);');
        winPrint.document.write('</script>');
        winPrint.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body style="margin:0; padding:0"><table width="100%">');
        winPrint.document.write(tbl.innerHTML);
        winPrint.document.write('</table></body></html>');
        winPrint.document.close();


    }
}   
