﻿// JScript File
function popUp(URL) {
//    alert('order: ' + URL);
//    if (orderid) {
//        URL = '../Store/ViewOrder.aspx?OrderId=' + orderid + '&CustomerId=' + custid
//        }
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=150,left = 290,top = 150');");
    return false;
}
function RefreshParent(URL) {
    opener.location.href = URL;
    //window.parent.location.href = URL;
    window.close();
}
    function ValidateTransNoteForm() {
    //alert('validating!');
        //document.getElementById('IsLastCell').value = isLast;
        datetb = document.getElementById('DateTB');
        if (ParseDate(datetb.value) == false) { 
            alert('The date entered is invalid.');
            return false; 
        } else {
            //the date check passed so let's check the closed cbox
            closecb = document.getElementById('CloseCB');
            skipcb = document.getElementById('SkipCB');
            if (closecb.checked == false && skipcb.checked == false) { 
                return true; 
            } else { // not closed so no need to require note
            
                //The candidate's process is being closed so require a note
                notetb = document.getElementById('DescTB');
                if (notetb.value == '') {
                    alert('When closing the process for a candidate or skipping a step, a note is required.');
                    return false;
                } else {
                    return true;
                }
            }
       }
    }
    function ValidatePositionForm() {
        //plant = document.getElementById('ctl00_Body_DateTB0');
        //intranet = document.getElementById('ctl00_Body_DateTB1');
        intsearch = document.getElementById('ctl00_Body_DateTB2');
        extsearch = document.getElementById('ctl00_Body_DateTB3');

        if (intsearch.value == '' && extsearch.value == '') {
            alert('Internal or external search date required!');
            return false;
        }
        return true;
    }
    function ParseDate(input) {
        if (input == '') { return true; }
        parts = input.split("/");
        if (parts.length == 3) {
            //continue
            if (isNaN(parts[0])) { return false; }
            if (isNaN(parts[1])) { return false; }
            if (isNaN(parts[2])) { return false; }
            if (parts[0] < 1) { return false; }
            if (parts[0] > 12) { return false; }
            if (parts[1] < 1) { return false; }
            if (parts[1] > 31) { return false; }
            if (parts[2] < 2005) { return false; }
            if (parts[2] > 2100) { return false; }
        } else {
            //alert('Invalid date! ' + parts.length);
            return false;
        }
        return true;
    }
    function CheckDates(tb) {
        plant = document.getElementById('ctl00_Body_DateTB0').value;
        intranet = document.getElementById('ctl00_Body_DateTB1').value;
        intsearch = document.getElementById('ctl00_Body_DateTB2');
       
        if (ParseDate(plant)) {
            if (ParseDate(intranet)) {
                var pDate = new Date(plant);
                var iDate = new Date(intranet);
                 if (plant == '') { pDate = new Date('1/1/3000'); }
                if (intranet == '') { iDate = new Date('1/1/3000'); }
               if (pDate < iDate) {
                    intsearch.value = plant;
                } else {
                    intsearch.value = intranet;
                }
            } else {
                intsearch.value = plant;
                if (tb.name == 'ctl00$Body$DateTB1') {
                    alert('Invalid intranet date.');
                    document.getElementById('ctl00_Body_DateTB1').focus();
                }
            }
        } else {
            if (ParseDate(intranet)) {
                intsearch.value = intranet;
                if (tb.name == 'ctl00$Body$DateTB0') {
                    alert('Invalid plant date.');
                    document.getElementById('ctl00_Body_DateTB0').focus();
                }
            } else {
                if (tb.name == 'ctl00$Body$DateTB1') {
                alert('Invalid date.');
                document.getElementById('ctl00_Body_DateTB1').focus();
                }
            }
        }
       
    }
